Skip to content

Commit b573af1

Browse files
authored
Remove deprecated initialization postconditions (#971)
* deprecate init posts * fix unit tests
1 parent e48d71a commit b573af1

File tree

12 files changed

+11
-37
lines changed

12 files changed

+11
-37
lines changed

src/main/antlr4/GobraLexer.g4

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ OUTLINE : 'outline';
9292
DUPLICABLE : 'dup';
9393
PKG_INV : 'pkgInvariant';
9494
OPEN_DUP_SINV : 'openDupPkgInv' -> mode(NLSEMI);
95-
INIT_POST : 'initEnsures';
9695
IMPORT_PRE : 'importRequires';
9796
PROOF : 'proof';
9897
GHOST_EQUALS : '===';

src/main/antlr4/GobraParser.g4

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,13 @@ friendPkgDecl: FRIENDPKG importPath assertion;
3535

3636
// Ghost members
3737
sourceFile:
38-
(pkgInvariant eos)* (initPost eos)* packageClause eos (friendPkgDecl eos)* (importDecl eos)* (
38+
(pkgInvariant eos)* packageClause eos (friendPkgDecl eos)* (importDecl eos)* (
3939
member eos
4040
)* EOF;
4141

4242
// `preamble` is a second entry point allowing us to parse only the top of a source.
4343
// That's also why we don not enforce EOF at the end.
44-
preamble: (pkgInvariant eos)* (initPost eos)* packageClause eos (friendPkgDecl eos)* (importDecl eos)*;
45-
46-
initPost: INIT_POST expression;
44+
preamble: (pkgInvariant eos)* packageClause eos (friendPkgDecl eos)* (importDecl eos)*;
4745

4846
importPre: IMPORT_PRE expression;
4947

src/main/scala/viper/gobra/ast/frontend/Ast.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ case class PPackage(
5454
case class PProgram(
5555
packageClause: PPackageClause,
5656
pkgInvariants: Vector[PPkgInvariant],
57-
@deprecated("Init postconditions were deprecated in PR #797 and will soon be completely removed.")
58-
initPosts: Vector[PExpression],
5957
imports: Vector[PImport],
6058
friends: Vector[PFriendPkgDecl],
6159
declarations: Vector[PMember]
@@ -65,8 +63,6 @@ case class PProgram(
6563
case class PPreamble(
6664
packageClause: PPackageClause,
6765
pkgInvariants: Vector[PPkgInvariant],
68-
@deprecated("Init postconditions were deprecated in PR #797 and will soon be completely removed.")
69-
initPosts: Vector[PExpression],
7066
imports: Vector[PImport],
7167
friends: Vector[PFriendPkgDecl],
7268
positions: PositionManager,

src/main/scala/viper/gobra/ast/frontend/PrettyPrinter.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,15 @@ class DefaultPrettyPrinter extends PrettyPrinter with kiama.output.PrettyPrinter
6363
// program
6464

6565
def showProgram(p: PProgram): Doc = p match {
66-
// initPosts not shown, they are deprecated and will soon be removed
67-
case PProgram(packageClause, pkgInvs, _, imports, friends, declarations) =>
66+
case PProgram(packageClause, pkgInvs, imports, friends, declarations) =>
6867
showPreamble(packageClause, pkgInvs, imports, friends) <>
6968
ssep(declarations map showMember, line <> line) <> line
7069
}
7170

7271
// preamble
7372

7473
def showPreamble(p: PPreamble): Doc = p match {
75-
// initPosts not shown, they are deprecated and will soon be removed
76-
case PPreamble(packageClause, pkgInvs, _, imports, friends, _) =>
74+
case PPreamble(packageClause, pkgInvs, imports, friends, _) =>
7775
showPreamble(packageClause, pkgInvs, imports, friends)
7876
}
7977

src/main/scala/viper/gobra/frontend/ParseTreeTranslator.scala

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,30 +2302,21 @@ class ParseTreeTranslator(pom: PositionManager, source: Source, specOnly : Boole
23022302
*/
23032303
override def visitSourceFile(ctx: GobraParser.SourceFileContext): PProgram = {
23042304
val packageClause: PPackageClause = visitNode(ctx.packageClause())
2305-
val initPosts: Vector[PExpression] = visitListNode[PExpression](ctx.initPost())
23062305
val pkgInvs: Vector[PPkgInvariant] = visitListNode[PPkgInvariant](ctx.pkgInvariant())
23072306
val importDecls = ctx.importDecl().asScala.toVector.flatMap(visitImportDecl)
23082307
val friendPkgs: Vector[PFriendPkgDecl] = visitListNode[PFriendPkgDecl](ctx.friendPkgDecl())
23092308
val members = ctx.member().asScala.toVector.flatMap(visitMember)
2310-
PProgram(packageClause, pkgInvs, initPosts, importDecls, friendPkgs, members).at(ctx)
2309+
PProgram(packageClause, pkgInvs, importDecls, friendPkgs, members).at(ctx)
23112310
}
23122311

23132312
override def visitPreamble(ctx: GobraParser.PreambleContext): PPreamble = {
23142313
val packageClause: PPackageClause = visitNode(ctx.packageClause())
2315-
val initPosts: Vector[PExpression] = visitListNode[PExpression](ctx.initPost())
23162314
val pkgInvs: Vector[PPkgInvariant] = visitListNode[PPkgInvariant](ctx.pkgInvariant())
23172315
val importDecls = ctx.importDecl().asScala.toVector.flatMap(visitImportDecl)
23182316
val friendPkgs: Vector[PFriendPkgDecl] = visitListNode[PFriendPkgDecl](ctx.friendPkgDecl())
2319-
PPreamble(packageClause, pkgInvs, initPosts, importDecls, friendPkgs, pom).at(ctx)
2317+
PPreamble(packageClause, pkgInvs, importDecls, friendPkgs, pom).at(ctx)
23202318
}
23212319

2322-
/**
2323-
* Visists an init postcondition
2324-
* @param ctx the parse tree
2325-
* @return the positioned PPackageclause
2326-
*/
2327-
override def visitInitPost(ctx: InitPostContext): PExpression = visitNode[PExpression](ctx.expression())
2328-
23292320
/**
23302321
* Visits a pkgInvariant
23312322
*

src/main/scala/viper/gobra/frontend/Parser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ object Parser extends LazyLogging {
460460
// note that the resolveImports strategy could be embedded in e.g. a logfail strategy to report a
461461
// failed strategy application
462462
val updatedImports = rewrite(topdown(attempt(resolveImports)))(prog.imports)
463-
PProgram(prog.packageClause, prog.pkgInvariants, prog.initPosts, updatedImports, prog.friends, prog.declarations).at(prog)
463+
PProgram(prog.packageClause, prog.pkgInvariants, updatedImports, prog.friends, prog.declarations).at(prog)
464464
})
465465
// create a new package node with the updated programs
466466
val updatedPkg = PPackage(pkg.packageClause, updatedProgs, pkg.positions, pkg.info).at(pkg)
@@ -508,7 +508,7 @@ object Parser extends LazyLogging {
508508
// apply the replaceTerminationMeasuresForFunctionsAndMethods to declarations until the strategy has succeeded
509509
// (i.e. has reached PMember nodes) and stop then
510510
val updatedDecls = rewrite(alltd(replaceTerminationMeasuresForFunctionsAndMethods))(prog.declarations)
511-
PProgram(prog.packageClause, prog.pkgInvariants, prog.initPosts, prog.imports, prog.friends, updatedDecls).at(prog)
511+
PProgram(prog.packageClause, prog.pkgInvariants, prog.imports, prog.friends, updatedDecls).at(prog)
512512
})
513513
// create a new package node with the updated programs
514514
Right(PPackage(pkg.packageClause, updatedProgs, pkg.positions, pkg.info).at(pkg))

src/main/scala/viper/gobra/frontend/info/implementation/typing/ProgramTyping.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ import viper.gobra.util.{Computation, Violation}
1818
trait ProgramTyping extends BaseTyping { this: TypeInfoImpl =>
1919

2020
lazy val wellDefProgram: WellDefinedness[PProgram] = createWellDef {
21-
case PProgram(_, _, initPosts, _, _, _) if initPosts.nonEmpty =>
22-
error(initPosts.head, "'initEnsures' clauses are now deprecated." +
23-
" Consider using 'pkgInvariant' clauses instead.")
24-
case PProgram(_, _, _, _, friends, _) if !config.enableExperimentalFriendClauses && friends.nonEmpty =>
21+
case PProgram(_, _, _, friends, _) if !config.enableExperimentalFriendClauses && friends.nonEmpty =>
2522
error(friends.head, "Usage of experimental 'friendPkg' clauses is disallowed by default. " +
2623
"Pass the flag --experimentalFriendClauses to allow it. This feature may change in the future.")
27-
case prog@PProgram(_, pkgInvs, _, _, friends, _) =>
24+
case prog@PProgram(_, pkgInvs, _, friends, _) =>
2825
// Obtains global variable declarations sorted by the order in which they appear in the file
2926
val sortedByPosDecls: Vector[PVarDecl] = globalVarDeclsSortedByPos(prog)
3027
// HACK: without this explicit check, Gobra does not find repeated declarations

src/test/scala/viper/gobra/erasing/GhostErasureUnitTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ class GhostErasureUnitTests extends AnyFunSuite with Matchers with Inside {
378378
Vector.empty,
379379
Vector.empty,
380380
Vector.empty,
381-
Vector.empty,
382381
Vector(PFunctionDecl(
383382
PIdnDef("foo"),
384383
inArgs.map(_._1),
@@ -417,7 +416,7 @@ class GhostErasureUnitTests extends AnyFunSuite with Matchers with Inside {
417416
val program = stubProgram(inArgs, stmt)
418417
val ghostLess = ghostLessProg(program)
419418
val block = ghostLess match {
420-
case PProgram(_, _, _, _, _, Vector(PFunctionDecl(PIdnDef("foo"), _, _, _, Some((_, b))))) => b
419+
case PProgram(_, _, _, _, Vector(PFunctionDecl(PIdnDef("foo"), _, _, _, Some((_, b))))) => b
421420
case p => fail(s"Parsing succeeded but with an unexpected program $p")
422421
}
423422
normalize(block.stmts) match {

src/test/scala/viper/gobra/typing/ExprTypingUnitTests.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3367,7 +3367,6 @@ class ExprTypingUnitTests extends AnyFunSuite with Matchers with Inside {
33673367
Vector(),
33683368
Vector(),
33693369
Vector(),
3370-
Vector(),
33713370
Vector(PMethodDecl(
33723371
PIdnDef("foo"),
33733372
PUnnamedReceiver(PMethodReceiveName(PNamedOperand(PIdnUse("self")))),

src/test/scala/viper/gobra/typing/MemberTypingUnitTests.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class MemberTypingUnitTests extends AnyFunSuite with Matchers with Inside {
8585
Vector(),
8686
Vector(),
8787
Vector(),
88-
Vector(),
8988
members
9089
)
9190
(prog, idnUse.map(_ => idnDefX))

0 commit comments

Comments
 (0)