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 pretty printer for termination measures #831

Merged
merged 2 commits into from
Jan 10, 2025

Conversation

jcp19
Copy link
Contributor

@jcp19 jcp19 commented Jan 10, 2025

While pretty printing the Viper files emitted by Gobra, I found two issues with the pretty printer of termination measures:

  1. because termination measures are converted into preconditions (posts are also supported, IIRC) by the termination plugin, the pretty printer prints decreases clauses as requires decreases X instead of decreases X
  2. When the termination measure is a predicate instance, the PredicateInstance plugin will insert an "@" before the name of the predicate in the termination measure

For a concrete example, viper pretty prints

function IsDuplicableMem(thisItf: Tuple2[Ref, Types]): Bool
  requires decreases @ErrorMem(thisItf)

instead of

function IsDuplicableMem(thisItf: Tuple2[Ref, Types]): Bool
  decreases ErrorMem(thisItf)

PS: I don't understand why predicate instances where being printed with a "@" in the first place, and as far as I can tell, no one relies on this behaviour. Maybe @mschwerhoff knows why.

Copy link
Contributor

@marcoeilers marcoeilers left a comment

Choose a reason for hiding this comment

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

LGTM. It doesn't look great if the standard silver code refers to a plugin, but IIRC we decided that the termination plugin is supposed to be considered an actual part of silver now, so I think that's fine.

@jcp19
Copy link
Contributor Author

jcp19 commented Jan 10, 2025

I was equally apprehensive to make the silver code dependent on a plugin, but having termination checks implemented by a plugin has been a fruitful source of bugs and hacks. I think termination should always have been a part of the language, and I am glad to move in that direction.

@jcp19 jcp19 enabled auto-merge (squash) January 10, 2025 14:58
@jcp19 jcp19 merged commit 4833685 into master Jan 10, 2025
5 checks passed
@jcp19 jcp19 deleted the jcp19-fix-pretty-printer-decreases branch January 10, 2025 15:09
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.

2 participants