Skip to content

Commit 7d06ba5

Browse files
committed
be clearer about implicitly starting backgrounnd work
1 parent d9e7ce0 commit 7d06ba5

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

docs/content/queue.fsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ Compiler Services: Notes on the FSharpChecker operations queue
66
77
This is a design note on the FSharpChecker component and its operations queue. See also the notes on the [FSharpChecker caches](caches.html)
88
9-
FSharpChecker maintains an operations queue. Items from the FSharpChecker operations queue are currently processed
9+
FSharpChecker maintains an operations queue. Items from the FSharpChecker operations queue are processed
1010
sequentially and in order.
1111
1212
In addition to operations in the queue, there is also a low-priority, interleaved background operation
1313
to bring the checking of the checking of "the current background project" up-to-date. When the queue is empty
14-
this operation is conducted in small incremental fragments of parse/check work (cooperatively time-sliced to be approximately <50ms,
15-
see `maxTimeShareMilliseconds` in IncrementalBuild.fs). For a working definition of "current background project"
14+
this operation is run in small incremental fragments of work. This work id cooperatively time-sliced to be approximately <50ms,
15+
(see `maxTimeShareMilliseconds` in IncrementalBuild.fs).
16+
17+
The For a working definition of "current background project"
1618
you currently have to see the calls to `StartBackgroundCompile`
1719
in [service.fs](https://github.com/fsharp/FSharp.Compiler.Service/blob/master/src/fsharp/vs/service.fs),
1820
where an API call which in turn calls StartBackgroundCompile indicates that the current background project has been specified.

src/fsharp/vs/service.fs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,7 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
22042204
let fileChecked = Event<string>()
22052205
let projectChecked = Event<string>()
22062206

2207+
let mutable implicitlyStartBackgroundWork = true
22072208
let reactorOps =
22082209
{ new IReactorOperations with
22092210
member __.EnqueueAndAwaitOpAsync (desc, op) = reactor.EnqueueAndAwaitOpAsync (desc, op)
@@ -2344,14 +2345,15 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
23442345
member bc.RecordTypeCheckFileInProjectResults(filename,options,parseResults,fileVersion,checkAnswer,source) =
23452346
match checkAnswer with
23462347
| None
2347-
| Some FSharpCheckFileAnswer.Aborted ->
2348-
bc.StartBackgroundCompile(options) // This is a _very_ awkward place to put this logic.
2348+
| Some FSharpCheckFileAnswer.Aborted -> ()
23492349
| Some (FSharpCheckFileAnswer.Succeeded typedResults) ->
23502350
foregroundTypeCheckCount <- foregroundTypeCheckCount + 1
23512351
locked (fun () ->
23522352
parseAndCheckFileInProjectCachePossiblyStale.Set((filename,options),(parseResults,typedResults,fileVersion))
23532353
parseAndCheckFileInProjectCache.Set((filename,source,options),(parseResults,typedResults,fileVersion))
23542354
parseFileInProjectCache.Set((filename,source,options),parseResults))
2355+
if implicitlyStartBackgroundWork then
2356+
bc.CheckProjectInBackground(options)
23552357

23562358
/// Parses the source file and returns untyped AST
23572359
member bc.ParseFileInProject(filename:string, source,options:FSharpProjectOptions) =
@@ -2599,8 +2601,9 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
25992601
// We do not need to decrement here - the onDiscard function is called each time an entry is pushed out of the build cache,
26002602
// including by SetAlternate.
26012603
let builderB, errorsB, decrementB = CreateOneIncrementalBuilder options
2602-
incrementalBuildersCache.Set(options, (builderB, errorsB, decrementB)))
2603-
bc.StartBackgroundCompile(options)
2604+
incrementalBuildersCache.Set(options, (builderB, errorsB, decrementB))
2605+
if implicitlyStartBackgroundWork then
2606+
bc.CheckProjectInBackground(options))
26042607

26052608
member bc.NotifyProjectCleaned(options : FSharpProjectOptions) =
26062609
match incrementalBuildersCache.TryGetAny options with
@@ -2614,7 +2617,7 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
26142617
()
26152618
#endif
26162619

2617-
member bc.StartBackgroundCompile(options) =
2620+
member bc.CheckProjectInBackground(options) =
26182621
reactor.SetBackgroundOp(Some(fun () ->
26192622
let builderOpt,_,_ = getOrCreateBuilder options
26202623
match builderOpt with
@@ -2659,6 +2662,7 @@ type BackgroundCompiler(projectCacheSize, keepAssemblyContents, keepAllBackgroun
26592662
scriptClosureCache.Resize(keepStrongly=1, keepMax=1))
26602663

26612664
member __.FrameworkImportsCache = frameworkTcImportsCache
2665+
member __.ImplicitlyStartBackgroundWork with get() = implicitlyStartBackgroundWork and set v = implicitlyStartBackgroundWork <- v
26622666
static member GlobalForegroundParseCountStatistic = foregroundParseCount
26632667
static member GlobalForegroundTypeCheckCountStatistic = foregroundTypeCheckCount
26642668

@@ -3172,7 +3176,10 @@ type FSharpChecker(projectCacheSize, keepAssemblyContents, keepAllBackgroundReso
31723176
#endif
31733177

31743178
/// Begin background parsing the given project.
3175-
member ic.StartBackgroundCompile(options) = backgroundCompiler.StartBackgroundCompile(options)
3179+
member ic.StartBackgroundCompile(options) = backgroundCompiler.CheckProjectInBackground(options)
3180+
3181+
/// Begin background parsing the given project.
3182+
member ic.CheckProjectInBackground(options) = backgroundCompiler.CheckProjectInBackground(options)
31763183

31773184
/// Stop the background compile.
31783185
member ic.StopBackgroundCompile() = backgroundCompiler.StopBackgroundCompile()
@@ -3191,6 +3198,7 @@ type FSharpChecker(projectCacheSize, keepAssemblyContents, keepAllBackgroundReso
31913198
member ic.FileParsed = backgroundCompiler.FileParsed
31923199
member ic.FileChecked = backgroundCompiler.FileChecked
31933200
member ic.ProjectChecked = backgroundCompiler.ProjectChecked
3201+
member ic.ImplicitlyStartBackgroundWork with get() = backgroundCompiler.ImplicitlyStartBackgroundWork and set v = backgroundCompiler.ImplicitlyStartBackgroundWork <- v
31943202

31953203
static member GlobalForegroundParseCountStatistic = BackgroundCompiler.GlobalForegroundParseCountStatistic
31963204
static member GlobalForegroundTypeCheckCountStatistic = BackgroundCompiler.GlobalForegroundTypeCheckCountStatistic

src/fsharp/vs/service.fsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,11 @@ type FSharpChecker =
676676
/// A maximum number of megabytes of allocated memory. If the figure reported by <c>System.GC.GetTotalMemory(false)</c> goes over this limit, the FSharpChecker object will attempt to free memory and reduce cache sizes to a minimum.</param>
677677
member MaxMemory : int with get, set
678678
679+
/// If true, then calls to CheckFileInProject implicitly start a background check of that project, replacing
680+
/// any other background checks in progress. This is useful in IDE applications with spare CPU cycles as
681+
/// it prepares the project analysis results for use. The default is 'true'.
682+
member ImplicitlyStartBackgroundWork: bool with get, set
683+
679684
[<Obsolete("Renamed to BeforeBackgroundFileCheck")>]
680685
member FileTypeCheckStateIsDirty : IEvent<string>
681686

0 commit comments

Comments
 (0)