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

Use refresh resolver by default #5653

Draft
wants to merge 159 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
51e033a
Change default settings
RustanLeino May 28, 2024
5204eeb
Explicitly declare trait to be a reference type
RustanLeino May 28, 2024
3bdaa87
Make the new type system the default
keyboardDrummer Jun 27, 2024
48a8cf4
Merge branch 'master' into refresh-by-default
RustanLeino Jun 27, 2024
3101604
Explicitly declare trait as reference type
RustanLeino Jun 27, 2024
a134465
Changed from full to datatype
keyboardDrummer Jun 28, 2024
d75f39f
Add “extends object” where it was assumed to be so before
RustanLeino Jun 28, 2024
46484e6
Fix error location for desugared elephant assert
RustanLeino Jun 28, 2024
74a49df
Merge branch 'refresh-by-default' into typeSystemRefreshDefault
RustanLeino Jun 28, 2024
af730de
Merge branch 'master' into refresh-by-default
RustanLeino Jul 17, 2024
5acc14b
Use explicit legacy switches in testDafnyForEach…
RustanLeino Jul 18, 2024
611ac55
Fix missing box adjustment in verifier
RustanLeino Jul 18, 2024
4979a6e
fix: Use just one pre-type proxy for element type in array allocation
RustanLeino Jul 18, 2024
d701a33
Merge branch 'master' into refresh-by-default
RustanLeino Jul 30, 2024
7a5d171
Fix pre-type of StaticReceiverExpr
RustanLeino Aug 18, 2024
a4bf314
Update tests to support new defaults
RustanLeino Aug 20, 2024
18addcf
Involve compatible-type constraints in decision process
RustanLeino Aug 20, 2024
47d4abc
Update test
RustanLeino Aug 20, 2024
43a6a37
Extract method SansPrintablePreType
RustanLeino Aug 20, 2024
a6820e1
Fix type inference of seq/map/multiset update expressions
RustanLeino Aug 20, 2024
99fbb08
Merge branch 'master' into refresh-by-default
RustanLeino Aug 21, 2024
5026519
Fix asserted-expression output for frames
RustanLeino Aug 21, 2024
dab7870
Fix creation of yield-identifier expression
RustanLeino Aug 21, 2024
8028152
Update expect files
RustanLeino Aug 21, 2024
86e2312
Fix pre-type resolution of export-provided members/types
RustanLeino Aug 21, 2024
bb2d519
Improve formatting
RustanLeino Aug 21, 2024
d2624ee
Adjust tests and expected test output
RustanLeino Aug 21, 2024
456afc5
Fix parameter order
RustanLeino Aug 21, 2024
954dd42
Adjust tests and expected test output
RustanLeino Aug 22, 2024
3d617aa
Fix Boogie type of receiver in function-valued members
RustanLeino Aug 22, 2024
fbec421
chore: Improve code
RustanLeino Aug 22, 2024
6ec3676
Add tests
RustanLeino Aug 22, 2024
68ce112
fix: Pass in original (overridden) member
RustanLeino Aug 22, 2024
2d45cf6
Pass CLI parameter values explicitly
RustanLeino Aug 22, 2024
867a207
Prescribe type-refinement flows for SeqUpdateExpr
RustanLeino Aug 22, 2024
289a996
Add some temporary casts, waiting for flows to do more with bounded p…
RustanLeino Aug 22, 2024
785e4cc
Update tests and results
RustanLeino Aug 22, 2024
a442d33
Update tests and expected results
RustanLeino Aug 22, 2024
bddc2ce
Update tests and expected test output
RustanLeino Aug 22, 2024
cec4940
fix: Fix a printing crash
RustanLeino Aug 22, 2024
272bfe4
Update tests and expected output
RustanLeino Aug 23, 2024
35f4877
Update tests
RustanLeino Aug 23, 2024
a6bebff
Use basename for filename in %translate test
RustanLeino Aug 23, 2024
c44b7f8
Update test output
RustanLeino Aug 23, 2024
044d6e6
fix: Report error (and don’t crash) on disjunctive patterns inside ot…
RustanLeino Aug 23, 2024
f35922c
Expect errors for missing parentheses of non-nullary constructors in …
RustanLeino Aug 23, 2024
af98137
Move {:only} warnings from pass 0 to pass 3
RustanLeino Aug 23, 2024
8eadfea
Adjust tests and answers
RustanLeino Aug 23, 2024
2beb41f
Use nested comparable-types constraints as default advice
RustanLeino Aug 23, 2024
f9ca74e
fix: Subrange check and conversions to arrow types
RustanLeino Aug 24, 2024
be77ce8
Handle “as” for datatypes and arrows in compilers and verifier
RustanLeino Aug 24, 2024
8dcd806
Adjust tests
RustanLeino Aug 24, 2024
50c4987
Adjust tests and answers
RustanLeino Aug 24, 2024
d46da94
Adjust tests and outputs
RustanLeino Aug 24, 2024
138b341
Adjust tests and outputs
RustanLeino Aug 24, 2024
a73d698
fix: Support “assigned” in new resolver
RustanLeino Aug 24, 2024
bfb9100
Fill in missing case in type cloning
RustanLeino Aug 27, 2024
5cb67b9
fix: Print DecreasesToExpr with parentheses
RustanLeino Aug 28, 2024
2c3db7b
Don’t update RangeToken when resolving ParensExpression
RustanLeino Aug 28, 2024
b0739ec
Use sub/equal constraints to make type decisions
RustanLeino Aug 28, 2024
32a995a
Update improved (reduced) error messages
RustanLeino Aug 28, 2024
04be175
Update test and answers
RustanLeino Aug 28, 2024
c940168
Merge branch 'master' into refresh-by-default
RustanLeino Aug 28, 2024
e29ded6
Validate resolution CLI options (at a terrible place in the code)
RustanLeino Sep 3, 2024
16a91fe
Merge branch 'master' into refresh-by-default
RustanLeino Sep 3, 2024
5a7f699
Correct previous compensation
RustanLeino Sep 3, 2024
6bc0bab
Merge branch 'master' into refresh-by-default
RustanLeino Sep 4, 2024
8d83506
Fix test script for git-issue-321
RustanLeino Sep 4, 2024
110ff22
fix: Include case for BVNot
RustanLeino Sep 4, 2024
ba1b866
Adjust test outputs
RustanLeino Sep 4, 2024
e691271
Merge branch 'master' into refresh-by-default
RustanLeino Sep 5, 2024
4ba909c
Adjust tests
RustanLeino Sep 26, 2024
3dbd746
Adjust tests
RustanLeino Sep 26, 2024
737c57c
Start adjusting test
RustanLeino Sep 27, 2024
3b54b7e
Merge branch 'master' into refresh-by-default
RustanLeino Sep 27, 2024
27faf49
Merge branch 'master' into refresh-by-default
RustanLeino Oct 4, 2024
feeaa06
Adjust tests and answers
RustanLeino Oct 4, 2024
6652b68
Adjust tests and answers
RustanLeino Oct 5, 2024
006c8af
chore: Improve C#
RustanLeino Oct 5, 2024
ad77757
fix: Incorporate explicit type arguments for function calls and datat…
RustanLeino Oct 5, 2024
1a6ea55
Merge branch 'master' into refresh-by-default
RustanLeino Oct 7, 2024
a79a23e
Adjust tests
RustanLeino Oct 8, 2024
7466e28
Add “extends object” to tests
RustanLeino Oct 8, 2024
68d8dda
Merge branch 'master' into refresh-by-default
RustanLeino Oct 31, 2024
d048c19
Fix parameter resolution
RustanLeino Oct 31, 2024
29353b8
Merge branch 'master' into refresh-by-default
RustanLeino Nov 1, 2024
5e1d3c7
Improve code
RustanLeino Nov 1, 2024
8d69f48
Merge branch 'master' into refresh-by-default
RustanLeino Nov 1, 2024
3b1eb8f
Remove deprecated semi-colons
RustanLeino Nov 1, 2024
b4dc9a4
Update tests
RustanLeino Nov 2, 2024
d90e117
chore: Clean up code
RustanLeino Nov 2, 2024
2c0142d
Fix case where all candidate ctors are ghost
RustanLeino Nov 2, 2024
31af1c2
Fix output
RustanLeino Nov 2, 2024
dcc4ce1
Set .PreType even when DatatypeValue is in error
RustanLeino Nov 2, 2024
717288f
chore: Clean up code and comment
RustanLeino Nov 2, 2024
7b2f342
Forget duplicate destructor names
RustanLeino Nov 2, 2024
d9a5fbe
Merge branch 'master' into refresh-by-default
RustanLeino Nov 11, 2024
a4194d1
fix: Fix issue 2019 for new resolver
RustanLeino Nov 11, 2024
9c56002
Adjust test output
RustanLeino Nov 11, 2024
46721b7
Adjust tests and outputs
RustanLeino Nov 11, 2024
64bb5ac
Fix crash from illegal literal expression in case pattern
RustanLeino Nov 12, 2024
94cff6a
Update test to new type-conversion rules
RustanLeino Nov 12, 2024
c507770
Fix sed issue for the last last time!!
RustanLeino Nov 12, 2024
d56fe91
Improve test and error messages
RustanLeino Nov 12, 2024
2606e87
Adjust tests
RustanLeino Nov 12, 2024
8c6ef14
Clarify tests and don’t insist on having type for _
RustanLeino Nov 12, 2024
bd090f2
Update test answers
RustanLeino Nov 12, 2024
c04d7ee
Fix tests
RustanLeino Nov 12, 2024
ac82f59
Fix type checking of real division
RustanLeino Nov 12, 2024
7c90391
Fix type inference for string literals
RustanLeino Nov 12, 2024
62b36c2
chore: Improve code
RustanLeino Nov 12, 2024
c9b37e7
Make error message more consistent
RustanLeino Nov 12, 2024
d030c34
Fix type constraint checking on string literals
RustanLeino Nov 12, 2024
2f133bd
Improve error messages
RustanLeino Nov 13, 2024
7f74680
Improve error message
RustanLeino Nov 13, 2024
5cf5c0c
Merge branch 'master' into refresh-by-default
RustanLeino Nov 13, 2024
8fc1f58
Fix DatatypeValue type parameter, and fix tests
RustanLeino Nov 13, 2024
59a0849
Merge branch 'master' into refresh-by-default
RustanLeino Nov 13, 2024
18232fe
Remove variance parameter from PreType-to-Type process
RustanLeino Nov 15, 2024
1126c91
Update tests
RustanLeino Nov 15, 2024
f1f54ac
Merge branch 'master' into refresh-by-default
RustanLeino Nov 15, 2024
4aa3559
Merge branch 'master' into refresh-by-default
RustanLeino Dec 10, 2024
4d0aaeb
Adjust tests with improved type inference
RustanLeino Dec 14, 2024
8ab207d
Adjust tests with improved type inference
RustanLeino Dec 14, 2024
1f69ce8
Improve error message
RustanLeino Dec 17, 2024
c39c02e
Use old resolver for tests that need more work
RustanLeino Dec 17, 2024
ca3b1da
Say ‘string’ instead of ‘seq<char>’ for string literals
RustanLeino Dec 17, 2024
6efb5cd
Merge branch 'master' into refresh-by-default
RustanLeino Dec 18, 2024
f17aba5
Revert some tests back to explicitly using old resolver (for now)
RustanLeino Dec 19, 2024
5cc235e
Update AsIs expected output
RustanLeino Dec 23, 2024
8efb254
Add test case for Issue 2040, which has been fixed
RustanLeino Jan 2, 2025
6f59e17
Merge branch 'master' into refresh-by-default
RustanLeino Jan 2, 2025
0137d3d
Fix merge
RustanLeino Jan 2, 2025
14e69f6
Fix and add tests and adjust expected test output
RustanLeino Jan 3, 2025
b06cae7
Merge branch 'master' into refresh-by-default
RustanLeino Jan 4, 2025
9e72c35
Fix up tests and expected output
RustanLeino Jan 4, 2025
b03dbbd
Fix up tests and expected output
RustanLeino Jan 4, 2025
ade18b7
Merge branch 'master' into refresh-by-default
RustanLeino Jan 13, 2025
044fcb0
Update tests
RustanLeino Jan 13, 2025
78885b0
chore: Improve code formatting
RustanLeino Jan 14, 2025
1b7407d
chore: Simplify code (remove premature optimizations)
RustanLeino Jan 14, 2025
e51d4fe
fix: Apply function-call substitution in frame override check
RustanLeino Jan 14, 2025
b047c44
fix: Use correct type of “this” in allowance disjunct
RustanLeino Jan 14, 2025
5ba3a0b
Updated expected output
RustanLeino Jan 14, 2025
bf070b0
Cop-out: Mark failing test as legacy-resolver-only
RustanLeino Jan 14, 2025
e72c868
Merge branch 'master' into refresh-by-default
RustanLeino Jan 14, 2025
f6519a0
Cop-out: Mark failing test as legacy-resolver-only
RustanLeino Jan 14, 2025
71e78d4
Adjust tests
RustanLeino Jan 14, 2025
7acb9bd
Update HowToFAQ ID’s and expected output
RustanLeino Jan 14, 2025
3a2ad0e
Merge branch 'master' into refresh-by-default
RustanLeino Jan 14, 2025
7558275
Update HowToFAQ template
RustanLeino Jan 15, 2025
f0bf4f1
Merge branch 'master' into refresh-by-default
RustanLeino Jan 15, 2025
4e26996
Update some HowToFAQ resolver errors and punted on others
RustanLeino Jan 16, 2025
62c0a59
Fix test expectations
RustanLeino Jan 16, 2025
ec26b80
Add “extends object”
RustanLeino Jan 16, 2025
9d2aa89
Revert Rust tests to using old resolver
RustanLeino Jan 16, 2025
01ddf38
Fix Rust tests via lit on osx
RustanLeino Jan 16, 2025
322da9a
Revert Rust tests to use legacy traits
RustanLeino Jan 16, 2025
66767c6
Revert "Fix Rust tests via lit on osx"
RustanLeino Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions Source/DafnyCore/AST/Cloner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ public virtual Type CloneType(Type t) {
} else if (t is TypeRefinementWrapper typeRefinementWrapper) {
// don't bother keeping TypeRefinementWrapper wrappers
return CloneType(typeRefinementWrapper.T);
} else if (t is BottomTypePlaceholder bottomTypePlaceholder) {
// don't bother keeping BottomTypePlaceholder wrappers
return CloneType(bottomTypePlaceholder.T);
} else {
Contract.Assert(false); // unexpected type (e.g., no other type proxies are expected at this time)
return null; // to please compiler
Expand Down
12 changes: 11 additions & 1 deletion Source/DafnyCore/AST/Modules/ModuleDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ public static IEnumerable<Field> AllFields(IEnumerable<TopLevelDecl> declaration
}
}

public static IEnumerable<MemberDecl> AllMembers(IEnumerable<TopLevelDecl> declarations) {
foreach (var decl in declarations.OfType<TopLevelDeclWithMembers>()) {
foreach (var member in decl.Members) {
yield return member;
}
}
}

public static IEnumerable<TopLevelDeclWithMembers> AllTypesWithMembers(List<TopLevelDecl> declarations) {
foreach (var d in declarations) {
if (d is TopLevelDeclWithMembers cl) {
Expand Down Expand Up @@ -905,7 +913,9 @@ public ModuleSignature RegisterTopLevelDecls(ModuleResolver resolver, bool useIm
}
}

ctor.Destructors.Add(dtor);
if (!localDuplicate) {
ctor.Destructors.Add(dtor);
}
}

foreach (var duplicate in duplicates) {
Expand Down
5 changes: 3 additions & 2 deletions Source/DafnyCore/AST/SystemModuleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public byte[] MyHash {
public readonly ISet<int> Bitwidths = new HashSet<int>();
[FilledInDuringResolution] public SpecialField ORDINAL_Offset; // used by the translator

public readonly TypeSynonymDecl StringDecl;
public readonly SubsetTypeDecl NatDecl;
public UserDefinedType Nat() { return new UserDefinedType(Token.NoToken, "nat", NatDecl, new List<Type>()); }
public readonly TraitDecl ObjectDecl;
Expand All @@ -92,10 +93,10 @@ public SystemModuleManager(DafnyOptions options) {
this.Options = options;
SystemModule.Height = -1; // the system module doesn't get a height assigned later, so we set it here to something below everything else
// create type synonym 'string'
var str = new TypeSynonymDecl(SourceOrigin.NoToken, new Name("string"),
StringDecl = new TypeSynonymDecl(SourceOrigin.NoToken, new Name("string"),
new TypeParameter.TypeParameterCharacteristics(TypeParameter.EqualitySupportValue.InferredRequired, Type.AutoInitInfo.CompilableValue, false),
new List<TypeParameter>(), SystemModule, new SeqType(new CharType()), null);
SystemModule.SourceDecls.Add(str);
SystemModule.SourceDecls.Add(StringDecl);
// create subset type 'nat'
var bvNat = new BoundVar(Token.NoToken, "x", Type.Int);
var natConstraint = Expression.CreateAtMost(Expression.CreateIntLiteral(Token.NoToken, 0), Expression.CreateIdentExpr(bvNat));
Expand Down
6 changes: 5 additions & 1 deletion Source/DafnyCore/AST/TypeDeclarations/Declaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ void ObjectInvariant() {
public IOrigin BodyStartTok = Token.NoToken;
public Name NameNode;

public string GetNameRelativeToModule() {
return this is ICallable iCallable ? iCallable.NameRelativeToModule : ToString();
}

public virtual IOrigin NavigationToken => NameNode.Origin;

public string Name => NameNode.Value;
Expand Down Expand Up @@ -150,4 +154,4 @@ public override string ToString() {

// For Compilation
internal CodeGenIdGenerator CodeGenIdGenerator = new();
}
}
3 changes: 2 additions & 1 deletion Source/DafnyCore/Backends/CSharp/CsharpCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3366,7 +3366,8 @@ protected override void EmitConversionExpr(Expression fromExpr, Type fromType, T
} else if (fromType.Equals(toType) || fromType.AsNewtype != null || toType.AsNewtype != null) {
wr.Append(Expr(fromExpr, inLetExprBody, wStmts));
} else {
Contract.Assert(false, $"not implemented for C#: {fromType} -> {toType}");
wr = EmitDowncast(fromType, toType, fromExpr.Origin, wr);
EmitExpr(fromExpr, inLetExprBody, wr, wStmts);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Source/DafnyCore/Backends/GoLang/GoCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3794,7 +3794,8 @@ protected override void EmitConversionExpr(Expression fromExpr, Type fromType, T
} else if (fromType.Equals(toType) || fromType.AsNewtype != null || toType.AsNewtype != null) {
wr.Append(Expr(fromExpr, inLetExprBody, wStmts));
} else {
Contract.Assert(false, $"not implemented for go: {fromType} -> {toType}");
wr = EmitCoercionIfNecessary(fromType, toType, fromExpr.Origin, wr);
EmitExpr(fromExpr, inLetExprBody, wr, wStmts);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Source/DafnyCore/Backends/Java/JavaCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4249,7 +4249,8 @@ protected override void EmitConversionExpr(Expression fromExpr, Type fromType, T
} else if (fromType.Equals(toType) || fromType.AsNewtype != null || toType.AsNewtype != null) {
wr.Append(Expr(fromExpr, inLetExprBody, wStmts));
} else {
Contract.Assert(false, $"not implemented for java: {fromType} -> {toType}");
wr = EmitDowncast(fromType, toType, fromExpr.Origin, wr);
EmitExpr(fromExpr, inLetExprBody, wr, wStmts);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,7 @@ protected override void EmitConversionExpr(Expression fromExpr, Type fromType, T
} else if (fromType.Equals(toType) || fromType.AsNewtype != null || toType.AsNewtype != null) {
wr.Append(Expr(fromExpr, inLetExprBody, wStmts));
} else {
Contract.Assert(false, $"not implemented for javascript: {fromType} -> {toType}");
EmitExpr(fromExpr, inLetExprBody, wr, wStmts);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4547,9 +4547,9 @@ protected virtual void TrCallStmt(CallStmt s, string receiverReplacement, Concre
if (!p.IsGhost) {
wr.Write(sep);
var fromType = s.Args[i].Type;
var toType = s.Method.Ins[i].Type;
var instantiatedToType = toType.Subst(s.MethodSelect.TypeArgumentSubstitutionsWithParents());
var w = EmitCoercionIfNecessary(fromType, instantiatedToType, s.Origin, wr, toType);
var origToType = s.Method.Original.Ins[i].Type;
var instantiatedToType = origToType.Subst(s.MethodSelect.TypeArgumentSubstitutionsWithParents());
var w = EmitCoercionIfNecessary(fromType, instantiatedToType, s.Origin, wr, origToType);
w = EmitDowncastIfNecessary(fromType, instantiatedToType, s.Origin, w);
EmitExpr(s.Args[i], false, w, wStmts);
sep = ", ";
Expand Down Expand Up @@ -5325,7 +5325,7 @@ protected virtual void CompileFunctionCallExpr(FunctionCallExpr e, ConcreteSynta
wr.Write(sep);
var fromType = e.Args[i].Type;
var instantiatedToType = e.Function.Ins[i].Type.Subst(e.TypeArgumentSubstitutionsWithParents());
var w = EmitCoercionIfNecessary(fromType, instantiatedToType, tok: e.Origin, wr: wr, e.Function.Ins[i].Type);
var w = EmitCoercionIfNecessary(fromType, instantiatedToType, tok: e.Origin, wr: wr, e.Function.Original.Ins[i].Type);
w = EmitDowncastIfNecessary(fromType, instantiatedToType, e.Origin, w);
tr(e.Args[i], w, inLetExprBody, wStmts);
sep = ", ";
Expand Down
4 changes: 2 additions & 2 deletions Source/DafnyCore/CompileNestedMatch/MatchFlattener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ private ExtendedPattern RemoveIllegalSubpatterns(ExtendedPattern pat, bool inDis
return pat;
case IdPattern p:
if (inDisjunctivePattern && p.ResolvedLit == null && p.Arguments == null && !p.IsWildcardPattern) {
return new IdPattern(p.Origin, FreshTempVarName("_", null), null, p.IsGhost);
return new IdPattern(p.Origin, "_", null, p.IsGhost);
}
var args = p.Arguments?.ConvertAll(a => RemoveIllegalSubpatterns(a, inDisjunctivePattern));
return new IdPattern(p.Origin, p.Id, p.Type, args, p.IsGhost) { ResolvedLit = p.ResolvedLit, BoundVar = p.BoundVar };
case DisjunctivePattern p:
return new IdPattern(p.Origin, FreshTempVarName("_", null), null, p.IsGhost);
return new IdPattern(p.Origin, "_", null, p.IsGhost);
default:
Contract.Assert(false);
return null;
Expand Down
4 changes: 0 additions & 4 deletions Source/DafnyCore/DafnyMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ public static string Resolve(Program program) {
return null;
}

if (program.Options.Get(CommonOptionBag.GeneralNewtypes) && !program.Options.Get(CommonOptionBag.TypeSystemRefresh)) {
return "use of --general-newtypes requires --type-system-refresh";
}

var programResolver = new ProgramResolver(program);
#pragma warning disable VSTHRD002
LargeStackFactory.StartNew(() => programResolver.Resolve(CancellationToken.None)).Wait();
Expand Down
22 changes: 15 additions & 7 deletions Source/DafnyCore/Generic/ErrorReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void Error(MessageSource source, Enum errorId, IOrigin tok, string format
Contract.Requires(tok != null);
Contract.Requires(format != null);
Contract.Requires(args != null);
Error(source, errorId.ToString(), tok, string.Format(format, args));
Error(source, errorId.ToString(), tok, Format(format, args));
}

public void Error(MessageSource source, Enum errorId, IOrigin tok, string msg) {
Expand Down Expand Up @@ -139,7 +139,7 @@ public void Warning(MessageSource source, Enum errorId, IOrigin tok, string form
Contract.Requires(tok != null);
Contract.Requires(format != null);
Contract.Requires(args != null);
Warning(source, errorId, tok, String.Format(format, args));
Warning(source, errorId, tok, Format(format, args));
}

public void Warning(MessageSource source, Enum errorId, IOrigin tok, string msg) {
Expand Down Expand Up @@ -179,7 +179,7 @@ public void Deprecated(MessageSource source, Enum errorId, IOrigin tok, string f
Contract.Requires(format != null);
Contract.Requires(args != null);
if (Options.DeprecationNoise != 0) {
Warning(source, errorId, tok, String.Format(format, args));
Warning(source, errorId, tok, Format(format, args));
}
}

Expand All @@ -189,14 +189,22 @@ public void Info(MessageSource source, IOrigin tok, string msg, object errorId =
Message(source, ErrorLevel.Info, errorId?.ToString(), tok, msg);
}

public void Info(MessageSource source, IOrigin tok, string msg, params object[] args) {
public void Info(MessageSource source, IOrigin tok, string format, params object[] args) {
Contract.Requires(tok != null);
Contract.Requires(msg != null);
Contract.Requires(format != null);
Contract.Requires(args != null);
Info(source, tok, String.Format(msg, args));
Info(source, tok, Format(format, args));
}

private string Format(string format, object[] args) {
// In some cases, the "format" isn't actually a (Dafny-generated) format string, but a (user-defined) literal string.
// Such a user-defined literal may contain format information, like the "{0}" in the "ensures x in {0} <==> x in {1}".
// To prevent such string from going to string.Format, we first check if "args" has any arguments at all.
// This solves all known issues.
return args.Length == 0 ? format : string.Format(format, args);
}

public string ErrorToString(ErrorLevel header, IOrigin tok, string msg) {
return $"{tok.TokenToString(Options)}: {header.ToString()}: {msg}";
}
}
}
27 changes: 14 additions & 13 deletions Source/DafnyCore/Options/CommonOptionBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ Note that quantifier variable domains (<- <Domain>) are available in both syntax
"Prevents a warning from being generated for axioms, such as assume statements and functions or methods without a body, that don't have an {:axiom} attribute.") {
};

public static readonly Option<bool> TypeSystemRefresh = new("--type-system-refresh", () => false,
public static readonly Option<bool> TypeSystemRefresh = new("--type-system-refresh", () => true,
@"
false - The type-inference engine and supported types are those of Dafny 4.0.
true - Use an updated type-inference engine.".TrimStart()) {
true (default) - Use an updated type-inference engine.".TrimStart()) {
IsHidden = true
};

Expand All @@ -223,18 +223,18 @@ public enum GeneralTraitsOptions {
Full
}

public static readonly Option<GeneralTraitsOptions> GeneralTraits = new("--general-traits", () => GeneralTraitsOptions.Legacy,
public static readonly Option<GeneralTraitsOptions> GeneralTraits = new("--general-traits", () => GeneralTraitsOptions.Datatype,
@"
legacy - Every trait implicitly extends 'object', and thus is a reference type. Only traits and reference types can extend traits.
datatype - A trait is a reference type only if it or one of its ancestor traits is 'object'. Any non-'newtype' type with members can extend traits.
datatype (default) - A trait is a reference type only if it or one of its ancestor traits is 'object'. Any non-'newtype' type with members can extend traits.
full - (don't use; not yet completely supported) A trait is a reference type only if it or one of its ancestor traits is 'object'. Any type with members can extend traits.".TrimStart()) {
IsHidden = true
};

public static readonly Option<bool> GeneralNewtypes = new("--general-newtypes", () => false,
public static readonly Option<bool> GeneralNewtypes = new("--general-newtypes", () => true,
@"
false - A newtype can only be based on numeric types or another newtype.
true - (requires --type-system-refresh) A newtype case be based on any non-reference, non-trait, non-arrow, non-ORDINAL type.".TrimStart()) {
true (default) - (requires --type-system-refresh) A newtype case be based on any non-reference, non-trait, non-arrow, non-ORDINAL type.".TrimStart()) {
IsHidden = true
};

Expand Down Expand Up @@ -434,15 +434,16 @@ datatype with a single non-ghost constructor that has a single
0 - The char type represents any UTF-16 code unit.
1 (default) - The char type represents any Unicode scalar value.".TrimStart(), defaultValue: true);
DafnyOptions.RegisterLegacyUi(TypeSystemRefresh, DafnyOptions.ParseBoolean, "Language feature selection", "typeSystemRefresh", @"
0 (default) - The type-inference engine and supported types are those of Dafny 4.0.
1 - Use an updated type-inference engine. Warning: This mode is under construction and probably won't work at this time.".TrimStart(), defaultValue: false);
0 - The type-inference engine and supported types are those of Dafny 4.0.
1 (default) - Use an updated type-inference engine.".TrimStart(), defaultValue: true);
DafnyOptions.RegisterLegacyUi(GeneralTraits, DafnyOptions.ParseGeneralTraitsOption, "Language feature selection", "generalTraits", @"
legacy (default) - Every trait implicitly extends 'object', and thus is a reference type. Only traits and reference types can extend traits.
datatype - A trait is a reference type only if it or one of its ancestor traits is 'object'. Any non-'newtype' type with members can extend traits.
full - (don't use; not yet completely supported) A trait is a reference type only if it or one of its ancestor traits is 'object'. Any type with members can extend traits.".TrimStart());
legacy - Every trait implicitly extends 'object', and thus is a reference type. Only traits and reference types can extend traits.
datatype (default) - A trait is a reference type only if it or one of its ancestor traits is 'object'. Any non-'newtype' type with members can extend traits.
full - (don't use; not yet completely supported) A trait is a reference type only if it or one of its ancestor traits is 'object'. Any type with members can extend traits.".TrimStart(),
defaultValue: GeneralTraitsOptions.Datatype);
DafnyOptions.RegisterLegacyUi(GeneralNewtypes, DafnyOptions.ParseBoolean, "Language feature selection", "generalNewtypes", @"
0 (default) - A newtype can only be based on numeric types or another newtype.
1 - (requires /typeSystemRefresh:1) A newtype case be based on any non-reference, non-trait, non-arrow, non-ORDINAL type.".TrimStart(), false);
0 - A newtype can only be based on numeric types or another newtype.
1 (default) - (requires /typeSystemRefresh:1) A newtype case be based on any non-reference, non-trait, non-arrow, non-ORDINAL type.".TrimStart(), true);
DafnyOptions.RegisterLegacyUi(TypeInferenceDebug, DafnyOptions.ParseBoolean, "Language feature selection", "titrace", @"
0 (default) - Don't print type-inference debug information.
1 - Print type-inference debug information.".TrimStart(), defaultValue: false);
Expand Down
18 changes: 17 additions & 1 deletion Source/DafnyCore/Resolver/ModuleResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,11 @@ public void ResolveTopLevelDecls_Core(List<TopLevelDecl> declarations,

int prevErrorCount = reporter.Count(ErrorLevel.Error);

if (Options.Get(CommonOptionBag.GeneralNewtypes) && !Options.Get(CommonOptionBag.TypeSystemRefresh)) {
reporter.Error(MessageSource.Resolver, Token.NoToken, "use of --general-newtypes requires --type-system-refresh");
return;
}

// ---------------------------------- Pass 0 ----------------------------------
// This pass:
// * resolves names, introduces (and may solve) type constraints
Expand Down Expand Up @@ -1477,6 +1482,17 @@ public void ResolveTopLevelDecls_Core(List<TopLevelDecl> declarations,
}
}

foreach (var member in ModuleDefinition.AllMembers(declarations)) {
if (member.HasUserAttribute("only", out var attribute)) {
reporter.Warning(MessageSource.Verifier, ResolutionErrors.ErrorId.r_member_only_assumes_other.ToString(), attribute.Origin,
"Members with {:only} temporarily disable the verification of other members in the entire file");
if (attribute.Args.Count >= 1) {
reporter.Warning(MessageSource.Verifier, ResolutionErrors.ErrorId.r_member_only_has_no_before_after.ToString(), attribute.Args[0].Origin,
"{:only} on members does not support arguments");
}
}
}

if (reporter.Count(ErrorLevel.Error) == prevErrorCount) {
// Check that class constructors are called when required.
new ObjectConstructorChecker(reporter).VisitDeclarations(declarations);
Expand Down Expand Up @@ -2159,7 +2175,7 @@ public void RegisterInheritedMembers(TopLevelDeclWithMembers cl, [CanBeNull] DPr
if (cl is NewtypeDecl newtypeDecl) {
if (Options.Get(CommonOptionBag.TypeSystemRefresh)) {
baseTypeDecl = basePreType?.Decl as TopLevelDeclWithMembers;
baseTypeArguments = basePreType?.Arguments.ConvertAll(preType => PreType2TypeUtil.PreType2Type(preType, false, TypeParameter.TPVariance.Co));
baseTypeArguments = basePreType?.Arguments.ConvertAll(preType => PreType2TypeUtil.PreType2Type(preType, false));
} else {
// ignore any subset types, since they have no members and thus we don't need their type-parameter mappings
var baseType = newtypeDecl.BaseType.NormalizeExpand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5151,7 +5151,7 @@ private Expression DesugarDatatypeUpdate(IOrigin tok, Expression root, DatatypeD
if (candidateResultCtors.Count == 0) {
return root;
}
Expression rewrite = null;

// Create a unique name for d', the variable we introduce in the let expression
var dName = FreshTempVarName("dt_update_tmp#", resolutionContext.CodeContext);
var dVar = new BoundVar(new AutoGeneratedOrigin(tok), dName, root.Type);
Expand All @@ -5160,7 +5160,6 @@ private Expression DesugarDatatypeUpdate(IOrigin tok, Expression root, DatatypeD
candidateResultCtors.Reverse();
foreach (var crc in candidateResultCtors) {
// Build the arguments to the datatype constructor, using the updated value in the appropriate slot
var ctorArguments = new List<Expression>();
var actualBindings = new List<ActualBinding>();
foreach (var f in crc.Formals) {
Expression ctorArg;
Expand All @@ -5169,7 +5168,6 @@ private Expression DesugarDatatypeUpdate(IOrigin tok, Expression root, DatatypeD
} else {
ctorArg = new ExprDotName(tok, d, f.NameNode, null);
}
ctorArguments.Add(ctorArg);
var bindingName = new Token(tok.line, tok.col) {
Uri = tok.Uri,
val = f.Name
Expand All @@ -5191,7 +5189,7 @@ private Expression DesugarDatatypeUpdate(IOrigin tok, Expression root, DatatypeD
Contract.Assert(body != null); // because there was at least one element in candidateResultCtors

// Wrap the let's around body
rewrite = body;
var rewrite = body;
foreach (var entry in rhsBindings) {
if (entry.Value.Item1 != null) {
var lhs = new CasePattern<BoundVar>(tok, entry.Value.Item1);
Expand Down
Loading
Loading