Provide byInterface fields for fetch, exercise. (#11607)

Part of #10915

changelog_begin
changelog_end
This commit is contained in:
Sofia Faro 2021-11-09 16:37:07 +00:00 committed by GitHub
parent 830779ff78
commit 70b2fe3534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 16 deletions

View File

@ -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)
}
}
}

View File

@ -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