diff --git a/common/shared/src/main/scala/sigma/CollsOverArrays.scala b/common/shared/src/main/scala/sigma/CollsOverArrays.scala index cbc8bc7bdf..7d57c8a4fb 100644 --- a/common/shared/src/main/scala/sigma/CollsOverArrays.scala +++ b/common/shared/src/main/scala/sigma/CollsOverArrays.scala @@ -1,6 +1,5 @@ package sigma -import sigma.core._ import sigma.util.CollectionUtil import sigma.core.RType import debox.Buffer @@ -245,8 +244,8 @@ class PairOfCols[@specialized L, @specialized R](val ls: Coll[L], val rs: Coll[R }) override def hashCode() = ls.hashCode() * 41 + rs.hashCode() - @inline implicit def tL = ls.tItem - @inline implicit def tR = rs.tItem + @inline implicit def tL: RType[L] = ls.tItem + @inline implicit def tR: RType[R] = rs.tItem override lazy val tItem: RType[(L, R)] = { RType.pairRType(tL, tR) diff --git a/common/shared/src/main/scala/sigma/core/RType.scala b/common/shared/src/main/scala/sigma/core/RType.scala index 2fbdb43454..ead1968c09 100644 --- a/common/shared/src/main/scala/sigma/core/RType.scala +++ b/common/shared/src/main/scala/sigma/core/RType.scala @@ -30,12 +30,12 @@ object RType { @inline def asType[T](t: RType[_]): RType[T] = t.asInstanceOf[RType[T]] def fromClassTag[A](ctA: ClassTag[A]): RType[A] = (ctA match { - case ClassTag.Boolean => BooleanType - case ClassTag.Byte => ByteType - case ClassTag.Short => ShortType - case ClassTag.Int => IntType - case ClassTag.Long => LongType - case ClassTag.Unit => UnitType + case ClassTag.Boolean => sigma.BooleanType + case ClassTag.Byte => sigma.ByteType + case ClassTag.Short => sigma.ShortType + case ClassTag.Int => sigma.IntType + case ClassTag.Long => sigma.LongType + case ClassTag.Unit => sigma.UnitType case _ => GeneralType[A](ctA) }).asInstanceOf[RType[A]] @@ -62,15 +62,6 @@ object RType { override def name: String = classTag.toString() } - val AnyType : RType[Any] = GeneralType[Any] (ClassTag.Any) - - implicit val BooleanType : RType[Boolean] = PrimitiveType[Boolean] (ClassTag.Boolean, Array.emptyBooleanArray) - implicit val ByteType : RType[Byte] = PrimitiveType[Byte] (ClassTag.Byte, Array.emptyByteArray) - implicit val ShortType : RType[Short] = PrimitiveType[Short] (ClassTag.Short, Array.emptyShortArray) - implicit val IntType : RType[Int] = PrimitiveType[Int] (ClassTag.Int, Array.emptyIntArray) - implicit val LongType : RType[Long] = PrimitiveType[Long] (ClassTag.Long, Array.emptyLongArray) - implicit val UnitType : RType[Unit] = PrimitiveType[Unit] (ClassTag.Unit, Array[Unit]()(ClassTag.Unit)) - implicit case object StringType extends RType[String] { override def classTag: ClassTag[String] = ClassTag[String](classOf[String]) override def name: String = "String" diff --git a/common/shared/src/main/scala/sigma/TupleType.scala b/common/shared/src/main/scala/sigma/core/TupleType.scala similarity index 94% rename from common/shared/src/main/scala/sigma/TupleType.scala rename to common/shared/src/main/scala/sigma/core/TupleType.scala index abe91608cb..ad16ec59d5 100644 --- a/common/shared/src/main/scala/sigma/TupleType.scala +++ b/common/shared/src/main/scala/sigma/core/TupleType.scala @@ -1,6 +1,6 @@ -package sigma +package sigma.core -import sigma.core.RType +import sigma.TupleData import sigma.core.RType.SomeType import sigma.util.CollectionUtil diff --git a/common/shared/src/main/scala/sigma/core/package.scala b/common/shared/src/main/scala/sigma/core/package.scala index e1b214c2b6..81091f0387 100644 --- a/common/shared/src/main/scala/sigma/core/package.scala +++ b/common/shared/src/main/scala/sigma/core/package.scala @@ -1,5 +1,6 @@ package sigma +import scala.annotation.nowarn import scala.reflect.classTag /** Contains cores definitions which serves as a basis for [[sigma]] package implementations. */ @@ -7,7 +8,7 @@ package object core { /** Shadow the implicit from sigma package so it doesn't interfere with the resolution * of ClassTags below. */ - private def rtypeToClassTag = ??? + @nowarn private def rtypeToClassTag = ??? val BigIntClassTag = classTag[BigInt] val GroupElementClassTag = classTag[GroupElement] diff --git a/common/shared/src/main/scala/sigma/package.scala b/common/shared/src/main/scala/sigma/package.scala index b0c8ce9022..0c0bab03c1 100644 --- a/common/shared/src/main/scala/sigma/package.scala +++ b/common/shared/src/main/scala/sigma/package.scala @@ -1,6 +1,6 @@ import sigma.core._ -import sigma.core.RType.{GeneralType, SomeType} +import sigma.core.RType.{GeneralType, PrimitiveType, SomeType} import scala.reflect.ClassTag @@ -11,6 +11,20 @@ package object sigma { /** Forces reflection data initialization */ val coreLibReflection = CoreLibReflection + val AnyType: RType[Any] = GeneralType[Any](ClassTag.Any) + + implicit val BooleanType: RType[Boolean] = PrimitiveType[Boolean](ClassTag.Boolean, Array.emptyBooleanArray) + + implicit val ByteType : RType[Byte] = PrimitiveType[Byte](ClassTag.Byte, Array.emptyByteArray) + + implicit val ShortType : RType[Short] = PrimitiveType[Short](ClassTag.Short, Array.emptyShortArray) + + implicit val IntType : RType[Int] = PrimitiveType[Int](ClassTag.Int, Array.emptyIntArray) + + implicit val LongType : RType[Long] = PrimitiveType[Long](ClassTag.Long, Array.emptyLongArray) + + implicit val UnitType : RType[Unit] = PrimitiveType[Unit](ClassTag.Unit, Array[Unit]()(ClassTag.Unit)) + implicit val BigIntRType: RType[BigInt] = GeneralType(BigIntClassTag) implicit val GroupElementRType: RType[GroupElement] = GeneralType(GroupElementClassTag) implicit val SigmaPropRType: RType[SigmaProp] = GeneralType(SigmaPropClassTag) diff --git a/interpreter/js/src/main/scala/sigmastate/crypto/Platform.scala b/interpreter/js/src/main/scala/sigmastate/crypto/Platform.scala index 538b14348b..3786e233ea 100644 --- a/interpreter/js/src/main/scala/sigmastate/crypto/Platform.scala +++ b/interpreter/js/src/main/scala/sigmastate/crypto/Platform.scala @@ -244,7 +244,7 @@ object Platform { */ def isCorrectType[T <: SType](value: Any, tpe: T): Boolean = value match { case c: Coll[_] => tpe match { - case STuple(items) => c.tItem == RType.AnyType && c.length == items.length + case STuple(items) => c.tItem == sigma.AnyType && c.length == items.length case tpeColl: SCollection[_] => true case _ => sys.error(s"Collection value $c has unexpected type $tpe") } diff --git a/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala b/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala index 1c6d822f3a..1c5c63b197 100644 --- a/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala +++ b/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala @@ -5,7 +5,6 @@ import org.bouncycastle.crypto.ec.CustomNamedCurves import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator import org.bouncycastle.crypto.params.KeyParameter import org.bouncycastle.math.ec.{ECCurve, ECFieldElement, ECPoint} -import sigma.core.RType import java.math.BigInteger import sigmastate._ @@ -174,7 +173,7 @@ object Platform { */ def isCorrectType[T <: SType](value: Any, tpe: T): Boolean = value match { case c: Coll[_] => tpe match { - case STuple(items) => c.tItem == RType.AnyType && c.length == items.length + case STuple(items) => c.tItem == sigma.AnyType && c.length == items.length case _: SCollection[_] => true case _ => sys.error(s"Collection value $c has unexpected type $tpe") } diff --git a/interpreter/shared/src/main/scala/sigmastate/DataValueComparer.scala b/interpreter/shared/src/main/scala/sigmastate/DataValueComparer.scala index 194e545310..f625ccd23c 100644 --- a/interpreter/shared/src/main/scala/sigmastate/DataValueComparer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/DataValueComparer.scala @@ -2,15 +2,13 @@ package sigmastate import sigma.core.{AVHashMap, Nullable, RType} import debox.{cfor, sp} -import sigma.core.RType._ import sigmastate.Values.SigmaBoolean import sigmastate.crypto.DLogProtocol.ProveDlog import sigmastate.crypto.ProveDHTuple import sigmastate.eval.SigmaDsl import sigmastate.crypto.CryptoConstants.EcPointType import sigmastate.interpreter.{ErgoTreeEvaluator, NamedDesc, OperationCostInfo} -import sigma.{AvlTree, AvlTreeRType, BigInt, BigIntRType, Box, BoxRType, GroupElement, GroupElementRType, Header, HeaderRType, PreHeader, PreHeaderRType, SigmaProp} -import sigma.{Coll, CollOverArray, PairOfCols} +import sigma._ /** Implementation of data equality for two arbitrary ErgoTree data types. * @see [[DataValueComparer.equalDataValues]] diff --git a/interpreter/shared/src/main/scala/sigmastate/Values.scala b/interpreter/shared/src/main/scala/sigmastate/Values.scala index 366581d5e5..bc15b54df0 100644 --- a/interpreter/shared/src/main/scala/sigmastate/Values.scala +++ b/interpreter/shared/src/main/scala/sigmastate/Values.scala @@ -848,7 +848,7 @@ object Values { override lazy val value = { val xs = items.cast[EvaluatedValue[SAny.type]].map(_.value) - Colls.fromArray(xs.toArray(SAny.classTag.asInstanceOf[ClassTag[SAny.WrappedType]]))(RType.AnyType) + Colls.fromArray(xs.toArray(SAny.classTag.asInstanceOf[ClassTag[SAny.WrappedType]]))(sigma.AnyType) } protected final override def eval(env: DataEnv)(implicit E: ErgoTreeEvaluator): Any = { diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala b/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala index daf520a0f1..0dd9f9cf0b 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala @@ -1,7 +1,7 @@ package sigmastate.eval import org.ergoplatform._ -import sigma.core.{CollType, RType} +import sigma.core.{CollType, RType, TupleType} import sigma.core.RType._ import sigmastate.SType._ import sigmastate.Values.SigmaBoolean @@ -156,7 +156,7 @@ object Evaluation { /** Convert SigmaDsl representation of tuple to ErgoTree serializable representation. */ def fromDslTuple(value: Any, tupleTpe: STuple): Coll[Any] = value match { case t: Tuple2[_,_] => TupleColl(t._1, t._2) - case a: Coll[Any]@unchecked if a.tItem == RType.AnyType => a + case a: Coll[Any]@unchecked if a.tItem == sigma.AnyType => a case _ => sys.error(s"Cannot execute fromDslTuple($value, $tupleTpe)") } diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/package.scala b/interpreter/shared/src/main/scala/sigmastate/eval/package.scala index cee9117304..21a8240cf4 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/package.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/package.scala @@ -31,7 +31,7 @@ package object eval { * Such long tuples are represented as Coll[Any]. * This representaion of tuples is different from representation of pairs (x, y), * where Tuple2 type is used instead of Coll. */ - def TupleColl(items: Any*): Coll[Any] = Colls.fromItems(items:_*)(RType.AnyType) + def TupleColl(items: Any*): Coll[Any] = Colls.fromItems(items:_*)(sigma.AnyType) trait BaseDigestColl extends TaggedType[Coll[Byte]] diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala index b6e6c2ea57..30660093ea 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala @@ -126,7 +126,7 @@ object DataSerializer { val arr = tuple.items.map { t => deserialize(t, r) }.toArray[Any] - val coll = Colls.fromArray(arr)(RType.AnyType) + val coll = Colls.fromArray(arr)(sigma.AnyType) Evaluation.toDslTuple(coll, tuple) case t => CheckSerializableTypeCode(t.typeCode) @@ -147,7 +147,7 @@ object DataSerializer { case tTup: STuple if tTup.items.length == 2 => Evaluation.stypeToRType(tpeElem) case _: STuple => - collRType(RType.AnyType) + collRType(sigma.AnyType) case _ => Evaluation.stypeToRType(tpeElem) }).asInstanceOf[RType[T#WrappedType]] diff --git a/interpreter/shared/src/test/scala/sigmastate/serialization/ConstantSerializerSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/serialization/ConstantSerializerSpecification.scala index 573c6ea261..92813e44cf 100644 --- a/interpreter/shared/src/test/scala/sigmastate/serialization/ConstantSerializerSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/serialization/ConstantSerializerSpecification.scala @@ -27,7 +27,7 @@ class ConstantSerializerSpecification extends TableSerializationSpecification { implicit val tT = Evaluation.stypeToRType(tpe) implicit val tag = tT.classTag forAll { xs: Array[T#WrappedType] => - implicit val tAny = RType.AnyType + implicit val tAny = sigma.AnyType roundTripTest(Constant[SCollection[T]](xs.toColl, SCollection(tpe))) roundTripTest(Constant[SType](xs.toColl.map(x => (x, x)).asWrappedType, SCollection(STuple(tpe, tpe)))) // pairs are special case val triples = xs.toColl.map(x => TupleColl(x, x, x)).asWrappedType @@ -49,7 +49,7 @@ class ConstantSerializerSpecification extends TableSerializationSpecification { implicit val wWrapped = wrappedTypeGen(tpe) implicit val tT = Evaluation.stypeToRType(tpe) @nowarn implicit val tag = tT.classTag - implicit val tAny: RType[Any] = RType.AnyType + implicit val tAny: RType[Any] = sigma.AnyType forAll { in: (T#WrappedType, T#WrappedType) => val (x,y) = (in._1, in._2) roundTripTest(Constant[SType]((x, y).asWrappedType, STuple(tpe, tpe))) diff --git a/interpreter/shared/src/test/scala/sigmastate/serialization/DataSerializerSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/serialization/DataSerializerSpecification.scala index d10b9396ff..1dee51c26f 100644 --- a/interpreter/shared/src/test/scala/sigmastate/serialization/DataSerializerSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/serialization/DataSerializerSpecification.scala @@ -51,7 +51,7 @@ class DataSerializerSpecification extends SerializationSpecification { implicit val wWrapped = wrappedTypeGen(tpe) implicit val tT = Evaluation.stypeToRType(tpe) implicit val tagT = tT.classTag - implicit val tAny = RType.AnyType + implicit val tAny = sigma.AnyType forAll { xs: Array[T#WrappedType] => roundtrip[SCollection[T]](xs.toColl, SCollection(tpe)) roundtrip[SType](xs.toColl.map(x => (x, x)).asWrappedType, SCollection(STuple(tpe, tpe))) @@ -78,7 +78,7 @@ class DataSerializerSpecification extends SerializationSpecification { def testTuples[T <: SType](tpe: T) = { implicit val wWrapped = wrappedTypeGen(tpe) @nowarn implicit val tag = tpe.classTag[T#WrappedType] - implicit val tAny: RType[Any] = RType.AnyType + implicit val tAny: RType[Any] = sigma.AnyType forAll { in: (T#WrappedType, T#WrappedType) => val (x,y) = (in._1, in._2) roundtrip[SType]((x, y).asWrappedType, STuple(tpe, tpe)) @@ -107,7 +107,7 @@ class DataSerializerSpecification extends SerializationSpecification { property("Should check limits and fail") { val len = 0xFFFF + 1 - val tup = SigmaDsl.Colls.replicate(len, 1.asInstanceOf[Any])(RType.AnyType) + val tup = SigmaDsl.Colls.replicate(len, 1.asInstanceOf[Any])(sigma.AnyType) assertExceptionThrown({ val w = SigmaSerializer.startWriter() DataSerializer.serialize(tup.asWrappedType, STuple(Array.fill(len)(SInt)), w) diff --git a/sc/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala b/sc/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala index 06cbdd64a5..8568e6c1db 100644 --- a/sc/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala +++ b/sc/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala @@ -6,6 +6,7 @@ import scalan.Scalan import scalan.core.ScalaNameUtil import sigma.util.{FileUtil, ProcessUtil, StringUtil} +import scala.annotation.unused import scala.collection.immutable.StringOps // TODO implement this outside of the cake @@ -21,7 +22,7 @@ class GraphVizExport[Ctx <: Scalan](val scalan: Ctx) { // TODO it would be better to have nodeColor(elem: Elem[_], optDef: Option[Def[_]]) to // avoid looking up definition, but this leads to ClassFormatError (likely Scala bug) - protected def nodeColor(td: TypeDesc, d: Def[_])(implicit config: GraphVizConfig): String = d match { + protected def nodeColor(td: TypeDesc, d: Def[_])(implicit @unused config: GraphVizConfig): String = d match { case _ => nodeColor(td) } @@ -137,7 +138,7 @@ class GraphVizExport[Ctx <: Scalan](val scalan: Ctx) { case _ => x.toString } - private def emitDepEdges(sym: Sym, rhs: Def[_])(implicit stream: PrintWriter, config: GraphVizConfig) = { + private def emitDepEdges(sym: Sym, rhs: Def[_])(implicit stream: PrintWriter, @unused config: GraphVizConfig) = { val (deps, lambdaVars) = rhs match { case l: Lambda[_, _] => lambdaDeps(l) case _ => (rhs.deps.toList, Nil) diff --git a/sc/jvm/src/test/scala/sigmastate/helpers/SigmaPPrintSpec.scala b/sc/jvm/src/test/scala/sigmastate/helpers/SigmaPPrintSpec.scala index 2b39d8d2af..38feb207b6 100644 --- a/sc/jvm/src/test/scala/sigmastate/helpers/SigmaPPrintSpec.scala +++ b/sc/jvm/src/test/scala/sigmastate/helpers/SigmaPPrintSpec.scala @@ -42,8 +42,8 @@ class SigmaPPrintSpec extends SigmaDslTesting { test(SCollectionType(SBoolean), "SBooleanArray") test(STuple(Vector(SBoolean, SInt)), "SPair(SBoolean, SInt)") - test(RType.BooleanType, "RType.BooleanType") - test(CollType(RType.ByteType), "CollType(RType.ByteType)") + test(sigma.BooleanType, "RType.BooleanType") + test(CollType(sigma.ByteType), "CollType(RType.ByteType)") // exception handlers test(new ArithmeticException("msg"), "new ArithmeticException(\"msg\")") diff --git a/sc/jvm/src/test/scala/special/collections/BenchmarkGens.scala b/sc/jvm/src/test/scala/special/collections/BenchmarkGens.scala index 74684194be..3819772202 100644 --- a/sc/jvm/src/test/scala/special/collections/BenchmarkGens.scala +++ b/sc/jvm/src/test/scala/special/collections/BenchmarkGens.scala @@ -14,11 +14,4 @@ trait BenchmarkGens extends CollGens { suite: Bench[Double] => val arrays = ranges.map { case (r, i) => (r.toArray, i) } val colls = arrays.map { case (arr, i) => (builder.fromArray(arr), i) } - - private val config = Seq[KeyValue]( - exec.minWarmupRuns -> 5, - exec.maxWarmupRuns -> 10, - exec.benchRuns -> 30, - exec.requireGC -> true - ) } diff --git a/sc/shared/src/main/scala/scalan/TypeDescs.scala b/sc/shared/src/main/scala/scalan/TypeDescs.scala index a84533c445..6449861d11 100644 --- a/sc/shared/src/main/scala/scalan/TypeDescs.scala +++ b/sc/shared/src/main/scala/scalan/TypeDescs.scala @@ -361,17 +361,17 @@ abstract class TypeDescs extends Base { self: Scalan => } /** Type descriptor for `Any`, cannot be used implicitly. */ - val AnyElement: Elem[Any] = new BaseElemLiftable[Any](null, AnyType) + val AnyElement: Elem[Any] = new BaseElemLiftable[Any](null, sigma.AnyType) /** Predefined Lazy value saved here to be used in hotspot code. */ val LazyAnyElement = Lazy(AnyElement) - implicit val BooleanElement: Elem[Boolean] = new BaseElemLiftable(false, BooleanType) - implicit val ByteElement: Elem[Byte] = new BaseElemLiftable(0.toByte, ByteType) - implicit val ShortElement: Elem[Short] = new BaseElemLiftable(0.toShort, ShortType) - implicit val IntElement: Elem[Int] = new BaseElemLiftable(0, IntType) - implicit val LongElement: Elem[Long] = new BaseElemLiftable(0L, LongType) - implicit val UnitElement: Elem[Unit] = new BaseElemLiftable((), UnitType) + implicit val BooleanElement: Elem[Boolean] = new BaseElemLiftable(false, sigma.BooleanType) + implicit val ByteElement: Elem[Byte] = new BaseElemLiftable(0.toByte, sigma.ByteType) + implicit val ShortElement: Elem[Short] = new BaseElemLiftable(0.toShort, sigma.ShortType) + implicit val IntElement: Elem[Int] = new BaseElemLiftable(0, sigma.IntType) + implicit val LongElement: Elem[Long] = new BaseElemLiftable(0L, sigma.LongType) + implicit val UnitElement: Elem[Unit] = new BaseElemLiftable((), sigma.UnitType) implicit val StringElement: Elem[String] = new BaseElemLiftable("", StringType) /** Implicitly defines element type for pairs. */ diff --git a/sc/shared/src/main/scala/scalan/primitives/Equal.scala b/sc/shared/src/main/scala/scalan/primitives/Equal.scala index e2a35acf15..4d64e94383 100644 --- a/sc/shared/src/main/scala/scalan/primitives/Equal.scala +++ b/sc/shared/src/main/scala/scalan/primitives/Equal.scala @@ -2,6 +2,8 @@ package scalan.primitives import scalan.{Base, Scalan} +import scala.annotation.unused + trait Equal extends Base { self: Scalan => /** Binary operation representing structural equality between arguments. */ case class Equals[A: Elem]() extends BinOp[A, Boolean]("==") { @@ -13,11 +15,11 @@ trait Equal extends Base { self: Scalan => override def applySeq(x: A, y: A): Boolean = !equalValues[A](x, y) } - protected def equalValues[A](x: Any, y: Any)(implicit eA: Elem[A]) = x == y + protected def equalValues[A](x: Any, y: Any)(implicit @unused eA: Elem[A]) = x == y /** Extension methods to construct ApplyBinOp nodes */ implicit class EqualOps[A](x: Ref[A]) { - implicit private val eA = x.elem + implicit private val eA: Elem[A] = x.elem /** Apply Equals binary operation and return Ref to ApplyBinOp node. */ def ===(y: Ref[A]): Ref[Boolean] = Equals[A].apply(x, y) diff --git a/sc/shared/src/test/scala/sigma/SigmaDslSpecification.scala b/sc/shared/src/test/scala/sigma/SigmaDslSpecification.scala index 343ad5396b..6a90429e20 100644 --- a/sc/shared/src/test/scala/sigma/SigmaDslSpecification.scala +++ b/sc/shared/src/test/scala/sigma/SigmaDslSpecification.scala @@ -9716,10 +9716,10 @@ class SigmaDslSpecification extends SigmaDslTesting }, changedFeature( { (x: (Coll[Byte], Int)) => - SigmaDsl.substConstants(x._1, Coll[Int](x._2), Coll[Any](SigmaDsl.sigmaProp(false))(RType.AnyType)) + SigmaDsl.substConstants(x._1, Coll[Int](x._2), Coll[Any](SigmaDsl.sigmaProp(false))(sigma.AnyType)) }, { (x: (Coll[Byte], Int)) => - SigmaDsl.substConstants(x._1, Coll[Int](x._2), Coll[Any](SigmaDsl.sigmaProp(false))(RType.AnyType)) + SigmaDsl.substConstants(x._1, Coll[Int](x._2), Coll[Any](SigmaDsl.sigmaProp(false))(sigma.AnyType)) }, "{ (x: (Coll[Byte], Int)) => substConstants[Any](x._1, Coll[Int](x._2), Coll[Any](sigmaProp(false))) }", FuncValue( diff --git a/sc/shared/src/test/scala/sigmastate/helpers/SigmaPPrint.scala b/sc/shared/src/test/scala/sigmastate/helpers/SigmaPPrint.scala index 1193fc7db8..a9f7997d63 100644 --- a/sc/shared/src/test/scala/sigmastate/helpers/SigmaPPrint.scala +++ b/sc/shared/src/test/scala/sigmastate/helpers/SigmaPPrint.scala @@ -146,7 +146,7 @@ object SigmaPPrint extends PPrinter { case Some(v) => Tree.Apply("Some", treeifyMany(v)) - case coll: Coll[Byte @unchecked] if coll.tItem == RType.ByteType => + case coll: Coll[Byte @unchecked] if coll.tItem == sigma.ByteType => val hexString = ErgoAlgos.encode(coll) Tree.Apply("Helpers.decodeBytes", treeifyMany(hexString)) diff --git a/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala b/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala index f6266cf285..129f096d85 100644 --- a/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala +++ b/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala @@ -5,13 +5,15 @@ import org.ergoplatform._ import scorex.util.encode.Base58 import sigmastate.Values._ import sigmastate._ +import sigmastate.exceptions.{GraphBuildingException, InvalidArguments, TyperException} import sigmastate.helpers.CompilerTestingCommons import sigmastate.interpreter.Interpreter.ScriptEnv -import sigmastate.lang.Terms.{Apply, Ident, Lambda, MethodCall, ZKProofBlock} -import sigmastate.exceptions.{GraphBuildingException, InvalidArguments, TyperException} +import sigmastate.lang.Terms.{Apply, MethodCall, ZKProofBlock} import sigmastate.serialization.ValueSerializer import sigmastate.serialization.generators.ObjectGenerators -import sigmastate.utxo.{ByIndex, ExtractAmount, GetVar, SelectField} +import sigmastate.utxo.{ByIndex, ExtractAmount, GetVar} + +import scala.annotation.unused class SigmaCompilerTest extends CompilerTestingCommons with LangTests with ObjectGenerators { import CheckingSigmaBuilder._ @@ -22,11 +24,11 @@ class SigmaCompilerTest extends CompilerTestingCommons with LangTests with Objec private def comp(env: ScriptEnv, x: String): Value[SType] = compile(env, x) private def comp(x: String): Value[SType] = compile(env, x) - private def testMissingCosting(script: String, expected: SValue): Unit = { + private def testMissingCosting(script: String, @unused expected: SValue): Unit = { an [GraphBuildingException] should be thrownBy comp(env, script) } - private def testMissingCostingWOSerialization(script: String, expected: SValue): Unit = { + private def testMissingCostingWOSerialization(script: String, @unused expected: SValue): Unit = { an [GraphBuildingException] should be thrownBy comp(env, script) } diff --git a/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala b/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala index 35c21b5c82..5a1b93fdf5 100644 --- a/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala +++ b/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala @@ -59,7 +59,7 @@ class SigmaTyperTest extends AnyPropSpec sourceContext.line shouldBe expectedLine sourceContext.column shouldBe expectedCol true - case pe: ParserException => true + case _: ParserException => true case t => throw t }) } diff --git a/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala index 2d8d62380e..004564cf9f 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala @@ -338,7 +338,7 @@ class BasicOpsSpecification extends CompilerTestingCommons val dataVar = (lastExtVar + 1).toByte val Colls = IR.sigmaDslBuilderValue.Colls - implicit val eAny = RType.AnyType + implicit val eAny = sigma.AnyType val data = Colls.fromItems((Array[Byte](1,2,3).toColl, 10L)) val env1 = env + ("dataVar" -> CAnyValue(dataVar)) val dataType = SCollection(STuple(SByteArray, SLong)) diff --git a/sc/shared/src/test/scala/special/wrappers/WRTypeTests.scala b/sc/shared/src/test/scala/special/wrappers/WRTypeTests.scala index 400a4355f6..86fe106075 100644 --- a/sc/shared/src/test/scala/special/wrappers/WRTypeTests.scala +++ b/sc/shared/src/test/scala/special/wrappers/WRTypeTests.scala @@ -19,7 +19,7 @@ class WRTypeTests extends WrappersTests { } test("Implicit conversion from RType to Elem") { - val eInt: Elem[Int] = RType.IntType + val eInt: Elem[Int] = sigma.IntType eInt shouldBe IntElement val ePair: Elem[(Int, Coll[Byte])] = RType[(Int, SColl[Byte])] diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Type.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Type.scala index 846407737b..5c79513f9c 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Type.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Type.scala @@ -20,16 +20,16 @@ class Type(private[js] final val rtype: RType[_]) extends js.Object { @JSExportTopLevel("TypeObj") object Type extends js.Object { /** Descriptor of ErgoScript type Byte. */ - val Byte = new Type(RType.ByteType) + val Byte = new Type(sigma.ByteType) /** Descriptor of ErgoScript type Short. */ - val Short = new Type(RType.ShortType) + val Short = new Type(sigma.ShortType) /** Descriptor of ErgoScript type Int. */ - val Int = new Type(RType.IntType) + val Int = new Type(sigma.IntType) /** Descriptor of ErgoScript type Long. */ - val Long = new Type(RType.LongType) + val Long = new Type(sigma.LongType) /** Descriptor of ErgoScript type BigInt. */ val BigInt = new Type(sigma.BigIntRType) diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Value.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Value.scala index 852bd867a8..ff739a7f43 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Value.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Value.scala @@ -82,9 +82,9 @@ object Value extends js.Object { * in register and [[sigmastate.Values.Constant]] nodes. */ final private[js] def toRuntimeData(data: Any, rtype: RType[_]): Any = rtype match { - case RType.BooleanType => data - case RType.ByteType | RType.ShortType | RType.IntType => data - case RType.LongType => java.lang.Long.parseLong(data.asInstanceOf[js.BigInt].toString(10)) + case sigma.BooleanType => data + case sigma.ByteType | sigma.ShortType | sigma.IntType => data + case sigma.LongType => java.lang.Long.parseLong(data.asInstanceOf[js.BigInt].toString(10)) case sigma.BigIntRType => val v = data.asInstanceOf[js.BigInt] SigmaDsl.BigInt(new BigInteger(v.toString(16), 16)) @@ -110,7 +110,7 @@ object Value extends js.Object { val x = toRuntimeData(p(0), pt.tFst).asInstanceOf[a] val y = toRuntimeData(p(1), pt.tSnd).asInstanceOf[b] (x, y) - case RType.UnitType => data + case sigma.UnitType => data case _ => throw new IllegalArgumentException(s"Unsupported type $rtype") } @@ -122,9 +122,9 @@ object Value extends js.Object { * @param rtype type descriptor of Sigma runtime value */ final private[js] def fromRuntimeData(value: Any, rtype: RType[_]): Any = rtype match { - case RType.BooleanType => value - case RType.ByteType | RType.ShortType | RType.IntType => value - case RType.LongType => js.BigInt(value.asInstanceOf[Long].toString) + case sigma.BooleanType => value + case sigma.ByteType | sigma.ShortType | sigma.IntType => value + case sigma.LongType => js.BigInt(value.asInstanceOf[Long].toString) case sigma.BigIntRType => val hex = SigmaDsl.toBigInteger(value.asInstanceOf[sigma.BigInt]).toString(10) js.BigInt(hex) @@ -143,7 +143,7 @@ object Value extends js.Object { case pt: PairType[a, b] => val p = value.asInstanceOf[(a, b)] js.Array(fromRuntimeData(p._1, pt.tFst), fromRuntimeData(p._2, pt.tSnd)) - case RType.UnitType => value + case sigma.UnitType => value case _ => throw new IllegalArgumentException(s"Unsupported type $rtype") } @@ -154,10 +154,10 @@ object Value extends js.Object { * @param rtype type descriptor of Sigma runtime value */ final private def checkJsData[T](data: T, rtype: RType[_]): Any = rtype match { - case RType.ByteType => data.asInstanceOf[Int].toByteExact - case RType.ShortType => data.asInstanceOf[Int].toShortExact - case RType.IntType => data.asInstanceOf[Int].toLong.toIntExact - case RType.LongType => + case sigma.ByteType => data.asInstanceOf[Int].toByteExact + case sigma.ShortType => data.asInstanceOf[Int].toShortExact + case sigma.IntType => data.asInstanceOf[Int].toLong.toIntExact + case sigma.LongType => val n = data.asInstanceOf[js.BigInt] if (n < MinLong || n > MaxLong) throw new ArithmeticException(s"value $n is out of long range") diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ContractTemplate.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ContractTemplate.scala index 4320555628..f763824400 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ContractTemplate.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ContractTemplate.scala @@ -1,19 +1,18 @@ package org.ergoplatform.sdk -import cats.syntax.either._ import debox.cfor import io.circe._ -import io.circe.syntax.{EncoderOps, _} +import io.circe.syntax.EncoderOps import org.ergoplatform.sdk.utils.SerializationUtils.{parseString, serializeString} import org.ergoplatform.sdk.utils.Zero +import sigma.util.safeNewArray import sigmastate.Values.ErgoTree.headerWithVersion import sigmastate.Values.{ErgoTree, _} import sigmastate._ -import sigmastate.eval.{Colls, _} +import sigmastate.eval._ import sigmastate.exceptions.SerializerException import sigmastate.lang.{DeserializationSigmaBuilder, StdSigmaBuilder} import sigmastate.serialization._ -import sigma.util.safeNewArray import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import java.util.Objects diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/DataJsonEncoder.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/DataJsonEncoder.scala index 71e460cd42..06ffa951db 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/DataJsonEncoder.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/DataJsonEncoder.scala @@ -190,7 +190,7 @@ object DataJsonEncoder { cfor(1)(_ <= tArr.length, _ + 1) { i => collSource += decodeData(json.hcursor.downField(s"_${i}").focus.get, tArr(i - 1)) } - val coll = Colls.fromArray(collSource.result())(RType.AnyType) + val coll = Colls.fromArray(collSource.result())(sigma.AnyType) Evaluation.toDslTuple(coll, t) case SGroupElement => val str = decodeBytes(json) diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala index 769455e252..0d4db24003 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala @@ -242,12 +242,12 @@ object JavaHelpers { def toErgoTree: ErgoTree = decodeStringToErgoTree(base16) } - implicit val TokenIdRType: RType[TokenId] = collRType(RType.ByteType).asInstanceOf[RType[TokenId]] - implicit val JByteRType: RType[JByte] = RType.ByteType.asInstanceOf[RType[JByte]] - implicit val JShortRType: RType[JShort] = RType.ShortType.asInstanceOf[RType[JShort]] - implicit val JIntRType: RType[JInt] = RType.IntType.asInstanceOf[RType[JInt]] - implicit val JLongRType: RType[JLong] = RType.LongType.asInstanceOf[RType[JLong]] - implicit val JBooleanRType: RType[JBoolean] = RType.BooleanType.asInstanceOf[RType[JBoolean]] + implicit val TokenIdRType: RType[TokenId] = collRType(sigma.ByteType).asInstanceOf[RType[TokenId]] + implicit val JByteRType: RType[JByte] = sigma.ByteType.asInstanceOf[RType[JByte]] + implicit val JShortRType: RType[JShort] = sigma.ShortType.asInstanceOf[RType[JShort]] + implicit val JIntRType: RType[JInt] = sigma.IntType.asInstanceOf[RType[JInt]] + implicit val JLongRType: RType[JLong] = sigma.LongType.asInstanceOf[RType[JLong]] + implicit val JBooleanRType: RType[JBoolean] = sigma.BooleanType.asInstanceOf[RType[JBoolean]] val HeaderRType: RType[Header] = sigma.HeaderRType val PreHeaderRType: RType[sigma.PreHeader] = sigma.PreHeaderRType diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/OutBoxBuilder.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/OutBoxBuilder.scala index 0a5bd8c1d0..142ad31c06 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/OutBoxBuilder.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/OutBoxBuilder.scala @@ -68,7 +68,7 @@ object OutBoxBuilder { val nRegs = registers.length require(nRegs <= nonMandatoryRegisters.length, s"Too many additional registers $nRegs. Max allowed ${nonMandatoryRegisters.length}") - implicit val TokenIdRType: RType[TokenId] = collRType(RType.ByteType).asInstanceOf[RType[TokenId]] + implicit val TokenIdRType: RType[TokenId] = collRType(sigma.ByteType).asInstanceOf[RType[TokenId]] val ts = Colls.fromItems(tokens.map(Iso.isoErgoTokenToPair.to(_)): _*) val rs = registers.zipWithIndex.map { case (c, i) => val id = ErgoBox.nonMandatoryRegisters(i) diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/utils/Zero.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/utils/Zero.scala index fd3bb455d6..6c7cbde440 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/utils/Zero.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/utils/Zero.scala @@ -1,7 +1,7 @@ package org.ergoplatform.sdk.utils import org.ergoplatform.ErgoBox -import sigma.core.{CollType, RType} +import sigma.core.{CollType, RType, TupleType} import sigma.core.RType._ import scorex.crypto.authds.avltree.batch.BatchAVLProver import scorex.crypto.hash.{Blake2b256, Digest32} diff --git a/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala b/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala index 019db458c0..e4a1b2b7e2 100644 --- a/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala +++ b/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala @@ -2,8 +2,8 @@ package org.ergoplatform.sdk import java.math.BigInteger - import org.scalacheck.Arbitrary._ +import org.scalacheck.Gen import sigma.core.RType import sigmastate.SCollection.SByteArray import sigmastate.SType.AnyOps @@ -13,9 +13,12 @@ import sigmastate.eval.Extensions._ import sigmastate.eval.{Evaluation, _} import sigmastate.crypto.CryptoConstants.EcPointType import sigmastate.exceptions.SerializerException -import sigma.{Box, AvlTree} +import sigma.{AvlTree, Box} import sigmastate.serialization.SerializationSpecification +import scala.annotation.nowarn +import scala.reflect.ClassTag + class DataJsonEncoderSpecification extends SerializationSpecification { object JsonCodecs extends JsonCodecs @@ -47,9 +50,9 @@ class DataJsonEncoderSpecification extends SerializationSpecification { } def testTuples[T <: SType](tpe: T) = { - implicit val wWrapped = wrappedTypeGen(tpe) - implicit val tag = tpe.classTag[T#WrappedType] - implicit val tAny = RType.AnyType + implicit val wWrapped: Gen[T#WrappedType] = wrappedTypeGen(tpe) + implicit val tag : ClassTag[T#WrappedType] = tpe.classTag[T#WrappedType] + implicit val tAny : RType[Any] = sigma.AnyType forAll { in: (T#WrappedType, T#WrappedType) => val (x,y) = (in._1, in._2) roundtrip[SType]((x, y).asWrappedType, STuple(tpe, tpe)) @@ -58,11 +61,11 @@ class DataJsonEncoderSpecification extends SerializationSpecification { } } - def testAnyValue[T <: SType](tpe: T) = { + @nowarn def testAnyValue[T <: SType](tpe: T) = { implicit val wWrapped = wrappedTypeGen(tpe) implicit val tag = tpe.classTag[T#WrappedType] implicit val tT = Evaluation.stypeToRType(tpe) - implicit val tAny = RType.AnyType + implicit val tAny = sigma.AnyType forAll { in: T#WrappedType => val x = CAnyValue(in) val json = JsonCodecs.anyValueEncoder(x) @@ -181,7 +184,7 @@ class DataJsonEncoderSpecification extends SerializationSpecification { def testEncodeError[T <: SType](tpe: T) = { implicit val wWrapped = wrappedTypeGen(tpe) implicit val tag = tpe.classTag[T#WrappedType] - implicit val tAny = RType.AnyType + implicit val tAny = sigma.AnyType forAll { x: T#WrappedType => an[SerializerException] should be thrownBy { DataJsonEncoder.encode(TupleColl(x, x, x).asWrappedType, STuple(tpe, tpe, tpe))