@@ -1426,7 +1426,7 @@ let CheckOneInputAux'
14261426 tcState : TcState ,
14271427 inp : ParsedInput ,
14281428 _skipImplIfSigExists : bool ): ( unit -> bool ) * TcConfig * TcImports * TcGlobals * LongIdent option * TcResultsSink * TcState * ParsedInput * bool )
1429- : Cancellable < bool -> TcState -> PartialResult * TcState > =
1429+ : Cancellable < TcState -> PartialResult * TcState > =
14301430
14311431 cancellable {
14321432 try
@@ -1478,43 +1478,27 @@ let CheckOneInputAux'
14781478
14791479 // printfn $"Finished Processing Sig {file.FileName}"
14801480 return
1481- fun isFinalFold tcState ->
1482- printfn $" Applying Sig {file.FileName} (final: {isFinalFold}) "
1481+ fun tcState ->
1482+ // printfn $"Applying Sig {file.FileName}"
14831483
1484- let fsiPartialResult , tcState =
1485- let rootSigs = Zmap.add qualNameOfFile sigFileType tcState.tcsRootSigs
1484+ let rootSigs = Zmap.add qualNameOfFile sigFileType tcState.tcsRootSigs
14861485
1487- let tcSigEnv =
1488- AddLocalRootModuleOrNamespace TcResultsSink.NoSink tcGlobals amap m tcState.tcsTcSigEnv sigFileType
1486+ let tcSigEnv =
1487+ AddLocalRootModuleOrNamespace TcResultsSink.NoSink tcGlobals amap m tcState.tcsTcSigEnv sigFileType
14891488
1490- // Add the signature to the signature env (unless it had an explicit signature)
1491- let ccuSigForFile = CombineCcuContentFragments [ sigFileType; tcState.tcsCcuSig ]
1489+ // Add the signature to the signature env (unless it had an explicit signature)
1490+ let ccuSigForFile = CombineCcuContentFragments [ sigFileType; tcState.tcsCcuSig ]
14921491
1493- let partialResult = tcEnv, EmptyTopAttrs, None, ccuSigForFile
1492+ let partialResult = tcEnv, EmptyTopAttrs, None, ccuSigForFile
14941493
1495- let tcState =
1496- { tcState with
1497- tcsTcSigEnv = tcSigEnv
1498- tcsRootSigs = rootSigs
1499- tcsCreatesGeneratedProvidedTypes =
1500- tcState.tcsCreatesGeneratedProvidedTypes || createsGeneratedProvidedTypes
1501- }
1494+ let tcState =
1495+ { tcState with
1496+ tcsTcSigEnv = tcSigEnv
1497+ tcsRootSigs = rootSigs
1498+ tcsCreatesGeneratedProvidedTypes = tcState.tcsCreatesGeneratedProvidedTypes || createsGeneratedProvidedTypes
1499+ }
15021500
1503- partialResult, tcState
1504-
1505- if isFinalFold then
1506- fsiPartialResult, tcState
1507- else
1508- // Train of thought: I'm not sure you want to add the results to the tcState,
1509- // when this function is called right before it will check the implementation file.
1510-
1511- // Update the TcEnv of implementation files to also contain the signature data.
1512- let _ccuSigForFile , tcState =
1513- AddCheckResultsToTcState
1514- ( tcGlobals, amap, true , prefixPathOpt, tcSink, tcState.tcsTcImplEnv, qualNameOfFile, sigFileType)
1515- tcState
1516-
1517- fsiPartialResult, tcState
1501+ partialResult, tcState
15181502
15191503 | ParsedInput.ImplFile file ->
15201504 // printfn $"Processing Impl {file.FileName}"
@@ -1543,45 +1527,34 @@ let CheckOneInputAux'
15431527
15441528 // printfn $"Finished Processing Impl {file.FileName}"
15451529 return
1546- fun isFinalFold tcState ->
1547- let addResultToState () =
1548- // Check if we've already seen an implementation for this fragment
1549- if Zset.contains qualNameOfFile tcState.tcsRootImpls then
1550- errorR ( Error( FSComp.SR.buildImplementationAlreadyGiven ( qualNameOfFile.Text), m))
1551-
1552- // printfn $"Applying Impl Backed={backed} {file.FileName}"
1553- let ccuSigForFile , fsTcState =
1554- AddCheckResultsToTcState
1555- ( tcGlobals, amap, false , prefixPathOpt, tcSink, tcState.tcsTcImplEnv, qualNameOfFile, implFile.Signature)
1556- tcState
1557-
1558- // backed impl files must not add results as there are already results from .fsi files
1559- //let fsTcState = if backed then tcState else fsTcState
1560-
1561- let partialResult = tcEnvAtEnd, topAttrs, Some implFile, ccuSigForFile
1562-
1563- let tcState =
1564- { fsTcState with
1565- tcsCreatesGeneratedProvidedTypes =
1566- fsTcState.tcsCreatesGeneratedProvidedTypes || createsGeneratedProvidedTypes
1567- }
1568-
1569- // printfn $"Finished applying Impl {file.FileName}"
1570- partialResult, tcState
1571-
1572- match rootSigOpt with
1573- | None -> addResultToState ()
1574- | Some _ when isFinalFold -> addResultToState ()
1575- | Some rootSig ->
1576- // In this case, we are skipping the step where we add the results of the implementation file to the tcState.
1577- // The fold function of a signature file will add the result (of the signature),
1578- // to the implementation when it is not processing the final fold.
1579- let partialResult = tcEnvAtEnd, topAttrs, Some implFile, rootSig
1580- partialResult, tcState
1530+ fun tcState ->
1531+ // Check if we've already seen an implementation for this fragment
1532+ if Zset.contains qualNameOfFile tcState.tcsRootImpls then
1533+ errorR ( Error( FSComp.SR.buildImplementationAlreadyGiven ( qualNameOfFile.Text), m))
1534+
1535+ // printfn $"Applying Impl Backed={backed} {file.FileName}"
1536+ let ccuSigForFile , fsTcState =
1537+ AddCheckResultsToTcState
1538+ ( tcGlobals, amap, false , prefixPathOpt, tcSink, tcState.tcsTcImplEnv, qualNameOfFile, implFile.Signature)
1539+ tcState
1540+
1541+ // backed impl files must not add results as there are already results from .fsi files
1542+ //let fsTcState = if backed then tcState else fsTcState
1543+
1544+ let partialResult = tcEnvAtEnd, topAttrs, Some implFile, ccuSigForFile
1545+
1546+ let tcState =
1547+ { fsTcState with
1548+ tcsCreatesGeneratedProvidedTypes =
1549+ fsTcState.tcsCreatesGeneratedProvidedTypes || createsGeneratedProvidedTypes
1550+ }
1551+
1552+ // printfn $"Finished applying Impl {file.FileName}"
1553+ partialResult, tcState
15811554
15821555 with e ->
15831556 errorRecovery e range0
1584- return fun _ tcState -> ( tcState.TcEnvFromSignatures, EmptyTopAttrs, None, tcState.tcsCcuSig), tcState
1557+ return fun tcState -> ( tcState.TcEnvFromSignatures, EmptyTopAttrs, None, tcState.tcsCcuSig), tcState
15851558 }
15861559
15871560/// Typecheck a single file (or interactive entry into F# Interactive). If skipImplIfSigExists is set to true
@@ -1596,9 +1569,31 @@ let CheckOneInput'
15961569 tcState : TcState ,
15971570 input : ParsedInput ,
15981571 skipImplIfSigExists : bool ): ( unit -> bool ) * TcConfig * TcImports * TcGlobals * LongIdent option * TcResultsSink * TcState * ParsedInput * bool )
1599- : Cancellable < bool -> TcState -> PartialResult * TcState > =
1572+ : Cancellable < TcState -> PartialResult * TcState > =
16001573 CheckOneInputAux'( checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input, skipImplIfSigExists)
16011574
1575+ let AddSignatureResultToTcImplEnv ( tcImports : TcImports , tcGlobals , prefixPathOpt , tcSink , tcState , input : ParsedInput ) =
1576+ let qualNameOfFile = input.QualifiedName
1577+ let rootSigOpt = tcState.tcsRootSigs.TryFind qualNameOfFile
1578+
1579+ match rootSigOpt with
1580+ | None -> failwithf $" No signature data was found for %s {input.FileName}"
1581+ | Some rootSig ->
1582+ fun ( tcState : TcState ) ->
1583+ let amap = tcImports.GetImportMap()
1584+
1585+ // Add the results of type checking the signature file to the TcEnv of implementation files.
1586+ let ccuSigForFile , tcState =
1587+ AddCheckResultsToTcState
1588+ ( tcGlobals, amap, true , prefixPathOpt, tcSink, tcState.tcsTcImplEnv, qualNameOfFile, rootSig)
1589+ tcState
1590+
1591+ // This partial result will be discarded in the end of the graph resolution.
1592+ let partialResult : PartialResult =
1593+ tcState.tcsTcSigEnv, EmptyTopAttrs, None, ccuSigForFile
1594+
1595+ partialResult, tcState
1596+
16021597// Within a file, equip loggers to locally filter w.r.t. scope pragmas in each input
16031598let DiagnosticsLoggerForInput ( tcConfig : TcConfig , input : ParsedInput , oldLogger ) =
16041599 GetDiagnosticsLoggerFilteringByScopedPragmas( false , input.ScopedPragmas, tcConfig.diagnosticsOptions, oldLogger)
0 commit comments