From fa0c3b897dfd39201f4be6a1d03169d6725495cf Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 12 Apr 2024 10:49:18 -0400 Subject: [PATCH 1/3] Use alternative way of ignoring measures * Use `typeEquivAux EraseMeasures` instead of calling `stripMeasuresFromTy` and passing the result into `typeEquiv` when determining whether the range operator's type argument is an integral type. I would have expected the outcome to be the same for both approaches, but that appears not always to be the case (though it often is). --- src/Compiler/TypedTree/TypedTreeOps.fs | 58 +- .../ForEachRangeStep_UnitsOfMeasure.fs | 47 ++ ...EachRangeStep_UnitsOfMeasure.fs.opt.il.bsl | 637 +++++++++++++++++ .../RealInternalSignatureOff/ForLoop.fs | 7 + .../ForEachRangeStep_UnitsOfMeasure.fs | 47 ++ ...EachRangeStep_UnitsOfMeasure.fs.opt.il.bsl | 656 ++++++++++++++++++ .../RealInternalSignatureOn/ForLoop.fs | 7 + 7 files changed, 1429 insertions(+), 30 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForEachRangeStep_UnitsOfMeasure.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForEachRangeStep_UnitsOfMeasure.fs.opt.il.bsl create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForEachRangeStep_UnitsOfMeasure.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForEachRangeStep_UnitsOfMeasure.fs.opt.il.bsl diff --git a/src/Compiler/TypedTree/TypedTreeOps.fs b/src/Compiler/TypedTree/TypedTreeOps.fs index 0a2642a002f..92c1e7355be 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.fs @@ -7417,39 +7417,37 @@ let mkTwo g m = mkInt g m 2 let mkMinusOne g m = mkInt g m -1 let mkTypedZero g m ty = - let underlyingTy = stripMeasuresFromTy g ty - if typeEquiv g underlyingTy g.int32_ty then Expr.Const (Const.Int32 0, m, ty) - elif typeEquiv g underlyingTy g.int64_ty then Expr.Const (Const.Int64 0L, m, ty) - elif typeEquiv g underlyingTy g.uint64_ty then Expr.Const (Const.UInt64 0UL, m, ty) - elif typeEquiv g underlyingTy g.uint32_ty then Expr.Const (Const.UInt32 0u, m, ty) - elif typeEquiv g underlyingTy g.nativeint_ty then Expr.Const (Const.IntPtr 0L, m, ty) - elif typeEquiv g underlyingTy g.unativeint_ty then Expr.Const (Const.UIntPtr 0UL, m, ty) - elif typeEquiv g underlyingTy g.int16_ty then Expr.Const (Const.Int16 0s, m, ty) - elif typeEquiv g underlyingTy g.uint16_ty then Expr.Const (Const.UInt16 0us, m, ty) - elif typeEquiv g underlyingTy g.sbyte_ty then Expr.Const (Const.SByte 0y, m, ty) - elif typeEquiv g underlyingTy g.byte_ty then Expr.Const (Const.Byte 0uy, m, ty) - elif typeEquiv g underlyingTy g.char_ty then Expr.Const (Const.Char '\000', m, ty) - elif typeEquiv g underlyingTy g.float32_ty then Expr.Const (Const.Single 0.0f, m, ty) - elif typeEquiv g underlyingTy g.float_ty then Expr.Const (Const.Double 0.0, m, ty) - elif typeEquiv g underlyingTy g.decimal_ty then Expr.Const (Const.Decimal 0m, m, ty) + if typeEquivAux EraseMeasures g ty g.int32_ty then Expr.Const (Const.Int32 0, m, ty) + elif typeEquivAux EraseMeasures g ty g.int64_ty then Expr.Const (Const.Int64 0L, m, ty) + elif typeEquivAux EraseMeasures g ty g.uint64_ty then Expr.Const (Const.UInt64 0UL, m, ty) + elif typeEquivAux EraseMeasures g ty g.uint32_ty then Expr.Const (Const.UInt32 0u, m, ty) + elif typeEquivAux EraseMeasures g ty g.nativeint_ty then Expr.Const (Const.IntPtr 0L, m, ty) + elif typeEquivAux EraseMeasures g ty g.unativeint_ty then Expr.Const (Const.UIntPtr 0UL, m, ty) + elif typeEquivAux EraseMeasures g ty g.int16_ty then Expr.Const (Const.Int16 0s, m, ty) + elif typeEquivAux EraseMeasures g ty g.uint16_ty then Expr.Const (Const.UInt16 0us, m, ty) + elif typeEquivAux EraseMeasures g ty g.sbyte_ty then Expr.Const (Const.SByte 0y, m, ty) + elif typeEquivAux EraseMeasures g ty g.byte_ty then Expr.Const (Const.Byte 0uy, m, ty) + elif typeEquivAux EraseMeasures g ty g.char_ty then Expr.Const (Const.Char '\000', m, ty) + elif typeEquivAux EraseMeasures g ty g.float32_ty then Expr.Const (Const.Single 0.0f, m, ty) + elif typeEquivAux EraseMeasures g ty g.float_ty then Expr.Const (Const.Double 0.0, m, ty) + elif typeEquivAux EraseMeasures g ty g.decimal_ty then Expr.Const (Const.Decimal 0m, m, ty) else error (InternalError ($"Unrecognized numeric type '{ty}'.", m)) let mkTypedOne g m ty = - let underlyingTy = stripMeasuresFromTy g ty - if typeEquiv g underlyingTy g.int32_ty then Expr.Const (Const.Int32 1, m, ty) - elif typeEquiv g underlyingTy g.int64_ty then Expr.Const (Const.Int64 1L, m, ty) - elif typeEquiv g underlyingTy g.uint64_ty then Expr.Const (Const.UInt64 1UL, m, ty) - elif typeEquiv g underlyingTy g.uint32_ty then Expr.Const (Const.UInt32 1u, m, ty) - elif typeEquiv g underlyingTy g.nativeint_ty then Expr.Const (Const.IntPtr 1L, m, ty) - elif typeEquiv g underlyingTy g.unativeint_ty then Expr.Const (Const.UIntPtr 1UL, m, ty) - elif typeEquiv g underlyingTy g.int16_ty then Expr.Const (Const.Int16 1s, m, ty) - elif typeEquiv g underlyingTy g.uint16_ty then Expr.Const (Const.UInt16 1us, m, ty) - elif typeEquiv g underlyingTy g.sbyte_ty then Expr.Const (Const.SByte 1y, m, ty) - elif typeEquiv g underlyingTy g.byte_ty then Expr.Const (Const.Byte 1uy, m, ty) - elif typeEquiv g underlyingTy g.char_ty then Expr.Const (Const.Char '\001', m, ty) - elif typeEquiv g underlyingTy g.float32_ty then Expr.Const (Const.Single 1.0f, m, ty) - elif typeEquiv g underlyingTy g.float_ty then Expr.Const (Const.Double 1.0, m, ty) - elif typeEquiv g underlyingTy g.decimal_ty then Expr.Const (Const.Decimal 1m, m, ty) + if typeEquivAux EraseMeasures g ty g.int32_ty then Expr.Const (Const.Int32 1, m, ty) + elif typeEquivAux EraseMeasures g ty g.int64_ty then Expr.Const (Const.Int64 1L, m, ty) + elif typeEquivAux EraseMeasures g ty g.uint64_ty then Expr.Const (Const.UInt64 1UL, m, ty) + elif typeEquivAux EraseMeasures g ty g.uint32_ty then Expr.Const (Const.UInt32 1u, m, ty) + elif typeEquivAux EraseMeasures g ty g.nativeint_ty then Expr.Const (Const.IntPtr 1L, m, ty) + elif typeEquivAux EraseMeasures g ty g.unativeint_ty then Expr.Const (Const.UIntPtr 1UL, m, ty) + elif typeEquivAux EraseMeasures g ty g.int16_ty then Expr.Const (Const.Int16 1s, m, ty) + elif typeEquivAux EraseMeasures g ty g.uint16_ty then Expr.Const (Const.UInt16 1us, m, ty) + elif typeEquivAux EraseMeasures g ty g.sbyte_ty then Expr.Const (Const.SByte 1y, m, ty) + elif typeEquivAux EraseMeasures g ty g.byte_ty then Expr.Const (Const.Byte 1uy, m, ty) + elif typeEquivAux EraseMeasures g ty g.char_ty then Expr.Const (Const.Char '\001', m, ty) + elif typeEquivAux EraseMeasures g ty g.float32_ty then Expr.Const (Const.Single 1.0f, m, ty) + elif typeEquivAux EraseMeasures g ty g.float_ty then Expr.Const (Const.Double 1.0, m, ty) + elif typeEquivAux EraseMeasures g ty g.decimal_ty then Expr.Const (Const.Decimal 1m, m, ty) else error (InternalError ($"Unrecognized numeric type '{ty}'.", m)) let destInt32 = function Expr.Const (Const.Int32 n, _, _) -> Some n | _ -> None diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForEachRangeStep_UnitsOfMeasure.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForEachRangeStep_UnitsOfMeasure.fs new file mode 100644 index 00000000000..a142d0f5e00 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForEachRangeStep_UnitsOfMeasure.fs @@ -0,0 +1,47 @@ +open FSharp.Data.UnitSystems.SI.UnitSymbols + +let mutable c = 0L + +let f1 () = + for n in 10L..1L..1L do + c <- n + +let f2 () = + for n in 1L..1L..10L do + c <- n + +let f3 () = + for n in 1L..2L..10L do + c <- n + +let f4 start = + for n in start..2L..10L do + c <- n + +let f5 step = + for n in 1L..step..10L do + c <- n + +let f6 finish = + for n in 1L..2L..finish do + c <- n + +let f7 start step finish = + for n in start..step..finish do + c <- n + +let f8 start finish = + for n in start..0L..finish do + c <- n + +let f9 () = + for n in 1L..0L..10L do + c <- n + +let f10 () = + for n in 10L .. -1L..1L do + c <- n + +let f11 () = + for n in 10L .. -2L..1L do + c <- n diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForEachRangeStep_UnitsOfMeasure.fs.opt.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForEachRangeStep_UnitsOfMeasure.fs.opt.il.bsl new file mode 100644 index 00000000000..c47ef1b4a90 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForEachRangeStep_UnitsOfMeasure.fs.opt.il.bsl @@ -0,0 +1,637 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public specialname static int64 get_c() cil managed + { + + .maxstack 8 + IL_0000: ldsfld int64 ''.$assembly::c@3 + IL_0005: ret + } + + .method public specialname static void set_c(int64 'value') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: stsfld int64 ''.$assembly::c@3 + IL_0006: ret + } + + .method public static void f1() cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stloc.0 + IL_0003: ldc.i4.s 10 + IL_0005: conv.i8 + IL_0006: stloc.1 + IL_0007: br.s IL_0019 + + IL_0009: ldloc.1 + IL_000a: call void assembly::set_c(int64) + IL_000f: ldloc.1 + IL_0010: ldc.i4.1 + IL_0011: conv.i8 + IL_0012: add + IL_0013: stloc.1 + IL_0014: ldloc.0 + IL_0015: ldc.i4.1 + IL_0016: conv.i8 + IL_0017: add + IL_0018: stloc.0 + IL_0019: ldloc.0 + IL_001a: ldc.i4.0 + IL_001b: conv.i8 + IL_001c: blt.un.s IL_0009 + + IL_001e: ret + } + + .method public static void f2() cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stloc.0 + IL_0003: ldc.i4.1 + IL_0004: conv.i8 + IL_0005: stloc.1 + IL_0006: br.s IL_0018 + + IL_0008: ldloc.1 + IL_0009: call void assembly::set_c(int64) + IL_000e: ldloc.1 + IL_000f: ldc.i4.1 + IL_0010: conv.i8 + IL_0011: add + IL_0012: stloc.1 + IL_0013: ldloc.0 + IL_0014: ldc.i4.1 + IL_0015: conv.i8 + IL_0016: add + IL_0017: stloc.0 + IL_0018: ldloc.0 + IL_0019: ldc.i4.s 10 + IL_001b: conv.i8 + IL_001c: blt.un.s IL_0008 + + IL_001e: ret + } + + .method public static void f3() cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stloc.0 + IL_0003: ldc.i4.1 + IL_0004: conv.i8 + IL_0005: stloc.1 + IL_0006: br.s IL_0018 + + IL_0008: ldloc.1 + IL_0009: call void assembly::set_c(int64) + IL_000e: ldloc.1 + IL_000f: ldc.i4.2 + IL_0010: conv.i8 + IL_0011: add + IL_0012: stloc.1 + IL_0013: ldloc.0 + IL_0014: ldc.i4.1 + IL_0015: conv.i8 + IL_0016: add + IL_0017: stloc.0 + IL_0018: ldloc.0 + IL_0019: ldc.i4.5 + IL_001a: conv.i8 + IL_001b: blt.un.s IL_0008 + + IL_001d: ret + } + + .method public static void f4(int64 start) cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldc.i4.s 10 + IL_0002: conv.i8 + IL_0003: ldarg.0 + IL_0004: bge.s IL_000b + + IL_0006: ldc.i4.0 + IL_0007: conv.i8 + IL_0008: nop + IL_0009: br.s IL_0017 + + IL_000b: ldc.i4.s 10 + IL_000d: conv.i8 + IL_000e: ldarg.0 + IL_000f: sub + IL_0010: ldc.i4.2 + IL_0011: conv.i8 + IL_0012: div.un + IL_0013: ldc.i4.1 + IL_0014: conv.i8 + IL_0015: add + IL_0016: nop + IL_0017: stloc.0 + IL_0018: ldc.i4.0 + IL_0019: conv.i8 + IL_001a: stloc.1 + IL_001b: ldarg.0 + IL_001c: stloc.2 + IL_001d: br.s IL_002f + + IL_001f: ldloc.2 + IL_0020: call void assembly::set_c(int64) + IL_0025: ldloc.2 + IL_0026: ldc.i4.2 + IL_0027: conv.i8 + IL_0028: add + IL_0029: stloc.2 + IL_002a: ldloc.1 + IL_002b: ldc.i4.1 + IL_002c: conv.i8 + IL_002d: add + IL_002e: stloc.1 + IL_002f: ldloc.1 + IL_0030: ldloc.0 + IL_0031: blt.un.s IL_001f + + IL_0033: ret + } + + .method public static void f5(int64 step) cil managed + { + + .maxstack 5 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldarg.0 + IL_0001: brtrue.s IL_0012 + + IL_0003: ldc.i4.1 + IL_0004: conv.i8 + IL_0005: ldarg.0 + IL_0006: ldc.i4.s 10 + IL_0008: conv.i8 + IL_0009: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_000e: pop + IL_000f: nop + IL_0010: br.s IL_0013 + + IL_0012: nop + IL_0013: ldc.i4.0 + IL_0014: conv.i8 + IL_0015: ldarg.0 + IL_0016: bge.s IL_0023 + + IL_0018: ldc.i4.s 9 + IL_001a: conv.i8 + IL_001b: ldarg.0 + IL_001c: div.un + IL_001d: ldc.i4.1 + IL_001e: conv.i8 + IL_001f: add + IL_0020: nop + IL_0021: br.s IL_0026 + + IL_0023: ldc.i4.0 + IL_0024: conv.i8 + IL_0025: nop + IL_0026: stloc.0 + IL_0027: ldc.i4.0 + IL_0028: conv.i8 + IL_0029: stloc.1 + IL_002a: ldc.i4.1 + IL_002b: conv.i8 + IL_002c: stloc.2 + IL_002d: br.s IL_003e + + IL_002f: ldloc.2 + IL_0030: call void assembly::set_c(int64) + IL_0035: ldloc.2 + IL_0036: ldarg.0 + IL_0037: add + IL_0038: stloc.2 + IL_0039: ldloc.1 + IL_003a: ldc.i4.1 + IL_003b: conv.i8 + IL_003c: add + IL_003d: stloc.1 + IL_003e: ldloc.1 + IL_003f: ldloc.0 + IL_0040: blt.un.s IL_002f + + IL_0042: ret + } + + .method public static void f6(int64 finish) cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldarg.0 + IL_0001: ldc.i4.1 + IL_0002: conv.i8 + IL_0003: bge.s IL_000a + + IL_0005: ldc.i4.0 + IL_0006: conv.i8 + IL_0007: nop + IL_0008: br.s IL_0015 + + IL_000a: ldarg.0 + IL_000b: ldc.i4.1 + IL_000c: conv.i8 + IL_000d: sub + IL_000e: ldc.i4.2 + IL_000f: conv.i8 + IL_0010: div.un + IL_0011: ldc.i4.1 + IL_0012: conv.i8 + IL_0013: add + IL_0014: nop + IL_0015: stloc.0 + IL_0016: ldc.i4.0 + IL_0017: conv.i8 + IL_0018: stloc.1 + IL_0019: ldc.i4.1 + IL_001a: conv.i8 + IL_001b: stloc.2 + IL_001c: br.s IL_002e + + IL_001e: ldloc.2 + IL_001f: call void assembly::set_c(int64) + IL_0024: ldloc.2 + IL_0025: ldc.i4.2 + IL_0026: conv.i8 + IL_0027: add + IL_0028: stloc.2 + IL_0029: ldloc.1 + IL_002a: ldc.i4.1 + IL_002b: conv.i8 + IL_002c: add + IL_002d: stloc.1 + IL_002e: ldloc.1 + IL_002f: ldloc.0 + IL_0030: blt.un.s IL_001e + + IL_0032: ret + } + + .method public static void f7(int64 start, + int64 step, + int64 finish) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_000f + + IL_0003: ldarg.0 + IL_0004: ldarg.1 + IL_0005: ldarg.2 + IL_0006: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_000b: pop + IL_000c: nop + IL_000d: br.s IL_0010 + + IL_000f: nop + IL_0010: ldc.i4.0 + IL_0011: conv.i8 + IL_0012: ldarg.1 + IL_0013: bge.s IL_0029 + + IL_0015: ldarg.2 + IL_0016: ldarg.0 + IL_0017: bge.s IL_001e + + IL_0019: ldc.i4.0 + IL_001a: conv.i8 + IL_001b: nop + IL_001c: br.s IL_003f + + IL_001e: ldarg.2 + IL_001f: ldarg.0 + IL_0020: sub + IL_0021: ldarg.1 + IL_0022: div.un + IL_0023: ldc.i4.1 + IL_0024: conv.i8 + IL_0025: add + IL_0026: nop + IL_0027: br.s IL_003f + + IL_0029: ldarg.0 + IL_002a: ldarg.2 + IL_002b: bge.s IL_0032 + + IL_002d: ldc.i4.0 + IL_002e: conv.i8 + IL_002f: nop + IL_0030: br.s IL_003f + + IL_0032: ldarg.0 + IL_0033: ldarg.2 + IL_0034: sub + IL_0035: ldarg.1 + IL_0036: not + IL_0037: ldc.i4.1 + IL_0038: conv.i8 + IL_0039: add + IL_003a: div.un + IL_003b: ldc.i4.1 + IL_003c: conv.i8 + IL_003d: add + IL_003e: nop + IL_003f: stloc.0 + IL_0040: ldc.i4.0 + IL_0041: conv.i8 + IL_0042: stloc.1 + IL_0043: ldarg.0 + IL_0044: stloc.2 + IL_0045: br.s IL_0056 + + IL_0047: ldloc.2 + IL_0048: call void assembly::set_c(int64) + IL_004d: ldloc.2 + IL_004e: ldarg.1 + IL_004f: add + IL_0050: stloc.2 + IL_0051: ldloc.1 + IL_0052: ldc.i4.1 + IL_0053: conv.i8 + IL_0054: add + IL_0055: stloc.1 + IL_0056: ldloc.1 + IL_0057: ldloc.0 + IL_0058: blt.un.s IL_0047 + + IL_005a: ret + } + + .method public static void f8(int64 start, + int64 finish) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 5 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: conv.i8 + IL_0003: ldarg.1 + IL_0004: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_0009: pop + IL_000a: ldc.i4.0 + IL_000b: conv.i8 + IL_000c: stloc.0 + IL_000d: ldc.i4.0 + IL_000e: conv.i8 + IL_000f: stloc.1 + IL_0010: ldarg.0 + IL_0011: stloc.2 + IL_0012: br.s IL_0024 + + IL_0014: ldloc.2 + IL_0015: call void assembly::set_c(int64) + IL_001a: ldloc.2 + IL_001b: ldc.i4.0 + IL_001c: conv.i8 + IL_001d: add + IL_001e: stloc.2 + IL_001f: ldloc.1 + IL_0020: ldc.i4.1 + IL_0021: conv.i8 + IL_0022: add + IL_0023: stloc.1 + IL_0024: ldloc.1 + IL_0025: ldloc.0 + IL_0026: blt.un.s IL_0014 + + IL_0028: ret + } + + .method public static void f9() cil managed + { + + .maxstack 5 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldc.i4.1 + IL_0001: conv.i8 + IL_0002: ldc.i4.0 + IL_0003: conv.i8 + IL_0004: ldc.i4.s 10 + IL_0006: conv.i8 + IL_0007: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_000c: pop + IL_000d: ldc.i4.0 + IL_000e: conv.i8 + IL_000f: stloc.0 + IL_0010: ldc.i4.0 + IL_0011: conv.i8 + IL_0012: stloc.1 + IL_0013: ldc.i4.1 + IL_0014: conv.i8 + IL_0015: stloc.2 + IL_0016: br.s IL_0028 + + IL_0018: ldloc.2 + IL_0019: call void assembly::set_c(int64) + IL_001e: ldloc.2 + IL_001f: ldc.i4.0 + IL_0020: conv.i8 + IL_0021: add + IL_0022: stloc.2 + IL_0023: ldloc.1 + IL_0024: ldc.i4.1 + IL_0025: conv.i8 + IL_0026: add + IL_0027: stloc.1 + IL_0028: ldloc.1 + IL_0029: ldloc.0 + IL_002a: blt.un.s IL_0018 + + IL_002c: ret + } + + .method public static void f10() cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stloc.0 + IL_0003: ldc.i4.s 10 + IL_0005: conv.i8 + IL_0006: stloc.1 + IL_0007: br.s IL_0019 + + IL_0009: ldloc.1 + IL_000a: call void assembly::set_c(int64) + IL_000f: ldloc.1 + IL_0010: ldc.i4.m1 + IL_0011: conv.i8 + IL_0012: add + IL_0013: stloc.1 + IL_0014: ldloc.0 + IL_0015: ldc.i4.1 + IL_0016: conv.i8 + IL_0017: add + IL_0018: stloc.0 + IL_0019: ldloc.0 + IL_001a: ldc.i4.s 10 + IL_001c: conv.i8 + IL_001d: blt.un.s IL_0009 + + IL_001f: ret + } + + .method public static void f11() cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stloc.0 + IL_0003: ldc.i4.s 10 + IL_0005: conv.i8 + IL_0006: stloc.1 + IL_0007: br.s IL_001a + + IL_0009: ldloc.1 + IL_000a: call void assembly::set_c(int64) + IL_000f: ldloc.1 + IL_0010: ldc.i4.s -2 + IL_0012: conv.i8 + IL_0013: add + IL_0014: stloc.1 + IL_0015: ldloc.0 + IL_0016: ldc.i4.1 + IL_0017: conv.i8 + IL_0018: add + IL_0019: stloc.0 + IL_001a: ldloc.0 + IL_001b: ldc.i4.5 + IL_001c: conv.i8 + IL_001d: blt.un.s IL_0009 + + IL_001f: ret + } + + .property int64 c() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .set void assembly::set_c(int64) + .get int64 assembly::get_c() + } +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .field static assembly int64 c@3 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stsfld int64 ''.$assembly::c@3 + IL_0007: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForLoop.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForLoop.fs index 58bd7c3bd2d..69d37924d10 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForLoop.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOff/ForLoop.fs @@ -207,3 +207,10 @@ module ForLoopRealInternalSignatureOff = compilation |> withLangVersionPreview // TODO https://github.com/dotnet/fsharp/issues/16739: Remove this when LanguageFeature.LowerIntegralRangesToFastLoops is out of preview. |> verifyCompilation + + // SOURCE=ForEachRangeStep_UnitsOfMeasure.fs SCFLAGS="--optimize+" # ForEachRangeStep_UnitsOfMeasure.fs --optimize+ + [] + let ``ForEachRangeStep_UnitsOfMeasure_opt`` compilation = + compilation + |> withLangVersionPreview // TODO https://github.com/dotnet/fsharp/issues/16739: Remove this when LanguageFeature.LowerIntegralRangesToFastLoops is out of preview. + |> verifyCompilation diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForEachRangeStep_UnitsOfMeasure.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForEachRangeStep_UnitsOfMeasure.fs new file mode 100644 index 00000000000..a142d0f5e00 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForEachRangeStep_UnitsOfMeasure.fs @@ -0,0 +1,47 @@ +open FSharp.Data.UnitSystems.SI.UnitSymbols + +let mutable c = 0L + +let f1 () = + for n in 10L..1L..1L do + c <- n + +let f2 () = + for n in 1L..1L..10L do + c <- n + +let f3 () = + for n in 1L..2L..10L do + c <- n + +let f4 start = + for n in start..2L..10L do + c <- n + +let f5 step = + for n in 1L..step..10L do + c <- n + +let f6 finish = + for n in 1L..2L..finish do + c <- n + +let f7 start step finish = + for n in start..step..finish do + c <- n + +let f8 start finish = + for n in start..0L..finish do + c <- n + +let f9 () = + for n in 1L..0L..10L do + c <- n + +let f10 () = + for n in 10L .. -1L..1L do + c <- n + +let f11 () = + for n in 10L .. -2L..1L do + c <- n diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForEachRangeStep_UnitsOfMeasure.fs.opt.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForEachRangeStep_UnitsOfMeasure.fs.opt.il.bsl new file mode 100644 index 00000000000..1776b519709 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForEachRangeStep_UnitsOfMeasure.fs.opt.il.bsl @@ -0,0 +1,656 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .field static assembly int64 c@3 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method public specialname static int64 get_c() cil managed + { + + .maxstack 8 + IL_0000: ldsfld int64 assembly::c@3 + IL_0005: ret + } + + .method public specialname static void set_c(int64 'value') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: stsfld int64 assembly::c@3 + IL_0006: ret + } + + .method public static void f1() cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stloc.0 + IL_0003: ldc.i4.s 10 + IL_0005: conv.i8 + IL_0006: stloc.1 + IL_0007: br.s IL_0019 + + IL_0009: ldloc.1 + IL_000a: call void assembly::set_c(int64) + IL_000f: ldloc.1 + IL_0010: ldc.i4.1 + IL_0011: conv.i8 + IL_0012: add + IL_0013: stloc.1 + IL_0014: ldloc.0 + IL_0015: ldc.i4.1 + IL_0016: conv.i8 + IL_0017: add + IL_0018: stloc.0 + IL_0019: ldloc.0 + IL_001a: ldc.i4.0 + IL_001b: conv.i8 + IL_001c: blt.un.s IL_0009 + + IL_001e: ret + } + + .method public static void f2() cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stloc.0 + IL_0003: ldc.i4.1 + IL_0004: conv.i8 + IL_0005: stloc.1 + IL_0006: br.s IL_0018 + + IL_0008: ldloc.1 + IL_0009: call void assembly::set_c(int64) + IL_000e: ldloc.1 + IL_000f: ldc.i4.1 + IL_0010: conv.i8 + IL_0011: add + IL_0012: stloc.1 + IL_0013: ldloc.0 + IL_0014: ldc.i4.1 + IL_0015: conv.i8 + IL_0016: add + IL_0017: stloc.0 + IL_0018: ldloc.0 + IL_0019: ldc.i4.s 10 + IL_001b: conv.i8 + IL_001c: blt.un.s IL_0008 + + IL_001e: ret + } + + .method public static void f3() cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stloc.0 + IL_0003: ldc.i4.1 + IL_0004: conv.i8 + IL_0005: stloc.1 + IL_0006: br.s IL_0018 + + IL_0008: ldloc.1 + IL_0009: call void assembly::set_c(int64) + IL_000e: ldloc.1 + IL_000f: ldc.i4.2 + IL_0010: conv.i8 + IL_0011: add + IL_0012: stloc.1 + IL_0013: ldloc.0 + IL_0014: ldc.i4.1 + IL_0015: conv.i8 + IL_0016: add + IL_0017: stloc.0 + IL_0018: ldloc.0 + IL_0019: ldc.i4.5 + IL_001a: conv.i8 + IL_001b: blt.un.s IL_0008 + + IL_001d: ret + } + + .method public static void f4(int64 start) cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldc.i4.s 10 + IL_0002: conv.i8 + IL_0003: ldarg.0 + IL_0004: bge.s IL_000b + + IL_0006: ldc.i4.0 + IL_0007: conv.i8 + IL_0008: nop + IL_0009: br.s IL_0017 + + IL_000b: ldc.i4.s 10 + IL_000d: conv.i8 + IL_000e: ldarg.0 + IL_000f: sub + IL_0010: ldc.i4.2 + IL_0011: conv.i8 + IL_0012: div.un + IL_0013: ldc.i4.1 + IL_0014: conv.i8 + IL_0015: add + IL_0016: nop + IL_0017: stloc.0 + IL_0018: ldc.i4.0 + IL_0019: conv.i8 + IL_001a: stloc.1 + IL_001b: ldarg.0 + IL_001c: stloc.2 + IL_001d: br.s IL_002f + + IL_001f: ldloc.2 + IL_0020: call void assembly::set_c(int64) + IL_0025: ldloc.2 + IL_0026: ldc.i4.2 + IL_0027: conv.i8 + IL_0028: add + IL_0029: stloc.2 + IL_002a: ldloc.1 + IL_002b: ldc.i4.1 + IL_002c: conv.i8 + IL_002d: add + IL_002e: stloc.1 + IL_002f: ldloc.1 + IL_0030: ldloc.0 + IL_0031: blt.un.s IL_001f + + IL_0033: ret + } + + .method public static void f5(int64 step) cil managed + { + + .maxstack 5 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldarg.0 + IL_0001: brtrue.s IL_0012 + + IL_0003: ldc.i4.1 + IL_0004: conv.i8 + IL_0005: ldarg.0 + IL_0006: ldc.i4.s 10 + IL_0008: conv.i8 + IL_0009: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_000e: pop + IL_000f: nop + IL_0010: br.s IL_0013 + + IL_0012: nop + IL_0013: ldc.i4.0 + IL_0014: conv.i8 + IL_0015: ldarg.0 + IL_0016: bge.s IL_0023 + + IL_0018: ldc.i4.s 9 + IL_001a: conv.i8 + IL_001b: ldarg.0 + IL_001c: div.un + IL_001d: ldc.i4.1 + IL_001e: conv.i8 + IL_001f: add + IL_0020: nop + IL_0021: br.s IL_0026 + + IL_0023: ldc.i4.0 + IL_0024: conv.i8 + IL_0025: nop + IL_0026: stloc.0 + IL_0027: ldc.i4.0 + IL_0028: conv.i8 + IL_0029: stloc.1 + IL_002a: ldc.i4.1 + IL_002b: conv.i8 + IL_002c: stloc.2 + IL_002d: br.s IL_003e + + IL_002f: ldloc.2 + IL_0030: call void assembly::set_c(int64) + IL_0035: ldloc.2 + IL_0036: ldarg.0 + IL_0037: add + IL_0038: stloc.2 + IL_0039: ldloc.1 + IL_003a: ldc.i4.1 + IL_003b: conv.i8 + IL_003c: add + IL_003d: stloc.1 + IL_003e: ldloc.1 + IL_003f: ldloc.0 + IL_0040: blt.un.s IL_002f + + IL_0042: ret + } + + .method public static void f6(int64 finish) cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldarg.0 + IL_0001: ldc.i4.1 + IL_0002: conv.i8 + IL_0003: bge.s IL_000a + + IL_0005: ldc.i4.0 + IL_0006: conv.i8 + IL_0007: nop + IL_0008: br.s IL_0015 + + IL_000a: ldarg.0 + IL_000b: ldc.i4.1 + IL_000c: conv.i8 + IL_000d: sub + IL_000e: ldc.i4.2 + IL_000f: conv.i8 + IL_0010: div.un + IL_0011: ldc.i4.1 + IL_0012: conv.i8 + IL_0013: add + IL_0014: nop + IL_0015: stloc.0 + IL_0016: ldc.i4.0 + IL_0017: conv.i8 + IL_0018: stloc.1 + IL_0019: ldc.i4.1 + IL_001a: conv.i8 + IL_001b: stloc.2 + IL_001c: br.s IL_002e + + IL_001e: ldloc.2 + IL_001f: call void assembly::set_c(int64) + IL_0024: ldloc.2 + IL_0025: ldc.i4.2 + IL_0026: conv.i8 + IL_0027: add + IL_0028: stloc.2 + IL_0029: ldloc.1 + IL_002a: ldc.i4.1 + IL_002b: conv.i8 + IL_002c: add + IL_002d: stloc.1 + IL_002e: ldloc.1 + IL_002f: ldloc.0 + IL_0030: blt.un.s IL_001e + + IL_0032: ret + } + + .method public static void f7(int64 start, + int64 step, + int64 finish) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_000f + + IL_0003: ldarg.0 + IL_0004: ldarg.1 + IL_0005: ldarg.2 + IL_0006: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_000b: pop + IL_000c: nop + IL_000d: br.s IL_0010 + + IL_000f: nop + IL_0010: ldc.i4.0 + IL_0011: conv.i8 + IL_0012: ldarg.1 + IL_0013: bge.s IL_0029 + + IL_0015: ldarg.2 + IL_0016: ldarg.0 + IL_0017: bge.s IL_001e + + IL_0019: ldc.i4.0 + IL_001a: conv.i8 + IL_001b: nop + IL_001c: br.s IL_003f + + IL_001e: ldarg.2 + IL_001f: ldarg.0 + IL_0020: sub + IL_0021: ldarg.1 + IL_0022: div.un + IL_0023: ldc.i4.1 + IL_0024: conv.i8 + IL_0025: add + IL_0026: nop + IL_0027: br.s IL_003f + + IL_0029: ldarg.0 + IL_002a: ldarg.2 + IL_002b: bge.s IL_0032 + + IL_002d: ldc.i4.0 + IL_002e: conv.i8 + IL_002f: nop + IL_0030: br.s IL_003f + + IL_0032: ldarg.0 + IL_0033: ldarg.2 + IL_0034: sub + IL_0035: ldarg.1 + IL_0036: not + IL_0037: ldc.i4.1 + IL_0038: conv.i8 + IL_0039: add + IL_003a: div.un + IL_003b: ldc.i4.1 + IL_003c: conv.i8 + IL_003d: add + IL_003e: nop + IL_003f: stloc.0 + IL_0040: ldc.i4.0 + IL_0041: conv.i8 + IL_0042: stloc.1 + IL_0043: ldarg.0 + IL_0044: stloc.2 + IL_0045: br.s IL_0056 + + IL_0047: ldloc.2 + IL_0048: call void assembly::set_c(int64) + IL_004d: ldloc.2 + IL_004e: ldarg.1 + IL_004f: add + IL_0050: stloc.2 + IL_0051: ldloc.1 + IL_0052: ldc.i4.1 + IL_0053: conv.i8 + IL_0054: add + IL_0055: stloc.1 + IL_0056: ldloc.1 + IL_0057: ldloc.0 + IL_0058: blt.un.s IL_0047 + + IL_005a: ret + } + + .method public static void f8(int64 start, + int64 finish) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 5 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: conv.i8 + IL_0003: ldarg.1 + IL_0004: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_0009: pop + IL_000a: ldc.i4.0 + IL_000b: conv.i8 + IL_000c: stloc.0 + IL_000d: ldc.i4.0 + IL_000e: conv.i8 + IL_000f: stloc.1 + IL_0010: ldarg.0 + IL_0011: stloc.2 + IL_0012: br.s IL_0024 + + IL_0014: ldloc.2 + IL_0015: call void assembly::set_c(int64) + IL_001a: ldloc.2 + IL_001b: ldc.i4.0 + IL_001c: conv.i8 + IL_001d: add + IL_001e: stloc.2 + IL_001f: ldloc.1 + IL_0020: ldc.i4.1 + IL_0021: conv.i8 + IL_0022: add + IL_0023: stloc.1 + IL_0024: ldloc.1 + IL_0025: ldloc.0 + IL_0026: blt.un.s IL_0014 + + IL_0028: ret + } + + .method public static void f9() cil managed + { + + .maxstack 5 + .locals init (int64 V_0, + int64 V_1, + int64 V_2) + IL_0000: ldc.i4.1 + IL_0001: conv.i8 + IL_0002: ldc.i4.0 + IL_0003: conv.i8 + IL_0004: ldc.i4.s 10 + IL_0006: conv.i8 + IL_0007: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_000c: pop + IL_000d: ldc.i4.0 + IL_000e: conv.i8 + IL_000f: stloc.0 + IL_0010: ldc.i4.0 + IL_0011: conv.i8 + IL_0012: stloc.1 + IL_0013: ldc.i4.1 + IL_0014: conv.i8 + IL_0015: stloc.2 + IL_0016: br.s IL_0028 + + IL_0018: ldloc.2 + IL_0019: call void assembly::set_c(int64) + IL_001e: ldloc.2 + IL_001f: ldc.i4.0 + IL_0020: conv.i8 + IL_0021: add + IL_0022: stloc.2 + IL_0023: ldloc.1 + IL_0024: ldc.i4.1 + IL_0025: conv.i8 + IL_0026: add + IL_0027: stloc.1 + IL_0028: ldloc.1 + IL_0029: ldloc.0 + IL_002a: blt.un.s IL_0018 + + IL_002c: ret + } + + .method public static void f10() cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stloc.0 + IL_0003: ldc.i4.s 10 + IL_0005: conv.i8 + IL_0006: stloc.1 + IL_0007: br.s IL_0019 + + IL_0009: ldloc.1 + IL_000a: call void assembly::set_c(int64) + IL_000f: ldloc.1 + IL_0010: ldc.i4.m1 + IL_0011: conv.i8 + IL_0012: add + IL_0013: stloc.1 + IL_0014: ldloc.0 + IL_0015: ldc.i4.1 + IL_0016: conv.i8 + IL_0017: add + IL_0018: stloc.0 + IL_0019: ldloc.0 + IL_001a: ldc.i4.s 10 + IL_001c: conv.i8 + IL_001d: blt.un.s IL_0009 + + IL_001f: ret + } + + .method public static void f11() cil managed + { + + .maxstack 4 + .locals init (int64 V_0, + int64 V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stloc.0 + IL_0003: ldc.i4.s 10 + IL_0005: conv.i8 + IL_0006: stloc.1 + IL_0007: br.s IL_001a + + IL_0009: ldloc.1 + IL_000a: call void assembly::set_c(int64) + IL_000f: ldloc.1 + IL_0010: ldc.i4.s -2 + IL_0012: conv.i8 + IL_0013: add + IL_0014: stloc.1 + IL_0015: ldloc.0 + IL_0016: ldc.i4.1 + IL_0017: conv.i8 + IL_0018: add + IL_0019: stloc.0 + IL_001a: ldloc.0 + IL_001b: ldc.i4.5 + IL_001c: conv.i8 + IL_001d: blt.un.s IL_0009 + + IL_001f: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$assembly::init@ + IL_0006: ldsfld int32 ''.$assembly::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: stsfld int64 assembly::c@3 + IL_0007: ret + } + + .property int64 c() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .set void assembly::set_c(int64) + .get int64 assembly::get_c() + } +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: call void assembly::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForLoop.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForLoop.fs index 40ca24c3a14..57fa5bd39ac 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForLoop.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/RealInternalSignatureOn/ForLoop.fs @@ -211,3 +211,10 @@ module ForLoopRealInternalSignatureOn = compilation |> withLangVersionPreview // TODO https://github.com/dotnet/fsharp/issues/16739: Remove this when LanguageFeature.LowerIntegralRangesToFastLoops is out of preview. |> verifyCompilation + + // SOURCE=ForEachRangeStep_UnitsOfMeasure.fs SCFLAGS="--optimize+" # ForEachRangeStep_UnitsOfMeasure.fs --optimize+ + [] + let ``ForEachRangeStep_UnitsOfMeasure_opt`` compilation = + compilation + |> withLangVersionPreview // TODO https://github.com/dotnet/fsharp/issues/16739: Remove this when LanguageFeature.LowerIntegralRangesToFastLoops is out of preview. + |> verifyCompilation From a54238ab8342693f05a9705cdb7e34bc1b6b0944 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 12 Apr 2024 13:08:17 -0400 Subject: [PATCH 2/3] Update release notes --- docs/release-notes/.FSharp.Compiler.Service/8.0.400.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/release-notes/.FSharp.Compiler.Service/8.0.400.md diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md new file mode 100644 index 00000000000..40ac372299c --- /dev/null +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md @@ -0,0 +1,3 @@ +### Fixed + +* Fix bug in optimization of for-loops over integral ranges with steps and units of measure. ([Issue #17025](https://github.com/dotnet/fsharp/issues/17025), [PR #17040](hwttps://github.com/dotnet/fsharp/pull/17040)) From 747776286ba0713b5601a100ec01d6c57f4e62ad Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 12 Apr 2024 13:12:32 -0400 Subject: [PATCH 3/3] Typo --- docs/release-notes/.FSharp.Compiler.Service/8.0.400.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md index 40ac372299c..d28d8663d3c 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md @@ -1,3 +1,3 @@ ### Fixed -* Fix bug in optimization of for-loops over integral ranges with steps and units of measure. ([Issue #17025](https://github.com/dotnet/fsharp/issues/17025), [PR #17040](hwttps://github.com/dotnet/fsharp/pull/17040)) +* Fix bug in optimization of for-loops over integral ranges with steps and units of measure. ([Issue #17025](https://github.com/dotnet/fsharp/issues/17025), [PR #17040](https://github.com/dotnet/fsharp/pull/17040))