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

Opaque function annotation #767

Merged
merged 8 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/scala/rules/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,16 @@ object evaluator extends EvaluationRules {
val snap1 = snap.convert(sorts.Snap)
val preFApp = App(functionSupporter.preconditionVersion(v3.symbolConverter.toFunction(func)), snap1 :: tArgs)
v3.decider.assume(preFApp)
val tFApp = App(v3.symbolConverter.toFunction(func), snap1 :: tArgs)
val funcAnn = func.info.getUniqueInfo[AnnotationInfo]
val tFApp = funcAnn match {
case Some(a) if a.values.contains("opaque") =>
val funcAppAnn = fapp.info.getUniqueInfo[AnnotationInfo]
funcAppAnn match {
case Some(a) if a.values.contains("reveal") => App(v3.symbolConverter.toFunction(func), snap1 :: tArgs)
case _ => App(functionSupporter.limitedVersion(v3.symbolConverter.toFunction(func)), snap1 :: tArgs)
}
case _ => App(v3.symbolConverter.toFunction(func), snap1 :: tArgs)
}
val fr5 =
s4.functionRecorder.changeDepthBy(-1)
.recordSnapshot(fapp, v3.decider.pcs.branchConditions, snap1)
Expand Down
8 changes: 6 additions & 2 deletions src/main/scala/supporters/functions/FunctionData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,13 @@ class FunctionData(val programFunction: ast.Function,
val pre = preconditionFunctionApplication
val nestedDefinitionalAxioms = generateNestedDefinitionalAxioms
val body = And(nestedDefinitionalAxioms ++ List(Implies(pre, And(functionApplication === translatedBody))))
val funcAnn = programFunction.info.getUniqueInfo[ast.AnnotationInfo]
val actualPredicateTriggers = funcAnn match {
case Some(a) if a.values.contains("opaque") => Seq()
case _ => predicateTriggers.values.map(pt => Trigger(Seq(triggerFunctionApplication, pt)))
}
val allTriggers = (
Seq(Trigger(functionApplication))
++ predicateTriggers.values.map(pt => Trigger(Seq(triggerFunctionApplication, pt))))
Seq(Trigger(functionApplication)) ++ actualPredicateTriggers)

Forall(arguments, body, allTriggers)})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import viper.silicon.rules.functionSupporter
import viper.silicon.state.{Identifier, SimpleIdentifier, SuffixedIdentifier, SymbolConverter}
import viper.silicon.state.terms._
import viper.silicon.supporters.ExpressionTranslator
import viper.silver.ast.AnnotationInfo
import viper.silver.reporter.{InternalWarningMessage, Reporter}

class HeapAccessReplacingExpressionTranslator(symbolConverter: SymbolConverter,
Expand Down Expand Up @@ -127,7 +128,16 @@ class HeapAccessReplacingExpressionTranslator(symbolConverter: SymbolConverter,

case eFApp: ast.FuncApp =>
val silverFunc = program.findFunction(eFApp.funcname)
val fun = symbolConverter.toFunction(silverFunc)
val funcAnn = silverFunc.info.getUniqueInfo[AnnotationInfo]
val fun = funcAnn match {
case Some(a) if a.values.contains("opaque") =>
val funcAppAnn = eFApp.info.getUniqueInfo[AnnotationInfo]
funcAppAnn match {
case Some(a) if a.values.contains("reveal") => symbolConverter.toFunction(silverFunc)
case _ => functionSupporter.limitedVersion(symbolConverter.toFunction(silverFunc))
}
case _ => symbolConverter.toFunction(silverFunc)
}
val args = eFApp.args map (arg => translate(arg))
val snap = getOrFail(data.fappToSnap, eFApp, sorts.Snap)
val fapp = App(fun, snap +: args)
Expand Down
Loading