Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit ec1766e

Browse files
TIHannosami
authored andcommitted
[Tooling Optimization] Skip background type-checking on implementation files if signature files exist (dotnet#10199)
* Initial work to enable FSI optimizations in tooling * Remove extra type-check function * Not working but initial work to lazily eval * some work * simplify * simplify again * Using Async * work * work * builds * almost there * Minor change * minor refactor * working, but not quite optimized * Fix dependency files * Refactor types * Added 'enableLazyTypeChecking'. * Enable lazy type checking in VS * Added documentation * Added SyntaxTreeAccumulator * prevent parsing impl files if possible * Trying to fix tests * Refactor * Throw if enablePartialChecking and keepAssemblyContents are both enabled * minor comment update * minor refactor * Trying to pass tests * Only getting assembly data * Remove unnecessary change * Added some documentation * Minor comment update * Renamed quickCheck to skipImplIfSigExists * Minor update * Feedback
1 parent 4f00837 commit ec1766e

File tree

8 files changed

+722
-364
lines changed

8 files changed

+722
-364
lines changed

src/fsharp/ParseAndCheckInputs.fs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ type TcState =
576576

577577
member x.NextStateAfterIncrementalFragment tcEnvAtEndOfLastInput =
578578
{ x with tcsTcSigEnv = tcEnvAtEndOfLastInput
579-
tcsTcImplEnv = tcEnvAtEndOfLastInput }
579+
tcsTcImplEnv = tcEnvAtEndOfLastInput }
580580

581581

582582
/// Create the initial type checking state for compiling an assembly
@@ -621,7 +621,7 @@ let GetInitialTcState(m, ccuName, tcConfig: TcConfig, tcGlobals, tcImports: TcIm
621621
tcsCcuSig = Construct.NewEmptyModuleOrNamespaceType Namespace }
622622

623623
/// Typecheck a single file (or interactive entry into F# Interactive)
624-
let TypeCheckOneInputEventually (checkForErrors, tcConfig: TcConfig, tcImports: TcImports, tcGlobals, prefixPathOpt, tcSink, tcState: TcState, inp: ParsedInput) =
624+
let TypeCheckOneInputEventually (checkForErrors, tcConfig: TcConfig, tcImports: TcImports, tcGlobals, prefixPathOpt, tcSink, tcState: TcState, inp: ParsedInput, skipImplIfSigExists: bool) =
625625

626626
eventually {
627627
try
@@ -686,11 +686,21 @@ let TypeCheckOneInputEventually (checkForErrors, tcConfig: TcConfig, tcImports:
686686
let conditionalDefines =
687687
if tcConfig.noConditionalErasure then None else Some (tcConfig.conditionalCompilationDefines)
688688

689+
let hadSig = rootSigOpt.IsSome
690+
689691
// Typecheck the implementation file
690-
let! topAttrs, implFile, _implFileHiddenType, tcEnvAtEnd, createsGeneratedProvidedTypes =
691-
TypeCheckOneImplFile (tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors, conditionalDefines, tcSink, tcConfig.internalTestSpanStackReferring) tcImplEnv rootSigOpt file
692+
let typeCheckOne =
693+
if skipImplIfSigExists && hadSig then
694+
let dummyExpr = ModuleOrNamespaceExprWithSig.ModuleOrNamespaceExprWithSig(rootSigOpt.Value, ModuleOrNamespaceExpr.TMDefs [], range.Zero)
695+
let dummyImplFile = TypedImplFile.TImplFile(qualNameOfFile, [], dummyExpr, false, false, StampMap [])
696+
697+
(EmptyTopAttrs, dummyImplFile, Unchecked.defaultof<_>, tcImplEnv, false)
698+
|> Eventually.Done
699+
else
700+
TypeCheckOneImplFile (tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors, conditionalDefines, tcSink, tcConfig.internalTestSpanStackReferring) tcImplEnv rootSigOpt file
701+
702+
let! topAttrs, implFile, _implFileHiddenType, tcEnvAtEnd, createsGeneratedProvidedTypes = typeCheckOne
692703

693-
let hadSig = rootSigOpt.IsSome
694704
let implFileSigType = SigTypeOfImplFile implFile
695705

696706
let rootImpls = Zset.add qualNameOfFile tcState.tcsRootImpls
@@ -741,7 +751,7 @@ let TypeCheckOneInput (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, pre
741751
// 'use' ensures that the warning handler is restored at the end
742752
use unwindEL = PushErrorLoggerPhaseUntilUnwind(fun oldLogger -> GetErrorLoggerFilteringByScopedPragmas(false, GetScopedPragmasForInput inp, oldLogger) )
743753
use unwindBP = PushThreadBuildPhaseUntilUnwind BuildPhase.TypeCheck
744-
TypeCheckOneInputEventually (checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, TcResultsSink.NoSink, tcState, inp)
754+
TypeCheckOneInputEventually (checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, TcResultsSink.NoSink, tcState, inp, false)
745755
|> Eventually.force ctok
746756

747757
/// Finish checking multiple files (or one interactive entry into F# Interactive)
@@ -756,7 +766,7 @@ let TypeCheckMultipleInputsFinish(results, tcState: TcState) =
756766
let TypeCheckOneInputAndFinishEventually(checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input) =
757767
eventually {
758768
Logger.LogBlockStart LogCompilerFunctionId.CompileOps_TypeCheckOneInputAndFinishEventually
759-
let! results, tcState = TypeCheckOneInputEventually(checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input)
769+
let! results, tcState = TypeCheckOneInputEventually(checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input, false)
760770
let result = TypeCheckMultipleInputsFinish([results], tcState)
761771
Logger.LogBlockStop LogCompilerFunctionId.CompileOps_TypeCheckOneInputAndFinishEventually
762772
return result
@@ -779,4 +789,3 @@ let TypeCheckClosedInputSet (ctok, checkForErrors, tcConfig, tcImports, tcGlobal
779789
let (tcEnvAtEndOfLastFile, topAttrs, implFiles, _), tcState = TypeCheckMultipleInputsFinish(results, tcState)
780790
let tcState, declaredImpls = TypeCheckClosedInputSetFinish (implFiles, tcState)
781791
tcState, topAttrs, declaredImpls, tcEnvAtEndOfLastFile
782-

src/fsharp/ParseAndCheckInputs.fsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ val TypeCheckOneInputEventually :
8787
LongIdent option *
8888
NameResolution.TcResultsSink *
8989
TcState *
90-
ParsedInput
90+
ParsedInput *
91+
skipImplIfSigExists: bool
9192
-> Eventually<(TcEnv * TopAttribs * TypedImplFile option * ModuleOrNamespaceType) * TcState>
9293

9394
/// Finish the checking of multiple inputs

0 commit comments

Comments
 (0)