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

Allow using project files together with --library #5297

Merged
merged 63 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
27948b8
Include libraries of projects referenced through source or libraries
keyboardDrummer Apr 4, 2024
942394e
Add warning when using non-doo files with --library
keyboardDrummer Apr 4, 2024
e4f9a0d
Update tests
keyboardDrummer Apr 4, 2024
d827340
Add release note
keyboardDrummer Apr 4, 2024
6919db7
Update warning
keyboardDrummer Apr 4, 2024
5f1d9fb
Couple of fixes
keyboardDrummer Apr 5, 2024
3b06f43
Async fixes
keyboardDrummer Apr 5, 2024
3bdbe2a
Resolve warnings
keyboardDrummer Apr 5, 2024
f2c0cec
Tiny refactor
keyboardDrummer Apr 5, 2024
379700f
One fix to Server.Main
keyboardDrummer Apr 5, 2024
cf8e18b
Fix tests
keyboardDrummer Apr 5, 2024
13eaf8e
Fix ProducerLibrary test
keyboardDrummer Apr 5, 2024
c08ac17
Merge branch 'master' into projectAsLibrary
robin-aws Apr 8, 2024
d3da45f
Merge remote-tracking branch 'origin/master' into projectAsLibrary
keyboardDrummer Apr 9, 2024
17fa4c9
Fix warning
keyboardDrummer Apr 9, 2024
f804f17
Merge branch 'master' into projectAsLibrary
keyboardDrummer Apr 9, 2024
3f49b9c
Stop accepting project files as source files
keyboardDrummer Apr 10, 2024
946ccfa
Slightly more refactoring
keyboardDrummer Apr 10, 2024
f2d17a3
Revert "Stop accepting project files as source files"
keyboardDrummer Apr 10, 2024
b6078e4
Merge branch 'master' into warnNonDooLibrary
keyboardDrummer Apr 10, 2024
48e7d10
Merge remote-tracking branch 'origin/master' into warnNonDooLibrary
keyboardDrummer Apr 10, 2024
969b504
Code review
keyboardDrummer Apr 10, 2024
74e3329
Rename .feat file
keyboardDrummer Apr 10, 2024
10d47f1
Merge branch 'warnNonDooLibrary' into projectAsLibrary
keyboardDrummer Apr 10, 2024
3c81005
Add .feat file
keyboardDrummer Apr 10, 2024
fbb49f3
Refactor CreateAndValidate
keyboardDrummer Apr 17, 2024
4f64df6
Check that referenced project files have compatible verification options
keyboardDrummer Apr 17, 2024
6de008e
Merge commit '4e586b5628838c2~1' into projectAsLibrary
keyboardDrummer Apr 17, 2024
682c637
Merge commit '4e586b5628838c2' into projectAsLibrary
keyboardDrummer Apr 17, 2024
6769bca
Merge remote-tracking branch 'origin/master' into projectAsLibrary
keyboardDrummer Apr 17, 2024
d3a2d3d
Merge remote-tracking branch 'fork/projectAsLibrary' into projectAsLi…
keyboardDrummer Apr 17, 2024
acf6338
Properly propagate parse options for includes, fix tests
keyboardDrummer Apr 17, 2024
f831280
Fixes
keyboardDrummer Apr 17, 2024
2d852c3
Merge remote-tracking branch 'origin/master' into projectAsLibrary
keyboardDrummer Apr 17, 2024
8f48b87
Fix warnings
keyboardDrummer Apr 17, 2024
68e18f6
Refactoring
keyboardDrummer Apr 17, 2024
5f8eb4f
Fixes
keyboardDrummer Apr 18, 2024
ed8827b
Merge branch 'master' into projectAsLibrary
keyboardDrummer Apr 18, 2024
3a2ef27
Do not let project files include themselves
keyboardDrummer Apr 18, 2024
848edad
Fixes
keyboardDrummer Apr 18, 2024
b944e5c
Fix for implicit projects
keyboardDrummer Apr 18, 2024
ada83d3
Update doo files
keyboardDrummer Apr 18, 2024
8161f20
Update release notes
keyboardDrummer Apr 19, 2024
9cdf185
Changed and fixes
keyboardDrummer Apr 22, 2024
6c8c234
Remove projectFileAsSource test
keyboardDrummer Apr 22, 2024
69589c0
Remove RegisterModuleLevelOptions
keyboardDrummer Apr 22, 2024
3041683
Fix oops
keyboardDrummer Apr 22, 2024
10847c8
Merge remote-tracking branch 'origin/master' into projectAsLibrary
keyboardDrummer Apr 22, 2024
58768d3
Rename
keyboardDrummer Apr 22, 2024
9318494
Change CheckAndGetLibraryOptions
keyboardDrummer Apr 22, 2024
e51848a
Cleanup code
keyboardDrummer Apr 22, 2024
4af6b73
Update release note
keyboardDrummer Apr 22, 2024
b29e288
Fix
keyboardDrummer Apr 23, 2024
0d5e8b7
Fix tests
keyboardDrummer Apr 23, 2024
7ed8bb6
Fix warning
keyboardDrummer Apr 23, 2024
0071919
Remove unused imports
keyboardDrummer Apr 23, 2024
eb00d69
Tweaks
keyboardDrummer Apr 23, 2024
e7547d6
Merge remote-tracking branch 'fork/projectAsLibrary' into projectAsLi…
keyboardDrummer Apr 23, 2024
87b9bc7
Improve indirection
keyboardDrummer Apr 23, 2024
56e1fd0
Resolve warnings
keyboardDrummer Apr 23, 2024
d4b2a3c
Merge remote-tracking branch 'origin/master' into projectAsLibrary
keyboardDrummer Apr 25, 2024
0e91310
Merge branch 'master' into projectAsLibrary
keyboardDrummer Apr 29, 2024
9d47fd1
Merge branch 'master' into projectAsLibrary
alex-chew Apr 29, 2024
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
15 changes: 8 additions & 7 deletions Source/DafnyCore/AST/Grammar/ProgramParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -62,7 +63,7 @@ public virtual async Task<Program> ParseFiles(string programName, IReadOnlyList<
}

var parseResult = ParseFileWithErrorHandling(
dafnyFile.ParseOptions,
dafnyFile.FileOptions,
dafnyFile.GetContent,
dafnyFile.Origin,
dafnyFile.Uri,
Expand Down Expand Up @@ -96,7 +97,7 @@ public virtual async Task<Program> ParseFiles(string programName, IReadOnlyList<
// if we're building a .doo file.
// See comment on LibraryBackend.DooFile.
if (program.Options.Backend is LibraryBackend libBackend) {
libBackend.ProgramAfterParsing = new Program(new Cloner(true), program);
program.AfterParsingClone = new Program(new Cloner(true), program);
}
}

Expand Down Expand Up @@ -220,7 +221,7 @@ CancellationToken cancellationToken
}

foreach (var root in roots) {
var dafnyFile = await IncludeToDafnyFile(systemModuleManager, errorReporter, root);
var dafnyFile = await IncludeToDafnyFile(errorReporter, root);
if (dafnyFile != null) {
stack.Push(dafnyFile);
}
Expand All @@ -234,15 +235,15 @@ CancellationToken cancellationToken

cancellationToken.ThrowIfCancellationRequested();
var parseIncludeResult = ParseFileWithErrorHandling(
errorReporter.Options,
top.FileOptions,
top.GetContent,
top.Origin,
top.Uri,
cancellationToken);
result.Add(parseIncludeResult);

foreach (var include in parseIncludeResult.Module.Includes) {
var dafnyFile = await IncludeToDafnyFile(systemModuleManager, errorReporter, include);
var dafnyFile = await IncludeToDafnyFile(errorReporter, include);
if (dafnyFile != null) {
stack.Push(dafnyFile);
}
Expand All @@ -252,8 +253,8 @@ CancellationToken cancellationToken
return result;
}

private Task<DafnyFile> IncludeToDafnyFile(SystemModuleManager systemModuleManager, ErrorReporter errorReporter, Include include) {
return DafnyFile.CreateAndValidate(errorReporter, fileSystem, systemModuleManager.Options, include.IncludedFilename, include.tok);
private async Task<DafnyFile> IncludeToDafnyFile(ErrorReporter errorReporter, Include include) {
return await DafnyFile.CreateAndValidate(errorReporter, fileSystem, include.ParseOptions, include.IncludedFilename, include.tok);
}

///<summary>
Expand Down
4 changes: 3 additions & 1 deletion Source/DafnyCore/AST/Include.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
namespace Microsoft.Dafny;

public class Include : TokenNode, IComparable {
public DafnyOptions ParseOptions { get; }
public Uri IncluderFilename { get; }
public Uri IncludedFilename { get; }
public string CanonicalPath { get; }

public Include(IToken tok, Uri includer, Uri theFilename) {
public Include(IToken tok, Uri includer, Uri theFilename, DafnyOptions parseOptions) {
this.tok = tok;
this.IncluderFilename = includer;
this.IncludedFilename = theFilename;
ParseOptions = parseOptions;
this.CanonicalPath = DafnyFile.Canonicalize(theFilename.LocalPath).LocalPath;
}

Expand Down
1 change: 0 additions & 1 deletion Source/DafnyCore/AST/Members/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ static Function() {
DafnyOptions.RegisterLegacyBinding(FunctionSyntaxOption, (options, value) => {
options.FunctionSyntax = functionSyntaxOptionsMap[value];
});

DooFile.RegisterNoChecksNeeded(FunctionSyntaxOption);
}

Expand Down
14 changes: 14 additions & 0 deletions Source/DafnyCore/AST/Members/Method.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
using System.Collections.Generic;
using System.CommandLine;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Numerics;
using DafnyCore;
using Microsoft.Dafny.Auditor;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;

namespace Microsoft.Dafny;

public class Method : MethodOrFunction, TypeParameter.ParentType,
IMethodCodeContext, ICanFormat, IHasDocstring, IHasSymbolChildren, ICanAutoRevealDependencies, ICanVerify {

public static readonly Option<bool> ReadsClausesOnMethods = new("--reads-clauses-on-methods",
"Allows reads clauses on methods (with a default of 'reads *') as well as functions."
);

static Method() {
DafnyOptions.RegisterLegacyUi(ReadsClausesOnMethods, DafnyOptions.ParseBoolean, "Language feature selection", "readsClausesOnMethods", @"
0 (default) - Reads clauses on methods are forbidden.
1 - Reads clauses on methods are permitted (with a default of 'reads *').".TrimStart(), defaultValue: false);
DooFile.RegisterLibraryCheck(ReadsClausesOnMethods, DooFile.CheckOptionLocalImpliesLibrary);
}

public override IEnumerable<INode> Children => new Node[] { Body, Decreases }.Where(x => x != null).
Concat(Ins).Concat(Outs).Concat<Node>(TypeArgs).
Concat(Req).Concat(Ens).Concat(Reads.Expressions).Concat(Mod.Expressions);
Expand Down
18 changes: 18 additions & 0 deletions Source/DafnyCore/AST/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ void ObjectInvariant() {

public ProofDependencyManager ProofDependencyManager { get; set; } = new();

/// <summary>
/// Serializing the state of the Program passed to this backend,
/// after resolution, can be problematic.
/// If nothing else, very early on in the resolution process
/// we create explicit module definitions for implicit ones appearing
/// in qualified names such as `module A.B.C { ... }`,
/// and this means that multiple .doo files would then not be able to
/// share these prefixes without hitting duplicate name errors.
///
/// Instead we serialize the state of the program immediately after parsing.
/// See also ProgramParser.ParseFiles().
///
/// This could be captured somewhere else, such as on the Program itself,
/// if having this state here hampers reuse in the future,
/// especially parallel processing.
/// </summary>
public Program AfterParsingClone { get; set; }

public Program(string name, [Captured] LiteralModuleDecl module, [Captured] SystemModuleManager systemModuleManager, ErrorReporter reporter,
CompilationData compilation) {
Contract.Requires(name != null);
Expand Down
29 changes: 7 additions & 22 deletions Source/DafnyCore/Backends/Library/LibraryBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,6 @@ public override string TargetBaseDir(string dafnyProgramName) =>
// Necessary since Compiler is null
public override string ModuleSeparator => ".";

/// <summary>
/// Serializing the state of the Program passed to this backend,
/// after resolution, can be problematic.
/// If nothing else, very early on in the resolution process
/// we create explicit module definitions for implicit ones appearing
/// in qualified names such as `module A.B.C { ... }`,
/// and this means that multiple .doo files would then not be able to
/// share these prefixes without hitting duplicate name errors.
///
/// Instead we serialize the state of the program immediately after parsing.
/// See also ProgramParser.ParseFiles().
///
/// This could be captured somewhere else, such as on the Program itself,
/// if having this state here hampers reuse in the future,
/// especially parallel processing.
/// </summary>
internal Program ProgramAfterParsing { get; set; }

protected override SinglePassCodeGenerator CreateCodeGenerator() {
return null;
}
Expand All @@ -72,7 +54,7 @@ public override void Compile(Program dafnyProgram, ConcreteSyntaxTree output) {
throw new UnsupportedFeatureException(dafnyProgram.GetStartOfFirstFileToken(), Feature.LegacyCLI);
}

var dooFile = new DooFile(ProgramAfterParsing);
var dooFile = new DooFile(dafnyProgram.AfterParsingClone);
dooFile.Write(output);
}

Expand All @@ -81,10 +63,10 @@ public override void EmitCallToMain(Method mainMethod, string baseName, Concrete
}

private string DooFilePath(string dafnyProgramName) {
return Path.GetFullPath(Path.ChangeExtension(dafnyProgramName, ".doo"));
return Path.GetFullPath(Path.ChangeExtension(dafnyProgramName, DooFile.Extension));
}

public override Task<(bool Success, object CompilationResult)> CompileTargetProgram(string dafnyProgramName,
public override async Task<(bool Success, object CompilationResult)> CompileTargetProgram(string dafnyProgramName,
string targetProgramText, string callToMain,
string targetFilename,
ReadOnlyCollection<string> otherFileNames, bool runAfterCompile, TextWriter outputWriter) {
Expand All @@ -94,8 +76,11 @@ private string DooFilePath(string dafnyProgramName) {

File.Delete(dooPath);
ZipFile.CreateFromDirectory(targetDirectory, dooPath);
if (Options.Verbose) {
await outputWriter.WriteLineAsync($"Wrote Dafny library to {dooPath}");
}

return Task.FromResult((true, (object)null));
return (true, null);
}

public override Task<bool> RunTargetProgram(string dafnyProgramName, string targetProgramText, string callToMain,
Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyCore/Dafny.atg
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Dafny
string basePath = parsedFile.Scheme == "stdin" ? "" : Path.GetDirectoryName(parsedFile.LocalPath);
includedFile = Path.Combine(basePath, includedFile);
}
var oneInclude = new Include(t, parsedFile, new Uri(Path.GetFullPath(includedFile)));
var oneInclude = new Include(t, parsedFile, new Uri(Path.GetFullPath(includedFile)), theOptions);
oneInclude.RangeToken = new RangeToken(includeStartToken, t);
theModule.Includes.Add(oneInclude);
}
Expand Down
Loading