Skip to content

Commit 1558a9f

Browse files
committed
Reuse SymbolEnv for file type check info
1 parent 5c4bf16 commit 1558a9f

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

src/fsharp/fsi/fsi.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ type internal FsiDynamicCompiler
11781178
| Item.Value vref ->
11791179
let optValue = newState.ilxGenerator.LookupGeneratedValue(valuePrinter.GetEvaluationContext(newState.emEnv), vref.Deref)
11801180
match optValue with
1181-
| Some (res, typ) -> Some(FsiValue(res, typ, FSharpType(tcGlobals, newState.tcState.Ccu, newState.tcState.CcuSig, newState.tcImports, vref.Type)))
1181+
| Some (res, typ) -> Some(FsiValue(res, typ, FSharpType(cenv, vref.Type)))
11821182
| None -> None
11831183
| _ -> None
11841184

src/fsharp/service/service.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ type TypeCheckInfo
183183
let amap = tcImports.GetImportMap()
184184
let infoReader = new InfoReader(g,amap)
185185
let ncenv = new NameResolver(g,amap,infoReader,NameResolution.FakeInstantiationGenerator)
186+
let cenv = SymbolEnv(g, thisCcu, Some ccuSigForFile, tcImports, amap, infoReader)
186187

187188
/// Find the most precise naming environment for the given line and column
188189
let GetBestEnvForPos cursorPos =
@@ -938,7 +939,6 @@ type TypeCheckInfo
938939
match GetDeclItemsForNamesAtPosition(ctok, parseResultsOpt, Some partialName.QualifyingIdents, Some partialName.PartialIdent, partialName.LastDotPos, line, lineStr, partialName.EndColumn + 1, ResolveTypeNamesToCtors, ResolveOverloads.Yes, getAllEntities, hasTextChangedSinceLastTypecheck) with
939940
| None -> FSharpDeclarationListInfo.Empty
940941
| Some (items, denv, ctx, m) ->
941-
let cenv = SymbolEnv(g, thisCcu, Some ccuSigForFile, tcImports)
942942
let items = if isInterfaceFile then items |> List.filter (fun x -> IsValidSignatureFileItem x.Item) else items
943943
let getAccessibility item = FSharpSymbol.GetAccessibility (FSharpSymbol.Create(cenv, item))
944944
let currentNamespaceOrModule =
@@ -1011,16 +1011,15 @@ type TypeCheckInfo
10111011

10121012
items |> List.filter (fun (nm,items) -> not (isOpItem(nm,items)) && not(isFSharpList nm))
10131013

1014-
let cenv = SymbolEnv(g, thisCcu, Some ccuSigForFile, tcImports)
10151014
let items =
10161015
// Filter out duplicate names
10171016
items |> List.map (fun (_nm,itemsWithSameName) ->
10181017
match itemsWithSameName with
10191018
| [] -> failwith "Unexpected empty bag"
10201019
| items ->
1021-
items |> List.map (fun item ->
1022-
let symbol = FSharpSymbol.Create(cenv, item.Item)
1023-
FSharpSymbolUse(g, denv, symbol, ItemOccurence.Use, m)))
1020+
items
1021+
|> List.map (fun item -> let symbol = FSharpSymbol.Create(cenv, item.Item)
1022+
FSharpSymbolUse(g, denv, symbol, ItemOccurence.Use, m)))
10241023

10251024
//end filtering
10261025
items)
@@ -1134,7 +1133,6 @@ type TypeCheckInfo
11341133
match GetDeclItemsForNamesAtPosition (ctok, None,Some(names), None, None,line, lineStr, colAtEndOfNames, ResolveTypeNamesToCtors, ResolveOverloads.No,(fun() -> []),fun _ -> false) with
11351134
| None | Some ([],_,_,_) -> None
11361135
| Some (items, denv, _, m) ->
1137-
let cenv = SymbolEnv(g, thisCcu, Some ccuSigForFile, tcImports)
11381136
let allItems = items |> List.collect (fun item -> SymbolHelpers.FlattenItems g m item.Item)
11391137
let symbols = allItems |> List.map (fun item -> FSharpSymbol.Create(cenv, item))
11401138
Some (symbols, denv, m)
@@ -1250,7 +1248,7 @@ type TypeCheckInfo
12501248
match GetDeclItemsForNamesAtPosition (ctok, None,Some(names), None, None, line, lineStr, colAtEndOfNames, ResolveTypeNamesToCtors, ResolveOverloads.Yes,(fun() -> []), fun _ -> false) with
12511249
| None | Some ([], _, _, _) -> None
12521250
| Some (item :: _, denv, _, m) ->
1253-
let symbol = FSharpSymbol.Create(g, thisCcu, ccuSigForFile, tcImports, item.Item)
1251+
let symbol = FSharpSymbol.Create(cenv, item.Item)
12541252
Some (symbol, denv, m)
12551253
)
12561254
(fun msg ->
@@ -1402,6 +1400,8 @@ type TypeCheckInfo
14021400
/// All open declarations in the file, including auto open modules
14031401
member __.OpenDeclarations = openDeclarations
14041402

1403+
member __.SymbolEnv = cenv
1404+
14051405
override __.ToString() = "TypeCheckInfo(" + mainInputFileName + ")"
14061406

14071407
type FSharpParsingOptions =
@@ -2084,7 +2084,7 @@ type FSharpCheckFileResults(filename: string, errors: FSharpErrorInfo[], scopeOp
20842084
threadSafeOp
20852085
(fun () -> [| |])
20862086
(fun scope ->
2087-
let cenv = SymbolEnv(scope.TcGlobals, scope.ThisCcu, Some scope.CcuSigForFile, scope.TcImports)
2087+
let cenv = scope.SymbolEnv
20882088
[| for symbolUse in scope.ScopeSymbolUses.AllUsesOfSymbols do
20892089
if symbolUse.ItemOccurence <> ItemOccurence.RelatedText then
20902090
let symbol = FSharpSymbol.Create(cenv, symbolUse.Item)
@@ -2129,7 +2129,7 @@ type FSharpCheckFileResults(filename: string, errors: FSharpErrorInfo[], scopeOp
21292129
member info.OpenDeclarations =
21302130
scopeOptX
21312131
|> Option.map (fun scope ->
2132-
let cenv = SymbolEnv(scope.TcGlobals, scope.ThisCcu, Some scope.CcuSigForFile, scope.TcImports)
2132+
let cenv = scope.SymbolEnv
21332133
scope.OpenDeclarations |> Array.map (fun x -> FSharpOpenDeclaration(x.LongId, x.Range, (x.Modules |> List.map (fun x -> FSharpEntity(cenv, x))), x.AppliedScope, x.IsOwnNamespace)))
21342134
|> Option.defaultValue [| |]
21352135

src/fsharp/symbols/Symbols.fs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ type FSharpAccessibility(a:Accessibility, ?isProtected) =
4949
let mangledTextOfCompPath (CompPath(scoref, path)) = getNameOfScopeRef scoref + "/" + textOfPath (List.map fst path)
5050
String.concat ";" (List.map mangledTextOfCompPath paths)
5151

52-
type SymbolEnv(g:TcGlobals, thisCcu: CcuThunk, thisCcuTyp: ModuleOrNamespaceType option, tcImports: TcImports) =
53-
let amapV = tcImports.GetImportMap()
54-
let infoReaderV = InfoReader(g, amapV)
52+
type SymbolEnv(g: TcGlobals, thisCcu: CcuThunk, thisCcuTyp: ModuleOrNamespaceType option, tcImports: TcImports, amapV: Import.ImportMap, infoReaderV: InfoReader) =
53+
54+
new(g: TcGlobals, thisCcu: CcuThunk, thisCcuTyp: ModuleOrNamespaceType option, tcImports: TcImports) =
55+
let amap = tcImports.GetImportMap()
56+
let infoReader = InfoReader(g, amap)
57+
SymbolEnv(g, thisCcu, thisCcuTyp, tcImports, amap, infoReader)
58+
5559
member __.g = g
5660
member __.amap = amapV
5761
member __.thisCcu = thisCcu

src/fsharp/symbols/Symbols.fsi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ open System.Collections.Generic
66
open Microsoft.FSharp.Compiler
77
open Microsoft.FSharp.Compiler.AccessibilityLogic
88
open Microsoft.FSharp.Compiler.CompileOps
9+
open Microsoft.FSharp.Compiler.Import
10+
open Microsoft.FSharp.Compiler.InfoReader
911
open Microsoft.FSharp.Compiler.Range
1012
open Microsoft.FSharp.Compiler.Ast
1113
open Microsoft.FSharp.Compiler.Tast
@@ -14,8 +16,9 @@ open Microsoft.FSharp.Compiler.NameResolution
1416

1517
// Implementation details used by other code in the compiler
1618
type internal SymbolEnv =
17-
new : TcGlobals * thisCcu:CcuThunk * thisCcuTyp: ModuleOrNamespaceType option * tcImports: TcImports -> SymbolEnv
18-
member amap: Import.ImportMap
19+
new: TcGlobals * thisCcu:CcuThunk * thisCcuTyp: ModuleOrNamespaceType option * tcImports: TcImports -> SymbolEnv
20+
new: TcGlobals * thisCcu:CcuThunk * thisCcuTyp: ModuleOrNamespaceType option * tcImports: TcImports * amap: ImportMap * infoReader: InfoReader -> SymbolEnv
21+
member amap: ImportMap
1922
member g: TcGlobals
2023

2124
/// Indicates the accessibility of a symbol, as seen by the F# language

0 commit comments

Comments
 (0)