@@ -1372,12 +1372,12 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o
13721372 | _ -> args
13731373 let modul , meth , args =
13741374 match genArg with
1375- | Char -> " Seq " , " rangeChar" , args
1376- | Builtin BclInt64 -> " Seq " , " rangeLong " , ( addStep args) @ [ makeBoolConst false ]
1377- | Builtin BclUInt64 -> " Seq " , " rangeLong " , ( addStep args) @ [ makeBoolConst true ]
1378- | Builtin BclDecimal -> " Seq " , " rangeDecimal" , addStep args
1379- | Builtin BclBigInt -> " BigInt " , " range " , addStep args
1380- | _ -> " Seq " , " rangeNumber " , addStep args
1375+ | Char -> " Range " , " rangeChar" , args
1376+ | Builtin BclInt64 -> " Range " , " rangeInt64 " , addStep args
1377+ | Builtin BclUInt64 -> " Range " , " rangeUInt64 " , addStep args
1378+ | Builtin BclDecimal -> " Range " , " rangeDecimal" , addStep args
1379+ | Builtin BclBigInt -> " Range " , " rangeBigInt " , addStep args
1380+ | _ -> " Range " , " rangeDouble " , addStep args
13811381 Helper.LibCall( com, modul, meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
13821382 // Pipes and composition
13831383 | " op_PipeRight" , [ x; f]
@@ -1542,7 +1542,7 @@ let implementedStringFunctions =
15421542 |]
15431543
15441544let getEnumerator com r t expr =
1545- Helper.LibCall( com, " Seq " , " getEnumerator" , t, [ toSeq Any expr], ?loc= r)
1545+ Helper.LibCall( com, " Util " , " getEnumerator" , t, [ toSeq Any expr], ?loc= r)
15461546
15471547let strings ( com : ICompiler ) ( ctx : Context ) r t ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
15481548 match i.CompiledName, thisArg, args with
@@ -1660,51 +1660,13 @@ let stringModule (com: ICompiler) (ctx: Context) r t (i: CallInfo) (_: Expr opti
16601660 | meth, args ->
16611661 Helper.LibCall( com, " String" , Naming.lowerFirst meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
16621662
1663- let seqs ( com : ICompiler ) ( ctx : Context ) r ( t : Type ) ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
1664- let sort r returnType descending projection args genArg =
1665- let compareFn =
1666- let identExpr ident =
1667- match projection with
1668- | Some projection ->
1669- let info = makeCallInfo None [ IdentExpr ident] []
1670- Call( projection, info, genArg, None)
1671- | None -> IdentExpr ident
1672- let x = makeUniqueIdent ctx genArg " x"
1673- let y = makeUniqueIdent ctx genArg " y"
1674- let comparison =
1675- let comparison = compare com ctx None ( identExpr x) ( identExpr y)
1676- if descending
1677- then makeUnOp None ( Number Int32) comparison UnaryMinus
1678- else comparison
1679- Delegate([ x; y], comparison, None)
1680- Helper.LibCall( com, " Seq" , " sortWith" , returnType, compareFn:: args, ?loc= r) |> Some
1681-
1663+ let seqModule ( com : ICompiler ) ( ctx : Context ) r ( t : Type ) ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
16821664 match i.CompiledName, args with
16831665 | " Cast" , [ arg] -> Some arg // Erase
1684- | ( " Cache" | " ToArray" ), [ arg] -> toArray r t arg |> Some
1685- | " OfList" , [ arg] -> toSeq t arg |> Some
1686- | " ToList" , _ -> Helper.LibCall( com, " List" , " ofSeq" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
1687- | ( " ChunkBySize" | " Permute" | " SplitInto" ) as meth, [ arg1; arg2] ->
1688- let arg2 = toArray r ( Array Any) arg2
1689- let result = Helper.LibCall( com, " Array" , Naming.lowerFirst meth, Any, [ arg1; arg2])
1690- Helper.LibCall( com, " Seq" , " ofArray" , t, [ result]) |> Some
1691- // For Using we need to cast the argument to IDisposable
1692- | " EnumerateUsing" , [ arg; f] ->
1693- Helper.LibCall( com, " Seq" , " enumerateUsing" , t, [ arg; f], i.SignatureArgTypes, ?loc= r) |> Some
1694- | ( " Sort" | " SortDescending" as meth), args ->
1695- ( genArg com ctx r 0 i.GenericArgs) |> sort r t ( meth = " SortDescending" ) None args
1696- | ( " SortBy" | " SortByDescending" as meth), projection:: args ->
1697- ( genArg com ctx r 1 i.GenericArgs) |> sort r t ( meth = " SortByDescending" ) ( Some projection) args
1698- | ( " GroupBy" | " CountBy" as meth), args ->
1699- let meth = Naming.lowerFirst meth
1700- let args = injectArg com ctx r " Map" meth i.GenericArgs args
1701- Helper.LibCall( com, " Map" , meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
1702- | ( " Distinct" | " DistinctBy" as meth), args ->
1666+ | ( " Distinct" | " DistinctBy" | " Except" | " GroupBy" | " CountBy" as meth), args ->
17031667 let meth = Naming.lowerFirst meth
1704- let args = injectArg com ctx r " Set" meth i.GenericArgs args
1705- Helper.LibCall( com, " Set" , meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
1706- | " TryExactlyOne" , args ->
1707- tryCoreOp com r t " Seq" " exactlyOne" args |> Some
1668+ let args = injectArg com ctx r " Seq2" meth i.GenericArgs args
1669+ Helper.LibCall( com, " Seq2" , meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
17081670 | meth, _ ->
17091671 let meth = Naming.lowerFirst meth
17101672 let args = injectArg com ctx r " Seq" meth i.GenericArgs args
@@ -1749,16 +1711,16 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this
17491711 | " Clear" , Some ar, _ ->
17501712 Helper.LibCall( com, " Util" , " clear" , t, [ ar], ?loc= r) |> Some
17511713 | " Find" , Some ar, [ arg] ->
1752- let opt = Helper.LibCall( com, " Seq " , " tryFind" , t, [ arg; ar; defaultof com ctx t ], ?loc= r)
1753- Helper.LibCall( com, " Option" , " value " , t, [ opt], ?loc= r) |> Some
1714+ let opt = Helper.LibCall( com, " Array " , " tryFind" , t, [ arg; ar], ?loc= r)
1715+ Helper.LibCall( com, " Option" , " defaultArg " , t, [ opt; defaultof com ctx t ], ?loc= r) |> Some
17541716 | " Exists" , Some ar, [ arg] ->
17551717 let left = Helper.InstanceCall( ar, " findIndex" , Number Int32, [ arg], ?loc= r)
17561718 makeEqOp r left ( makeIntConst - 1 ) BinaryGreater |> Some
17571719 | " FindLast" , Some ar, [ arg] ->
1758- let opt = Helper.LibCall( com, " Seq " , " tryFindBack" , t, [ arg; ar; defaultof com ctx t ], ?loc= r)
1759- Helper.LibCall( com, " Option" , " value " , t, [ opt], ?loc= r) |> Some
1720+ let opt = Helper.LibCall( com, " Array " , " tryFindBack" , t, [ arg; ar], ?loc= r)
1721+ Helper.LibCall( com, " Option" , " defaultArg " , t, [ opt; defaultof com ctx t ], ?loc= r) |> Some
17601722 | " FindAll" , Some ar, [ arg] ->
1761- Helper.LibCall( com, " Seq " , " filter" , t, [ arg; ar], ?loc= r) |> toArray r t |> Some
1723+ Helper.LibCall( com, " Array " , " filter" , t, [ arg; ar], ?loc= r) |> Some
17621724 | " AddRange" , Some ar, [ arg] ->
17631725 Helper.LibCall( com, " Array" , " addRangeInPlace" , t, [ arg; ar], ?loc= r) |> Some
17641726 | " GetRange" , Some ar, [ idx; cnt] ->
@@ -1845,8 +1807,10 @@ let arrayModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (_: Ex
18451807 match i.CompiledName, args with
18461808 | " ToSeq" , [ arg] -> Some arg
18471809 | " OfSeq" , [ arg] -> toArray r t arg |> Some
1848- | " OfList" , [ arg] -> toArray r t arg |> Some
1849- | " ToList" , _ -> Helper.LibCall( com, " List" , " ofArray" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
1810+ | " OfList" , [ arg] ->
1811+ Helper.LibCall( com, " List" , " toArray" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
1812+ | " ToList" , args ->
1813+ Helper.LibCall( com, " List" , " ofArray" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
18501814 | ( " Length" | " Count" ), [ arg] -> get r t arg " length" |> Some
18511815 | " Item" , [ idx; ar] -> getExpr r t ar idx |> Some
18521816 | " Get" , [ ar; idx] -> getExpr r t ar idx |> Some
@@ -1858,22 +1822,16 @@ let arrayModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (_: Ex
18581822 newArray ( makeIntConst 0 ) t |> Some
18591823 | " IsEmpty" , [ ar] ->
18601824 eq ( get r ( Number Int32) ar " length" ) ( makeIntConst 0 ) |> Some
1861- | " AllPairs" , args ->
1862- let allPairs = Helper.LibCall( com, " Seq" , " allPairs" , t, args, i.SignatureArgTypes, ?loc= r)
1863- toArray r t allPairs |> Some
1864- | " TryExactlyOne" , args ->
1865- tryCoreOp com r t " Array" " exactlyOne" args |> Some
1866- | " SortInPlace" , args ->
1867- let _ , thisArg = List.splitLast args
1868- let argTypes = List.take ( List.length args) i.SignatureArgTypes
1869- let compareFn = ( genArg com ctx r 0 i.GenericArgs) |> makeComparerFunction com ctx
1870- Helper.InstanceCall( thisArg, " sort" , t, [ compareFn], argTypes, ?loc= r) |> Some
18711825 | " CopyTo" , args ->
18721826 copyToArray com r t i args
18731827 | Patterns.DicContains nativeArrayFunctions meth, _ ->
18741828 let args , thisArg = List.splitLast args
18751829 let argTypes = List.take ( List.length args) i.SignatureArgTypes
18761830 Helper.InstanceCall( thisArg, meth, t, args, argTypes, ?loc= r) |> Some
1831+ | ( " Distinct" | " DistinctBy" | " Except" | " GroupBy" | " CountBy" as meth), args ->
1832+ let meth = Naming.lowerFirst meth
1833+ let args = injectArg com ctx r " Seq2" meth i.GenericArgs args
1834+ Helper.LibCall( com, " Seq2" , " Array_" + meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
18771835 | meth, _ ->
18781836 let meth = Naming.lowerFirst meth
18791837 let args = injectArg com ctx r " Array" meth i.GenericArgs args
@@ -1906,12 +1864,10 @@ let listModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (_: Exp
19061864 // Use a cast to give it better chances of optimization (e.g. converting list
19071865 // literals to arrays) after the beta reduction pass
19081866 | " ToSeq" , [ x] -> toSeq t x |> Some
1909- | " ToArray" , [ x] -> toArray r t x |> Some
1910- | " AllPairs" , args ->
1911- let allPairs = Helper.LibCall( com, " Seq" , " allPairs" , t, args, i.SignatureArgTypes, ?loc= r)
1912- toList com t allPairs |> Some
1913- | " TryExactlyOne" , args ->
1914- tryCoreOp com r t " List" " exactlyOne" args |> Some
1867+ | ( " Distinct" | " DistinctBy" | " Except" | " GroupBy" | " CountBy" as meth), args ->
1868+ let meth = Naming.lowerFirst meth
1869+ let args = injectArg com ctx r " Seq2" meth i.GenericArgs args
1870+ Helper.LibCall( com, " Seq2" , " List_" + meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
19151871 | meth, _ ->
19161872 let meth = Naming.lowerFirst meth
19171873 let args = injectArg com ctx r " List" meth i.GenericArgs args
@@ -1989,19 +1945,20 @@ let optionModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (_: E
19891945 Helper.LibCall( com, " Option" , Naming.lowerFirst meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
19901946 | " ToArray" , [ arg] ->
19911947 toArray r t arg |> Some
1948+ | " ToList" , [ arg] ->
1949+ let args = args |> List.replaceLast ( toArray None t)
1950+ Helper.LibCall( com, " List" , " ofArray" , t, args, ?loc= r) |> Some
19921951 | " FoldBack" , [ folder; opt; state] ->
19931952 Helper.LibCall( com, " Seq" , " foldBack" , t, [ folder; toArray None t opt; state], i.SignatureArgTypes, ?loc= r) |> Some
19941953 | ( " DefaultValue" | " OrElse" ), _ ->
19951954 Helper.LibCall( com, " Option" , " defaultArg" , t, List.rev args, ?loc= r) |> Some
19961955 | ( " DefaultWith" | " OrElseWith" ), _ ->
19971956 Helper.LibCall( com, " Option" , " defaultArgWith" , t, List.rev args, List.rev i.SignatureArgTypes, ?loc= r) |> Some
1998- | ( " Count" | " Contains" | " Exists" | " Fold" | " ForAll" | " Iterate" | " ToList" as meth), _ ->
1957+ | ( " Count" | " Contains" | " Exists" | " Fold" | " ForAll" | " Iterate" as meth), _ ->
1958+ let meth = Naming.lowerFirst meth
19991959 let args = args |> List.replaceLast ( toArray None t)
2000- let moduleName , meth =
2001- if meth = " ToList"
2002- then " List" , " ofArray"
2003- else " Seq" , Naming.lowerFirst meth
2004- Helper.LibCall( com, moduleName, meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
1960+ let args = injectArg com ctx r " Seq" meth i.GenericArgs args
1961+ Helper.LibCall( com, " Seq" , meth, t, args, i.SignatureArgTypes, ?loc= r) |> Some
20051962 | _ -> None
20061963
20071964let parseBool ( com : ICompiler ) ( ctx : Context ) r t ( i : CallInfo ) ( thisArg : Expr option ) ( args : Expr list ) =
@@ -2266,18 +2223,19 @@ let intrinsicFunctions (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr
22662223 // Type: RangeChar : char -> char -> seq<char>
22672224 // Usage: RangeChar start stop
22682225 | " RangeChar" , None, _ ->
2269- Helper.LibCall( com, " Seq " , " rangeChar" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
2226+ Helper.LibCall( com, " Range " , " rangeChar" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
22702227 // reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangedouble-function-%5bfsharp%5d
22712228 // Type: RangeDouble: float -> float -> float -> seq<float>
22722229 // Usage: RangeDouble start step stop
22732230 | ( " RangeSByte" | " RangeByte"
22742231 | " RangeInt16" | " RangeUInt16"
22752232 | " RangeInt32" | " RangeUInt32"
22762233 | " RangeSingle" | " RangeDouble" ), None, args ->
2277- Helper.LibCall( com, " Seq" , " rangeNumber" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
2278- | ( " RangeInt64" | " RangeUInt64" ), None, args ->
2279- let isUnsigned = makeBoolConst ( i.CompiledName = " RangeUInt64" )
2280- Helper.LibCall( com, " Seq" , " rangeLong" , t, args @ [ isUnsigned] , i.SignatureArgTypes, ?loc= r) |> Some
2234+ Helper.LibCall( com, " Range" , " rangeDouble" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
2235+ | " RangeInt64" , None, args ->
2236+ Helper.LibCall( com, " Range" , " rangeInt64" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
2237+ | " RangeUInt64" , None, args ->
2238+ Helper.LibCall( com, " Range" , " rangeUInt64" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
22812239 | _ -> None
22822240
22832241let runtimeHelpers ( com : ICompiler ) ( ctx : Context ) r t ( i : CallInfo ) thisArg args =
@@ -3061,8 +3019,8 @@ let private replacedModules =
30613019 " Microsoft.FSharp.Collections.ListModule" , listModule
30623020 " Microsoft.FSharp.Collections.HashIdentity" , fsharpModule
30633021 " Microsoft.FSharp.Collections.ComparisonIdentity" , fsharpModule
3064- " Microsoft.FSharp.Core.CompilerServices.RuntimeHelpers" , seqs
3065- " Microsoft.FSharp.Collections.SeqModule" , seqs
3022+ " Microsoft.FSharp.Core.CompilerServices.RuntimeHelpers" , seqModule
3023+ " Microsoft.FSharp.Collections.SeqModule" , seqModule
30663024 " System.Collections.Generic.KeyValuePair`2" , keyValuePairs
30673025 " System.Collections.Generic.Comparer`1" , bclType
30683026 " System.Collections.Generic.EqualityComparer`1" , bclType
0 commit comments