Skip to content

Commit

Permalink
removing unused code #1
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Dec 18, 2023
1 parent 9f372c5 commit 46e9daf
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 55 deletions.
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
}.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
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
7 changes: 2 additions & 5 deletions sc/shared/src/main/scala/sigmastate/eval/GraphBuilding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext =>
import Context._
import GroupElement._
import Header._
import Liftables._
import PreHeader._
import SigmaDslBuilder._
import SigmaProp._
Expand Down Expand Up @@ -173,7 +172,7 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext =>
case ThunkForce(Def(ThunkDef(root, sch))) if sch.isEmpty => root

// Rule: l.isValid op Thunk {... root} => (l op TrivialSigma(root)).isValid
case ApplyBinOpLazy(op, SigmaM.isValid(l), Def(ThunkDef(root, sch))) if root.elem == BooleanElement =>
case ApplyBinOpLazy(op, SigmaM.isValid(l), Def(ThunkDef(root, _))) if root.elem == BooleanElement =>
// don't need new Thunk because sigma logical ops always strict
val r = asRep[SigmaProp](sigmaDslBuilder.sigmaProp(asRep[Boolean](root)))
val res = if (op == And)
Expand Down Expand Up @@ -630,9 +629,7 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext =>
checkTupleType(IR)(eTuple)
eTuple match {
case pe: PairElem[a,b] =>
assert(fieldIndex == 1 || fieldIndex == 2, s"Invalid field index $fieldIndex of the pair ${tup}: $pe")
implicit val ea = pe.eFst
implicit val eb = pe.eSnd
assert(fieldIndex == 1 || fieldIndex == 2, s"Invalid field index $fieldIndex of the pair $tup: $pe")
val pair = asRep[(a,b)](tup)
val res = if (fieldIndex == 1) pair._1 else pair._2
res
Expand Down
6 changes: 3 additions & 3 deletions sc/shared/src/main/scala/sigmastate/eval/TreeBuilding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ trait TreeBuilding extends SigmaLibrary { IR: IRContext =>
val colTpe = col.tpe
val method = SCollection.methods.find(_.name == m.getName).getOrElse(error(s"unknown method Coll.${m.getName}"))
val typeSubst = (method, args) match {
case (mth @ SCollection.FlatMapMethod, Seq(f)) =>
case (_ @ SCollection.FlatMapMethod, Seq(f)) =>
val typeSubst = Map(SCollection.tOV -> f.asFunc.tpe.tRange.asCollection.elemType)
typeSubst
case (mth @ SCollection.ZipMethod, Seq(coll)) =>
case (_ @ SCollection.ZipMethod, Seq(coll)) =>
val typeSubst = Map(SCollection.tOV -> coll.asCollection[SType].tpe.elemType)
typeSubst
case (mth, _) => Terms.EmptySubst
case (_, _) => Terms.EmptySubst
}
val specMethod = method.withConcreteTypes(typeSubst + (SCollection.tIV -> colTpe.elemType))
builder.mkMethodCall(col, specMethod, args.toIndexedSeq, Map())
Expand Down
4 changes: 1 addition & 3 deletions sc/shared/src/main/scala/sigmastate/lang/SigmaCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import sigmastate.lang.SigmaPredef.PredefinedFuncRegistry
import sigmastate.lang.Terms.MethodCall
import sigmastate.lang.syntax.ParserException
import sigmastate.utxo._
import sigmastate.{Exponentiate, MultiplyGroup, SCollection, SGlobal, SGroupElement, SType, STypeVar, Xor}
import sigmastate.{Exponentiate, MultiplyGroup, SCollection, SGlobal, SGroupElement, SType, Xor}

/**
* @param networkPrefix network prefix to decode an ergo address from string (PK op)
Expand All @@ -33,9 +33,7 @@ case class CompilerSettings(
/** Result of ErgoScript source code compilation.
* @param env compiler environment used to compile the code
* @param code ErgoScript source code
* @param calcF graph obtained by using old AOT costing based compiler
* @param compiledGraph graph obtained by using new [[GraphBuilding]]
* @param calcTree ErgoTree expression obtained from calcF graph.
* @param buildTree ErgoTree expression obtained from graph created by [[GraphBuilding]]
*/
case class CompilerResult[Ctx <: IRContext](
Expand Down
6 changes: 2 additions & 4 deletions sc/shared/src/main/scala/sigmastate/lang/SigmaTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class SigmaTyper(val builder: SigmaBuilder,
* Rewrite tree to typed tree. Checks constituent names and types. Uses
* the env map to resolve bound variables and their types.
*/
def assignType(env: Map[String, SType],
bound: SValue,
expected: Option[SType] = None): SValue = ( bound match {
def assignType(env: Map[String, SType], bound: SValue): SValue = ( bound match {
case Block(bs, res) =>
var curEnv = env
val bs1 = ArrayBuffer[Val]()
Expand Down Expand Up @@ -212,7 +210,7 @@ class SigmaTyper(val builder: SigmaBuilder,
if (args.length != argTypes.length)
error(s"Invalid argument type of application $app: invalid number of arguments", app.sourceContext)
val typedArgs = args.zip(argTypes).map {
case (arg, expectedType) => assignType(env, arg, Some(expectedType))
case (arg, expectedType) => assignType(env, arg)
}
val adaptedTypedArgs = (new_f, typedArgs) match {
case (AllOfFunc.sym | AnyOfFunc.sym, _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import debox.cfor
import sigmastate.exceptions.SerializerException
import scala.collection.compat.immutable.ArraySeq
import scala.collection.mutable
import fastparse.{Parsed, parse}
import sigmastate.serialization.SigmaSerializer
import sigmastate.serialization.DataSerializer
import sigmastate.serialization.ErgoTreeSerializer
Expand Down
4 changes: 1 addition & 3 deletions sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package org.ergoplatform.sdk

import scorex.utils.Ints

import java.util

object ErgoId {
/** Creates a new ErgoId decoding it from the given hex string. */
def create(base16Str: String) = new ErgoId(JavaHelpers.decodeStringToBytes(base16Str))
Expand All @@ -17,7 +15,7 @@ class ErgoId(val _idBytes: Array[Byte]) {
/** Extracts underlying byte array with id bytes. */
def getBytes = _idBytes

override def hashCode =
override def hashCode: Int =
if (_idBytes != null && _idBytes.length >= 4) Ints.fromByteArray(_idBytes)
else java.util.Arrays.hashCode(_idBytes)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.ergoplatform.sdk

import debox.cfor

import java.util

/**
* Encapsulates secret array of characters (char[]) with proper equality.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.ergoplatform.sdk.wallet.secrets

import org.ergoplatform.sdk.wallet.Constants
import scorex.util.serialization.{Reader, Writer}
import sigmastate.serialization.SigmaSerializer
import sigmastate.utils.{SigmaByteReader, SigmaByteWriter}

Expand Down

0 comments on commit 46e9daf

Please sign in to comment.