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

Removing unused code #1 #944

Merged
merged 7 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ErgoLikeContext(val lastBlockUtxoRoot: AvlTreeData,
def withTransaction(newSpendingTransaction: ErgoLikeTransactionTemplate[_ <: UnsignedInput]): ErgoLikeContext =
ErgoLikeContext.copy(this)(spendingTransaction = newSpendingTransaction)

override def toSigmaContext(extensions: Map[Byte, AnyValue] = Map()): sigma.Context = {
override def toSigmaContext(): sigma.Context = {
import Evaluation._

def contextVars(m: Map[Byte, AnyValue]): Coll[AnyValue] = {
Expand All @@ -161,7 +161,7 @@ class ErgoLikeContext(val lastBlockUtxoRoot: AvlTreeData,
val tVal = stypeToRType[SType](v.tpe)
k -> toAnyValue(v.value.asWrappedType)(tVal)
}.toMap
val vars = contextVars(varMap ++ extensions)
val vars = contextVars(varMap)
val avlTree = CAvlTree(lastBlockUtxoRoot)
// so selfBox is never one of the `inputs` instances
// as result selfBoxIndex is always (erroneously) returns -1 in ErgoTree v0, v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package sigmastate.interpreter

import java.util
import sigma.kiama.rewriting.Rewriter.{everywherebu, rule, strategy}
import org.ergoplatform.ErgoLikeContext
import org.ergoplatform.validation.SigmaValidationSettings
import org.ergoplatform.validation.ValidationRules._
import sigmastate.crypto.DLogProtocol.ProveDlog
import sigmastate.SCollection.SByteArray
import sigmastate.Values._
import sigmastate.crypto.DLogProtocol.{DLogInteractiveProver, FirstDLogProverMessage, ProveDlog}
import sigmastate.crypto.DLogProtocol.{DLogInteractiveProver, FirstDLogProverMessage}
import sigmastate.crypto._
import sigmastate.interpreter.Interpreter._
import sigmastate.serialization.{SigmaSerializer, ValueSerializer}
Expand Down Expand Up @@ -199,7 +198,6 @@ trait Interpreter {
def fullReduction(ergoTree: ErgoTree,
ctx: CTX,
env: ScriptEnv): ReductionResult = {
implicit val vs: SigmaValidationSettings = ctx.validationSettings
val context = ctx.withErgoTreeVersion(ergoTree.version).asInstanceOf[CTX]
VersionContext.withVersions(context.activatedScriptVersion, ergoTree.version) {
val prop = propositionFromErgoTree(ergoTree, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import sigmastate.Values.EvaluatedValue
import sigmastate.interpreter.ContextExtension.VarBinding
import sigmastate.serialization.SigmaSerializer
import sigmastate.utils.{SigmaByteWriter, SigmaByteReader}
import sigma.AnyValue

/**
* User-defined variables to be put into context.
Expand All @@ -33,12 +32,12 @@ object ContextExtension {
type VarBinding = (Byte, EvaluatedValue[_ <: SType])

object serializer extends SigmaSerializer[ContextExtension, ContextExtension] {
override def serialize(obj: ContextExtension, w: SigmaByteWriter): Unit = {
val size = obj.values.size
override def serialize(contextExtension: ContextExtension, w: SigmaByteWriter): Unit = {
val size = contextExtension.values.size
if (size > Byte.MaxValue)
error(s"Number of ContextExtension values $size exceeds ${Byte.MaxValue}.")
w.putUByte(size)
obj.values.foreach { case (id, v) => w.put(id).putValue(v) }
contextExtension.values.foreach { case (id, v) => w.put(id).putValue(v) }
}

override def parse(r: SigmaByteReader): ContextExtension = {
Expand Down Expand Up @@ -111,12 +110,8 @@ trait InterpreterContext {
* Thus, this method performs transformation from Ergo to internal Sigma representation
* of all context data.
*
* @param extensions additional context variables which will be merged with those in the
* `extension` of this instance, overriding existing bindings in case
* variable ids overlap.
*
* @see sigmastate.eval.Evaluation
*/
def toSigmaContext(extensions: Map[Byte, AnyValue] = Map()): sigma.Context
def toSigmaContext(): sigma.Context
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ import sigmastate.utils._
import sigmastate.utxo.ComplexityTable._
import sigmastate.utxo._

import scala.collection.compat.immutable.ArraySeq
import scala.collection.mutable
import scala.collection.mutable.{HashMap, Map}

abstract class ValueSerializer[V <: Value[SType]] extends SigmaSerializer[Value[SType], V] {
import scala.language.implicitConversions
private val companion = ValueSerializer

def getComplexity: Int = OpCodeComplexity.getOrElse(opCode, MinimalComplexity)
lazy val complexity: Int = getComplexity
Expand Down Expand Up @@ -256,7 +252,6 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] {

def printSerInfo(): String = {
serializerInfo.map { case (_, s) =>
val ser = getSerializer(s.opCode)
s.toString
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sanity check, to make sure only resolvable serializers got printed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assignment is not needed anyway, fixed with a note

}.mkString("\n")
}
Expand Down
6 changes: 0 additions & 6 deletions interpreter/shared/src/main/scala/sigmastate/types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1778,12 +1778,6 @@ case class STuple(items: IndexedSeq[SType]) extends SCollection[SAny.type] {
import STuple._
override val typeCode = STuple.TupleTypeCode

/** Lazily computed value representing true | false | none.
* 0 - none, 1 - false, 2 - true
*/
@volatile
private var _isConstantSizeCode: Byte = 0.toByte

override def elemType: SAny.type = SAny

protected override def getMethods() = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ trait Exprs extends Core with Types {
// varies.

// Expressions used as statements, directly within a {block}
object StatCtx extends WsCtx(semiInference=true, arrowTypeAscriptions=false)
object StatCtx extends WsCtx(semiInference=true)
// Expressions nested within other expressions
object ExprCtx extends WsCtx(semiInference=false, arrowTypeAscriptions=true)
object ExprCtx extends WsCtx(semiInference=false)
// Expressions directly within a `val x = ...` or `def x = ...`
object FreeCtx extends WsCtx(semiInference=true, arrowTypeAscriptions=true)
object FreeCtx extends WsCtx(semiInference=true)

override def TypeExpr[_:P]: P[Value[SType]] = ExprCtx.Expr

Expand All @@ -38,7 +38,7 @@ trait Exprs extends Core with Types {

//noinspection TypeAnnotation,ForwardReference
/** Parsing context of expressions (see derived classes). */
class WsCtx(semiInference: Boolean, arrowTypeAscriptions: Boolean) {
class WsCtx(semiInference: Boolean) {

private def OneSemiMax[_:P]: P[Unit] = if (semiInference) OneNLMax else Pass
private def NoSemis[_:P]: P[Unit] = if (semiInference) NotNewline else Pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import sigmastate.interpreter.{CostedProverResult, ProverResult}
import sigma.data.RType
import org.ergoplatform.{ErgoBox, ErgoLikeContext}
import sigma.{AnyValue, Coll, SigmaDslBuilder, SigmaProp}
import sigmastate.Values.ErgoTree
import sigmastate.Values.{ErgoTree, EvaluatedValue}
import sigmastate.eval.{CostingSigmaDslBuilder, IRContext}

import scala.util.Try
import org.ergoplatform.dsl.ContractSyntax.{ErgoScript, Proposition, Token}
import sigmastate.SType

import scala.language.implicitConversions

Expand Down Expand Up @@ -49,7 +50,7 @@ trait ContractSpec {

/** Generate proof for the given `inBox`. The input box has attached guarding proposition,
* which is executed in the Context, specifically created for `inBox`.*/
def prove(inBox: InputBox, extensions: Map[Byte, AnyValue] = Map()): Try[CostedProverResult]
def prove(inBox: InputBox, extensions: Map[Byte, EvaluatedValue[_ <: SType]] = Map()): Try[CostedProverResult]
}
object ProvingParty {
def apply(name: String): ProvingParty = mkProvingParty(name)
Expand All @@ -68,7 +69,7 @@ trait ContractSpec {
trait InputBox {
def tx: TransactionCandidate
def utxoBox: OutBox
def runDsl(extensions: Map[Byte, AnyValue] = Map()): SigmaProp
def runDsl(extensions: Map[Byte, EvaluatedValue[_ <: SType]] = Map()): SigmaProp
private [dsl] def toErgoContext: ErgoLikeContext
}

Expand Down
46 changes: 23 additions & 23 deletions sc/shared/src/main/scala/scalan/GraphIRReflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ object GraphIRReflection {
mkMethod(clazz, "filter", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.WOption[Any]].filter(args(0).asInstanceOf[ctx.Ref[Any => Boolean]])
},
mkMethod(clazz, "get", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "get", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.WOption[_]].get
},
mkMethod(clazz, "isDefined", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "isDefined", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.WOption[_]].isDefined
},
mkMethod(clazz, "getOrElse", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
Expand Down Expand Up @@ -76,10 +76,10 @@ object GraphIRReflection {
mkMethod(clazz, "$bar$bar", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.SigmaProp].$bar$bar(args(0).asInstanceOf[ctx.Ref[ctx.SigmaProp]])
},
mkMethod(clazz, "isValid", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "isValid", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.SigmaProp].isValid
},
mkMethod(clazz, "propBytes", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "propBytes", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.SigmaProp].propBytes
},
mkMethod(clazz, "$amp$amp", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
Expand Down Expand Up @@ -221,26 +221,26 @@ object GraphIRReflection {
obj.asInstanceOf[ctx.AvlTree].update(args(0).asInstanceOf[ctx.Ref[ctx.Coll[(ctx.Coll[Byte], ctx.Coll[Byte])]]],
args(1).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]])
},
mkMethod(clazz, "keyLength", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "keyLength", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].keyLength
},
mkMethod(clazz, "enabledOperations", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "enabledOperations", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].enabledOperations
},
mkMethod(clazz, "updateDigest", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.AvlTree].updateDigest(args(0).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]])
},
mkMethod(clazz, "digest", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "digest", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].digest
},
mkMethod(clazz, "insert", Array[Class[_]](classOf[Base#Ref[_]], classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.AvlTree].insert(args(0).asInstanceOf[ctx.Ref[ctx.Coll[(ctx.Coll[Byte], ctx.Coll[Byte])]]],
args(1).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]])
},
mkMethod(clazz, "isRemoveAllowed", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "isRemoveAllowed", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].isRemoveAllowed
},
mkMethod(clazz, "valueLengthOpt", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "valueLengthOpt", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].valueLengthOpt
},
mkMethod(clazz, "get", Array[Class[_]](classOf[Base#Ref[_]], classOf[Base#Ref[_]])) { (obj, args) =>
Expand All @@ -254,10 +254,10 @@ object GraphIRReflection {
obj.asInstanceOf[ctx.AvlTree].contains(args(0).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]],
args(1).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]])
},
mkMethod(clazz, "isUpdateAllowed", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "isUpdateAllowed", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].isUpdateAllowed
},
mkMethod(clazz, "isInsertAllowed", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "isInsertAllowed", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].isInsertAllowed
}
)
Expand All @@ -268,22 +268,22 @@ object GraphIRReflection {
val ctx = null.asInstanceOf[SigmaLibrary] // ok! type level only
registerClassEntry(clazz,
methods = Map(
mkMethod(clazz, "value", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "value", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Box].value
},
mkMethod(clazz, "id", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "id", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Box].id
},
mkMethod(clazz, "creationInfo", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "creationInfo", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Box].creationInfo
},
mkMethod(clazz, "bytes", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "bytes", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Box].bytes
},
mkMethod(clazz, "getReg", Array[Class[_]](classOf[Base#Ref[_]], classOf[TypeDescs#Elem[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.Box].getReg(args(0).asInstanceOf[ctx.Ref[Int]])(args(1).asInstanceOf[ctx.Elem[_]])
},
mkMethod(clazz, "tokens", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "tokens", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Box].tokens
},
mkMethod(clazz, "bytesWithoutRef", Array[Class[_]]()) { (obj, args) =>
Expand Down Expand Up @@ -415,25 +415,25 @@ object GraphIRReflection {
val ctx = null.asInstanceOf[SigmaLibrary] // ok! type level only
registerClassEntry(clazz,
methods = Map(
mkMethod(clazz, "minerPk", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "minerPk", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].minerPk
},
mkMethod(clazz, "votes", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "votes", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].votes
},
mkMethod(clazz, "nBits", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "nBits", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].nBits
},
mkMethod(clazz, "version", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "version", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].version
},
mkMethod(clazz, "timestamp", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "timestamp", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].timestamp
},
mkMethod(clazz, "parentId", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "parentId", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].parentId
},
mkMethod(clazz, "height", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "height", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].height
}
)
Expand Down
1 change: 0 additions & 1 deletion sc/shared/src/main/scala/scalan/TypeDescs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package scalan
import scala.language.implicitConversions
import scala.annotation.implicitNotFound
import scala.collection.immutable.ListMap
import sigma.data.RType._

import scala.collection.mutable
import debox.cfor
Expand Down
4 changes: 0 additions & 4 deletions sc/shared/src/main/scala/scalan/primitives/Tuples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ trait Tuples extends Base { self: Scalan =>
case Tup(a, b) => (a, b)
case _ => p.elem match {
case pe: PairElem[_, _] =>
implicit val eA = pe.eFst
implicit val eB = pe.eSnd
if (cachePairs) {
if (!tuplesCache.containsKey(p)) {
tuplesCache.put(p, (First(p), Second(p)))
Expand All @@ -74,8 +72,6 @@ trait Tuples extends Base { self: Scalan =>
}

implicit def zipPair[A, B](p: (Ref[A], Ref[B])): Ref[(A, B)] = {
implicit val ea = p._1.elem
implicit val eb = p._2.elem
Tup(p._1, p._2)
}

Expand Down
29 changes: 0 additions & 29 deletions sc/shared/src/main/scala/scalan/staged/ProgramGraphs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,40 +63,11 @@ trait ProgramGraphs extends AstGraphs { self: Scalan =>
sch
}

/** Mirror all the nodes of this graph applying transformer and performing rewriting.
* @param m mirror instance to be used for mirroring of nodes
* @param rw rewriter to be tried for each new created mirrored node
* @param t transformer of symbols, to be used for substitution of symbols in the new nodes.
* @return new graph which is not necessary clone of this graph, but should be semantically
* equivalent to this graph (provided all rw rules preserve equivalence).
* If rw is identity, then the resulting graph is alpha-equivalent to this graph
* as long as t is bijection.
*/
def transform(m: Mirror, rw: Rewriter, t: Transformer): ProgramGraph = {
val t0 = mapping match {
case Nullable(mapping) => t merge mapping
case _ => t
}
val t1 = m.mirrorSymbols(t0, rw, this, scheduleIds)
val newRoots = roots map { t1(_) }
new ProgramGraph(newRoots, Nullable(t1), filterNode)
}

/** Remove transformer component of the graph. */
def withoutContext = ProgramGraph(roots, Nullable.None, filterNode)

override def toString: String = {
val mappingStr = if (mapping.isEmpty) "None" else mapping.toString
val filterNodeStr = if (filterNode.isDefined) filterNode.toString else "None"
s"ProgramGraph($roots, $mappingStr, $filterNodeStr)"
}
}

object ProgramGraph {
def transform[A](s: Ref[A], rw: Rewriter = NoRewriting, t: MapTransformer = MapTransformer.empty()): Ref[A] = {
val g = ProgramGraph(List(s), Nullable.None, Nullable.None)
val g1 = g.transform(DefaultMirror, rw, t)
g1.roots(0).asInstanceOf[Ref[A]]
}
}
}
Loading
Loading