Skip to content

Commit 89d072d

Browse files
authored
Merge pull request #24 from nojaf/trie-approach
Alternative Trie approach
2 parents f9745ed + 1cf73f2 commit 89d072d

28 files changed

Lines changed: 3077 additions & 2922 deletions

src/Compiler/Driver/ParseAndCheckInputs.fs

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,10 +1395,6 @@ let CheckOneInput
13951395
)
13961396
}
13971397

1398-
let mutable asts = ConcurrentDictionary<string, ParsedInput>()
1399-
1400-
let mutable fsiBackedInfos = ConcurrentDictionary<string, ModuleOrNamespaceType>()
1401-
14021398
/// Typecheck a single file (or interactive entry into F# Interactive)
14031399
let CheckOneInputAux'
14041400
((checkForErrors,
@@ -1410,7 +1406,7 @@ let CheckOneInputAux'
14101406
tcState: TcState,
14111407
inp: ParsedInput,
14121408
_skipImplIfSigExists: bool): (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcResultsSink * TcState * ParsedInput * bool)
1413-
: Cancellable<TcState -> PartialResult * TcState> =
1409+
: Cancellable<bool -> TcState -> PartialResult * TcState> =
14141410

14151411
cancellable {
14161412
try
@@ -1459,13 +1455,9 @@ let CheckOneInputAux'
14591455
let m = qualNameOfFile.Range
14601456
TcOpenModuleOrNamespaceDecl tcSink tcGlobals amap m tcEnv (prefixPath, m)
14611457

1462-
// Save info needed for type-checking .fs file later on
1463-
// printfn $"[{Thread.CurrentThread.ManagedThreadId}] Saving fsiBackedInfos for {file.FileName}"
1464-
fsiBackedInfos[file.FileName] <- sigFileType
1465-
14661458
// printfn $"Finished Processing Sig {file.FileName}"
14671459
return
1468-
fun tcState ->
1460+
fun isFinalFold tcState ->
14691461
// printfn $"Applying Sig {file.FileName}"
14701462
let fsiPartialResult, tcState =
14711463
let rootSigs = Zmap.add qualNameOfFile sigFileType tcState.tcsRootSigs
@@ -1488,7 +1480,16 @@ let CheckOneInputAux'
14881480

14891481
partialResult, tcState
14901482

1491-
fsiPartialResult, tcState
1483+
if isFinalFold then
1484+
fsiPartialResult, tcState
1485+
else
1486+
// Update the TcEnv of implementation files to also contain the signature data.
1487+
let _ccuSigForFile, tcState =
1488+
AddCheckResultsToTcState
1489+
(tcGlobals, amap, true, prefixPathOpt, tcSink, tcState.tcsTcImplEnv, qualNameOfFile, sigFileType)
1490+
tcState
1491+
1492+
fsiPartialResult, tcState
14921493

14931494
| ParsedInput.ImplFile file ->
14941495
// printfn $"Processing Impl {file.FileName}"
@@ -1499,10 +1500,6 @@ let CheckOneInputAux'
14991500

15001501
// Typecheck the implementation file not backed by a signature file
15011502

1502-
// Check if we've already seen an implementation for this fragment
1503-
if Zset.contains qualNameOfFile tcState.tcsRootImpls then
1504-
errorR (Error(FSComp.SR.buildImplementationAlreadyGiven (qualNameOfFile.Text), m))
1505-
15061503
let! topAttrs, implFile, tcEnvAtEnd, createsGeneratedProvidedTypes =
15071504
CheckOneImplFile(
15081505
tcGlobals,
@@ -1520,32 +1517,45 @@ let CheckOneInputAux'
15201517

15211518
// printfn $"Finished Processing Impl {file.FileName}"
15221519
return
1523-
fun tcState ->
1524-
// let backed = rootSigOpt.IsSome
1525-
// printfn $"Applying Impl Backed={backed} {file.FileName}"
1520+
fun isFinalFold tcState ->
1521+
let addResultToState () =
1522+
// Check if we've already seen an implementation for this fragment
1523+
if Zset.contains qualNameOfFile tcState.tcsRootImpls then
1524+
errorR (Error(FSComp.SR.buildImplementationAlreadyGiven (qualNameOfFile.Text), m))
15261525

1527-
let ccuSigForFile, fsTcState =
1528-
AddCheckResultsToTcState
1529-
(tcGlobals, amap, false, prefixPathOpt, tcSink, tcState.tcsTcImplEnv, qualNameOfFile, implFile.Signature)
1530-
tcState
1526+
// printfn $"Applying Impl Backed={backed} {file.FileName}"
1527+
let ccuSigForFile, fsTcState =
1528+
AddCheckResultsToTcState
1529+
(tcGlobals, amap, false, prefixPathOpt, tcSink, tcState.tcsTcImplEnv, qualNameOfFile, implFile.Signature)
1530+
tcState
15311531

1532-
// backed impl files must not add results as there are already results from .fsi files
1533-
//let fsTcState = if backed then tcState else fsTcState
1532+
// backed impl files must not add results as there are already results from .fsi files
1533+
//let fsTcState = if backed then tcState else fsTcState
15341534

1535-
let partialResult = tcEnvAtEnd, topAttrs, Some implFile, ccuSigForFile
1535+
let partialResult = tcEnvAtEnd, topAttrs, Some implFile, ccuSigForFile
15361536

1537-
let tcState =
1538-
{ fsTcState with
1539-
tcsCreatesGeneratedProvidedTypes =
1540-
fsTcState.tcsCreatesGeneratedProvidedTypes || createsGeneratedProvidedTypes
1541-
}
1537+
let tcState =
1538+
{ fsTcState with
1539+
tcsCreatesGeneratedProvidedTypes =
1540+
fsTcState.tcsCreatesGeneratedProvidedTypes || createsGeneratedProvidedTypes
1541+
}
15421542

1543-
// printfn $"Finished applying Impl {file.FileName}"
1544-
partialResult, tcState
1543+
// printfn $"Finished applying Impl {file.FileName}"
1544+
partialResult, tcState
1545+
1546+
match rootSigOpt with
1547+
| None -> addResultToState ()
1548+
| Some _ when isFinalFold -> addResultToState ()
1549+
| Some rootSig ->
1550+
// In this case, we are skipping the step where we add the results of the implementation file to the tcState.
1551+
// The fold function of a signature file will add the result (of the signature),
1552+
// to the implementation when it is not processing the final fold.
1553+
let partialResult = tcEnvAtEnd, topAttrs, Some implFile, rootSig
1554+
partialResult, tcState
15451555

15461556
with e ->
15471557
errorRecovery e range0
1548-
return fun tcState -> (tcState.TcEnvFromSignatures, EmptyTopAttrs, None, tcState.tcsCcuSig), tcState
1558+
return fun _ tcState -> (tcState.TcEnvFromSignatures, EmptyTopAttrs, None, tcState.tcsCcuSig), tcState
15491559
}
15501560

15511561
/// Typecheck a single file (or interactive entry into F# Interactive). If skipImplIfSigExists is set to true
@@ -1560,7 +1570,7 @@ let CheckOneInput'
15601570
tcState: TcState,
15611571
input: ParsedInput,
15621572
skipImplIfSigExists: bool): (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcResultsSink * TcState * ParsedInput * bool)
1563-
: Cancellable<TcState -> PartialResult * TcState> =
1573+
: Cancellable<bool -> TcState -> PartialResult * TcState> =
15641574
CheckOneInputAux'(checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input, skipImplIfSigExists)
15651575

15661576
// Within a file, equip loggers to locally filter w.r.t. scope pragmas in each input

src/Compiler/Driver/ParseAndCheckInputs.fsi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ val AddCheckResultsToTcState:
152152

153153
type PartialResult = TcEnv * TopAttribs * CheckedImplFile option * ModuleOrNamespaceType
154154

155-
val mutable fsiBackedInfos: System.Collections.Concurrent.ConcurrentDictionary<string, ModuleOrNamespaceType>
156-
157155
type CheckArgs =
158156
CompilationThreadToken * (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcState * (PhasedDiagnostic -> PhasedDiagnostic) * ParsedInput list
159157

@@ -176,8 +174,6 @@ val CheckOneInput:
176174
skipImplIfSigExists: bool ->
177175
Cancellable<(TcEnv * TopAttribs * CheckedImplFile option * ModuleOrNamespaceType) * TcState>
178176

179-
val mutable asts: System.Collections.Concurrent.ConcurrentDictionary<string, ParsedInput>
180-
181177
/// Check one input, returned as an Eventually computation
182178
val CheckOneInput':
183179
checkForErrors: (unit -> bool) *
@@ -189,7 +185,7 @@ val CheckOneInput':
189185
tcState: TcState *
190186
input: ParsedInput *
191187
skipImplIfSigExists: bool ->
192-
Cancellable<TcState -> PartialResult * TcState>
188+
Cancellable<bool -> TcState -> PartialResult * TcState>
193189

194190
val CheckMultipleInputsInParallel:
195191
(CompilationThreadToken * (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcState * (PhasedDiagnostic -> PhasedDiagnostic) * ParsedInput list) ->

0 commit comments

Comments
 (0)