Skip to content

Commit 9d69b49

Browse files
Refactor integration (#8574)
* 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 <[email protected]> * Update src/fsharp/Interactive.DependencyManager/DependencyManager.fs Co-Authored-By: Phillip Carter <[email protected]> * feedback Co-authored-by: Phillip Carter <[email protected]>
1 parent acd7cfd commit 9d69b49

36 files changed

+992
-488
lines changed

FSharp.sln

+15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.Private.Scr
4848
EndProject
4949
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}"
5050
EndProject
51+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Interactive.DependencyManager", "src\fsharp\Interactive.DependencyManager\Interactive.DependencyManager.fsproj", "{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}"
52+
EndProject
5153
Global
5254
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5355
Debug|Any CPU = Debug|Any CPU
@@ -250,6 +252,18 @@ Global
250252
{4FEDF286-0252-4EBC-9E75-879CCA3B85DC}.Release|Any CPU.Build.0 = Release|Any CPU
251253
{4FEDF286-0252-4EBC-9E75-879CCA3B85DC}.Release|x86.ActiveCfg = Release|Any CPU
252254
{4FEDF286-0252-4EBC-9E75-879CCA3B85DC}.Release|x86.Build.0 = Release|Any CPU
255+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
256+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
257+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Debug|x86.ActiveCfg = Debug|Any CPU
258+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Debug|x86.Build.0 = Debug|Any CPU
259+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Proto|Any CPU.ActiveCfg = Debug|Any CPU
260+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Proto|Any CPU.Build.0 = Debug|Any CPU
261+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Proto|x86.ActiveCfg = Debug|Any CPU
262+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Proto|x86.Build.0 = Debug|Any CPU
263+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
264+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Release|Any CPU.Build.0 = Release|Any CPU
265+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Release|x86.ActiveCfg = Release|Any CPU
266+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6}.Release|x86.Build.0 = Release|Any CPU
253267
EndGlobalSection
254268
GlobalSection(SolutionProperties) = preSolution
255269
HideSolutionNode = FALSE
@@ -270,6 +284,7 @@ Global
270284
{8B7BF62E-7D8C-4928-BE40-4E392A9EE851} = {3881429D-A97A-49EB-B7AE-A82BA5FE9C77}
271285
{6771860A-614D-4FDD-A655-4C70EBCC91B0} = {B8DDA694-7939-42E3-95E5-265C2217C142}
272286
{4FEDF286-0252-4EBC-9E75-879CCA3B85DC} = {CFE3259A-2D30-4EB0-80D5-E8B5F3D01449}
287+
{B5A043F8-6D7F-4D4E-B8AD-5880070180B6} = {3881429D-A97A-49EB-B7AE-A82BA5FE9C77}
273288
EndGlobalSection
274289
GlobalSection(ExtensibilityGlobals) = postSolution
275290
SolutionGuid = {BD5177C7-1380-40E7-94D2-7768E1A8B1B8}

VisualFSharp.sln

+15
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibraryProject", "vsintegra
160160
EndProject
161161
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TutorialProject", "vsintegration\ProjectTemplates\TutorialProject\TutorialProject.csproj", "{2937CBEC-262D-4C94-BE1D-291FAB72E3E8}"
162162
EndProject
163+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Interactive.DependencyManager", "src\fsharp\Interactive.DependencyManager\Interactive.DependencyManager.fsproj", "{C2F38485-5F87-4986-985B-55D7ED96D5CE}"
164+
EndProject
163165
Global
164166
GlobalSection(SolutionConfigurationPlatforms) = preSolution
165167
Debug|Any CPU = Debug|Any CPU
@@ -926,6 +928,18 @@ Global
926928
{2937CBEC-262D-4C94-BE1D-291FAB72E3E8}.Release|Any CPU.Build.0 = Release|Any CPU
927929
{2937CBEC-262D-4C94-BE1D-291FAB72E3E8}.Release|x86.ActiveCfg = Release|Any CPU
928930
{2937CBEC-262D-4C94-BE1D-291FAB72E3E8}.Release|x86.Build.0 = Release|Any CPU
931+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
932+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
933+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Debug|x86.ActiveCfg = Debug|Any CPU
934+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Debug|x86.Build.0 = Debug|Any CPU
935+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Proto|Any CPU.ActiveCfg = Debug|Any CPU
936+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Proto|Any CPU.Build.0 = Debug|Any CPU
937+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Proto|x86.ActiveCfg = Debug|Any CPU
938+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Proto|x86.Build.0 = Debug|Any CPU
939+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
940+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Release|Any CPU.Build.0 = Release|Any CPU
941+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Release|x86.ActiveCfg = Release|Any CPU
942+
{C2F38485-5F87-4986-985B-55D7ED96D5CE}.Release|x86.Build.0 = Release|Any CPU
929943
EndGlobalSection
930944
GlobalSection(SolutionProperties) = preSolution
931945
HideSolutionNode = FALSE
@@ -1001,6 +1015,7 @@ Global
10011015
{44155269-9B30-43DA-B97F-4F36F887B211} = {12EF27FD-A34B-4373-860A-F9FCE9651859}
10021016
{B53D9D05-8EF7-43A6-9A5B-0B113CBC54F8} = {12EF27FD-A34B-4373-860A-F9FCE9651859}
10031017
{2937CBEC-262D-4C94-BE1D-291FAB72E3E8} = {12EF27FD-A34B-4373-860A-F9FCE9651859}
1018+
{C2F38485-5F87-4986-985B-55D7ED96D5CE} = {3881429D-A97A-49EB-B7AE-A82BA5FE9C77}
10041019
EndGlobalSection
10051020
GlobalSection(ExtensibilityGlobals) = postSolution
10061021
SolutionGuid = {48EDBBBE-C8EE-4E3C-8B19-97184A487B37}

fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj

+7-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
<EmbeddedText Include="$(FSharpSourcesRoot)\fsharp\FSComp.txt">
4747
<Link>FSComp.txt</Link>
4848
</EmbeddedText>
49+
<EmbeddedText Include="$(FSharpSourcesRoot)\fsharp\Interactive.DependencyManager\InteractiveDependencyManager.txt">
50+
<Link>InteractiveDependencyManager.txt</Link>
51+
</EmbeddedText>
4952
<EmbeddedText Include="$(FSharpSourcesRoot)\fsharp\fsi\FSIstrings.txt">
5053
<Link>FSIstrings.txt</Link>
5154
</EmbeddedText>
@@ -519,11 +522,11 @@
519522
<Compile Include="$(FSharpSourcesRoot)/fsharp/DotNetFrameworkDependencies.fs">
520523
<Link>Driver\DotNetFrameworkDependencies.fs</Link>
521524
</Compile>
522-
<Compile Include="$(FSharpSourcesRoot)/fsharp/DependencyManager.Integration.fsi">
523-
<Link>Driver/DependencyManager.Integration.fsi</Link>
525+
<Compile Include="$(FSharpSourcesRoot)/fsharp/Interactive.DependencyManager/DependencyManager.fsi">
526+
<Link>Driver/DependencyManager.fsi</Link>
524527
</Compile>
525-
<Compile Include="$(FSharpSourcesRoot)/fsharp/DependencyManager.Integration.fs">
526-
<Link>Driver/DependencyManager.Integration.fs</Link>
528+
<Compile Include="$(FSharpSourcesRoot)/fsharp/Interactive.DependencyManager/DependencyManager.fs">
529+
<Link>Driver/DependencyManager.fs</Link>
527530
</Compile>
528531
<Compile Include="$(FSharpSourcesRoot)/fsharp/CompileOps.fsi">
529532
<Link>Driver/CompileOps.fsi</Link>

src/fsharp/CompileOps.fs

+75-58
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ open FSharp.Compiler.Text
5151

5252
open FSharp.Compiler.DotNetFrameworkDependencies
5353

54+
open Interactive.DependencyManager
55+
5456
#if !NO_EXTENSIONTYPING
5557
open FSharp.Compiler.ExtensionTyping
5658
open Microsoft.FSharp.Core.CompilerServices
@@ -2235,8 +2237,8 @@ type TcConfigBuilder =
22352237
mutable shadowCopyReferences: bool
22362238
mutable useSdkRefs: bool
22372239

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

22422244
mutable internalTestSpanStackReferring: bool
@@ -2246,6 +2248,8 @@ type TcConfigBuilder =
22462248
mutable pathMap: PathMap
22472249

22482250
mutable langVersion: LanguageVersion
2251+
2252+
mutable dependencyProvider: DependencyProvider
22492253
}
22502254

22512255
static member Initial =
@@ -2386,6 +2390,7 @@ type TcConfigBuilder =
23862390
noConditionalErasure = false
23872391
pathMap = PathMap.empty
23882392
langVersion = LanguageVersion("default")
2393+
dependencyProvider = new DependencyProvider()
23892394
}
23902395

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

2498-
24992503
member tcConfigB.AddEmbeddedSourceFile (file) =
25002504
tcConfigB.embedSourceList <- tcConfigB.embedSourceList ++ file
25012505

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

2518-
member tcConfigB.AddDependencyManagerText (packageManager:DependencyManagerIntegration.IDependencyManagerProvider, m, path:string) =
2519-
let path = DependencyManagerIntegration.removeDependencyManagerKey packageManager.Key path
2522+
member tcConfigB.AddDependencyManagerText (packageManager:IDependencyManagerProvider, m, path:string) =
2523+
let path = tcConfigB.dependencyProvider.RemoveDependencyManagerKey(packageManager.Key, path)
25202524

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

28442848
member x.legacyReferenceResolver = data.legacyReferenceResolver
2849+
2850+
member x.dependencyProvider = data.dependencyProvider
2851+
28452852
member tcConfig.CloneOfOriginalBuilder =
28462853
{ data with conditionalCompilationDefines=data.conditionalCompilationDefines }
28472854

@@ -4924,7 +4931,7 @@ let RequireDLL (ctok, tcImports: TcImports, tcEnv, thisAssemblyName, m, file) =
49244931
let ProcessMetaCommandsFromInput
49254932
(nowarnF: 'state -> range * string -> 'state,
49264933
dllRequireF: 'state -> range * string -> 'state,
4927-
packageRequireF: 'state -> DependencyManagerIntegration.IDependencyManagerProvider * range * string -> 'state,
4934+
packageRequireF: 'state -> IDependencyManagerProvider * range * string -> 'state,
49284935
loadSourceF: 'state -> range * string -> unit)
49294936
(tcConfig:TcConfigBuilder, inp, pathOfMetaCommandSource, state0) =
49304937

@@ -4944,7 +4951,7 @@ let ProcessMetaCommandsFromInput
49444951
errorR(HashIncludeNotAllowedInNonScript m)
49454952
match args with
49464953
| [path] ->
4947-
matchedm<-m
4954+
matchedm <- m
49484955
tcConfig.AddIncludePath(m, path, pathOfMetaCommandSource)
49494956
state
49504957
| _ ->
@@ -4954,27 +4961,35 @@ let ProcessMetaCommandsFromInput
49544961
List.fold (fun state d -> nowarnF state (m,d)) state numbers
49554962

49564963
| ParsedHashDirective(("reference" | "r"),args,m) ->
4957-
if not canHaveScriptMetaCommands then
4958-
errorR(HashReferenceNotAllowedInNonScript m)
4964+
if not canHaveScriptMetaCommands then
4965+
errorR(HashReferenceNotAllowedInNonScript m)
4966+
4967+
let reportError errorType error =
4968+
match errorType with
4969+
| ErrorReportType.Warning -> warning(Error(error,m))
4970+
| ErrorReportType.Error -> errorR(Error(error, m))
4971+
4972+
match args with
4973+
| [path] ->
4974+
matchedm <- m
4975+
let output = tcConfig.outputDir |> Option.defaultValue ""
4976+
let dm = tcConfig.dependencyProvider.TryFindDependencyManagerInPath(tcConfig.compilerToolPaths, output , reportError, path)
4977+
match dm with
4978+
| dllpath, null when String.IsNullOrWhiteSpace(dllpath) ->
4979+
state // error already reported
4980+
4981+
| _, dependencyManager when not(isNull dependencyManager) ->
4982+
if tcConfig.langVersion.SupportsFeature(LanguageFeature.PackageManagement) then
4983+
packageRequireF state (dependencyManager, m, path)
4984+
else
4985+
errorR(Error(FSComp.SR.packageManagementRequiresVFive(), m))
4986+
state
49594987

4960-
match args with
4961-
| [path] ->
4962-
matchedm <- m
4963-
match DependencyManagerIntegration.tryFindDependencyManagerInPath tcConfig.compilerToolPaths tcConfig.outputDir m (path:string) with
4964-
| DependencyManagerIntegration.ReferenceType.RegisteredDependencyManager packageManager ->
4965-
if tcConfig.langVersion.SupportsFeature(LanguageFeature.PackageManagement) then
4966-
packageRequireF state (packageManager,m,path)
4967-
else
4968-
errorR(Error(FSComp.SR.packageManagementRequiresVFive(), m))
4969-
state
4970-
4971-
// #r "Assembly"
4972-
| DependencyManagerIntegration.ReferenceType.Library path ->
4973-
dllRequireF state (m,path)
4974-
4975-
| DependencyManagerIntegration.ReferenceType.UnknownType ->
4976-
state // error already reported
4977-
| _ ->
4988+
// #r "Assembly"
4989+
| path, _ ->
4990+
dllRequireF state (m, path)
4991+
4992+
| _ ->
49784993
errorR(Error(FSComp.SR.buildInvalidHashrDirective(), m))
49794994
state
49804995

@@ -5227,10 +5242,10 @@ module ScriptPreprocessClosure =
52275242
// Recover by using a default TcConfig.
52285243
let tcConfigB = tcConfig.CloneOfOriginalBuilder
52295244
TcConfig.Create(tcConfigB, validate=false), nowarns
5230-
5245+
52315246
let FindClosureFiles(mainFile, _m, closureSources, origTcConfig:TcConfig, codeContext, lexResourceManager: Lexhelp.LexResourceManager) =
52325247
let mutable tcConfig = origTcConfig
5233-
5248+
52345249
let observedSources = Observed()
52355250
let loadScripts = HashSet<_>()
52365251

@@ -5242,41 +5257,43 @@ module ScriptPreprocessClosure =
52425257
match packageManagerLines with
52435258
| [] -> ()
52445259
| (_, _, m)::_ ->
5260+
let reportError errorType error =
5261+
match errorType with
5262+
| ErrorReportType.Warning -> warning(Error(error,m))
5263+
| ErrorReportType.Error -> errorR(Error(error, m))
5264+
52455265
match origTcConfig.packageManagerLines |> Map.tryFind packageManagerKey with
52465266
| Some oldDependencyManagerLines when oldDependencyManagerLines = packageManagerLines -> ()
52475267
| _ ->
5248-
match DependencyManagerIntegration.tryFindDependencyManagerByKey tcConfig.compilerToolPaths tcConfig.outputDir m packageManagerKey with
5249-
| None ->
5250-
errorR(DependencyManagerIntegration.createPackageManagerUnknownError tcConfig.compilerToolPaths tcConfig.outputDir packageManagerKey m)
5251-
| Some packageManager ->
5268+
let outputDir = tcConfig.outputDir |> Option.defaultValue ""
5269+
match tcConfig.dependencyProvider.TryFindDependencyManagerByKey(tcConfig.compilerToolPaths, outputDir, reportError, packageManagerKey) with
5270+
| null ->
5271+
errorR(Error(tcConfig.dependencyProvider.CreatePackageManagerUnknownError(tcConfig.compilerToolPaths, outputDir, packageManagerKey, reportError), m))
5272+
5273+
| dependencyManager ->
52525274
let inline snd3 (_, b, _) = b
52535275
let packageManagerTextLines = packageManagerLines |> List.map snd3
5254-
5255-
match DependencyManagerIntegration.resolve packageManager tcConfig.implicitIncludeDir mainFile scriptName ".fsx" m packageManagerTextLines with
5256-
| None -> () // error already reported
5257-
| Some (succeeded, generatedScripts, additionalIncludeFolders) ->
5258-
// This may incrementally update tcConfig too with new #r references
5259-
// New package text is ignored on this second phase
5260-
match succeeded with
5261-
| true ->
5262-
// Resolution produced no errors
5263-
if not (isNil additionalIncludeFolders) then
5264-
let tcConfigB = tcConfig.CloneOfOriginalBuilder
5265-
for folder in additionalIncludeFolders do
5266-
tcConfigB.AddIncludePath(m, folder, "")
5267-
tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map(fun _ l -> l |> List.map(fun (_, p, m) -> true, p, m))
5268-
tcConfig <- TcConfig.Create(tcConfigB, validate=false)
5269-
for script in generatedScripts do
5270-
let scriptText = File.ReadAllText script
5271-
loadScripts.Add script |> ignore
5272-
let iSourceText = SourceText.ofString scriptText
5273-
yield! loop (ClosureSource(script, m, iSourceText, true))
5274-
| false ->
5275-
// Resolution produced errors update packagerManagerLines entries to note these failure
5276-
// failed resolutions will no longer be considered
5276+
match tcConfig.dependencyProvider.Resolve(dependencyManager, tcConfig.implicitIncludeDir, mainFile, scriptName, ".fsx", packageManagerTextLines, reportError, executionTfm) with
5277+
| true, _references, generatedScripts, additionalIncludeFolders ->
5278+
// Resolution produced no errors
5279+
if not (Seq.isEmpty additionalIncludeFolders) then
52775280
let tcConfigB = tcConfig.CloneOfOriginalBuilder
5278-
tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map(fun _ l -> l |> List.filter(fun (tried, _, _) -> tried))
5279-
tcConfig <- TcConfig.Create(tcConfigB, validate=false)]
5281+
for folder in additionalIncludeFolders do
5282+
tcConfigB.AddIncludePath(m, folder, "")
5283+
tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map(fun _ l -> l |> List.map(fun (_, p, m) -> true, p, m))
5284+
tcConfig <- TcConfig.Create(tcConfigB, validate=false)
5285+
for script in generatedScripts do
5286+
let scriptText = File.ReadAllText script
5287+
loadScripts.Add script |> ignore
5288+
let iSourceText = SourceText.ofString scriptText
5289+
yield! loop (ClosureSource(script, m, iSourceText, true))
5290+
5291+
| false, _, _, _ ->
5292+
// Resolution produced errors update packagerManagerLines entries to note these failure
5293+
// failed resolutions will no longer be considered
5294+
let tcConfigB = tcConfig.CloneOfOriginalBuilder
5295+
tcConfigB.packageManagerLines <- tcConfigB.packageManagerLines |> Map.map(fun _ l -> l |> List.filter(fun (tried, _, _) -> tried))
5296+
tcConfig <- TcConfig.Create(tcConfigB, validate=false)]
52805297
else []
52815298

52825299
and loop (ClosureSource(filename, m, sourceText, parseRequired)) =

0 commit comments

Comments
 (0)