Skip to content

Commit 977d853

Browse files
authored
Add Cancellable.CheckAndThrow (#16137)
1 parent f88d5d4 commit 977d853

24 files changed

+378
-284
lines changed

src/Compiler/Checking/CheckDeclarations.fs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ module MutRecBindingChecking =
11901190
let inheritsExpr, tpenv =
11911191
try
11921192
TcNewExpr cenv envInstance tpenv baseTy (Some synBaseTy.Range) true arg m
1193-
with e ->
1193+
with RecoverableException e ->
11941194
errorRecovery e m
11951195
mkUnit g m, tpenv
11961196
let envInstance = match baseValOpt with Some baseVal -> AddLocalVal g cenv.tcSink scopem baseVal envInstance | None -> envInstance
@@ -1927,7 +1927,7 @@ let TcMutRecDefns_Phase2 (cenv: cenv) envInitial mBinds scopem mutRecNSInfo (env
19271927

19281928
MutRecBindingChecking.TcMutRecDefns_Phase2_Bindings cenv envInitial tpenv mBinds scopem mutRecNSInfo envMutRec binds
19291929

1930-
with exn -> errorRecovery exn scopem; [], envMutRec
1930+
with RecoverableException exn -> errorRecovery exn scopem; [], envMutRec
19311931

19321932
//-------------------------------------------------------------------------
19331933
// Build augmentation declarations
@@ -3050,7 +3050,7 @@ module EstablishTypeDefinitionCores =
30503050
if not inSig then
30513051
cenv.amap.assemblyLoader.RecordGeneratedTypeRoot (ProviderGeneratedType(ilOrigRootTypeRef, ilTgtRootTyRef, nested))
30523052

3053-
with exn ->
3053+
with RecoverableException exn ->
30543054
errorRecovery exn rhsType.Range
30553055
#endif
30563056

@@ -3145,7 +3145,7 @@ module EstablishTypeDefinitionCores =
31453145

31463146
| _ -> ()
31473147

3148-
with exn ->
3148+
with RecoverableException exn ->
31493149
errorRecovery exn m
31503150

31513151
// Third phase: check and publish the super types. Run twice, once before constraints are established
@@ -3257,7 +3257,7 @@ module EstablishTypeDefinitionCores =
32573257
// Publish the super type
32583258
tycon.TypeContents.tcaug_super <- super
32593259

3260-
with exn -> errorRecovery exn m))
3260+
with RecoverableException exn -> errorRecovery exn m))
32613261

32623262
/// Establish the fields, dispatch slots and union cases of a type
32633263
let private TcTyconDefnCore_Phase1G_EstablishRepresentation (cenv: cenv) envinner tpenv inSig (MutRecDefnsPhase1DataForTycon(_, synTyconRepr, _, _, _, _)) (tycon: Tycon) (attrs: Attribs) =
@@ -3643,7 +3643,7 @@ module EstablishTypeDefinitionCores =
36433643
| _ -> ()
36443644

36453645
(baseValOpt, safeInitInfo)
3646-
with exn ->
3646+
with RecoverableException exn ->
36473647
errorRecovery exn m
36483648
None, NoSafeInitInfo
36493649

@@ -3864,7 +3864,7 @@ module EstablishTypeDefinitionCores =
38643864
let envForTycon = MakeInnerEnvForTyconRef envForTycon thisTyconRef false
38653865
try
38663866
TcTyparConstraints cenv NoNewTypars checkConstraints ItemOccurence.UseInType envForTycon tpenv synTyconConstraints |> ignore
3867-
with exn ->
3867+
with RecoverableException exn ->
38683868
errorRecovery exn m
38693869
| _ -> ())
38703870

@@ -4818,7 +4818,7 @@ let rec TcSignatureElementNonMutRec (cenv: cenv) parent typeNames endm (env: TcE
48184818

48194819
return env
48204820

4821-
with exn ->
4821+
with RecoverableException exn ->
48224822
errorRecovery exn endm
48234823
return env
48244824
}
@@ -5186,7 +5186,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
51865186
return
51875187
(defns, [], topAttrs), env, envAtEnd
51885188

5189-
with exn ->
5189+
with RecoverableException exn ->
51905190
errorRecovery exn synDecl.Range
51915191
return ([], [], []), env, env
51925192
}
@@ -5408,7 +5408,7 @@ let CreateInitialTcEnv(g, amap, scopem, assemblyName, ccus) =
54085408
(emptyTcEnv g, ccus) ||> List.collectFold (fun env (ccu, autoOpens, internalsVisible) ->
54095409
try
54105410
AddCcuToTcEnv(g, amap, scopem, env, assemblyName, ccu, autoOpens, internalsVisible)
5411-
with exn ->
5411+
with RecoverableException exn ->
54125412
errorRecovery exn scopem
54135413
[], env)
54145414

@@ -5459,7 +5459,7 @@ let ApplyDefaults (cenv: cenv) g denvAtEnd m moduleContents extraAttribs =
54595459
if not tp.IsSolved then
54605460
if (tp.StaticReq <> TyparStaticReq.None) then
54615461
ChooseTyparSolutionAndSolve cenv.css denvAtEnd tp)
5462-
with exn ->
5462+
with RecoverableException exn ->
54635463
errorRecovery exn m
54645464

54655465
let CheckValueRestriction denvAtEnd infoReader rootSigOpt implFileTypePriorToSig m =
@@ -5479,7 +5479,7 @@ let CheckValueRestriction denvAtEnd infoReader rootSigOpt implFileTypePriorToSig
54795479
| tp :: _ -> errorR (ValueRestriction(denvAtEnd, infoReader, false, v, tp, v.Range))
54805480
| _ -> ()
54815481
mty.ModuleAndNamespaceDefinitions |> List.iter (fun v -> check v.ModuleOrNamespaceType)
5482-
try check implFileTypePriorToSig with e -> errorRecovery e m
5482+
try check implFileTypePriorToSig with RecoverableException e -> errorRecovery e m
54835483

54845484

54855485
let SolveInternalUnknowns g (cenv: cenv) denvAtEnd moduleContents extraAttribs =
@@ -5517,7 +5517,7 @@ let CheckModuleSignature g (cenv: cenv) m denvAtEnd rootSigOpt implFileTypePrior
55175517
if not (SignatureConformance.Checker(g, cenv.amap, denv, remapInfo, true).CheckSignature aenv cenv.infoReader (mkLocalModuleRef implFileSpecPriorToSig) sigFileType) then
55185518
// We can just raise 'ReportedError' since CheckModuleOrNamespace raises its own error
55195519
raise (ReportedError None)
5520-
with exn ->
5520+
with RecoverableException exn ->
55215521
errorRecovery exn m
55225522

55235523
(sigFileType, moduleContents)
@@ -5595,7 +5595,7 @@ let CheckOneImplFile
55955595
for check in cenv.css.GetPostInferenceChecksPreDefaults() do
55965596
try
55975597
check()
5598-
with exn ->
5598+
with RecoverableException exn ->
55995599
errorRecovery exn m
56005600

56015601
conditionallySuppressErrorReporting (checkForErrors()) (fun () ->
@@ -5609,7 +5609,7 @@ let CheckOneImplFile
56095609
implFileTypePriorToSig |> IterTyconsOfModuleOrNamespaceType (fun tycon ->
56105610
FinalTypeDefinitionChecksAtEndOfInferenceScope (cenv.infoReader, envAtEnd.NameEnv, cenv.tcSink, true, denvAtEnd, tycon))
56115611

5612-
with exn ->
5612+
with RecoverableException exn ->
56135613
errorRecovery exn m)
56145614

56155615
// Check the value restriction. Only checked if there is no signature.
@@ -5630,7 +5630,7 @@ let CheckOneImplFile
56305630
for check in cenv.css.GetPostInferenceChecksFinal() do
56315631
try
56325632
check()
5633-
with exn ->
5633+
with RecoverableException exn ->
56345634
errorRecovery exn m)
56355635

56365636
// We ALWAYS run the PostTypeCheckSemanticChecks phase, though we if we have already encountered some
@@ -5649,7 +5649,7 @@ let CheckOneImplFile
56495649
implFileTy, implFileContents, extraAttribs, isLastCompiland,
56505650
isInternalTestSpanStackReferring)
56515651

5652-
with exn ->
5652+
with RecoverableException exn ->
56535653
errorRecovery exn m
56545654
false, StampMap.Empty)
56555655

@@ -5711,7 +5711,7 @@ let CheckOneSigFile (g, amap, thisCcu, checkForErrors, conditionalDefines, tcSin
57115711
try
57125712
sigFileType |> IterTyconsOfModuleOrNamespaceType (fun tycon ->
57135713
FinalTypeDefinitionChecksAtEndOfInferenceScope(cenv.infoReader, tcEnv.NameEnv, cenv.tcSink, false, tcEnv.DisplayEnv, tycon))
5714-
with exn -> errorRecovery exn sigFile.QualifiedName.Range
5714+
with RecoverableException exn -> errorRecovery exn sigFile.QualifiedName.Range
57155715

57165716
UpdatePrettyTyparNames.updateModuleOrNamespaceType sigFileType
57175717

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ let UnifyOverallType (cenv: cenv) (env: TcEnv) m overallTy actualTy =
474474
let UnifyOverallTypeAndRecover (cenv: cenv) env m overallTy actualTy =
475475
try
476476
UnifyOverallType cenv env m overallTy actualTy
477-
with exn ->
477+
with RecoverableException exn ->
478478
errorRecovery exn m
479479

480480
/// Make an environment suitable for a module or namespace. Does not create a new accumulator but uses one we already have/
@@ -4963,7 +4963,7 @@ and TcTypeOrMeasureAndRecover kindOpt (cenv: cenv) newOk checkConstraints occ iw
49634963
let g = cenv.g
49644964
try
49654965
TcTypeOrMeasure kindOpt cenv newOk checkConstraints occ iwsam env tpenv ty
4966-
with e ->
4966+
with RecoverableException e ->
49674967
errorRecovery e ty.Range
49684968

49694969
let recoveryTy =
@@ -5156,7 +5156,7 @@ and TcExpr (cenv: cenv) ty (env: TcEnv) tpenv (synExpr: SynExpr) =
51565156
// So be careful!
51575157
try
51585158
TcExprNoRecover cenv ty env tpenv synExpr
5159-
with exn ->
5159+
with RecoverableException exn ->
51605160
let m = synExpr.Range
51615161
// Error recovery - return some rubbish expression, but replace/annotate
51625162
// the type of the current expression with a type variable that indicates an error
@@ -5185,7 +5185,7 @@ and TcExprOfUnknownTypeThen (cenv: cenv) env tpenv synExpr delayed =
51855185
let expr, tpenv =
51865186
try
51875187
TcExprThen cenv (MustEqual exprTy) env tpenv false synExpr delayed
5188-
with exn ->
5188+
with RecoverableException exn ->
51895189
let m = synExpr.Range
51905190
errorRecovery exn m
51915191
SolveTypeAsError env.DisplayEnv cenv.css m exprTy
@@ -10962,7 +10962,7 @@ and TcAttributesWithPossibleTargetsEx canFail (cenv: cenv) env attrTgt attrEx sy
1096210962

1096310963
attribsAndTargets, didFail || didFail2
1096410964

10965-
with e ->
10965+
with RecoverableException e ->
1096610966
errorRecovery e synAttrib.Range
1096710967
[], false)
1096810968

src/Compiler/Checking/CheckPatterns.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ and TcPatBindingName cenv env id ty isMemberThis vis1 valReprInfo (vFlags: TcPat
216216
and TcPatAndRecover warnOnUpper cenv (env: TcEnv) valReprInfo (vFlags: TcPatValFlags) patEnv ty (synPat: SynPat) =
217217
try
218218
TcPat warnOnUpper cenv env valReprInfo vFlags patEnv ty synPat
219-
with e ->
219+
with RecoverableException e ->
220220
// Error recovery - return some rubbish expression, but replace/annotate
221221
// the type of the current expression with a type variable that indicates an error
222222
let m = synPat.Range
@@ -335,7 +335,7 @@ and TcConstPat warnOnUpper cenv env vFlags patEnv ty synConst m =
335335
try
336336
let c = TcConst cenv ty m env synConst
337337
(fun _ -> TPat_const (c, m)), patEnv
338-
with e ->
338+
with RecoverableException e ->
339339
errorRecovery e m
340340
(fun _ -> TPat_error m), patEnv
341341

@@ -394,7 +394,7 @@ and TcPatOr warnOnUpper cenv env vFlags patEnv ty pat1 pat2 m =
394394
match names2.TryGetValue id1.idText with
395395
| true, PrelimVal1 (id=id2; prelimType=ty2) ->
396396
try UnifyTypes cenv env id2.idRange ty1 ty2
397-
with exn -> errorRecovery exn m
397+
with RecoverableException exn -> errorRecovery exn m
398398
| _ -> ())
399399

400400
let namesR = NameMap.layer names1 names2
@@ -417,7 +417,7 @@ and TcPatTuple warnOnUpper cenv env vFlags patEnv ty isExplicitStruct args m =
417417
let argsR, acc = TcPatterns warnOnUpper cenv env vFlags patEnv argTys args
418418
let phase2 values = TPat_tuple(tupInfo, List.map (fun f -> f values) argsR, argTys, m)
419419
phase2, acc
420-
with e ->
420+
with RecoverableException e ->
421421
errorRecovery e m
422422
let _, acc = TcPatterns warnOnUpper cenv env vFlags patEnv (NewInferenceTypes g args) args
423423
let phase2 _ = TPat_error m
@@ -462,7 +462,7 @@ and TcRecordPat warnOnUpper cenv env vFlags patEnv ty fieldPats m =
462462
and TcNullPat cenv env patEnv ty m =
463463
try
464464
AddCxTypeUseSupportsNull env.DisplayEnv cenv.css m NoTrace ty
465-
with exn ->
465+
with RecoverableException exn ->
466466
errorRecovery exn m
467467
(fun _ -> TPat_null m), patEnv
468468

src/Compiler/Checking/MethodOverrides.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ module DispatchSlotChecking =
826826

827827
CheckOverridesAreAllUsedOnce (denv, g, infoReader, false, reqdTy, dispatchSlotsKeyed, availPriorOverrides, overridesToCheck)
828828

829-
with e -> errorRecovery e m
829+
with RecoverableException e -> errorRecovery e m
830830

831831
// Now record the full slotsigs of the abstract members implemented by each override.
832832
// This is used to generate IL MethodImpls in the code generator.

src/Compiler/Checking/NameResolution.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ let GetTyconRefForExtensionMembers minfo (deref: Entity) amap m g =
568568
| AppTy g (tcrefOfTypeExtended, _) when not (isByrefTy g thisTy) -> Some tcrefOfTypeExtended
569569
| _ -> None
570570
Some rs
571-
with e -> // Import of the ILType may fail, if so report the error and skip on
571+
with RecoverableException e -> // Import of the ILType may fail, if so report the error and skip on
572572
errorRecovery e m
573573
None
574574

src/Compiler/Checking/PatternMatchCompilation.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,8 @@ let CompilePatternBasic
11461146

11471147
// The main recursive loop of the pattern match compiler.
11481148
let rec InvestigateFrontiers refuted frontiers =
1149+
Cancellable.CheckAndThrow()
1150+
11491151
match frontiers with
11501152
| [] -> failwith "CompilePattern: compile - empty clauses: at least the final clause should always succeed"
11511153
| Frontier (i, active, valMap) :: rest ->

src/Compiler/Checking/PostInferenceChecks.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,7 @@ let CheckModuleBinding cenv env (TBind(v, e, _) as bind) =
22122212
match TryChopPropertyName v.DisplayName with
22132213
| Some res -> check true res
22142214
| None -> ()
2215-
with e -> errorRecovery e v.Range
2215+
with RecoverableException e -> errorRecovery e v.Range
22162216
end
22172217

22182218
CheckBinding cenv { env with returnScope = 1 } true PermitByRefExpr.Yes bind |> ignore

src/Compiler/Driver/CompilerConfig.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
12111211
| Some path when FileSystem.DirectoryExistsShim(path) -> yield path
12121212
| _ -> ()
12131213
]
1214-
with e ->
1214+
with RecoverableException e ->
12151215
errorRecovery e range0
12161216
[]
12171217

@@ -1408,7 +1408,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
14081408
None
14091409
else
14101410
Some(m, path)
1411-
with e ->
1411+
with RecoverableException e ->
14121412
errorRecovery e m
14131413
None
14141414

src/Compiler/Driver/CompilerImports.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ type TcAssemblyResolutions(tcConfig: TcConfig, results: AssemblyResolution list,
680680
tcConfig.ResolveLibWithDirectories(CcuLoadFailureAction.RaiseError, assemblyReference)
681681

682682
Choice1Of2 resolutionOpt.Value
683-
with e ->
683+
with RecoverableException e ->
684684
errorRecovery e assemblyReference.Range
685685
Choice2Of2 assemblyReference)
686686

@@ -1913,7 +1913,7 @@ and [<Sealed>] TcImports
19131913

19141914
for providedNamespace in providedNamespaces do
19151915
loop providedNamespace
1916-
with e ->
1916+
with RecoverableException e ->
19171917
errorRecovery e m
19181918

19191919
if startingErrorCount < DiagnosticsThreadStatics.DiagnosticsLogger.ErrorCount then

src/Compiler/Driver/CompilerOptions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2334,7 +2334,7 @@ let ApplyCommandLineArgs (tcConfigB: TcConfigBuilder, sourceFiles: string list,
23342334

23352335
ParseCompilerOptions(collect, GetCoreServiceCompilerOptions tcConfigB, argv)
23362336
sourceFilesAcc |> CheckAndReportSourceFileDuplicates
2337-
with e ->
2337+
with RecoverableException e ->
23382338
errorRecovery e range0
23392339
sourceFiles
23402340

0 commit comments

Comments
 (0)