Skip to content

Commit

Permalink
Provide byInterface fields for fetch, exercise. (#11607)
Browse files Browse the repository at this point in the history
Part of #10915

changelog_begin
changelog_end
  • Loading branch information
sofiafaro-da authored Nov 9, 2021
1 parent 830779f commit 70b2fe3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ private[lf] object SBuiltin {
choiceId: ChoiceName,
consuming: Boolean,
byKey: Boolean,
byInterface: Option[TypeConName],
) extends OnLedgerBuiltin(4) {

override protected def execute(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
)
}

Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 70b2fe3

Please sign in to comment.