From 9627d3373ee6c4c7dbb09295f5c8230cde303eea Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Thu, 27 Apr 2023 10:34:18 +0200 Subject: [PATCH] Fix some blocking in incremental builder (#15146) --- src/Compiler/Service/IncrementalBuild.fs | 23 +++++++++-------------- src/Compiler/Service/IncrementalBuild.fsi | 7 +++++-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Compiler/Service/IncrementalBuild.fs b/src/Compiler/Service/IncrementalBuild.fs index 4d88e39c428..d010a518b80 100644 --- a/src/Compiler/Service/IncrementalBuild.fs +++ b/src/Compiler/Service/IncrementalBuild.fs @@ -914,7 +914,7 @@ module IncrementalBuilderStateHelpers = return! prevBoundModel.Next(syntaxTree) }) - let rec createFinalizeBoundModelGraphNode (initialState: IncrementalBuilderInitialState) (boundModels: GraphNode seq) = + let createFinalizeBoundModelGraphNode (initialState: IncrementalBuilderInitialState) (boundModels: GraphNode seq) = GraphNode(node { use _ = Activity.start "GetCheckResultsAndImplementationsForProject" [|Activity.Tags.project, initialState.outfile|] let! result = @@ -928,7 +928,7 @@ module IncrementalBuilderStateHelpers = return result, DateTime.UtcNow }) - and computeStampedFileNames (initialState: IncrementalBuilderInitialState) (state: IncrementalBuilderState) (cache: TimeStampCache) = + let computeStampedFileNames (initialState: IncrementalBuilderInitialState) (state: IncrementalBuilderState) (cache: TimeStampCache) = let slots = if initialState.useChangeNotifications then state.slots @@ -967,7 +967,7 @@ module IncrementalBuilderStateHelpers = else state - and computeStampedReferencedAssemblies (initialState: IncrementalBuilderInitialState) state canTriggerInvalidation (cache: TimeStampCache) = + let computeStampedReferencedAssemblies (initialState: IncrementalBuilderInitialState) state canTriggerInvalidation (cache: TimeStampCache) = let stampedReferencedAssemblies = state.stampedReferencedAssemblies.ToBuilder() let mutable referencesUpdated = false @@ -1132,11 +1132,6 @@ type IncrementalBuilder(initialState: IncrementalBuilderInitialState, state: Inc do! setCurrentState currentState cache ct } - let checkFileTimeStampsSynchronously cache = - checkFileTimeStamps cache - |> Async.AwaitNodeCode - |> Async.RunSynchronously - do IncrementalBuilderEventTesting.MRU.Add(IncrementalBuilderEventTesting.IBECreated) member _.TcConfig = tcConfig @@ -1192,10 +1187,10 @@ type IncrementalBuilder(initialState: IncrementalBuilderInitialState, state: Inc member builder.TryGetCheckResultsBeforeFileInProject fileName = let cache = TimeStampCache defaultTimeStamp - checkFileTimeStampsSynchronously cache + let tmpState = computeStampedFileNames initialState currentState cache let slotOfFile = builder.GetSlotOfFileName fileName - match tryGetBeforeSlot currentState slotOfFile with + match tryGetBeforeSlot tmpState slotOfFile with | Some(boundModel, timestamp) -> let projectTimeStamp = builder.GetLogicalTimeStampForFileInProject(fileName) Some (PartialCheckResults (boundModel, timestamp, projectTimeStamp)) @@ -1277,12 +1272,12 @@ type IncrementalBuilder(initialState: IncrementalBuilderInitialState, state: Inc member _.GetLogicalTimeStampForFileInProject(slotOfFile: int) = let cache = TimeStampCache defaultTimeStamp - checkFileTimeStampsSynchronously cache - computeProjectTimeStamp currentState slotOfFile + let tempState = computeStampedFileNames initialState currentState cache + computeProjectTimeStamp tempState slotOfFile member _.GetLogicalTimeStampForProject(cache) = - checkFileTimeStampsSynchronously cache - computeProjectTimeStamp currentState -1 + let tempState = computeStampedFileNames initialState currentState cache + computeProjectTimeStamp tempState -1 member _.TryGetSlotOfFileName(fileName: string) = // Get the slot of the given file and force it to build. diff --git a/src/Compiler/Service/IncrementalBuild.fsi b/src/Compiler/Service/IncrementalBuild.fsi index 9ffc66a2fdb..ec8d0ed7461 100644 --- a/src/Compiler/Service/IncrementalBuild.fsi +++ b/src/Compiler/Service/IncrementalBuild.fsi @@ -185,6 +185,8 @@ type internal IncrementalBuilder = /// This is safe for use from non-compiler threads but the objects returned must in many cases be accessed only from the compiler thread. member GetCheckResultsForFileInProjectEvenIfStale: fileName: string -> PartialCheckResults option + // TODO: Looks like the following doc does not match the actual method or it's signature. + /// Get the preceding typecheck state of a slot, but only if it is up-to-date w.r.t. /// the timestamps on files and referenced DLLs prior to this one. Return None if the result is not available. /// This is a relatively quick operation. @@ -192,8 +194,9 @@ type internal IncrementalBuilder = /// This is safe for use from non-compiler threads member AreCheckResultsBeforeFileInProjectReady: fileName: string -> bool - /// Get the preceding typecheck state of a slot, WITH checking if it is up-to-date w.r.t. However, files will not be parsed or checked. - /// the timestamps on files and referenced DLLs prior to this one. Return None if the result is not available or if it is not up-to-date. + /// Get the preceding typecheck state of a slot, WITH checking if it is up-to-date w.r.t. the timestamps of files and referenced DLLs prior to this one. + /// However, files will not be parsed or checked. + /// Return None if the result is not available or if it is not up-to-date. /// /// This is safe for use from non-compiler threads but the objects returned must in many cases be accessed only from the compiler thread. member TryGetCheckResultsBeforeFileInProject: fileName: string -> PartialCheckResults option