Skip to content

Commit

Permalink
Refactor integration (#8574)
Browse files Browse the repository at this point in the history
* Remove events from fsi

* Change data types

* temp

* Refactor dm integration into new dll

* More refactor and tests

* sigs

* Fix interactivetext link

* fix tests on non-windows

* Update src/fsharp/Interactive.DependencyManager/DependencyManager.fs

Co-Authored-By: Phillip Carter <pcarter@fastmail.com>

* Update src/fsharp/Interactive.DependencyManager/DependencyManager.fs

Co-Authored-By: Phillip Carter <pcarter@fastmail.com>

* feedback

Co-authored-by: Phillip Carter <pcarter@fastmail.com>
  • Loading branch information
KevinRansom and cartermp committed Feb 19, 2020
1 parent acd7cfd commit 9d69b49
Show file tree
Hide file tree
Showing 36 changed files with 992 additions and 488 deletions.
15 changes: 15 additions & 0 deletions FSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.Private.Scr
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.Private.Scripting.UnitTests", "tests\FSharp.Compiler.Private.Scripting.UnitTests\FSharp.Compiler.Private.Scripting.UnitTests.fsproj", "{4FEDF286-0252-4EBC-9E75-879CCA3B85DC}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Interactive.DependencyManager", "src\fsharp\Interactive.DependencyManager\Interactive.DependencyManager.fsproj", "{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -250,6 +252,18 @@ Global
{4FEDF286-0252-4EBC-9E75-879CCA3B85DC}.Release|Any CPU.Build.0 = Release|Any CPU
{4FEDF286-0252-4EBC-9E75-879CCA3B85DC}.Release|x86.ActiveCfg = Release|Any CPU
{4FEDF286-0252-4EBC-9E75-879CCA3B85DC}.Release|x86.Build.0 = Release|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Debug|x86.ActiveCfg = Debug|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Debug|x86.Build.0 = Debug|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Proto|Any CPU.ActiveCfg = Debug|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Proto|Any CPU.Build.0 = Debug|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Proto|x86.ActiveCfg = Debug|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Proto|x86.Build.0 = Debug|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Release|Any CPU.Build.0 = Release|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Release|x86.ActiveCfg = Release|Any CPU
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -270,6 +284,7 @@ Global
{8B7BF62E-7D8C-4928-BE40-4E392A9EE851} = {3881429D-A97A-49EB-B7AE-A82BA5FE9C77}
{6771860A-614D-4FDD-A655-4C70EBCC91B0} = {B8DDA694-7939-42E3-95E5-265C2217C142}
{4FEDF286-0252-4EBC-9E75-879CCA3B85DC} = {CFE3259A-2D30-4EB0-80D5-E8B5F3D01449}
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6} = {3881429D-A97A-49EB-B7AE-A82BA5FE9C77}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BD5177C7-1380-40E7-94D2-7768E1A8B1B8}
Expand Down
15 changes: 15 additions & 0 deletions VisualFSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryProject", "vsintegra
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TutorialProject", "vsintegration\ProjectTemplates\TutorialProject\TutorialProject.csproj", "{2937CBEC-262D-4C94-BE1D-291FAB72E3E8}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Interactive.DependencyManager", "src\fsharp\Interactive.DependencyManager\Interactive.DependencyManager.fsproj", "{C2F38485-5F87-4986-985B-55D7ED96D5CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -926,6 +928,18 @@ Global
{2937CBEC-262D-4C94-BE1D-291FAB72E3E8}.Release|Any CPU.Build.0 = Release|Any CPU
{2937CBEC-262D-4C94-BE1D-291FAB72E3E8}.Release|x86.ActiveCfg = Release|Any CPU
{2937CBEC-262D-4C94-BE1D-291FAB72E3E8}.Release|x86.Build.0 = Release|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Debug|x86.ActiveCfg = Debug|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Debug|x86.Build.0 = Debug|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Proto|Any CPU.ActiveCfg = Debug|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Proto|Any CPU.Build.0 = Debug|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Proto|x86.ActiveCfg = Debug|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Proto|x86.Build.0 = Debug|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Release|Any CPU.Build.0 = Release|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Release|x86.ActiveCfg = Release|Any CPU
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1001,6 +1015,7 @@ Global
{44155269-9B30-43DA-B97F-4F36F887B211} = {12EF27FD-A34B-4373-860A-F9FCE9651859}
{B53D9D05-8EF7-43A6-9A5B-0B113CBC54F8} = {12EF27FD-A34B-4373-860A-F9FCE9651859}
{2937CBEC-262D-4C94-BE1D-291FAB72E3E8} = {12EF27FD-A34B-4373-860A-F9FCE9651859}
{C2F38485-5F87-4986-985B-55D7ED96D5CE} = {3881429D-A97A-49EB-B7AE-A82BA5FE9C77}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {48EDBBBE-C8EE-4E3C-8B19-97184A487B37}
Expand Down
11 changes: 7 additions & 4 deletions fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<EmbeddedText Include="$(FSharpSourcesRoot)\fsharp\FSComp.txt">
<Link>FSComp.txt</Link>
</EmbeddedText>
<EmbeddedText Include="$(FSharpSourcesRoot)\fsharp\Interactive.DependencyManager\InteractiveDependencyManager.txt">
<Link>InteractiveDependencyManager.txt</Link>
</EmbeddedText>
<EmbeddedText Include="$(FSharpSourcesRoot)\fsharp\fsi\FSIstrings.txt">
<Link>FSIstrings.txt</Link>
</EmbeddedText>
Expand Down Expand Up @@ -519,11 +522,11 @@
<Compile Include="$(FSharpSourcesRoot)/fsharp/DotNetFrameworkDependencies.fs">
<Link>Driver\DotNetFrameworkDependencies.fs</Link>
</Compile>
<Compile Include="$(FSharpSourcesRoot)/fsharp/DependencyManager.Integration.fsi">
<Link>Driver/DependencyManager.Integration.fsi</Link>
<Compile Include="$(FSharpSourcesRoot)/fsharp/Interactive.DependencyManager/DependencyManager.fsi">
<Link>Driver/DependencyManager.fsi</Link>
</Compile>
<Compile Include="$(FSharpSourcesRoot)/fsharp/DependencyManager.Integration.fs">
<Link>Driver/DependencyManager.Integration.fs</Link>
<Compile Include="$(FSharpSourcesRoot)/fsharp/Interactive.DependencyManager/DependencyManager.fs">
<Link>Driver/DependencyManager.fs</Link>
</Compile>
<Compile Include="$(FSharpSourcesRoot)/fsharp/CompileOps.fsi">
<Link>Driver/CompileOps.fsi</Link>
Expand Down
133 changes: 75 additions & 58 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ open FSharp.Compiler.Text

open FSharp.Compiler.DotNetFrameworkDependencies

open Interactive.DependencyManager

#if !NO_EXTENSIONTYPING
open FSharp.Compiler.ExtensionTyping
open Microsoft.FSharp.Core.CompilerServices
Expand Down Expand Up @@ -2235,8 +2237,8 @@ type TcConfigBuilder =
mutable shadowCopyReferences: bool
mutable useSdkRefs: bool

/// A function to call to try to get an object that acts as a snapshot of the metadata section of a .NET binary,
/// and from which we can read the metadata. Only used when metadataOnly=true.
/// A function to call to try to get an object that acts as a snapshot of the metadata section of a .NET binary,
/// and from which we can read the metadata. Only used when metadataOnly=true.
mutable tryGetMetadataSnapshot: ILReaderTryGetMetadataSnapshot

mutable internalTestSpanStackReferring: bool
Expand All @@ -2246,6 +2248,8 @@ type TcConfigBuilder =
mutable pathMap: PathMap

mutable langVersion: LanguageVersion

mutable dependencyProvider: DependencyProvider
}

static member Initial =
Expand Down Expand Up @@ -2386,6 +2390,7 @@ type TcConfigBuilder =
noConditionalErasure = false
pathMap = PathMap.empty
langVersion = LanguageVersion("default")
dependencyProvider = new DependencyProvider()
}

static member CreateNew(legacyReferenceResolver, defaultFSharpBinariesDir, reduceMemoryUsage, implicitIncludeDir,
Expand Down Expand Up @@ -2495,7 +2500,6 @@ type TcConfigBuilder =
if not (List.contains path (List.map (fun (_, _, path) -> path) tcConfigB.loadedSources)) then
tcConfigB.loadedSources <- tcConfigB.loadedSources ++ (m, originalPath, path)


member tcConfigB.AddEmbeddedSourceFile (file) =
tcConfigB.embedSourceList <- tcConfigB.embedSourceList ++ file

Expand All @@ -2515,8 +2519,8 @@ type TcConfigBuilder =
let projectReference = tcConfigB.projectReferences |> List.tryPick (fun pr -> if pr.FileName = path then Some pr else None)
tcConfigB.referencedDLLs <- tcConfigB.referencedDLLs ++ AssemblyReference(m, path, projectReference)

member tcConfigB.AddDependencyManagerText (packageManager:DependencyManagerIntegration.IDependencyManagerProvider, m, path:string) =
let path = DependencyManagerIntegration.removeDependencyManagerKey packageManager.Key path
member tcConfigB.AddDependencyManagerText (packageManager:IDependencyManagerProvider, m, path:string) =
let path = tcConfigB.dependencyProvider.RemoveDependencyManagerKey(packageManager.Key, path)

match tcConfigB.packageManagerLines |> Map.tryFind packageManager.Key with
| Some lines -> tcConfigB.packageManagerLines <- Map.add packageManager.Key (lines ++ (false, path, m)) tcConfigB.packageManagerLines
Expand Down Expand Up @@ -2842,6 +2846,9 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
TcConfig(builder, validate)

member x.legacyReferenceResolver = data.legacyReferenceResolver

member x.dependencyProvider = data.dependencyProvider

member tcConfig.CloneOfOriginalBuilder =
{ data with conditionalCompilationDefines=data.conditionalCompilationDefines }

Expand Down Expand Up @@ -4924,7 +4931,7 @@ let RequireDLL (ctok, tcImports: TcImports, tcEnv, thisAssemblyName, m, file) =
let ProcessMetaCommandsFromInput
(nowarnF: 'state -> range * string -> 'state,
dllRequireF: 'state -> range * string -> 'state,
packageRequireF: 'state -> DependencyManagerIntegration.IDependencyManagerProvider * range * string -> 'state,
packageRequireF: 'state -> IDependencyManagerProvider * range * string -> 'state,
loadSourceF: 'state -> range * string -> unit)
(tcConfig:TcConfigBuilder, inp, pathOfMetaCommandSource, state0) =

Expand All @@ -4944,7 +4951,7 @@ let ProcessMetaCommandsFromInput
errorR(HashIncludeNotAllowedInNonScript m)
match args with
| [path] ->
matchedm<-m
matchedm <- m
tcConfig.AddIncludePath(m, path, pathOfMetaCommandSource)
state
| _ ->
Expand All @@ -4954,27 +4961,35 @@ let ProcessMetaCommandsFromInput
List.fold (fun state d -> nowarnF state (m,d)) state numbers

| ParsedHashDirective(("reference" | "r"),args,m) ->
if not canHaveScriptMetaCommands then
errorR(HashReferenceNotAllowedInNonScript m)
if not canHaveScriptMetaCommands then
errorR(HashReferenceNotAllowedInNonScript m)

let reportError errorType error =
match errorType with
| ErrorReportType.Warning -> warning(Error(error,m))
| ErrorReportType.Error -> errorR(Error(error, m))

match args with
| [path] ->
matchedm <- m
let output = tcConfig.outputDir |> Option.defaultValue ""
let dm = tcConfig.dependencyProvider.TryFindDependencyManagerInPath(tcConfig.compilerToolPaths, output , reportError, path)
match dm with
| dllpath, null when String.IsNullOrWhiteSpace(dllpath) ->
state // error already reported

| _, dependencyManager when not(isNull dependencyManager) ->
if tcConfig.langVersion.SupportsFeature(LanguageFeature.PackageManagement) then
packageRequireF state (dependencyManager, m, path)
else
errorR(Error(FSComp.SR.packageManagementRequiresVFive(), m))
state

match args with
| [path] ->
matchedm <- m
match DependencyManagerIntegration.tryFindDependencyManagerInPath tcConfig.compilerToolPaths tcConfig.outputDir m (path:string) with
| DependencyManagerIntegration.ReferenceType.RegisteredDependencyManager packageManager ->
if tcConfig.langVersion.SupportsFeature(LanguageFeature.PackageManagement) then
packageRequireF state (packageManager,m,path)
else
errorR(Error(FSComp.SR.packageManagementRequiresVFive(), m))
state

// #r "Assembly"
| DependencyManagerIntegration.ReferenceType.Library path ->
dllRequireF state (m,path)

| DependencyManagerIntegration.ReferenceType.UnknownType ->
state // error already reported
| _ ->
// #r "Assembly"
| path, _ ->
dllRequireF state (m, path)

| _ ->
errorR(Error(FSComp.SR.buildInvalidHashrDirective(), m))
state

Expand Down Expand Up @@ -5227,10 +5242,10 @@ module ScriptPreprocessClosure =
// Recover by using a default TcConfig.
let tcConfigB = tcConfig.CloneOfOriginalBuilder
TcConfig.Create(tcConfigB, validate=false), nowarns

let FindClosureFiles(mainFile, _m, closureSources, origTcConfig:TcConfig, codeContext, lexResourceManager: Lexhelp.LexResourceManager) =
let mutable tcConfig = origTcConfig

let observedSources = Observed()
let loadScripts = HashSet<_>()

Expand All @@ -5242,41 +5257,43 @@ module ScriptPreprocessClosure =
match packageManagerLines with
| [] -> ()
| (_, _, m)::_ ->
let reportError errorType error =
match errorType with
| ErrorReportType.Warning -> warning(Error(error,m))
| ErrorReportType.Error -> errorR(Error(error, m))

match origTcConfig.packageManagerLines |> Map.tryFind packageManagerKey with
| Some oldDependencyManagerLines when oldDependencyManagerLines = packageManagerLines -> ()
| _ ->
match DependencyManagerIntegration.tryFindDependencyManagerByKey tcConfig.compilerToolPaths tcConfig.outputDir m packageManagerKey with
| None ->
errorR(DependencyManagerIntegration.createPackageManagerUnknownError tcConfig.compilerToolPaths tcConfig.outputDir packageManagerKey m)
| Some packageManager ->
let outputDir = tcConfig.outputDir |> Option.defaultValue ""
match tcConfig.dependencyProvider.TryFindDependencyManagerByKey(tcConfig.compilerToolPaths, outputDir, reportError, packageManagerKey) with
| null ->
errorR(Error(tcConfig.dependencyProvider.CreatePackageManagerUnknownError(tcConfig.compilerToolPaths, outputDir, packageManagerKey, reportError), m))

| dependencyManager ->
let inline snd3 (_, b, _) = b
let packageManagerTextLines = packageManagerLines |> List.map snd3

match DependencyManagerIntegration.resolve packageManager tcConfig.implicitIncludeDir mainFile scriptName ".fsx" m packageManagerTextLines with
| None -> () // error already reported
| Some (succeeded, generatedScripts, additionalIncludeFolders) ->
// This may incrementally update tcConfig too with new #r references
// New package text is ignored on this second phase
match succeeded with
| true ->
// Resolution produced no errors
if not (isNil additionalIncludeFolders) then
let tcConfigB = tcConfig.CloneOfOriginalBuilder
for folder in additionalIncludeFolders do
tcConfigB.AddIncludePath(m, folder, "")
tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map(fun _ l -> l |> List.map(fun (_, p, m) -> true, p, m))
tcConfig <- TcConfig.Create(tcConfigB, validate=false)
for script in generatedScripts do
let scriptText = File.ReadAllText script
loadScripts.Add script |> ignore
let iSourceText = SourceText.ofString scriptText
yield! loop (ClosureSource(script, m, iSourceText, true))
| false ->
// Resolution produced errors update packagerManagerLines entries to note these failure
// failed resolutions will no longer be considered
match tcConfig.dependencyProvider.Resolve(dependencyManager, tcConfig.implicitIncludeDir, mainFile, scriptName, ".fsx", packageManagerTextLines, reportError, executionTfm) with
| true, _references, generatedScripts, additionalIncludeFolders ->
// Resolution produced no errors
if not (Seq.isEmpty additionalIncludeFolders) then
let tcConfigB = tcConfig.CloneOfOriginalBuilder
tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map(fun _ l -> l |> List.filter(fun (tried, _, _) -> tried))
tcConfig <- TcConfig.Create(tcConfigB, validate=false)]
for folder in additionalIncludeFolders do
tcConfigB.AddIncludePath(m, folder, "")
tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map(fun _ l -> l |> List.map(fun (_, p, m) -> true, p, m))
tcConfig <- TcConfig.Create(tcConfigB, validate=false)
for script in generatedScripts do
let scriptText = File.ReadAllText script
loadScripts.Add script |> ignore
let iSourceText = SourceText.ofString scriptText
yield! loop (ClosureSource(script, m, iSourceText, true))

| false, _, _, _ ->
// Resolution produced errors update packagerManagerLines entries to note these failure
// failed resolutions will no longer be considered
let tcConfigB = tcConfig.CloneOfOriginalBuilder
tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map(fun _ l -> l |> List.filter(fun (tried, _, _) -> tried))
tcConfig <- TcConfig.Create(tcConfigB, validate=false)]
else []

and loop (ClosureSource(filename, m, sourceText, parseRequired)) =
Expand Down
Loading

0 comments on commit 9d69b49

Please sign in to comment.