From 824b4e4ade8ffe352373d1c5030ea059d30f063e Mon Sep 17 00:00:00 2001 From: "Kevin Ransom (msft)" Date: Wed, 15 Feb 2023 11:35:04 -0800 Subject: [PATCH] Refactor component test compilation (#14747) * refactor testdriver * Netstandard test case --- .gitignore | 13 + .../EmittedIL/Misc/Misc.fs | 36 +- .../Misc/Structs02_asNetStandard20.fs | 18 + .../Structs02_asNetStandard20.fs.il.debug.bsl | 392 ++++++++++++++++++ ...tructs02_asNetStandard20.fs.il.release.bsl | 359 ++++++++++++++++ tests/FSharp.Test.Utilities/Compiler.fs | 19 +- tests/FSharp.Test.Utilities/CompilerAssert.fs | 83 ++-- .../DirectoryAttribute.fs | 4 +- .../FSharp.Test.Utilities.fsproj | 5 +- tests/FSharp.Test.Utilities/Utilities.fs | 120 ++++-- .../CodeGen/EmittedIL/StaticLinkTests.fs | 3 +- .../Compiler/Service/MultiProjectTests.fs | 4 +- 12 files changed, 974 insertions(+), 82 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs.il.debug.bsl create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs.il.release.bsl diff --git a/.gitignore b/.gitignore index 78418b2b36b..875098dae1d 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,16 @@ nCrunchTemp_* tests/FSharp.Compiler.Service.Tests/FSharp.CompilerService.SurfaceArea.netstandard.actual *.vsp +/Z.fs +/Y.fs +/X.fs +/Library.fs +/Ghost.fs +/D.fsi +/D.fs +/C.fsi +/C.fs +/B.fsi +/B.fs +/A.fsi +/A.fs diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Misc.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Misc.fs index 12df8ad0d8d..b210b9e9c71 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Misc.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Misc.fs @@ -10,7 +10,6 @@ module Misc = let verifyCompilation compilation = compilation |> withOptions [ "--test:EmitFeeFeeAs100001" ] - |> asExe |> withNoOptimize |> withEmbeddedPdb |> withEmbedAllSource @@ -21,108 +20,126 @@ module Misc = [] let ``AnonRecd_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=CodeGenRenamings01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd CodeGenRenamings01.exe" # CodeGenRenamings01.fs - [] let ``CodeGenRenamings01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=ArgumentNamesInClosures01.fs SCFLAGS="-a -g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd ArgumentNamesInClosures01.dll" # ArgumentNamesInClosures01.fs - [] let ``ArgumentNamesInClosures01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=Decimal01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd Decimal01.exe" # Decimal01.fs [] let ``Decimal01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=EntryPoint01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd EntryPoint01.exe" # EntryPoint01.fs [] let ``EntryPoint01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=EqualsOnUnions01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd EqualsOnUnions01.exe" # EqualsOnUnions01.fs - [] let ``EqualsOnUnions01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=ForLoop01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd ForLoop01.exe" # ForLoop01.fs - [] let ``ForLoop01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=ForLoop02.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd ForLoop02.exe" # ForLoop02.fs [] let ``ForLoop02_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=ForLoop03.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd ForLoop03.exe" # ForLoop03.fs [] let ``ForLoop03_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=NoBoxingOnDispose01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd NoBoxingOnDispose01.exe" # NoBoxingOnDispose01.fs [] let ``NoBoxingOnDispose01_fs`` compilation = compilation + |> asExe |> verifyCompilation //SOURCE=IfThenElse01.fs SCFLAGS="-a -g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd IfThenElse01.dll" # IfThenElse01.fs [] let ``IfThenElse01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=LetIfThenElse01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd LetIfThenElse01.exe" # LetIfThenElse01.fs - [] let ``LetIfThenElse01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=Lock01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd Lock01.exe" # Lock01.fs - [] let ``Lock01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=ModuleWithExpression01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd ModuleWithExpression01.exe" # ModuleWithExpression01.fs [] let ``ModuleWithExpression01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=NonEscapingArguments02.fs SCFLAGS="-a -g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd NonEscapingArguments02.dll" # NonEscapingArguments02.fs [] let ``NonEscapingArguments02_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=Seq_for_all01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd Seq_for_all01.exe" # Seq_for_all01.fs [] let ``Seq_for_all01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=StructsAsArrayElements01.fs SCFLAGS="-a -g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd StructsAsArrayElements01.dll" # StructsAsArrayElements01.fs - [] let ``StructsAsArrayElements01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=PreserveSig.fs SCFLAGS="-a -g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd PreserveSig.dll" # PreserveSig.fs - [] let ``PreserveSig_fs`` compilation = compilation + |> asExe |> verifyCompilation // # The name of this test is a bit misleading for legacy reasons: it used to test the --no-generate-filter-blocks option, which is now gone @@ -130,58 +147,75 @@ module Misc = [] let ``TryWith_NoFilterBlocks01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=Structs01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd Structs01.exe" # Structs01.fs - [] let ``Structs01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=Structs02.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd Structs02.exe" # Structs02.fs - [] let ``Structs02_fs`` compilation = compilation + |> asExe |> verifyCompilation + [] + let ``Structs02_asNetStandard20_fs`` compilation = + compilation + |>asLibrary + |>asNetStandard20 + |>verifyCompilation + // SOURCE=Marshal.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd Marshal.exe" # Marshal.fs [] let ``Marshal_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=MethodImplNoInline.fs SCFLAGS="-O" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd MethodImplNoInline.exe" # MethodImplNoInline.fs [] let ``MethodImplNoInline_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=MethodImplNoInline02.fs SCFLAGS="-O" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd MethodImplNoInline02.exe" # MethodImplNoInline02.fs [] let ``MethodImplNoInline02_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=CustomAttributeGenericParameter01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd CustomAttributeGenericParameter01.exe" # CustomAttributeGenericParameter01.fs - [] let ``CustomAttributeGenericParameter01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=GenericTypeStaticField.fs SCFLAGS="-g --optimize+" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd GenericTypeStaticField.exe" # GenericTypeStaticField.fs - [] let ``GenericTypeStaticField_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=GeneralizationOnUnions01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd GeneralizationOnUnions01.exe" # GeneralizationOnUnions01.fs [] let ``GeneralizationOnUnions01_fs`` compilation = compilation + |> asExe |> verifyCompilation // SOURCE=AbstractClass.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd AbstractClass.exe" # AbstractClass.fs [] let ``AbstractClass_fs`` compilation = compilation + |> asExe |> verifyCompilation diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs new file mode 100644 index 00000000000..83fdc826755 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs @@ -0,0 +1,18 @@ +// regression test for 767815: Invalid code is generated when using field initializers in struct constructor + +module Experiment.Test + +[] +type Repro = + val hash : int + new(length) = + { hash = + let mutable h = 0 + for i=0 to length-1 do + h <- 26*h + h + } + +let test() = + let t = Repro(42) + t.hash \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs.il.debug.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs.il.debug.bsl new file mode 100644 index 00000000000..44822a0a902 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs.il.debug.bsl @@ -0,0 +1,392 @@ + +// Microsoft (R) .NET IL Disassembler. Version 5.0.0-preview.7.20364.11 + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly extern netstandard +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) // .{...-.Q + .ver 2:0:0:0 +} +.assembly extern FSharp.Core +{ + .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....: + .ver 7:0:0:0 +} +.assembly Structs02_asNetStandard20 +{ + .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 ) + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [netstandard]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [netstandard]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 01 01 00 00 00 00 ) + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.Structs02_asNetStandard20 +{ + // Offset: 0x00000000 Length: 0x000007F5 + // WARNING: managed resource file FSharpSignatureData.Structs02_asNetStandard20 created +} +.mresource public FSharpOptimizationData.Structs02_asNetStandard20 +{ + // Offset: 0x00000800 Length: 0x0000024A + // WARNING: managed resource file FSharpOptimizationData.Structs02_asNetStandard20 created +} +.module Structs02_asNetStandard20.dll +// MVID: {63EADB4E-37AB-0DD0-A745-03834EDBEA63} +.imagebase 0x00400000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x0000024835680000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public abstract auto ansi sealed Experiment.Test + extends [mscorlib]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 ) + .class sequential ansi serializable sealed nested public Repro + extends [netstandard]System.ValueType + implements class [netstandard]System.IEquatable`1, + [netstandard]System.Collections.IStructuralEquatable, + class [netstandard]System.IComparable`1, + [netstandard]System.IComparable, + [netstandard]System.Collections.IStructuralComparable + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.StructAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 hash@ + .method public hidebysig specialname + instance int32 get_hash() cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [netstandard]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 Experiment.Test/Repro::hash@ + IL_0006: ret + } // end of method Repro::get_hash + + .method public hidebysig virtual final + instance int32 CompareTo(valuetype Experiment.Test/Repro obj) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 46 (0x2e) + .maxstack 5 + .locals init (valuetype Experiment.Test/Repro& V_0, + class [netstandard]System.Collections.IComparer V_1, + int32 V_2, + int32 V_3, + class [netstandard]System.Collections.IComparer V_4, + int32 V_5, + int32 V_6) + IL_0000: ldarga.s obj + IL_0002: stloc.0 + IL_0003: call class [netstandard]System.Collections.IComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericComparer() + IL_0008: stloc.1 + IL_0009: ldarg.0 + IL_000a: ldfld int32 Experiment.Test/Repro::hash@ + IL_000f: stloc.2 + IL_0010: ldloc.0 + IL_0011: ldfld int32 Experiment.Test/Repro::hash@ + IL_0016: stloc.3 + IL_0017: ldloc.1 + IL_0018: stloc.s V_4 + IL_001a: ldloc.2 + IL_001b: stloc.s V_5 + IL_001d: ldloc.3 + IL_001e: stloc.s V_6 + IL_0020: ldloc.s V_5 + IL_0022: ldloc.s V_6 + IL_0024: cgt + IL_0026: ldloc.s V_5 + IL_0028: ldloc.s V_6 + IL_002a: clt + IL_002c: sub + IL_002d: ret + } // end of method Repro::CompareTo + + .method public hidebysig virtual final + instance int32 CompareTo(object obj) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: unbox.any Experiment.Test/Repro + IL_0007: call instance int32 Experiment.Test/Repro::CompareTo(valuetype Experiment.Test/Repro) + IL_000c: ret + } // end of method Repro::CompareTo + + .method public hidebysig virtual final + instance int32 CompareTo(object obj, + class [netstandard]System.Collections.IComparer comp) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 51 (0x33) + .maxstack 5 + .locals init (valuetype Experiment.Test/Repro V_0, + valuetype Experiment.Test/Repro& V_1, + class [netstandard]System.Collections.IComparer V_2, + int32 V_3, + int32 V_4, + class [netstandard]System.Collections.IComparer V_5, + int32 V_6, + int32 V_7) + IL_0000: ldarg.1 + IL_0001: unbox.any Experiment.Test/Repro + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: stloc.1 + IL_000a: ldarg.2 + IL_000b: stloc.2 + IL_000c: ldarg.0 + IL_000d: ldfld int32 Experiment.Test/Repro::hash@ + IL_0012: stloc.3 + IL_0013: ldloc.1 + IL_0014: ldfld int32 Experiment.Test/Repro::hash@ + IL_0019: stloc.s V_4 + IL_001b: ldloc.2 + IL_001c: stloc.s V_5 + IL_001e: ldloc.3 + IL_001f: stloc.s V_6 + IL_0021: ldloc.s V_4 + IL_0023: stloc.s V_7 + IL_0025: ldloc.s V_6 + IL_0027: ldloc.s V_7 + IL_0029: cgt + IL_002b: ldloc.s V_6 + IL_002d: ldloc.s V_7 + IL_002f: clt + IL_0031: sub + IL_0032: ret + } // end of method Repro::CompareTo + + .method public hidebysig virtual final + instance int32 GetHashCode(class [netstandard]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 31 (0x1f) + .maxstack 7 + .locals init (int32 V_0, + class [netstandard]System.Collections.IEqualityComparer V_1, + int32 V_2, + class [netstandard]System.Collections.IEqualityComparer V_3) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4 0x9e3779b9 + IL_0007: ldarg.1 + IL_0008: stloc.1 + IL_0009: ldarg.0 + IL_000a: ldfld int32 Experiment.Test/Repro::hash@ + IL_000f: stloc.2 + IL_0010: ldloc.1 + IL_0011: stloc.3 + IL_0012: ldloc.2 + IL_0013: ldloc.0 + IL_0014: ldc.i4.6 + IL_0015: shl + IL_0016: ldloc.0 + IL_0017: ldc.i4.2 + IL_0018: shr + IL_0019: add + IL_001a: add + IL_001b: add + IL_001c: stloc.0 + IL_001d: ldloc.0 + IL_001e: ret + } // end of method Repro::GetHashCode + + .method public hidebysig virtual final + instance int32 GetHashCode() cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call class [netstandard]System.Collections.IEqualityComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericEqualityComparer() + IL_0006: call instance int32 Experiment.Test/Repro::GetHashCode(class [netstandard]System.Collections.IEqualityComparer) + IL_000b: ret + } // end of method Repro::GetHashCode + + .method public hidebysig virtual final + instance bool Equals(object obj, + class [netstandard]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 53 (0x35) + .maxstack 4 + .locals init (object V_0, + valuetype Experiment.Test/Repro V_1, + valuetype Experiment.Test/Repro& V_2, + class [netstandard]System.Collections.IEqualityComparer V_3, + int32 V_4, + int32 V_5, + class [netstandard]System.Collections.IEqualityComparer V_6) + IL_0000: ldarg.1 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: isinst Experiment.Test/Repro + IL_0008: ldnull + IL_0009: cgt.un + IL_000b: brfalse.s IL_0033 + + IL_000d: ldarg.1 + IL_000e: unbox.any Experiment.Test/Repro + IL_0013: stloc.1 + IL_0014: ldloca.s V_1 + IL_0016: stloc.2 + IL_0017: ldarg.2 + IL_0018: stloc.3 + IL_0019: ldarg.0 + IL_001a: ldfld int32 Experiment.Test/Repro::hash@ + IL_001f: stloc.s V_4 + IL_0021: ldloc.2 + IL_0022: ldfld int32 Experiment.Test/Repro::hash@ + IL_0027: stloc.s V_5 + IL_0029: ldloc.3 + IL_002a: stloc.s V_6 + IL_002c: ldloc.s V_4 + IL_002e: ldloc.s V_5 + IL_0030: ceq + IL_0032: ret + + IL_0033: ldc.i4.0 + IL_0034: ret + } // end of method Repro::Equals + + .method public specialname rtspecialname + instance void .ctor(int32 length) cil managed + { + // Code size 37 (0x25) + .maxstack 5 + .locals init (int32 V_0, + valuetype Experiment.Test/Repro& V_1, + int32 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: stloc.1 + IL_0004: ldc.i4.0 + IL_0005: stloc.3 + IL_0006: ldarg.1 + IL_0007: ldc.i4.1 + IL_0008: sub + IL_0009: stloc.2 + IL_000a: ldloc.2 + IL_000b: ldloc.3 + IL_000c: blt.s IL_001d + + IL_000e: ldc.i4.s 26 + IL_0010: ldloc.0 + IL_0011: mul + IL_0012: stloc.0 + IL_0013: ldloc.3 + IL_0014: ldc.i4.1 + IL_0015: add + IL_0016: stloc.3 + IL_0017: ldloc.3 + IL_0018: ldloc.2 + IL_0019: ldc.i4.1 + IL_001a: add + IL_001b: bne.un.s IL_000e + + IL_001d: ldloc.1 + IL_001e: ldloc.0 + IL_001f: stfld int32 Experiment.Test/Repro::hash@ + IL_0024: ret + } // end of method Repro::.ctor + + .method public hidebysig virtual final + instance bool Equals(valuetype Experiment.Test/Repro obj) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 18 (0x12) + .maxstack 4 + .locals init (valuetype Experiment.Test/Repro& V_0) + IL_0000: ldarga.s obj + IL_0002: stloc.0 + IL_0003: ldarg.0 + IL_0004: ldfld int32 Experiment.Test/Repro::hash@ + IL_0009: ldloc.0 + IL_000a: ldfld int32 Experiment.Test/Repro::hash@ + IL_000f: ceq + IL_0011: ret + } // end of method Repro::Equals + + .method public hidebysig virtual final + instance bool Equals(object obj) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 30 (0x1e) + .maxstack 4 + .locals init (object V_0, + valuetype Experiment.Test/Repro V_1) + IL_0000: ldarg.1 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: isinst Experiment.Test/Repro + IL_0008: ldnull + IL_0009: cgt.un + IL_000b: brfalse.s IL_001c + + IL_000d: ldarg.1 + IL_000e: unbox.any Experiment.Test/Repro + IL_0013: stloc.1 + IL_0014: ldarg.0 + IL_0015: ldloc.1 + IL_0016: call instance bool Experiment.Test/Repro::Equals(valuetype Experiment.Test/Repro) + IL_001b: ret + + IL_001c: ldc.i4.0 + IL_001d: ret + } // end of method Repro::Equals + + .property instance int32 hash() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, + int32) = ( 01 00 04 00 00 00 00 00 00 00 00 00 ) + .get instance int32 Experiment.Test/Repro::get_hash() + } // end of property Repro::hash + } // end of class Repro + + .method public static int32 test() cil managed + { + // Code size 16 (0x10) + .maxstack 3 + .locals init (valuetype Experiment.Test/Repro V_0) + IL_0000: ldc.i4.s 42 + IL_0002: newobj instance void Experiment.Test/Repro::.ctor(int32) + IL_0007: stloc.0 + IL_0008: ldloca.s V_0 + IL_000a: ldfld int32 Experiment.Test/Repro::hash@ + IL_000f: ret + } // end of method Test::test + +} // end of class Experiment.Test + +.class private abstract auto ansi sealed '.$Experiment'.Test + extends [mscorlib]System.Object +{ +} // end of class '.$Experiment'.Test + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// WARNING: Created Win32 resource file C:\kevinransom\fsharp\artifacts\bin\FSharp.Compiler.ComponentTests\Debug\net472\tests\EmittedIL\Misc\Structs02_asNetStandard20_fs\Structs02_asNetStandard20.res diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs.il.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs.il.release.bsl new file mode 100644 index 00000000000..412cae2efaa --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/Structs02_asNetStandard20.fs.il.release.bsl @@ -0,0 +1,359 @@ + +// Microsoft (R) .NET IL Disassembler. Version 5.0.0-preview.7.20364.11 + + + +// Metadata version: v4.0.30319 +.assembly extern System.Runtime +{ + .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....: + .ver 4:1:2:0 +} +.assembly extern netstandard +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) // .{...-.Q + .ver 2:0:0:0 +} +.assembly extern FSharp.Core +{ + .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....: + .ver 7:0:0:0 +} +.assembly Structs02_asNetStandard20 +{ + .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 ) + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [netstandard]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [netstandard]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 01 01 00 00 00 00 ) + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.Structs02_asNetStandard20 +{ + // Offset: 0x00000000 Length: 0x000007F9 + // WARNING: managed resource file FSharpSignatureData.Structs02_asNetStandard20 created +} +.mresource public FSharpOptimizationData.Structs02_asNetStandard20 +{ + // Offset: 0x00000800 Length: 0x0000024A + // WARNING: managed resource file FSharpOptimizationData.Structs02_asNetStandard20 created +} +.module Structs02_asNetStandard20.dll +// MVID: {63EADE74-4477-7170-A745-038374DEEA63} +.imagebase 0x00400000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x0000025E8FF30000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public abstract auto ansi sealed Experiment.Test + extends [System.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 ) + .class sequential ansi serializable sealed nested public Repro + extends [netstandard]System.ValueType + implements class [netstandard]System.IEquatable`1, + [netstandard]System.Collections.IStructuralEquatable, + class [netstandard]System.IComparable`1, + [netstandard]System.IComparable, + [netstandard]System.Collections.IStructuralComparable + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.StructAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 hash@ + .method public hidebysig specialname + instance int32 get_hash() cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [netstandard]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 Experiment.Test/Repro::hash@ + IL_0006: ret + } // end of method Repro::get_hash + + .method public hidebysig virtual final + instance int32 CompareTo(valuetype Experiment.Test/Repro obj) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 33 (0x21) + .maxstack 5 + .locals init (valuetype Experiment.Test/Repro& V_0, + class [netstandard]System.Collections.IComparer V_1, + int32 V_2, + int32 V_3) + IL_0000: ldarga.s obj + IL_0002: stloc.0 + IL_0003: call class [netstandard]System.Collections.IComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericComparer() + IL_0008: stloc.1 + IL_0009: ldarg.0 + IL_000a: ldfld int32 Experiment.Test/Repro::hash@ + IL_000f: stloc.2 + IL_0010: ldloc.0 + IL_0011: ldfld int32 Experiment.Test/Repro::hash@ + IL_0016: stloc.3 + IL_0017: ldloc.2 + IL_0018: ldloc.3 + IL_0019: cgt + IL_001b: ldloc.2 + IL_001c: ldloc.3 + IL_001d: clt + IL_001f: sub + IL_0020: ret + } // end of method Repro::CompareTo + + .method public hidebysig virtual final + instance int32 CompareTo(object obj) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: unbox.any Experiment.Test/Repro + IL_0007: call instance int32 Experiment.Test/Repro::CompareTo(valuetype Experiment.Test/Repro) + IL_000c: ret + } // end of method Repro::CompareTo + + .method public hidebysig virtual final + instance int32 CompareTo(object obj, + class [netstandard]System.Collections.IComparer comp) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 39 (0x27) + .maxstack 5 + .locals init (valuetype Experiment.Test/Repro V_0, + valuetype Experiment.Test/Repro& V_1, + class [netstandard]System.Collections.IComparer V_2, + int32 V_3, + int32 V_4) + IL_0000: ldarg.1 + IL_0001: unbox.any Experiment.Test/Repro + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: stloc.1 + IL_000a: ldarg.2 + IL_000b: stloc.2 + IL_000c: ldarg.0 + IL_000d: ldfld int32 Experiment.Test/Repro::hash@ + IL_0012: stloc.3 + IL_0013: ldloc.1 + IL_0014: ldfld int32 Experiment.Test/Repro::hash@ + IL_0019: stloc.s V_4 + IL_001b: ldloc.3 + IL_001c: ldloc.s V_4 + IL_001e: cgt + IL_0020: ldloc.3 + IL_0021: ldloc.s V_4 + IL_0023: clt + IL_0025: sub + IL_0026: ret + } // end of method Repro::CompareTo + + .method public hidebysig virtual final + instance int32 GetHashCode(class [netstandard]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 27 (0x1b) + .maxstack 7 + .locals init (int32 V_0, + class [netstandard]System.Collections.IEqualityComparer V_1) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4 0x9e3779b9 + IL_0007: ldarg.1 + IL_0008: stloc.1 + IL_0009: ldarg.0 + IL_000a: ldfld int32 Experiment.Test/Repro::hash@ + IL_000f: ldloc.0 + IL_0010: ldc.i4.6 + IL_0011: shl + IL_0012: ldloc.0 + IL_0013: ldc.i4.2 + IL_0014: shr + IL_0015: add + IL_0016: add + IL_0017: add + IL_0018: stloc.0 + IL_0019: ldloc.0 + IL_001a: ret + } // end of method Repro::GetHashCode + + .method public hidebysig virtual final + instance int32 GetHashCode() cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call class [netstandard]System.Collections.IEqualityComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericEqualityComparer() + IL_0006: call instance int32 Experiment.Test/Repro::GetHashCode(class [netstandard]System.Collections.IEqualityComparer) + IL_000b: ret + } // end of method Repro::GetHashCode + + .method public hidebysig virtual final + instance bool Equals(object obj, + class [netstandard]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 42 (0x2a) + .maxstack 4 + .locals init (object V_0, + valuetype Experiment.Test/Repro V_1, + valuetype Experiment.Test/Repro& V_2, + class [netstandard]System.Collections.IEqualityComparer V_3) + IL_0000: ldarg.1 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: isinst Experiment.Test/Repro + IL_0008: ldnull + IL_0009: cgt.un + IL_000b: brfalse.s IL_0028 + + IL_000d: ldarg.1 + IL_000e: unbox.any Experiment.Test/Repro + IL_0013: stloc.1 + IL_0014: ldloca.s V_1 + IL_0016: stloc.2 + IL_0017: ldarg.2 + IL_0018: stloc.3 + IL_0019: ldarg.0 + IL_001a: ldfld int32 Experiment.Test/Repro::hash@ + IL_001f: ldloc.2 + IL_0020: ldfld int32 Experiment.Test/Repro::hash@ + IL_0025: ceq + IL_0027: ret + + IL_0028: ldc.i4.0 + IL_0029: ret + } // end of method Repro::Equals + + .method public specialname rtspecialname + instance void .ctor(int32 length) cil managed + { + // Code size 37 (0x25) + .maxstack 5 + .locals init (int32 V_0, + valuetype Experiment.Test/Repro& V_1, + int32 V_2, + int32 V_3) + IL_0000: ldarg.0 + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: stloc.1 + IL_0004: ldc.i4.0 + IL_0005: stloc.3 + IL_0006: ldarg.1 + IL_0007: ldc.i4.1 + IL_0008: sub + IL_0009: stloc.2 + IL_000a: ldloc.2 + IL_000b: ldloc.3 + IL_000c: blt.s IL_001d + + IL_000e: ldc.i4.s 26 + IL_0010: ldloc.0 + IL_0011: mul + IL_0012: stloc.0 + IL_0013: ldloc.3 + IL_0014: ldc.i4.1 + IL_0015: add + IL_0016: stloc.3 + IL_0017: ldloc.3 + IL_0018: ldloc.2 + IL_0019: ldc.i4.1 + IL_001a: add + IL_001b: bne.un.s IL_000e + + IL_001d: ldloc.1 + IL_001e: ldloc.0 + IL_001f: stfld int32 Experiment.Test/Repro::hash@ + IL_0024: ret + } // end of method Repro::.ctor + + .method public hidebysig virtual final + instance bool Equals(valuetype Experiment.Test/Repro obj) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 18 (0x12) + .maxstack 4 + .locals init (valuetype Experiment.Test/Repro& V_0) + IL_0000: ldarga.s obj + IL_0002: stloc.0 + IL_0003: ldarg.0 + IL_0004: ldfld int32 Experiment.Test/Repro::hash@ + IL_0009: ldloc.0 + IL_000a: ldfld int32 Experiment.Test/Repro::hash@ + IL_000f: ceq + IL_0011: ret + } // end of method Repro::Equals + + .method public hidebysig virtual final + instance bool Equals(object obj) cil managed + { + .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 30 (0x1e) + .maxstack 4 + .locals init (object V_0, + valuetype Experiment.Test/Repro V_1) + IL_0000: ldarg.1 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: isinst Experiment.Test/Repro + IL_0008: ldnull + IL_0009: cgt.un + IL_000b: brfalse.s IL_001c + + IL_000d: ldarg.1 + IL_000e: unbox.any Experiment.Test/Repro + IL_0013: stloc.1 + IL_0014: ldarg.0 + IL_0015: ldloc.1 + IL_0016: call instance bool Experiment.Test/Repro::Equals(valuetype Experiment.Test/Repro) + IL_001b: ret + + IL_001c: ldc.i4.0 + IL_001d: ret + } // end of method Repro::Equals + + .property instance int32 hash() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, + int32) = ( 01 00 04 00 00 00 00 00 00 00 00 00 ) + .get instance int32 Experiment.Test/Repro::get_hash() + } // end of property Repro::hash + } // end of class Repro + + .method public static int32 test() cil managed + { + // Code size 16 (0x10) + .maxstack 3 + .locals init (valuetype Experiment.Test/Repro V_0) + IL_0000: ldc.i4.s 42 + IL_0002: newobj instance void Experiment.Test/Repro::.ctor(int32) + IL_0007: stloc.0 + IL_0008: ldloca.s V_0 + IL_000a: ldfld int32 Experiment.Test/Repro::hash@ + IL_000f: ret + } // end of method Test::test + +} // end of class Experiment.Test + +.class private abstract auto ansi sealed '.$Experiment'.Test + extends [System.Runtime]System.Object +{ +} // end of class '.$Experiment'.Test + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// WARNING: Created Win32 resource file C:\kevinransom\fsharp\artifacts\bin\FSharp.Compiler.ComponentTests\Release\net7.0\tests\EmittedIL\Misc\Structs02_asNetStandard20_fs\Structs02_asNetStandard20.res diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 74250c83cdf..0eaa71a6348 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -59,7 +59,8 @@ module rec Compiler = OutputDirectory: DirectoryInfo option Name: string option IgnoreWarnings: bool - References: CompilationUnit list } + References: CompilationUnit list + TargetFramework: TargetFramework } member this.CreateOutputDirectory() = match this.OutputDirectory with @@ -204,6 +205,7 @@ module rec Compiler = Name = None IgnoreWarnings = false References = [] + TargetFramework = TargetFramework.Current } let private csFromString (source: SourceCodeFileKind) : CSharpCompilationSource = @@ -306,6 +308,7 @@ module rec Compiler = Name = Some name IgnoreWarnings = false References = [] + TargetFramework = TargetFramework.Current } |> FS let CSharp (source: string) : CompilationUnit = @@ -488,6 +491,12 @@ module rec Compiler = let asLibrary (cUnit: CompilationUnit) : CompilationUnit = withOutputType CompileOutput.Library cUnit + let asNetStandard20 (cUnit: CompilationUnit) : CompilationUnit = + match cUnit with + | FS fs -> FS { fs with TargetFramework = TargetFramework.NetStandard20 } + | CS cs -> CS { cs with TargetFramework = TargetFramework.NetStandard20 } + | IL _ -> failwith "References are not supported in IL" + let asExe (cUnit: CompilationUnit) : CompilationUnit = withOutputType CompileOutput.Exe cUnit @@ -544,7 +553,7 @@ module rec Compiler = | Some outputDirectory -> outputDirectory | _ -> defaultOutputDirectory let cmpl = - Compilation.CreateFromSources([fs.Source] @ fs.AdditionalSources, fs.OutputType, options, refs, name, outDir) |> CompilationReference.CreateFSharp + Compilation.CreateFromSources([fs.Source] @ fs.AdditionalSources, fs.OutputType, options, fs.TargetFramework, refs, name, outDir) |> CompilationReference.CreateFSharp loop (cmpl::acc) xs | CS cs -> @@ -590,7 +599,7 @@ module rec Compiler = | Some di -> di | None -> DirectoryInfo(tryCreateTemporaryDirectory()) let references = processReferences fs.References outputDirectory - let compilation = Compilation.CreateFromSources([fs.Source] @ fs.AdditionalSources, output, options, references, name, outputDirectory) + let compilation = Compilation.CreateFromSources([fs.Source] @ fs.AdditionalSources, output, options, fs.TargetFramework, references, name, outputDirectory) compileFSharpCompilation compilation fs.IgnoreWarnings (FS fs) let toErrorInfo (d: Diagnostic) = @@ -847,7 +856,7 @@ module rec Compiler = disposals.Add({ new IDisposable with member _.Dispose() = outputDirectory.Delete(true) }) let references = processReferences fs.References outputDirectory - let cmpl = Compilation.Create(fs.Source, fs.OutputType, options, references, name, outputDirectory) + let cmpl = Compilation.Create(fs.Source, fs.OutputType, options, fs.TargetFramework, references, name, outputDirectory) let _compilationRefs, _deps = evaluateReferences outputDirectory disposals fs.IgnoreWarnings cmpl let options = let opts = new ResizeArray(fs.Options) @@ -857,7 +866,7 @@ module rec Compiler = match reference with | CompilationReference( cmpl, _) -> match cmpl with - | Compilation(_sources, _outputType, _options, _references, _name, outputDirectory) -> + | Compilation(_sources, _outputType, _options, _targetFramework, _references, _name, outputDirectory) -> if outputDirectory.IsSome then opts.Add($"-I:\"{(outputDirectory.Value.FullName)}\"") | _ -> () diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index eb9ea5d3a36..0824a065aa0 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -206,44 +206,49 @@ and Compilation = sources: SourceCodeFileKind list * outputType: CompileOutput * options: string[] * + targetFramework: TargetFramework * CompilationReference list * name: string option * outputDirectory: DirectoryInfo option with - static member Create(source:SourceCodeFileKind, output:CompileOutput, ?options:string array, ?cmplRefs:CompilationReference list, ?name:string, ?outputDirectory: DirectoryInfo) = + static member Create(source:SourceCodeFileKind, output:CompileOutput, ?options:string array, ?targetFramework:TargetFramework, ?cmplRefs:CompilationReference list, ?name:string, ?outputDirectory: DirectoryInfo) = let options = defaultArg options [||] + let targetFramework = defaultArg targetFramework TargetFramework.Current let cmplRefs = defaultArg cmplRefs [] let name = match defaultArg name null with | null -> None | n -> Some n - Compilation([source], output, options, cmplRefs, name, outputDirectory) + Compilation([source], output, options, targetFramework, cmplRefs, name, outputDirectory) - static member Create(source:string, output:CompileOutput, ?options:string array, ?cmplRefs:CompilationReference list, ?name:string, ?outputDirectory: DirectoryInfo) = + static member Create(source:string, output:CompileOutput, ?options:string array, ?targetFramework:TargetFramework, ?cmplRefs:CompilationReference list, ?name:string, ?outputDirectory: DirectoryInfo) = let options = defaultArg options [||] + let targetFramework = defaultArg targetFramework TargetFramework.Current let cmplRefs = defaultArg cmplRefs [] let name = match defaultArg name null with | null -> None | n -> Some n - Compilation([SourceCodeFileKind.Create("test.fs", source)], output, options, cmplRefs, name, outputDirectory) + Compilation([SourceCodeFileKind.Create("test.fs", source)], output, options, targetFramework, cmplRefs, name, outputDirectory) - static member Create(fileName:string, source:string, output, ?options, ?cmplRefs, ?name, ?outputDirectory: DirectoryInfo) = + static member Create(fileName:string, source:string, output, ?options, ?targetFramework:TargetFramework, ?cmplRefs, ?name, ?outputDirectory: DirectoryInfo) = let source = SourceCodeFileKind.Create(fileName, source) let options = defaultArg options [||] + let targetFramework = defaultArg targetFramework TargetFramework.Current let cmplRefs = defaultArg cmplRefs [] let name = defaultArg name null let outputDirectory = defaultArg outputDirectory null - Compilation.Create(source, output, options, cmplRefs, name, outputDirectory) + Compilation.Create(source, output, options, targetFramework, cmplRefs, name, outputDirectory) - static member CreateFromSources(sources, output, ?options, ?cmplRefs, ?name, ?outputDirectory: DirectoryInfo) = + static member CreateFromSources(sources, output, ?options, ?targetFramework, ?cmplRefs, ?name, ?outputDirectory: DirectoryInfo) = let options = defaultArg options [||] + let targetFramework = defaultArg targetFramework TargetFramework.Current let cmplRefs = defaultArg cmplRefs [] let name = match defaultArg name null with | null -> None | n -> Some n - Compilation(sources, output, options, cmplRefs, name, outputDirectory) + Compilation(sources, output, options, targetFramework, cmplRefs, name, outputDirectory) module rec CompilerAssertHelpers = @@ -302,19 +307,23 @@ module rec CompilerAssertHelpers = worker.ExecuteTestCase assembly (deps |> Array.ofList) #endif - let defaultProjectOptions = + let defaultProjectOptions (targetFramework: TargetFramework) = + let assemblies = TargetFrameworkUtil.getFileReferences targetFramework |> Array.map (fun x -> sprintf "-r:%s" x) + let testDefaults = [| + "--preferreduilang:en-US" + "--noframework" + "--warn:5" +#if NETCOREAPP + "--targetprofile:netcore" +#else + "--targetprofile:mscorlib" +#endif + |] { ProjectFileName = "Z:\\test.fsproj" ProjectId = None SourceFiles = [|"test.fs"|] - OtherOptions = - let assemblies = TargetFrameworkUtil.currentReferences |> Array.map (fun x -> sprintf "-r:%s" x) - let defaultOptions = Array.append [|"--preferreduilang:en-US"; "--noframework"; "--warn:5"|] assemblies -#if NETCOREAPP - Array.append [|"--targetprofile:netcore"|] defaultOptions -#else - Array.append [|"--targetprofile:mscorlib"|] defaultOptions -#endif + OtherOptions = Array.append testDefaults assemblies ReferencedProjects = [||] IsIncompleteTypeCheckEnvironment = false UseScriptResolutionRules = false @@ -324,7 +333,7 @@ module rec CompilerAssertHelpers = Stamp = None } - let rawCompile outputFilePath isExe options (sources: SourceCodeFileKind list) = + let rawCompile outputFilePath isExe options (targetFramework: TargetFramework) (sources: SourceCodeFileKind list) = let args = [| yield "fsc.dll" @@ -332,7 +341,8 @@ module rec CompilerAssertHelpers = yield item.GetSourceFileName yield "-o:" + outputFilePath yield (if isExe then "--target:exe" else "--target:library") - yield! defaultProjectOptions.OtherOptions + yield! (defaultProjectOptions targetFramework).OtherOptions +// yield! TargetFrameworkUtil.getFileReferences targetFramework yield! options |] @@ -341,7 +351,7 @@ module rec CompilerAssertHelpers = let errors, _ = checker.Compile args |> Async.RunImmediate errors, outputFilePath - let compileDisposable (outputDirectory:DirectoryInfo) isExe options nameOpt (sources:SourceCodeFileKind list) = + let compileDisposable (outputDirectory:DirectoryInfo) isExe options targetFramework nameOpt (sources:SourceCodeFileKind list) = let disposeFile path = { new IDisposable with @@ -383,7 +393,7 @@ module rec CompilerAssertHelpers = yield source.WithFileName(destFileName) ] try - disposeList, rawCompile outputFilePath isExe options sources + disposeList, rawCompile outputFilePath isExe options targetFramework sources with | _ -> disposeList.Dispose() @@ -429,14 +439,14 @@ module rec CompilerAssertHelpers = let outputFilePath = Path.ChangeExtension (tryCreateTemporaryFileName (), if isExe then ".exe" else ".dll") try - f (rawCompile outputFilePath isExe options [source]) + f (rawCompile outputFilePath isExe options TargetFramework.Current [source]) finally try File.Delete sourceFile.GetSourceFileName with | _ -> () try File.Delete outputFilePath with | _ -> () let rec evaluateReferences (outputPath:DirectoryInfo) (disposals: ResizeArray) ignoreWarnings (cmpl: Compilation) : string[] * string list = match cmpl with - | Compilation(_, _, _, cmpls, _, _) -> + | Compilation(_, _, _, _, cmpls, _, _) -> let compiledRefs = cmpls |> List.map (fun cmpl -> @@ -476,15 +486,16 @@ module rec CompilerAssertHelpers = let compileCompilationAux outputDirectory (disposals: ResizeArray) ignoreWarnings (cmpl: Compilation) : (FSharpDiagnostic[] * string) * string list = let compilationRefs, deps = evaluateReferences outputDirectory disposals ignoreWarnings cmpl - let isExe, sources, options, name = + let isExe, sources, options, targetFramework, name = match cmpl with - | Compilation(sources, output, options, _, name, _) -> + | Compilation(sources, output, options, targetFramework, _, name, _) -> (match output with | Library -> false | Exe -> true), // isExe sources, options, + targetFramework, name - let disposal, res = compileDisposable outputDirectory isExe (Array.append options compilationRefs) name sources + let disposal, res = compileDisposable outputDirectory isExe (Array.append options compilationRefs) targetFramework name sources disposals.Add(disposal) let deps2 = @@ -686,7 +697,7 @@ Updated automatically, please check diffs in your pull request, changes must be CompilerAssert.Execute(cmpl, newProcess = true, onOutput = (fun output -> Assert.AreEqual(expectedOutput, output, sprintf "'%s' = '%s'" expectedOutput output))) static member Pass (source: string) = - let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, defaultProjectOptions) |> Async.RunImmediate + let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, defaultProjectOptions TargetFramework.Current) |> Async.RunImmediate Assert.IsEmpty(parseResults.Diagnostics, sprintf "Parse errors: %A" parseResults.Diagnostics) @@ -697,7 +708,8 @@ Updated automatically, please check diffs in your pull request, changes must be Assert.IsEmpty(typeCheckResults.Diagnostics, sprintf "Type Check errors: %A" typeCheckResults.Diagnostics) static member PassWithOptions options (source: string) = - let options = { defaultProjectOptions with OtherOptions = Array.append options defaultProjectOptions.OtherOptions} + let defaultOptions = defaultProjectOptions TargetFramework.Current + let options = { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions} let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, options) |> Async.RunImmediate @@ -712,11 +724,12 @@ Updated automatically, please check diffs in your pull request, changes must be static member TypeCheckWithErrorsAndOptionsAgainstBaseLine options (sourceDirectory:string) (sourceFile: string) = let absoluteSourceFile = System.IO.Path.Combine(sourceDirectory, sourceFile) let parseResults, fileAnswer = + let defaultOptions = defaultProjectOptions TargetFramework.Current checker.ParseAndCheckFileInProject( sourceFile, 0, SourceText.ofString (File.ReadAllText absoluteSourceFile), - { defaultProjectOptions with OtherOptions = Array.append options defaultProjectOptions.OtherOptions; SourceFiles = [|sourceFile|] }) + { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions; SourceFiles = [|sourceFile|] }) |> Async.RunImmediate Assert.IsEmpty(parseResults.Diagnostics, sprintf "Parse errors: %A" parseResults.Diagnostics) @@ -742,11 +755,12 @@ Updated automatically, please check diffs in your pull request, changes must be static member TypeCheckWithOptionsAndName options name (source: string) = let errors = let parseResults, fileAnswer = + let defaultOptions = defaultProjectOptions TargetFramework.Current checker.ParseAndCheckFileInProject( name, 0, SourceText.ofString source, - { defaultProjectOptions with OtherOptions = Array.append options defaultProjectOptions.OtherOptions; SourceFiles = [|name|] }) + { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions; SourceFiles = [|name|] }) |> Async.RunImmediate if parseResults.Diagnostics.Length > 0 then @@ -762,11 +776,12 @@ Updated automatically, please check diffs in your pull request, changes must be static member TypeCheckWithOptions options (source: string) = let errors = let parseResults, fileAnswer = + let defaultOptions = defaultProjectOptions TargetFramework.Current checker.ParseAndCheckFileInProject( "test.fs", 0, SourceText.ofString source, - { defaultProjectOptions with OtherOptions = Array.append options defaultProjectOptions.OtherOptions}) + { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions}) |> Async.RunImmediate if parseResults.Diagnostics.Length > 0 then @@ -782,11 +797,12 @@ Updated automatically, please check diffs in your pull request, changes must be /// Parses and type checks the given source. Fails if type checker is aborted. static member ParseAndTypeCheck(options, name, source: string) = let parseResults, fileAnswer = + let defaultOptions = defaultProjectOptions TargetFramework.Current checker.ParseAndCheckFileInProject( name, 0, SourceText.ofString source, - { defaultProjectOptions with OtherOptions = Array.append options defaultProjectOptions.OtherOptions}) + { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions}) |> Async.RunImmediate match fileAnswer with @@ -804,11 +820,12 @@ Updated automatically, please check diffs in your pull request, changes must be static member TypeCheckWithErrorsAndOptionsAndAdjust options libAdjust (source: string) expectedTypeErrors = let errors = let parseResults, fileAnswer = + let defaultOptions = defaultProjectOptions TargetFramework.Current checker.ParseAndCheckFileInProject( "test.fs", 0, SourceText.ofString source, - { defaultProjectOptions with OtherOptions = Array.append options defaultProjectOptions.OtherOptions}) + { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions}) |> Async.RunImmediate if parseResults.Diagnostics.Length > 0 then diff --git a/tests/FSharp.Test.Utilities/DirectoryAttribute.fs b/tests/FSharp.Test.Utilities/DirectoryAttribute.fs index abb37e0b6c5..f7c3a380aa3 100644 --- a/tests/FSharp.Test.Utilities/DirectoryAttribute.fs +++ b/tests/FSharp.Test.Utilities/DirectoryAttribute.fs @@ -8,6 +8,7 @@ open Xunit.Sdk open FSharp.Compiler.IO open FSharp.Test.Compiler +open FSharp.Test.Utilities /// Attribute to use with Xunit's TheoryAttribute. /// Takes a directory, relative to current test suite's root. @@ -135,7 +136,8 @@ type DirectoryAttribute(dir: string) = Name = Some filename IgnoreWarnings = false References = [] - OutputDirectory = outputDirectory } |> FS + OutputDirectory = outputDirectory + TargetFramework = TargetFramework.Current} |> FS member _.BaselineSuffix with get() = baselineSuffix and set v = baselineSuffix <- v member _.Includes with get() = includes and set v = includes <- v diff --git a/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj b/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj index 0e656339974..89ab2119ad7 100644 --- a/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj +++ b/tests/FSharp.Test.Utilities/FSharp.Test.Utilities.fsproj @@ -52,7 +52,7 @@ - + @@ -88,6 +88,9 @@ Always + + Always + diff --git a/tests/FSharp.Test.Utilities/Utilities.fs b/tests/FSharp.Test.Utilities/Utilities.fs index 1c6781fdd9b..106a4003108 100644 --- a/tests/FSharp.Test.Utilities/Utilities.fs +++ b/tests/FSharp.Test.Utilities/Utilities.fs @@ -14,9 +14,9 @@ open Microsoft.CodeAnalysis.CSharp open TestFramework open NUnit.Framework -type TheoryForNETCOREAPPAttribute() = +type TheoryForNETCOREAPPAttribute() = inherit Xunit.TheoryAttribute() - #if !NETCOREAPP + #if !NETCOREAPP do base.Skip <- "Only NETCOREAPP is supported runtime for this kind of test." #endif @@ -86,43 +86,61 @@ module Utilities = let inline getTestsDirectory src dir = src ++ dir - let private getOrCreateResource (resource: byref) (name: string) = - match resource with - | null -> getResourceBlob name - | _ -> resource - module private TestReferences = + let testDirectory = lazy ( + let path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()) + Directory.CreateDirectory(path) |> ignore + path) + + let private writeToTempDirectory name (image: byte array) = + let path = Path.Combine(testDirectory.Force(), $"{name}.dll") + File.WriteAllBytes(path, image) + path + [] module NetStandard20 = - let netStandard = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.netstandard).GetReference(display = "netstandard.dll (netstandard 2.0 ref)") - let mscorlibRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.mscorlib).GetReference(display = "mscorlib.dll (netstandard 2.0 ref)") - let systemRuntimeRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.System_Runtime).GetReference(display = "System.Runtime.dll (netstandard 2.0 ref)") - let systemCoreRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.System_Core).GetReference(display = "System.Core.dll (netstandard 2.0 ref)") - let systemDynamicRuntimeRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.System_Dynamic_Runtime).GetReference(display = "System.Dynamic.Runtime.dll (netstandard 2.0 ref)") - - - module private NetCoreApp31Refs = - let mutable (_mscorlib: byte[]) = Unchecked.defaultof - let mutable (_netstandard: byte[]) = Unchecked.defaultof - let mutable (_System_Console: byte[]) = Unchecked.defaultof - let mutable (_System_Core: byte[]) = Unchecked.defaultof - let mutable (_System_Dynamic_Runtime: byte[]) = Unchecked.defaultof - let mutable (_System_Runtime: byte[]) = Unchecked.defaultof - let mscorlib () = getOrCreateResource &_mscorlib "mscorlib.dll" - let netstandard () = getOrCreateResource &_netstandard "netstandard.dll" - let System_Core () = getOrCreateResource &_System_Core "System.Core.dll" - let System_Console () = getOrCreateResource &_System_Console "System.Console.dll" - let System_Runtime () = getOrCreateResource &_System_Runtime "System.Runtime.dll" - let System_Dynamic_Runtime () = getOrCreateResource &_System_Dynamic_Runtime "System.Dynamic.Runtime.dll" + let private System_Collections_Immutable = lazy getResourceBlob "System.Collections.Immutable.dll" + + module Files = + let netStandard = lazy writeToTempDirectory "netstandard" TestResources.NetFX.netstandard20.netstandard + let mscorlib = lazy writeToTempDirectory "mscorlib" TestResources.NetFX.netstandard20.mscorlib + let systemRuntime = lazy writeToTempDirectory "System.Runtime" TestResources.NetFX.netstandard20.System_Runtime + let systemCore = lazy writeToTempDirectory "System.Core" TestResources.NetFX.netstandard20.System_Core + let systemDynamicRuntime = lazy writeToTempDirectory "System.Core" TestResources.NetFX.netstandard20.System_Dynamic_Runtime + let systemCollectionsImmutable = lazy writeToTempDirectory "System.Collections.Immutable" (System_Collections_Immutable.Force()) + + module References = + let netStandardRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.netstandard).GetReference(display = "netstandard.dll (netstandard 2.0 ref)") + let mscorlibRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.mscorlib).GetReference(display = "mscorlib.dll (netstandard 2.0 ref)") + let systemRuntimeRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.System_Runtime).GetReference(display = "System.Runtime.dll (netstandard 2.0 ref)") + let systemCoreRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.System_Core).GetReference(display = "System.Core.dll (netstandard 2.0 ref)") + let systemDynamicRuntimeRef = lazy AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.System_Dynamic_Runtime).GetReference(display = "System.Dynamic.Runtime.dll (netstandard 2.0 ref)") + let systemCollectionsImmutableRef = lazy AssemblyMetadata.CreateFromImage(System_Collections_Immutable.Force()).GetReference(display = "System.Collections.Immutable.dll (netstandard 2.0 ref)") [] module NetCoreApp31 = - let netStandard = lazy AssemblyMetadata.CreateFromImage(NetCoreApp31Refs.netstandard ()).GetReference(display = "netstandard.dll (netcoreapp 3.1 ref)") - let mscorlibRef = lazy AssemblyMetadata.CreateFromImage(NetCoreApp31Refs.mscorlib ()).GetReference(display = "mscorlib.dll (netcoreapp 3.1 ref)") - let systemRuntimeRef = lazy AssemblyMetadata.CreateFromImage(NetCoreApp31Refs.System_Runtime ()).GetReference(display = "System.Runtime.dll (netcoreapp 3.1 ref)") - let systemCoreRef = lazy AssemblyMetadata.CreateFromImage(NetCoreApp31Refs.System_Core ()).GetReference(display = "System.Core.dll (netcoreapp 3.1 ref)") - let systemDynamicRuntimeRef = lazy AssemblyMetadata.CreateFromImage(NetCoreApp31Refs.System_Dynamic_Runtime ()).GetReference(display = "System.Dynamic.Runtime.dll (netcoreapp 3.1 ref)") - let systemConsoleRef = lazy AssemblyMetadata.CreateFromImage(NetCoreApp31Refs.System_Console ()).GetReference(display = "System.Console.dll (netcoreapp 3.1 ref)") + let private mscorlib = lazy getResourceBlob "mscorlib.dll" + let private netstandard = lazy getResourceBlob "netstandard.dll" + let private System_Console = lazy getResourceBlob "System.Console.dll" + let private System_Core = lazy getResourceBlob "System.Core.dll" + let private System_Dynamic_Runtime = lazy getResourceBlob "System.Dynamic.Runtime.dll" + let private System_Runtime = lazy getResourceBlob "System.Runtime.dll" + + module Files = + let mscorlib = lazy writeToTempDirectory "mscorlib" (mscorlib.Force()) + let netStandard = lazy writeToTempDirectory "netstandard" (netstandard.Force()) + let systemConsole = lazy writeToTempDirectory "System.Console" (System_Console.Force()) + let systemCore = lazy writeToTempDirectory "System.Core" (System_Core.Force()) + let systemDynamicRuntime = lazy writeToTempDirectory "System.Dynamic.Runtime" (System_Dynamic_Runtime.Force()) + let systemRuntime = lazy writeToTempDirectory "System.Runtime" (System_Runtime.Force()) + + module References = + let netStandardRef = lazy AssemblyMetadata.CreateFromImage(netstandard.Force()).GetReference(display = "netstandard.dll (netcoreapp 3.1 ref)") + let mscorlibRef = lazy AssemblyMetadata.CreateFromImage(mscorlib.Force()).GetReference(display = "mscorlib.dll (netcoreapp 3.1 ref)") + let systemConsoleRef = lazy AssemblyMetadata.CreateFromImage(System_Console.Force()).GetReference(display = "System.Console.dll (netcoreapp 3.1 ref)") + let systemCoreRef = lazy AssemblyMetadata.CreateFromImage(System_Core.Force()).GetReference(display = "System.Core.dll (netcoreapp 3.1 ref)") + let systemDynamicRuntimeRef = lazy AssemblyMetadata.CreateFromImage(System_Dynamic_Runtime.Force()).GetReference(display = "System.Dynamic.Runtime.dll (netcoreapp 3.1 ref)") + let systemRuntimeRef = lazy AssemblyMetadata.CreateFromImage(System_Runtime.Force ()).GetReference(display = "System.Runtime.dll (netcoreapp 3.1 ref)") [] module public TargetFrameworkUtil = @@ -230,19 +248,39 @@ let main argv = 0""" open TestReferences + let private netStandard20Files = + lazy ImmutableArray.Create( + NetStandard20.Files.netStandard.Value, + NetStandard20.Files.mscorlib.Value, + NetStandard20.Files.systemRuntime.Value, + NetStandard20.Files.systemCore.Value, + NetStandard20.Files.systemDynamicRuntime.Value, + NetStandard20.Files.systemCollectionsImmutable.Value) + let private netStandard20References = - lazy ImmutableArray.Create(NetStandard20.netStandard.Value, NetStandard20.mscorlibRef.Value, NetStandard20.systemRuntimeRef.Value, NetStandard20.systemCoreRef.Value, NetStandard20.systemDynamicRuntimeRef.Value) + lazy ImmutableArray.Create( + NetStandard20.References.netStandardRef.Value, + NetStandard20.References.mscorlibRef.Value, + NetStandard20.References.systemRuntimeRef.Value, + NetStandard20.References.systemCoreRef.Value, + NetStandard20.References.systemDynamicRuntimeRef.Value, + NetStandard20.References.systemCollectionsImmutableRef.Value) + let private netCoreApp31References = - lazy ImmutableArray.Create(NetCoreApp31.netStandard.Value, NetCoreApp31.mscorlibRef.Value, NetCoreApp31.systemRuntimeRef.Value, NetCoreApp31.systemCoreRef.Value, NetCoreApp31.systemDynamicRuntimeRef.Value, NetCoreApp31.systemConsoleRef.Value) + lazy ImmutableArray.Create( + NetCoreApp31.References.netStandardRef.Value, + NetCoreApp31.References.mscorlibRef.Value, + NetCoreApp31.References.systemRuntimeRef.Value, + NetCoreApp31.References.systemCoreRef.Value, + NetCoreApp31.References.systemDynamicRuntimeRef.Value, + NetCoreApp31.References.systemConsoleRef.Value) let currentReferences = getNetCoreAppReferences let currentReferencesAsPEs = getNetCoreAppReferences - |> Seq.map (fun x -> - PortableExecutableReference.CreateFromFile(x) - ) + |> Seq.map (fun x -> PortableExecutableReference.CreateFromFile(x)) |> ImmutableArray.CreateRange let getReferences tf = @@ -250,3 +288,9 @@ let main argv = 0""" | TargetFramework.NetStandard20 -> netStandard20References.Value | TargetFramework.NetCoreApp31 -> netCoreApp31References.Value | TargetFramework.Current -> currentReferencesAsPEs + + let getFileReferences tf = + match tf with + | TargetFramework.NetStandard20 -> netStandard20Files.Value |> Seq.toArray + | TargetFramework.NetCoreApp31 -> [||] //ToDo --- Perhaps NetCoreApp31Files + | TargetFramework.Current -> currentReferences diff --git a/tests/fsharp/Compiler/CodeGen/EmittedIL/StaticLinkTests.fs b/tests/fsharp/Compiler/CodeGen/EmittedIL/StaticLinkTests.fs index 00ffedb910e..2349afe4fd6 100644 --- a/tests/fsharp/Compiler/CodeGen/EmittedIL/StaticLinkTests.fs +++ b/tests/fsharp/Compiler/CodeGen/EmittedIL/StaticLinkTests.fs @@ -5,6 +5,7 @@ namespace FSharp.Compiler.UnitTests.CodeGen.EmittedIL open System.IO open System.Reflection open FSharp.Test +open FSharp.Test.Utilities open NUnit.Framework [] @@ -222,7 +223,7 @@ if not test3 then if test1 && test2 && test3 then () else failwith "Test Failed" """ - Compilation.Create(source, Exe, [|"--optimize+"|], [CompilationReference.CreateFSharp(module1, staticLink=true)]) + Compilation.Create(source, Exe, [|"--optimize+"|], TargetFramework.Current, [CompilationReference.CreateFSharp(module1, staticLink=true)]) CompilerAssert.Execute(module2, ignoreWarnings=true) diff --git a/tests/fsharp/Compiler/Service/MultiProjectTests.fs b/tests/fsharp/Compiler/Service/MultiProjectTests.fs index 25ad78f019b..0505bcdcaec 100644 --- a/tests/fsharp/Compiler/Service/MultiProjectTests.fs +++ b/tests/fsharp/Compiler/Service/MultiProjectTests.fs @@ -45,7 +45,7 @@ namespace CSharpTest let stamp = DateTime.UtcNow let csRefProj = FSharpReferencedProject.CreatePortableExecutable("""Z:\csharp_test.dll""", (fun () -> stamp), getStream) - let fsOptions = CompilerAssert.DefaultProjectOptions + let fsOptions = CompilerAssert.DefaultProjectOptions TargetFramework.Current let fsOptions = { fsOptions with ProjectId = Some(Guid.NewGuid().ToString()) @@ -155,7 +155,7 @@ let x = Script1.x """ try - let fsOptions1 = CompilerAssert.DefaultProjectOptions + let fsOptions1 = CompilerAssert.DefaultProjectOptions TargetFramework.Current let fsOptions1 = { fsOptions1 with ProjectId = Some(Guid.NewGuid().ToString())