Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcea1aac

Browse files
authored
don't keep parse results in background builder (dotnet#2378)
Likedotnet#2377 this eliminates a source of unnecessarily retained memory - the parse trees from the background build. These are unused in the Visual F# Tools and even if they were needed it is easy to recreate them on-demand.The original code is being kept #if because the FSharp.Compiler.Service buget package component might choose to optionally allow the storage of these, so there's no need to delete the original code path yet* don't keep parse results in background builder* fix memory capture by TcSymbolUses* use struct tuples* fix test
1 parente861d98 commitcea1aac

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

‎src/fsharp/NameResolution.fs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,17 +1393,17 @@ type TcResolutions
13931393
typeTcSymbolUses(g, capturedNameResolutions:ResizeArray<CapturedNameResolution>,formatSpecifierLocations: range[])=
13941394

13951395
// Make sure we only capture the information we really need to report symbol uses
1396-
letcnrs=[|for cnrin capturedNameResolutions-> cnr.Item, cnr.ItemOccurence, cnr.DisplayEnv, cnr.Range|]
1396+
letcnrs=[|for cnrin capturedNameResolutions->struct(cnr.Item, cnr.ItemOccurence, cnr.DisplayEnv, cnr.Range)|]
13971397
letcapturedNameResolutions=()
13981398
do ignore capturedNameResolutions// don't capture this!
13991399

14001400
memberthis.GetUsesOfSymbol(item)=
1401-
[|for(cnrItem,occ,denv,m)in cnrsdo
1401+
[|for(struct(cnrItem,occ,denv,m))in cnrsdo
14021402
if protectAssemblyExplorationfalse(fun()-> ItemsAreEffectivelyEqual g item cnrItem)then
14031403
yield occ, denv, m|]
14041404

14051405
memberthis.GetAllUsesOfSymbols()=
1406-
[|for(cnrItem,occ,denv,m)in cnrsdo
1406+
[|for(struct(cnrItem,occ,denv,m))in cnrsdo
14071407
yield(cnrItem, occ, denv, m)|]
14081408

14091409
memberthis.GetFormatSpecifierLocations()= formatSpecifierLocations

‎src/fsharp/vs/IncrementalBuild.fs‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,18 +1600,24 @@ type IncrementalBuilder(frameworkTcImportsCache: FrameworkImportsCache, tcConfig
16001600

16011601
// Build
16021602
letstampedFileNamesNode= Vector.Stamp"SourceFileTimeStamps" StampFileNameTask fileNamesNode
1603-
letparseTreesNode= Vector.Map"ParseTrees" ParseTask stampedFileNamesNode
16041603
letstampedReferencedAssembliesNode= Vector.Stamp"TimestampReferencedAssembly" TimestampReferencedAssemblyTask referencedAssembliesNode
16051604
letinitialTcAccNode= Vector.Demultiplex"CombineImportedAssemblies" CombineImportedAssembliesTask stampedReferencedAssembliesNode
1606-
lettcStatesNode= Vector.ScanLeft"TypeCheckingStates" TypeCheckTask initialTcAccNode parseTreesNode
1605+
#if FCS_RETAIN_BACKGROUND_PARSE_RESULTS
1606+
letparseTreesNode= Vector.Map"ParseTrees" ParseTask stampedFileNamesNode
1607+
lettcStatesNode= Vector.ScanLeft"TypeCheckingStates" TypeCheckTask initialTcAccNode stampedFileNamesNode
1608+
#else
1609+
lettcStatesNode= Vector.ScanLeft"TypeCheckingStates"(fun tcAcc n-> TypeCheckTask tcAcc(ParseTask n)) initialTcAccNode stampedFileNamesNode
1610+
#endif
16071611
letfinalizedTypeCheckNode= Vector.Demultiplex"FinalizeTypeCheck" FinalizeTypeCheckTask tcStatesNode
16081612

16091613
// Outputs
16101614
letbuildDescription=new BuildDescriptionScope()
16111615

16121616
do buildDescription.DeclareVectorOutput stampedFileNamesNode
16131617
do buildDescription.DeclareVectorOutput stampedReferencedAssembliesNode
1618+
#if FCS_RETAIN_BACKGROUND_PARSE_RESULTS
16141619
do buildDescription.DeclareVectorOutput parseTreesNode
1620+
#endif
16151621
do buildDescription.DeclareVectorOutput tcStatesNode
16161622
do buildDescription.DeclareScalarOutput initialTcAccNode
16171623
do buildDescription.DeclareScalarOutput finalizedTypeCheckNode
@@ -1760,13 +1766,26 @@ type IncrementalBuilder(frameworkTcImportsCache: FrameworkImportsCache, tcConfig
17601766

17611767
memberib.GetParseResultsForFile(filename,ct)=
17621768
letslotOfFile= ib.GetSlotOfFileName filename
1769+
#if FCS_RETAIN_BACKGROUND_PARSE_RESULTS
17631770
match GetVectorResultBySlot(parseTreesNode,slotOfFile,partialBuild)with
17641771
| Some(results,_)-> results
17651772
| None->
17661773
letbuild= IncrementalBuild.EvalUpTo SavePartialBuild ct(parseTreesNode, slotOfFile) partialBuild
17671774
match GetVectorResultBySlot(parseTreesNode,slotOfFile,build)with
17681775
| Some(results,_)-> results
17691776
| None-> failwith"Build was not evaluated, expcted the results to be ready after 'Eval'."
1777+
#else
1778+
letresults=
1779+
match GetVectorResultBySlot(stampedFileNamesNode,slotOfFile,partialBuild)with
1780+
| Some(results,_)-> results
1781+
| None->
1782+
letbuild= IncrementalBuild.EvalUpTo SavePartialBuild ct(stampedFileNamesNode, slotOfFile) partialBuild
1783+
match GetVectorResultBySlot(stampedFileNamesNode,slotOfFile,build)with
1784+
| Some(results,_)-> results
1785+
| None-> failwith"Build was not evaluated, expcted the results to be ready after 'Eval'."
1786+
// re-parse on demand instead of retaining
1787+
ParseTask results
1788+
#endif
17701789

17711790
member__.ProjectFileNames= sourceFiles|> List.map(fun(_,f,_)-> f)
17721791

‎tests/service/ProjectAnalysisTests.fs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4817,7 +4817,11 @@ let ``Test request for parse and check doesn't check whole project`` () =
48174817
backgroundCheckCount.Value|> shouldEqual0
48184818
letcheckResults1= checker.CheckFileInProject(parseResults1, ProjectBig.fileNames.[5],0, ProjectBig.fileSources2.[5], ProjectBig.options)|> Async.RunSynchronously
48194819
letpD,tD= FSharpChecker.GlobalForegroundParseCountStatistic, FSharpChecker.GlobalForegroundTypeCheckCountStatistic
4820-
backgroundParseCount.Value|> shouldEqual10// This could be reduced to 5 - the whole project gets parsed
4820+
#if FCS_RETAIN_BACKGROUND_PARSE_RESULTS
4821+
backgroundParseCount.Value|> shouldEqual10
4822+
#else
4823+
backgroundParseCount.Value|> shouldEqual5
4824+
#endif
48214825
backgroundCheckCount.Value|> shouldEqual5
48224826
(pD- pC)|> shouldEqual0
48234827
(tD- tC)|> shouldEqual1
@@ -4826,15 +4830,23 @@ let ``Test request for parse and check doesn't check whole project`` () =
48264830
letpE,tE= FSharpChecker.GlobalForegroundParseCountStatistic, FSharpChecker.GlobalForegroundTypeCheckCountStatistic
48274831
(pE- pD)|> shouldEqual0
48284832
(tE- tD)|> shouldEqual1
4833+
#if FCS_RETAIN_BACKGROUND_PARSE_RESULTS
48294834
backgroundParseCount.Value|> shouldEqual10// but note, the project does not get reparsed
4835+
#else
4836+
backgroundParseCount.Value|> shouldEqual7// but note, the project does not get reparsed
4837+
#endif
48304838
backgroundCheckCount.Value|> shouldEqual7// only two extra typechecks of files
48314839

48324840
// A subsequent ParseAndCheck of identical source code doesn't do any more anything
48334841
letcheckResults2= checker.ParseAndCheckFileInProject(ProjectBig.fileNames.[7],0, ProjectBig.fileSources2.[7], ProjectBig.options)|> Async.RunSynchronously
48344842
letpF,tF= FSharpChecker.GlobalForegroundParseCountStatistic, FSharpChecker.GlobalForegroundTypeCheckCountStatistic
48354843
(pF- pE)|> shouldEqual0// note, no new parse of the file
48364844
(tF- tE)|> shouldEqual0// note, no new typecheck of the file
4845+
#if FCS_RETAIN_BACKGROUND_PARSE_RESULTS
48374846
backgroundParseCount.Value|> shouldEqual10// but note, the project does not get reparsed
4847+
#else
4848+
backgroundParseCount.Value|> shouldEqual7// but note, the project does not get reparsed
4849+
#endif
48384850
backgroundCheckCount.Value|> shouldEqual7// only two extra typechecks of files
48394851

48404852
()

‎vsintegration/tests/unittests/Tests.LanguageService.Completion.fs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4218,7 +4218,11 @@ let x = query { for bbbb in abbbbc(*D0*) do
42184218
SaveFileToDisk file2
42194219
TakeCoffeeBreak(this.VS)
42204220

4221+
#if FCS_RETAIN_BACKGROUND_PARSE_RESULTS
42214222
gpatcc.AssertExactly(notAA[file2], notAA[file2;file3])
4223+
#else
4224+
gpatcc.AssertExactly(notAA[file2; file3], notAA[file2;file3])
4225+
#endif
42224226

42234227
/// FEATURE: References added to the project bring corresponding new .NET and F# items into scope.
42244228
[<Test;Category("ReproX")>]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp