mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 09:17:43 +03:00
DAML Engine: Remove token argument to SBU* builtins (#7542)
We currently pass the token to all builtins named `SBU*` aka the update builtins. Since we pass the token immediately on all call sites of these builtins, there's no point in passing the token at all. This PR removes the token passing for the `SBU*` builtins. Unfortunately, this does not improve execution performance. However, since it simplifies the code, I still consider it worthwhile. CHANGELOG_BEGIN CHANGELOG_END
This commit is contained in:
parent
0382a62965
commit
6a0b13ad73
@ -927,7 +927,7 @@ private[lf] final class Compiler(
|
||||
// in <retValue>
|
||||
topLevelFunction(ChoiceDefRef(tmplId, choice.name), 4) {
|
||||
case List(actorsPos, cidPos, choiceArgPos, tokenPos) =>
|
||||
val tmplArg = SBUFetch(tmplId)(svar(cidPos), svar(tokenPos))
|
||||
val tmplArg = SBUFetch(tmplId)(svar(cidPos))
|
||||
nextPositionWithExprName(tmpl.param)
|
||||
val beginExercise =
|
||||
SBUBeginExercise(tmplId, choice.name, choice.consuming, byKey = false)(
|
||||
@ -941,13 +941,12 @@ private[lf] final class Compiler(
|
||||
compile(choice.controllers)
|
||||
},
|
||||
compileKeyWithMaintainers(tmpl.key),
|
||||
svar(tokenPos)
|
||||
)
|
||||
nextPosition()
|
||||
addExprVar(choice.selfBinder, cidPos)
|
||||
val update = SEApp(compile(choice.update), Array(svar(tokenPos)))
|
||||
val retValuePos = nextPosition()
|
||||
val endExercise = SBUEndExercise(tmplId)(svar(tokenPos), svar(retValuePos))
|
||||
val endExercise = SBUEndExercise(tmplId)(svar(retValuePos))
|
||||
nextPosition()
|
||||
|
||||
SELet(
|
||||
@ -979,9 +978,9 @@ private[lf] final class Compiler(
|
||||
case List(actorsPos, keyPos, choiceArgPos, tokenPos) =>
|
||||
val keyWithM = encodeKeyWithMaintainers(keyPos, tmplKey)
|
||||
val keyWithMPos = nextPosition()
|
||||
val cid = SBUFetchKey(tmplId)(svar(keyWithMPos), svar(tokenPos))
|
||||
val cid = SBUFetchKey(tmplId)(svar(keyWithMPos))
|
||||
val cidPos = nextPosition()
|
||||
val tmplArg = SBUFetch(tmplId)(svar(cidPos), svar(tokenPos))
|
||||
val tmplArg = SBUFetch(tmplId)(svar(cidPos))
|
||||
nextPositionWithExprName(tmpl.param)
|
||||
val beginExercise =
|
||||
SBUBeginExercise(tmplId, choice.name, choice.consuming, byKey = true)(
|
||||
@ -995,13 +994,12 @@ private[lf] final class Compiler(
|
||||
compile(choice.controllers)
|
||||
},
|
||||
SBSome(svar(keyWithMPos)),
|
||||
svar(tokenPos)
|
||||
)
|
||||
nextPosition()
|
||||
addExprVar(choice.selfBinder, cidPos)
|
||||
val update = SEApp(compile(choice.update), Array(svar(tokenPos)))
|
||||
val retValuePos = nextPosition()
|
||||
val endExercise = SBUEndExercise(tmplId)(svar(tokenPos), svar(retValuePos))
|
||||
val endExercise = SBUEndExercise(tmplId)(svar(retValuePos))
|
||||
nextPosition()
|
||||
SELet(
|
||||
keyWithM,
|
||||
@ -1378,15 +1376,14 @@ private[lf] final class Compiler(
|
||||
// _ = $insertFetch(tmplId, false) coid [tmpl.signatories] [tmpl.observers] [tmpl.key] <token>
|
||||
// in <tmplArg>
|
||||
topLevelFunction(FetchDefRef(tmplId), 2) {
|
||||
case List(cidPos, tokenPos) =>
|
||||
val fetch = SBUFetch(tmplId)(svar(cidPos), svar(tokenPos))
|
||||
case List(cidPos, tokenPos @ _) =>
|
||||
val fetch = SBUFetch(tmplId)(svar(cidPos))
|
||||
val tmplArgPos = nextPositionWithExprName(tmpl.param)
|
||||
val insertNode = SBUInsertFetchNode(tmplId, byKey = false)(
|
||||
svar(cidPos),
|
||||
compile(tmpl.signatories),
|
||||
compile(tmpl.observers),
|
||||
compileKeyWithMaintainers(tmpl.key),
|
||||
svar(tokenPos)
|
||||
)
|
||||
nextPosition()
|
||||
|
||||
@ -1403,7 +1400,7 @@ private[lf] final class Compiler(
|
||||
// let _ = $checkPreconf(tmplId)(<tmplArg> [tmpl.precond]
|
||||
// in $create <tmplArg> [tmpl.agreementText] [tmpl.signatories] [tmpl.observers] [tmpl.key] <token>
|
||||
topLevelFunction(CreateDefRef(tmplId), 2) {
|
||||
case List(tmplArgPos, tokenPos) =>
|
||||
case List(tmplArgPos, tokenPos @ _) =>
|
||||
addExprVar(tmpl.param, tmplArgPos)
|
||||
val precond = SBCheckPrecond(tmplId)(svar(tmplArgPos), compile(tmpl.precond))
|
||||
nextPosition()
|
||||
@ -1418,7 +1415,6 @@ private[lf] final class Compiler(
|
||||
compile(tmpl.signatories),
|
||||
compile(tmpl.observers),
|
||||
compileKeyWithMaintainers(tmpl.key),
|
||||
svar(tokenPos)
|
||||
)
|
||||
}
|
||||
|
||||
@ -1496,13 +1492,13 @@ private[lf] final class Compiler(
|
||||
// _ = $insertLookup(tmplId> <keyWithM> <mbCid> <token>
|
||||
// in <mbCid>
|
||||
topLevelFunction(LookupByKeyDefRef(tmplId), 2) {
|
||||
case List(keyPos, tokenPos) =>
|
||||
case List(keyPos, tokenPos @ _) =>
|
||||
val keyWithM = encodeKeyWithMaintainers(keyPos, tmplKey)
|
||||
val keyWithMPos = nextPosition()
|
||||
val mbCid = SBULookupKey(tmplId)(svar(keyWithMPos), svar(tokenPos))
|
||||
val mbCid = SBULookupKey(tmplId)(svar(keyWithMPos))
|
||||
val maybeCidPos = nextPosition()
|
||||
val insertNode =
|
||||
SBUInsertLookupNode(tmplId)(svar(keyWithMPos), svar(maybeCidPos), svar(tokenPos))
|
||||
SBUInsertLookupNode(tmplId)(svar(keyWithMPos), svar(maybeCidPos))
|
||||
nextPosition()
|
||||
|
||||
SELet(
|
||||
@ -1529,19 +1525,18 @@ private[lf] final class Compiler(
|
||||
// _ = $insertFetch <coid> <signatories> <observers> (Some <keyWithM> )
|
||||
// in { contractId: ContractId Foo, contract: Foo }
|
||||
topLevelFunction(FetchByKeyDefRef(tmplId), 2) {
|
||||
case List(keyPos, tokenPos) =>
|
||||
case List(keyPos, tokenPos @ _) =>
|
||||
val keyWithM = encodeKeyWithMaintainers(keyPos, tmplKey)
|
||||
val keyWithMPos = nextPosition()
|
||||
val fetchKey = SBUFetchKey(tmplId)(svar(keyWithMPos), svar(tokenPos))
|
||||
val fetchKey = SBUFetchKey(tmplId)(svar(keyWithMPos))
|
||||
val cidPos = nextPosition()
|
||||
val fetch = SBUFetch(tmplId)(svar(cidPos), svar(tokenPos))
|
||||
val fetch = SBUFetch(tmplId)(svar(cidPos))
|
||||
val contractPos = nextPositionWithExprName(tmpl.param)
|
||||
val insertNode = SBUInsertFetchNode(tmplId, byKey = true)(
|
||||
svar(cidPos),
|
||||
compile(tmpl.signatories),
|
||||
compile(tmpl.observers),
|
||||
SBSome(svar(keyWithMPos)),
|
||||
svar(tokenPos)
|
||||
)
|
||||
nextPosition()
|
||||
|
||||
|
@ -848,16 +848,14 @@ private[lf] object SBuiltin {
|
||||
* -> List Party (signatories)
|
||||
* -> List Party (observers)
|
||||
* -> Optional {key: key, maintainers: List Party} (template key, if present)
|
||||
* -> Token
|
||||
* -> ContractId arg
|
||||
*/
|
||||
final case class SBUCreate(templateId: TypeConName) extends OnLedgerBuiltin(6) {
|
||||
final case class SBUCreate(templateId: TypeConName) extends OnLedgerBuiltin(5) {
|
||||
override protected final def execute(
|
||||
args: util.ArrayList[SValue],
|
||||
machine: Machine,
|
||||
onLedger: OnLedger
|
||||
): Unit = {
|
||||
checkToken(args.get(5))
|
||||
val createArg = args.get(0)
|
||||
val createArgValue = createArg.toValue
|
||||
val agreement = args.get(1) match {
|
||||
@ -895,7 +893,6 @@ private[lf] object SBuiltin {
|
||||
* -> List Party (observers)
|
||||
* -> List Party (choice controllers)
|
||||
* -> Optional {key: key, maintainers: List Party} (template key, if present)
|
||||
* -> Token
|
||||
* -> ()
|
||||
*/
|
||||
final case class SBUBeginExercise(
|
||||
@ -903,14 +900,13 @@ private[lf] object SBuiltin {
|
||||
choiceId: ChoiceName,
|
||||
consuming: Boolean,
|
||||
byKey: Boolean,
|
||||
) extends OnLedgerBuiltin(8) {
|
||||
) extends OnLedgerBuiltin(7) {
|
||||
|
||||
override protected final def execute(
|
||||
args: util.ArrayList[SValue],
|
||||
machine: Machine,
|
||||
onLedger: OnLedger
|
||||
): Unit = {
|
||||
checkToken(args.get(7))
|
||||
val arg = args.get(0).toValue
|
||||
val coid = args.get(1) match {
|
||||
case SContractId(coid) => coid
|
||||
@ -950,18 +946,16 @@ private[lf] object SBuiltin {
|
||||
}
|
||||
|
||||
/** $endExercise[T]
|
||||
* :: Token
|
||||
* -> Value (result of the exercise)
|
||||
* :: Value (result of the exercise)
|
||||
* -> ()
|
||||
*/
|
||||
final case class SBUEndExercise(templateId: TypeConName) extends OnLedgerBuiltin(2) {
|
||||
final case class SBUEndExercise(templateId: TypeConName) extends OnLedgerBuiltin(1) {
|
||||
override protected final def execute(
|
||||
args: util.ArrayList[SValue],
|
||||
machine: Machine,
|
||||
onLedger: OnLedger
|
||||
): Unit = {
|
||||
checkToken(args.get(0))
|
||||
val exerciseResult = args.get(1).toValue
|
||||
val exerciseResult = args.get(0).toValue
|
||||
onLedger.ptx = onLedger.ptx.endExercises(exerciseResult)
|
||||
checkAborted(onLedger.ptx)
|
||||
machine.returnValue = SUnit
|
||||
@ -970,16 +964,14 @@ private[lf] object SBuiltin {
|
||||
|
||||
/** $fetch[T]
|
||||
* :: ContractId a
|
||||
* -> Token
|
||||
* -> a
|
||||
*/
|
||||
final case class SBUFetch(templateId: TypeConName) extends OnLedgerBuiltin(2) {
|
||||
final case class SBUFetch(templateId: TypeConName) extends OnLedgerBuiltin(1) {
|
||||
override protected final def execute(
|
||||
args: util.ArrayList[SValue],
|
||||
machine: Machine,
|
||||
onLedger: OnLedger
|
||||
): Unit = {
|
||||
checkToken(args.get(1))
|
||||
val coid = args.get(0) match {
|
||||
case SContractId(coid) => coid
|
||||
case v => crash(s"expected contract id, got: $v")
|
||||
@ -1024,17 +1016,15 @@ private[lf] object SBuiltin {
|
||||
* -> List Party (signatories)
|
||||
* -> List Party (observers)
|
||||
* -> Optional {key: key, maintainers: List Party} (template key, if present)
|
||||
* -> Token
|
||||
* -> ()
|
||||
*/
|
||||
final case class SBUInsertFetchNode(templateId: TypeConName, byKey: Boolean)
|
||||
extends OnLedgerBuiltin(5) {
|
||||
extends OnLedgerBuiltin(4) {
|
||||
override protected final def execute(
|
||||
args: util.ArrayList[SValue],
|
||||
machine: Machine,
|
||||
onLedger: OnLedger
|
||||
): Unit = {
|
||||
checkToken(args.get(4))
|
||||
val coid = args.get(0) match {
|
||||
case SContractId(coid) => coid
|
||||
case v => crash(s"expected contract id, got: $v")
|
||||
@ -1063,16 +1053,14 @@ private[lf] object SBuiltin {
|
||||
|
||||
/** $lookupKey[T]
|
||||
* :: { key: key, maintainers: List Party }
|
||||
* -> Token
|
||||
* -> Maybe (ContractId T)
|
||||
*/
|
||||
final case class SBULookupKey(templateId: TypeConName) extends OnLedgerBuiltin(2) {
|
||||
final case class SBULookupKey(templateId: TypeConName) extends OnLedgerBuiltin(1) {
|
||||
override protected final def execute(
|
||||
args: util.ArrayList[SValue],
|
||||
machine: Machine,
|
||||
onLedger: OnLedger
|
||||
): Unit = {
|
||||
checkToken(args.get(1))
|
||||
val keyWithMaintainers =
|
||||
extractKeyWithMaintainers(args.get(0))
|
||||
val gkey = GlobalKey(templateId, keyWithMaintainers.key)
|
||||
@ -1112,16 +1100,14 @@ private[lf] object SBuiltin {
|
||||
/** $insertLookup[T]
|
||||
* :: { key : key, maintainers: List Party}
|
||||
* -> Maybe (ContractId T)
|
||||
* -> Token
|
||||
* -> ()
|
||||
*/
|
||||
final case class SBUInsertLookupNode(templateId: TypeConName) extends OnLedgerBuiltin(3) {
|
||||
final case class SBUInsertLookupNode(templateId: TypeConName) extends OnLedgerBuiltin(2) {
|
||||
override protected final def execute(
|
||||
args: util.ArrayList[SValue],
|
||||
machine: Machine,
|
||||
onLedger: OnLedger
|
||||
): Unit = {
|
||||
checkToken(args.get(2))
|
||||
val keyWithMaintainers = extractKeyWithMaintainers(args.get(0))
|
||||
val mbCoid = args.get(1) match {
|
||||
case SOptional(mb) =>
|
||||
@ -1149,16 +1135,14 @@ private[lf] object SBuiltin {
|
||||
|
||||
/** $fetchKey[T]
|
||||
* :: { key: key, maintainers: List Party }
|
||||
* -> Token
|
||||
* -> ContractId T
|
||||
*/
|
||||
final case class SBUFetchKey(templateId: TypeConName) extends OnLedgerBuiltin(2) {
|
||||
final case class SBUFetchKey(templateId: TypeConName) extends OnLedgerBuiltin(1) {
|
||||
override protected final def execute(
|
||||
args: util.ArrayList[SValue],
|
||||
machine: Machine,
|
||||
onLedger: OnLedger
|
||||
): Unit = {
|
||||
checkToken(args.get(1))
|
||||
val keyWithMaintainers = extractKeyWithMaintainers(args.get(0))
|
||||
val gkey = GlobalKey(templateId, keyWithMaintainers.key)
|
||||
// check if we find it locally
|
||||
|
Loading…
Reference in New Issue
Block a user