Skip to content

Module-level options #4598

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

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from
Draft
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
4235832
Optimize uses clauses added by Translator.cs
zafer-esen Aug 16, 2023
7ac0fbe
Add trigger to an axiom that was incorrectly being pruned away.
zafer-esen Aug 16, 2023
943ade9
Revert change in Translator for Boogie compatibility.
zafer-esen Aug 16, 2023
b52e014
Update integration tests. Minor changes in the prelude.
zafer-esen Aug 17, 2023
99a24cc
Simplify certain formulas with literals.
zafer-esen Aug 21, 2023
0f76db6
Fixes some issues introduced during merge with upstream.
zafer-esen Sep 8, 2023
81ce40e
Fixes another issue introduced during merge.
zafer-esen Sep 8, 2023
1224fd2
Simplify F in BplAnd.
zafer-esen Sep 8, 2023
80bde0a
Make BplIff static.
zafer-esen Sep 8, 2023
09dcb06
Merge branch 'master' into simplify-imp-iff
zafer-esen Sep 8, 2023
ec7b088
Adds a few more and replacements.
zafer-esen Sep 8, 2023
56ebbf7
Merge branch 'master' into simplify-imp-iff
zafer-esen Sep 11, 2023
7234e99
More simplification for BplIff
zafer-esen Sep 11, 2023
17e4d53
Specialize Seq#{Singleon,Index} axioms to Box
atomb Jun 5, 2023
166f9e2
Specialize all Seq#Update axioms to box
atomb Jun 5, 2023
b9710a6
Specialize MultiSet#FromSeq to Box
atomb Jun 5, 2023
f0471f1
Specialize all but one Seq axiom to Box
atomb Jun 6, 2023
9f8f0a3
Specialize auto-generated axiom to Box
atomb Jun 6, 2023
309c711
Specialize one final Seq axiom to Box
atomb Jun 6, 2023
e27ab51
Remove type parameters from Seq operations
atomb Jun 7, 2023
31bd8a7
Remove type parameter from Seq type
atomb Jun 8, 2023
daa3f3b
WIP
atomb Jun 20, 2023
9b5cbc9
Optionally inline Seq functions
atomb Jun 21, 2023
cd1a3c5
Fix off by one error in Seq Update
zafer-esen Aug 25, 2023
4ab927d
Removes polymorphism from types and reverts Seq builtin theory change…
zafer-esen Sep 11, 2023
3de483a
Update Dafny model parameters for monomorphic collections.
zafer-esen Sep 11, 2023
b32d4b8
Revert unrelated changes
zafer-esen Sep 11, 2023
ce6cb75
Merge back reverted changes in previous commit from master
zafer-esen Sep 11, 2023
7075a2f
Splits away collection type axiomatizations.
zafer-esen Sep 11, 2023
0c4751e
Disable Lit in modules not needing fuel.
zafer-esen Sep 12, 2023
1bc4fb4
Fixes a bug where fuel usage was not detected.
zafer-esen Sep 12, 2023
e4ecd13
Merge branch 'master' into monomorphic-types
zafer-esen Sep 12, 2023
deb6584
Merge branch 'master' into split-prelude
zafer-esen Sep 12, 2023
ca4b1ac
An attempt to fix incorrect type names in counterexamples
zafer-esen Sep 13, 2023
738dbe8
Merge branch 'master' into monomorphic-types
zafer-esen Sep 13, 2023
e133bd0
Update test expected outputs
zafer-esen Sep 13, 2023
bbddd74
Merge branch 'monomorphic-types' into split-prelude
zafer-esen Sep 13, 2023
9e2f304
Merge branch 'master' into fewer-lits
zafer-esen Sep 13, 2023
7c52a0d
Remove obsolete comments
zafer-esen Sep 13, 2023
f3f4b4f
Merge branch 'master' into monomorphic-types
zafer-esen Sep 14, 2023
ab2dcf3
Merge branch 'monomorphic-types' into split-prelude
zafer-esen Sep 14, 2023
d820e8d
Merge branch 'master' into monomorphic-types
zafer-esen Sep 15, 2023
27588ea
Merge branch 'master' into monomorphic-types
zafer-esen Sep 15, 2023
29b25bb
Merge branch 'master' into monomorphic-types
zafer-esen Sep 18, 2023
ef924dd
Merge branch 'monomorphic-types' into split-prelude
zafer-esen Sep 18, 2023
ede9181
Adds support for several module-level attributes
zafer-esen Sep 18, 2023
0d2ca3a
Merge branch 'fewer-lits' into module-options
zafer-esen Sep 18, 2023
4b81584
Merge branch 'simplify-imp-iff' into module-options
zafer-esen Sep 18, 2023
7401e63
Add module-level isolate-assertions
zafer-esen Sep 18, 2023
54bbcbb
Attribute to set prover options and choose solver
zafer-esen Sep 19, 2023
00f1d49
Merge branch 'master' into monomorphic-types
zafer-esen Sep 25, 2023
4228f5c
Merge branch 'master' into simplify-imp-iff
zafer-esen Sep 25, 2023
7c83590
Merge branch 'monomorphic-types' into split-prelude
zafer-esen Sep 25, 2023
65bccc1
No duplicate symbol status (#4523)
keyboardDrummer Sep 12, 2023
08e5fc1
Support all option types in the project file (#4506)
keyboardDrummer Sep 12, 2023
4cd4c81
Go to definition simple module import (#4534)
keyboardDrummer Sep 12, 2023
2a3edc3
Merge branch 'master' into fewer-lits
zafer-esen Sep 25, 2023
4dc1c0e
Consider Lit when simplifying and update expected test results.
zafer-esen Sep 25, 2023
898beb1
Merge branch 'master' into module-options
zafer-esen Sep 29, 2023
8f7148f
Merge branch 'split-prelude' into module-options
zafer-esen Sep 29, 2023
87a95d1
Merge branch 'simplify-imp-iff' into module-options
zafer-esen Sep 29, 2023
8ffb7d0
Merge branch 'fewer-lits' into module-options
zafer-esen Sep 29, 2023
ee7e0d3
Merge branch 'master' into module-options
zafer-esen Sep 29, 2023
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
7 changes: 7 additions & 0 deletions Source/DafnyCore/AST/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ void ObjectInvariant() {
public static string ExternAttributeName = "extern";
public static string VerifyAttributeName = "verify";
public static string AutoGeneratedAttributeName = "auto_generated";
public static string TypeEncodingAttributeName = "type_encoding";
public static string PruneAttributeName = "prune";
public static string SolverAttributeName = "solver";
public static string NativeSeqAttributeName = "native_seq";
public static string NoLitAttributeName = "no_lit";
public static string IsolateAssertionsAttriubuteName = "isolate_assertions";
public static string ProverOptAttributeName = "prover_opt";

public string Name;
/*Frozen*/
Expand Down
72 changes: 72 additions & 0 deletions Source/DafnyCore/AST/Modules/ModuleDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
using System.Linq;
using Microsoft.Boogie.SMTLib;
using Microsoft.Dafny.Auditor;

namespace Microsoft.Dafny;
Expand Down Expand Up @@ -49,6 +50,7 @@ public string FullName {
public readonly bool IsFacade; // True iff this module represents a module facade (that is, an abstract interface)
private readonly bool IsBuiltinName; // true if this is something like _System that shouldn't have it's name mangled.

public bool UsesFuel = false; // Set by Translator.ComputeFunctionFuel
public DefaultClassDecl DefaultClass { get; set; }

public readonly List<TopLevelDecl> SourceDecls = new();
Expand All @@ -69,6 +71,76 @@ public string FullName {
: new[] { new Pointer<TopLevelDecl>(() => DefaultClass, v => DefaultClass = (DefaultClassDecl)v) }).
Concat(SourceDecls.ToPointers()).Concat(ResolvedPrefixNamedModules.ToPointers());

public Boogie.CoreOptions.TypeEncoding? GetTypeEncodingAttribute {
get {
if (Attributes.Find(Attributes, Attributes.TypeEncodingAttributeName) is Attributes te
&& te.Args.Count == 1
&& te.Args[0] is LiteralExpr { Value: string encoding }) {
return encoding switch {
"p" => Boogie.CoreOptions.TypeEncoding.Predicates,
"a" => Boogie.CoreOptions.TypeEncoding.Arguments,
"m" => Boogie.CoreOptions.TypeEncoding.Monomorphic,
_ => null
};
}
return null;
}
}

public bool? GetPruneAttribute {
get {
if (Attributes.Find(Attributes, Attributes.PruneAttributeName) is Attributes pa
&& pa.Args.Count == 1
&& pa.Args[0] is LiteralExpr { Value: string prune }) {
return int.Parse(prune) switch {
1 => true,
0 => false,
_ => null
};
}
return null;
}
}

public List<(string, string)> GetAllProverOptAttributes {
get {
var allExpressions = Attributes.FindAllExpressions(Attributes, Attributes.ProverOptAttributeName);
if (allExpressions == null) {
return null;
}
return allExpressions
.SelectMany(exprs => exprs.Select(expr => expr?.AsStringLiteral()?.Split('=')))
.Where(splitArray => splitArray is {Length: 2})
.Select(splitArray => (splitArray[0], splitArray[1]))
.ToList();
}
}

public SolverKind? GetSolverAttribute {
get {
if (Attributes.Find(Attributes, Attributes.SolverAttributeName) is Attributes te
&& te.Args.Count == 1
&& te.Args[0] is LiteralExpr { Value: string encoding }) {
return encoding switch {
"cvc5" => SolverKind.CVC5,
"z3" => SolverKind.Z3,
"yices2" => SolverKind.YICES2,
_ => null
};
}
return null;
}
}

public bool UseNativeSeq =>
Attributes.Contains(Attributes, Attributes.NativeSeqAttributeName);

public bool NoLits =>
Attributes.Contains(Attributes, Attributes.NoLitAttributeName);

public bool IsolateAssertions =>
Attributes.Contains(Attributes, Attributes.IsolateAssertionsAttriubuteName);

public IEnumerable<TopLevelDecl> DefaultClasses {
get { return DefaultClass == null ? Enumerable.Empty<TopLevelDecl>() : new TopLevelDecl[] { DefaultClass }; }
}
Expand Down
7 changes: 7 additions & 0 deletions Source/DafnyCore/DafnyCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@

<ItemGroup>
<Content Include="DafnyPrelude.bpl" CopyToOutputDirectory="PreserveNewest" />
<Content Include="DafnyPreludeSeqNative.bpl" CopyToOutputDirectory="PreserveNewest" />
<Content Include="DafnyPreludeSeqAxiom.bpl" CopyToOutputDirectory="PreserveNewest" />
<Content Include="DafnyPreludeSetAxiom.bpl" CopyToOutputDirectory="PreserveNewest" />
<Content Include="DafnyPreludeISetAxiom.bpl" CopyToOutputDirectory="PreserveNewest" />
<Content Include="DafnyPreludeMultiSetAxiom.bpl" CopyToOutputDirectory="PreserveNewest" />
<Content Include="DafnyPreludeMapAxiom.bpl" CopyToOutputDirectory="PreserveNewest" />
<Content Include="DafnyPreludeIMapAxiom.bpl" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
49 changes: 46 additions & 3 deletions Source/DafnyCore/DafnyOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Reflection;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
using Microsoft.Boogie.SMTLib;
using Microsoft.Dafny;
using Microsoft.Dafny.Compilers;
using Microsoft.Dafny.Plugins;
Expand Down Expand Up @@ -311,6 +312,20 @@ public enum DiagnosticsFormats {
public bool AllowSourceFolders = false;
public List<string> SourceFolders { get; } = new(); // list of folders, for those commands that permit processing all source files in folders

public bool UseSeqs = true;
public bool UseSeqTheory = false; // Requires UseSeqs = true. TypeEncoding must be Monomorphic.
public bool InlineSeqTheoryFunctions = true; // Do not enable if theory functions are used in axiom triggers.
public bool UseSets = true;
public bool UseISets = true;
public bool UseMultiSets = true;
public bool UseMaps = true;
public bool UseIMaps = true;
public string CVC5Path = null;
public bool UseLits = true;

public SolverKind Solver = SolverKind.Z3; // TODO: Heads up: this is not currently used!
public int Z3CaseSplitValue = 3;

public enum ContractTestingMode {
None,
Externs,
Expand Down Expand Up @@ -824,6 +839,18 @@ protected bool ParseDafnySpecificOption(string name, Bpl.CommandLineParseState p
}
}
return true;

case "prune":
if (ps.ConfirmArgumentCount(1)) {
if (args[ps.i] == "1") {
Prune = true;
} else if (args[ps.i] == "0") {
Prune = false;
} else {
InvalidArgumentError(name, ps);
}
}
return true;
}

// Defer to superclass
Expand Down Expand Up @@ -872,6 +899,8 @@ public void ApplyDefaultOptionsWithoutSettingsDefault() {
SetZ3Options(z3Version);
}

SetCVC5ExecutablePath();

// Ask Boogie to perform abstract interpretation
UseAbstractInterpretation = true;
Ai.J_Intervals = true;
Expand Down Expand Up @@ -1163,6 +1192,16 @@ private Version SetZ3ExecutablePath() {
return null;
}

private void SetCVC5ExecutablePath() {
var platform = System.Environment.OSVersion.Platform;
var isUnix = platform == PlatformID.Unix || platform == PlatformID.MacOSX;
CVC5Path ??= System.Environment
.GetEnvironmentVariable("PATH")?
.Split(isUnix ? ':' : ';')
.Select(s => Path.Combine(s, isUnix ? "cvc5" : "cvc5.exe"))
.FirstOrDefault(File.Exists);
}

private static readonly Regex Z3VersionRegex = new Regex(@"Z3 version (?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)");

[CanBeNull]
Expand Down Expand Up @@ -1193,9 +1232,13 @@ public static Version GetZ3Version(string proverPath) {
}

// Set a Z3 option, but only if it is not overwriting an existing option.
private void SetZ3Option(string name, string value) {
if (!ProverOptions.Any(o => o.StartsWith($"O:{name}="))) {
ProverOptions.Add($"O:{name}={value}");
public void SetZ3Option(string name, string value, bool overwrite = false) {
string optionPrefix = $"O:{name}=";
int index = ProverOptions.FindIndex(o => o.StartsWith(optionPrefix));
if (index == -1) {
ProverOptions.Add($"{optionPrefix}{value}");
} else if (overwrite) {
ProverOptions[index] = $"{optionPrefix}{value}";
}
}

Expand Down
Loading