@@ -841,7 +841,7 @@ let makeMap (com: ICompiler) ctx r t methName args genArg =
841841 Helper.LibCall( com, " Map" , Naming.lowerFirst methName, t, args, ?loc= r)
842842
843843let makeDictionaryWithComparer com r t sourceSeq comparer =
844- Helper.LibCall( com, " Map " , " createMutable " , t, [ sourceSeq; comparer], ?loc= r)
844+ Helper.LibCall( com, " MutableMap " , " Dictionary " , t, [ sourceSeq; comparer], isJsConstructor = true , ?loc= r)
845845
846846let makeDictionary ( com : ICompiler ) ctx r t sourceSeq =
847847 match t with
@@ -852,7 +852,7 @@ let makeDictionary (com: ICompiler) ctx r t sourceSeq =
852852 | _ -> Helper.GlobalCall( " Map" , t, [ sourceSeq], isJsConstructor= true , ?loc= r)
853853
854854let makeHashSetWithComparer com r t sourceSeq comparer =
855- Helper.LibCall( com, " Set " , " createMutable " , t, [ sourceSeq; comparer], ?loc= r)
855+ Helper.LibCall( com, " MutableSet " , " HashSet " , t, [ sourceSeq; comparer], isJsConstructor = true , ?loc= r)
856856
857857let makeHashSet ( com : ICompiler ) ctx r t sourceSeq =
858858 match t with
@@ -1614,17 +1614,12 @@ let seqs (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Exp
16141614
16151615 match i.CompiledName, args with
16161616 | " Cast" , [ arg] -> Some arg // Erase
1617- | ( " Cache" | " ToArray" ), [ arg] -> toArray com t arg |> Some
1617+ | ( " Cache" | " ToArray" ), [ arg] -> toArray com t arg |> Some
16181618 | " OfList" , [ arg] -> toSeq t arg |> Some
16191619 | " ToList" , _ -> Helper.LibCall( com, " List" , " ofSeq" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
1620- | " ChunkBySize" | " Permute" as meth, [ arg1; arg2] ->
1620+ | ( " ChunkBySize" | " Permute" | " SplitInto " ) as meth, [ arg1; arg2] ->
16211621 let arg2 = toArray com ( Array Any) arg2
1622- let args =
1623- match meth, t with
1624- | " Permute" , DeclaredType(_ seq, [ genArg]) ->
1625- [ arg1; arg2] @ [ arrayCons com genArg]
1626- | _ -> [ arg1; arg2]
1627- let result = Helper.LibCall( com, " Array" , Naming.lowerFirst meth, Any, args)
1622+ let result = Helper.LibCall( com, " Array" , Naming.lowerFirst meth, Any, [ arg1; arg2])
16281623 Helper.LibCall( com, " Seq" , " ofArray" , t, [ result]) |> Some
16291624 // For Using we need to cast the argument to IDisposable
16301625 | " EnumerateUsing" , [ arg; f] ->
@@ -1696,6 +1691,8 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this
16961691 Helper.LibCall( com, " Seq" , " filter" , t, [ arg; ar], ?loc= r) |> toArray com t |> Some
16971692 | " AddRange" , Some ar, [ arg] ->
16981693 Helper.LibCall( com, " Array" , " addRangeInPlace" , t, [ arg; ar], ?loc= r) |> Some
1694+ | " GetRange" , Some ar, [ idx; cnt] ->
1695+ Helper.LibCall( com, " Array" , " getSubArray" , t, [ ar; idx; cnt], ?loc= r) |> Some
16991696 | " Contains" , Some ( MaybeCasted( ar)), [ arg] ->
17001697 match ar.Type with
17011698 | Array _ ->
@@ -1772,6 +1769,7 @@ let arrayModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (_: Ex
17721769 | " ToSeq" , [ arg] -> Some arg
17731770 | " OfSeq" , [ arg] -> toArray com t arg |> Some
17741771 | " OfList" , [ arg] -> listToArray com r t arg |> Some
1772+ | " ToList" , _ -> Helper.LibCall( com, " List" , " ofArray" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
17751773 | ( " Length" | " Count" ), [ arg] -> get r t arg " length" |> Some
17761774 | " Item" , [ idx; ar] -> getExpr r t ar idx |> Some
17771775 | " Get" , [ ar; idx] -> getExpr r t ar idx |> Some
@@ -1803,29 +1801,26 @@ let arrayModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (_: Ex
18031801 Helper.LibCall( com, " Array" , meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
18041802
18051803let lists ( com : ICompiler ) ( ctx : Context ) r ( t : Type ) ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
1804+ let meth = Naming.removeGetSetPrefix i.CompiledName |> Naming.lowerFirst
18061805 match i.CompiledName, thisArg, args with
1807- // Use methods for Head and Tail (instead of Get(ListHead) for example) to check for empty lists
1808- | ReplaceName
1809- [ " get_Head" , " head"
1810- " get_Tail" , " tail"
1811- " get_Item" , " item"
1812- " get_Length" , " length"
1813- " GetSlice" , " slice" ] methName, Some x, _ ->
1814- let args = match args with [ ExprType Unit] -> [ x] | args -> args @ [ x]
1815- Helper.LibCall( com, " List" , methName, t, args, i.SignatureArgTypes, ?loc= r) |> Some
1816- | " get_IsEmpty" , Some x, _ -> Test( x, ListTest false , r) |> Some
1817- | " get_Empty" , None, _ -> NewList( None, ( genArg com ctx r 0 i.GenericArgs)) |> makeValue r |> Some
1818- | " Cons" , None, [ h; t] -> NewList( Some( h, t), ( genArg com ctx r 0 i.GenericArgs)) |> makeValue r |> Some
1806+ | ( " get_Head" | " get_Tail" | " get_IsEmpty" | " get_Length" ), Some x, _ ->
1807+ Helper.LibCall( com, " List" , meth, t, [ x], i.SignatureArgTypes, ?loc= r) |> Some
1808+ // get r t x meth |> Some
1809+ | ( " get_Item" | " GetSlice" ), Some x, _ ->
1810+ Helper.LibCall( com, " List" , meth, t, args @ [ x], i.SignatureArgTypes, ?loc= r) |> Some
1811+ | ( " get_Empty" | " Cons" ), None, _ ->
1812+ Helper.LibCall( com, " List" , meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
18191813 | ( " GetHashCode" | " Equals" | " CompareTo" ), Some callee, _ ->
18201814 Helper.InstanceCall( callee, i.CompiledName, t, args, i.SignatureArgTypes, ?loc= r) |> Some
18211815 | _ -> None
18221816
18231817let listModule ( com : ICompiler ) ( ctx : Context ) r ( t : Type ) ( i : CallInfo ) ( _ : Expr option ) ( args : Expr list ) =
18241818 match i.CompiledName, args with
1825- | " IsEmpty" , [ x] -> Test( x, ListTest false , r) |> Some
1826- | " Empty" , _ -> NewList( None, ( genArg com ctx r 0 i.GenericArgs)) |> makeValue r |> Some
1827- | " Singleton" , [ x] ->
1828- NewList( Some( x, Value( NewList( None, t), None)), ( genArg com ctx r 0 i.GenericArgs)) |> makeValue r |> Some
1819+ // | ("Head" | "Tail" | "IsEmpty") as meth, [x] -> get r t x (Naming.lowerFirst meth) |> Some
1820+ // | "IsEmpty", [x] -> Test(x, ListTest false, r) |> Some
1821+ // | "Empty", _ -> NewList(None, (genArg com ctx r 0 i.GenericArgs)) |> makeValue r |> Some
1822+ // | "Singleton", [x] ->
1823+ // NewList(Some(x, Value(NewList(None, t), None)), (genArg com ctx r 0 i.GenericArgs)) |> makeValue r |> Some
18291824 // Use a cast to give it better chances of optimization (e.g. converting list
18301825 // literals to arrays) after the beta reduction pass
18311826 | " ToSeq" , [ x] -> toSeq t x |> Some
@@ -2612,12 +2607,6 @@ let enumerables (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr
26122607 | Some callee, " GetEnumerator" -> getEnumerator com r t callee |> Some
26132608 | _ -> None
26142609
2615- let enumerators ( com : ICompiler ) ( ctx : Context ) r ( t : Type ) ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
2616- match i.CompiledName, thisArg with
2617- | " get_Current" , Some x -> get r t x " Current" |> Some
2618- | meth, Some x -> Helper.InstanceCall( x, meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
2619- | _ -> None
2620-
26212610let events ( com : ICompiler ) ( ctx : Context ) r ( t : Type ) ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
26222611 match i.CompiledName, thisArg with
26232612 | " .ctor" , _ -> Helper.LibCall( com, " Event" , " default" , t, args, i.SignatureArgTypes, isJsConstructor= true , ?loc= r) |> Some
@@ -2904,11 +2893,6 @@ let private replacedModules =
29042893 Types.ienumerable, enumerables
29052894 " System.Collections.Generic.Dictionary`2.ValueCollection" , enumerables
29062895 " System.Collections.Generic.Dictionary`2.KeyCollection" , enumerables
2907- Types.ienumeratorGeneric, enumerators
2908- " System.Collections.Generic.Dictionary`2.Enumerator" , enumerators
2909- " System.Collections.Generic.Dictionary`2.ValueCollection.Enumerator" , enumerators
2910- " System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator" , enumerators
2911- " System.Collections.Generic.List`1.Enumerator" , enumerators
29122896 Types.resizeArray, resizeArrays
29132897 " System.Collections.Generic.IList`1" , resizeArrays
29142898 " System.Collections.IList" , resizeArrays
@@ -3044,7 +3028,7 @@ let tryBaseConstructor com ctx (ent: Entity) (argTypes: Lazy<Type list>) genArgs
30443028 | [ Number _; IEqualityComparer], [_; eqComp] ->
30453029 [ makeArray Any []; makeComparerFromEqualityComparer eqComp]
30463030 | _ -> failwith " Unexpected dictionary constructor"
3047- let entityName = FSharp2Fable.Helpers.cleanNameAsJsIdentifier " MutableMap`2 "
3031+ let entityName = FSharp2Fable.Helpers.cleanNameAsJsIdentifier " Dictionary "
30483032 Some( makeImportLib com Any entityName " MutableMap" , args)
30493033 | Types.hashset ->
30503034 let args =
@@ -3058,6 +3042,6 @@ let tryBaseConstructor com ctx (ent: Entity) (argTypes: Lazy<Type list>) genArgs
30583042 | [ IEqualityComparer], [ eqComp] ->
30593043 [ makeArray Any []; makeComparerFromEqualityComparer eqComp]
30603044 | _ -> failwith " Unexpected hashset constructor"
3061- let entityName = FSharp2Fable.Helpers.cleanNameAsJsIdentifier " MutableSet`1 "
3045+ let entityName = FSharp2Fable.Helpers.cleanNameAsJsIdentifier " HashSet "
30623046 Some( makeImportLib com Any entityName " MutableSet" , args)
30633047 | _ -> None
0 commit comments