diff --git a/.vscode/launch.json b/.vscode/launch.json index 455046b4e4..dde10cbb32 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -193,18 +193,12 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/src/Fable.Cli/bin/Debug/net6.0/fable.dll", "args": [ - "--", "src/fable-library-dart", - "--outDir", - "temp/fable-library-dart", - "--fableLib", - "./temp/fable-library-dart", - "--lang", - "dart", - "--exclude", - "Fable.Core", - "--define", - "FABLE_LIBRARY", + "--outDir", "temp/fable-library-dart", + "--fableLib", "./temp/fable-library-dart", + "--exclude", "Fable.Core", + "--define", "FABLE_LIBRARY", + "--lang", "Dart", "--noCache" ] }, @@ -216,21 +210,14 @@ "program": "${workspaceFolder}/src/Fable.Cli/bin/Debug/net6.0/fable.dll", "args": [ "src/fable-library-ts", - "--outDir", - "temp/fable-library-ts", - "--fableLib", - "./temp/fable-library-ts", - "--lang", - "typescript", - "--exclude", - "Fable.Core", - "--define", - "FABLE_LIBRARY", - "--noCache", - "--typedArrays", - "false", - "--define", - "FX_NO_BIGINT" + "--outDir", "temp/fable-library-ts", + "--fableLib", "./temp/fable-library-ts", + "--exclude", "Fable.Core", + "--define", "FABLE_LIBRARY", + "--define", "FX_NO_BIGINT", + "--typedArrays", "false", + "--lang", "TypeScript", + "--noCache" ] }, { @@ -241,16 +228,11 @@ "program": "${workspaceFolder}/src/Fable.Cli/bin/Debug/net6.0/fable.dll", "args": [ "src/fable-library-py/fable_library", - "--outDir", - "temp/fable-library-py/fable_library", - "--fableLib", - ".", - "--lang", - "python", - "--exclude", - "Fable.Core", - "--define", - "FABLE_LIBRARY", + "--outDir", "temp/fable-library-py/fable_library", + "--fableLib", ".", + "--exclude", "Fable.Core", + "--define", "FABLE_LIBRARY", + "--lang", "Python", "--noCache" ] }, @@ -262,29 +244,34 @@ "program": "${workspaceFolder}/src/Fable.Cli/bin/Debug/net6.0/fable.dll", "args": [ "src/fable-library-rust/src", - "--outDir", - "temp/fable-library-rust/src", - "--fableLib", - ".", - "--lang", - "rust", - "--exclude", - "Fable.Core", - "--define", - "FABLE_LIBRARY", - "--noCache" + "--outDir", "temp/fable-library-rust/src", + "--fableLib", ".", + "--exclude", "Fable.Core", + "--define", "FABLE_LIBRARY", + "--lang", "Rust", + "--noCache", + "--noParallelTypeCheck", + "--test:MSBuildCracker" ] }, { - "name": "Fable.Cli on ../fable-test", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - "program": "${workspaceRoot}/src/Fable.Cli/bin/Debug/net6.0/fable.dll", - "args": ["--outDir", "${workspaceRoot}/../fable-test", "--fableLib", "${workspaceRoot}/temp/fable-library-rust", "--exclude", "Fable.Core", "--lang", "Rust", "--noCache", "--noParallelTypeCheck", "--test:MSBuildCracker"], - "cwd": "${workspaceRoot}/../fable-test", - "stopAtEntry": false, - "console": "internalConsole" + "name": "Fable.Cli on ../fable-test", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceRoot}/src/Fable.Cli/bin/Debug/net6.0/fable.dll", + "args": [ + "--outDir", "${workspaceRoot}/../fable-test", + "--fableLib", "${workspaceRoot}/temp/fable-library-rust", + "--exclude", "Fable.Core", + "--lang", "Rust", + "--noCache", + "--noParallelTypeCheck", + "--test:MSBuildCracker" + ], + "cwd": "${workspaceRoot}/../fable-test", + "stopAtEntry": false, + "console": "internalConsole" } ] -} +} \ No newline at end of file diff --git a/src/Fable.Cli/Main.fs b/src/Fable.Cli/Main.fs index 4b5177228f..a85fb92dd3 100644 --- a/src/Fable.Cli/Main.fs +++ b/src/Fable.Cli/Main.fs @@ -478,7 +478,7 @@ type FableCompilerState = and FableCompiler(checker: InteractiveChecker, projCracked: ProjectCracked, fableProj: Project) = let agent = MailboxProcessor.Start(fun agent -> - let startInThreadPool toMsg work = + let postTo toMsg work = async { try let! result = work () @@ -486,12 +486,22 @@ and FableCompiler(checker: InteractiveChecker, projCracked: ProjectCracked, fabl with e -> UnexpectedError e |> agent.Post } - |> Async.Start + + let startInThreadPool toMsg work = postTo toMsg work |> Async.Start + + let runSynchronously toMsg work = + postTo toMsg work |> Async.RunSynchronously let fableCompile state fileName = let fableProj = state.FableProj - startInThreadPool + let runner = + // for Rust, sequential compilation captures all imports and namespaces + match projCracked.CliArgs.CompilerOptions.Language with + | Rust -> runSynchronously // sequential file compilation + | _ -> startInThreadPool // parallel file compilation + + runner FableFileCompiled (fun () -> async { @@ -574,7 +584,6 @@ and FableCompiler(checker: InteractiveChecker, projCracked: ProjectCracked, fabl // Print F# AST to file if projCracked.CliArgs.PrintAst then let outPath = getOutPath projCracked.CliArgs state.PathResolver file.FileName - let outDir = IO.Path.GetDirectoryName(outPath) Printers.printAst outDir [ file ] @@ -586,7 +595,6 @@ and FableCompiler(checker: InteractiveChecker, projCracked: ProjectCracked, fabl state else let state = { state with FableProj = state.FableProj.Update([ file ]) } - fableCompile state fileName return! loop state diff --git a/src/Fable.Transforms/FSharp2Fable.Util.fs b/src/Fable.Transforms/FSharp2Fable.Util.fs index 59b7ee48a6..11fbe48403 100644 --- a/src/Fable.Transforms/FSharp2Fable.Util.fs +++ b/src/Fable.Transforms/FSharp2Fable.Util.fs @@ -354,6 +354,8 @@ type FsEnt(maybeAbbrevEnt: FSharpEntity) = | None -> ent.LogicalName static member Ref(ent: FSharpEntity) : Fable.EntityRef = + let ent = Helpers.nonAbbreviatedDefinition ent + let path = match ent.Assembly.FileName with | Some asmPath -> @@ -2711,6 +2713,13 @@ module Util = ) |> snd + let getInterfaceMembers (com: Compiler) (ent: Fable.Entity) = + ent.AllInterfaces + |> Seq.collect (fun ifc -> + let ifcEnt = com.GetEntity(ifc.Entity) + ifcEnt.MembersFunctionsAndValues |> Seq.map (fun memb -> ifc, memb) + ) + let hasInterface fullName (ent: Fable.Entity) = ent.AllInterfaces |> Seq.exists (fun ifc -> ifc.Entity.FullName = fullName) diff --git a/src/Fable.Transforms/Global/Naming.fs b/src/Fable.Transforms/Global/Naming.fs index 741d378e36..616334470e 100644 --- a/src/Fable.Transforms/Global/Naming.fs +++ b/src/Fable.Transforms/Global/Naming.fs @@ -127,8 +127,16 @@ module Naming = else s.Substring(i1 + 1, i2 - i1 - 1) + let splitFirstBy (sep: string) (s: string) = + let i = s.IndexOf(sep, StringComparison.Ordinal) + + if i < 0 then + s, "" + else + s.Substring(0, i), s.Substring(i + sep.Length) + let splitLastBy (sep: string) (s: string) = - let i = s.LastIndexOf(sep) + let i = s.LastIndexOf(sep, StringComparison.Ordinal) if i < 0 then "", s diff --git a/src/Fable.Transforms/Rust/Fable2Rust.fs b/src/Fable.Transforms/Rust/Fable2Rust.fs index 01fb7f8f11..bad7b91857 100644 --- a/src/Fable.Transforms/Rust/Fable2Rust.fs +++ b/src/Fable.Transforms/Rust/Fable2Rust.fs @@ -828,57 +828,19 @@ module TypeInfo = | None -> match entRef.Path with | Fable.AssemblyPath _ - | Fable.CoreAssemblyName _ when not (Util.isFableLibrary com) -> + | Fable.CoreAssemblyName _ -> //TODO: perhaps only import from library if it's already implemented BCL class - let importName = com.GetImportName(ctx, entRef.FullName, "fable_library_rust", None) + let importPath = "fable_library_rust" + let importName = com.GetImportName(ctx, entRef.FullName, importPath, None) importName - | _ when (Util.isFableLibrary com) -> "crate::" + entRef.FullName | _ -> entRef.FullName - let declaredInterfaces = - Set.ofList - [ - Types.icollection - Types.icollectionGeneric - Types.idictionary - Types.ireadonlydictionary - Types.idisposable - Types.iformattable - Types.iformatProvider - Types.icomparer - Types.icomparerGeneric - Types.iequalityComparer - Types.iequalityComparerGeneric - Types.ienumerable - Types.ienumerableGeneric - Types.ienumerator - Types.ienumeratorGeneric - Types.iequatableGeneric - Types.icomparable - Types.icomparableGeneric - Types.iStructuralEquatable - Types.iStructuralComparable - ] - - let isDeclaredInterface fullName = - Set.contains fullName declaredInterfaces - - let getInterfaceImportName (com: IRustCompiler) ctx (entRef: Fable.EntityRef) = - if isDeclaredInterface entRef.FullName then - getLibraryImportName com ctx "Interfaces" entRef.FullName - else - getEntityFullName com ctx entRef - // let selector = "crate::" + entRef.FullName - // let path = "" - // com.GetImportName(ctx, selector, path, None) - let tryFindInterface (com: IRustCompiler) fullName (entRef: Fable.EntityRef) : Fable.DeclaredType option = let ent = com.GetEntity(entRef) - ent.AllInterfaces |> Seq.tryFind (fun ifc -> ifc.Entity.FullName = fullName) let transformInterfaceType com ctx (entRef: Fable.EntityRef) genArgs : Rust.Ty = - let nameParts = getInterfaceImportName com ctx entRef |> splitNameParts + let nameParts = getEntityFullName com ctx entRef |> splitNameParts let genArgsOpt = transformGenArgs com ctx genArgs let traitBound = mkTypeTraitGenericBound nameParts genArgsOpt mkDynTraitTy [ traitBound ] @@ -2173,7 +2135,8 @@ module Util = let memberItems = members |> List.map (fun decl -> decl, com.GetMember(decl.MemberRef)) - |> List.filter (fun (d, m) -> m.DeclaringEntity = Some(entRef)) + |> List.filter (fun (d, m) -> isInterfaceMember com entRef m) + |> List.distinctBy (fun (d, m) -> Fable.Naming.splitLast m.CompiledName) |> List.map (makeMemberItem com ctx false) |> makeInterfaceTraitImpls com ctx entName genParams entRef genArgs @@ -2420,7 +2383,7 @@ module Util = // match calleeExpr.Type with // | IsNonErasedInterface com (entRef, genArgs) -> // // interface instance call (using fully qualified syntax) - // let ifcName = getInterfaceImportName com ctx entRef + // let ifcName = getEntityFullName com ctx entRef // let parts = (ifcName + "::" + membName) |> splitNameParts // (callee |> makeAsRef) :: args |> makeCall parts None // | _ -> @@ -3720,7 +3683,7 @@ module Util = let ent = com.GetEntity(entRef) if ent.IsInterface then - let nameParts = getInterfaceImportName com ctx entRef |> splitNameParts + let nameParts = getEntityFullName com ctx entRef |> splitNameParts let genArgsOpt = transformGenArgs com ctx genArgs let traitBound = mkTypeTraitGenericBound nameParts genArgsOpt [ traitBound ] @@ -3907,7 +3870,6 @@ module Util = let macroItem = mkMacroItem attrs macroName [ expr ] [ macroItem ] - let transformExtensionMethod (com: IRustCompiler) ctx (memb: Fable.MemberFunctionOrValue) (decl: Fable.MemberDecl) = let argTypes = decl.Args |> List.map (fun arg -> arg.Type) @@ -4087,17 +4049,24 @@ module Util = let fnItem = mkFnAssocItem attrs name fnKind fnItem - let getInterfaceMemberNames (com: IRustCompiler) (entRef: Fable.EntityRef) = + let isInterfaceMember (com: IRustCompiler) (entRef: Fable.EntityRef) (memb: Fable.MemberFunctionOrValue) = let ent = com.GetEntity(entRef) assert (ent.IsInterface) - ent.AllInterfaces - |> Seq.collect (fun i -> - let e = com.GetEntity(i.Entity) - e.MembersFunctionsAndValues - ) - |> Seq.map (fun m -> m.CompiledName) - |> Set.ofSeq + match memb.DeclaringEntity with + | Some declEntRef -> + let declEnt = com.GetEntity(declEntRef) + + if declEnt.IsInterface then + ent.AllInterfaces |> Seq.exists (fun ifc -> ifc.Entity = declEntRef) + else + // if declaring entity is not an interface, the interface is in the member.CompiledName + let ifcName, membName = Fable.Naming.splitLastBy "." memb.CompiledName + let ifcName, _ = Fable.Naming.splitFirstBy "<" ifcName // trim the generics + + ent.AllInterfaces + |> Seq.exists (fun ifc -> ifc.Entity.FullName.StartsWith(ifcName)) + | None -> false let makeDerivedFrom com (ent: Fable.Entity) = let isCopyable = ent |> isCopyableEntity com Set.empty @@ -4289,59 +4258,56 @@ module Util = let ctor = { ctor with Body = body } let memb = com.GetMember(ctor.MemberRef) - let fnItem = transformAssocMember com ctx memb ctor.Name ctor.Args ctor.Body - let fnItem = fnItem |> memberAssocItemWithVis com ctx memb fnItem let makeInterfaceItems (com: IRustCompiler) ctx hasBody typeName (ent: Fable.Entity) = - ent.AllInterfaces - |> Seq.collect (fun ifc -> - let ifcTyp = Fable.DeclaredType(ifc.Entity, ifc.GenericArgs) - let ifcEnt = com.GetEntity(ifc.Entity) + assert (ent.IsInterface) - ifcEnt.MembersFunctionsAndValues - |> Seq.filter (fun memb -> memb.IsDispatchSlot) - |> Seq.distinctBy (fun memb -> memb.CompiledName) - |> Seq.map (fun memb -> - let thisArg = { makeTypedIdent ifcTyp "this" with IsThisArgument = true } + ent + |> FSharp2Fable.Util.getInterfaceMembers com + |> Seq.filter (fun (ifc, memb) -> memb.IsDispatchSlot) // TODO: is that needed? + |> Seq.distinctBy (fun (ifc, memb) -> Fable.Naming.splitLast memb.CompiledName) // skip inherited overwrites + |> Seq.map (fun (ifc, memb) -> + let ifcEnt = com.GetEntity(ifc.Entity) + let ifcTyp = Fable.DeclaredType(ifc.Entity, ifc.GenericArgs) + let thisArg = { makeTypedIdent ifcTyp "this" with IsThisArgument = true } - let membName = memb.CompiledName + let membName = memb.CompiledName - let memberArgs = - memb.CurriedParameterGroups - |> List.collect id - |> List.mapi (fun i p -> - let name = defaultArg p.Name $"arg{i}" - makeTypedIdent p.Type name - ) + let memberArgs = + memb.CurriedParameterGroups + |> List.collect id + |> List.mapi (fun i p -> + let name = defaultArg p.Name $"arg{i}" + makeTypedIdent p.Type name + ) - let args = - if memb.IsInstance then - thisArg :: memberArgs - else - memberArgs - - let bodyOpt = - if hasBody then - let args = memberArgs |> List.map (transformIdent com ctx None) - - let body = - if memb.IsInstance then - // let thisExpr = makeThis com ctx None ifcTyp - let thisExpr = mkGenericPathExpr [ rawIdent "self" ] None - let callee = thisExpr |> mkDerefExpr |> mkDerefExpr - mkMethodCallExpr membName None callee args - else - makeCall [ typeName; membName ] None args + let args = + if memb.IsInstance then + thisArg :: memberArgs + else + memberArgs + + let bodyOpt = + if hasBody then + let args = memberArgs |> List.map (transformIdent com ctx None) + + let body = + if memb.IsInstance then + // let thisExpr = makeThis com ctx None ifcTyp + let thisExpr = mkGenericPathExpr [ rawIdent "self" ] None + let callee = thisExpr |> mkDerefExpr |> mkDerefExpr + mkMethodCallExpr membName None callee args + else + makeCall [ typeName; membName ] None args - [ mkExprStmt body ] |> mkBlock |> Some - else - None + [ mkExprStmt body ] |> mkBlock |> Some + else + None - makeAssocMemberItem com ctx memb args bodyOpt - ) + makeAssocMemberItem com ctx memb args bodyOpt ) let transformInterface (com: IRustCompiler) ctx (ent: Fable.Entity) (decl: Fable.ClassDecl) = @@ -4516,9 +4482,7 @@ module Util = { ctx with UsedNames = { ctx.UsedNames with CurrentDeclarationScope = HashSet usedNames } } let result = f ctx - ctx.UsedNames.DeclarationScopes.UnionWith(ctx.UsedNames.CurrentDeclarationScope) - result let makeMemberItem (com: IRustCompiler) ctx withVis (decl: Fable.MemberDecl, memb: Fable.MemberFunctionOrValue) = @@ -4555,7 +4519,7 @@ module Util = let ty = mkTraitTy [ traitBound ] let generics = makeGenerics com ctx genArgs - let ifcFullName = ifcEntRef |> getInterfaceImportName com ctx + let ifcFullName = ifcEntRef |> getEntityFullName com ctx let ifcGenArgsOpt = ifcGenArgs |> transformGenArgs com ctx let path = makeFullNamePath ifcFullName ifcGenArgsOpt @@ -4576,6 +4540,14 @@ module Util = let ignoredInterfaceNames = set [ Types.ienumerable; Types.ienumerator ] + let getAllInterfaces (ent: Fable.Entity) : Fable.DeclaredType list = + ent.AllInterfaces + |> Seq.filter (fun ifc -> + // throws out anything on the ignored interfaces list + not (Set.contains ifc.Entity.FullName ignoredInterfaceNames) + ) + |> Seq.toList + let transformClassMembers (com: IRustCompiler) ctx (classDecl: Fable.ClassDecl) = let entRef = classDecl.Entity let ent = com.GetEntity(entRef) @@ -4636,25 +4608,13 @@ module Util = nonInterfaceMembers |> List.choose (makeOpTraitImpls com ctx ent entType self_ty genArgTys) - let interfaces = - ent.AllInterfaces - |> Seq.filter (fun ifc -> - // throws out anything on the ignored interfaces list - not (Set.contains ifc.Entity.FullName ignoredInterfaceNames) - ) - |> Seq.toList - let interfaceTraitImpls = - interfaces + getAllInterfaces ent |> List.collect (fun ifc -> - let ifcMemberNames = ifc.Entity |> getInterfaceMemberNames com - let memberItems = interfaceMembers - |> List.filter (fun (d, m) -> - //TODO: match the interface entity too, not just the member name - Set.contains d.Name ifcMemberNames - ) + |> List.filter (fun (d, m) -> isInterfaceMember com ifc.Entity m) + |> List.distinctBy (fun (d, m) -> Fable.Naming.splitLast m.CompiledName) |> List.map (makeMemberItem com ctx false) if List.isEmpty memberItems then @@ -4671,10 +4631,7 @@ module Util = if ent.IsFSharpAbbreviation then transformAbbrev com ctx ent decl elif ent.IsInterface then - if isDeclaredInterface ent.FullName then - [] - else - transformInterface com ctx ent decl + transformInterface com ctx ent decl else let entityItem = if ent.IsFSharpUnion then @@ -4954,11 +4911,10 @@ module Compiler = let isMacro = selector.EndsWith("!", StringComparison.Ordinal) let selector = selector |> Fable.Naming.replaceSuffix "!" "" + let selector = selector.Replace(".", "::").Replace("`", "_") let path = fixFileExtension self path let cacheKey = - let selector = selector.Replace(".", "::").Replace("`", "_") - if (isFableLibraryPath self path) then "fable_library_rust::" + selector elif path.Length = 0 then @@ -4986,7 +4942,11 @@ module Compiler = Depths = [ ctx.ModuleDepth ] } // add import module to a global list (across files) - if path.Length > 0 && not (isFableLibraryPath self path) then + if + path.Length > 0 + && path <> "fable_library_rust" + && not (isFableLibraryPath self path) + then importModules.TryAdd(modulePath, true) |> ignore imports.Add(cacheKey, import) diff --git a/src/fable-library-rust/src/Fable.Library.Rust.fsproj b/src/fable-library-rust/src/Fable.Library.Rust.fsproj index 8252c7e825..1365dbd308 100644 --- a/src/fable-library-rust/src/Fable.Library.Rust.fsproj +++ b/src/fable-library-rust/src/Fable.Library.Rust.fsproj @@ -7,11 +7,6 @@ - - - - - @@ -22,6 +17,11 @@ + + + + + diff --git a/src/fable-library-rust/src/HashMap.rs b/src/fable-library-rust/src/HashMap.rs index a1bc5d2308..c2dee0058f 100644 --- a/src/fable-library-rust/src/HashMap.rs +++ b/src/fable-library-rust/src/HashMap.rs @@ -9,7 +9,7 @@ pub mod HashMap_ { #[cfg(not(feature = "no_std"))] use std::collections; - use crate::Interfaces_::System::Collections::Generic::IEqualityComparer_1; + use crate::System::Collections::Generic::IEqualityComparer_1; use crate::NativeArray_::{array_from, Array}; use crate::Native_::{mkRefMut, seq_to_iter, HashKey, Lrc, LrcPtr, MutCell, Seq, Vec}; diff --git a/src/fable-library-rust/src/HashSet.rs b/src/fable-library-rust/src/HashSet.rs index 2e0068f5a4..d35b3f8116 100644 --- a/src/fable-library-rust/src/HashSet.rs +++ b/src/fable-library-rust/src/HashSet.rs @@ -9,7 +9,7 @@ pub mod HashSet_ { #[cfg(not(feature = "no_std"))] use std::collections; - use crate::Interfaces_::System::Collections::Generic::IEqualityComparer_1; + use crate::System::Collections::Generic::IEqualityComparer_1; use crate::NativeArray_::{array_from, Array}; use crate::Native_::{mkRefMut, seq_to_iter, HashKey, Lrc, LrcPtr, MutCell, Seq, Vec}; diff --git a/src/fable-library-rust/src/Interfaces.fs b/src/fable-library-rust/src/Interfaces.fs index 0ea8fb3f07..6974b5700a 100644 --- a/src/fable-library-rust/src/Interfaces.fs +++ b/src/fable-library-rust/src/Interfaces.fs @@ -1,84 +1,81 @@ -module Interfaces_ +namespace System -module System = +type IDisposable = + abstract Dispose: unit -> unit - type IDisposable = - abstract Dispose: unit -> unit +type IEquatable<'T> = + abstract Equals: 'T -> bool - type IEquatable<'T> = - abstract Equals: 'T -> bool +type IComparable = + abstract CompareTo: obj -> int - type IComparable = - abstract CompareTo: obj -> int +type IComparable<'T> = + abstract CompareTo: 'T -> int - type IComparable<'T> = - abstract CompareTo: 'T -> int +type IFormatProvider = + abstract GetFormat: System.Type -> obj - type IFormatProvider = - abstract GetFormat: System.Type -> obj +type IFormattable = + abstract ToString: string * IFormatProvider -> string - type IFormattable = - abstract ToString: string * IFormatProvider -> string - module Collections = +namespace System.Collections - type IComparer = - abstract Compare: obj * obj -> int +type IComparer = + abstract Compare: obj * obj -> int - type IEqualityComparer = - abstract Equals: obj * obj -> bool - abstract GetHashCode: obj -> int +type IEqualityComparer = + abstract Equals: obj * obj -> bool + abstract GetHashCode: obj -> int - type IEnumerator = - inherit System.IDisposable - abstract Current: obj - abstract MoveNext: unit -> bool - abstract Reset: unit -> unit +type IEnumerator = + abstract Current: obj + abstract MoveNext: unit -> bool + abstract Reset: unit -> unit - type IEnumerable = - abstract GetEnumerator: unit -> IEnumerator +type IEnumerable = + abstract GetEnumerator: unit -> IEnumerator - type IStructuralComparable = - abstract CompareTo: obj * IComparer -> int +type IStructuralComparable = + abstract CompareTo: obj * IComparer -> int - type IStructuralEquatable = - abstract Equals: obj * IEqualityComparer -> bool - abstract GetHashCode: IEqualityComparer -> int +type IStructuralEquatable = + abstract Equals: obj * IEqualityComparer -> bool + abstract GetHashCode: IEqualityComparer -> int - module Generic = - type IComparer<'T> = - abstract Compare: 'T * 'T -> int +namespace System.Collections.Generic - type IEqualityComparer<'T> = - abstract Equals: 'T * 'T -> bool - abstract GetHashCode: 'T -> int +type IComparer<'T> = + abstract Compare: 'T * 'T -> int - type IEnumerator<'T> = - inherit System.IDisposable - // inherit System.Collections.IEnumerator - abstract Current: 'T - abstract MoveNext: unit -> bool - abstract Reset: unit -> unit +type IEqualityComparer<'T> = + abstract Equals: 'T * 'T -> bool + abstract GetHashCode: 'T -> int - type IEnumerable<'T> = - // inherit System.Collections.IEnumerable - abstract GetEnumerator: unit -> IEnumerator<'T> +type IEnumerator<'T> = + inherit System.IDisposable + inherit System.Collections.IEnumerator + abstract Current: 'T - type ICollection<'T> = - abstract Count: int - abstract IsReadOnly: bool - abstract Contains: 'T -> bool - abstract Add: 'T -> unit - abstract Remove: 'T -> bool - abstract Clear: unit -> unit - abstract CopyTo: 'T[] * int -> unit +type IEnumerable<'T> = + inherit System.Collections.IEnumerable + abstract GetEnumerator: unit -> IEnumerator<'T> - type IDictionary<'K, 'V> = - abstract Item: 'K -> 'V with get //, set //TODO: support property setters - abstract Keys: ICollection<'K> - abstract Values: ICollection<'V> - abstract Add: 'K * 'V -> unit - abstract ContainsKey: 'K -> bool - abstract TryGetValue: 'K * byref<'V> -> bool - abstract Remove: 'K -> bool +type ICollection<'T> = + abstract Count: int + abstract IsReadOnly: bool + abstract Contains: 'T -> bool + abstract Add: 'T -> unit + abstract Remove: 'T -> bool + abstract Clear: unit -> unit + abstract CopyTo: 'T[] * int -> unit + +type IDictionary<'K, 'V> = + abstract Item: 'K -> 'V with get, set + abstract Keys: ICollection<'K> + abstract Values: ICollection<'V> + abstract Add: 'K * 'V -> unit + abstract ContainsKey: 'K -> bool + abstract TryGetValue: 'K * byref<'V> -> bool + abstract Remove: 'K -> bool diff --git a/src/fable-library-rust/src/Native.rs b/src/fable-library-rust/src/Native.rs index 880a3cc94a..08e4ac41c8 100644 --- a/src/fable-library-rust/src/Native.rs +++ b/src/fable-library-rust/src/Native.rs @@ -55,8 +55,8 @@ pub mod Native_ { value } - use crate::Interfaces_::System::Collections::Generic::IEnumerable_1; - use crate::Interfaces_::System::Collections::Generic::IEqualityComparer_1; + use crate::System::Collections::Generic::IEnumerable_1; + use crate::System::Collections::Generic::IEqualityComparer_1; // TODO: use these types in generated code pub type Seq = LrcPtr>; diff --git a/src/fable-library-rust/src/RegExp.rs b/src/fable-library-rust/src/RegExp.rs index dd2a7f10f7..3b234836cc 100644 --- a/src/fable-library-rust/src/RegExp.rs +++ b/src/fable-library-rust/src/RegExp.rs @@ -3,7 +3,7 @@ pub mod RegExp_ { use core::borrow::{Borrow, BorrowMut}; use crate::{ - Interfaces_::System::Collections::Generic::{IEnumerable_1, IEnumerator_1}, + System::Collections::Generic::{IEnumerable_1, IEnumerator_1}, NativeArray_::{array_from, new_array, new_empty, Array}, Native_::{Func1, LrcPtr, ToString, Vec}, Seq_::ofArray, diff --git a/src/fable-library-rust/src/Seq.fs b/src/fable-library-rust/src/Seq.fs index f65ef160c5..205d7b3e2e 100644 --- a/src/fable-library-rust/src/Seq.fs +++ b/src/fable-library-rust/src/Seq.fs @@ -6,13 +6,7 @@ module Seq_ open Global_ -open Interfaces_ -//open System.Collections.Generic - -type IEnumerable<'T> = System.Collections.Generic.IEnumerable<'T> -type IEnumerator<'T> = System.Collections.Generic.IEnumerator<'T> - -type 'T seq = IEnumerable<'T> +open System.Collections.Generic let inline indexNotFound () = failwith SR.keyNotFoundAlt @@ -27,8 +21,10 @@ module Enumerable = type Enumerable<'T>(f) = interface IEnumerable<'T> with member _.GetEnumerator() = f () - // interface System.Collections.IEnumerable with - // member _.GetEnumerator() = f() :> System.Collections.IEnumerator + + interface System.Collections.IEnumerable with + member _.GetEnumerator() = f () :> System.Collections.IEnumerator + // override xs.ToString() = // let maxCount = 4 // let mutable i = 0 @@ -49,22 +45,17 @@ module Enumerable = interface IEnumerator<'T> with member _.Current = curr.Value + interface System.Collections.IEnumerator with + member _.Current = curr.Value + member _.MoveNext() = curr <- next () curr.IsSome member _.Reset() = () + + interface System.IDisposable with member _.Dispose() = dispose () - // interface System.Collections.IEnumerator with - // member _.Current = - // curr.Value - // member _.MoveNext() = - // curr <- next() - // curr.IsSome - // member _.Reset() = () - // member _.Dispose() = dispose() - // interface System.IDisposable with - // member _.Dispose() = dispose() let fromFunction next : IEnumerator<'T> = let dispose () = () diff --git a/src/fable-library-ts/Fable.Library.TypeScript.fsproj b/src/fable-library-ts/Fable.Library.TypeScript.fsproj index f8047462ee..02beb89615 100644 --- a/src/fable-library-ts/Fable.Library.TypeScript.fsproj +++ b/src/fable-library-ts/Fable.Library.TypeScript.fsproj @@ -3,7 +3,7 @@ net8.0 $(DefineConstants);FABLE_COMPILER - $(DefineConstants);FX_NO_BIGINT +