From 1cd73db1ad75ca70646362dacd55ccfd5ccd86b1 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 27 Nov 2024 16:18:54 -0500 Subject: [PATCH 1/5] Emit `ldelem.i8`, `ldelem.i`, etc. --- .../Optimize/LowerComputedCollections.fs | 6 +- .../ForXInArray_ToArray.fs | 8 + .../ForXInArray_ToArray.fs.il.bsl | 250 ++++++++++++++++++ 3 files changed, 260 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 1f224ea499c..35c17f44f5c 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -359,11 +359,9 @@ module List = module Array = let private mkIlInstr (g: TcGlobals) specific any ilTy = if ilTy = g.ilg.typ_Int32 then specific DT_I4 - elif ilTy = g.ilg.typ_Int64 then specific DT_I8 - elif ilTy = g.ilg.typ_UInt64 then specific DT_U8 + elif ilTy = g.ilg.typ_Int64 || ilTy = g.ilg.typ_UInt64 then specific DT_I8 elif ilTy = g.ilg.typ_UInt32 then specific DT_U4 - elif ilTy = g.ilg.typ_IntPtr then specific DT_I - elif ilTy = g.ilg.typ_UIntPtr then specific DT_U + elif ilTy = g.ilg.typ_IntPtr || ilTy = g.ilg.typ_UIntPtr then specific DT_I elif ilTy = g.ilg.typ_Int16 then specific DT_I2 elif ilTy = g.ilg.typ_UInt16 then specific DT_U2 elif ilTy = g.ilg.typ_SByte then specific DT_I1 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs index 1f55bc40d91..d3f9b38bb5a 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs @@ -35,3 +35,11 @@ let ``for Failure _ | _ in ...`` () = [|for Failure _ | _ in [||] do 0|] let ``for true | false in ...`` () = [|for true | false in [||] do 0|] let ``for true | _ in ...`` () = [|for true | _ in [||] do 0|] let ``for _ | true in ...`` () = [|for _ | true in [||] do 0|] + +// https://github.com/dotnet/fsharp/issues/18066 +let ``[|for x in uint64Array -> x|]`` (xs : uint64 array) = [|for x in xs -> x|] +let ``[|for x in uint64Array -> int x|]`` (xs : uint64 array) = [|for x in xs -> int x|] +let ``[|for x in intArray -> uint64 x|]`` (xs : int array) = [|for x in xs -> uint64 x|] +let ``[|for x in unativeintArray -> x|]`` (xs : unativeint array) = [|for x in xs -> x|] +let ``[|for x in unativeintArray -> int x|]`` (xs : unativeint array) = [|for x in xs -> int x|] +let ``[|for x in intArray -> unativeint x|]`` (xs : int array) = [|for x in xs -> unativeint x|] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl index 2e1eeb67e45..8267a7338a6 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl @@ -1798,6 +1798,256 @@ IL_0022: ret } + .method public static uint64[] '[|for x in uint64Array -> x|]'(uint64[] xs) cil managed + { + + .maxstack 6 + .locals init (uint64[] V_0, + uint64[] V_1, + int32 V_2, + uint64 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.UInt64 + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001b + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.i8 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: stelem.i8 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret + } + + .method public static int32[] '[|for x in uint64Array -> int x|]'(uint64[] xs) cil managed + { + + .maxstack 6 + .locals init (uint64[] V_0, + int32[] V_1, + int32 V_2, + uint64 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.Int32 + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001c + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.i8 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: conv.i4 + IL_0017: stelem.i4 + IL_0018: ldloc.2 + IL_0019: ldc.i4.1 + IL_001a: add + IL_001b: stloc.2 + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: ldlen + IL_001f: conv.i4 + IL_0020: blt.s IL_000f + + IL_0022: ldloc.1 + IL_0023: ret + } + + .method public static uint64[] '[|for x in intArray -> uint64 x|]'(int32[] xs) cil managed + { + + .maxstack 6 + .locals init (int32[] V_0, + uint64[] V_1, + int32 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.UInt64 + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001c + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.i4 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: conv.i8 + IL_0017: stelem.i8 + IL_0018: ldloc.2 + IL_0019: ldc.i4.1 + IL_001a: add + IL_001b: stloc.2 + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: ldlen + IL_001f: conv.i4 + IL_0020: blt.s IL_000f + + IL_0022: ldloc.1 + IL_0023: ret + } + + .method public static native uint[] '[|for x in unativeintArray -> x|]'(native uint[] xs) cil managed + { + + .maxstack 6 + .locals init (native uint[] V_0, + native uint[] V_1, + int32 V_2, + native uint V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.UIntPtr + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001b + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.i + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: stelem.i + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret + } + + .method public static int32[] '[|for x in unativeintArray -> int x|]'(native uint[] xs) cil managed + { + + .maxstack 6 + .locals init (native uint[] V_0, + int32[] V_1, + int32 V_2, + native uint V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.Int32 + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001c + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.i + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: conv.i4 + IL_0017: stelem.i4 + IL_0018: ldloc.2 + IL_0019: ldc.i4.1 + IL_001a: add + IL_001b: stloc.2 + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: ldlen + IL_001f: conv.i4 + IL_0020: blt.s IL_000f + + IL_0022: ldloc.1 + IL_0023: ret + } + + .method public static native uint[] '[|for x in intArray -> unativeint x|]'(int32[] xs) cil managed + { + + .maxstack 6 + .locals init (int32[] V_0, + native uint[] V_1, + int32 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.UIntPtr + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001c + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.i4 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: conv.i + IL_0017: stelem.i + IL_0018: ldloc.2 + IL_0019: ldc.i4.1 + IL_001a: add + IL_001b: stloc.2 + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: ldlen + IL_001f: conv.i4 + IL_0020: blt.s IL_000f + + IL_0022: ldloc.1 + IL_0023: ret + } + } .class private abstract auto ansi sealed ''.$assembly From 969eb0a111bfa81edb7a5bc3ce1f2e75179a1491 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 27 Nov 2024 16:26:52 -0500 Subject: [PATCH 2/5] Update release notes --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index 232853cfea5..fd50a84ded4 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -12,6 +12,7 @@ * Add warning when downcasting from nullable type to non-nullable ([PR #17965](https://github.com/dotnet/fsharp/pull/17965)) * Fix missing nullness warning in case of method resolution multiple candidates ([PR #17917](https://github.com/dotnet/fsharp/pull/17918)) * Fix failure to use bound values in `when` clauses of `try-with` in `seq` expressions ([# 17990](https://github.com/dotnet/fsharp/pull/17990)) +* Fix lowering of computed array expressions when the expression consists of a simple mapping from a `uint64` or `unativeint` array. [PR #18081](https://github.com/dotnet/fsharp/pull/18081) ### Added From b6a865871fc85a139c5ac2d325ab8cb5fba30c9a Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 27 Nov 2024 16:36:58 -0500 Subject: [PATCH 3/5] Probably better --- .../ForXInArray_ToArray.fs | 15 +- .../ForXInArray_ToArray.fs.il.bsl | 455 ++++++++++++++---- 2 files changed, 380 insertions(+), 90 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs index d3f9b38bb5a..4d1e3e8c879 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs @@ -37,9 +37,16 @@ let ``for true | _ in ...`` () = [|for true | _ in [||] do 0|] let ``for _ | true in ...`` () = [|for _ | true in [||] do 0|] // https://github.com/dotnet/fsharp/issues/18066 +let ``[|for x in sbyteArray -> x|]`` (xs : sbyte array) = [|for x in xs -> x|] +let ``[|for x in byteArray -> x|]`` (xs : byte array) = [|for x in xs -> x|] +let ``[|for x in int16Array -> x|]`` (xs : int16 array) = [|for x in xs -> x|] +let ``[|for x in uint16Array -> x|]`` (xs : uint16 array) = [|for x in xs -> x|] +let ``[|for x in charArray -> x|]`` (xs : char array) = [|for x in xs -> x|] +let ``[|for x in intArray -> x|]`` (xs : int array) = [|for x in xs -> x|] +let ``[|for x in uintArray -> x|]`` (xs : uint array) = [|for x in xs -> x|] +let ``[|for x in int64Array -> x|]`` (xs : int64 array) = [|for x in xs -> x|] let ``[|for x in uint64Array -> x|]`` (xs : uint64 array) = [|for x in xs -> x|] -let ``[|for x in uint64Array -> int x|]`` (xs : uint64 array) = [|for x in xs -> int x|] -let ``[|for x in intArray -> uint64 x|]`` (xs : int array) = [|for x in xs -> uint64 x|] +let ``[|for x in nativeintArray -> x|]`` (xs : nativeint array) = [|for x in xs -> x|] let ``[|for x in unativeintArray -> x|]`` (xs : unativeint array) = [|for x in xs -> x|] -let ``[|for x in unativeintArray -> int x|]`` (xs : unativeint array) = [|for x in xs -> int x|] -let ``[|for x in intArray -> unativeint x|]`` (xs : int array) = [|for x in xs -> unativeint x|] +let ``[|for x in floatArray -> x|]`` (xs : float array) = [|for x in xs -> x|] +let ``[|for x in float32Array -> x|]`` (xs : float32 array) = [|for x in xs -> x|] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl index 8267a7338a6..7cfc61c36b6 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl @@ -1798,20 +1798,20 @@ IL_0022: ret } - .method public static uint64[] '[|for x in uint64Array -> x|]'(uint64[] xs) cil managed + .method public static int8[] '[|for x in sbyteArray -> x|]'(int8[] xs) cil managed { .maxstack 6 - .locals init (uint64[] V_0, - uint64[] V_1, + .locals init (int8[] V_0, + int8[] V_1, int32 V_2, - uint64 V_3) + int8 V_3) IL_0000: ldarg.0 IL_0001: stloc.0 IL_0002: ldloc.0 IL_0003: ldlen IL_0004: conv.i4 - IL_0005: newarr [runtime]System.UInt64 + IL_0005: newarr [runtime]System.SByte IL_000a: stloc.1 IL_000b: ldc.i4.0 IL_000c: stloc.2 @@ -1821,10 +1821,10 @@ IL_0010: ldloc.2 IL_0011: ldloc.0 IL_0012: ldloc.2 - IL_0013: ldelem.i8 + IL_0013: ldelem.i1 IL_0014: stloc.3 IL_0015: ldloc.3 - IL_0016: stelem.i8 + IL_0016: stelem.i1 IL_0017: ldloc.2 IL_0018: ldc.i4.1 IL_0019: add @@ -1839,14 +1839,178 @@ IL_0022: ret } - .method public static int32[] '[|for x in uint64Array -> int x|]'(uint64[] xs) cil managed + .method public static uint8[] '[|for x in byteArray -> x|]'(uint8[] xs) cil managed { .maxstack 6 - .locals init (uint64[] V_0, + .locals init (uint8[] V_0, + uint8[] V_1, + int32 V_2, + uint8 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.Byte + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001b + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.u1 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: stelem.i1 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret + } + + .method public static int16[] '[|for x in int16Array -> x|]'(int16[] xs) cil managed + { + + .maxstack 6 + .locals init (int16[] V_0, + int16[] V_1, + int32 V_2, + int16 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.Int16 + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001b + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.i2 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: stelem.i2 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret + } + + .method public static uint16[] '[|for x in uint16Array -> x|]'(uint16[] xs) cil managed + { + + .maxstack 6 + .locals init (uint16[] V_0, + uint16[] V_1, + int32 V_2, + uint16 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.UInt16 + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001b + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.u2 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: stelem.i2 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret + } + + .method public static char[] '[|for x in charArray -> x|]'(char[] xs) cil managed + { + + .maxstack 6 + .locals init (char[] V_0, + char[] V_1, + int32 V_2, + char V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.Char + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001b + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.u2 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: stelem.i2 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret + } + + .method public static int32[] '[|for x in intArray -> x|]'(int32[] xs) cil managed + { + + .maxstack 6 + .locals init (int32[] V_0, int32[] V_1, int32 V_2, - uint64 V_3) + int32 V_3) IL_0000: ldarg.0 IL_0001: stloc.0 IL_0002: ldloc.0 @@ -1856,7 +2020,89 @@ IL_000a: stloc.1 IL_000b: ldc.i4.0 IL_000c: stloc.2 - IL_000d: br.s IL_001c + IL_000d: br.s IL_001b + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.i4 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: stelem.i4 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret + } + + .method public static uint32[] '[|for x in uintArray -> x|]'(uint32[] xs) cil managed + { + + .maxstack 6 + .locals init (uint32[] V_0, + uint32[] V_1, + int32 V_2, + uint32 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.UInt32 + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001b + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.u4 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: stelem.i4 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret + } + + .method public static int64[] '[|for x in int64Array -> x|]'(int64[] xs) cil managed + { + + .maxstack 6 + .locals init (int64[] V_0, + int64[] V_1, + int32 V_2, + int64 V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.Int64 + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001b IL_000f: ldloc.1 IL_0010: ldloc.2 @@ -1865,30 +2111,29 @@ IL_0013: ldelem.i8 IL_0014: stloc.3 IL_0015: ldloc.3 - IL_0016: conv.i4 - IL_0017: stelem.i4 - IL_0018: ldloc.2 - IL_0019: ldc.i4.1 - IL_001a: add - IL_001b: stloc.2 - IL_001c: ldloc.2 - IL_001d: ldloc.1 - IL_001e: ldlen - IL_001f: conv.i4 - IL_0020: blt.s IL_000f - - IL_0022: ldloc.1 - IL_0023: ret + IL_0016: stelem.i8 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret } - .method public static uint64[] '[|for x in intArray -> uint64 x|]'(int32[] xs) cil managed + .method public static uint64[] '[|for x in uint64Array -> x|]'(uint64[] xs) cil managed { .maxstack 6 - .locals init (int32[] V_0, + .locals init (uint64[] V_0, uint64[] V_1, int32 V_2, - int32 V_3) + uint64 V_3) IL_0000: ldarg.0 IL_0001: stloc.0 IL_0002: ldloc.0 @@ -1898,29 +2143,69 @@ IL_000a: stloc.1 IL_000b: ldc.i4.0 IL_000c: stloc.2 - IL_000d: br.s IL_001c + IL_000d: br.s IL_001b IL_000f: ldloc.1 IL_0010: ldloc.2 IL_0011: ldloc.0 IL_0012: ldloc.2 - IL_0013: ldelem.i4 + IL_0013: ldelem.i8 + IL_0014: stloc.3 + IL_0015: ldloc.3 + IL_0016: stelem.i8 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret + } + + .method public static native int[] '[|for x in nativeintArray -> x|]'(native int[] xs) cil managed + { + + .maxstack 6 + .locals init (native int[] V_0, + native int[] V_1, + int32 V_2, + native int V_3) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldlen + IL_0004: conv.i4 + IL_0005: newarr [runtime]System.IntPtr + IL_000a: stloc.1 + IL_000b: ldc.i4.0 + IL_000c: stloc.2 + IL_000d: br.s IL_001b + + IL_000f: ldloc.1 + IL_0010: ldloc.2 + IL_0011: ldloc.0 + IL_0012: ldloc.2 + IL_0013: ldelem.i IL_0014: stloc.3 IL_0015: ldloc.3 - IL_0016: conv.i8 - IL_0017: stelem.i8 - IL_0018: ldloc.2 - IL_0019: ldc.i4.1 - IL_001a: add - IL_001b: stloc.2 - IL_001c: ldloc.2 - IL_001d: ldloc.1 - IL_001e: ldlen - IL_001f: conv.i4 - IL_0020: blt.s IL_000f - - IL_0022: ldloc.1 - IL_0023: ret + IL_0016: stelem.i + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret } .method public static native uint[] '[|for x in unativeintArray -> x|]'(native uint[] xs) cil managed @@ -1964,88 +2249,86 @@ IL_0022: ret } - .method public static int32[] '[|for x in unativeintArray -> int x|]'(native uint[] xs) cil managed + .method public static float64[] '[|for x in floatArray -> x|]'(float64[] xs) cil managed { .maxstack 6 - .locals init (native uint[] V_0, - int32[] V_1, + .locals init (float64[] V_0, + float64[] V_1, int32 V_2, - native uint V_3) + float64 V_3) IL_0000: ldarg.0 IL_0001: stloc.0 IL_0002: ldloc.0 IL_0003: ldlen IL_0004: conv.i4 - IL_0005: newarr [runtime]System.Int32 + IL_0005: newarr [runtime]System.Double IL_000a: stloc.1 IL_000b: ldc.i4.0 IL_000c: stloc.2 - IL_000d: br.s IL_001c + IL_000d: br.s IL_001b IL_000f: ldloc.1 IL_0010: ldloc.2 IL_0011: ldloc.0 IL_0012: ldloc.2 - IL_0013: ldelem.i + IL_0013: ldelem.r8 IL_0014: stloc.3 IL_0015: ldloc.3 - IL_0016: conv.i4 - IL_0017: stelem.i4 - IL_0018: ldloc.2 - IL_0019: ldc.i4.1 - IL_001a: add - IL_001b: stloc.2 - IL_001c: ldloc.2 - IL_001d: ldloc.1 - IL_001e: ldlen - IL_001f: conv.i4 - IL_0020: blt.s IL_000f - - IL_0022: ldloc.1 - IL_0023: ret + IL_0016: stelem.r8 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret } - .method public static native uint[] '[|for x in intArray -> unativeint x|]'(int32[] xs) cil managed + .method public static float32[] '[|for x in float32Array -> x|]'(float32[] xs) cil managed { .maxstack 6 - .locals init (int32[] V_0, - native uint[] V_1, + .locals init (float32[] V_0, + float32[] V_1, int32 V_2, - int32 V_3) + float32 V_3) IL_0000: ldarg.0 IL_0001: stloc.0 IL_0002: ldloc.0 IL_0003: ldlen IL_0004: conv.i4 - IL_0005: newarr [runtime]System.UIntPtr + IL_0005: newarr [runtime]System.Single IL_000a: stloc.1 IL_000b: ldc.i4.0 IL_000c: stloc.2 - IL_000d: br.s IL_001c + IL_000d: br.s IL_001b IL_000f: ldloc.1 IL_0010: ldloc.2 IL_0011: ldloc.0 IL_0012: ldloc.2 - IL_0013: ldelem.i4 + IL_0013: ldelem.r4 IL_0014: stloc.3 IL_0015: ldloc.3 - IL_0016: conv.i - IL_0017: stelem.i - IL_0018: ldloc.2 - IL_0019: ldc.i4.1 - IL_001a: add - IL_001b: stloc.2 - IL_001c: ldloc.2 - IL_001d: ldloc.1 - IL_001e: ldlen - IL_001f: conv.i4 - IL_0020: blt.s IL_000f - - IL_0022: ldloc.1 - IL_0023: ret + IL_0016: stelem.r4 + IL_0017: ldloc.2 + IL_0018: ldc.i4.1 + IL_0019: add + IL_001a: stloc.2 + IL_001b: ldloc.2 + IL_001c: ldloc.1 + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: blt.s IL_000f + + IL_0021: ldloc.1 + IL_0022: ret } } From 23eb581165845289986e6978edf7dce8f8504536 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Thu, 28 Nov 2024 10:08:12 -0500 Subject: [PATCH 4/5] Support `ldelem.u8`, `ldelem.u` opcode aliases --- src/Compiler/AbstractIL/ilwrite.fs | 4 ++-- src/Compiler/Optimize/LowerComputedCollections.fs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Compiler/AbstractIL/ilwrite.fs b/src/Compiler/AbstractIL/ilwrite.fs index 3cbdd3c752b..e5183809e1a 100644 --- a/src/Compiler/AbstractIL/ilwrite.fs +++ b/src/Compiler/AbstractIL/ilwrite.fs @@ -2026,11 +2026,11 @@ module Codebuf = | I_ldelem dt -> emitInstrCode codebuf (match dt with - | DT_I -> i_ldelem_i + | DT_I | DT_U -> i_ldelem_i | DT_I1 -> i_ldelem_i1 | DT_I2 -> i_ldelem_i2 | DT_I4 -> i_ldelem_i4 - | DT_I8 -> i_ldelem_i8 + | DT_I8 | DT_U8 -> i_ldelem_i8 | DT_U1 -> i_ldelem_u1 | DT_U2 -> i_ldelem_u2 | DT_U4 -> i_ldelem_u4 diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 35c17f44f5c..1f224ea499c 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -359,9 +359,11 @@ module List = module Array = let private mkIlInstr (g: TcGlobals) specific any ilTy = if ilTy = g.ilg.typ_Int32 then specific DT_I4 - elif ilTy = g.ilg.typ_Int64 || ilTy = g.ilg.typ_UInt64 then specific DT_I8 + elif ilTy = g.ilg.typ_Int64 then specific DT_I8 + elif ilTy = g.ilg.typ_UInt64 then specific DT_U8 elif ilTy = g.ilg.typ_UInt32 then specific DT_U4 - elif ilTy = g.ilg.typ_IntPtr || ilTy = g.ilg.typ_UIntPtr then specific DT_I + elif ilTy = g.ilg.typ_IntPtr then specific DT_I + elif ilTy = g.ilg.typ_UIntPtr then specific DT_U elif ilTy = g.ilg.typ_Int16 then specific DT_I2 elif ilTy = g.ilg.typ_UInt16 then specific DT_U2 elif ilTy = g.ilg.typ_SByte then specific DT_I1 From 6a46cd189454e1e159cdfaa62a4aa2d117869716 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 29 Nov 2024 09:52:19 -0500 Subject: [PATCH 5/5] Fix merge --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index 45d78170e6a..22b160629f3 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -13,7 +13,6 @@ * Fix missing nullness warning in case of method resolution multiple candidates ([PR #17917](https://github.com/dotnet/fsharp/pull/17918)) * Fix failure to use bound values in `when` clauses of `try-with` in `seq` expressions ([PR #17990](https://github.com/dotnet/fsharp/pull/17990)) * Fix locals allocating for the special `copyOfStruct` defensive copy ([PR #18025](https://github.com/dotnet/fsharp/pull/18025)) -* Fix failure to use bound values in `when` clauses of `try-with` in `seq` expressions ([# 17990](https://github.com/dotnet/fsharp/pull/17990)) * Fix lowering of computed array expressions when the expression consists of a simple mapping from a `uint64` or `unativeint` array. [PR #18081](https://github.com/dotnet/fsharp/pull/18081) ### Added