Repository navigation
Fix issue #841 #919
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
Open
jcp19
wants to merge
19
commits into
master
Choose a base branch
from
fix-841
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix issue #841 #919
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
035413f
Revert "Revert commits accidentally pushed to master"
jcp19 4db912e
add missing termination measures
jcp19 fa08b49
add more termination measures to stdlib packages
jcp19 18dabab
merge with master
jcp19 06f6a04
Merge branch 'master' into fix-841
jcp19 83074a8
Restrict issue #841 regression test to always-checked rules; fix embe…
jcp19 d1bda4f
Add unit tests for the termination-measure requirement on pure interf…
jcp19 e14daf0
Check pure-member termination measures uniformly in wellDefIfPureSpec
jcp19 dc554ec
Fix parse error in 000841 regression test
jcp19 e7188ad
Merge branch 'master' into fix-841
jcp19 02e7cdd
Test that pure interface methods must have termination measures
jcp19 29b75ae
Require termination measures for ghost interface methods
jcp19 7d7b73f
Check interface method signatures in a single place
jcp19 bfbf3fa
Check pure closure literals like all other pure members
jcp19 2eda1d1
Document why the termination checks need their own test suite
jcp19 844fa54
Update src/main/scala/viper/gobra/frontend/info/implementation/typing…
jcp19 467f4fb
Update src/main/scala/viper/gobra/frontend/info/implementation/typing…
jcp19 ae62d80
Update src/main/scala/viper/gobra/frontend/ParseTreeTranslator.scala
jcp19 309fbb1
Update src/test/resources/regressions/features/opaque/opaque-closure-…
jcp19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/resources/check_termination/ghost-and-pure-members-need-measures.gobra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Any copyright is dedicated to the Public Domain. | ||
| // http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
|
||
| package ghost_and_pure_members_need_measures | ||
|
jcp19 marked this conversation as resolved.
|
||
|
|
||
| // Ghost and pure members must be guaranteed to terminate on every call. Following issue #841, this | ||
| // includes the method signatures declared in an interface, which used to be exempt. Unlike the main | ||
| // regression test suite, the files in this directory are checked with `disableCheckTerminationPureFns` | ||
| // disabled. | ||
|
|
||
| type T struct{ f int } | ||
|
|
||
| // Type error, a pure function must have a termination measure. | ||
| //:: ExpectedOutput(type_error) | ||
| pure func missingMeasureFunc(a int) int { | ||
| return a | ||
| } | ||
|
|
||
| // Type error, a pure method must have a termination measure. | ||
| //:: ExpectedOutput(type_error) | ||
| pure func (t T) missingMeasureMethod(a int) int { | ||
| return a | ||
| } | ||
|
|
||
| // Type error, a ghost function must have a termination measure. | ||
| ghost | ||
| //:: ExpectedOutput(type_error) | ||
| func missingMeasureGhostFunc(a int) int { | ||
| return a | ||
| } | ||
|
|
||
| // Type error, a ghost method must have a termination measure. | ||
| ghost | ||
| //:: ExpectedOutput(type_error) | ||
| func (t T) missingMeasureGhostMethod(a int) int { | ||
| return a | ||
| } | ||
|
|
||
| type I interface { | ||
| // Type error, a pure interface method must have a termination measure. | ||
| //:: ExpectedOutput(type_error) | ||
| pure MissingMeasurePure(a int) int | ||
|
|
||
| // Type error, a ghost interface method must have a termination measure. | ||
| //:: ExpectedOutput(type_error) | ||
| ghost MissingMeasureGhost(a int) | ||
|
|
||
| decreases | ||
| pure HasMeasurePure(a int) int | ||
|
|
||
| ghost | ||
| decreases | ||
| HasMeasureGhost(a int) | ||
|
|
||
| // An interface method that is neither ghost nor pure need not terminate. | ||
| NeedNotTerminate(a int) | ||
| } | ||
|
jcp19 marked this conversation as resolved.
|
||
|
|
||
| decreases | ||
| pure func withMeasureFunc(a int) int { | ||
| return a | ||
| } | ||
|
|
||
| decreases | ||
| pure func (t T) withMeasureMethod(a int) int { | ||
| return a | ||
| } | ||
|
|
||
| ghost | ||
| decreases | ||
| func withMeasureGhostFunc(a int) int { | ||
| return a | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Any copyright is dedicated to the Public Domain. | ||
| // http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
|
||
| package issue000841 | ||
|
|
||
| // Issue #841: pure method signatures declared in an interface must satisfy the same requirements as | ||
| // pure functions and pure methods. The requirement of carrying a termination measure is gated behind | ||
| // `disableCheckTerminationPureFns`, which this test suite enables; that case is covered by the tests | ||
| // in `src/test/resources/check_termination` instead. | ||
|
|
||
| type J interface { | ||
| // Type error, a pure member must have exactly one result parameter. | ||
| //:: ExpectedOutput(type_error) | ||
| decreases | ||
| pure NoResult(a int) | ||
|
|
||
| // Type error, a pure member must have exactly one result parameter. | ||
| //:: ExpectedOutput(type_error) | ||
| decreases | ||
| pure TwoResults(a int) (int, int) | ||
|
|
||
| decreases | ||
| // Type error, a pure member cannot have variadic parameters. | ||
| //:: ExpectedOutput(type_error) | ||
| pure Variadic(a ...int) int | ||
|
|
||
| // Type error, a pure member cannot have preserves clauses. | ||
| //:: ExpectedOutput(type_error) | ||
| preserves a > 0 | ||
| decreases | ||
| pure Preserves(a int) int | ||
|
|
||
| // Type error, the postconditions of a pure member must be pure. | ||
| //:: ExpectedOutput(type_error) | ||
| ensures acc(x) | ||
| decreases | ||
| pure ImpurePostcondition(x *int) int | ||
| } | ||
|
|
||
| // A pure method signature that satisfies all of the requirements above is accepted. | ||
| type K interface { | ||
| ensures res >= a | ||
| decreases | ||
| pure WellFormed(a int) (res int) | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/test/scala/viper/gobra/GobraCheckTerminationTests.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| // | ||
| // Copyright (c) 2011-2026 ETH Zurich. | ||
|
|
||
| package viper.gobra | ||
|
|
||
| import org.bitbucket.inkytonik.kiama.util.Source | ||
| import viper.gobra.frontend.Config | ||
|
|
||
| /** | ||
| * Runs the test files in `src/test/resources/check_termination` with `disableCheckTerminationPureFns` | ||
| * disabled, i.e., with the requirement that all pure and ghost members carry a termination measure. | ||
| * | ||
| * The main regression test suite ([[GobraTests]]) sets `disableCheckTerminationPureFns` to `true`, | ||
| * because adding termination measures to all of its test files is still pending work. Note that an | ||
| * in-file configuration (`// ##(...)`) cannot be used to opt out of that setting, as configurations | ||
| * are merged by taking the disjunction of the boolean flags. This suite exists so that the | ||
| * requirement itself can be tested; test files that are unrelated to termination checking belong to | ||
| * the main regression test suite instead. | ||
| */ | ||
|
jcp19 marked this conversation as resolved.
|
||
| class GobraCheckTerminationTests extends GobraTests { | ||
| val checkTerminationPropertyName = "GOBRATESTS_CHECK_TERMINATION_DIR" | ||
|
|
||
| val checkTerminationDir: String = System.getProperty(checkTerminationPropertyName, "check_termination") | ||
|
|
||
| override val testDirectories: Seq[String] = Vector(checkTerminationDir) | ||
|
|
||
| override protected def getConfig(source: Source): Config = | ||
| super.getConfig(source).copy(disableCheckTerminationPureFns = false) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.