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

Commitb7c2099

Browse files
forkidsyme
authored andcommitted
Reduce intermediate collections when checking symboluse (dotnet#4442)
1 parent214475e commitb7c2099

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

‎src/fsharp/NameResolution.fs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,20 +1450,18 @@ type TcSymbolUseData =
14501450
typeTcSymbolUses(g, capturedNameResolutions:ResizeArray<CapturedNameResolution>,formatSpecifierLocations:(range*int)[])=
14511451

14521452
// Make sure we only capture the information we really need to report symbol uses
1453-
letcnrs=[|for cnrin capturedNameResolutions->{ Item=cnr.Item; ItemOccurence=cnr.ItemOccurence; DisplayEnv=cnr.DisplayEnv; Range=cnr.Range}|]
1453+
letallUsesOfSymbols=[|for cnrin capturedNameResolutions->{ Item=cnr.Item; ItemOccurence=cnr.ItemOccurence; DisplayEnv=cnr.DisplayEnv; Range=cnr.Range}|]
14541454
letcapturedNameResolutions=()
14551455
do ignore capturedNameResolutions// don't capture this!
14561456

14571457
memberthis.GetUsesOfSymbol(item)=
1458-
[|forcnrincnrsdo
1459-
if protectAssemblyExplorationfalse(fun()-> ItemsAreEffectivelyEqual g itemcnr.Item)then
1460-
yield(cnr.ItemOccurence, cnr.DisplayEnv, cnr.Range)|]
1458+
[|forsymbolUseinallUsesOfSymbolsdo
1459+
if protectAssemblyExplorationfalse(fun()-> ItemsAreEffectivelyEqual g itemsymbolUse.Item)then
1460+
yieldsymbolUse|]
14611461

1462-
memberthis.GetAllUsesOfSymbols()=
1463-
[|for cnrin cnrsdo
1464-
yield(cnr.Item, cnr.ItemOccurence, cnr.DisplayEnv, cnr.Range)|]
1462+
memberthis.AllUsesOfSymbols= allUsesOfSymbols
14651463

1466-
memberthis.GetFormatSpecifierLocationsAndArity()=formatSpecifierLocations
1464+
memberthis.GetFormatSpecifierLocationsAndArity()= formatSpecifierLocations
14671465

14681466

14691467
/// An accumulator for the results being emitted into the tcSink.

‎src/fsharp/NameResolution.fsi‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,22 @@ type internal TcResolutions =
298298
static memberEmpty:TcResolutions
299299

300300

301+
[<Struct>]
302+
type TcSymbolUseData=
303+
{ Item:Item
304+
ItemOccurence:ItemOccurence
305+
DisplayEnv:DisplayEnv
306+
Range:range}
307+
301308
[<Class>]
302309
/// Represents container for all name resolutions that were met so far when typechecking some particular file
303310
typeinternalTcSymbolUses=
304311

305312
/// Get all the uses of a particular item within the file
306-
memberGetUsesOfSymbol:Item->(ItemOccurence* DisplayEnv* range)[]
313+
memberGetUsesOfSymbol:Item->TcSymbolUseData[]
307314

308-
///Get all the uses of all items within the file
309-
memberGetAllUsesOfSymbols:unit->(Item* ItemOccurence* DisplayEnv* range)[]
315+
///All the uses of all items within the file
316+
memberAllUsesOfSymbols:TcSymbolUseData[]
310317

311318
/// Get the locations of all the printf format specifiers in the file
312319
memberGetFormatSpecifierLocationsAndArity:unit->(range* int)[]

‎src/fsharp/service/service.fs‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,22 +1855,23 @@ type FSharpCheckProjectResults(projectFileName:string, tcConfigOption, keepAssem
18551855
memberinfo.GetUsesOfSymbol(symbol:FSharpSymbol)=
18561856
let(tcGlobals,_tcImports,_thisCcu,_ccuSig,tcSymbolUses,_topAttribs,_tcAssemblyData,_ilAssemRef,_ad,_tcAssemblyExpr,_dependencyFiles)= getDetails()
18571857

1858-
[|for rin tcSymbolUsesdoyield! r.GetUsesOfSymbol(symbol.Item)|]
1859-
|> Seq.distinctBy(fun(itemOcc,_denv,m)-> itemOcc, m)
1860-
|> Seq.filter(fun(itemOcc,_,_)-> itemOcc<> ItemOccurence.RelatedText)
1861-
|> Seq.map(fun(itemOcc,denv,m)-> FSharpSymbolUse(tcGlobals, denv, symbol, itemOcc, m))
1858+
tcSymbolUses
1859+
|> Seq.collect(fun r-> r.GetUsesOfSymbol symbol.Item)
1860+
|> Seq.distinctBy(fun symbolUse-> symbolUse.ItemOccurence, symbolUse.Range)
1861+
|> Seq.filter(fun symbolUse-> symbolUse.ItemOccurence<> ItemOccurence.RelatedText)
1862+
|> Seq.map(fun symbolUse-> FSharpSymbolUse(tcGlobals, symbolUse.DisplayEnv, symbol, symbolUse.ItemOccurence, symbolUse.Range))
18621863
|> Seq.toArray
18631864
|> async.Return
18641865

18651866
// Not, this does not have to be a SyncOp, it can be called from any thread
18661867
memberinfo.GetAllUsesOfAllSymbols()=
18671868
let(tcGlobals,tcImports,thisCcu,_ccuSig,tcSymbolUses,_topAttribs,_tcAssemblyData,_ilAssemRef,_ad,_tcAssemblyExpr,_dependencyFiles)= getDetails()
18681869

1869-
[|for rin tcSymbolUsesdo
1870-
for(item,itemOcc,denv,m)in r.GetAllUsesOfSymbols()do
1871-
ifitemOcc<> ItemOccurence.RelatedTextthen
1872-
letsymbol= FSharpSymbol.Create(tcGlobals, thisCcu, tcImports,item)
1873-
yield FSharpSymbolUse(tcGlobals,denv, symbol,itemOcc, m)|]
1870+
[|for rin tcSymbolUsesdo
1871+
forsymbolUsein r.AllUsesOfSymbolsdo
1872+
ifsymbolUse.ItemOccurence<> ItemOccurence.RelatedTextthen
1873+
letsymbol= FSharpSymbol.Create(tcGlobals, thisCcu, tcImports,symbolUse.Item)
1874+
yield FSharpSymbolUse(tcGlobals,symbolUse.DisplayEnv, symbol,symbolUse.ItemOccurence, symbolUse.Range)|]
18741875
|> async.Return
18751876

18761877
memberinfo.ProjectContext=
@@ -2050,7 +2051,7 @@ type FSharpCheckFileResults(filename: string, errors: FSharpErrorInfo[], scopeOp
20502051
threadSafeOp
20512052
(fun()-> failwith"not available")
20522053
(fun scope->
2053-
// This operation is not asynchronous - GetReferencedAssemblies can be run on the calling thread
2054+
// This operation is not asynchronous - GetReferencedAssemblies can be run on the calling thread
20542055
FSharpProjectContext(scope.ThisCcu, scope.GetReferencedAssemblies(), scope.AccessRights))
20552056

20562057
memberinfo.DependencyFiles= dependencyFiles
@@ -2059,19 +2060,19 @@ type FSharpCheckFileResults(filename: string, errors: FSharpErrorInfo[], scopeOp
20592060
threadSafeOp
20602061
(fun()->[||])
20612062
(fun scope->
2062-
[|for(item,itemOcc,denv,m)in scope.ScopeSymbolUses.GetAllUsesOfSymbols()do
2063-
ifitemOcc<> ItemOccurence.RelatedTextthen
2064-
letsymbol= FSharpSymbol.Create(scope.TcGlobals, scope.ThisCcu, scope.TcImports,item)
2065-
yield FSharpSymbolUse(scope.TcGlobals,denv, symbol,itemOcc, m)|])
2063+
[|forsymbolUsein scope.ScopeSymbolUses.AllUsesOfSymbolsdo
2064+
ifsymbolUse.ItemOccurence<> ItemOccurence.RelatedTextthen
2065+
letsymbol= FSharpSymbol.Create(scope.TcGlobals, scope.ThisCcu, scope.TcImports,symbolUse.Item)
2066+
yield FSharpSymbolUse(scope.TcGlobals,symbolUse.DisplayEnv, symbol,symbolUse.ItemOccurence, symbolUse.Range)|])
20662067
|> async.Return
20672068

20682069
memberinfo.GetUsesOfSymbolInFile(symbol:FSharpSymbol)=
20692070
threadSafeOp
20702071
(fun()->[||])
20712072
(fun scope->
2072-
[|for(itemOcc,denv,m)in scope.ScopeSymbolUses.GetUsesOfSymbol(symbol.Item)|> Seq.distinctBy(fun(itemOcc,_denv,m)->itemOcc, m)do
2073-
ifitemOcc<> ItemOccurence.RelatedTextthen
2074-
yield FSharpSymbolUse(scope.TcGlobals,denv, symbol,itemOcc, m)|])
2073+
[|forsymbolUsein scope.ScopeSymbolUses.GetUsesOfSymbol(symbol.Item)|> Seq.distinctBy(funsymbolUse->symbolUse.ItemOccurence, symbolUse.Range)do
2074+
ifsymbolUse.ItemOccurence<> ItemOccurence.RelatedTextthen
2075+
yield FSharpSymbolUse(scope.TcGlobals,symbolUse.DisplayEnv, symbol,symbolUse.ItemOccurence, symbolUse.Range)|])
20752076
|> async.Return
20762077

20772078
memberinfo.GetVisibleNamespacesAndModulesAtPoint(pos:pos)=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp