Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug that occurred when using resolution caching and replaceable modules #5189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Source/DafnyCore/AST/Modules/ModuleQualifiedId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public ModuleQualifiedId(List<Name> path) {

public ModuleQualifiedId(Cloner cloner, ModuleQualifiedId original) {
Path = original.Path.Select(n => n.Clone(cloner)).ToList();
Root = original.Root;
if (cloner.CloneResolvedFields) {
Root = original.Root;
}
}

public string RootName() {
Expand Down
6 changes: 6 additions & 0 deletions Source/DafnyCore/Resolver/ProgramResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ private void CheckDuplicateModuleNames(Program program) {
}

protected void InstantiateReplaceableModules(Program dafnyProgram) {
foreach (var compiledModule in dafnyProgram.Modules()) {
// This is a workaround for the problem that the IDE caches resolved modules,
// So this field might still be set from a previous compilation.
// Better solution is described here: https://github.com/dafny-lang/dafny/issues/5188
compiledModule.Replacement = null;
}
foreach (var compiledModule in dafnyProgram.Modules().OrderByDescending(m => m.Height)) {
if (compiledModule.Implements is { Kind: ImplementationKind.Replacement }) {
var target = compiledModule.Implements.Target.Def;
Expand Down
34 changes: 34 additions & 0 deletions Source/DafnyLanguageServer.Test/ProjectFiles/StandardLibrary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.IO;
using System.Threading.Tasks;
using Microsoft.Dafny.LanguageServer.IntegrationTest.Util;
using Microsoft.Extensions.Logging;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Dafny.LanguageServer.IntegrationTest.ProjectFiles;

public class StandardLibrary : ClientBasedLanguageServerTest {

[Fact]
public async Task EditWhenUsingStandardLibrary() {
var projectFile = @"
[options]
standard-libraries=true
";
var program = @"
method Foo() ensures false { }
".TrimStart();
var path = Path.GetRandomFileName();
var project = CreateAndOpenTestDocument(projectFile, Path.Combine(path, DafnyProject.FileName));
var document = CreateAndOpenTestDocument(program, Path.Combine(path, "EditWhenUsingStandardLibrary.dfy"));
var diagnostics1 = await GetLastDiagnostics(document);
Assert.Single(diagnostics1);
ApplyChange(ref document, new Range(0, 0, 1, 0), "method Bar() ensures true { }");
var diagnostics2 = await GetLastDiagnostics(document);
Assert.Empty(diagnostics2);
}

public StandardLibrary(ITestOutputHelper output, LogLevel dafnyLogLevel = LogLevel.Information) : base(output, dafnyLogLevel) {
}
}
6 changes: 3 additions & 3 deletions Source/DafnyLanguageServer/DafnyLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ private static void PublishSolverPath(ILanguageServer server) {
var proverOptions = new SMTLibSolverOptions(options);
proverOptions.Parse(options.ProverOptions);
solverPath = proverOptions.ExecutablePath();
HandleZ3Version(telemetryPublisher, proverOptions);
HandleZ3Version(telemetryPublisher, solverPath);
} catch (Exception e) {
solverPath = $"Error while determining solver path: {e}";
}

telemetryPublisher.PublishSolverPath(solverPath);
}

private static void HandleZ3Version(TelemetryPublisherBase telemetryPublisher, SMTLibSolverOptions proverOptions) {
var z3Version = DafnyOptions.GetZ3Version(proverOptions.ProverPath);
private static void HandleZ3Version(TelemetryPublisherBase telemetryPublisher, string solverPath) {
var z3Version = DafnyOptions.GetZ3Version(solverPath);
if (z3Version is null) {
return;
}
Expand Down