Drop ValueBuiltinException (#9576)

As discussed, we don’t want to expose this via serializable values at
least for now (and it’s not exposed on the ledger API anyway) so this
PR drops the type.

changelog_begin
changelog_end
This commit is contained in:
Moritz Kiefer 2021-05-05 12:32:58 +02:00 committed by GitHub
parent 1c456be79d
commit de80a6dc60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 15 additions and 175 deletions

View File

@ -708,8 +708,6 @@ prettyValue' showRecordType prec world (Value (Just vsum)) = case vsum of
then \fs -> prettyMay "" (prettyDefName world) mbRecordId <-> keyword_ "with" $$ nest 2 fs
else id)
(sep (punctuate ";" (mapV prettyField fields)))
ValueSumBuiltinException(BuiltinException tag mbValue) ->
ltext tag <> char '(' <> prettyMay "<missing value>" (prettyValue' True prec world) mbValue <> char ')'
ValueSumVariant (Variant mbVariantId ctor mbValue) ->
prettyMay "" (\v -> prettyDefName world v <> ":") mbVariantId <> ltext ctor
<-> prettyMay "<missing value>" (prettyValue' True precHighest world) mbValue

View File

@ -290,11 +290,6 @@ message Variant {
Value value = 3;
}
message BuiltinException {
string tag = 1;
Value value = 2;
}
message Enum {
Identifier enum_id = 1;
string constructor = 2;
@ -335,8 +330,6 @@ message Value {
// An unserializable value, e.g. closure. Contains a description of the value.
string unserializable = 17;
BuiltinException builtin_exception = 18;
}
}

View File

@ -650,14 +650,6 @@ final class Conversions(
)
.build
)
case V.ValueBuiltinException(tag, value) =>
val vbuilder = proto.BuiltinException.newBuilder
builder.setBuiltinException(
vbuilder
.setTag(tag)
.setValue(convertValue(value))
.build
)
case V.ValueVariant(tycon, variant, value) =>
val vbuilder = proto.Variant.newBuilder
tycon.foreach(x => vbuilder.setVariantId(convertIdentifier(x)))

View File

@ -313,7 +313,6 @@ object ScenarioLedger {
fs.foreach { case (_, v) =>
collect(v)
}
case ValueBuiltinException(_, arg) => collect(arg)
case ValueVariant(_, _, arg) => collect(arg)
case _: ValueEnum => ()
case ValueList(vs) =>

View File

@ -417,8 +417,6 @@ private[lf] object Pretty {
text("")
}) +
text(constructor)
case ValueBuiltinException(tag, value) =>
text(tag) + char('(') + prettyValue(true)(value) + char(')')
case ValueText(t) => char('"') + text(t) + char('"')
case ValueContractId(acoid) => text(acoid.coid)
case ValueUnit => text("<unit>")

View File

@ -62,8 +62,8 @@ sealed trait SValue {
V.ValueGenMap(entries.view.map { case (k, v) => k.toValue -> v.toValue }.to(ImmArray))
case SContractId(coid) =>
V.ValueContractId(coid)
case SBuiltinException(tag, value) =>
V.ValueBuiltinException(tag, value.toValue)
case SBuiltinException(_, _) =>
throw SErrorCrash("SValue.toValue: unexpected SBuiltinException")
case SStruct(_, _) =>
throw SErrorCrash("SValue.toValue: unexpected SStruct")
case SAny(_, _) =>

View File

@ -153,10 +153,10 @@ class ExceptionTest extends AnyWordSpec with Matchers with TableDrivenPropertyCh
module M {
val unhandled1 : Update Int64 =
upure @Int64 (ADD_INT64 10 (throw @Int64 @GeneralError (MAKE_GENERAL_ERROR "oops1")));
upure @Int64 (ADD_INT64 10 (throw @Int64 @M:E1 (M:E1 {})));
val unhandled2 : Update Int64 =
try @Int64 (upure @Int64 (ADD_INT64 10 (throw @Int64 @GeneralError (MAKE_GENERAL_ERROR "oops2"))))
try @Int64 (upure @Int64 (ADD_INT64 10 (throw @Int64 @M:E1 (M:E1 {}))))
catch e -> None @(Update Int64);
record @serializable E1 = { } ;
@ -180,18 +180,15 @@ class ExceptionTest extends AnyWordSpec with Matchers with TableDrivenPropertyCh
(
"M:unhandled1",
SResultError(
DamlEUnhandledException(
TBuiltin(BTGeneralError),
ValueBuiltinException("GeneralError", ValueText("oops1")),
)
DamlEUnhandledException(TTyCon(e1), ValueRecord(Some(e1), data.ImmArray.empty))
),
),
(
"M:unhandled2",
SResultError(
DamlEUnhandledException(
TBuiltin(BTGeneralError),
ValueBuiltinException("GeneralError", ValueText("oops2")),
TTyCon(e1),
ValueRecord(Some(e1), data.ImmArray.empty),
)
),
),
@ -216,31 +213,6 @@ class ExceptionTest extends AnyWordSpec with Matchers with TableDrivenPropertyCh
}
}
"throw/catch (GeneralError)" should {
// Basic throw/catch example for a builtin (GeneralError) exception
val pkgs: PureCompiledPackages = typeAndCompile(p"""
module M {
val throwAndCatch : Update Int64 =
try @Int64 (upure @Int64 (ADD_INT64 10 (throw @Int64 @GeneralError (MAKE_GENERAL_ERROR "oops"))))
catch e -> Some @(Update Int64) (upure @Int64 77);
}
""")
val testCases = Table[String, Long](
("expression", "expected"),
("M:throwAndCatch", 77),
)
forEvery(testCases) { (exp: String, num: Long) =>
s"eval[$exp] --> $num" in {
val expected: SResult = SResultFinalValue(SValue.SInt64(num))
runUpdateExpr(pkgs)(e"$exp") shouldBe expected
}
}
}
"throw/catch (UserDefined)" should {
// Basic throw/catch example a user defined exception
@ -470,13 +442,18 @@ class ExceptionTest extends AnyWordSpec with Matchers with TableDrivenPropertyCh
val pkgs: PureCompiledPackages = typeAndCompile(p"""
module M {
record @serializable E = { message: Text } ;
exception E = {
message \(e: M:E) -> M:E {message} e
};
val myThrow : forall (a: *). (Text -> a) =
/\ (a: *). \(mes : Text) ->
throw @a @GeneralError (MAKE_GENERAL_ERROR mes);
throw @a @M:E (M:E { message = mes });
val isPayLoad : AnyException -> Text -> Bool =
\(e: AnyException) (mes: Text) ->
EQUAL @AnyException e (to_any_exception @GeneralError (MAKE_GENERAL_ERROR mes)) ;
EQUAL @AnyException e (to_any_exception @M:E (M:E { message = mes })) ;
val extractPayload : AnyException -> Int64 =
\(e: AnyException) ->

View File

@ -316,9 +316,6 @@ object TransactionBuilder {
go(currentVersion, map.values ++: values)
case ValueEnum(_, _) =>
go(currentVersion, values)
// for things added after version 10, we raise the minimum if present
case ValueBuiltinException(_, arg) =>
go(currentVersion max TransactionVersion.minExceptions, arg +: values)
case ValueGenMap(entries) =>
val newValues = entries.iterator.foldLeft(values) { case (acc, (key, value)) =>
key +: value +: acc

View File

@ -108,15 +108,6 @@ object ValueGenerators {
.chooseNum(Time.Timestamp.MinValue.micros, Time.Timestamp.MaxValue.micros)
.map(Time.Timestamp.assertFromLong)
// generate a builtinException with arbitrary value
private def builtinExceptionGen(nesting: Int): Gen[ValueBuiltinException[ContractId]] =
for {
tag <- Gen.alphaStr
value <- Gen.lzy(valueGen(nesting))
} yield ValueBuiltinException(tag, value)
def builtinExceptionGen: Gen[ValueBuiltinException[ContractId]] = builtinExceptionGen(0)
// generate a variant with arbitrary value
private def variantGen(nesting: Int): Gen[ValueVariant[ContractId]] =
for {
@ -224,9 +215,6 @@ object ValueGenerators {
val nested = List(
(sz / 2 + 1, Gen.resize(sz / 5, valueListGen(newNesting))),
(sz / 2 + 1, Gen.resize(sz / 5, variantGen(newNesting))),
// TODO https://github.com/digital-asset/daml/issues/8020
// test must work when we enable the following line:
//(sz / 2 + 1, Gen.resize(sz / 5, builtinExceptionGen(newNesting))),
(sz / 2 + 1, Gen.resize(sz / 5, recordGen(newNesting))),
(sz / 2 + 1, Gen.resize(sz / 5, valueOptionalGen(newNesting))),
(sz / 2 + 1, Gen.resize(sz / 5, valueMapGen(newNesting))),

View File

@ -211,8 +211,6 @@ object Hash {
iterateOver(xs.toImmArray)((acc, x) => acc.add(x._1).addTypedValue(x._2))
case Value.ValueRecord(_, fs) =>
iterateOver(fs)(_ addTypedValue _._2)
case Value.ValueBuiltinException(tag, v) =>
add(tag).addTypedValue(v)
case Value.ValueVariant(_, variant, v) =>
add(variant).addTypedValue(v)
case Value.ValueEnum(_, v) =>

View File

@ -50,8 +50,6 @@ object Util {
handleTypeInfo(tyCon),
fields.map { case (fieldName, value) => handleTypeInfo(fieldName) -> go(value) },
)
case ValueBuiltinException(tag, value) =>
ValueBuiltinException(tag, go(value))
case ValueVariant(tyCon, variant, value) =>
ValueVariant(handleTypeInfo(tyCon), variant, go(value))
case _: ValueCidlessLeaf | _: ValueContractId[_] => value

View File

@ -76,18 +76,6 @@ sealed abstract class Value[+Cid] extends CidContainer[Value[Cid]] with Product
go(exceededNesting, errs, values.toImmArray.map(v => (v, newNesting)) ++: vs)
}
case ValueBuiltinException(_, value) =>
if (newNesting > MAXIMUM_NESTING) {
if (exceededNesting) {
// we already exceeded the nesting, do not output again
go(exceededNesting, errs, vs)
} else {
go(true, errs :+ exceedsNestingErr, vs)
}
} else {
go(exceededNesting, errs, (value, newNesting) +: vs)
}
case ValueVariant(_, _, value) =>
if (newNesting > MAXIMUM_NESTING) {
if (exceededNesting) {
@ -170,8 +158,6 @@ object Value extends CidContainer1[Value] {
(lbl, go(value))
}),
)
case ValueBuiltinException(tag, value) =>
ValueBuiltinException(tag, go(value))
case ValueVariant(id, variant, value) =>
ValueVariant(id, variant, go(value))
case x: ValueCidlessLeaf => x
@ -194,8 +180,6 @@ object Value extends CidContainer1[Value] {
f(coid)
case ValueRecord(id @ _, fs) =>
fs.foreach { case (_, value) => go(value) }
case ValueBuiltinException(tag @ _, value) =>
go(value)
case ValueVariant(id @ _, variant @ _, value) =>
go(value)
case _: ValueCidlessLeaf =>
@ -265,7 +249,6 @@ object Value extends CidContainer1[Value] {
tycon: Option[Identifier],
fields: ImmArray[(Option[Name], Value[Cid])],
) extends Value[Cid]
final case class ValueBuiltinException[+Cid](tag: String, value: Value[Cid]) extends Value[Cid]
final case class ValueVariant[+Cid](tycon: Option[Identifier], variant: Name, value: Value[Cid])
extends Value[Cid]
final case class ValueEnum(tycon: Option[Identifier], value: Name) extends ValueCidlessLeaf
@ -517,13 +500,6 @@ private final class `Value Order instance`[Cid: Order](Scope: Value.LookupVarian
},
)
case ValueRecord(_, a) => (140, k { case ValueRecord(_, b) => _2.T.subst(a) ?|? _2.T.subst(b) })
case ValueBuiltinException(tagA, a) =>
(
150,
k { case ValueBuiltinException(tagB, b) =>
tagA ?|? tagB |+| a ?|? b
},
)
case ValueVariant(idA, conA, a) =>
(
160,
@ -581,10 +557,6 @@ private final class `Value Equal instance`[Cid: Equal] extends Equal[Value[Cid]]
import r._
tycon == tycon2 && fields === fields2
}
case v: ValueBuiltinException[Cid] => { case ValueBuiltinException(tag2, value2) =>
import v._
tag == tag2 && value === value2
}
case v: ValueVariant[Cid] => { case ValueVariant(tycon2, variant2, value2) =>
import v._
tycon == tycon2 && variant == variant2 && value === value2

View File

@ -432,10 +432,6 @@ object ValueCoder {
id.foreach(i => recordBuilder.setRecordId(encodeIdentifier(i)))
builder.setRecord(recordBuilder).build()
case ValueBuiltinException(_, _) =>
// TODO https://github.com/digital-asset/daml/issues/8020
throw Err(s"Exceptions not supported")
case ValueVariant(id, con, arg) =>
val protoVar = proto.Variant.newBuilder()
protoVar.setConstructor(con)

View File

@ -468,15 +468,8 @@ class HashSpec extends AnyWordSpec with Matchers {
List(None, Some(false), Some(true)).map(VA.optional(VA.bool).inj(_)) ++
List(Some(None), Some(Some(false))).map(VA.optional(VA.optional(VA.bool)).inj(_))
val builtinExceptions =
List(
ValueBuiltinException("", ValueText("")),
ValueBuiltinException("someTag", ValueText("someMessage")),
ValueBuiltinException("differentTag", ValueInt64(42)),
)
val testCases: List[V] =
units ++ bools ++ ints ++ decimals ++ numeric0s ++ dates ++ timestamps ++ texts ++ parties ++ contractIds ++ optionals ++ lists ++ textMaps ++ genMaps ++ enums ++ records0 ++ records2 ++ variants ++ builtinExceptions
units ++ bools ++ ints ++ decimals ++ numeric0s ++ dates ++ timestamps ++ texts ++ parties ++ contractIds ++ optionals ++ lists ++ textMaps ++ genMaps ++ enums ++ records0 ++ records2 ++ variants
val expectedOut =
"""ValueUnit
@ -609,12 +602,6 @@ class HashSpec extends AnyWordSpec with Matchers {
| bd89c47c2379a69e8e0d46ff634c533449e8e7e532e84def4e2b2e168bc786e7
|ValueVariant(Some(pkgId:Mod:EitherBis),Left,ValueBool(false))
| 41edeaec86ac919e3c184057b021753781bd2ac1d60b8d4329375f60df953097
|ValueBuiltinException(,ValueText())
| 13c6a7b85fcb0443c1d31dafe22561aac714fbaa99d3b9a56474d8dda0c9aee0
|ValueBuiltinException(someTag,ValueText(someMessage))
| c7e681e156c80b804a4b105419564e3deb801f3be7ca2ca08fbd81da7a520323
|ValueBuiltinException(differentTag,ValueInt64(42))
| c086e55d65a985baaa8d46503905f3711b7390add30d7811f7a7cf93ce6394ad
|""".stripMargin
val sep = System.getProperty("line.separator")

View File

@ -286,9 +286,6 @@ object Queries {
Fragment.const(if (value) "TRUE" else "FALSE")
case r @ V.ValueRecord(_, _) =>
fr0"${toJsonString(r)}::jsonb"
case _ @V.ValueBuiltinException(_, _) =>
// TODO https://github.com/digital-asset/daml/issues/8020
sys.error("exceptions not supported")
case v @ V.ValueVariant(_, _, _) =>
fr0"${toJsonString(v)}::jsonb"
case V.ValueEnum(_, constructor) =>

View File

@ -80,10 +80,6 @@ message Value {
// The GenMap type
GenMap gen_map = 18;
// TODO https://github.com/digital-asset/daml/issues/8020
// // The BuiltinException type
// BuiltinException builtin_exception = 19;
}
}

View File

@ -64,9 +64,6 @@ object ApiValueToLfValueConverterTest {
case _: V.ValueCidlessLeaf | V.ValueContractId(_) => fa
case r @ V.ValueRecord(_, fields) => r copy (fields = fields map (_ rightMap go))
case v @ V.ValueVariant(_, _, value) => v copy (value = go(value))
case _ @V.ValueBuiltinException(_, value @ _) =>
// TODO https://github.com/digital-asset/daml/issues/8020
sys.error("exceptions not supported")
case V.ValueList(fs) => V.ValueList(fs map go)
case V.ValueOptional(o) => V.ValueOptional(o map go)
case V.ValueTextMap(m) => V.ValueTextMap(m mapValue go)

View File

@ -44,10 +44,6 @@ class ApiCodecCompressed[Cid](val encodeDecimalAsString: Boolean, val encodeInt6
case v: V.ValueVariant[Cid] => apiVariantToJsValue(v)
case v: V.ValueEnum => apiEnumToJsValue(v)
case v: V.ValueList[Cid] => apiListToJsValue(v)
case _: V.ValueBuiltinException[Cid] =>
// TODO https://github.com/digital-asset/daml/issues/8020
//apiBuiltinExceptionToJsValue(v)
sys.error("exceptions not supported")
case V.ValueText(v) => JsString(v)
case V.ValueInt64(v) => if (encodeInt64AsString) JsString((v: Long).toString) else JsNumber(v)
case V.ValueNumeric(v) =>
@ -77,10 +73,6 @@ class ApiCodecCompressed[Cid](val encodeDecimalAsString: Boolean, val encodeInt6
private[this] def apiListToJsValue(value: V.ValueList[Cid]): JsValue =
JsArray(value.values.map(apiValueToJsValue(_)).toImmArray.toSeq: _*)
// TODO https://github.com/digital-asset/daml/issues/8020
/*private[this] def apiBuiltinExceptionToJsValue(value: V.ValueBuiltinException[Cid]): JsValue =
JsonVariant(value.tag, apiValueToJsValue(value.value))*/
private[this] def apiVariantToJsValue(value: V.ValueVariant[Cid]): JsValue =
JsonVariant(value.variant, apiValueToJsValue(value.value))

View File

@ -69,7 +69,6 @@ trait NavigatorModelAliases[Cid] {
type ApiValue = OfCid[V]
type ApiRecordField = (Option[DamlLfRef.Name], ApiValue)
type ApiRecord = OfCid[V.ValueRecord]
type ApiBuiltinException = OfCid[V.ValueBuiltinException]
type ApiVariant = OfCid[V.ValueVariant]
type ApiList = OfCid[V.ValueList]
type ApiOptional = OfCid[V.ValueOptional]

View File

@ -136,16 +136,6 @@ object LfEngineToApi {
vs.toImmArray.toSeq.traverseEitherStrictly(lfValueToApiValue(verbose, _)) map { xs =>
api.Value(api.Value.Sum.List(api.List(xs)))
}
case Lf.ValueBuiltinException(tag @ _, v @ _) =>
// TODO https://github.com/digital-asset/daml/issues/8020
/*lfValueToApiValue(verbose, v) map { x =>
api.Value(
api.Value.Sum.BuiltinException(
api.BuiltinException(tag, Some(x))
)
)
}*/
sys.error("exceptions not supported")
case Lf.ValueVariant(tycon, variant, v) =>
lfValueToApiValue(verbose, v) map { x =>
api.Value(

View File

@ -79,15 +79,6 @@ object KeyHasher extends KeyHasher {
val z1 = op(z, HashTokenCollectionBegin(0))
op(z1, HashTokenCollectionEnd())
// Variant: [CollectionBegin(), Text(tag), Token(value), CollectionEnd()]
case ValueBuiltinException(tag @ _, v @ _) =>
// TODO https://github.com/digital-asset/daml/issues/8020
/*val z1 = op(z, HashTokenCollectionBegin(1))
val z2 = op(z1, HashTokenText(tag))
val z3 = foldLeft(v, z2, op)
op(z3, HashTokenCollectionEnd())*/
sys.error("exceptions not supported")
// Variant: [CollectionBegin(), Text(variant), Token(value), CollectionEnd()]
case ValueVariant(_, variant, v) =>
val z1 = op(z, HashTokenCollectionBegin(1))

View File

@ -83,8 +83,6 @@ private[replay] final class Adapter(
Value.ValueRecord(tycon.map(adapt), fields.map { case (f, v) => f -> adapt(v) })
case Value.ValueVariant(tycon, variant, value) =>
Value.ValueVariant(tycon.map(adapt), variant, adapt(value))
case Value.ValueBuiltinException(tag, value) =>
Value.ValueBuiltinException(tag, adapt(value))
case Value.ValueList(values) =>
Value.ValueList(values.map(adapt))
case Value.ValueOptional(value) =>

View File

@ -50,10 +50,6 @@ object ApiCodecVerbose {
def apiValueToJsValue(value: Model.ApiValue): JsValue = value match {
case v: Model.ApiRecord => apiRecordToJsValue(v)
case v: Model.ApiVariant => apiVariantToJsValue(v)
case _: Model.ApiBuiltinException =>
// TODO https://github.com/digital-asset/daml/issues/8020
//apiBuiltinExceptionToJsValue(v)
sys.error("exceptions not supported")
case v: V.ValueEnum => apiEnumToJsValue(v)
case v: Model.ApiList => apiListToJsValue(v)
case V.ValueText(v) => JsObject(propType -> JsString(tagText), propValue -> JsString(v))

View File

@ -430,9 +430,6 @@ case object LedgerApiV1 {
case v: Model.ApiList => fillInListTI(v, typ, ctx)
case v: Model.ApiRecord => fillInRecordTI(v, typ, ctx)
case v: Model.ApiVariant => fillInVariantTI(v, typ, ctx)
case _: Model.ApiBuiltinException =>
// TODO https://github.com/digital-asset/daml/issues/8020
Left(GenericConversionError(s"Exceptions not supported"))
}
def readCompletion(completion: V1.completion.Completion): Result[Option[Model.CommandStatus]] = {

View File

@ -217,9 +217,6 @@ package object filter {
}
}
case V.ValueBuiltinException(_, _) =>
// TODO https://github.com/digital-asset/daml/issues/8020
sys.error("exceptions not supported")
}
loop(rootArgument, cursor.prev.get)

View File

@ -223,9 +223,6 @@ object project {
Left(TypeCoercionFailure("GenMap index", "int", cursor, cursor.current))
}
}
case V.ValueBuiltinException(_, _) =>
// TODO https://github.com/digital-asset/daml/issues/8020
sys.error("exceptions not supported")
}
loop(rootArgument, cursor.prev.get)
}