@@ -4,6 +4,7 @@ module internal FSharp.Compiler.CheckDeclarations
44
55open System
66open System.Collections .Generic
7+ open System.Threading
78
89open FSharp.Compiler .Diagnostics
910open Internal.Utilities .Collections
@@ -5330,22 +5331,29 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
53305331 }
53315332
53325333/// 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
53415349
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)
53435351
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
53495357
53505358/// The mutually recursive case for a sequence of declarations (and nested modules)
53515359and TcModuleOrNamespaceElementsMutRec ( cenv : cenv ) parent typeNames m envInitial mutRecNSInfo ( defs : SynModuleDecl list ) =
@@ -5470,20 +5478,24 @@ and TcModuleOrNamespaceElements cenv parent endm env xml mutRecNSInfo openDecls0
54705478 escapeCheck()
54715479 return ( moduleContents, topAttrsNew, envAtEnd)
54725480
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+ }
54815498
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-
54875499
54885500//--------------------------------------------------------------------------
54895501// CheckOneImplFile - Typecheck all the namespace fragments in a file.
0 commit comments