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

fix: Termination override check for certain non-reference trait implementations #5087

Merged
merged 4 commits into from
Feb 14, 2024

Conversation

fabiomadge
Copy link
Collaborator

@fabiomadge fabiomadge commented Feb 14, 2024

Closes #4969 and #4982.

Copy link
Collaborator

@RustanLeino RustanLeino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this.

I have two suggestions for additional tests. One is to add the test from #4969 (and to mark this PR as fixing that Issue, too).

The other is to add a test that involves type parameters. This would show that the updated substitution maps / types passed to FunctionCallSubstituter are working as expected (and will cause the test suite to break if that code is changed in the future).

Comment on lines 1464 to 1465
var T = (TraitDecl)(overryd is Function f1 ? f1.EnclosingClass : ((Method)overryd).EnclosingClass);
var I = (TopLevelDeclWithMembers)(original is Function f2 ? f2.EnclosingClass : ((Method)original).EnclosingClass);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the ? :, cast to MemberDecl and then take its .EnclosingClass. Like this:

((MemberDecl)overryd).EnclosingClass

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I tried for some time, but not hard enough, as it turns out.

for (int i = 0; i < N; i++) {
Expression e0 = calleeDecreases[i];
Expression e1 = Substitute(contextDecreases[i], null, substMap, typeMap);
sub ??= new FunctionCallSubstituter(substMap, typeMap, T, I);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave this as is, but I don't think the extra lines here are worth the saving of creating sub only once and only if needed. If you agree, you could either always initialize sub before the loop (which is more costly only when N is 0) or create a new sub in each iteration (which is more costly only if N is 2 or more). I'd probably go for the latter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried inlining the construction of the substituter, but even I think it a little much for a single line. Without it, we're only saving a single line.

@fabiomadge fabiomadge merged commit 73fcdf3 into dafny-lang:master Feb 14, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Boogie crash due to decreases clause in trait
2 participants