Skip to content

Commit

Permalink
Allow not migrating legacy symbols (#4674)
Browse files Browse the repository at this point in the history
### Description
Attempt at making `QuickEditsInLargeFile` pass more reliably on OSX

### How has this been tested?
It's a change intended to affect the existing test
`QuickEditsInLargeFile`

<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 authored and robin-aws committed Oct 18, 2023
1 parent 30cdf42 commit bc1bd5e
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Source/DafnyDriver/Commands/ServerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ static ServerCommand() {
GutterIconAndHoverVerificationDetailsManager.LineVerificationStatus,
LanguageServer.VerifySnapshots,
DafnyLangSymbolResolver.UseCaching,
ProjectManager.UpdateThrottling
ProjectManager.UpdateThrottling,
LegacySignatureAndCompletionTable.MigrateSignatureAndCompletionTable
);
}

Expand Down
2 changes: 2 additions & 0 deletions Source/DafnyLanguageServer.Test/Performance/LargeFilesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Microsoft.Dafny.LanguageServer.IntegrationTest.Extensions;
using Microsoft.Dafny.LanguageServer.IntegrationTest.Util;
using Microsoft.Dafny.LanguageServer.Language.Symbols;
using Microsoft.Dafny.LanguageServer.Workspace;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -18,6 +19,7 @@ protected override Task SetUp(Action<DafnyOptions> modifyOptions) {
modifyOptions?.Invoke(options);
// We're setting LineVerificationStatus to false already, with the expectation that this will become the default.
options.Set(GutterIconAndHoverVerificationDetailsManager.LineVerificationStatus, false);
options.Set(LegacySignatureAndCompletionTable.MigrateSignatureAndCompletionTable, false);
options.Set(ProjectManager.UpdateThrottling, ProjectManager.DefaultThrottleTime);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task CancelUnstartedCompilationLeadsToCancelledTasks() {
new Mock<IProgramVerifier>().Object,
new Mock<IGutterIconAndHoverVerificationDetailsManager>().Object,
dafnyOptions,
null, new Compilation(0, new DafnyProject() { Uri = new Uri(Directory.GetCurrentDirectory()) }, new Uri[] { }), null);
null, new Compilation(dafnyOptions, 0, new DafnyProject() { Uri = new Uri(Directory.GetCurrentDirectory()) }, new Uri[] { }), null);
compilationManager.CancelPendingUpdates();
await Assert.ThrowsAsync<TaskCanceledException>(() => compilationManager.ParsedCompilation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task LoadReturnsCanceledTaskIfOperationIsCanceled() {

private static Compilation GetCompilation() {
var versionedTextDocumentIdentifier = CreateTestDocumentId();
var compilation = new Compilation(0, ProjectManagerDatabase.ImplicitProject(versionedTextDocumentIdentifier.Uri.ToUri()), new[] { versionedTextDocumentIdentifier.Uri.ToUri() });
var compilation = new Compilation(DafnyOptions.Default, 0, ProjectManagerDatabase.ImplicitProject(versionedTextDocumentIdentifier.Uri.ToUri()), new[] { versionedTextDocumentIdentifier.Uri.ToUri() });
return compilation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.CommandLine;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
Expand All @@ -16,6 +18,11 @@ namespace Microsoft.Dafny.LanguageServer.Language.Symbols {
/// Represents the symbol table
/// </summary>
public class LegacySignatureAndCompletionTable {

public static readonly Option<bool> MigrateSignatureAndCompletionTable = new("--migrate-signature-and-completion-table", () => true) {
IsHidden = true
};

private readonly ILogger<LegacySignatureAndCompletionTable> logger;

// TODO Guard the properties from changes
Expand Down Expand Up @@ -54,16 +61,27 @@ public static LegacySignatureAndCompletionTable Empty(DafnyOptions options, Dafn
symbolsResolved: false);
}

private static readonly ConditionalWeakTable<DafnyOptions, SystemModuleManager> systemModuleManagers = new();

public static Program GetEmptyProgram(DafnyOptions options, Uri uri) {
var outerModule = new DefaultModuleDefinition();
var errorReporter = new DiagnosticErrorReporter(options, uri);
var compilation = new CompilationData(errorReporter, new List<Include>(), new List<Uri>(), Sets.Empty<Uri>(),
Sets.Empty<Uri>());

SystemModuleManager manager;
lock (options) {
if (!systemModuleManagers.TryGetValue(options, out manager!)) {
manager = new SystemModuleManager(options);
systemModuleManagers.Add(options, manager);
}
}

var emptyProgram = new Program(
uri.ToString(),
new LiteralModuleDecl(outerModule, null, Guid.NewGuid()),
// BuiltIns cannot be initialized without Type.ResetScopes() before.
new SystemModuleManager(options), // TODO creating a BuiltIns is a heavy operation
manager,
errorReporter, compilation
);
return emptyProgram;
Expand Down
3 changes: 2 additions & 1 deletion Source/DafnyLanguageServer/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class LanguageServer {
ProjectManager.UpdateThrottling,
DeveloperOptionBag.BoogiePrint,
CommonOptionBag.EnforceDeterminism,
CommonOptionBag.UseJavadocLikeDocstringRewriterOption
CommonOptionBag.UseJavadocLikeDocstringRewriterOption,
LegacySignatureAndCompletionTable.MigrateSignatureAndCompletionTable
}.Concat(DafnyCommands.VerificationOptions).
Concat(DafnyCommands.ResolverOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public class Compilation {
/// </summary>
public IReadOnlyList<Uri> RootUris { get; }
public int Version { get; }
public DafnyOptions Options { get; }
public DafnyProject Project { get; }
public DocumentUri Uri => Project.Uri;

public Compilation(int version, DafnyProject project, IReadOnlyList<Uri> rootUris) {
public Compilation(DafnyOptions options, int version, DafnyProject project, IReadOnlyList<Uri> rootUris) {
this.RootUris = rootUris;
Options = options;
Version = version;
Project = project;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public CompilationAfterParsing(Compilation compilation,
Program program,
IReadOnlyDictionary<Uri, List<DafnyDiagnostic>> diagnostics,
Dictionary<Uri, DocumentVerificationTree> verificationTrees)
: base(compilation.Version, compilation.Project, compilation.RootUris) {
: base(compilation.Options, compilation.Version, compilation.Project, compilation.RootUris) {
ResolutionDiagnostics = diagnostics;
VerificationTrees = verificationTrees;
Program = program;
Expand Down
3 changes: 2 additions & 1 deletion Source/DafnyLanguageServer/Workspace/IdeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public IdeState Migrate(Migrator migrator, int version) {
return this with {
Version = version,
VerificationResults = MigrateImplementationViews(migrator, VerificationResults),
SignatureAndCompletionTable = migrator.MigrateSymbolTable(SignatureAndCompletionTable),
SignatureAndCompletionTable = Compilation.Options.Get(LegacySignatureAndCompletionTable.MigrateSignatureAndCompletionTable)
? migrator.MigrateSymbolTable(SignatureAndCompletionTable) : LegacySignatureAndCompletionTable.Empty(Compilation.Options, Compilation.Project),
VerificationTrees = migratedVerificationTrees
};
}
Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyLanguageServer/Workspace/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public ProjectManager(

private Compilation CreateInitialCompilation() {
var rootUris = Project.GetRootSourceUris(fileSystem).Concat(options.CliRootSourceUris).ToList();
return new Compilation(version, Project, rootUris);
return new Compilation(options, version, Project, rootUris);
}

private const int MaxRememberedChanges = 100;
Expand Down

0 comments on commit bc1bd5e

Please sign in to comment.