@@ -1087,10 +1087,14 @@ module internal IncrementalFSharpBuild =
10871087
10881088 /// Global service state
10891089 type FrameworkImportsCacheKey = (* resolvedpath*) string list * string * (* ClrRoot*) string list* (* fsharpBinaries*) string
1090- let private frameworkTcImportsCache = AgedLookup< FrameworkImportsCacheKey,( TcGlobals * TcImports)>( 8 , areSame=( fun ( x , y ) -> x = y))
1091- let ClearFrameworkTcImportsCache () = frameworkTcImportsCache.Clear()
1092- /// This function strips the "System" assemblies from the tcConfig and returns a age-cached TcImports for them.
1093- let GetFrameworkTcImports ( tcConfig : TcConfig ) =
1090+
1091+ type FrameworkImportsCache ( keepStrongly ) =
1092+ let frameworkTcImportsCache = AgedLookup< FrameworkImportsCacheKey,( TcGlobals * TcImports)>( keepStrongly, areSame=( fun ( x , y ) -> x = y))
1093+ member __.Downsize () = frameworkTcImportsCache.Resize( keepStrongly= 0 )
1094+ member __.Clear () = frameworkTcImportsCache.Clear()
1095+
1096+ /// This function strips the "System" assemblies from the tcConfig and returns a age-cached TcImports for them.
1097+ member __.Get ( tcConfig : TcConfig ) =
10941098 // Split into installed and not installed.
10951099 let frameworkDLLs , nonFrameworkResolutions , unresolved = TcAssemblyResolutions.SplitNonFoundationalResolutions( tcConfig)
10961100 let frameworkDLLsKey =
@@ -1188,7 +1192,7 @@ module internal IncrementalFSharpBuild =
11881192 TimeStamp = timestamp }
11891193
11901194
1191- type IncrementalBuilder ( tcConfig : TcConfig , projectDirectory , outfile , assemblyName , niceNameGen : Ast.NiceNameGenerator , lexResourceManager ,
1195+ type IncrementalBuilder ( frameworkTcImportsCache : FrameworkImportsCache , tcConfig : TcConfig , projectDirectory , outfile , assemblyName , niceNameGen : Ast.NiceNameGenerator , lexResourceManager ,
11921196 sourceFiles, projectReferences: IProjectReference list, ensureReactive,
11931197 keepAssemblyContents, keepAllBackgroundResolutions) =
11941198
@@ -1202,7 +1206,7 @@ module internal IncrementalFSharpBuild =
12021206 // Resolve assemblies and create the framework TcImports. This is done when constructing the
12031207 // builder itself, rather than as an incremental task. This caches a level of "system" references. No type providers are
12041208 // included in these references.
1205- let ( tcGlobals , frameworkTcImports , nonFrameworkResolutions , unresolvedReferences ) = GetFrameworkTcImports tcConfig
1209+ let ( tcGlobals , frameworkTcImports , nonFrameworkResolutions , unresolvedReferences ) = frameworkTcImportsCache.Get tcConfig
12061210
12071211 // Check for the existence of loaded sources and prepend them to the sources list if present.
12081212 let sourceFiles = tcConfig.GetAvailableLoadedSources() @ ( sourceFiles |> List.map( fun s -> rangeStartup, s))
@@ -1723,7 +1727,7 @@ module internal IncrementalFSharpBuild =
17231727
17241728 /// CreateIncrementalBuilder (for background type checking). Note that fsc.fs also
17251729 /// creates an incremental builder used by the command line compiler.
1726- static member TryCreateBackgroundBuilderForProjectOptions ( scriptClosureOptions : LoadClosure option , sourceFiles : string list , commandLineArgs : string list , projectReferences , projectDirectory , useScriptResolutionRules , isIncompleteTypeCheckEnvironment , keepAssemblyContents , keepAllBackgroundResolutions ) =
1730+ static member TryCreateBackgroundBuilderForProjectOptions ( frameworkTcImportsCache , scriptClosureOptions : LoadClosure option , sourceFiles : string list , commandLineArgs : string list , projectReferences , projectDirectory , useScriptResolutionRules , isIncompleteTypeCheckEnvironment , keepAssemblyContents , keepAllBackgroundResolutions ) =
17271731
17281732 // Trap and report warnings and errors from creation.
17291733 use errorScope = new ErrorScope()
@@ -1800,7 +1804,8 @@ module internal IncrementalFSharpBuild =
18001804 let outfile , _ , assemblyName = tcConfigB.DecideNames sourceFilesNew
18011805
18021806 let builder =
1803- new IncrementalBuilder( tcConfig, projectDirectory, outfile, assemblyName, niceNameGen,
1807+ new IncrementalBuilder( frameworkTcImportsCache,
1808+ tcConfig, projectDirectory, outfile, assemblyName, niceNameGen,
18041809 resourceManager, sourceFilesNew, projectReferences, ensureReactive= true ,
18051810 keepAssemblyContents= keepAssemblyContents,
18061811 keepAllBackgroundResolutions= keepAllBackgroundResolutions)
0 commit comments