mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +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>
|
// in <retValue>
|
||||||
topLevelFunction(ChoiceDefRef(tmplId, choice.name), 4) {
|
topLevelFunction(ChoiceDefRef(tmplId, choice.name), 4) {
|
||||||
case List(actorsPos, cidPos, choiceArgPos, tokenPos) =>
|
case List(actorsPos, cidPos, choiceArgPos, tokenPos) =>
|
||||||
val tmplArg = SBUFetch(tmplId)(svar(cidPos), svar(tokenPos))
|
val tmplArg = SBUFetch(tmplId)(svar(cidPos))
|
||||||
nextPositionWithExprName(tmpl.param)
|
nextPositionWithExprName(tmpl.param)
|
||||||
val beginExercise =
|
val beginExercise =
|
||||||
SBUBeginExercise(tmplId, choice.name, choice.consuming, byKey = false)(
|
SBUBeginExercise(tmplId, choice.name, choice.consuming, byKey = false)(
|
||||||
@ -941,13 +941,12 @@ private[lf] final class Compiler(
|
|||||||
compile(choice.controllers)
|
compile(choice.controllers)
|
||||||
},
|
},
|
||||||
compileKeyWithMaintainers(tmpl.key),
|
compileKeyWithMaintainers(tmpl.key),
|
||||||
svar(tokenPos)
|
|
||||||
)
|
)
|
||||||
nextPosition()
|
nextPosition()
|
||||||
addExprVar(choice.selfBinder, cidPos)
|
addExprVar(choice.selfBinder, cidPos)
|
||||||
val update = SEApp(compile(choice.update), Array(svar(tokenPos)))
|
val update = SEApp(compile(choice.update), Array(svar(tokenPos)))
|
||||||
val retValuePos = nextPosition()
|
val retValuePos = nextPosition()
|
||||||
val endExercise = SBUEndExercise(tmplId)(svar(tokenPos), svar(retValuePos))
|
val endExercise = SBUEndExercise(tmplId)(svar(retValuePos))
|
||||||
nextPosition()
|
nextPosition()
|
||||||
|
|
||||||
SELet(
|
SELet(
|
||||||
@ -979,9 +978,9 @@ private[lf] final class Compiler(
|
|||||||
case List(actorsPos, keyPos, choiceArgPos, tokenPos) =>
|
case List(actorsPos, keyPos, choiceArgPos, tokenPos) =>
|
||||||
val keyWithM = encodeKeyWithMaintainers(keyPos, tmplKey)
|
val keyWithM = encodeKeyWithMaintainers(keyPos, tmplKey)
|
||||||
val keyWithMPos = nextPosition()
|
val keyWithMPos = nextPosition()
|
||||||
val cid = SBUFetchKey(tmplId)(svar(keyWithMPos), svar(tokenPos))
|
val cid = SBUFetchKey(tmplId)(svar(keyWithMPos))
|
||||||
val cidPos = nextPosition()
|
val cidPos = nextPosition()
|
||||||
val tmplArg = SBUFetch(tmplId)(svar(cidPos), svar(tokenPos))
|
val tmplArg = SBUFetch(tmplId)(svar(cidPos))
|
||||||
nextPositionWithExprName(tmpl.param)
|
nextPositionWithExprName(tmpl.param)
|
||||||
val beginExercise =
|
val beginExercise =
|
||||||
SBUBeginExercise(tmplId, choice.name, choice.consuming, byKey = true)(
|
SBUBeginExercise(tmplId, choice.name, choice.consuming, byKey = true)(
|
||||||
@ -995,13 +994,12 @@ private[lf] final class Compiler(
|
|||||||
compile(choice.controllers)
|
compile(choice.controllers)
|
||||||
},
|
},
|
||||||
SBSome(svar(keyWithMPos)),
|
SBSome(svar(keyWithMPos)),
|
||||||
svar(tokenPos)
|
|
||||||
)
|
)
|
||||||
nextPosition()
|
nextPosition()
|
||||||
addExprVar(choice.selfBinder, cidPos)
|
addExprVar(choice.selfBinder, cidPos)
|
||||||
val update = SEApp(compile(choice.update), Array(svar(tokenPos)))
|
val update = SEApp(compile(choice.update), Array(svar(tokenPos)))
|
||||||
val retValuePos = nextPosition()
|
val retValuePos = nextPosition()
|
||||||
val endExercise = SBUEndExercise(tmplId)(svar(tokenPos), svar(retValuePos))
|
val endExercise = SBUEndExercise(tmplId)(svar(retValuePos))
|
||||||
nextPosition()
|
nextPosition()
|
||||||
SELet(
|
SELet(
|
||||||
keyWithM,
|
keyWithM,
|
||||||
@ -1378,15 +1376,14 @@ private[lf] final class Compiler(
|
|||||||
// _ = $insertFetch(tmplId, false) coid [tmpl.signatories] [tmpl.observers] [tmpl.key] <token>
|
// _ = $insertFetch(tmplId, false) coid [tmpl.signatories] [tmpl.observers] [tmpl.key] <token>
|
||||||
// in <tmplArg>
|
// in <tmplArg>
|
||||||
topLevelFunction(FetchDefRef(tmplId), 2) {
|
topLevelFunction(FetchDefRef(tmplId), 2) {
|
||||||
case List(cidPos, tokenPos) =>
|
case List(cidPos, tokenPos @ _) =>
|
||||||
val fetch = SBUFetch(tmplId)(svar(cidPos), svar(tokenPos))
|
val fetch = SBUFetch(tmplId)(svar(cidPos))
|
||||||
val tmplArgPos = nextPositionWithExprName(tmpl.param)
|
val tmplArgPos = nextPositionWithExprName(tmpl.param)
|
||||||
val insertNode = SBUInsertFetchNode(tmplId, byKey = false)(
|
val insertNode = SBUInsertFetchNode(tmplId, byKey = false)(
|
||||||
svar(cidPos),
|
svar(cidPos),
|
||||||
compile(tmpl.signatories),
|
compile(tmpl.signatories),
|
||||||
compile(tmpl.observers),
|
compile(tmpl.observers),
|
||||||
compileKeyWithMaintainers(tmpl.key),
|
compileKeyWithMaintainers(tmpl.key),
|
||||||
svar(tokenPos)
|
|
||||||
)
|
)
|
||||||
nextPosition()
|
nextPosition()
|
||||||
|
|
||||||
@ -1403,7 +1400,7 @@ private[lf] final class Compiler(
|
|||||||
// let _ = $checkPreconf(tmplId)(<tmplArg> [tmpl.precond]
|
// let _ = $checkPreconf(tmplId)(<tmplArg> [tmpl.precond]
|
||||||
// in $create <tmplArg> [tmpl.agreementText] [tmpl.signatories] [tmpl.observers] [tmpl.key] <token>
|
// in $create <tmplArg> [tmpl.agreementText] [tmpl.signatories] [tmpl.observers] [tmpl.key] <token>
|
||||||
topLevelFunction(CreateDefRef(tmplId), 2) {
|
topLevelFunction(CreateDefRef(tmplId), 2) {
|
||||||
case List(tmplArgPos, tokenPos) =>
|
case List(tmplArgPos, tokenPos @ _) =>
|
||||||
addExprVar(tmpl.param, tmplArgPos)
|
addExprVar(tmpl.param, tmplArgPos)
|
||||||
val precond = SBCheckPrecond(tmplId)(svar(tmplArgPos), compile(tmpl.precond))
|
val precond = SBCheckPrecond(tmplId)(svar(tmplArgPos), compile(tmpl.precond))
|
||||||
nextPosition()
|
nextPosition()
|
||||||
@ -1418,7 +1415,6 @@ private[lf] final class Compiler(
|
|||||||
compile(tmpl.signatories),
|
compile(tmpl.signatories),
|
||||||
compile(tmpl.observers),
|
compile(tmpl.observers),
|
||||||
compileKeyWithMaintainers(tmpl.key),
|
compileKeyWithMaintainers(tmpl.key),
|
||||||
svar(tokenPos)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1496,13 +1492,13 @@ private[lf] final class Compiler(
|
|||||||
// _ = $insertLookup(tmplId> <keyWithM> <mbCid> <token>
|
// _ = $insertLookup(tmplId> <keyWithM> <mbCid> <token>
|
||||||
// in <mbCid>
|
// in <mbCid>
|
||||||
topLevelFunction(LookupByKeyDefRef(tmplId), 2) {
|
topLevelFunction(LookupByKeyDefRef(tmplId), 2) {
|
||||||
case List(keyPos, tokenPos) =>
|
case List(keyPos, tokenPos @ _) =>
|
||||||
val keyWithM = encodeKeyWithMaintainers(keyPos, tmplKey)
|
val keyWithM = encodeKeyWithMaintainers(keyPos, tmplKey)
|
||||||
val keyWithMPos = nextPosition()
|
val keyWithMPos = nextPosition()
|
||||||
val mbCid = SBULookupKey(tmplId)(svar(keyWithMPos), svar(tokenPos))
|
val mbCid = SBULookupKey(tmplId)(svar(keyWithMPos))
|
||||||
val maybeCidPos = nextPosition()
|
val maybeCidPos = nextPosition()
|
||||||
val insertNode =
|
val insertNode =
|
||||||
SBUInsertLookupNode(tmplId)(svar(keyWithMPos), svar(maybeCidPos), svar(tokenPos))
|
SBUInsertLookupNode(tmplId)(svar(keyWithMPos), svar(maybeCidPos))
|
||||||
nextPosition()
|
nextPosition()
|
||||||
|
|
||||||
SELet(
|
SELet(
|
||||||
@ -1529,19 +1525,18 @@ private[lf] final class Compiler(
|
|||||||
// _ = $insertFetch <coid> <signatories> <observers> (Some <keyWithM> )
|
// _ = $insertFetch <coid> <signatories> <observers> (Some <keyWithM> )
|
||||||
// in { contractId: ContractId Foo, contract: Foo }
|
// in { contractId: ContractId Foo, contract: Foo }
|
||||||
topLevelFunction(FetchByKeyDefRef(tmplId), 2) {
|
topLevelFunction(FetchByKeyDefRef(tmplId), 2) {
|
||||||
case List(keyPos, tokenPos) =>
|
case List(keyPos, tokenPos @ _) =>
|
||||||
val keyWithM = encodeKeyWithMaintainers(keyPos, tmplKey)
|
val keyWithM = encodeKeyWithMaintainers(keyPos, tmplKey)
|
||||||
val keyWithMPos = nextPosition()
|
val keyWithMPos = nextPosition()
|
||||||
val fetchKey = SBUFetchKey(tmplId)(svar(keyWithMPos), svar(tokenPos))
|
val fetchKey = SBUFetchKey(tmplId)(svar(keyWithMPos))
|
||||||
val cidPos = nextPosition()
|
val cidPos = nextPosition()
|
||||||
val fetch = SBUFetch(tmplId)(svar(cidPos), svar(tokenPos))
|
val fetch = SBUFetch(tmplId)(svar(cidPos))
|
||||||
val contractPos = nextPositionWithExprName(tmpl.param)
|
val contractPos = nextPositionWithExprName(tmpl.param)
|
||||||
val insertNode = SBUInsertFetchNode(tmplId, byKey = true)(
|
val insertNode = SBUInsertFetchNode(tmplId, byKey = true)(
|
||||||
svar(cidPos),
|
svar(cidPos),
|
||||||
compile(tmpl.signatories),
|
compile(tmpl.signatories),
|
||||||
compile(tmpl.observers),
|
compile(tmpl.observers),
|
||||||
SBSome(svar(keyWithMPos)),
|
SBSome(svar(keyWithMPos)),
|
||||||
svar(tokenPos)
|
|
||||||
)
|
)
|
||||||
nextPosition()
|
nextPosition()
|
||||||
|
|
||||||
|
@ -848,16 +848,14 @@ private[lf] object SBuiltin {
|
|||||||
* -> List Party (signatories)
|
* -> List Party (signatories)
|
||||||
* -> List Party (observers)
|
* -> List Party (observers)
|
||||||
* -> Optional {key: key, maintainers: List Party} (template key, if present)
|
* -> Optional {key: key, maintainers: List Party} (template key, if present)
|
||||||
* -> Token
|
|
||||||
* -> ContractId arg
|
* -> 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(
|
override protected final def execute(
|
||||||
args: util.ArrayList[SValue],
|
args: util.ArrayList[SValue],
|
||||||
machine: Machine,
|
machine: Machine,
|
||||||
onLedger: OnLedger
|
onLedger: OnLedger
|
||||||
): Unit = {
|
): Unit = {
|
||||||
checkToken(args.get(5))
|
|
||||||
val createArg = args.get(0)
|
val createArg = args.get(0)
|
||||||
val createArgValue = createArg.toValue
|
val createArgValue = createArg.toValue
|
||||||
val agreement = args.get(1) match {
|
val agreement = args.get(1) match {
|
||||||
@ -895,7 +893,6 @@ private[lf] object SBuiltin {
|
|||||||
* -> List Party (observers)
|
* -> List Party (observers)
|
||||||
* -> List Party (choice controllers)
|
* -> List Party (choice controllers)
|
||||||
* -> Optional {key: key, maintainers: List Party} (template key, if present)
|
* -> Optional {key: key, maintainers: List Party} (template key, if present)
|
||||||
* -> Token
|
|
||||||
* -> ()
|
* -> ()
|
||||||
*/
|
*/
|
||||||
final case class SBUBeginExercise(
|
final case class SBUBeginExercise(
|
||||||
@ -903,14 +900,13 @@ private[lf] object SBuiltin {
|
|||||||
choiceId: ChoiceName,
|
choiceId: ChoiceName,
|
||||||
consuming: Boolean,
|
consuming: Boolean,
|
||||||
byKey: Boolean,
|
byKey: Boolean,
|
||||||
) extends OnLedgerBuiltin(8) {
|
) extends OnLedgerBuiltin(7) {
|
||||||
|
|
||||||
override protected final def execute(
|
override protected final def execute(
|
||||||
args: util.ArrayList[SValue],
|
args: util.ArrayList[SValue],
|
||||||
machine: Machine,
|
machine: Machine,
|
||||||
onLedger: OnLedger
|
onLedger: OnLedger
|
||||||
): Unit = {
|
): Unit = {
|
||||||
checkToken(args.get(7))
|
|
||||||
val arg = args.get(0).toValue
|
val arg = args.get(0).toValue
|
||||||
val coid = args.get(1) match {
|
val coid = args.get(1) match {
|
||||||
case SContractId(coid) => coid
|
case SContractId(coid) => coid
|
||||||
@ -950,18 +946,16 @@ private[lf] object SBuiltin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** $endExercise[T]
|
/** $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(
|
override protected final def execute(
|
||||||
args: util.ArrayList[SValue],
|
args: util.ArrayList[SValue],
|
||||||
machine: Machine,
|
machine: Machine,
|
||||||
onLedger: OnLedger
|
onLedger: OnLedger
|
||||||
): Unit = {
|
): Unit = {
|
||||||
checkToken(args.get(0))
|
val exerciseResult = args.get(0).toValue
|
||||||
val exerciseResult = args.get(1).toValue
|
|
||||||
onLedger.ptx = onLedger.ptx.endExercises(exerciseResult)
|
onLedger.ptx = onLedger.ptx.endExercises(exerciseResult)
|
||||||
checkAborted(onLedger.ptx)
|
checkAborted(onLedger.ptx)
|
||||||
machine.returnValue = SUnit
|
machine.returnValue = SUnit
|
||||||
@ -970,16 +964,14 @@ private[lf] object SBuiltin {
|
|||||||
|
|
||||||
/** $fetch[T]
|
/** $fetch[T]
|
||||||
* :: ContractId a
|
* :: ContractId a
|
||||||
* -> Token
|
|
||||||
* -> a
|
* -> a
|
||||||
*/
|
*/
|
||||||
final case class SBUFetch(templateId: TypeConName) extends OnLedgerBuiltin(2) {
|
final case class SBUFetch(templateId: TypeConName) extends OnLedgerBuiltin(1) {
|
||||||
override protected final def execute(
|
override protected final def execute(
|
||||||
args: util.ArrayList[SValue],
|
args: util.ArrayList[SValue],
|
||||||
machine: Machine,
|
machine: Machine,
|
||||||
onLedger: OnLedger
|
onLedger: OnLedger
|
||||||
): Unit = {
|
): Unit = {
|
||||||
checkToken(args.get(1))
|
|
||||||
val coid = args.get(0) match {
|
val coid = args.get(0) match {
|
||||||
case SContractId(coid) => coid
|
case SContractId(coid) => coid
|
||||||
case v => crash(s"expected contract id, got: $v")
|
case v => crash(s"expected contract id, got: $v")
|
||||||
@ -1024,17 +1016,15 @@ private[lf] object SBuiltin {
|
|||||||
* -> List Party (signatories)
|
* -> List Party (signatories)
|
||||||
* -> List Party (observers)
|
* -> List Party (observers)
|
||||||
* -> Optional {key: key, maintainers: List Party} (template key, if present)
|
* -> Optional {key: key, maintainers: List Party} (template key, if present)
|
||||||
* -> Token
|
|
||||||
* -> ()
|
* -> ()
|
||||||
*/
|
*/
|
||||||
final case class SBUInsertFetchNode(templateId: TypeConName, byKey: Boolean)
|
final case class SBUInsertFetchNode(templateId: TypeConName, byKey: Boolean)
|
||||||
extends OnLedgerBuiltin(5) {
|
extends OnLedgerBuiltin(4) {
|
||||||
override protected final def execute(
|
override protected final def execute(
|
||||||
args: util.ArrayList[SValue],
|
args: util.ArrayList[SValue],
|
||||||
machine: Machine,
|
machine: Machine,
|
||||||
onLedger: OnLedger
|
onLedger: OnLedger
|
||||||
): Unit = {
|
): Unit = {
|
||||||
checkToken(args.get(4))
|
|
||||||
val coid = args.get(0) match {
|
val coid = args.get(0) match {
|
||||||
case SContractId(coid) => coid
|
case SContractId(coid) => coid
|
||||||
case v => crash(s"expected contract id, got: $v")
|
case v => crash(s"expected contract id, got: $v")
|
||||||
@ -1063,16 +1053,14 @@ private[lf] object SBuiltin {
|
|||||||
|
|
||||||
/** $lookupKey[T]
|
/** $lookupKey[T]
|
||||||
* :: { key: key, maintainers: List Party }
|
* :: { key: key, maintainers: List Party }
|
||||||
* -> Token
|
|
||||||
* -> Maybe (ContractId T)
|
* -> 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(
|
override protected final def execute(
|
||||||
args: util.ArrayList[SValue],
|
args: util.ArrayList[SValue],
|
||||||
machine: Machine,
|
machine: Machine,
|
||||||
onLedger: OnLedger
|
onLedger: OnLedger
|
||||||
): Unit = {
|
): Unit = {
|
||||||
checkToken(args.get(1))
|
|
||||||
val keyWithMaintainers =
|
val keyWithMaintainers =
|
||||||
extractKeyWithMaintainers(args.get(0))
|
extractKeyWithMaintainers(args.get(0))
|
||||||
val gkey = GlobalKey(templateId, keyWithMaintainers.key)
|
val gkey = GlobalKey(templateId, keyWithMaintainers.key)
|
||||||
@ -1112,16 +1100,14 @@ private[lf] object SBuiltin {
|
|||||||
/** $insertLookup[T]
|
/** $insertLookup[T]
|
||||||
* :: { key : key, maintainers: List Party}
|
* :: { key : key, maintainers: List Party}
|
||||||
* -> Maybe (ContractId T)
|
* -> 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(
|
override protected final def execute(
|
||||||
args: util.ArrayList[SValue],
|
args: util.ArrayList[SValue],
|
||||||
machine: Machine,
|
machine: Machine,
|
||||||
onLedger: OnLedger
|
onLedger: OnLedger
|
||||||
): Unit = {
|
): Unit = {
|
||||||
checkToken(args.get(2))
|
|
||||||
val keyWithMaintainers = extractKeyWithMaintainers(args.get(0))
|
val keyWithMaintainers = extractKeyWithMaintainers(args.get(0))
|
||||||
val mbCoid = args.get(1) match {
|
val mbCoid = args.get(1) match {
|
||||||
case SOptional(mb) =>
|
case SOptional(mb) =>
|
||||||
@ -1149,16 +1135,14 @@ private[lf] object SBuiltin {
|
|||||||
|
|
||||||
/** $fetchKey[T]
|
/** $fetchKey[T]
|
||||||
* :: { key: key, maintainers: List Party }
|
* :: { key: key, maintainers: List Party }
|
||||||
* -> Token
|
|
||||||
* -> ContractId T
|
* -> 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(
|
override protected final def execute(
|
||||||
args: util.ArrayList[SValue],
|
args: util.ArrayList[SValue],
|
||||||
machine: Machine,
|
machine: Machine,
|
||||||
onLedger: OnLedger
|
onLedger: OnLedger
|
||||||
): Unit = {
|
): Unit = {
|
||||||
checkToken(args.get(1))
|
|
||||||
val keyWithMaintainers = extractKeyWithMaintainers(args.get(0))
|
val keyWithMaintainers = extractKeyWithMaintainers(args.get(0))
|
||||||
val gkey = GlobalKey(templateId, keyWithMaintainers.key)
|
val gkey = GlobalKey(templateId, keyWithMaintainers.key)
|
||||||
// check if we find it locally
|
// check if we find it locally
|
||||||
|
Loading…
Reference in New Issue
Block a user