Skip to content

Commit f96e31b

Browse files
committed
Merge pull request #259 from dsyme/memfix-1
Fixes to clarify feature to reduce background checker memory usage
2 parents 17df5b3 + 7bd5348 commit f96e31b

File tree

6 files changed

+84
-43
lines changed

6 files changed

+84
-43
lines changed

src/fsharp/nameres.fs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,20 +1275,25 @@ type CapturedNameResolution(p:pos, i:Item, io:ItemOccurence, de:DisplayEnv, nre:
12751275
sprintf "%A: %+A" (p.Line, p.Column) i
12761276

12771277
/// Represents container for all name resolutions that were met so far when typechecking some particular file
1278-
/// Has reference to the container for the previous file so at some point we can access results of all name resolution that happen before
12791278
type TcResolutions
1280-
(g,
1281-
capturedEnvs : ResizeArray<range * NameResolutionEnv * AccessorDomain>,
1279+
(capturedEnvs : ResizeArray<range * NameResolutionEnv * AccessorDomain>,
12821280
capturedExprTypes : ResizeArray<pos * TType * DisplayEnv * NameResolutionEnv * AccessorDomain * range>,
12831281
capturedNameResolutions : ResizeArray<CapturedNameResolution>,
1284-
capturedMethodGroupResolutions : ResizeArray<CapturedNameResolution>
1285-
) =
1282+
capturedMethodGroupResolutions : ResizeArray<CapturedNameResolution>) =
12861283

1284+
static let empty = TcResolutions(ResizeArray(0),ResizeArray(0),ResizeArray(0),ResizeArray(0))
1285+
12871286
member this.CapturedEnvs = capturedEnvs
12881287
member this.CapturedExpressionTypings = capturedExprTypes
12891288
member this.CapturedNameResolutions = capturedNameResolutions
12901289
member this.CapturedMethodGroupResolutions = capturedMethodGroupResolutions
12911290

1291+
static member Empty = empty
1292+
1293+
1294+
/// Represents container for all name resolutions that were met so far when typechecking some particular file
1295+
type TcSymbolUses(g,capturedNameResolutions : ResizeArray<CapturedNameResolution>) =
1296+
12921297
member this.GetUsesOfSymbol(item) =
12931298
[| for cnr in capturedNameResolutions do
12941299
if protectAssemblyExploration false (fun () -> ItemsAreEffectivelyEqual g item cnr.Item) then
@@ -1300,17 +1305,23 @@ type TcResolutions
13001305

13011306
/// An accumulator for the results being emitted into the tcSink.
13021307
type TcResultsSinkImpl(g) =
1303-
let capturedEnvs = new ResizeArray<_>(100)
1304-
let capturedExprTypings = new ResizeArray<_>(100)
1305-
let capturedNameResolutions = new ResizeArray<_>(100)
1308+
let capturedEnvs = ResizeArray<_>()
1309+
let capturedExprTypings = ResizeArray<_>()
1310+
let capturedNameResolutions = ResizeArray<_>()
13061311
let capturedNameResolutionIdentifiers =
13071312
new System.Collections.Generic.Dictionary<pos * string, unit>
13081313
( { new IEqualityComparer<_> with
13091314
member __.GetHashCode((p:pos,i)) = p.Line + 101 * p.Column + hash i
13101315
member __.Equals((p1,i1),(p2,i2)) = posEq p1 p2 && i1 = i2 } )
1311-
let capturedMethodGroupResolutions = new ResizeArray<_>(100)
1316+
let capturedMethodGroupResolutions = ResizeArray<_>()
13121317
let allowedRange (m:range) = not m.IsSynthetic
1313-
member this.GetTcResolutions() = TcResolutions(g, capturedEnvs, capturedExprTypings, capturedNameResolutions, capturedMethodGroupResolutions)
1318+
1319+
member this.GetResolutions() =
1320+
TcResolutions(capturedEnvs, capturedExprTypings, capturedNameResolutions, capturedMethodGroupResolutions)
1321+
1322+
member this.GetSymbolUses() =
1323+
TcSymbolUses(g, capturedNameResolutions)
1324+
13141325
interface ITypecheckResultsSink with
13151326
member sink.NotifyEnvWithScope(m,nenv,ad) =
13161327
if allowedRange m then

src/fsharp/nameres.fsi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,28 @@ type internal CapturedNameResolution =
204204

205205
[<Class>]
206206
type internal TcResolutions =
207+
207208
/// Name resolution environments for every interesting region in the file. These regions may
208209
/// overlap, in which case the smallest region applicable should be used.
209210
member CapturedEnvs : ResizeArray<range * NameResolutionEnv * AccessorDomain>
211+
210212
/// Information of exact types found for expressions, that can be to the left of a dot.
211213
/// typ - the inferred type for an expression
212214
member CapturedExpressionTypings : ResizeArray<pos * TType * DisplayEnv * NameResolutionEnv * AccessorDomain * range>
215+
213216
/// Exact name resolutions
214217
member CapturedNameResolutions : ResizeArray<CapturedNameResolution>
218+
215219
member CapturedMethodGroupResolutions : ResizeArray<CapturedNameResolution>
220+
221+
static member Empty : TcResolutions
222+
223+
224+
[<Class>]
225+
type internal TcSymbolUses =
226+
216227
member GetUsesOfSymbol : Item -> (ItemOccurence * DisplayEnv * range)[]
228+
217229
member GetAllUsesOfSymbols : unit -> (Item * ItemOccurence * DisplayEnv * range)[]
218230

219231
/// An abstract type for reporting the results of name resolution and type checking
@@ -224,7 +236,8 @@ type ITypecheckResultsSink =
224236

225237
type internal TcResultsSinkImpl =
226238
new : tcGlobals : TcGlobals -> TcResultsSinkImpl
227-
member GetTcResolutions : unit -> TcResolutions
239+
member GetResolutions : unit -> TcResolutions
240+
member GetSymbolUses : unit -> TcSymbolUses
228241
interface ITypecheckResultsSink
229242

230243
/// An abstract type for reporting the results of name resolution and type checking, and which allows

src/fsharp/vs/IncrementalBuild.fs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ module internal IncrementalFSharpBuild =
10661066
tcConfig:TcConfig
10671067
tcEnvAtEndOfFile: TcEnv
10681068
tcResolutions: Nameres.TcResolutions list
1069+
tcSymbolUses: Nameres.TcSymbolUses list
10691070
topAttribs:TopAttribs option
10701071
typedImplFiles:TypedImplFile list
10711072
tcErrors:(PhasedError * FSharpErrorSeverity) list } // errors=true, warnings=false
@@ -1168,6 +1169,7 @@ module internal IncrementalFSharpBuild =
11681169
TcEnvAtEnd : TypeChecker.TcEnv
11691170
Errors : (PhasedError * FSharpErrorSeverity) list
11701171
TcResolutions: Nameres.TcResolutions list
1172+
TcSymbolUses: Nameres.TcSymbolUses list
11711173
TimeStamp: System.DateTime }
11721174

11731175
let GetPartialCheckResults (tcAcc: TypeCheckAccumulator, timestamp) =
@@ -1178,13 +1180,14 @@ module internal IncrementalFSharpBuild =
11781180
TcEnvAtEnd = tcAcc.tcEnvAtEndOfFile
11791181
Errors = tcAcc.tcErrors
11801182
TcResolutions = tcAcc.tcResolutions
1183+
TcSymbolUses = tcAcc.tcSymbolUses
11811184
TimeStamp = timestamp }
11821185

11831186

11841187
type IncrementalBuilder(tcConfig : TcConfig, projectDirectory, outfile, assemblyName, niceNameGen : Ast.NiceNameGenerator, lexResourceManager,
1185-
sourceFiles:string list, projectReferences: IProjectReference list, ensureReactive,
1186-
keepAssemblyContents:bool)
1187-
=
1188+
sourceFiles, projectReferences: IProjectReference list, ensureReactive,
1189+
keepAssemblyContents, keepAllBackgroundResolutions) =
1190+
11881191
let tcConfigP = TcConfigProvider.Constant(tcConfig)
11891192
let importsInvalidated = new Event<string>()
11901193
let fileParsed = new Event<_>()
@@ -1354,6 +1357,7 @@ module internal IncrementalFSharpBuild =
13541357
tcConfig=tcConfig
13551358
tcEnvAtEndOfFile=tcEnv0
13561359
tcResolutions=[]
1360+
tcSymbolUses=[]
13571361
topAttribs=None
13581362
typedImplFiles=[]
13591363
tcErrors=errorLogger.GetErrors() }
@@ -1386,13 +1390,15 @@ module internal IncrementalFSharpBuild =
13861390

13871391
/// Only keep the typed interface files when doing a "full" build for fsc.exe, otherwise just throw them away
13881392
let typedImplFiles = if keepAssemblyContents then typedImplFiles else []
1389-
let tcResolution = sink.GetTcResolutions()
1393+
let tcResolutions = if keepAllBackgroundResolutions then sink.GetResolutions() else Nameres.TcResolutions.Empty
1394+
let tcSymbolUses = sink.GetSymbolUses()
13901395
fileChecked.Trigger filename
13911396
return {tcAcc with tcState=tcState
13921397
tcEnvAtEndOfFile=tcEnvAtEndOfFile
13931398
topAttribs=Some topAttribs
13941399
typedImplFiles=typedImplFiles
1395-
tcResolutions=tcAcc.tcResolutions @ [tcResolution]
1400+
tcResolutions=tcAcc.tcResolutions @ [tcResolutions]
1401+
tcSymbolUses=tcAcc.tcSymbolUses @ [tcSymbolUses]
13961402
tcErrors = tcAcc.tcErrors @ parseErrors @ capturingErrorLogger.GetErrors() }
13971403
}
13981404

@@ -1709,7 +1715,7 @@ module internal IncrementalFSharpBuild =
17091715

17101716
/// CreateIncrementalBuilder (for background type checking). Note that fsc.fs also
17111717
/// creates an incremental builder used by the command line compiler.
1712-
static member TryCreateBackgroundBuilderForProjectOptions (scriptClosureOptions:LoadClosure option, sourceFiles:string list, commandLineArgs:string list, projectReferences, projectDirectory, useScriptResolutionRules, isIncompleteTypeCheckEnvironment, keepAssemblyContents) =
1718+
static member TryCreateBackgroundBuilderForProjectOptions (scriptClosureOptions:LoadClosure option, sourceFiles:string list, commandLineArgs:string list, projectReferences, projectDirectory, useScriptResolutionRules, isIncompleteTypeCheckEnvironment, keepAssemblyContents, keepAllBackgroundResolutions) =
17131719

17141720
// Trap and report warnings and errors from creation.
17151721
use errorScope = new ErrorScope()
@@ -1788,7 +1794,8 @@ module internal IncrementalFSharpBuild =
17881794
let builder =
17891795
new IncrementalBuilder(tcConfig, projectDirectory, outfile, assemblyName, niceNameGen,
17901796
resourceManager, sourceFilesNew, projectReferences, ensureReactive=true,
1791-
keepAssemblyContents=keepAssemblyContents)
1797+
keepAssemblyContents=keepAssemblyContents,
1798+
keepAllBackgroundResolutions=keepAllBackgroundResolutions)
17921799
Some builder
17931800
with e ->
17941801
errorRecoveryNoRange e

src/fsharp/vs/IncrementalBuild.fsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module internal IncrementalFSharpBuild =
5757
TcEnvAtEnd : TypeChecker.TcEnv
5858
Errors : (PhasedError * FSharpErrorSeverity) list
5959
TcResolutions: Nameres.TcResolutions list
60+
TcSymbolUses: Nameres.TcSymbolUses list
6061
TimeStamp: DateTime }
6162

6263
[<Class>]
@@ -144,7 +145,7 @@ module internal IncrementalFSharpBuild =
144145
/// This may be a marginally long-running operation (parses are relatively quick, only one file needs to be parsed)
145146
member GetParseResultsForFile : filename:string -> Ast.ParsedInput option * Range.range * string * (PhasedError * FSharpErrorSeverity) list
146147

147-
static member TryCreateBackgroundBuilderForProjectOptions : scriptClosureOptions:LoadClosure option * sourceFiles:string list * commandLineArgs:string list * projectReferences: IProjectReference list * projectDirectory:string * useScriptResolutionRules:bool * isIncompleteTypeCheckEnvironment : bool * keepAssemblyContents: bool -> IncrementalBuilder option * FSharpErrorInfo list
148+
static member TryCreateBackgroundBuilderForProjectOptions : scriptClosureOptions:LoadClosure option * sourceFiles:string list * commandLineArgs:string list * projectReferences: IProjectReference list * projectDirectory:string * useScriptResolutionRules:bool * isIncompleteTypeCheckEnvironment : bool * keepAssemblyContents: bool * keepAllBackgroundResolutions: bool -> IncrementalBuilder option * FSharpErrorInfo list
148149

149150
[<Obsolete("This type has been renamed to FSharpErrorInfo")>]
150151
/// Renamed to FSharpErrorInfo

0 commit comments

Comments
 (0)