Skip to content

Commit

Permalink
Stop reusing solvers with the IDE by default (#5325)
Browse files Browse the repository at this point in the history
### Description
- By default, do not let the IDE reuse solvers between compilations.
This makes the IDE verification behavior more like that of the CLI

### How has this been tested?
Manually tested that latency of verification after a change still feels
snappy

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
  • Loading branch information
keyboardDrummer committed Apr 17, 2024
1 parent 91cdb2b commit b34471f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions Source/DafnyDriver/Commands/ServerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ServerCommand {
LanguageServer.VerifySnapshots,
DafnyLangSymbolResolver.UseCaching,
ProjectManager.UpdateThrottling,
ProjectManager.ReuseSolvers,
LegacySignatureAndCompletionTable.MigrateSignatureAndCompletionTable
);
}
Expand Down
29 changes: 24 additions & 5 deletions Source/DafnyLanguageServer/Workspace/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class ProjectManager : IDisposable {
ArgumentHelpName = "event"
};

public static readonly Option<bool> ReuseSolvers = new("--reuse-solvers",
@"(experimental) Reuse solver for different verification of different document versions. Reduces verification latency but may reduce reliability of verification.".TrimStart()) {
ArgumentHelpName = "event"
};

private readonly CreateMigrator createMigrator;
public DafnyProject Project { get; }

Expand All @@ -55,6 +60,9 @@ public class ProjectManager : IDisposable {
private readonly EventLoopScheduler ideStateUpdateScheduler = new();
private readonly ILogger<ProjectManager> logger;

private readonly VerificationResultCache cache;
private readonly CustomStackSizePoolTaskScheduler scheduler;

/// <summary>
/// The version of this project.
/// Is incremented when any file in the project is updated.
Expand All @@ -73,7 +81,7 @@ public class ProjectManager : IDisposable {
private readonly DafnyOptions options;
private readonly DafnyOptions serverOptions;
private readonly CreateCompilation createCompilation;
private readonly ExecutionEngine boogieEngine;
private ExecutionEngine? boogieEngine;
private readonly IFileSystem fileSystem;
private readonly TelemetryPublisherBase telemetryPublisher;
private readonly IProjectDatabase projectDatabase;
Expand Down Expand Up @@ -104,13 +112,14 @@ public class ProjectManager : IDisposable {

options = DetermineProjectOptions(project, serverOptions);
options.Printer = new OutputLogger(logger);
boogieEngine = new ExecutionEngine(options, cache, scheduler);
this.cache = cache;
this.scheduler = scheduler;
var compilationInput = new CompilationInput(options, version, Project);
var initialIdeState = IdeState.InitialIdeState(compilationInput);
latestIdeState = initialIdeState;

observer = createIdeStateObserver(initialIdeState);
Compilation = createCompilation(boogieEngine, compilationInput);
Compilation = this.createCompilation(GetBoogie(), compilationInput);

observerSubscription = Disposable.Empty;
}
Expand All @@ -135,7 +144,7 @@ public class ProjectManager : IDisposable {

Compilation.Dispose();
var input = new CompilationInput(options, version, Project);
Compilation = createCompilation(boogieEngine, input);
Compilation = createCompilation(GetBoogie(), input);
var migratedUpdates = GetStates(Compilation);
states = new ReplaySubject<IdeState>(1);
var statesSubscription = observerSubscription =
Expand All @@ -155,6 +164,16 @@ public class ProjectManager : IDisposable {
TriggerVerificationForFile(triggeringFile);
}

private ExecutionEngine GetBoogie() {
if (options.Get(ReuseSolvers)) {
boogieEngine ??= new ExecutionEngine(options, cache, scheduler);
} else {
boogieEngine?.Dispose();
boogieEngine = new ExecutionEngine(options, cache, scheduler);
}
return boogieEngine;
}

private void UpdateRecentChanges(DidChangeTextDocumentParams changes, Migrator? migrator) {
lock (RecentChanges) {
var newChanges = changes.ContentChanges.Where(c => c.Range != null).
Expand Down Expand Up @@ -354,7 +373,7 @@ public class ProjectManager : IDisposable {
}

public void Dispose() {
boogieEngine.Dispose();
boogieEngine?.Dispose();
Compilation.Dispose();
observerSubscription.Dispose();
// Dispose the update scheduler after the observer subscription, to prevent accessing a disposed object.
Expand Down

0 comments on commit b34471f

Please sign in to comment.