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 #6 #973

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
59 changes: 12 additions & 47 deletions core/shared/src/main/scala/sigma/data/SigmaConstants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import sigma.util.CollectionUtil.TraversableOps // used in Scala 2.11
/** Descriptor of a constant which represents some size value.
* @tparam T type of the constant value
* @param value value of the constant
* @param id unique id of the constant
* @param description description of the constant purpose
*/
case class SizeConstant[T: Numeric](value: T, id: Short, description: String)
case class SizeConstant[T: Numeric](value: T, description: String)

/** Constants facade that provide access to the values used in sigma's logic and checks.
* All the constants are collected in a sequence.
Expand All @@ -21,82 +20,48 @@ case class SizeConstant[T: Numeric](value: T, id: Short, description: String)
*/
object SigmaConstants {

object MaxBoxSize extends SizeConstant[Int](4 * 1024, 1,
object MaxBoxSize extends SizeConstant[Int](4 * 1024,
"Box size should not be greater than provided value") {
}

object MaxTreeDepth extends SizeConstant[Int](110, 2,
object MaxTreeDepth extends SizeConstant[Int](110,
"Max tree depth should not be greater then provided value") {
}

object MaxTokens extends SizeConstant[Int](255, 3,
object MaxTokens extends SizeConstant[Int](255,
"Tokens count should not be greater than provided value") {
}

object MaxRegisters extends SizeConstant[Int](10, 4,
object MaxRegisters extends SizeConstant[Int](10,
"Registers count should not be greater than provided value") {
}

object MaxPropositionBytes extends SizeConstant[Int](4096 /*4K*/, 5,
object MaxPropositionBytes extends SizeConstant[Int](4096 /*4K*/,
"Max length of Box.propositionBytes collection") {
}

object MaxBoxSizeWithoutRefs extends SizeConstant[Int](
MaxBoxSize.value - (32/*CryptoConstants.hashLength*/ + 2/*size of Short*/), 6,
"Box size should not be greater than provided value") {
}

object MaxBigIntSizeInBytes extends SizeConstant[Long](32L, 7,
object MaxBigIntSizeInBytes extends SizeConstant[Long](32L,
"BigInt size in bytes should not be greater than provided value") {
}

object MaxSigmaPropSizeInBytes extends SizeConstant[Long](1024L, 8,
object MaxSigmaPropSizeInBytes extends SizeConstant[Long](1024L,
"SigmaProp size in bytes should not be greater than provided value") {
}

object MaxTupleLength extends SizeConstant[Int](255, 9,
object MaxTupleLength extends SizeConstant[Int](255,
"Tuple length should not be greater than provided value") {
}

object MaxHeaders extends SizeConstant[Int](10, 10,
"Headers count should not be greater than provided value") {
}

object MaxChildrenCountForAtLeastOp extends SizeConstant[Int](255, 11,
object MaxChildrenCountForAtLeastOp extends SizeConstant[Int](255,
"Max children count should not be greater than provided value") {
}

object MaxLoopLevelInCostFunction extends SizeConstant[Int](1, 13,
"Maximum allowed loop level in a cost function") {
}

object VotesArraySize extends SizeConstant[Int](3, 14,
object VotesArraySize extends SizeConstant[Int](3,
"Size of of Header.votes array") {
}

object AutolykosPowSolutionNonceArraySize extends SizeConstant[Int](8, 15,
object AutolykosPowSolutionNonceArraySize extends SizeConstant[Int](8,
"size of nonce array from Autolykos POW solution in Header.powNonce array") {
}

/** List of registered size constants with unique ids. */
val ConstTable: Seq[SizeConstant[_]] = {
val rows = Seq(
MaxBoxSize,
MaxTreeDepth,
MaxTokens,
MaxRegisters,
MaxPropositionBytes,
MaxBoxSizeWithoutRefs,
MaxBigIntSizeInBytes,
MaxSigmaPropSizeInBytes,
MaxTupleLength,
MaxHeaders,
MaxChildrenCountForAtLeastOp,
MaxLoopLevelInCostFunction,
VotesArraySize,
AutolykosPowSolutionNonceArraySize
)
require(rows.length == rows.distinctBy(_.id).length, s"Duplicate constant id in $rows")
rows
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ abstract class CoreSerializer[TFamily, T <: TFamily] extends Serializer[TFamily,
}

object CoreSerializer {
/** Max length of Box.propositionBytes collection */
val MaxPropositionSize: Int = SigmaConstants.MaxPropositionBytes.value

/** Max tree depth should not be greater then provided value */
val MaxTreeDepth: Int = SigmaConstants.MaxTreeDepth.value
Expand Down
26 changes: 1 addition & 25 deletions core/shared/src/main/scala/sigma/util/Extensions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,6 @@ object Extensions {
def ?:(whenNone: => T): T = if (opt.isDefined) opt.get else whenNone
}

implicit class ProductOps(val source: Product) extends AnyVal {
def toArray: Array[Any] = {
val arity = source.productArity
val res = new Array[Any](arity)
var i = 0
while (i < arity) {
res(i) = source.productElement(i)
i += 1
}
res
}
}

implicit class ByteBufferOps(val buf: ByteBuffer) extends AnyVal {
def toBytes: Array[Byte] = {
val res = new Array[Byte](buf.position())
Expand Down Expand Up @@ -304,18 +291,6 @@ object Extensions {
def showToString: String = toECPoint.showECPoint
}

implicit class DBufferOps[A](val buf: DBuffer[A]) extends AnyVal {
/** Sum all values in `buf` using the given Numeric. */
def sumAll(implicit n: Numeric[A]): A = {
val limit = buf.length
var result: A = n.zero
cfor(0)(_ < limit, _ + 1) { i =>
result = n.plus(result, buf.elems(i))
}
result
}
}

implicit class SigmaBooleanOps(val sb: SigmaBoolean) extends AnyVal {
/** Wraps SigmaBoolean into SigmaProp. */
def toSigmaProp: SigmaProp = CSigmaProp(sb)
Expand Down Expand Up @@ -344,4 +319,5 @@ object Extensions {
/** Extracts [[sigma.AvlTreeData]] from the AvlTree instance. */
def toAvlTreeData: AvlTreeData = tree.asInstanceOf[CAvlTree].wrappedValue
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ object ErgoLikeContext {

type Height = Int

/** Maximimum number of headers in `headers` collection of the context. */
val MaxHeaders = SigmaConstants.MaxHeaders.value

/** Copies the given context allowing also to update fields.
* NOTE: it can be used ONLY for instances of ErgoLikeContext.
* @tparam T used here to limit use of this method to only ErgoLikeContext instances
Expand Down
18 changes: 14 additions & 4 deletions interpreter/shared/src/main/scala/sigmastate/eval/CProfiler.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package sigmastate.eval

import debox.{sp, Buffer => DBuffer, Map => DMap}
import debox.{cfor, sp, Buffer => DBuffer, Map => DMap}
import sigma.ast.{CostItem, FixedCost, FixedCostItem, JitCost, SMethod, SeqCostItem, TypeBasedCostItem}
import sigma.ast.TypeCodes.LastConstantCode
import sigma.ast.syntax._
import sigma.util.Extensions.{ByteOps, DBufferOps}
import sigma.util.Extensions.ByteOps
import sigma.ast.{MethodCall, PropertyCall}
import sigma.eval.Profiler
import sigma.serialization.ValueCodes.OpCode
Expand Down Expand Up @@ -40,8 +40,18 @@ abstract class StatHolder[@sp (Long, Double) V] {
class StatCollection[@sp(Int) K, @sp(Long, Double) V]
(implicit n: Integral[V], ctK: ClassTag[K], ctV: ClassTag[V]) {

/** Sum all values in `buf` using the given Numeric. */
private def sumAll[A](buf: DBuffer[A], n: Numeric[A]): A = {
val limit = buf.length
var result: A = n.zero
cfor(0)(_ < limit, _ + 1) { i =>
result = n.plus(result, buf.elems(i))
}
result
}

private def calcAvg(buf: DBuffer[V]): V = {
n.quot(buf.sumAll, n.fromInt(buf.length))
n.quot(sumAll(buf, n), n.fromInt(buf.length))
}

// NOTE: this class is mutable so better to keep it private
Expand All @@ -58,7 +68,7 @@ class StatCollection[@sp(Int) K, @sp(Long, Double) V]
}

override def count: Int = dataPoints.length
override def sum: V = dataPoints.sumAll
override def sum: V = sumAll(dataPoints, n)
override def avg: V = calcAvg(dataPoints)

override def mean: (V, Int) = {
Expand Down
25 changes: 0 additions & 25 deletions sc/shared/src/test/scala/sigma/SigmaDslTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ class SigmaDslTesting extends AnyPropSpec
override val okMeasureOperationTime: Boolean = true
}

def checkEq2[A,B,R](f: (A, B) => R)(g: (A, B) => R): (A,B) => Unit = { (x: A, y: B) =>
val r1 = f(x, y); val r2 = g(x, y)
assert(r1.getClass == r2.getClass)
assert(r1 == r2)
}

def getArrayIndex(len: Int): Int = {
val index = Gen.choose(0, len - 1)
index.sample.get
}

/** Generate indices for an array of a given length.
* @return unordered array of indices with possibly repeated elements
Expand Down Expand Up @@ -99,10 +89,6 @@ class SigmaDslTesting extends AnyPropSpec

val LogScriptDefault: Boolean = false

val isNewVersion = new scala.util.DynamicVariable(false)

val predefScripts = Seq[String]()

/** Descriptor of the language feature.
* Each language feature is described by so called feature-function which exercises
* some specific operation under test.
Expand Down Expand Up @@ -433,17 +419,6 @@ class SigmaDslTesting extends AnyPropSpec
|""".stripMargin)
}

private def checkEqualResults(res1: Try[VerificationResult], res2: Try[VerificationResult]): Unit = {
(res1, res2) match {
case (Success((v1, c1)), Success((v2, c2))) =>
v1 shouldBe v2
case (Failure(t1), Failure(t2)) =>
rootCause(t1) shouldBe rootCause(t2)
case _ =>
res1 shouldBe res2
}
}

private def checkExpectedResult(
res: Try[VerificationResult], expectedCost: Option[Int]): Unit = {
res match {
Expand Down
Loading