@@ -1406,7 +1406,7 @@ let CheckOneInputAux'
14061406 tcState : TcState ,
14071407 inp : ParsedInput ,
14081408 _skipImplIfSigExists : bool ): ( unit -> bool ) * TcConfig * TcImports * TcGlobals * LongIdent option * TcResultsSink * TcState * ParsedInput * bool )
1409- : Cancellable < TcState -> PartialResult * TcState > =
1409+ : Cancellable < bool -> TcState -> PartialResult * TcState > =
14101410
14111411 cancellable {
14121412 try
@@ -1457,7 +1457,7 @@ let CheckOneInputAux'
14571457
14581458 // printfn $"Finished Processing Sig {file.FileName}"
14591459 return
1460- fun tcState ->
1460+ fun isFinalFold tcState ->
14611461 // printfn $"Applying Sig {file.FileName}"
14621462 let fsiPartialResult , tcState =
14631463 let rootSigs = Zmap.add qualNameOfFile sigFileType tcState.tcsRootSigs
@@ -1480,7 +1480,16 @@ let CheckOneInputAux'
14801480
14811481 partialResult, tcState
14821482
1483- 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
14841493
14851494 | ParsedInput.ImplFile file ->
14861495 // printfn $"Processing Impl {file.FileName}"
@@ -1491,10 +1500,6 @@ let CheckOneInputAux'
14911500
14921501 // Typecheck the implementation file not backed by a signature file
14931502
1494- // Check if we've already seen an implementation for this fragment
1495- if Zset.contains qualNameOfFile tcState.tcsRootImpls then
1496- errorR ( Error( FSComp.SR.buildImplementationAlreadyGiven ( qualNameOfFile.Text), m))
1497-
14981503 let! topAttrs , implFile , tcEnvAtEnd , createsGeneratedProvidedTypes =
14991504 CheckOneImplFile(
15001505 tcGlobals,
@@ -1512,32 +1517,45 @@ let CheckOneInputAux'
15121517
15131518 // printfn $"Finished Processing Impl {file.FileName}"
15141519 return
1515- fun tcState ->
1516- // let backed = rootSigOpt.IsSome
1517- // 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))
15181525
1519- let ccuSigForFile , fsTcState =
1520- AddCheckResultsToTcState
1521- ( tcGlobals, amap, false , prefixPathOpt, tcSink, tcState.tcsTcImplEnv, qualNameOfFile, implFile.Signature)
1522- 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
15231531
1524- // backed impl files must not add results as there are already results from .fsi files
1525- //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
15261534
1527- let partialResult = tcEnvAtEnd, topAttrs, Some implFile, ccuSigForFile
1535+ let partialResult = tcEnvAtEnd, topAttrs, Some implFile, ccuSigForFile
15281536
1529- let tcState =
1530- { fsTcState with
1531- tcsCreatesGeneratedProvidedTypes =
1532- fsTcState.tcsCreatesGeneratedProvidedTypes || createsGeneratedProvidedTypes
1533- }
1537+ let tcState =
1538+ { fsTcState with
1539+ tcsCreatesGeneratedProvidedTypes =
1540+ fsTcState.tcsCreatesGeneratedProvidedTypes || createsGeneratedProvidedTypes
1541+ }
15341542
1535- // printfn $"Finished applying Impl {file.FileName}"
1536- 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
15371555
15381556 with e ->
15391557 errorRecovery e range0
1540- return fun tcState -> ( tcState.TcEnvFromSignatures, EmptyTopAttrs, None, tcState.tcsCcuSig), tcState
1558+ return fun _ tcState -> ( tcState.TcEnvFromSignatures, EmptyTopAttrs, None, tcState.tcsCcuSig), tcState
15411559 }
15421560
15431561/// Typecheck a single file (or interactive entry into F# Interactive). If skipImplIfSigExists is set to true
@@ -1552,7 +1570,7 @@ let CheckOneInput'
15521570 tcState : TcState ,
15531571 input : ParsedInput ,
15541572 skipImplIfSigExists : bool ): ( unit -> bool ) * TcConfig * TcImports * TcGlobals * LongIdent option * TcResultsSink * TcState * ParsedInput * bool )
1555- : Cancellable < TcState -> PartialResult * TcState > =
1573+ : Cancellable < bool -> TcState -> PartialResult * TcState > =
15561574 CheckOneInputAux'( checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input, skipImplIfSigExists)
15571575
15581576// Within a file, equip loggers to locally filter w.r.t. scope pragmas in each input
0 commit comments