Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide byInterface fields for fetch, exercise in speedy. #11607

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this sufficient for ledger API commands with an interface id rather than just the LF exercise by interface? If not, we should either address this in this PR or in a follow-up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for speedy. This doesn't concern ledger API commands at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed/inherited choices should always have byInterface set, even if initially invoked at template id.
I think this is all working correctly wrt remy's PR to support inherited choice exercise by template in the ledger API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the speedy compiler is also used to compile ledger API commands via compileCommands. I think it works correctly but haven’t checked. probably worth tackling at least some minimal tests for this sooner rather than later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My PR is still not merge, so a bit tricky to test. ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually just merged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it does work regardless. Your PR exercises a choice on the interface id, which is the only way to exercise inherited choices in LF. This PR adds byInterface.

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