Skip to content

Commit

Permalink
v5.0.14-RC: CFunc removed
Browse files Browse the repository at this point in the history
  • Loading branch information
aslesarenko committed Apr 4, 2024
1 parent 5899701 commit de8c362
Showing 1 changed file with 0 additions and 56 deletions.
56 changes: 0 additions & 56 deletions interpreter/shared/src/main/scala/sigmastate/eval/CContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,6 @@ import sigma.exceptions.InvalidType
import scala.annotation.unused
import scala.reflect.ClassTag


/** This class represents context variable and register value of a functional type A => B.
* When variable or register is accessed using `getVar[A => B](id).get` or
* `box.getReg[A => B].get an instance of this class is returned.
*
* It internally transforms a given `tree` into executable function.
* This it similar to what happens during validation of propositions in the input boxes:
* - size check of underlying ErgoTree against limits
* - construction of `calcF` and `costF` graphs, both are stored together with resulting function.
* - check the types of `calcF` graph to be compatible with expected types A and B
* If anything goes wrong, this operation fails and if it is used in the script, the script also fails.
*
* When f is obtained as `val f = getVar[Int => Int](id).get` then any application `f(x)` involves size estimation
* using underlying `costF(x)`.
* */
//case class CFunc[A,B](context: sigmastate.interpreter.Context, tree: SValue)
// (implicit tDom: RType[A], tRange: RType[B], IR: IRContext) extends (A => B) {
// import CFunc._
//
// private val compiled = {
// import IR._
// val IR.Pair(calcF, costF) = IR.doCosting(emptyEnv, tree)
//
// val eDom = asElem[Any](IR.rtypeToElem(tDom))
// val eRange = asElem[Any](IR.rtypeToElem(tRange))
//
// IR.verifyCalcFunc[Any => Any](asRep[Context => (Any => Any)](calcF), IR.funcElement(eDom, eRange))
//// IR.verifyCostFunc(costF).getOrThrow
//// IR.verifyIsProven(calcF).getOrThrow
//
// // check cost
//// val costingCtx = context.toSigmaContext(IR, isCost = true)
//// val costFun = IR.compile[SInt.type](IR.getDataEnv, costF)
//// val IntConstant(estimatedCost) = costFun(costingCtx)
//// if (estimatedCost > maxCost) {
//// throw new Error(s"Estimated execution cost $estimatedCost exceeds the limit $maxCost in $tree")
//// }
// // check calc
// val calcCtx = context.toSigmaContext(IR, isCost = false)
// val valueFun = IR.compile[SFunc](IR.getDataEnv, asRep[Context => SFunc#WrappedType](calcF))
// val res = valueFun(calcCtx) match {
// case Constant(f, fTpe: SFunc) => f
// case v => v
// }
// res.asInstanceOf[A => B]
// }
//
// override def apply(x: A): B = compiled(x)
//}
object CFunc {
/** The cost of creating resulting function but not its execution.
* Thus it is expected to be small. It can be increased if useful cases are found
* such that `tree` should contains heavy operations. */
val maxCost = 1000
}

/** A default implementation of [[Context]] interface.
* @see [[Context]] for detailed descriptions
*/
Expand Down

0 comments on commit de8c362

Please sign in to comment.