Skip to content
Snippets Groups Projects
Commit f54da2c2 authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Replace solution within choose, since now it can do direct recursive

calls
parent 119a0f8c
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ package synthesis ...@@ -6,6 +6,7 @@ package synthesis
import purescala.Common._ import purescala.Common._
import purescala.Definitions._ import purescala.Definitions._
import purescala.ExprOps._ import purescala.ExprOps._
import purescala.DefOps._
import purescala.Expressions._ import purescala.Expressions._
import purescala.Constructors._ import purescala.Constructors._
import purescala.ScalaPrinter import purescala.ScalaPrinter
...@@ -97,28 +98,19 @@ class Synthesizer(val context : LeonContext, ...@@ -97,28 +98,19 @@ class Synthesizer(val context : LeonContext,
// Returns the new program and the new functions generated for this // Returns the new program and the new functions generated for this
def solutionToProgram(sol: Solution): (Program, List[FunDef]) = { def solutionToProgram(sol: Solution): (Program, List[FunDef]) = {
// We replace the choose with the body of the synthesized solution
// Create new fundef for the body val solutionExpr = sol.toSimplifiedExpr(context, program)
val ret = tupleTypeWrap(problem.xs.map(_.getType))
val res = Variable(FreshIdentifier("res", ret))
val mapPost: Map[Expr, Expr] = problem.xs.zipWithIndex.map{ case (id, i) => val (npr, fdMap) = replaceFunDefs(program)({
Variable(id) -> tupleSelect(res, i+1, problem.xs.size) case fd if fd eq ci.fd =>
}.toMap val nfd = fd.duplicate
nfd.fullBody = replace(Map(ci.source -> solutionExpr), nfd.fullBody)
val fd = new FunDef(FreshIdentifier(ci.fd.id.name+"_final", alwaysShowUniqueID = true), Nil, ret, problem.as.map(ValDef(_)), DefType.MethodDef) Some(nfd)
fd.precondition = Some(and(problem.pc, sol.pre)) case _ => None
fd.postcondition = Some(Lambda(Seq(ValDef(res.id)), replace(mapPost, problem.phi))) })
fd.body = Some(sol.term)
val newDefs = fd +: sol.defs.toList
val newModule = ModuleDef(FreshIdentifier("synthesis"), newDefs.toSeq, false)
val newUnit = UnitDef(FreshIdentifier("synthesis"), Seq(newModule), Nil, Seq(), true)
val npr = program.copy(units = newUnit :: program.units)
(npr, newDefs) (npr, fdMap.get(ci.fd).toList)
} }
def shutdown(): Unit = { def shutdown(): Unit = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment