Skip to content

Commit 62a134b

Browse files
committed
Merge branch 'master' into triggers-for-such-that
2 parents de78f97 + 3ace905 commit 62a134b

File tree

109 files changed

+2244
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2244
-296
lines changed

.github/workflows/msbuild.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: dotnet tool restore
3838
- name: Check whitespace and style
3939
working-directory: dafny
40-
run: dotnet format whitespace Source/Dafny.sln --verify-no-changes --exclude Source/DafnyCore/Scanner.cs --exclude Source/DafnyCore/Parser.cs --exclude Source/DafnyCore/GeneratedFromDafny/* --exclude Source/DafnyCore.Test/GeneratedFromDafny/* --exclude Source/DafnyRuntime/DafnyRuntimeSystemModule.cs
40+
run: dotnet format whitespace Source/Dafny.sln --verify-no-changes --exclude Source/DafnyCore/Generic/Deserializer/Generated.cs --exclude Source/DafnyCore/Scanner.cs --exclude Source/DafnyCore/Parser.cs --exclude Source/DafnyCore/GeneratedFromDafny/* --exclude Source/DafnyCore.Test/GeneratedFromDafny/* --exclude Source/DafnyRuntime/DafnyRuntimeSystemModule.cs
4141
- name: Check that it's possible to bump the version
4242
working-directory: dafny
4343
run: make bumpversion-test

.github/workflows/runtime-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ jobs:
4949
run: dotnet build Source/Dafny.sln
5050
- name: Get Z3
5151
run: make z3-ubuntu
52+
- name: Test using outer Makefile
53+
run: |
54+
make test-integration
5255
- name: Test DafnyCore
5356
run: |
5457
cd ./Source/DafnyCore

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ repos:
55
name: dotnet-format
66
language: system
77
entry: dotnet format whitespace Source/Dafny.sln -v:d --include
8-
exclude: 'Source/DafnyCore/Scanner.cs|Source/DafnyCore/Parser.cs|.git/modules/Source/boogie|Source/DafnyCore/GeneratedFromDafny|Source/DafnyCore.Test/GeneratedFromDafny|Source/DafnyRuntime/DafnyRuntimeSystemModule.cs'
8+
exclude: 'Source/DafnyCore/Generic/Deserializer/Generated.cs|Source/DafnyCore/Scanner.cs|Source/DafnyCore/Parser.cs|.git/modules/Source/boogie|Source/DafnyCore/GeneratedFromDafny|Source/DafnyCore.Test/GeneratedFromDafny|Source/DafnyRuntime/DafnyRuntimeSystemModule.cs'
99
types_or: ["c#"]

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ z3-ubuntu:
8787
chmod +x "${DIR}"/Binaries/z3/bin/z3-*
8888

8989
format:
90-
dotnet format whitespace Source/Dafny.sln --exclude Source/DafnyCore/Scanner.cs --exclude Source/DafnyCore/Parser.cs --exclude boogie --exclude Source/DafnyCore/GeneratedFromDafny/* --exclude Source/DafnyCore.Test/GeneratedFromDafny/* --exclude Source/DafnyRuntime/DafnyRuntimeSystemModule.cs
90+
dotnet format whitespace Source/Dafny.sln --exclude Source/DafnyCore/Generic/Deserializer/Generated.cs --exclude Source/DafnyCore/Scanner.cs --exclude Source/DafnyCore/Parser.cs --exclude boogie --exclude Source/DafnyCore/GeneratedFromDafny/* --exclude Source/DafnyCore.Test/GeneratedFromDafny/* --exclude Source/DafnyRuntime/DafnyRuntimeSystemModule.cs
9191

9292
clean:
9393
(cd "${DIR}"; cd Source; rm -rf Dafny/bin Dafny/obj DafnyDriver/bin DafnyDriver/obj DafnyRuntime/obj DafnyRuntime/bin DafnyServer/bin DafnyServer/obj DafnyPipeline/obj DafnyPipeline/bin DafnyCore/obj DafnyCore/bin)
@@ -132,3 +132,17 @@ pr: exe dfy-to-cs-exe pr-nogeneration
132132

133133
# Same as `make pr` but useful when resolving conflicts, to take the last compiled version of Dafny first
134134
pr-conflict: dfy-to-cs-exe dfy-to-cs-exe pr-nogeneration
135+
136+
gen-integration: gen-schema gen-deserializer
137+
138+
PARSED_AST_FILE=Source/Scripts/Syntax.cs-schema
139+
gen-schema:
140+
./script.sh generate-parsed-ast $(PARSED_AST_FILE)
141+
142+
GENERATED_DESERIALIZER_FILE=Source/DafnyCore/AST/SyntaxDeserializer/generated.cs
143+
gen-deserializer:
144+
./script.sh generate-syntax-deserializer ${GENERATED_DESERIALIZER_FILE}
145+
146+
test-integration: gen-integration
147+
(git status --porcelain || (echo 'Consider running `make gen-integration`'; exit 1; ))
148+

Source/DafnyCore.Test/ClonerTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class DummyDecl : Declaration {
1111
public DummyDecl(Cloner cloner, Declaration original) : base(cloner, original) {
1212
}
1313

14-
public DummyDecl(IOrigin origin, Name name, Attributes attributes, bool isRefining) : base(origin, name,
15-
attributes, isRefining) {
14+
public DummyDecl(IOrigin origin, Name name, Attributes attributes) : base(origin, name, attributes) {
1615
}
1716

1817
public override SymbolKind? Kind => null;

Source/DafnyCore/AST/Attributes.cs

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#nullable enable
12
using System;
23
using System.Collections.Generic;
34
using System.Diagnostics.Contracts;
@@ -20,7 +21,7 @@ public static bool IsExplicitAxiom(this IAttributeBearingDeclaration me) =>
2021
public record BuiltInAtAttributeArgSyntax(
2122
string ArgName,
2223
Type ArgType, // If null, it means it's not resolved (@Induction and @Trigger)
23-
Expression DefaultValue) {
24+
Expression? DefaultValue) {
2425
public Formal ToFormal() {
2526
Contract.Assert(ArgType != null);
2627
return new Formal(Token.NoToken, ArgName, ArgType, true, false,
@@ -34,7 +35,7 @@ public record BuiltInAtAttributeSyntax(
3435
string Name,
3536
List<BuiltInAtAttributeArgSyntax> Args,
3637
Func<IAttributeBearingDeclaration, bool> CanBeApplied) {
37-
public BuiltInAtAttributeSyntax WithArg(String argName, Type argType, Expression defaultValue = null) {
38+
public BuiltInAtAttributeSyntax WithArg(String argName, Type argType, Expression? defaultValue = null) {
3839
var c = new List<BuiltInAtAttributeArgSyntax>(Args) {
3940
new(argName, argType, defaultValue) };
4041
return this with { Args = c };
@@ -63,9 +64,16 @@ void ObjectInvariant() {
6364
/*Frozen*/
6465
public readonly List<Expression> Args;
6566

66-
public readonly Attributes Prev;
67-
public Attributes(string name, [Captured] List<Expression> args, Attributes prev) : base(Token.NoToken) {
68-
Contract.Requires(name != null);
67+
public readonly Attributes? Prev;
68+
69+
[SyntaxConstructor]
70+
public Attributes(IOrigin origin, string name, List<Expression> args, Attributes? prev) : base(origin) {
71+
Name = name;
72+
Args = args;
73+
Prev = prev;
74+
}
75+
76+
public Attributes(string name, [Captured] List<Expression> args, Attributes? prev) : base(Token.NoToken) {
6977
Contract.Requires(cce.NonNullElements(args));
7078
Contract.Requires(name != UserSuppliedAtAttribute.AtName || this is UserSuppliedAtAttribute);
7179
Name = name;
@@ -83,11 +91,11 @@ public override string ToString() {
8391
}
8492
}
8593

86-
public static IEnumerable<Expression> SubExpressions(Attributes attrs) {
94+
public static IEnumerable<Expression> SubExpressions(Attributes? attrs) {
8795
return attrs.AsEnumerable().SelectMany(aa => aa.Args);
8896
}
8997

90-
public static bool Contains(Attributes attrs, string nm) {
98+
public static bool Contains(Attributes? attrs, string nm) {
9199
Contract.Requires(nm != null);
92100
return attrs.AsEnumerable().Any(aa => aa.Name == nm);
93101
}
@@ -97,7 +105,7 @@ public static bool Contains(Attributes attrs, string nm) {
97105
/// attribute.
98106
/// </summary>
99107
[Pure]
100-
public static Attributes/*?*/ Find(Attributes attrs, string nm) {
108+
public static Attributes? Find(Attributes? attrs, string nm) {
101109
Contract.Requires(nm != null);
102110
return attrs.AsEnumerable().FirstOrDefault(attr => attr.Name == nm);
103111
}
@@ -111,7 +119,7 @@ public static bool Contains(Attributes attrs, string nm) {
111119
/// be called very early during resolution before types are available and names have been resolved.
112120
/// </summary>
113121
[Pure]
114-
public static bool ContainsBool(Attributes attrs, string nm, ref bool value) {
122+
public static bool ContainsBool(Attributes? attrs, string nm, ref bool value) {
115123
Contract.Requires(nm != null);
116124
var attr = attrs.AsEnumerable().FirstOrDefault(attr => attr.Name == nm);
117125
if (attr == null) {
@@ -156,7 +164,7 @@ public static bool ContainsBoolAtAnyLevel(MemberDecl decl, string attribName, bo
156164
/// - if the attribute is {:nm e1,...,en}, then returns (e1,...,en)
157165
/// Otherwise, returns null.
158166
/// </summary>
159-
public static List<Expression> FindExpressions(Attributes attrs, string nm) {
167+
public static List<Expression>? FindExpressions(Attributes attrs, string nm) {
160168
Contract.Requires(nm != null);
161169
foreach (var attr in attrs.AsEnumerable()) {
162170
if (attr.Name == nm) {
@@ -169,9 +177,8 @@ public static List<Expression> FindExpressions(Attributes attrs, string nm) {
169177
/// <summary>
170178
/// Same as FindExpressions, but returns all matches
171179
/// </summary>
172-
public static List<List<Expression>> FindAllExpressions(Attributes attrs, string nm) {
173-
Contract.Requires(nm != null);
174-
List<List<Expression>> ret = null;
180+
public static List<List<Expression>>? FindAllExpressions(Attributes? attrs, string nm) {
181+
List<List<Expression>>? ret = null;
175182
for (; attrs != null; attrs = attrs.Prev) {
176183
if (attrs.Name == nm) {
177184
ret = ret ?? []; // Avoid allocating the list in the common case where we don't find nm
@@ -192,11 +199,9 @@ public static List<List<Expression>> FindAllExpressions(Attributes attrs, string
192199
/// - return false, leave value unmodified, and call reporter with an error string.
193200
/// </summary>
194201
public enum MatchingValueOption { Empty, Bool, Int, String, Expression }
195-
public static bool ContainsMatchingValue(Attributes attrs, string nm, ref object value, IEnumerable<MatchingValueOption> allowed, Action<string> reporter) {
196-
Contract.Requires(nm != null);
197-
Contract.Requires(allowed != null);
198-
Contract.Requires(reporter != null);
199-
List<Expression> args = FindExpressions(attrs, nm);
202+
public static bool ContainsMatchingValue(Attributes attrs, string nm, ref object value,
203+
ISet<MatchingValueOption> allowed, Action<string> reporter) {
204+
var args = FindExpressions(attrs, nm);
200205
if (args == null) {
201206
return false;
202207
} else if (args.Count == 0) {
@@ -207,16 +212,15 @@ public static bool ContainsMatchingValue(Attributes attrs, string nm, ref object
207212
return false;
208213
}
209214
} else if (args.Count == 1) {
210-
Expression arg = args[0];
211-
StringLiteralExpr stringLiteral = arg as StringLiteralExpr;
212-
LiteralExpr literal = arg as LiteralExpr;
213-
if (literal != null && literal.Value is bool && allowed.Contains(MatchingValueOption.Bool)) {
215+
var arg = args[0];
216+
var literal = arg as LiteralExpr;
217+
if (literal is { Value: bool } && allowed.Contains(MatchingValueOption.Bool)) {
214218
value = literal.Value;
215219
return true;
216220
} else if (literal != null && literal.Value is BigInteger && allowed.Contains(MatchingValueOption.Int)) {
217221
value = literal.Value;
218222
return true;
219-
} else if (stringLiteral != null && stringLiteral.Value is string && allowed.Contains(MatchingValueOption.String)) {
223+
} else if (arg is StringLiteralExpr stringLiteral && stringLiteral.Value is string && allowed.Contains(MatchingValueOption.String)) {
220224
value = stringLiteral.Value;
221225
return true;
222226
} else if (allowed.Contains(MatchingValueOption.Expression)) {
@@ -300,8 +304,7 @@ private static Attributes A1(string name, ActualBindings bindings) {
300304

301305
// Given a user-supplied @-attribute, expand it if recognized as builtin to an old-style attribute
302306
// or mark it as not built-in for later resolution
303-
public static Attributes ExpandAtAttribute(Program program, UserSuppliedAtAttribute atAttribute, IAttributeBearingDeclaration attributeHost) {
304-
var toMatch = atAttribute.Arg;
307+
public static Attributes? ExpandAtAttribute(Program program, UserSuppliedAtAttribute atAttribute, IAttributeBearingDeclaration attributeHost) {
305308
var name = atAttribute.UserSuppliedName;
306309
var bindings = atAttribute.UserSuppliedPreResolveBindings;
307310

@@ -364,7 +367,7 @@ public static Attributes ExpandAtAttribute(Program program, UserSuppliedAtAttrib
364367
if (Get(bindings, 0, out var lowFuel) && lowFuel != null) {
365368
if (Get(bindings, 1, out var highFuel) && highFuel != null) {
366369
if (Get(bindings, 2, out var functionName) && IsStringNotEmpty(functionName)) {
367-
return A("fuel", functionName, lowFuel, highFuel);
370+
return A("fuel", functionName!, lowFuel, highFuel);
368371
}
369372

370373
return A("fuel", lowFuel, highFuel);
@@ -632,13 +635,13 @@ public static LiteralExpr DefaultInt(int value) {
632635
return Expression.CreateIntLiteralNonnegative(Token.NoToken, value);
633636
}
634637

635-
private static bool IsStringNotEmpty(Expression value) {
638+
private static bool IsStringNotEmpty(Expression? value) {
636639
return value is StringLiteralExpr { Value: string and not "" };
637640
}
638641

639642
// Given resolved bindings, gets the i-th argument according to the
640643
// declaration formals order
641-
private static bool Get(ActualBindings bindings, int i, out Expression expr) {
644+
private static bool Get(ActualBindings bindings, int i, out Expression? expr) {
642645
if (bindings.Arguments.Count < i + 1) {
643646
expr = null;
644647
return false;
@@ -667,7 +670,7 @@ private static void ResolveLikeDatatypeConstructor(Program program, Formal[] for
667670
}
668671

669672
// Recovers a built-in @-Attribute if it exists
670-
public static bool TryGetBuiltinAtAttribute(string name, out BuiltInAtAttributeSyntax builtinAtAttribute) {
673+
public static bool TryGetBuiltinAtAttribute(string name, out BuiltInAtAttributeSyntax? builtinAtAttribute) {
671674
return BuiltInAtAttributeDictionary.TryGetValue(name, out builtinAtAttribute);
672675
}
673676

@@ -681,27 +684,27 @@ public static bool TryGetBuiltinAtAttribute(string name, out BuiltInAtAttributeS
681684
}, b => b);
682685

683686
// Overridable method to clone the attribute as if the new attribute was placed after "prev" in the source code
684-
public virtual Attributes CloneAfter(Attributes prev) {
687+
public virtual Attributes CloneAfter(Attributes? prev) {
685688
return new Attributes(Name, Args, prev);
686689
}
687690

688691
//////// Helpers for parsing attributes //////////////////
689692

690693
// Returns the memory location's attributes content and set the memory location to null (no attributes)
691-
public static Attributes Consume(ref Attributes tmpStack) {
694+
public static Attributes? Consume(ref Attributes? tmpStack) {
692695
var result = tmpStack;
693696
tmpStack = null;
694697
return result;
695698
}
696699

697700
// Empties the first attribute memory location while prepending its attributes to the second attribute memory location, in the same order
698-
public static void MergeInto(ref Attributes tmpStack, ref Attributes attributesStack) {
701+
public static void MergeInto(ref Attributes? tmpStack, ref Attributes? attributesStack) {
699702
MergeIntoReadonly(tmpStack, ref attributesStack);
700703
tmpStack = null;
701704
}
702705

703706
// Prepends the attributes tmpStack before the attributes contained in the memory location attributesStack
704-
private static void MergeIntoReadonly(Attributes tmpStack, ref Attributes attributesStack) {
707+
private static void MergeIntoReadonly(Attributes? tmpStack, ref Attributes? attributesStack) {
705708
if (tmpStack == null) {
706709
return;
707710
}
@@ -718,7 +721,7 @@ public static class AttributesExtensions {
718721
/// <summary>
719722
/// By making this an extension method, it can also be invoked for a null receiver.
720723
/// </summary>
721-
public static IEnumerable<Attributes> AsEnumerable(this Attributes attr) {
724+
public static IEnumerable<Attributes> AsEnumerable(this Attributes? attr) {
722725
while (attr != null) {
723726
yield return attr;
724727
attr = attr.Prev;
@@ -731,12 +734,8 @@ public class UserSuppliedAttributes : Attributes {
731734
public readonly IOrigin OpenBrace;
732735
public readonly IOrigin CloseBrace;
733736
public bool Recognized; // set to true to indicate an attribute that is processed by some part of Dafny; this allows it to be colored in the IDE
734-
public UserSuppliedAttributes(IOrigin origin, IOrigin openBrace, IOrigin closeBrace, List<Expression> args, Attributes prev)
737+
public UserSuppliedAttributes(IOrigin origin, IOrigin openBrace, IOrigin closeBrace, List<Expression> args, Attributes? prev)
735738
: base(origin.val, args, prev) {
736-
Contract.Requires(origin != null);
737-
Contract.Requires(openBrace != null);
738-
Contract.Requires(closeBrace != null);
739-
Contract.Requires(args != null);
740739
SetOrigin(origin);
741740
OpenBrace = openBrace;
742741
CloseBrace = closeBrace;
@@ -749,22 +748,20 @@ public class UserSuppliedAtAttribute : Attributes {
749748
public readonly IOrigin AtSign;
750749
public bool Builtin; // set to true to indicate it was recognized as a builtin attribute
751750
// Otherwise it's a user-defined one and Arg needs to be fully resolved
752-
public UserSuppliedAtAttribute(IOrigin origin, Expression arg, Attributes prev)
751+
public UserSuppliedAtAttribute(IOrigin origin, Expression arg, Attributes? prev)
753752
: base(AtName, [arg], prev) {
754-
Contract.Requires(origin != null);
755753
SetOrigin(origin);
756754
this.AtSign = origin;
757755
}
758756

759757
public Expression Arg => Args[0];
760758

761-
public override Attributes CloneAfter(Attributes prev) {
759+
public override Attributes CloneAfter(Attributes? prev) {
762760
return new UserSuppliedAtAttribute(AtSign, Args[0], prev);
763761
}
764762

765763
// Name of this @-Attribute, which is the part right after the @
766-
public string UserSuppliedName =>
767-
GetName(this);
764+
public string? UserSuppliedName => GetName(this);
768765

769766
// Pre-resolved bindings of this @-Attribute
770767
public ActualBindings UserSuppliedPreResolveBindings =>
@@ -776,7 +773,7 @@ public override Attributes CloneAfter(Attributes prev) {
776773
GetPreResolveArguments(this);
777774

778775
// Gets the name of an @-attribute. Attributes might be applied.
779-
public static string GetName(Attributes a) {
776+
public static string? GetName(Attributes a) {
780777
if (a is UserSuppliedAtAttribute { Arg: ApplySuffix { Lhs: NameSegment { Name: var name } } }) {
781778
return name;
782779
}
@@ -818,12 +815,12 @@ public static IEnumerable<Expression> GetUserSuppliedArguments(Attributes a) {
818815
/// A class implementing this interface is one that can carry attributes.
819816
/// </summary>
820817
public interface IAttributeBearingDeclaration {
821-
Attributes Attributes { get; internal set; }
818+
Attributes? Attributes { get; internal set; }
822819
string WhatKind { get; }
823820
}
824821

825822
public static class AttributeBearingDeclarationExtensions {
826-
public static bool HasUserAttribute(this IAttributeBearingDeclaration decl, string name, out Attributes attribute) {
823+
public static bool HasUserAttribute(this IAttributeBearingDeclaration decl, string name, out Attributes? attribute) {
827824
if (Attributes.Find(decl.Attributes, name) is UserSuppliedAttributes attr) {
828825
attribute = attr;
829826
return true;

0 commit comments

Comments
 (0)