Skip to content

Commit 51635bb

Browse files
nojafdsyme0101vzarytovskii
authored
Parallel type checking for impl files with backing sig files (#13737)
* revamp parallel checking * simplify names * fix diagnostics * code formatting * update surface area * simplify diagnostic logging and format diagnostics eagerly when processing in parallel * format code * remove SplitRelatedDiagnostic * fix build and cleanup * further cleanup * further cleanup * format code * fix flaterrors * allow error recovery on collisions * fix name generation to be deterministic * fix build * Update RecursiveSafetyAnalysis.fs * Add flag for parallel type checking of files backed by signatures. * Update src/Compiler/Driver/ParseAndCheckInputs.fs Co-authored-by: Petr Pokorny <[email protected]> * format code * Update TypeTests.fs * Prefix DiagnosticsLoggerProvider with I * Remove duplicate hadSig binding. * Add basic test for ParallelCheckingWithSignatureFiles flag. * Add additional CI job. * Produce binlog for ParallelCheckingWithSignatureFiles * Update azure-pipelines.yml * Update azure-pipelines.yml * Update TypeTests.fs * Update SyntaxTreeTests * Correct code after rebase * Correct SynModuleSigDecl in SignatureTypeTests.fs * Format ParseAndCheckInputs.fs Co-authored-by: Don Syme <[email protected]> Co-authored-by: Don Syme <[email protected]> Co-authored-by: Petr Pokorny <[email protected]> Co-authored-by: Vlad Zarytovskii <[email protected]>
1 parent 6f78b1c commit 51635bb

File tree

80 files changed

+1947
-1586
lines changed

Some content is hidden

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

80 files changed

+1947
-1586
lines changed

FSharpBuild.Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<WarningsAsErrors>1182;0025;$(WarningsAsErrors)</WarningsAsErrors>
2727
<OtherFlags>$(OtherFlags) --nowarn:3384</OtherFlags>
2828
<OtherFlags>$(OtherFlags) --times --nowarn:75</OtherFlags>
29+
<OtherFlags Condition="$(ParallelCheckingWithSignatureFilesOn) == 'true'">$(OtherFlags) --test:ParallelCheckingWithSignatureFilesOn</OtherFlags>
2930
</PropertyGroup>
3031

3132
<!-- nuget -->

azure-pipelines.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,36 @@ stages:
508508
# filePath: eng\tests\UpToDate.ps1
509509
# arguments: -configuration $(_BuildConfig) -ci -binaryLog
510510

511+
# Run Build with --test:ParallelCheckingWithSignatureFilesOn
512+
- job: ParallelCheckingWithSignatureFiles
513+
condition: eq(variables['Build.Reason'], 'PullRequest')
514+
variables:
515+
- name: _SignType
516+
value: Test
517+
pool:
518+
name: NetCore-Public
519+
demands: ImageOverride -equals $(WindowsMachineQueueName)
520+
timeoutInMinutes: 90
521+
steps:
522+
- checkout: self
523+
clean: true
524+
- task: UseDotNet@2
525+
displayName: install SDK
526+
inputs:
527+
packageType: sdk
528+
useGlobalJson: true
529+
includePreviewVersions: false
530+
workingDirectory: $(Build.SourcesDirectory)
531+
installationPath: $(Build.SourcesDirectory)/.dotnet
532+
- script: .\build.cmd -c Release -binaryLog /p:ParallelCheckingWithSignatureFilesOn=true
533+
displayName: ParallelCheckingWithSignatureFiles build with Debug configuration
534+
- task: PublishPipelineArtifact@1
535+
displayName: Publish ParallelCheckingWithSignatureFiles Logs
536+
inputs:
537+
targetPath: '$(Build.SourcesDirectory)/artifacts/log/Release'
538+
artifactName: 'ParallelCheckingWithSignatureFiles Attempt $(System.JobAttempt) Logs'
539+
continueOnError: true
540+
511541
# Plain build Windows
512542
- job: Plain_Build_Windows
513543
pool:

src/Compiler/Checking/CheckBasics.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,14 @@ type TcFileState =
328328

329329
/// Create a new compilation environment
330330
static member Create
331-
(g, isScript, niceNameGen, amap, thisCcu, isSig, haveSig, conditionalDefines, tcSink, tcVal, isInternalTestSpanStackReferring,
331+
(g, isScript, amap, thisCcu, isSig, haveSig, conditionalDefines, tcSink, tcVal, isInternalTestSpanStackReferring,
332332
tcPat,
333333
tcSimplePats,
334334
tcSequenceExpressionEntry,
335335
tcArrayOrListSequenceExpression,
336336
tcComputationExpression) =
337337

338+
let niceNameGen = NiceNameGenerator()
338339
let infoReader = InfoReader(g, amap)
339340
let instantiationGenerator m tpsorig = FreshenTypars g m tpsorig
340341
let nameResolver = NameResolver(g, amap, infoReader, instantiationGenerator)

src/Compiler/Checking/CheckBasics.fsi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ type TcFileState =
311311
static member Create:
312312
g: TcGlobals *
313313
isScript: bool *
314-
niceNameGen: NiceNameGenerator *
315314
amap: ImportMap *
316315
thisCcu: CcuThunk *
317316
isSig: bool *

src/Compiler/Checking/CheckDeclarations.fs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,12 @@ let TcOpenDecl (cenv: cenv) mOpenDecl scopem env target =
688688
| SynOpenDeclTarget.Type (synType, m) ->
689689
TcOpenTypeDecl cenv mOpenDecl scopem env (synType, m)
690690

691-
let MakeSafeInitField (g: TcGlobals) env m isStatic =
691+
let MakeSafeInitField (cenv: cenv) env m isStatic =
692692
let id =
693693
// Ensure that we have an g.CompilerGlobalState
694-
assert(g.CompilerGlobalState |> Option.isSome)
695-
ident(g.CompilerGlobalState.Value.NiceNameGenerator.FreshCompilerGeneratedName("init", m), m)
694+
ident(cenv.niceNameGen.FreshCompilerGeneratedName("init", m), m)
696695
let taccess = TAccess [env.eAccessPath]
697-
Construct.NewRecdField isStatic None id false g.int_ty true true [] [] XmlDoc.Empty taccess true
696+
Construct.NewRecdField isStatic None id false cenv.g.int_ty true true [] [] XmlDoc.Empty taccess true
698697

699698
// Checking of mutually recursive types, members and 'let' bindings in classes
700699
//
@@ -1268,7 +1267,7 @@ module MutRecBindingChecking =
12681267
| _ -> false)
12691268

12701269
if needsSafeStaticInit && hasStaticBindings then
1271-
let rfield = MakeSafeInitField g envForDecls tcref.Range true
1270+
let rfield = MakeSafeInitField cenv envForDecls tcref.Range true
12721271
SafeInitField(mkRecdFieldRef tcref rfield.LogicalName, rfield)
12731272
else
12741273
NoSafeInitInfo
@@ -2426,7 +2425,7 @@ module EstablishTypeDefinitionCores =
24262425
let ComputeInstanceSafeInitInfo (cenv: cenv) env m thisTy =
24272426
let g = cenv.g
24282427
if InstanceMembersNeedSafeInitCheck cenv m thisTy then
2429-
let rfield = MakeSafeInitField g env m false
2428+
let rfield = MakeSafeInitField cenv env m false
24302429
let tcref = tcrefOfAppTy g thisTy
24312430
SafeInitField (mkRecdFieldRef tcref rfield.LogicalName, rfield)
24322431
else
@@ -4479,7 +4478,7 @@ let rec TcSignatureElementNonMutRec (cenv: cenv) parent typeNames endm (env: TcE
44794478

44804479
// Publish the combined module type
44814480
env.eModuleOrNamespaceTypeAccumulator.Value <-
4482-
CombineCcuContentFragments m [env.eModuleOrNamespaceTypeAccumulator.Value; modTyRoot]
4481+
CombineCcuContentFragments [env.eModuleOrNamespaceTypeAccumulator.Value; modTyRoot]
44834482
env
44844483

44854484
return env
@@ -4801,7 +4800,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
48014800

48024801
// Publish the combined module type
48034802
env.eModuleOrNamespaceTypeAccumulator.Value <-
4804-
CombineCcuContentFragments m [env.eModuleOrNamespaceTypeAccumulator.Value; modTyRoot]
4803+
CombineCcuContentFragments [env.eModuleOrNamespaceTypeAccumulator.Value; modTyRoot]
48054804
env, openDecls
48064805

48074806
let moduleContentsRoot = BuildRootModuleContents kind.IsModule enclosingNamespacePath envNS.eCompPath moduleContents
@@ -5157,7 +5156,7 @@ let MakeInitialEnv env =
51575156
/// Typecheck, then close the inference scope and then check the file meets its signature (if any)
51585157
let CheckOneImplFile
51595158
// checkForErrors: A function to help us stop reporting cascading errors
5160-
(g, niceNameGen, amap,
5159+
(g, amap,
51615160
thisCcu,
51625161
openDecls0,
51635162
checkForErrors,
@@ -5173,7 +5172,7 @@ let CheckOneImplFile
51735172

51745173
cancellable {
51755174
let cenv =
5176-
cenv.Create (g, isScript, niceNameGen, amap, thisCcu, false, Option.isSome rootSigOpt,
5175+
cenv.Create (g, isScript, amap, thisCcu, false, Option.isSome rootSigOpt,
51775176
conditionalDefines, tcSink, (LightweightTcValForUsingInBuildMethodCall g), isInternalTestSpanStackReferring,
51785177
tcPat=TcPat,
51795178
tcSimplePats=TcSimplePats,
@@ -5291,17 +5290,17 @@ let CheckOneImplFile
52915290

52925291
let implFile = CheckedImplFile (qualNameOfFile, scopedPragmas, implFileTy, implFileContents, hasExplicitEntryPoint, isScript, anonRecdTypes, namedDebugPointsForInlinedCode)
52935292

5294-
return (topAttrs, implFile, implFileTypePriorToSig, envAtEnd, cenv.createsGeneratedProvidedTypes)
5293+
return (topAttrs, implFile, envAtEnd, cenv.createsGeneratedProvidedTypes)
52955294
}
52965295

52975296

52985297

52995298
/// Check an entire signature file
5300-
let CheckOneSigFile (g, niceNameGen, amap, thisCcu, checkForErrors, conditionalDefines, tcSink, isInternalTestSpanStackReferring) tcEnv (ParsedSigFileInput (qualifiedNameOfFile = qualNameOfFile; modules = sigFileFrags)) =
5299+
let CheckOneSigFile (g, amap, thisCcu, checkForErrors, conditionalDefines, tcSink, isInternalTestSpanStackReferring) tcEnv (sigFile: ParsedSigFileInput) =
53015300
cancellable {
53025301
let cenv =
53035302
cenv.Create
5304-
(g, false, niceNameGen, amap, thisCcu, true, false, conditionalDefines, tcSink,
5303+
(g, false, amap, thisCcu, true, false, conditionalDefines, tcSink,
53055304
(LightweightTcValForUsingInBuildMethodCall g), isInternalTestSpanStackReferring,
53065305
tcPat=TcPat,
53075306
tcSimplePats=TcSimplePats,
@@ -5311,16 +5310,16 @@ let CheckOneSigFile (g, niceNameGen, amap, thisCcu, checkForErrors, conditionalD
53115310

53125311
let envinner, moduleTyAcc = MakeInitialEnv tcEnv
53135312

5314-
let specs = [ for x in sigFileFrags -> SynModuleSigDecl.NamespaceFragment x ]
5315-
let! tcEnv = TcSignatureElements cenv ParentNone qualNameOfFile.Range envinner PreXmlDoc.Empty None specs
5313+
let specs = [ for x in sigFile.Contents -> SynModuleSigDecl.NamespaceFragment x ]
5314+
let! tcEnv = TcSignatureElements cenv ParentNone sigFile.QualifiedName.Range envinner PreXmlDoc.Empty None specs
53165315

53175316
let sigFileType = moduleTyAcc.Value
53185317

53195318
if not (checkForErrors()) then
53205319
try
53215320
sigFileType |> IterTyconsOfModuleOrNamespaceType (fun tycon ->
53225321
FinalTypeDefinitionChecksAtEndOfInferenceScope(cenv.infoReader, tcEnv.NameEnv, cenv.tcSink, false, tcEnv.DisplayEnv, tycon))
5323-
with exn -> errorRecovery exn qualNameOfFile.Range
5322+
with exn -> errorRecovery exn sigFile.QualifiedName.Range
53245323

53255324
return (tcEnv, sigFileType, cenv.createsGeneratedProvidedTypes)
53265325
}

src/Compiler/Checking/CheckDeclarations.fsi

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ val AddLocalSubModule:
4949

5050
val CheckOneImplFile:
5151
TcGlobals *
52-
NiceNameGenerator *
5352
ImportMap *
5453
CcuThunk *
5554
OpenDeclaration list *
@@ -60,17 +59,10 @@ val CheckOneImplFile:
6059
TcEnv *
6160
ModuleOrNamespaceType option *
6261
ParsedImplFileInput ->
63-
Cancellable<TopAttribs * CheckedImplFile * ModuleOrNamespaceType * TcEnv * bool>
62+
Cancellable<TopAttribs * CheckedImplFile * TcEnv * bool>
6463

6564
val CheckOneSigFile:
66-
TcGlobals *
67-
NiceNameGenerator *
68-
ImportMap *
69-
CcuThunk *
70-
(unit -> bool) *
71-
ConditionalDefines option *
72-
TcResultsSink *
73-
bool ->
65+
TcGlobals * ImportMap * CcuThunk * (unit -> bool) * ConditionalDefines option * TcResultsSink * bool ->
7466
TcEnv ->
7567
ParsedSigFileInput ->
7668
Cancellable<TcEnv * ModuleOrNamespaceType * bool>

src/Compiler/Checking/ConstraintSolver.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ exception ConstraintSolverMissingConstraint of displayEnv: DisplayEnv * Typar *
244244

245245
exception ConstraintSolverError of string * range * range
246246

247-
exception ErrorFromApplyingDefault of tcGlobals: TcGlobals * displayEnv: DisplayEnv * Typar * TType * exn * range
247+
exception ErrorFromApplyingDefault of tcGlobals: TcGlobals * displayEnv: DisplayEnv * Typar * TType * error: exn * range: range
248248

249-
exception ErrorFromAddingTypeEquation of tcGlobals: TcGlobals * displayEnv: DisplayEnv * actualTy: TType * expectedTy: TType * exn * range
249+
exception ErrorFromAddingTypeEquation of tcGlobals: TcGlobals * displayEnv: DisplayEnv * actualTy: TType * expectedTy: TType * error: exn * range: range
250250

251-
exception ErrorsFromAddingSubsumptionConstraint of tcGlobals: TcGlobals * displayEnv: DisplayEnv * actualTy: TType * expectedTy: TType * exn * ContextInfo * parameterRange: range
251+
exception ErrorsFromAddingSubsumptionConstraint of tcGlobals: TcGlobals * displayEnv: DisplayEnv * actualTy: TType * expectedTy: TType * error: exn * ctxtInfo: ContextInfo * parameterRange: range
252252

253-
exception ErrorFromAddingConstraint of displayEnv: DisplayEnv * exn * range
253+
exception ErrorFromAddingConstraint of displayEnv: DisplayEnv * error: exn * range: range
254254

255-
exception UnresolvedOverloading of displayEnv: DisplayEnv * callerArgs: CallerArgs<Expr> * failure: OverloadResolutionFailure * range
255+
exception UnresolvedOverloading of displayEnv: DisplayEnv * callerArgs: CallerArgs<Expr> * failure: OverloadResolutionFailure * range: range
256256

257257
exception UnresolvedConversionOperator of displayEnv: DisplayEnv * TType * TType * range
258258

src/Compiler/Checking/ConstraintSolver.fsi

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,33 +170,39 @@ exception ConstraintSolverMissingConstraint of displayEnv: DisplayEnv * Typar *
170170

171171
exception ConstraintSolverError of string * range * range
172172

173-
exception ErrorFromApplyingDefault of tcGlobals: TcGlobals * displayEnv: DisplayEnv * Typar * TType * exn * range
173+
exception ErrorFromApplyingDefault of
174+
tcGlobals: TcGlobals *
175+
displayEnv: DisplayEnv *
176+
Typar *
177+
TType *
178+
error: exn *
179+
range: range
174180

175181
exception ErrorFromAddingTypeEquation of
176182
tcGlobals: TcGlobals *
177183
displayEnv: DisplayEnv *
178184
actualTy: TType *
179185
expectedTy: TType *
180-
exn *
181-
range
186+
error: exn *
187+
range: range
182188

183189
exception ErrorsFromAddingSubsumptionConstraint of
184190
tcGlobals: TcGlobals *
185191
displayEnv: DisplayEnv *
186192
actualTy: TType *
187193
expectedTy: TType *
188-
exn *
189-
ContextInfo *
194+
error: exn *
195+
ctxtInfo: ContextInfo *
190196
parameterRange: range
191197

192-
exception ErrorFromAddingConstraint of displayEnv: DisplayEnv * exn * range
198+
exception ErrorFromAddingConstraint of displayEnv: DisplayEnv * error: exn * range: range
193199
exception UnresolvedConversionOperator of displayEnv: DisplayEnv * TType * TType * range
194200

195201
exception UnresolvedOverloading of
196202
displayEnv: DisplayEnv *
197203
callerArgs: CallerArgs<Expr> *
198204
failure: OverloadResolutionFailure *
199-
range
205+
range: range
200206

201207
exception NonRigidTypar of displayEnv: DisplayEnv * string option * range * TType * TType * range
202208

src/Compiler/Checking/import.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ let ImportILAssemblyTypeDefs (amap, m, auxModLoader, aref, mainmod: ILModuleDef)
584584
let scoref = ILScopeRef.Assembly aref
585585
let mtypsForExportedTypes = ImportILAssemblyExportedTypes amap m auxModLoader scoref mainmod.ManifestOfAssembly.ExportedTypes
586586
let mainmod = ImportILAssemblyMainTypeDefs amap m scoref mainmod
587-
CombineCcuContentFragments m (mainmod :: mtypsForExportedTypes)
587+
CombineCcuContentFragments (mainmod :: mtypsForExportedTypes)
588588

589589
/// Import the type forwarder table for an IL assembly
590590
let ImportILAssemblyTypeForwarders (amap, m, exportedTypes: ILExportedTypesAndForwarders): CcuTypeForwarderTable =

src/Compiler/CodeGen/IlxGen.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11552,6 +11552,11 @@ let CodegenAssembly cenv eenv mgbuf implFiles =
1155211552
match List.tryFrontAndBack implFiles with
1155311553
| None -> ()
1155411554
| Some (firstImplFiles, lastImplFile) ->
11555+
11556+
// Generate the assembly sequentially, implementation file by implementation file.
11557+
//
11558+
// NOTE: In theory this could be done in parallel, except for the presence of linear
11559+
// state in the AssemblyBuilder
1155511560
let eenv = List.fold (GenImplFile cenv mgbuf None) eenv firstImplFiles
1155611561
let eenv = GenImplFile cenv mgbuf cenv.options.mainMethodInfo eenv lastImplFile
1155711562

@@ -11626,7 +11631,7 @@ type IlxGenResults =
1162611631

1162711632
let GenerateCode (cenv, anonTypeTable, eenv, CheckedAssemblyAfterOptimization implFiles, assemAttribs, moduleAttribs) =
1162811633

11629-
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind BuildPhase.IlxGen
11634+
use _ = UseBuildPhase BuildPhase.IlxGen
1163011635
let g = cenv.g
1163111636

1163211637
// Generate the implementations into the mgbuf

0 commit comments

Comments
 (0)