Skip to content

Commit 8ad0442

Browse files
committed
Reuse typechecking results - stage 1
1 parent fbdb7cb commit 8ad0442

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+935
-55
lines changed

docs/release-notes/.FSharp.Compiler.Service/9.0.200.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
### Added
2626

27+
* New flag `--reusetypecheckingresults`, for skipping recompilation in some cases
2728
* Let `dotnet fsi --help` print a link to the documentation website. ([PR #18006](https://github.com/dotnet/fsharp/pull/18006))
2829
* Deprecate places where `seq` can be omitted. ([Language suggestion #1033](https://github.com/fsharp/fslang-suggestions/issues/1033), [PR #17772](https://github.com/dotnet/fsharp/pull/17772))
2930
* Support literal attribute on decimals ([PR #17769](https://github.com/dotnet/fsharp/pull/17769))

src/Compiler/Driver/CompilerConfig.fs

+13
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,11 @@ type TypeCheckingMode =
444444
| Sequential
445445
| Graph
446446

447+
[<RequireQualifiedAccess>]
448+
type ReuseTcResults =
449+
| On
450+
| Off
451+
447452
[<RequireQualifiedAccess>]
448453
type TypeCheckingConfig =
449454
{
@@ -651,6 +656,8 @@ type TcConfigBuilder =
651656

652657
mutable parallelReferenceResolution: ParallelReferenceResolution
653658

659+
mutable reuseTcResults: ReuseTcResults
660+
654661
mutable captureIdentifiersWhenParsing: bool
655662

656663
mutable typeCheckingConfig: TypeCheckingConfig
@@ -660,6 +667,8 @@ type TcConfigBuilder =
660667
mutable realsig: bool
661668

662669
mutable compilationMode: TcGlobals.CompilationMode
670+
671+
mutable cmdLineArgs: string array
663672
}
664673

665674
// Directories to start probing in
@@ -861,6 +870,7 @@ type TcConfigBuilder =
861870
xmlDocInfoLoader = None
862871
exiter = QuitProcessExiter
863872
parallelReferenceResolution = ParallelReferenceResolution.Off
873+
reuseTcResults = ReuseTcResults.Off
864874
captureIdentifiersWhenParsing = false
865875
typeCheckingConfig =
866876
{
@@ -875,6 +885,7 @@ type TcConfigBuilder =
875885
realsig = false
876886
strictIndentation = None
877887
compilationMode = TcGlobals.CompilationMode.Unset
888+
cmdLineArgs = [||]
878889
}
879890

880891
member tcConfigB.FxResolver =
@@ -1415,11 +1426,13 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
14151426
member _.xmlDocInfoLoader = data.xmlDocInfoLoader
14161427
member _.exiter = data.exiter
14171428
member _.parallelReferenceResolution = data.parallelReferenceResolution
1429+
member _.reuseTcResults = data.reuseTcResults
14181430
member _.captureIdentifiersWhenParsing = data.captureIdentifiersWhenParsing
14191431
member _.typeCheckingConfig = data.typeCheckingConfig
14201432
member _.dumpSignatureData = data.dumpSignatureData
14211433
member _.realsig = data.realsig
14221434
member _.compilationMode = data.compilationMode
1435+
member _.cmdLineArgs = data.cmdLineArgs
14231436

14241437
static member Create(builder, validate) =
14251438
use _ = UseBuildPhase BuildPhase.Parameter

src/Compiler/Driver/CompilerConfig.fsi

+13
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ type ParallelReferenceResolution =
208208
| On
209209
| Off
210210

211+
[<RequireQualifiedAccess>]
212+
type ReuseTcResults =
213+
| On
214+
| Off
215+
211216
/// Determines the algorithm used for type-checking.
212217
[<RequireQualifiedAccess>]
213218
type TypeCheckingMode =
@@ -519,6 +524,8 @@ type TcConfigBuilder =
519524

520525
mutable parallelReferenceResolution: ParallelReferenceResolution
521526

527+
mutable reuseTcResults: ReuseTcResults
528+
522529
mutable captureIdentifiersWhenParsing: bool
523530

524531
mutable typeCheckingConfig: TypeCheckingConfig
@@ -528,6 +535,8 @@ type TcConfigBuilder =
528535
mutable realsig: bool
529536

530537
mutable compilationMode: TcGlobals.CompilationMode
538+
539+
mutable cmdLineArgs: string array
531540
}
532541

533542
static member CreateNew:
@@ -899,6 +908,8 @@ type TcConfig =
899908

900909
member parallelReferenceResolution: ParallelReferenceResolution
901910

911+
member reuseTcResults: ReuseTcResults
912+
902913
member captureIdentifiersWhenParsing: bool
903914

904915
member typeCheckingConfig: TypeCheckingConfig
@@ -909,6 +920,8 @@ type TcConfig =
909920

910921
member compilationMode: TcGlobals.CompilationMode
911922

923+
member cmdLineArgs: string array
924+
912925
/// Represents a computation to return a TcConfig. Normally this is just a constant immutable TcConfig,
913926
/// but for F# Interactive it may be based on an underlying mutable TcConfigBuilder.
914927
[<Sealed>]

src/Compiler/Driver/CompilerImports.fs

+51-3
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,54 @@ let EncodeOptimizationData (tcGlobals, tcConfig: TcConfig, outfile, exportRemapp
337337
else
338338
[]
339339

340+
let GetTypecheckingData (file, ilScopeRef, ilModule, byteReaderA, byteReaderB) =
341+
342+
let memA = byteReaderA ()
343+
344+
let memB =
345+
match byteReaderB with
346+
| None -> ByteMemory.Empty.AsReadOnly()
347+
| Some br -> br ()
348+
349+
unpickleObjWithDanglingCcus file ilScopeRef ilModule unpickleTcInfo memA memB
350+
351+
let WriteTypecheckingData (tcConfig: TcConfig, tcGlobals, fileName, inMem, ccu, tcInfo) =
352+
353+
// need to understand the naming and if we even want two resources here...
354+
let rName = "FSharpTypecheckingData"
355+
let rNameB = "FSharpTypecheckingDataB"
356+
357+
PickleToResource
358+
inMem
359+
fileName
360+
tcGlobals
361+
tcConfig.compressMetadata
362+
ccu
363+
(rName + ccu.AssemblyName)
364+
(rNameB + ccu.AssemblyName)
365+
pickleTcInfo
366+
tcInfo
367+
368+
let EncodeTypecheckingData (tcConfig: TcConfig, tcGlobals, generatedCcu, outfile, isIncrementalBuild, tcInfo) =
369+
let r1, r2 =
370+
WriteTypecheckingData(
371+
tcConfig,
372+
tcGlobals,
373+
outfile,
374+
isIncrementalBuild,
375+
generatedCcu,
376+
tcInfo)
377+
378+
let resources =
379+
[
380+
r1
381+
match r2 with
382+
| None -> ()
383+
| Some r -> r
384+
]
385+
386+
resources
387+
340388
exception AssemblyNotResolved of originalName: string * range: range
341389

342390
exception MSBuildReferenceResolutionWarning of message: string * warningCode: string * range: range
@@ -901,17 +949,17 @@ type TcAssemblyResolutions(tcConfig: TcConfig, results: AssemblyResolution list,
901949

902950
for UnresolvedAssemblyReference (referenceText, _ranges) in unresolved do
903951
if referenceText.Contains("mscorlib") then
904-
Debug.Assert(false, sprintf "whoops, did not resolve mscorlib: '%s'%s" referenceText addedText)
952+
//Debug.Assert(false, sprintf "whoops, did not resolve mscorlib: '%s'%s" referenceText addedText)
905953
itFailed <- true
906954

907955
for x in frameworkDLLs do
908956
if not (FileSystem.IsPathRootedShim(x.resolvedPath)) then
909-
Debug.Assert(false, sprintf "frameworkDLL should be absolute path: '%s'%s" x.resolvedPath addedText)
957+
//Debug.Assert(false, sprintf "frameworkDLL should be absolute path: '%s'%s" x.resolvedPath addedText)
910958
itFailed <- true
911959

912960
for x in nonFrameworkReferences do
913961
if not (FileSystem.IsPathRootedShim(x.resolvedPath)) then
914-
Debug.Assert(false, sprintf "nonFrameworkReference should be absolute path: '%s'%s" x.resolvedPath addedText)
962+
//Debug.Assert(false, sprintf "nonFrameworkReference should be absolute path: '%s'%s" x.resolvedPath addedText)
915963
itFailed <- true
916964

917965
if itFailed then

src/Compiler/Driver/CompilerImports.fsi

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ open FSharp.Compiler.TcGlobals
1919
open FSharp.Compiler.BuildGraph
2020
open FSharp.Compiler.IO
2121
open FSharp.Compiler.Text
22+
open FSharp.Compiler.TypedTreePickle
2223
open FSharp.Core.CompilerServices
2324

2425
#if !NO_TYPEPROVIDERS
@@ -71,6 +72,23 @@ val EncodeOptimizationData:
7172
isIncrementalBuild: bool ->
7273
ILResource list
7374

75+
val GetTypecheckingData:
76+
file: string *
77+
ilScopeRef: ILScopeRef *
78+
ilModule: ILModuleDef option *
79+
byteReaderA: (unit -> ReadOnlyByteMemory) *
80+
byteReaderB: (unit -> ReadOnlyByteMemory) option ->
81+
PickledDataWithReferences<PickledTcInfo>
82+
83+
val EncodeTypecheckingData:
84+
tcConfig: TcConfig *
85+
tcGlobals: TcGlobals *
86+
generatedCcu: CcuThunk *
87+
outfile: string *
88+
isIncrementalBuild: bool *
89+
tcInfo: PickledTcInfo ->
90+
ILResource list
91+
7492
[<RequireQualifiedAccess>]
7593
type ResolveAssemblyReferenceMode =
7694
| Speculative

src/Compiler/Driver/CompilerOptions.fs

+8
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,14 @@ let advancedFlagsFsc tcConfigB =
13881388
None,
13891389
Some(FSComp.SR.optsEmitDebugInfoInQuotations (formatOptionSwitch tcConfigB.emitDebugInfoInQuotations))
13901390
)
1391+
1392+
CompilerOption(
1393+
"reusetypecheckingresults",
1394+
tagNone,
1395+
OptionUnit(fun () -> tcConfigB.reuseTcResults <- ReuseTcResults.On),
1396+
None,
1397+
Some(FSComp.SR.optsReuseTcResults ())
1398+
)
13911399
]
13921400

13931401
// OptionBlock: Internal options (test use only)

src/Compiler/Driver/ParseAndCheckInputs.fs

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ open FSharp.Compiler.LexerStore
3131
open FSharp.Compiler.Lexhelp
3232
open FSharp.Compiler.NameResolution
3333
open FSharp.Compiler.ParseHelpers
34+
open FSharp.Compiler.ReuseTcResults
3435
open FSharp.Compiler.Syntax
3536
open FSharp.Compiler.SyntaxTrivia
3637
open FSharp.Compiler.Syntax.PrettyNaming
@@ -1960,6 +1961,10 @@ let CheckMultipleInputsUsingGraphMode
19601961
partialResults, tcState)
19611962

19621963
let CheckClosedInputSet (ctok, checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, eagerFormat, inputs) =
1964+
1965+
if tcConfig.reuseTcResults = ReuseTcResults.On then
1966+
CachingDriver(tcConfig).TryReuseTcResults(inputs)
1967+
19631968
// tcEnvAtEndOfLastFile is the environment required by fsi.exe when incrementally adding definitions
19641969
let results, tcState =
19651970
match tcConfig.typeCheckingConfig.Mode with

0 commit comments

Comments
 (0)