-
Notifications
You must be signed in to change notification settings - Fork 298
Recursive constraint dep #6328
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
base: master
Are you sure you want to change the base?
Recursive constraint dep #6328
Changes from all commits
c7caa77
9a39712
a2b5d1f
514fc9e
d135d51
a75a555
cb845ab
e636935
33c802a
8de5386
296febe
21c4e28
7e9c3a9
1d56796
63a36b2
0b87be3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4222,15 +4222,14 @@ public ResolveTypeReturn ResolveTypeLenient(IOrigin tok, Type type, ResolutionCo | |
| t.ResolvedClass = d; // Store the decl, so the compiler will generate the fully qualified name | ||
| } else if (d is RedirectingTypeDecl) { | ||
| var dd = (RedirectingTypeDecl)d; | ||
| var caller = CodeContextWrapper.Unwrap(resolutionContext.CodeContext) as ICallable; | ||
| if (caller != null && !(d is SubsetTypeDecl && caller is SpecialFunction)) { | ||
| if (caller != d) { | ||
| } else if (d is TypeSynonymDecl && !(d is SubsetTypeDecl)) { | ||
| // detect self-loops here, since they don't show up in the graph's SCC methods | ||
| reporter.Error(MessageSource.Resolver, d.Origin, "type-synonym cycle: {0} -> {0}", d.Name); | ||
| } else { | ||
| // detect self-loops here, since they don't show up in the graph's SCC methods | ||
| reporter.Error(MessageSource.Resolver, d.Origin, "recursive constraint dependency involving a {0}: {1} -> {1}", d.WhatKind, d.Name); | ||
| var parent = CodeContextWrapper.Unwrap(resolutionContext.CodeContext) as ICallable; | ||
| if (parent != null && !(d is SubsetTypeDecl && parent is SpecialFunction)) { | ||
| var cycleFound = parent == d; | ||
| if (cycleFound) { | ||
| if (d is TypeSynonymDecl && !(d is SubsetTypeDecl)) { | ||
| // detect self-loops here, since they don't show up in the graph's SCC methods | ||
| reporter.Error(MessageSource.Resolver, d.Origin, "type-synonym cycle: {0} -> {0}", d.Name); | ||
| } | ||
|
Comment on lines
+4229
to
+4232
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this change, you have removed one of the As I will argue (in a comment that I'm about to post on the PR), I think we should remove those messages, too. (But we do need to still check for cycles that consist solely of type synonyms, as you still do here on LL 4229-4232.) |
||
| } | ||
| } | ||
| t.ResolvedClass = d; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // RUN: ! %testDafnyForEachResolver "%s" -- --allow-axioms=false | ||
|
|
||
| type Even = x: int | x % 2 == 0 | ||
| opaque const ten: Even := 10 | ||
|
|
||
| const twoHundred: LessThanTwoHundred := 200 | ||
| type LessThanTwoHundred = k | 0 <= k < twoHundred | ||
|
|
||
| const twoHundred_2: LessThanHundredNinetyNine := 200 | ||
| const hundredNinetyNine: int := twoHundred_2 as int - 1 | ||
| type LessThanHundredNinetyNine = k | 0 <= k < hundredNinetyNine |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| constResolution.dfy(7,5): Error: recursive constraint dependency involving a subset type: LessThanTwoHundred -> twoHundred -> LessThanTwoHundred | ||
| constResolution.dfy(11,5): Error: recursive constraint dependency involving a subset type: LessThanHundredNinetyNine -> hundredNinetyNine -> twoHundred_2 -> LessThanHundredNinetyNine | ||
| 2 resolution/type errors detected in constResolution.dfy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // RUN: ! %verify --type-system-refresh --general-traits=datatype %s &> "%t" | ||
| // RUN: %diff "%s.expect" "%t" | ||
|
|
||
| datatype Stmt = | ||
| | Skip | ||
| | Block(stmts: seq<Stmt>) | ||
| | If(b: bool, thn: BlockStmt, els: BlockStmt) | ||
|
|
||
| type BlockStmt = s: Stmt | s.Block? witness Block([]) | ||
|
Comment on lines
+4
to
+9
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great example! (I think you got this from me. :)) But I would like to see this program go through. The |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| cycles.dfy(9,5): Error: recursive constraint dependency involving a subset type: BlockStmt -> Stmt -> BlockStmt | ||
| 1 resolution/type errors detected in cycles.dfy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // RUN: %verify --type-system-refresh --general-traits=datatype %s &> "%t" | ||
| // RUN: %diff "%s.expect" "%t" | ||
|
|
||
| trait SelfConstraintDep<T extends SelfConstraintDep<T>> {} | ||
| trait SelfConstraintDep2<T extends SelfConstraintDep2<T>> extends object {} | ||
|
|
||
| datatype D extends SelfConstraintDep<D> = D {} | ||
| class C extends SelfConstraintDep2<C> {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
|
|
||
| Dafny program verifier finished with 0 verified, 0 errors |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,11 +191,13 @@ GeneralNewtypeResolution.dfy(927,4): Error: type parameter 'ZZ' is not allowed t | |
| GeneralNewtypeResolution.dfy(932,5): Error: type parameter 'A' is not allowed to change variance (here, from '+' to '-') | ||
| GeneralNewtypeResolution.dfy(933,5): Error: type parameter 'B' is not allowed to change variance (here, from '=' to '+') | ||
| GeneralNewtypeResolution.dfy(934,4): Error: type parameter 'C' is not allowed to change variance (here, from '-' to '=') | ||
| GeneralNewtypeResolution.dfy(940,10): Error: recursive constraint dependency involving a newtype: A -> A | ||
| GeneralNewtypeResolution.dfy(945,10): Error: recursive constraint dependency involving a newtype: A -> A | ||
| GeneralNewtypeResolution.dfy(939,10): Error: a newtype ('W') must be based on some numeric type (got X) | ||
| GeneralNewtypeResolution.dfy(940,10): Error: Cyclic dependency among declarations: A -> A | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A recent change in Dafny was to make verification error messages more consistent. I believe those verification error messages now start with a lower-case letter. I'm not suggesting we change all resolution errors the same way (or at least not in this PR), but I think it would be nice to change this one. |
||
| GeneralNewtypeResolution.dfy(944,10): Error: a newtype ('W') must be based on some numeric type (got X) | ||
| GeneralNewtypeResolution.dfy(945,10): Error: Cyclic dependency among declarations: A -> A | ||
| GeneralNewtypeResolution.dfy(950,7): Error: type-synonym cycle: A -> A | ||
| GeneralNewtypeResolution.dfy(955,10): Error: recursive constraint dependency involving a newtype: A -> A | ||
| 197 resolution/type errors detected in GeneralNewtypeResolution.dfy | ||
| GeneralNewtypeResolution.dfy(955,10): Error: Cyclic dependency among declarations: A -> A | ||
| 199 resolution/type errors detected in GeneralNewtypeResolution.dfy | ||
| GeneralNewtypeResolution.dfy(34,10): Error: a newtype ('MyOrdinal') must be based on some non-reference, non-trait, non-arrow, non-ORDINAL, non-datatype type (got ORDINAL) | ||
| GeneralNewtypeResolution.dfy(40,10): Error: a newtype ('MyObject') must be based on some non-reference, non-trait, non-arrow, non-ORDINAL, non-datatype type (got object) | ||
| GeneralNewtypeResolution.dfy(41,10): Error: a newtype ('MyTrait') must be based on some non-reference, non-trait, non-arrow, non-ORDINAL, non-datatype type (got Trait) | ||
|
|
@@ -355,8 +357,8 @@ GeneralNewtypeResolution.dfy(927,4): Error: type parameter 'ZZ' is not allowed t | |
| GeneralNewtypeResolution.dfy(932,5): Error: type parameter 'A' is not allowed to change variance (here, from '+' to '-') | ||
| GeneralNewtypeResolution.dfy(933,5): Error: type parameter 'B' is not allowed to change variance (here, from '=' to '+') | ||
| GeneralNewtypeResolution.dfy(934,4): Error: type parameter 'C' is not allowed to change variance (here, from '-' to '=') | ||
| GeneralNewtypeResolution.dfy(940,10): Error: recursive constraint dependency involving a newtype: A -> A | ||
| GeneralNewtypeResolution.dfy(945,10): Error: recursive constraint dependency involving a newtype: A -> A | ||
| GeneralNewtypeResolution.dfy(940,10): Error: Cyclic dependency among declarations: A -> A | ||
| GeneralNewtypeResolution.dfy(945,10): Error: Cyclic dependency among declarations: A -> A | ||
| GeneralNewtypeResolution.dfy(950,7): Error: type-synonym cycle: A -> A | ||
| GeneralNewtypeResolution.dfy(955,10): Error: recursive constraint dependency involving a newtype: A -> A | ||
| GeneralNewtypeResolution.dfy(955,10): Error: Cyclic dependency among declarations: A -> A | ||
| 162 resolution/type errors detected in GeneralNewtypeResolution.dfy | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this line. In fact, if I remove it, the new test example still goes through.
This line looks to me as if it would be true for any SCC of size 1. If so, this
ifcondition would always be true. Here's my reasoning: If the SCC whereddis has size 1, then the only successor ofddisdditself.If you think this line is necessary, please add a comment describing what it does.