Skip to content

Commit

Permalink
todo-v5.x: removed SomeValue, NoneValue
Browse files Browse the repository at this point in the history
  • Loading branch information
aslesarenko committed Aug 19, 2023
1 parent 586104a commit 99a4081
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 72 deletions.
25 changes: 0 additions & 25 deletions interpreter/shared/src/main/scala/sigmastate/Values.scala
Original file line number Diff line number Diff line change
Expand Up @@ -878,31 +878,6 @@ object Values {
def apply(items: Value[SType]*): Tuple = Tuple(items.toIndexedSeq)
}

trait OptionValue[T <: SType] extends Value[SOption[T]] {
}

// TODO v5.x (4h): SomeValue and NoneValue are not used in ErgoTree and can be
// either removed or implemented in v6.0
case class SomeValue[T <: SType](x: Value[T]) extends OptionValue[T] {
override def companion = SomeValue
val tpe = SOption(x.tpe)
def opType = SFunc(x.tpe, tpe)
}
object SomeValue extends ValueCompanion {
override val opCode = SomeValueCode
override def costKind: CostKind = Constant.costKind
}

case class NoneValue[T <: SType](elemType: T) extends OptionValue[T] {
override def companion = NoneValue
val tpe = SOption(elemType)
def opType = SFunc(elemType, tpe)
}
object NoneValue extends ValueCompanion {
override val opCode = NoneValueCode
override def costKind: CostKind = Constant.costKind
}

/** ErgoTree node which converts a collection of expressions into a collection of data
* values. Each data value of the resulting collection is obtained by evaluating the
* corresponding expression in `items`. All items must have the same type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ abstract class SigmaBuilder {

def mkTaggedVariable[T <: SType](varId: Byte, tpe: T): TaggedVariable[T]

def mkSomeValue[T <: SType](x: Value[T]): Value[SOption[T]]
def mkNoneValue[T <: SType](elemType: T): Value[SOption[T]]

def mkBlock(bindings: Seq[Val], result: Value[SType]): Value[SType]
def mkBlockValue(items: IndexedSeq[BlockItem], result: Value[SType]): Value[SType]
def mkValUse(valId: Int, tpe: SType): Value[SType]
Expand Down Expand Up @@ -527,11 +524,6 @@ class StdSigmaBuilder extends SigmaBuilder {
override def mkTaggedVariable[T <: SType](varId: Byte, tpe: T): TaggedVariable[T] =
TaggedVariableNode(varId, tpe).withSrcCtx(currentSrcCtx.value).asInstanceOf[TaggedVariable[T]]

override def mkSomeValue[T <: SType](x: Value[T]): Value[SOption[T]] =
SomeValue(x).withSrcCtx(currentSrcCtx.value)
override def mkNoneValue[T <: SType](elemType: T): Value[SOption[T]] =
NoneValue(elemType).withSrcCtx(currentSrcCtx.value)

override def mkBlock(bindings: Seq[Val], result: Value[SType]): Value[SType] =
Block(bindings, result).withSrcCtx(currentSrcCtx.value)

Expand Down
7 changes: 0 additions & 7 deletions sc/shared/src/main/scala/sigmastate/lang/SigmaBinder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class SigmaBinder(env: ScriptEnv, builder: SigmaBuilder,
case "SELF" => Some(Self)
case "CONTEXT" => Some(Context)
case "Global" => Some(Global)
case "None" => Some(mkNoneValue(NoType))
case _ => None
}
}
Expand All @@ -62,12 +61,6 @@ class SigmaBinder(env: ScriptEnv, builder: SigmaBuilder,
val tpe = if (args.isEmpty) NoType else args(0).tpe
Some(mkConcreteCollection(args, tpe))

// Rule: Some(x) -->
case Apply(i @ Ident("Some", _), args) => args match {
case Seq(arg) => Some(mkSomeValue(arg))
case _ => error(s"Invalid arguments of Some: expected one argument but found $args", i.sourceContext)
}

// Rule: min(x, y) -->
case Apply(i @ Ident("min", _), args) => args match {
case Seq(l: SValue, r: SValue) =>
Expand Down
3 changes: 0 additions & 3 deletions sc/shared/src/main/scala/sigmastate/lang/SigmaTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,6 @@ class SigmaTyper(val builder: SigmaBuilder,
case Negation(i) => unmap[SNumericType](env, "-", i.asNumValue)(mkNegation)(tT)
case BitInversion(i) => unmap[SNumericType](env, "~", i.asNumValue)(mkBitInversion)(tT)

case SomeValue(x) => SomeValue(assignType(env, x))
case v: NoneValue[_] => v

case Global => Global
case Context => Context
case Height => Height
Expand Down
17 changes: 0 additions & 17 deletions sc/shared/src/test/scala/sigmastate/lang/SigmaBinderTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,6 @@ class SigmaBinderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Mat
If(EQ(IntConstant(10), IntConstant(11)), IntConstant(2), IntConstant(3)))
}

// TODO v5.x (4h): SomeValue and NoneValue are not used in ErgoTree and can be
// either removed or implemented in v4.x
property("Option constructors") {
bind(env, "None") shouldBe NoneValue(NoType)
bind(env, "Some(None)") shouldBe SomeValue(NoneValue(NoType))
bind(env, "Some(10)") shouldBe SomeValue(IntConstant(10))
bind(env, "Some(X)") shouldBe SomeValue(Ident("X"))
bind(env, "Some(Some(X - 1))") shouldBe
SomeValue(SomeValue(mkMinus(Ident("X").asValue[SInt.type], IntConstant(1))))
bind(env, "Some(Some(X + 1))") shouldBe
SomeValue(SomeValue(plus(Ident("X").asValue[SInt.type], IntConstant(1))))
}

property("lambdas") {
bind(env, "{ (a: Int) => a - 1 }") shouldBe
Lambda(IndexedSeq("a" -> SInt), NoType, mkMinus(IntIdent("a"), 1))
Expand Down Expand Up @@ -214,8 +201,4 @@ class SigmaBinderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Mat
e.source shouldBe Some(SourceContext(2, 5, "val x = 10"))
}

property("fail Some (invalid arguments)") {
fail(env, "Some(1, 2)", 1, 1)
fail(env, "Some()", 1, 1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,6 @@ class SigmaCompilerTest extends CompilerTestingCommons with LangTests with Objec
)
}

property("failed option constructors (not supported)") {
costerFail("None", 1, 1)
costerFail("Some(10)", 1, 1)
}

property("byteArrayToLong") {
comp("byteArrayToLong(longToByteArray(1L))") shouldBe ByteArrayToLong(LongToByteArray(LongConstant(1)))
}
Expand Down
7 changes: 0 additions & 7 deletions sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,6 @@ class SigmaTyperTest extends AnyPropSpec
typefail(env, "Coll(1, false)", 1, 1)
}

property("Option constructors") {
typecheck(env, "Some(10)") shouldBe SOption(SInt)
typecheck(env, "Some(x)") shouldBe SOption(SInt)
typecheck(env, "Some(x + 1)") shouldBe SOption(SInt)
typecheck(env, "Some(Some(10))") shouldBe SOption(SOption(SInt))
}

property("methods returning Option") {
typecheck(env, "getVar[Int](10)") shouldBe SOption(SInt)
typecheck(env, "{ val v = getVar[Int](1); v.get }") shouldBe SInt
Expand Down

0 comments on commit 99a4081

Please sign in to comment.