-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish cherry-picking Asserting/Assuming changes from Bob's branch
- Loading branch information
1 parent
51b0239
commit 7d8907e
Showing
8 changed files
with
64 additions
and
122 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,56 @@ | ||
package vct.rewrite | ||
|
||
import com.typesafe.scalalogging.LazyLogging | ||
import vct.col.ast.{ | ||
Assuming, | ||
Expr, | ||
Function, | ||
Let, | ||
TBool, | ||
UnitAccountedPredicate, | ||
Variable, | ||
} | ||
import vct.col.origin.{DiagnosticOrigin, UnsafeDontCare} | ||
import vct.col.rewrite.{Generation, Rewriter, RewriterBuilder} | ||
|
||
import vct.col.util.AstBuildHelpers._ | ||
|
||
case object EncodeAssuming extends RewriterBuilder { | ||
override def key: String = "encodeAssumeExpr" | ||
override def desc: String = "Encodes assume exprs using plain pure functions" | ||
} | ||
|
||
case class EncodeAssuming[Pre <: Generation]() | ||
extends Rewriter[Pre] with LazyLogging { | ||
|
||
lazy val assumingFunction: Function[Post] = { | ||
implicit val o = DiagnosticOrigin | ||
val assnVar = new Variable[Post](TBool())(o.where(name = "assn")) | ||
globalDeclarations.declare( | ||
function( | ||
blame = UnsafeDontCare.Contract("assumption primitive"), | ||
contractBlame = UnsafeDontCare.Satisfiability("assumption primitive"), | ||
returnType = TBool(), | ||
args = Seq(assnVar), | ||
ensures = UnitAccountedPredicate(assnVar.get), | ||
)(o.where(name = "assume_")) | ||
) | ||
} | ||
|
||
override def dispatch(expr: Expr[Pre]): Expr[Post] = | ||
expr match { | ||
case Assuming(assn, inner) => | ||
implicit val o = expr.o | ||
Let( | ||
new Variable(TBool())(o.where(name = "_")), | ||
functionInvocation( | ||
ref = assumingFunction.ref, | ||
args = Seq(dispatch(assn)), | ||
blame = UnsafeDontCare.Invocation("assumption"), | ||
), | ||
dispatch(inner), | ||
) | ||
|
||
case _ => expr.rewriteDefault() | ||
} | ||
} |