@@ -1911,7 +1911,7 @@ type FSharpCheckProjectResults(keepAssemblyContents, errors: FSharpErrorInfo[],
19111911 member info.GetUsesOfSymbol ( symbol : FSharpSymbol ) =
19121912 let ( tcGlobals , _tcImports , _thisCcu , _ccuSig , tcSymbolUses , _topAttribs , _tcAssemblyData , _ilAssemRef , _ad , _tcAssemblyExpr ) = getDetails()
19131913 // This probably doesn't need to be run on the reactor since all data touched by GetUsesOfSymbol is immutable.
1914- reactorOps.EnqueueAndAwaitOpAsync( " GetUsesOfSymbol" , fun () ->
1914+ reactorOps.EnqueueAndAwaitOpAsync( " GetUsesOfSymbol" , fun _ct ->
19151915 [| for r in tcSymbolUses do yield ! r.GetUsesOfSymbol( symbol.Item) |]
19161916 |> Seq.distinctBy ( fun ( itemOcc , _denv , m ) -> itemOcc, m)
19171917 |> Seq.map ( fun ( itemOcc , denv , m ) -> FSharpSymbolUse( tcGlobals, denv, symbol, itemOcc, m))
@@ -1921,7 +1921,7 @@ type FSharpCheckProjectResults(keepAssemblyContents, errors: FSharpErrorInfo[],
19211921 member info.GetAllUsesOfAllSymbols () =
19221922 let ( tcGlobals , tcImports , thisCcu , _ccuSig , tcSymbolUses , _topAttribs , _tcAssemblyData , _ilAssemRef , _ad , _tcAssemblyExpr ) = getDetails()
19231923 // This probably doesn't need to be run on the reactor since all data touched by GetAllUsesOfSymbols is immutable.
1924- reactorOps.EnqueueAndAwaitOpAsync( " GetAllUsesOfAllSymbols" , fun () ->
1924+ reactorOps.EnqueueAndAwaitOpAsync( " GetAllUsesOfAllSymbols" , fun _ct ->
19251925 [| for r in tcSymbolUses do
19261926 for ( item, itemOcc, denv, m) in r.GetAllUsesOfSymbols() do
19271927 let symbol = FSharpSymbol.Create( tcGlobals, thisCcu, tcImports, item)
@@ -1984,7 +1984,7 @@ type FSharpCheckFileResults(errors: FSharpErrorInfo[], scopeOptX: TypeCheckInfo
19841984 | Some ( scope, builderOpt, reactor) ->
19851985 // Ensure the builder doesn't get released while running operations asynchronously.
19861986 use _unwind = match builderOpt with Some builder -> builder.IncrementUsageCount() | None -> { new System.IDisposable with member __.Dispose () = () }
1987- let! res = reactor.EnqueueAndAwaitOpAsync( desc, fun () -> f scope)
1987+ let! res = reactor.EnqueueAndAwaitOpAsync( desc, fun _ct -> f scope)
19881988 return res
19891989 }
19901990
@@ -2206,8 +2206,8 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
22062206
22072207 let reactorOps =
22082208 { new IReactorOperations with
2209- member __.EnqueueAndAwaitOpAsync ( desc , op ) = reactor.EnqueueAndAwaitOpAsync ( desc, op)
2210- member __.EnqueueOp ( desc , op ) = reactor.EnqueueOp ( desc, op) }
2209+ member __.EnqueueAndAwaitOpAsync ( desc , op ) = reactor.EnqueueAndAwaitOpAsync ( desc, op)
2210+ member __.EnqueueOp ( desc , op ) = reactor.EnqueueOp ( desc, op) }
22112211
22122212 // STATIC ROOT: LanguageServiceState.FSharpChecker.backgroundCompiler.scriptClosureCache
22132213 /// Information about the derived script closure.
@@ -2350,20 +2350,26 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
23502350 foregroundTypeCheckCount <- foregroundTypeCheckCount + 1
23512351 locked ( fun () ->
23522352 parseAndCheckFileInProjectCachePossiblyStale.Set(( filename, options),( parseResults, typedResults, fileVersion))
2353- parseAndCheckFileInProjectCache.Set(( filename, source, options),( parseResults, typedResults, fileVersion)))
2353+ parseAndCheckFileInProjectCache.Set(( filename, source, options),( parseResults, typedResults, fileVersion))
2354+ parseFileInProjectCache.Set(( filename, source, options), parseResults))
23542355
23552356 /// Parses the source file and returns untyped AST
23562357 member bc.ParseFileInProject ( filename : string , source , options : FSharpProjectOptions ) =
23572358 match locked ( fun () -> parseFileInProjectCache.TryGet ( filename, source, options)) with
23582359 | Some res -> async.Return res
23592360 | None ->
2360- reactor.EnqueueAndAwaitOpAsync( " ParseFileInProject" , fun () ->
2361+ // Try this cache too (which might contain different entries)
2362+ let cachedResults = locked ( fun () -> parseAndCheckFileInProjectCache.TryGet(( filename, source, options)))
2363+ match cachedResults with
2364+ | Some ( parseResults, _ checkResults,_) -> async.Return parseResults
2365+ | _ ->
2366+ reactor.EnqueueAndAwaitOpAsync( " ParseFileInProject" , fun _ct ->
23612367
2368+ // Try the caches again - it may have been filled by the time this operation runs
23622369 match locked ( fun () -> parseFileInProjectCache.TryGet ( filename, source, options)) with
23632370 | Some res -> res
23642371 | None ->
23652372 let cachedResults = locked ( fun () -> parseAndCheckFileInProjectCache.TryGet(( filename, source, options)))
2366- // We can use cached results when there is no work to do to bring the background builder up-to-date
23672373 match cachedResults with
23682374 | Some ( parseResults, _ checkResults,_) -> parseResults
23692375 | _ ->
@@ -2383,8 +2389,8 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
23832389
23842390 /// Fetch the parse information from the background compiler (which checks w.r.t. the FileSystem API)
23852391 member bc.GetBackgroundParseResultsForFileInProject ( filename , options ) =
2386- reactor.EnqueueAndAwaitOpAsync( " GetBackgroundParseResultsForFileInProject" , fun () ->
2387- let builderOpt , creationErrors , _ = getOrCreateBuilder options
2392+ reactor.EnqueueAndAwaitOpAsync( " GetBackgroundParseResultsForFileInProject" , fun _ct ->
2393+ let builderOpt , creationErrors , _ = getOrCreateBuilder options
23882394 match builderOpt with
23892395 | None -> FSharpParseFileResults( List.toArray creationErrors, None, true , [])
23902396 | Some builder ->
@@ -2396,7 +2402,7 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
23962402 )
23972403
23982404 member bc.MatchBraces ( filename : string , source , options )=
2399- reactor.EnqueueAndAwaitOpAsync( " MatchBraces" , fun () ->
2405+ reactor.EnqueueAndAwaitOpAsync( " MatchBraces" , fun _ct ->
24002406 let builderOpt , _ , _ = getOrCreateBuilder options
24012407 match builderOpt with
24022408 | None -> [| |]
@@ -2409,17 +2415,17 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
24092415
24102416 /// Type-check the result obtained by parsing, but only if the antecedent type checking context is available.
24112417 member bc.CheckFileInProjectIfReady ( parseResults : FSharpParseFileResults , filename , fileVersion , source , options , isResultObsolete , textSnapshotInfo : obj option ) =
2412- reactor.EnqueueAndAwaitOpAsync( " CheckFileInProjectIfReady" , fun () ->
2418+ reactor.EnqueueAndAwaitOpAsync( " CheckFileInProjectIfReady" , fun _ct ->
24132419 let checkAnswer =
24142420 match incrementalBuildersCache.TryGetAny options with
24152421 | Some( Some builder, creationErrors, _) ->
24162422
2417- let cachedResults = locked ( fun () -> parseAndCheckFileInProjectCache.TryGet (( filename , source , options )))
2418- // We can use cached results when there is no work to do to bring the background builder up-to-date
2419- match cachedResults with
2420- | Some (_ parseResults, checkResults,_) when builder.AreCheckResultsBeforeFileInProjectReady( filename) ->
2421- Some ( FSharpCheckFileAnswer.Succeeded checkResults )
2422- | _ ->
2423+ // Check the cache. We can only use cached results when there is no work to do to bring the background builder up-to-date
2424+ let cachedResults = locked ( fun () -> parseAndCheckFileInProjectCache.TryGet (( filename , source , options )))
2425+ match cachedResults with
2426+ | Some (_ parseResults, checkResults,_) when builder.AreCheckResultsBeforeFileInProjectReady( filename) -> Some ( FSharpCheckFileAnswer.Succeeded checkResults )
2427+ | _ ->
2428+
24232429 match builder.GetCheckResultsBeforeFileInProjectIfReady filename with
24242430 | Some( tcPrior) ->
24252431
@@ -2441,18 +2447,18 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
24412447
24422448 /// Type-check the result obtained by parsing. Force the evaluation of the antecedent type checking context if needed.
24432449 member bc.CheckFileInProject ( parseResults : FSharpParseFileResults , filename , fileVersion , source , options , isResultObsolete , textSnapshotInfo ) =
2444- reactor.EnqueueAndAwaitOpAsync( " CheckFileInProject" , fun () ->
2450+ reactor.EnqueueAndAwaitOpAsync( " CheckFileInProject" , fun _ct ->
24452451 let builderOpt , creationErrors , _ = getOrCreateBuilder options
24462452 match builderOpt with
24472453 | None -> FSharpCheckFileAnswer.Succeeded ( MakeCheckFileResultsEmpty( creationErrors))
24482454 | Some builder ->
2449- let cachedResults = locked ( fun () -> parseAndCheckFileInProjectCache.TryGet(( filename, source, options)))
24502455
2451- // We can use cached results when there is no work to do to bring the background builder up-to-date
2456+ // Check the cache. We can only use cached results when there is no work to do to bring the background builder up-to-date
2457+ let cachedResults = locked ( fun () -> parseAndCheckFileInProjectCache.TryGet(( filename, source, options)))
24522458 match cachedResults with
2453- | Some (_ parseResults, checkResults,_) when builder.AreCheckResultsBeforeFileInProjectReady( filename) ->
2454- FSharpCheckFileAnswer.Succeeded checkResults
2459+ | Some (_ parseResults, checkResults,_) when builder.AreCheckResultsBeforeFileInProjectReady( filename) -> FSharpCheckFileAnswer.Succeeded checkResults
24552460 | _ ->
2461+
24562462 let tcPrior = builder.GetCheckResultsBeforeFileInProject filename
24572463 let loadClosure = scriptClosureCache.TryGet options
24582464 let tcErrors , tcFileResult =
@@ -2465,16 +2471,16 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
24652471
24662472 /// Parses the source file and returns untyped AST
24672473 member bc.ParseAndCheckFileInProject ( filename : string , fileVersion , source , options : FSharpProjectOptions , isResultObsolete , textSnapshotInfo ) =
2468- reactor.EnqueueAndAwaitOpAsync( " ParseAndCheckFileInProjectPartB " , fun () ->
2474+ reactor.EnqueueAndAwaitOpAsync( " ParseAndCheckFileInProject " , fun _ct ->
24692475 let builderOpt , creationErrors , _ = getOrCreateBuilder options // Q: Whis it it ok to ignore creationErrors in the build cache? A: These errors will be appended into the typecheck results
24702476 match builderOpt with
24712477 | None ->
24722478 let parseResults = FSharpParseFileResults( List.toArray creationErrors, None, true , [])
24732479 ( parseResults, FSharpCheckFileAnswer.Aborted)
24742480 | Some builder ->
2475- let cachedResults = locked ( fun () -> parseAndCheckFileInProjectCache.TryGet(( filename, source, options)))
24762481
2477- // We can use cached results when there is no work to do to bring the background builder up-to-date
2482+ // Check the cache. We can only use cached results when there is no work to do to bring the background builder up-to-date
2483+ let cachedResults = locked ( fun () -> parseAndCheckFileInProjectCache.TryGet(( filename, source, options)))
24782484 match cachedResults with
24792485 | Some ( parseResults, checkResults,_) when builder.AreCheckResultsBeforeFileInProjectReady( filename) ->
24802486 parseResults, FSharpCheckFileAnswer.Succeeded checkResults
@@ -2496,7 +2502,7 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
24962502
24972503 /// Fetch the check information from the background compiler (which checks w.r.t. the FileSystem API)
24982504 member bc.GetBackgroundCheckResultsForFileInProject ( filename , options ) =
2499- reactor.EnqueueAndAwaitOpAsync( " GetBackgroundCheckResultsForFileInProject" , fun () ->
2505+ reactor.EnqueueAndAwaitOpAsync( " GetBackgroundCheckResultsForFileInProject" , fun _ct ->
25002506 let ( builderOpt , creationErrors , _ ) = getOrCreateBuilder options
25012507 match builderOpt with
25022508 | None ->
@@ -2550,10 +2556,10 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
25502556
25512557 /// Parse and typecheck the whole project.
25522558 member bc.ParseAndCheckProject ( options ) =
2553- reactor.EnqueueAndAwaitOpAsync( " ParseAndCheckProject" , fun () -> bc.ParseAndCheckProjectImpl( options))
2559+ reactor.EnqueueAndAwaitOpAsync( " ParseAndCheckProject" , fun _ct -> bc.ParseAndCheckProjectImpl( options))
25542560
25552561 member bc.GetProjectOptionsFromScript ( filename , source , ? loadedTimeStamp , ? otherFlags , ? useFsiAuxLib ) =
2556- reactor.EnqueueAndAwaitOpAsync ( " GetProjectOptionsFromScript" , fun () ->
2562+ reactor.EnqueueAndAwaitOpAsync ( " GetProjectOptionsFromScript" , fun _ct ->
25572563 // Do we add a reference to FSharp.Compiler.Interactive.Settings by default?
25582564 let useFsiAuxLib = defaultArg useFsiAuxLib true
25592565 // Do we use a "FSharp.Core, 4.3.0.0" reference by default?
@@ -2630,7 +2636,7 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
26302636 member bc.CurrentQueueLength = reactor.CurrentQueueLength
26312637
26322638 member bc.ClearCaches () =
2633- reactor.EnqueueAndAwaitOpAsync ( " ClearCaches" , fun () ->
2639+ reactor.EnqueueAndAwaitOpAsync ( " ClearCaches" , fun _ct ->
26342640 locked ( fun () ->
26352641 parseAndCheckFileInProjectCachePossiblyStale.Clear()
26362642 parseAndCheckFileInProjectCache.Clear()
@@ -2640,7 +2646,7 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
26402646 scriptClosureCache.Clear())
26412647
26422648 member bc.DownsizeCaches () =
2643- reactor.EnqueueAndAwaitOpAsync ( " DownsizeCaches" , fun () ->
2649+ reactor.EnqueueAndAwaitOpAsync ( " DownsizeCaches" , fun _ct ->
26442650 locked ( fun () ->
26452651 parseAndCheckFileInProjectCachePossiblyStale.Resize( keepStrongly= 1 )
26462652 parseAndCheckFileInProjectCache.Resize( keepStrongly= 1 )
0 commit comments