@@ -4,6 +4,7 @@ module internal FSharp.Compiler.CheckDeclarations
4
4
5
5
open System
6
6
open System.Collections .Generic
7
+ open System.Threading
7
8
8
9
open FSharp.Compiler .Diagnostics
9
10
open Internal.Utilities .Collections
@@ -5330,22 +5331,29 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
5330
5331
}
5331
5332
5332
5333
/// The non-mutually recursive case for a sequence of declarations
5333
- and TcModuleOrNamespaceElementsNonMutRec cenv parent typeNames endm ( defsSoFar , env , envAtEnd ) ( moreDefs : SynModuleDecl list ) =
5334
- cancellable {
5335
- match moreDefs with
5336
- | firstDef :: otherDefs ->
5337
- // Lookahead one to find out the scope of the next declaration.
5338
- let scopem =
5339
- if isNil otherDefs then unionRanges firstDef.Range endm
5340
- else unionRanges ( List.head otherDefs). Range endm
5334
+ and [<TailCall>] TcModuleOrNamespaceElementsNonMutRec cenv parent typeNames endm ( defsSoFar , env , envAtEnd ) ( moreDefs : SynModuleDecl list ) ( ct : CancellationToken ) =
5335
+
5336
+ if ct.IsCancellationRequested then
5337
+ ValueOrCancelled.Cancelled ( OperationCanceledException())
5338
+ else
5339
+ match moreDefs with
5340
+ | [] ->
5341
+ ValueOrCancelled.Value ( List.rev defsSoFar, envAtEnd)
5342
+ | firstDef :: otherDefs ->
5343
+ // Lookahead one to find out the scope of the next declaration.
5344
+ let scopem =
5345
+ if isNil otherDefs then
5346
+ unionRanges firstDef.Range endm
5347
+ else
5348
+ unionRanges ( List.head otherDefs) .Range endm
5341
5349
5342
- let! firstDef , env , envAtEnd = TcModuleOrNamespaceElementNonMutRec cenv parent typeNames scopem env firstDef
5350
+ let result = Cancellable.run ct ( TcModuleOrNamespaceElementNonMutRec cenv parent typeNames scopem env firstDef)
5343
5351
5344
- // tail recursive
5345
- return ! TcModuleOrNamespaceElementsNonMutRec cenv parent typeNames endm ( ( firstDef :: defsSoFar ), env , envAtEnd ) otherDefs
5346
- | [] ->
5347
- return List.rev defsSoFar , envAtEnd
5348
- }
5352
+ match result with
5353
+ | ValueOrCancelled.Cancelled x ->
5354
+ ValueOrCancelled.Cancelled x
5355
+ | ValueOrCancelled.Value ( firstDef , env , envAtEnd) ->
5356
+ TcModuleOrNamespaceElementsNonMutRec cenv parent typeNames endm (( firstDef :: defsSoFar ), env , envAtEnd ) otherDefs ct
5349
5357
5350
5358
/// The mutually recursive case for a sequence of declarations (and nested modules)
5351
5359
and TcModuleOrNamespaceElementsMutRec ( cenv : cenv ) parent typeNames m envInitial mutRecNSInfo ( defs : SynModuleDecl list ) =
@@ -5470,20 +5478,24 @@ and TcModuleOrNamespaceElements cenv parent endm env xml mutRecNSInfo openDecls0
5470
5478
escapeCheck()
5471
5479
return ( moduleContents, topAttrsNew, envAtEnd)
5472
5480
5473
- | None ->
5474
-
5475
- let! compiledDefs , envAtEnd = TcModuleOrNamespaceElementsNonMutRec cenv parent typeNames endm ([], env, env) synModuleDecls
5476
-
5477
- // Apply the functions for each declaration to build the overall expression-builder
5478
- let moduleDefs = List.collect p13 compiledDefs
5479
- let moduleDefs = match openDecls0 with [] -> moduleDefs | _ -> TMDefOpens openDecls0 :: moduleDefs
5480
- let moduleContents = TMDefs moduleDefs
5481
+ | None ->
5482
+ let! ct = Cancellable.token ()
5483
+ let result = TcModuleOrNamespaceElementsNonMutRec cenv parent typeNames endm ([], env, env) synModuleDecls ct
5484
+
5485
+ match result with
5486
+ | ValueOrCancelled.Value( compiledDefs, envAtEnd) ->
5487
+ // Apply the functions for each declaration to build the overall expression-builder
5488
+ let moduleDefs = List.collect p13 compiledDefs
5489
+ let moduleDefs = match openDecls0 with [] -> moduleDefs | _ -> TMDefOpens openDecls0 :: moduleDefs
5490
+ let moduleContents = TMDefs moduleDefs
5491
+
5492
+ // Collect up the attributes that are global to the file
5493
+ let topAttrsNew = List.collect p33 compiledDefs
5494
+ return ( moduleContents, topAttrsNew, envAtEnd)
5495
+ | ValueOrCancelled.Cancelled x ->
5496
+ return ! Cancellable( fun _ -> ValueOrCancelled.Cancelled x)
5497
+ }
5481
5498
5482
- // Collect up the attributes that are global to the file
5483
- let topAttrsNew = compiledDefs |> List.collect p33
5484
- return ( moduleContents, topAttrsNew, envAtEnd)
5485
- }
5486
-
5487
5499
5488
5500
//--------------------------------------------------------------------------
5489
5501
// CheckOneImplFile - Typecheck all the namespace fragments in a file.
0 commit comments