From c5d802f5002d59bd2b381a9383d7984c614474df Mon Sep 17 00:00:00 2001 From: Sofia Faro Date: Tue, 9 Nov 2021 11:14:17 +0000 Subject: [PATCH] Provide byInterface fields for fetch, exercise. Part of #10915 changelog_begin changelog_end --- .../daml/lf/speedy/Compiler.scala | 25 +++++++++------ .../daml/lf/speedy/SBuiltin.scala | 32 +++++++++++++++---- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala index 2bc3fa7c511b..8d18b77293f2 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala @@ -1030,7 +1030,13 @@ private[lf] final class Compiler( _env.bindExprVar(tmpl.param, tmplArgPos).bindExprVar(choice.argBinder._1, choiceArgPos) let( env, - SBUBeginExercise(tmplId, choice.name, choice.consuming, byKey = mbKey.isDefined)( + SBUBeginExercise( + tmplId, + choice.name, + choice.consuming, + byKey = mbKey.isDefined, + byInterface = None, + )( env.toSEVar(choiceArgPos), env.toSEVar(cidPos), compile(env, choice.controllers), @@ -1063,7 +1069,7 @@ private[lf] final class Compiler( val env = _env.bindExprVar(param, payloadPos).bindExprVar(choice.argBinder._1, choiceArgPos) let( env, - SBResolveSBUBeginExercise(choice.name, choice.consuming, byKey = false)( + SBResolveSBUBeginExercise(choice.name, choice.consuming, byKey = false, ifaceId = ifaceId)( env.toSEVar(payloadPos), env.toSEVar(choiceArgPos), env.toSEVar(cidPos), @@ -1448,7 +1454,7 @@ private[lf] final class Compiler( val env = _env.bindExprVar(tmpl.param, tmplArgPos) let( env, - SBUInsertFetchNode(tmplId, byKey = mbKey.isDefined)(env.toSEVar(cidPos)), + SBUInsertFetchNode(tmplId, byKey = mbKey.isDefined, byInterface = None)(env.toSEVar(cidPos)), ) { (_, env) => env.toSEVar(tmplArgPos) } @@ -1472,13 +1478,14 @@ private[lf] final class Compiler( private[this] def compileFetchInterface( ifaceId: Identifier ): (SDefinitionRef, SDefinition) = - topLevelFunction2(FetchDefRef(ifaceId)) { (cidPos, tokenPos, env) => + topLevelFunction2(FetchDefRef(ifaceId)) { (cidPos, _, env) => let(env, SBUFetchInterface(ifaceId)(env.toSEVar(cidPos))) { (payloadPos, env) => - SBResolveVirtualFetch( - env.toSEVar(payloadPos), - env.toSEVar(cidPos), - env.toSEVar(tokenPos), - ) + let( + env, + SBResolveSBUInsertFetchNode(ifaceId)(env.toSEVar(payloadPos), env.toSEVar(cidPos)), + ) { (_, env) => + env.toSEVar(payloadPos) + } } } diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SBuiltin.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SBuiltin.scala index 25676e6ac9ca..70f732e7e3ee 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SBuiltin.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SBuiltin.scala @@ -971,6 +971,7 @@ private[lf] object SBuiltin { choiceId: ChoiceName, consuming: Boolean, byKey: Boolean, + byInterface: Option[TypeConName], ) extends OnLedgerBuiltin(4) { override protected def execute( @@ -1008,7 +1009,7 @@ private[lf] object SBuiltin { mbKey = mbKey, byKey = byKey, chosenValue = chosenValue, - byInterface = None, // TODO https://github.com/digital-asset/daml/issues/10915 + byInterface = byInterface, ) checkAborted(onLedger.ptx) machine.returnValue = SUnit @@ -1142,10 +1143,26 @@ private[lf] object SBuiltin { choiceName: ChoiceName, consuming: Boolean, byKey: Boolean, + ifaceId: TypeConName, ) extends SBuiltin(1) { override private[speedy] def execute(args: util.ArrayList[SValue], machine: Machine): Unit = machine.ctrl = SEBuiltin( - SBUBeginExercise(getSRecord(args, 0).id, choiceName, consuming, byKey) + SBUBeginExercise( + getSRecord(args, 0).id, + choiceName, + consuming, + byKey, + byInterface = Some(ifaceId), + ) + ) + } + + final case class SBResolveSBUInsertFetchNode( + ifaceId: TypeConName + ) extends SBuiltin(1) { + override private[speedy] def execute(args: util.ArrayList[SValue], machine: Machine): Unit = + machine.ctrl = SEBuiltin( + SBUInsertFetchNode(getSRecord(args, 0).id, byKey = false, byInterface = Some(ifaceId)) ) } @@ -1155,8 +1172,6 @@ private[lf] object SBuiltin { machine.ctrl = SEVal(toDef(getSRecord(args, 0).id)) } - final case object SBResolveVirtualFetch extends SBResolveVirtual(FetchDefRef) - // Convert an interface to a given template type if possible. Since interfaces have the // same representation as the underlying template, we only need to perform a check // that the record type matches the template type. @@ -1190,8 +1205,11 @@ private[lf] object SBuiltin { * -> Optional {key: key, maintainers: List Party} (template key, if present) * -> () */ - final case class SBUInsertFetchNode(templateId: TypeConName, byKey: Boolean) - extends OnLedgerBuiltin(1) { + final case class SBUInsertFetchNode( + templateId: TypeConName, + byKey: Boolean, + byInterface: Option[TypeConName], + ) extends OnLedgerBuiltin(1) { override protected def execute( args: util.ArrayList[SValue], machine: Machine, @@ -1219,7 +1237,7 @@ private[lf] object SBuiltin { stakeholders, key, byKey, - None, // TODO https://github.com/digital-asset/daml/issues/10915 + byInterface, ) checkAborted(onLedger.ptx) machine.returnValue = SUnit