Skip to content

Commit

Permalink
[Tooling Optimization] Skip background type-checking on implementatio…
Browse files Browse the repository at this point in the history
…n files if signature files exist (#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
  • Loading branch information
TIHan authored Oct 6, 2020
1 parent ac18f76 commit 6bb2c07
Show file tree
Hide file tree
Showing 8 changed files with 722 additions and 364 deletions.
25 changes: 17 additions & 8 deletions src/fsharp/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ type TcState =

member x.NextStateAfterIncrementalFragment tcEnvAtEndOfLastInput =
{ x with tcsTcSigEnv = tcEnvAtEndOfLastInput
tcsTcImplEnv = tcEnvAtEndOfLastInput }
tcsTcImplEnv = tcEnvAtEndOfLastInput }


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

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

eventually {
try
Expand Down Expand Up @@ -686,11 +686,21 @@ let TypeCheckOneInputEventually (checkForErrors, tcConfig: TcConfig, tcImports:
let conditionalDefines =
if tcConfig.noConditionalErasure then None else Some (tcConfig.conditionalCompilationDefines)

let hadSig = rootSigOpt.IsSome

// Typecheck the implementation file
let! topAttrs, implFile, _implFileHiddenType, tcEnvAtEnd, createsGeneratedProvidedTypes =
TypeCheckOneImplFile (tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors, conditionalDefines, tcSink, tcConfig.internalTestSpanStackReferring) tcImplEnv rootSigOpt file
let typeCheckOne =
if skipImplIfSigExists && hadSig then
let dummyExpr = ModuleOrNamespaceExprWithSig.ModuleOrNamespaceExprWithSig(rootSigOpt.Value, ModuleOrNamespaceExpr.TMDefs [], range.Zero)
let dummyImplFile = TypedImplFile.TImplFile(qualNameOfFile, [], dummyExpr, false, false, StampMap [])

(EmptyTopAttrs, dummyImplFile, Unchecked.defaultof<_>, tcImplEnv, false)
|> Eventually.Done
else
TypeCheckOneImplFile (tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors, conditionalDefines, tcSink, tcConfig.internalTestSpanStackReferring) tcImplEnv rootSigOpt file

let! topAttrs, implFile, _implFileHiddenType, tcEnvAtEnd, createsGeneratedProvidedTypes = typeCheckOne

let hadSig = rootSigOpt.IsSome
let implFileSigType = SigTypeOfImplFile implFile

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

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

3 changes: 2 additions & 1 deletion src/fsharp/ParseAndCheckInputs.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ val TypeCheckOneInputEventually :
LongIdent option *
NameResolution.TcResultsSink *
TcState *
ParsedInput
ParsedInput *
skipImplIfSigExists: bool
-> Eventually<(TcEnv * TopAttribs * TypedImplFile option * ModuleOrNamespaceType) * TcState>

/// Finish the checking of multiple inputs
Expand Down
Loading

0 comments on commit 6bb2c07

Please sign in to comment.