From 9dfe9f1ee52f7504c2e5e76f24b146566edcfcfe Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Thu, 28 Nov 2019 15:29:16 +0000 Subject: [PATCH 01/13] fix ast compilation in netcoreapp --- .../Compiler/Infrastructure/AstCompiler.fs | 24 +++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 1 + 2 files changed, 25 insertions(+) create mode 100644 tests/fsharp/Compiler/Infrastructure/AstCompiler.fs diff --git a/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs b/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs new file mode 100644 index 00000000000..21e45c0448f --- /dev/null +++ b/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests.AstCompiler + +open FSharp.Compiler.UnitTests +open NUnit.Framework +open System.Reflection + +[] +module ``AST Compiler Smoke Tests`` = + + [] + let ``Simple E2E module compilation``() = + let assembly = + CompilerAssert.CompileOfAstToDynamicAssembly + """ +module TestModule + + let rec fib n = if n <= 1 then n else fib (n - 2) + fib (n - 1) +""" + + let method = assembly.GetType("TestModule").GetMethod("fib", BindingFlags.Static ||| BindingFlags.Public) + Assert.NotNull(method) + Assert.AreEqual(55, method.Invoke(null, [|10|])) \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 92621a41a77..00969e56dab 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -81,6 +81,7 @@ + From 5fb48f7079b0c7cb8cb2c0c13943917480853b78 Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Thu, 28 Nov 2019 16:27:28 +0000 Subject: [PATCH 02/13] expose PrimaryAssembly parameter; add more tests --- src/fsharp/fsc.fs | 7 ++-- src/fsharp/fsc.fsi | 1 + src/fsharp/service/service.fs | 12 +++---- src/fsharp/service/service.fsi | 5 +-- tests/FSharp.Test.Utilities/CompilerAssert.fs | 1 + .../Compiler/Infrastructure/AstCompiler.fs | 33 ++++++++++++++++++- 6 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/fsharp/fsc.fs b/src/fsharp/fsc.fs index d4fc5019e6f..e1eab870d7f 100644 --- a/src/fsharp/fsc.fs +++ b/src/fsharp/fsc.fs @@ -1946,7 +1946,7 @@ let main1(Args (ctok, tcGlobals, tcImports: TcImports, frameworkTcImports, gener // This is for the compile-from-AST feature of FCS. // TODO: consider removing this feature from FCS, which as far as I know is not used by anyone. -let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outfile, pdbFile, dllReferences, noframework, exiter, errorLoggerProvider: ErrorLoggerProvider, inputs : ParsedInput list) = +let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outfile, pdbFile, dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider: ErrorLoggerProvider, inputs : ParsedInput list) = let tryGetMetadataSnapshot = (fun _ -> None) @@ -1966,6 +1966,7 @@ let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, | None -> OptionSwitch.Off) SetTailcallSwitch tcConfigB OptionSwitch.On tcConfigB.target <- target + primaryAssembly |> Option.iter (fun pA -> tcConfigB.primaryAssembly <- pA) let errorLogger = errorLoggerProvider.CreateErrorLoggerUpToMaxErrors (tcConfigB, exiter) @@ -2211,10 +2212,10 @@ let typecheckAndCompile let compileOfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, - outFile, pdbFile, dllReferences, noframework, exiter, errorLoggerProvider, inputs, tcImportsCapture, dynamicAssemblyCreator) = + outFile, pdbFile, dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider, inputs, tcImportsCapture, dynamicAssemblyCreator) = main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outFile, pdbFile, - dllReferences, noframework, exiter, errorLoggerProvider, inputs) + dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider, inputs) |> main2a |> main2b (tcImportsCapture, dynamicAssemblyCreator) |> main3 diff --git a/src/fsharp/fsc.fsi b/src/fsharp/fsc.fsi index ae90b34b822..96d79d05b26 100755 --- a/src/fsharp/fsc.fsi +++ b/src/fsharp/fsc.fsi @@ -68,6 +68,7 @@ val compileOfAst : targetDll:string * targetPdb:string option * dependencies:string list * + primaryAssemblies:PrimaryAssembly option * noframework:bool * exiter:Exiter * loggerProvider: ErrorLoggerProvider * diff --git a/src/fsharp/service/service.fs b/src/fsharp/service/service.fs index 246f6d7440e..57ce47ba694 100644 --- a/src/fsharp/service/service.fs +++ b/src/fsharp/service/service.fs @@ -170,7 +170,7 @@ module CompileHelpers = errors.ToArray(), result - let compileFromAsts (ctok, legacyReferenceResolver, asts, assemblyName, outFile, dependencies, noframework, pdbFile, executable, tcImportsCapture, dynamicAssemblyCreator) = + let compileFromAsts (ctok, legacyReferenceResolver, asts, assemblyName, outFile, dependencies, primaryAssembly, noframework, pdbFile, executable, tcImportsCapture, dynamicAssemblyCreator) = let errors, errorLogger, loggerProvider = mkCompilationErrorHandlers() @@ -179,7 +179,7 @@ module CompileHelpers = let result = tryCompile errorLogger (fun exiter -> - compileOfAst (ctok, legacyReferenceResolver, ReduceMemoryFlag.Yes, assemblyName, target, outFile, pdbFile, dependencies, noframework, exiter, loggerProvider, asts, tcImportsCapture, dynamicAssemblyCreator)) + compileOfAst (ctok, legacyReferenceResolver, ReduceMemoryFlag.Yes, assemblyName, target, outFile, pdbFile, dependencies, primaryAssembly, noframework, exiter, loggerProvider, asts, tcImportsCapture, dynamicAssemblyCreator)) errors.ToArray(), result @@ -1053,12 +1053,12 @@ type FSharpChecker(legacyReferenceResolver, return CompileHelpers.compileFromArgs (ctok, argv, legacyReferenceResolver, None, None) }) - member __.Compile (ast:ParsedInput list, assemblyName:string, outFile:string, dependencies:string list, ?pdbFile:string, ?executable:bool, ?noframework:bool, ?userOpName: string) = + member __.Compile (ast:ParsedInput list, assemblyName:string, outFile:string, dependencies:string list, ?pdbFile:string, ?executable:bool, ?primaryAssembly:PrimaryAssembly, ?noframework:bool, ?userOpName: string) = let userOpName = defaultArg userOpName "Unknown" backgroundCompiler.Reactor.EnqueueAndAwaitOpAsync (userOpName, "Compile", assemblyName, fun ctok -> cancellable { let noframework = defaultArg noframework false - return CompileHelpers.compileFromAsts (ctok, legacyReferenceResolver, ast, assemblyName, outFile, dependencies, noframework, pdbFile, executable, None, None) + return CompileHelpers.compileFromAsts (ctok, legacyReferenceResolver, ast, assemblyName, outFile, dependencies, primaryAssembly, noframework, pdbFile, executable, None, None) } ) @@ -1090,7 +1090,7 @@ type FSharpChecker(legacyReferenceResolver, } ) - member __.CompileToDynamicAssembly (asts:ParsedInput list, assemblyName:string, dependencies:string list, execute: (TextWriter * TextWriter) option, ?debug:bool, ?noframework:bool, ?userOpName: string) = + member __.CompileToDynamicAssembly (asts:ParsedInput list, assemblyName:string, dependencies:string list, execute: (TextWriter * TextWriter) option, ?debug:bool, ?primaryAssembly:PrimaryAssembly, ?noframework:bool, ?userOpName: string) = let userOpName = defaultArg userOpName "Unknown" backgroundCompiler.Reactor.EnqueueAndAwaitOpAsync (userOpName, "CompileToDynamicAssembly", assemblyName, fun ctok -> cancellable { @@ -1113,7 +1113,7 @@ type FSharpChecker(legacyReferenceResolver, // Perform the compilation, given the above capturing function. let errorsAndWarnings, result = - CompileHelpers.compileFromAsts (ctok, legacyReferenceResolver, asts, assemblyName, outFile, dependencies, noframework, None, Some execute.IsSome, tcImportsCapture, dynamicAssemblyCreator) + CompileHelpers.compileFromAsts (ctok, legacyReferenceResolver, asts, assemblyName, outFile, dependencies, primaryAssembly, noframework, None, Some execute.IsSome, tcImportsCapture, dynamicAssemblyCreator) // Retrieve and return the results let assemblyOpt = diff --git a/src/fsharp/service/service.fsi b/src/fsharp/service/service.fsi index 3ed57fa2f27..de8bc696f51 100755 --- a/src/fsharp/service/service.fsi +++ b/src/fsharp/service/service.fsi @@ -12,6 +12,7 @@ open FSharp.Compiler.AbstractIL.ILBinaryReader open FSharp.Compiler.SyntaxTree open FSharp.Compiler.Range open FSharp.Compiler.Text +open FSharp.Compiler.AbstractIL.IL /// Unused in this API type public UnresolvedReferencesSet @@ -316,7 +317,7 @@ type public FSharpChecker = /// /// /// An optional string used for tracing compiler operations associated with this request. - member Compile: ast:ParsedInput list * assemblyName:string * outFile:string * dependencies:string list * ?pdbFile:string * ?executable:bool * ?noframework:bool * ?userOpName: string -> Async + member Compile: ast:ParsedInput list * assemblyName:string * outFile:string * dependencies:string list * ?pdbFile:string * ?executable:bool * ?primaryAssembly:PrimaryAssembly * ?noframework:bool * ?userOpName: string -> Async /// /// Compiles to a dynamic assembly using the given flags. @@ -339,7 +340,7 @@ type public FSharpChecker = /// /// /// An optional string used for tracing compiler operations associated with this request. - member CompileToDynamicAssembly: ast:ParsedInput list * assemblyName:string * dependencies:string list * execute:(TextWriter * TextWriter) option * ?debug:bool * ?noframework:bool * ?userOpName: string -> Async + member CompileToDynamicAssembly: ast:ParsedInput list * assemblyName:string * dependencies:string list * execute:(TextWriter * TextWriter) option * ?debug:bool * ?primaryAssembly:PrimaryAssembly * ?noframework:bool * ?userOpName: string -> Async /// /// Try to get type check results for a file. This looks up the results of recent type checks of the diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index f4e221c811a..90be6cb4346 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -12,6 +12,7 @@ open System.Reflection open FSharp.Compiler.Text open FSharp.Compiler.SourceCodeServices open FSharp.Compiler.Interactive.Shell +open FSharp.Compiler.AbstractIL.IL #if FX_NO_APP_DOMAINS open System.Runtime.Loader #endif diff --git a/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs b/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs index 21e45c0448f..840dc1f62ec 100644 --- a/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs +++ b/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs @@ -21,4 +21,35 @@ module TestModule let method = assembly.GetType("TestModule").GetMethod("fib", BindingFlags.Static ||| BindingFlags.Public) Assert.NotNull(method) - Assert.AreEqual(55, method.Invoke(null, [|10|])) \ No newline at end of file + Assert.AreEqual(55, method.Invoke(null, [|10|])) + + [] + let ``Compile to Assembly``() = + let assembly = + CompilerAssert.CompileOfAst false + """ +module LiteralValue + +[] +let x = 7 +""" + + (ILVerifier assembly).VerifyIL [ + """ +.field public static literal int32 x = int32(0x00000007) + """ + ] + + [] + let ``Should resolve correct BCL types``() = + let assembly = + CompilerAssert.CompileOfAstToDynamicAssembly + """ +module TestModule + + let getStreamingContext() = new System.Runtime.Serialization.StreamingContext() +""" + + let method = assembly.GetType("TestModule").GetMethod("getStreamingContext", BindingFlags.Static ||| BindingFlags.Public) + Assert.NotNull(method) + Assert.IsInstanceOf(method.Invoke(null, [||])) \ No newline at end of file From 84614dcb6481970ba7640f58faf14eba355b6ef6 Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Thu, 28 Nov 2019 19:04:20 +0000 Subject: [PATCH 03/13] remove unnecessary test --- .../Compiler/Infrastructure/AstCompiler.fs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs b/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs index 840dc1f62ec..98a8123ddc5 100644 --- a/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs +++ b/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs @@ -38,18 +38,4 @@ let x = 7 """ .field public static literal int32 x = int32(0x00000007) """ - ] - - [] - let ``Should resolve correct BCL types``() = - let assembly = - CompilerAssert.CompileOfAstToDynamicAssembly - """ -module TestModule - - let getStreamingContext() = new System.Runtime.Serialization.StreamingContext() -""" - - let method = assembly.GetType("TestModule").GetMethod("getStreamingContext", BindingFlags.Static ||| BindingFlags.Public) - Assert.NotNull(method) - Assert.IsInstanceOf(method.Invoke(null, [||])) \ No newline at end of file + ] \ No newline at end of file From 3f6989be889b8e4c2b3699944db1fd43f06715ad Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Thu, 28 Nov 2019 19:18:12 +0000 Subject: [PATCH 04/13] expose PrimaryAssembly type in SourceCodeServices namespace --- src/fsharp/service/service.fs | 2 ++ src/fsharp/service/service.fsi | 4 +++- tests/FSharp.Test.Utilities/CompilerAssert.fs | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fsharp/service/service.fs b/src/fsharp/service/service.fs index 57ce47ba694..1f1d8887199 100644 --- a/src/fsharp/service/service.fs +++ b/src/fsharp/service/service.fs @@ -29,6 +29,8 @@ open Internal.Utilities.Collections type internal Layout = StructuredFormat.Layout +type PrimaryAssembly = FSharp.Compiler.AbstractIL.IL.PrimaryAssembly + [] module EnvMisc = let braceMatchCacheSize = GetEnvInteger "FCS_BraceMatchCacheSize" 5 diff --git a/src/fsharp/service/service.fsi b/src/fsharp/service/service.fsi index de8bc696f51..091035a77c9 100755 --- a/src/fsharp/service/service.fsi +++ b/src/fsharp/service/service.fsi @@ -12,11 +12,13 @@ open FSharp.Compiler.AbstractIL.ILBinaryReader open FSharp.Compiler.SyntaxTree open FSharp.Compiler.Range open FSharp.Compiler.Text -open FSharp.Compiler.AbstractIL.IL /// Unused in this API type public UnresolvedReferencesSet +/// Target profile used in AST compilation +type public PrimaryAssembly = FSharp.Compiler.AbstractIL.IL.PrimaryAssembly + /// A set of information describing a project or script build configuration. type public FSharpProjectOptions = { diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index 90be6cb4346..f4e221c811a 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -12,7 +12,6 @@ open System.Reflection open FSharp.Compiler.Text open FSharp.Compiler.SourceCodeServices open FSharp.Compiler.Interactive.Shell -open FSharp.Compiler.AbstractIL.IL #if FX_NO_APP_DOMAINS open System.Runtime.Loader #endif From af3a566c5028d95d0809a821735606a6117bf98d Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Tue, 7 Jan 2020 18:11:22 +0000 Subject: [PATCH 05/13] fix rebase conflicts --- tests/FSharp.Test.Utilities/CompilerAssert.fs | 46 +++++++++++++++++++ .../Compiler/Infrastructure/AstCompiler.fs | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index f4e221c811a..21752c537b0 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -84,6 +84,14 @@ type CompilerAssert private () = static let _ = config |> ignore // Do a one time dotnet sdk build to compute the proper set of reference assemblies to pass to the compiler + static let primaryAssembly = +#if NETCOREAPP + PrimaryAssembly.System_Runtime +#else + PrimaryAssembly.Mscorlib +#endif + +// Do a one time dotnet sdk build to compute the proper set of reference assemblies to pass to the compiler static let projectFile = """ @@ -499,6 +507,44 @@ let main argv = 0""" CompilerAssert.Execute(cmpl, newProcess = true, onOutput = (fun output -> Assert.AreEqual(expectedOutput, output))) /// Assert that the given source code compiles with the `defaultProjectOptions`, with no errors or warnings + static member CompileOfAst isExe source = + let outputFilePath = Path.ChangeExtension (Path.GetTempFileName(), if isExe then "exe" else ".dll") + let parseOptions = { FSharpParsingOptions.Default with SourceFiles = [|"test.fs"|] } + + let parseResults = + checker.ParseFile("test.fs", SourceText.ofString source, parseOptions) + |> Async.RunSynchronously + + Assert.IsEmpty(parseResults.Errors, sprintf "Parse errors: %A" parseResults.Errors) + Assert.IsTrue(parseResults.ParseTree.IsSome, "no parse tree returned") + + let compileErrors, statusCode = + checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, [], executable = isExe, primaryAssembly = primaryAssembly) + |> Async.RunSynchronously + + Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) + Assert.AreEqual(0, statusCode, sprintf "Nonzero status code: %d" statusCode) + outputFilePath + + static member CompileOfAstToDynamicAssembly source = + let assemblyName = sprintf "test-%O" (Guid.NewGuid()) + let parseOptions = { FSharpParsingOptions.Default with SourceFiles = [|"test.fs"|] } + let parseResults = + checker.ParseFile("test.fs", SourceText.ofString source, parseOptions) + |> Async.RunSynchronously + + Assert.IsEmpty(parseResults.Errors, sprintf "Parse errors: %A" parseResults.Errors) + Assert.IsTrue(parseResults.ParseTree.IsSome, "no parse tree returned") + + let compileErrors, statusCode, assembly = + checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, [], None, primaryAssembly = primaryAssembly) + |> Async.RunSynchronously + + Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) + Assert.AreEqual(0, statusCode, sprintf "Nonzero status code: %d" statusCode) + Assert.IsTrue(assembly.IsSome, "no assembly returned") + Option.get assembly + static member Pass (source: string) = lock gate <| fun () -> let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, defaultProjectOptions) |> Async.RunSynchronously diff --git a/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs b/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs index 98a8123ddc5..40caa07d3c9 100644 --- a/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs +++ b/tests/fsharp/Compiler/Infrastructure/AstCompiler.fs @@ -2,7 +2,7 @@ namespace FSharp.Compiler.UnitTests.AstCompiler -open FSharp.Compiler.UnitTests +open FSharp.Test.Utilities open NUnit.Framework open System.Reflection From 322d418b0274487fbf536af22ff3ea5efe237f9f Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Thu, 6 Feb 2020 16:18:16 +0000 Subject: [PATCH 06/13] feed shared framework dependencies --- tests/FSharp.Test.Utilities/CompilerAssert.fs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index 21752c537b0..ff490d90b7d 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -518,8 +518,15 @@ let main argv = 0""" Assert.IsEmpty(parseResults.Errors, sprintf "Parse errors: %A" parseResults.Errors) Assert.IsTrue(parseResults.ParseTree.IsSome, "no parse tree returned") + let dependencies = + #if NETCOREAPP + Array.toList getNetCoreAppReferences + #else + [] + #endif + let compileErrors, statusCode = - checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, [], executable = isExe, primaryAssembly = primaryAssembly) + checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, dependencies, executable = isExe, primaryAssembly = primaryAssembly) |> Async.RunSynchronously Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) @@ -536,8 +543,15 @@ let main argv = 0""" Assert.IsEmpty(parseResults.Errors, sprintf "Parse errors: %A" parseResults.Errors) Assert.IsTrue(parseResults.ParseTree.IsSome, "no parse tree returned") + let dependencies = + #if NETCOREAPP + Array.toList getNetCoreAppReferences + #else + [] + #endif + let compileErrors, statusCode, assembly = - checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, [], None, primaryAssembly = primaryAssembly) + checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, dependencies, None, primaryAssembly = primaryAssembly) |> Async.RunSynchronously Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) From 72b732a3612c6c228d3cf6827744659dc00555ee Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Fri, 7 Feb 2020 13:21:17 +0000 Subject: [PATCH 07/13] pass --noframework argument --- src/fsharp/fsc.fs | 5 ++++- tests/FSharp.Test.Utilities/CompilerAssert.fs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fsharp/fsc.fs b/src/fsharp/fsc.fs index e1eab870d7f..76a9a5b1d2c 100644 --- a/src/fsharp/fsc.fs +++ b/src/fsharp/fsc.fs @@ -1957,7 +1957,10 @@ let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, defaultCopyFSharpCore=CopyFSharpCoreFlag.No, tryGetMetadataSnapshot=tryGetMetadataSnapshot) - tcConfigB.framework <- not noframework + if not noframework then + tcConfigB.framework <- false + tcConfigB.implicitlyResolveAssemblies <- false + // Preset: --optimize+ -g --tailcalls+ (see 4505) SetOptimizeSwitch tcConfigB OptionSwitch.On SetDebugSwitch tcConfigB None ( diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index ff490d90b7d..829b5b2b393 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -526,7 +526,7 @@ let main argv = 0""" #endif let compileErrors, statusCode = - checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, dependencies, executable = isExe, primaryAssembly = primaryAssembly) + checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, dependencies, executable = isExe, primaryAssembly = primaryAssembly, noframework = true) |> Async.RunSynchronously Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) @@ -551,7 +551,7 @@ let main argv = 0""" #endif let compileErrors, statusCode, assembly = - checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, dependencies, None, primaryAssembly = primaryAssembly) + checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, dependencies, None, primaryAssembly = primaryAssembly, noframework = true) |> Async.RunSynchronously Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) From ffc5b6dd3e740823f18fff714a2624b274851b62 Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Fri, 7 Feb 2020 15:56:59 +0000 Subject: [PATCH 08/13] disable win32 manifest --- src/fsharp/fsc.fs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fsharp/fsc.fs b/src/fsharp/fsc.fs index 76a9a5b1d2c..e27b9facdb7 100644 --- a/src/fsharp/fsc.fs +++ b/src/fsharp/fsc.fs @@ -1970,6 +1970,9 @@ let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, SetTailcallSwitch tcConfigB OptionSwitch.On tcConfigB.target <- target primaryAssembly |> Option.iter (fun pA -> tcConfigB.primaryAssembly <- pA) + + if tcConfigB.primaryAssembly <> PrimaryAssembly.Mscorlib then + tcConfigB.includewin32manifest <- false let errorLogger = errorLoggerProvider.CreateErrorLoggerUpToMaxErrors (tcConfigB, exiter) From 0f5498483bef19b55c905b1d6ef9c7cfb8a8509d Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Fri, 7 Feb 2020 16:05:52 +0000 Subject: [PATCH 09/13] ensure compilation calls are synchronized --- tests/FSharp.Test.Utilities/CompilerAssert.fs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index 829b5b2b393..02dc1afe89e 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -526,8 +526,9 @@ let main argv = 0""" #endif let compileErrors, statusCode = - checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, dependencies, executable = isExe, primaryAssembly = primaryAssembly, noframework = true) - |> Async.RunSynchronously + lock gate (fun () -> + checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, dependencies, executable = isExe, primaryAssembly = primaryAssembly, noframework = true) + |> Async.RunSynchronously) Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) Assert.AreEqual(0, statusCode, sprintf "Nonzero status code: %d" statusCode) @@ -551,8 +552,9 @@ let main argv = 0""" #endif let compileErrors, statusCode, assembly = - checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, dependencies, None, primaryAssembly = primaryAssembly, noframework = true) - |> Async.RunSynchronously + lock gate (fun () -> + checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, dependencies, None, primaryAssembly = primaryAssembly, noframework = true) + |> Async.RunSynchronously) Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) Assert.AreEqual(0, statusCode, sprintf "Nonzero status code: %d" statusCode) From 5d295c398dc333af20281298d1cb035dd10d233c Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Fri, 7 Feb 2020 18:08:48 +0000 Subject: [PATCH 10/13] ensure main1 stage is run for assembly compile; synchronize mainOfAst implementation with cli pipeline --- src/fsharp/fsc.fs | 78 +++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/src/fsharp/fsc.fs b/src/fsharp/fsc.fs index e27b9facdb7..df9d50c5655 100644 --- a/src/fsharp/fsc.fs +++ b/src/fsharp/fsc.fs @@ -1945,8 +1945,8 @@ let main1(Args (ctok, tcGlobals, tcImports: TcImports, frameworkTcImports, gener // This is for the compile-from-AST feature of FCS. -// TODO: consider removing this feature from FCS, which as far as I know is not used by anyone. -let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outfile, pdbFile, dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider: ErrorLoggerProvider, inputs : ParsedInput list) = +// TODO: consider extracting TC in standalone phase to avoid duplication +let main0OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outfile, pdbFile, dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider: ErrorLoggerProvider, disposables : DisposablesTracker, inputs : ParsedInput list) = let tryGetMetadataSnapshot = (fun _ -> None) @@ -1957,6 +1957,8 @@ let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, defaultCopyFSharpCore=CopyFSharpCoreFlag.No, tryGetMetadataSnapshot=tryGetMetadataSnapshot) + tcConfigB.target <- target + primaryAssembly |> Option.iter (fun pA -> tcConfigB.primaryAssembly <- pA) if not noframework then tcConfigB.framework <- false tcConfigB.implicitlyResolveAssemblies <- false @@ -1968,13 +1970,10 @@ let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, | Some _ -> OptionSwitch.On | None -> OptionSwitch.Off) SetTailcallSwitch tcConfigB OptionSwitch.On - tcConfigB.target <- target - primaryAssembly |> Option.iter (fun pA -> tcConfigB.primaryAssembly <- pA) - if tcConfigB.primaryAssembly <> PrimaryAssembly.Mscorlib then - tcConfigB.includewin32manifest <- false - - let errorLogger = errorLoggerProvider.CreateErrorLoggerUpToMaxErrors (tcConfigB, exiter) + // Now install a delayed logger to hold all errors from flags until after all flags have been parsed (for example, --vserrors) + let delayForFlagsLogger = errorLoggerProvider.CreateDelayAndForwardLogger exiter + let _unwindEL_1 = PushErrorLoggerPhaseUntilUnwind (fun _ -> delayForFlagsLogger) tcConfigB.conditionalCompilationDefines <- "COMPILED" :: tcConfigB.conditionalCompilationDefines @@ -1986,11 +1985,27 @@ let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, try TcConfig.Create(tcConfigB,validate=false) with e -> + delayForFlagsLogger.ForwardDelayedDiagnostics tcConfigB exiter.Exit 1 + + let errorLogger = errorLoggerProvider.CreateErrorLoggerUpToMaxErrors(tcConfigB, exiter) + + // Install the global error logger and never remove it. This logger does have all command-line flags considered. + let _unwindEL_2 = PushErrorLoggerPhaseUntilUnwind (fun _ -> errorLogger) + + // Forward all errors from flags + delayForFlagsLogger.CommitDelayedDiagnostics errorLogger + // Resolve assemblies + ReportTime tcConfig "Import mscorlib and FSharp.Core.dll" let foundationalTcConfigP = TcConfigProvider.Constant tcConfig - let sysRes,otherRes,knownUnresolved = TcAssemblyResolutions.SplitNonFoundationalResolutions(ctok, tcConfig) - let tcGlobals,frameworkTcImports = TcImports.BuildFrameworkTcImports (ctok, foundationalTcConfigP, sysRes, otherRes) |> Cancellable.runWithoutCancellation + let sysRes, otherRes, knownUnresolved = TcAssemblyResolutions.SplitNonFoundationalResolutions(ctok, tcConfig) + + // Import basic assemblies + let tcGlobals, frameworkTcImports = TcImports.BuildFrameworkTcImports (ctok, foundationalTcConfigP, sysRes, otherRes) |> Cancellable.runWithoutCancellation + + // Register framework tcImports to be disposed in future + disposables.Register frameworkTcImports use unwindParsePhase = PushThreadBuildPhaseUntilUnwind (BuildPhase.Parse) @@ -1998,37 +2013,26 @@ let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, let tcConfig = (tcConfig,inputs) ||> List.fold (fun tcc inp -> ApplyMetaCommandsFromInputToTcConfig (tcc, inp,meta)) let tcConfigP = TcConfigProvider.Constant tcConfig - let tcGlobals,tcImports = - let tcImports = TcImports.BuildNonFrameworkTcImports(ctok, tcConfigP, tcGlobals, frameworkTcImports, otherRes,knownUnresolved) |> Cancellable.runWithoutCancellation - tcGlobals,tcImports + // Import other assemblies + ReportTime tcConfig "Import non-system references" + let tcImports = TcImports.BuildNonFrameworkTcImports(ctok, tcConfigP, tcGlobals, frameworkTcImports, otherRes, knownUnresolved) |> Cancellable.runWithoutCancellation + + // register tcImports to be disposed in future + disposables.Register tcImports + // Build the initial type checking environment + ReportTime tcConfig "Typecheck" use unwindParsePhase = PushThreadBuildPhaseUntilUnwind (BuildPhase.TypeCheck) let tcEnv0 = GetInitialTcEnv (assemblyName, rangeStartup, tcConfig, tcImports, tcGlobals) + // Type check the inputs let tcState, topAttrs, typedAssembly, _tcEnvAtEnd = - TypeCheck(ctok, tcConfig, tcImports, tcGlobals, errorLogger, assemblyName, NiceNameGenerator(), tcEnv0, inputs,exiter) - - let generatedCcu = tcState.Ccu - generatedCcu.Contents.SetAttribs(generatedCcu.Contents.Attribs @ topAttrs.assemblyAttrs) - - use unwindPhase = PushThreadBuildPhaseUntilUnwind (BuildPhase.CodeGen) - let signingInfo = ValidateKeySigningAttributes (tcConfig, tcGlobals, topAttrs) + TypeCheck(ctok, tcConfig, tcImports, tcGlobals, errorLogger, assemblyName, NiceNameGenerator(), tcEnv0, inputs, exiter) - // Try to find an AssemblyVersion attribute - let assemVerFromAttrib = - match AttributeHelpers.TryFindVersionAttribute tcGlobals "System.Reflection.AssemblyVersionAttribute" "AssemblyVersionAttribute" topAttrs.assemblyAttrs tcConfig.deterministic with - | Some v -> - match tcConfig.version with - | VersionNone -> Some v - | _ -> warning(Error(FSComp.SR.fscAssemblyVersionAttributeIgnored(),Range.range0)); None - | _ -> None + AbortOnError(errorLogger, exiter) + ReportTime tcConfig "Typechecked" - // Pass on only the minimum information required for the next phase to ensure GC kicks in. - // In principle the JIT should be able to do good liveness analysis to clean things up, but the - // data structures involved here are so large we can't take the risk. - Args(ctok, tcConfig, tcImports, frameworkTcImports, tcGlobals, errorLogger, - generatedCcu, outfile, typedAssembly, topAttrs, pdbFile, assemblyName, - assemVerFromAttrib, signingInfo,exiter) + Args (ctok, tcGlobals, tcImports, frameworkTcImports, tcState.Ccu, typedAssembly, topAttrs, tcConfig, outfile, pdbFile, assemblyName, errorLogger, exiter) /// Phase 2a: encode signature data, optimize, encode optimization data @@ -2220,8 +2224,10 @@ let compileOfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outFile, pdbFile, dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider, inputs, tcImportsCapture, dynamicAssemblyCreator) = - main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outFile, pdbFile, - dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider, inputs) + use d = new DisposablesTracker() + main0OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outFile, pdbFile, + dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider, d, inputs) + |> main1 |> main2a |> main2b (tcImportsCapture, dynamicAssemblyCreator) |> main3 From d86e439fd41537a8102f19b9cf08edfbc550b4e3 Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Fri, 7 Feb 2020 21:53:28 +0000 Subject: [PATCH 11/13] derp --- src/fsharp/fsc.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/fsc.fs b/src/fsharp/fsc.fs index df9d50c5655..89511f91a97 100644 --- a/src/fsharp/fsc.fs +++ b/src/fsharp/fsc.fs @@ -1959,7 +1959,7 @@ let main0OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, tcConfigB.target <- target primaryAssembly |> Option.iter (fun pA -> tcConfigB.primaryAssembly <- pA) - if not noframework then + if noframework then tcConfigB.framework <- false tcConfigB.implicitlyResolveAssemblies <- false From ba051ee93eebce5f5338d68cff772c24233601ed Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Fri, 7 Feb 2020 22:52:31 +0000 Subject: [PATCH 12/13] Revert "ensure compilation calls are synchronized" This reverts commit 596d6c1c4a20581f5f9ce861629b14077adfebed. --- tests/FSharp.Test.Utilities/CompilerAssert.fs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index 02dc1afe89e..829b5b2b393 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -526,9 +526,8 @@ let main argv = 0""" #endif let compileErrors, statusCode = - lock gate (fun () -> - checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, dependencies, executable = isExe, primaryAssembly = primaryAssembly, noframework = true) - |> Async.RunSynchronously) + checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, dependencies, executable = isExe, primaryAssembly = primaryAssembly, noframework = true) + |> Async.RunSynchronously Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) Assert.AreEqual(0, statusCode, sprintf "Nonzero status code: %d" statusCode) @@ -552,9 +551,8 @@ let main argv = 0""" #endif let compileErrors, statusCode, assembly = - lock gate (fun () -> - checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, dependencies, None, primaryAssembly = primaryAssembly, noframework = true) - |> Async.RunSynchronously) + checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, dependencies, None, primaryAssembly = primaryAssembly, noframework = true) + |> Async.RunSynchronously Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) Assert.AreEqual(0, statusCode, sprintf "Nonzero status code: %d" statusCode) From 927a8f5f9a011240cb5d22634e06358d376c4fc9 Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Thu, 13 Feb 2020 22:55:10 +0000 Subject: [PATCH 13/13] address feedback --- src/fsharp/fsc.fs | 16 ++++++++++++---- src/fsharp/fsc.fsi | 1 - src/fsharp/service/service.fs | 14 ++++++-------- src/fsharp/service/service.fsi | 7 ++----- tests/FSharp.Test.Utilities/CompilerAssert.fs | 12 ++---------- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/fsharp/fsc.fs b/src/fsharp/fsc.fs index 89511f91a97..1180ce2b788 100644 --- a/src/fsharp/fsc.fs +++ b/src/fsharp/fsc.fs @@ -1946,7 +1946,7 @@ let main1(Args (ctok, tcGlobals, tcImports: TcImports, frameworkTcImports, gener // This is for the compile-from-AST feature of FCS. // TODO: consider extracting TC in standalone phase to avoid duplication -let main0OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outfile, pdbFile, dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider: ErrorLoggerProvider, disposables : DisposablesTracker, inputs : ParsedInput list) = +let main0OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outfile, pdbFile, dllReferences, noframework, exiter, errorLoggerProvider: ErrorLoggerProvider, disposables : DisposablesTracker, inputs : ParsedInput list) = let tryGetMetadataSnapshot = (fun _ -> None) @@ -1957,8 +1957,16 @@ let main0OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, defaultCopyFSharpCore=CopyFSharpCoreFlag.No, tryGetMetadataSnapshot=tryGetMetadataSnapshot) + let primaryAssembly = + // temporary workaround until https://github.com/dotnet/fsharp/pull/8043 is merged: + // pick a primary assembly based on the current runtime. + // It's an ugly compromise used to avoid exposing primaryAssembly in the public api for this function. + let isNetCoreAppProcess = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith ".NET Core" + if isNetCoreAppProcess then PrimaryAssembly.System_Runtime + else PrimaryAssembly.Mscorlib + tcConfigB.target <- target - primaryAssembly |> Option.iter (fun pA -> tcConfigB.primaryAssembly <- pA) + tcConfigB.primaryAssembly <- primaryAssembly if noframework then tcConfigB.framework <- false tcConfigB.implicitlyResolveAssemblies <- false @@ -2222,11 +2230,11 @@ let typecheckAndCompile let compileOfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, - outFile, pdbFile, dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider, inputs, tcImportsCapture, dynamicAssemblyCreator) = + outFile, pdbFile, dllReferences, noframework, exiter, errorLoggerProvider, inputs, tcImportsCapture, dynamicAssemblyCreator) = use d = new DisposablesTracker() main0OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outFile, pdbFile, - dllReferences, primaryAssembly, noframework, exiter, errorLoggerProvider, d, inputs) + dllReferences, noframework, exiter, errorLoggerProvider, d, inputs) |> main1 |> main2a |> main2b (tcImportsCapture, dynamicAssemblyCreator) diff --git a/src/fsharp/fsc.fsi b/src/fsharp/fsc.fsi index 96d79d05b26..ae90b34b822 100755 --- a/src/fsharp/fsc.fsi +++ b/src/fsharp/fsc.fsi @@ -68,7 +68,6 @@ val compileOfAst : targetDll:string * targetPdb:string option * dependencies:string list * - primaryAssemblies:PrimaryAssembly option * noframework:bool * exiter:Exiter * loggerProvider: ErrorLoggerProvider * diff --git a/src/fsharp/service/service.fs b/src/fsharp/service/service.fs index 1f1d8887199..246f6d7440e 100644 --- a/src/fsharp/service/service.fs +++ b/src/fsharp/service/service.fs @@ -29,8 +29,6 @@ open Internal.Utilities.Collections type internal Layout = StructuredFormat.Layout -type PrimaryAssembly = FSharp.Compiler.AbstractIL.IL.PrimaryAssembly - [] module EnvMisc = let braceMatchCacheSize = GetEnvInteger "FCS_BraceMatchCacheSize" 5 @@ -172,7 +170,7 @@ module CompileHelpers = errors.ToArray(), result - let compileFromAsts (ctok, legacyReferenceResolver, asts, assemblyName, outFile, dependencies, primaryAssembly, noframework, pdbFile, executable, tcImportsCapture, dynamicAssemblyCreator) = + let compileFromAsts (ctok, legacyReferenceResolver, asts, assemblyName, outFile, dependencies, noframework, pdbFile, executable, tcImportsCapture, dynamicAssemblyCreator) = let errors, errorLogger, loggerProvider = mkCompilationErrorHandlers() @@ -181,7 +179,7 @@ module CompileHelpers = let result = tryCompile errorLogger (fun exiter -> - compileOfAst (ctok, legacyReferenceResolver, ReduceMemoryFlag.Yes, assemblyName, target, outFile, pdbFile, dependencies, primaryAssembly, noframework, exiter, loggerProvider, asts, tcImportsCapture, dynamicAssemblyCreator)) + compileOfAst (ctok, legacyReferenceResolver, ReduceMemoryFlag.Yes, assemblyName, target, outFile, pdbFile, dependencies, noframework, exiter, loggerProvider, asts, tcImportsCapture, dynamicAssemblyCreator)) errors.ToArray(), result @@ -1055,12 +1053,12 @@ type FSharpChecker(legacyReferenceResolver, return CompileHelpers.compileFromArgs (ctok, argv, legacyReferenceResolver, None, None) }) - member __.Compile (ast:ParsedInput list, assemblyName:string, outFile:string, dependencies:string list, ?pdbFile:string, ?executable:bool, ?primaryAssembly:PrimaryAssembly, ?noframework:bool, ?userOpName: string) = + member __.Compile (ast:ParsedInput list, assemblyName:string, outFile:string, dependencies:string list, ?pdbFile:string, ?executable:bool, ?noframework:bool, ?userOpName: string) = let userOpName = defaultArg userOpName "Unknown" backgroundCompiler.Reactor.EnqueueAndAwaitOpAsync (userOpName, "Compile", assemblyName, fun ctok -> cancellable { let noframework = defaultArg noframework false - return CompileHelpers.compileFromAsts (ctok, legacyReferenceResolver, ast, assemblyName, outFile, dependencies, primaryAssembly, noframework, pdbFile, executable, None, None) + return CompileHelpers.compileFromAsts (ctok, legacyReferenceResolver, ast, assemblyName, outFile, dependencies, noframework, pdbFile, executable, None, None) } ) @@ -1092,7 +1090,7 @@ type FSharpChecker(legacyReferenceResolver, } ) - member __.CompileToDynamicAssembly (asts:ParsedInput list, assemblyName:string, dependencies:string list, execute: (TextWriter * TextWriter) option, ?debug:bool, ?primaryAssembly:PrimaryAssembly, ?noframework:bool, ?userOpName: string) = + member __.CompileToDynamicAssembly (asts:ParsedInput list, assemblyName:string, dependencies:string list, execute: (TextWriter * TextWriter) option, ?debug:bool, ?noframework:bool, ?userOpName: string) = let userOpName = defaultArg userOpName "Unknown" backgroundCompiler.Reactor.EnqueueAndAwaitOpAsync (userOpName, "CompileToDynamicAssembly", assemblyName, fun ctok -> cancellable { @@ -1115,7 +1113,7 @@ type FSharpChecker(legacyReferenceResolver, // Perform the compilation, given the above capturing function. let errorsAndWarnings, result = - CompileHelpers.compileFromAsts (ctok, legacyReferenceResolver, asts, assemblyName, outFile, dependencies, primaryAssembly, noframework, None, Some execute.IsSome, tcImportsCapture, dynamicAssemblyCreator) + CompileHelpers.compileFromAsts (ctok, legacyReferenceResolver, asts, assemblyName, outFile, dependencies, noframework, None, Some execute.IsSome, tcImportsCapture, dynamicAssemblyCreator) // Retrieve and return the results let assemblyOpt = diff --git a/src/fsharp/service/service.fsi b/src/fsharp/service/service.fsi index 091035a77c9..1dfa9c6223e 100755 --- a/src/fsharp/service/service.fsi +++ b/src/fsharp/service/service.fsi @@ -16,9 +16,6 @@ open FSharp.Compiler.Text /// Unused in this API type public UnresolvedReferencesSet -/// Target profile used in AST compilation -type public PrimaryAssembly = FSharp.Compiler.AbstractIL.IL.PrimaryAssembly - /// A set of information describing a project or script build configuration. type public FSharpProjectOptions = { @@ -319,7 +316,7 @@ type public FSharpChecker = /// /// /// An optional string used for tracing compiler operations associated with this request. - member Compile: ast:ParsedInput list * assemblyName:string * outFile:string * dependencies:string list * ?pdbFile:string * ?executable:bool * ?primaryAssembly:PrimaryAssembly * ?noframework:bool * ?userOpName: string -> Async + member Compile: ast:ParsedInput list * assemblyName:string * outFile:string * dependencies:string list * ?pdbFile:string * ?executable:bool * ?noframework:bool * ?userOpName: string -> Async /// /// Compiles to a dynamic assembly using the given flags. @@ -342,7 +339,7 @@ type public FSharpChecker = /// /// /// An optional string used for tracing compiler operations associated with this request. - member CompileToDynamicAssembly: ast:ParsedInput list * assemblyName:string * dependencies:string list * execute:(TextWriter * TextWriter) option * ?debug:bool * ?primaryAssembly:PrimaryAssembly * ?noframework:bool * ?userOpName: string -> Async + member CompileToDynamicAssembly: ast:ParsedInput list * assemblyName:string * dependencies:string list * execute:(TextWriter * TextWriter) option * ?debug:bool * ?noframework:bool * ?userOpName: string -> Async /// /// Try to get type check results for a file. This looks up the results of recent type checks of the diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index 829b5b2b393..75ecb7ba9e1 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -83,14 +83,6 @@ type CompilerAssert private () = static let _ = config |> ignore - // Do a one time dotnet sdk build to compute the proper set of reference assemblies to pass to the compiler - static let primaryAssembly = -#if NETCOREAPP - PrimaryAssembly.System_Runtime -#else - PrimaryAssembly.Mscorlib -#endif - // Do a one time dotnet sdk build to compute the proper set of reference assemblies to pass to the compiler static let projectFile = """ @@ -526,7 +518,7 @@ let main argv = 0""" #endif let compileErrors, statusCode = - checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, dependencies, executable = isExe, primaryAssembly = primaryAssembly, noframework = true) + checker.Compile([parseResults.ParseTree.Value], "test", outputFilePath, dependencies, executable = isExe, noframework = true) |> Async.RunSynchronously Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors) @@ -551,7 +543,7 @@ let main argv = 0""" #endif let compileErrors, statusCode, assembly = - checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, dependencies, None, primaryAssembly = primaryAssembly, noframework = true) + checker.CompileToDynamicAssembly([parseResults.ParseTree.Value], assemblyName, dependencies, None, noframework = true) |> Async.RunSynchronously Assert.IsEmpty(compileErrors, sprintf "Compile errors: %A" compileErrors)