Skip to content

Commit

Permalink
Revert "TcSymbolUseData cleanup per dotnet#6084 (dotnet#6089)"
Browse files Browse the repository at this point in the history
This reverts commit 7584974.
  • Loading branch information
auduchinok committed Mar 2, 2021
1 parent 38d2ce8 commit fd9382f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
19 changes: 6 additions & 13 deletions src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1873,24 +1873,17 @@ type TcSymbolUseData =
/// This is a memory-critical data structure - allocations of this data structure and its immediate contents
/// is one of the highest memory long-lived data structures in typical uses of IDEs. Not many of these objects
/// are allocated (one per file), but they are large because the allUsesOfAllSymbols array is large.
type TcSymbolUses(g, capturedNameResolutions: ResizeArray<CapturedNameResolution>, formatSpecifierLocations: (range * int)[]) =

type TcSymbolUses(g, capturedNameResolutions: ResizeArray<CapturedNameResolution>, formatSpecifierLocations: (range * int)[]) =
// Make sure we only capture the information we really need to report symbol uses
let allUsesOfSymbols =
capturedNameResolutions
|> ResizeArray.mapToSmallArrayChunks (fun cnr -> { Item=cnr.Item; ItemOccurence=cnr.ItemOccurence; DisplayEnv=cnr.DisplayEnv; Range=cnr.Range })

let allUsesOfSymbols = [| for cnr in capturedNameResolutions -> { Item=cnr.Item; ItemOccurence=cnr.ItemOccurence; DisplayEnv=cnr.DisplayEnv; Range=cnr.Range } |]
let capturedNameResolutions = ()
do ignore capturedNameResolutions // don't capture this!

member this.GetUsesOfSymbol item =
// This member returns what is potentially a very large array, which may approach the size constraints of the Large Object Heap.
// This is unlikely in practice, though, because we filter down the set of all symbol uses to those specifically for the given `item`.
// Consequently we have a much lesser chance of ending up with an array large enough to be promoted to the LOH.
[| for symbolUseChunk in allUsesOfSymbols do
for symbolUse in symbolUseChunk do
if protectAssemblyExploration false (fun () -> ItemsAreEffectivelyEqual g item symbolUse.Item) then
yield symbolUse |]
[| for symbolUse in allUsesOfSymbols do
if protectAssemblyExploration false (fun () -> ItemsAreEffectivelyEqual g item symbolUse.Item) then
yield symbolUse |]

member this.AllUsesOfSymbols = allUsesOfSymbols

Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/NameResolution.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ type internal TcSymbolUses =
member GetUsesOfSymbol: Item -> TcSymbolUseData[]

/// All the uses of all items within the file
member AllUsesOfSymbols: TcSymbolUseData[][]
member AllUsesOfSymbols: TcSymbolUseData[]

/// Get the locations of all the printf format specifiers in the file
member GetFormatSpecifierLocationsAndArity: unit -> (range * int)[]
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module Order =
let toFunction (pxOrder: IComparer<'U>) x y = pxOrder.Compare(x, y)

//-------------------------------------------------------------------------
// Library: arrays, lists, options, resizearrays
// Library: arrays, lists, options
//-------------------------------------------------------------------------

module Array =
Expand Down
28 changes: 13 additions & 15 deletions src/fsharp/service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1926,17 +1926,16 @@ type FSharpCheckFileResults

member _.GetAllUsesOfAllSymbolsInFile(?cancellationToken: CancellationToken ) =
threadSafeOp
(fun () -> Seq.empty)
(fun () -> [||])
(fun scope ->
cancellationToken |> Option.iter (fun ct -> ct.ThrowIfCancellationRequested())
let cenv = scope.SymbolEnv
seq {
for symbolUseChunk in scope.ScopeSymbolUses.AllUsesOfSymbols do
for symbolUse in symbolUseChunk do
cancellationToken |> Option.iter (fun ct -> ct.ThrowIfCancellationRequested())
if symbolUse.ItemOccurence <> ItemOccurence.RelatedText then
let symbol = FSharpSymbol.Create(cenv, symbolUse.Item)
FSharpSymbolUse(scope.TcGlobals, symbolUse.DisplayEnv, symbol, symbolUse.ItemOccurence, symbolUse.Range)
})
[|
for symbolUse in scope.ScopeSymbolUses.AllUsesOfSymbols do
if symbolUse.ItemOccurence <> ItemOccurence.RelatedText then
let symbol = FSharpSymbol.Create(cenv, symbolUse.Item)
FSharpSymbolUse(scope.TcGlobals, symbolUse.DisplayEnv, symbol, symbolUse.ItemOccurence, symbolUse.Range)
|])

member _.GetUsesOfSymbolInFile(symbol:FSharpSymbol, ?cancellationToken: CancellationToken) =
threadSafeOp
Expand Down Expand Up @@ -2151,13 +2150,12 @@ type FSharpCheckProjectResults
let (tcGlobals, tcImports, thisCcu, ccuSig, tcSymbolUses, _topAttribs, _tcAssemblyData, _ilAssemRef, _ad, _tcAssemblyExpr, _dependencyFiles) = getDetails()
let cenv = SymbolEnv(tcGlobals, thisCcu, Some ccuSig, tcImports)

cancellationToken |> Option.iter (fun ct -> ct.ThrowIfCancellationRequested())
[| for r in tcSymbolUses do
for symbolUseChunk in r.AllUsesOfSymbols do
for symbolUse in symbolUseChunk do
cancellationToken |> Option.iter (fun ct -> ct.ThrowIfCancellationRequested())
if symbolUse.ItemOccurence <> ItemOccurence.RelatedText then
let symbol = FSharpSymbol.Create(cenv, symbolUse.Item)
yield FSharpSymbolUse(tcGlobals, symbolUse.DisplayEnv, symbol, symbolUse.ItemOccurence, symbolUse.Range) |]
for symbolUse in r.AllUsesOfSymbols do
if symbolUse.ItemOccurence <> ItemOccurence.RelatedText then
let symbol = FSharpSymbol.Create(cenv, symbolUse.Item)
yield FSharpSymbolUse(tcGlobals, symbolUse.DisplayEnv, symbol, symbolUse.ItemOccurence, symbolUse.Range) |]

member _.ProjectContext =
let (tcGlobals, tcImports, thisCcu, _ccuSig, _tcSymbolUses, _topAttribs, _tcAssemblyData, _ilAssemRef, ad, _tcAssemblyExpr, _dependencyFiles) = getDetails()
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/service/FSharpCheckerResults.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ type public FSharpCheckFileResults =
member GetFormatSpecifierLocationsAndArity : unit -> (range*int)[]

/// Get all textual usages of all symbols throughout the file
member GetAllUsesOfAllSymbolsInFile : ?cancellationToken: CancellationToken -> seq<FSharpSymbolUse>
member GetAllUsesOfAllSymbolsInFile : ?cancellationToken: CancellationToken -> FSharpSymbolUse[]

/// Get the textual usages that resolved to the given symbol throughout the file
member GetUsesOfSymbolInFile : symbol:FSharpSymbol * ?cancellationToken: CancellationToken -> FSharpSymbolUse[]
Expand Down

0 comments on commit fd9382f

Please sign in to comment.