Skip to content

Commit

Permalink
minimize-modules: addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aslesarenko committed Sep 11, 2023
1 parent 008d909 commit a13a03c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package sigma.kiama
package rewriting

import sigma.reflection.{Platform, RClass, RConstructor}
//import sigma.kiama.==>

/**
* Strategy-based term rewriting in the style of Stratego (http://strategoxt.org/).
Expand Down
2 changes: 2 additions & 0 deletions core/shared/src/main/scala/sigma/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ package object sigma {

/** Allows implicit resolution to find appropriate instance of ClassTag in
* the scope where RType is implicitly available.
* NOTE, this implicit is shadowed internally in some places (search for `def rtypeToClassTag`),
* hence renaming it requires changing of the shadowing methods.
*/
implicit def rtypeToClassTag[A](implicit t: RType[A]): ClassTag[A] = t.classTag

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
package sigmastate.eval

import debox.cfor
import org.ergoplatform.validation.{SigmaValidationSettings, ValidationRules}
import org.ergoplatform.{ErgoBox, SigmaConstants}
import org.ergoplatform.validation.{ValidationRules, SigmaValidationSettings}
import org.ergoplatform.{SigmaConstants, ErgoBox}
import sigma.data.OverloadHack.Overloaded1
import sigma.data.{CollOverArrayBuilder, RType}
import sigma.data.RType
import sigma.util.Extensions.BigIntegerOps
import scorex.crypto.authds.avltree.batch._
import scorex.crypto.authds.{ADDigest, ADKey, ADValue, SerializedAdProof}
import scorex.crypto.authds.{SerializedAdProof, ADDigest, ADValue, ADKey}
import scorex.crypto.hash.{Blake2b256, Digest32, Sha256}
import scorex.utils.{Ints, Longs}
import sigma.VersionContext
import scorex.utils.{Longs, Ints}
import sigmastate.SCollection.SByteArray
import sigmastate.Values.ErgoTree.EmptyConstants
import sigmastate.Values.{ConstantNode, ErgoTree, EvaluatedValue, SValue, SigmaBoolean}
import sigmastate.Values.{EvaluatedValue, SValue, ConstantNode, ErgoTree, SigmaBoolean}
import sigmastate._
import sigmastate.crypto.CryptoConstants.EcPointType
import sigmastate.crypto.DLogProtocol.ProveDlog
import sigmastate.crypto.{CryptoConstants, ProveDHTuple}
import sigmastate.crypto.{CryptoFacade, Ecp}
import sigmastate.crypto.{ProveDHTuple, CryptoConstants, Ecp, CryptoFacade}
import sigmastate.eval.Extensions._
import sigmastate.interpreter.Interpreter
import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer
import sigmastate.serialization.{GroupElementSerializer, SigmaSerializer}
import sigma._
import sigma.{VersionContext, _}

import java.math.BigInteger
import java.util.Arrays
import scala.annotation.unused
import scala.reflect.ClassTag
import scala.util.{Failure, Success}
import scala.util.{Success, Failure}

/** Interface implmented by wrappers to provide access to the underlying wrapped value. */
trait WrapperOf[T] {
Expand Down Expand Up @@ -154,7 +152,7 @@ case class CSigmaProp(sigmaTree: SigmaBoolean) extends SigmaProp with WrapperOf[
*
* @see BatchAVLVerifier
*/
class AvlTreeVerifier(startingDigest: ADDigest,
class AvlTreeVerifier private (startingDigest: ADDigest,
proof: SerializedAdProof,
override val keyLength: Int,
override val valueLengthOpt: Option[Int])
Expand All @@ -166,6 +164,12 @@ class AvlTreeVerifier(startingDigest: ADDigest,
override protected def logError(t: Throwable): Unit = {}
}
object AvlTreeVerifier {
/** Create an instance of [[AvlTreeVerifier]] for the given tree and proof.
* Both tree and proof are immutable.
* @param tree represents a tree state to verify
* @param proof proof of tree operations leading to the state digest in the tree
* @return a new verifier instance
*/
def apply(tree: AvlTree, proof: Coll[Byte]): AvlTreeVerifier = {
val treeData = tree.asInstanceOf[CAvlTree].treeData
val adProof = SerializedAdProof @@ proof.toArray
Expand Down Expand Up @@ -491,7 +495,6 @@ object CHeader {
class CostingSigmaDslBuilder extends SigmaDslBuilder { dsl =>
implicit val validationSettings: SigmaValidationSettings = ValidationRules.currentSettings

// manual fix
override val Colls: CollBuilder = sigma.Colls

override def BigInt(n: BigInteger): BigInt = CBigInt(n)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ object Evaluation {
}

/** Tries to reconstruct RType of the given value.
* If not successfull returns failure. */
* If not successfull returns failure.
* NOTE, this method is NOT used in consensus. */
def rtypeOf(value: Any): Try[RType[_]] = Try { value match {
case arr if arr.getClass.isArray =>
val itemClass = arr.getClass.getComponentType
Expand All @@ -140,7 +141,11 @@ object Evaluation {
case _: Unit => UnitType
case _: sigma.BigInt => BigIntRType
case _: GroupElement => GroupElementRType
case _: ErgoBox => ErgoBoxRType // TODO remove this RType
// TODO remove this case to allow removing of RType instances
// for ErgoBox, AvlTreeData, SigmaBoolean.
// RType describes only the types that can be put into registers, context variables and
// used as ErgoTree evaluation intermediate values.
case _: ErgoBox => ErgoBoxRType
case _: Box => BoxRType

case _: AvlTreeData => AvlTreeDataRType // TODO remove this RType
Expand Down
9 changes: 7 additions & 2 deletions interpreter/shared/src/main/scala/sigmastate/sigmastate.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import org.ergoplatform.{ErgoBox, ErgoBoxCandidate, ErgoLikeContext}
import sigma.data.{GeneralType, RType}
import sigma.data.{RType, GeneralType}
import sigmastate.Values._
import sigmastate.lang.CheckingSigmaBuilder

import scala.annotation.nowarn
import scala.reflect.classTag

package object sigmastate {
import CheckingSigmaBuilder._

/** Shadow the implicit from sigma package so it doesn't interfere with the resolution
* of ClassTags below.
*/
@nowarn private def rtypeToClassTag = ???

/** RType descriptors for predefined types used in AOTC-based interpreter. */
def rtypeToClassTag = ???

implicit val SigmaBooleanRType : RType[SigmaBoolean] = RType.fromClassTag(classTag[SigmaBoolean])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ class CollCls extends EntityObject("Coll") {
def map[A,B](xs: Ref[Coll[A]])(f: Ref[A] => Ref[B]) = { implicit val eA = unlift(xs.elem); xs.map(fun(f))}
}

// manual fix: CollIso, collIso

// familyElem
class CollElem[A, To <: Coll[A]](implicit _eA: Elem[A])
extends EntityElem1[A, To, Coll](_eA, container[Coll]) {
Expand All @@ -354,8 +352,6 @@ class CollCls extends EntityObject("Coll") {
implicit final def collElement[A](implicit eA: Elem[A]): Elem[Coll[A]] =
cachedElemByClass(eA)(RClass(classOf[CollElem[A, Coll[A]]]))

// manual fix: ViewColl

object CollMethods {
object length {
def unapply(d: Def[_]): Nullable[Ref[Coll[A]] forSome {type A}] = d match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,13 @@ object SigmaProp extends EntityObject("SigmaProp") {
true, false, element[Coll[Byte]]))
}

// manual fix &&
override def &&(other: Ref[SigmaProp]): Ref[SigmaProp] = {
asRep[SigmaProp](mkMethodCall(self,
SigmaPropClass.getMethod("$amp$amp", classOf[Sym]),
Array[AnyRef](other),
true, false, element[SigmaProp]))
}

// manual fix ||
override def ||(other: Ref[SigmaProp]): Ref[SigmaProp] = {
asRep[SigmaProp](mkMethodCall(self,
SigmaPropClass.getMethod("$bar$bar", classOf[Sym]),
Expand Down Expand Up @@ -486,15 +484,13 @@ object SigmaProp extends EntityObject("SigmaProp") {
true, true, element[Coll[Byte]]))
}

// manual fix &&
def &&(other: Ref[SigmaProp]): Ref[SigmaProp] = {
asRep[SigmaProp](mkMethodCall(source,
SigmaPropClass.getMethod("$amp$amp", classOf[Sym]),
Array[AnyRef](other),
true, true, element[SigmaProp]))
}

// manual fix ||
def ||(other: Ref[SigmaProp]): Ref[SigmaProp] = {
asRep[SigmaProp](mkMethodCall(source,
SigmaPropClass.getMethod("$bar$bar", classOf[Sym]),
Expand Down
Empty file.

0 comments on commit a13a03c

Please sign in to comment.