Skip to content

Commit

Permalink
scalafmt and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sofiafaro-da committed Nov 11, 2021
1 parent 122b8b2 commit 945922d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ private[daml] class EncodeV1(minor: LV.Minor) {
case UpdateCreate(templateId, arg) =>
builder.setCreate(PLF.Update.Create.newBuilder().setTemplate(templateId).setExpr(arg))
case UpdateCreateInterface(interface, arg) =>
builder.setCreateInterface(PLF.Update.CreateInterface.newBuilder().setTemplate(interface).setExpr(arg))
builder.setCreateInterface(
PLF.Update.CreateInterface.newBuilder().setTemplate(interface).setExpr(arg)
)
case UpdateFetch(templateId, contractId) =>
builder.setFetch(PLF.Update.Fetch.newBuilder().setTemplate(templateId).setCid(contractId))
case UpdateFetchInterface(interface, contractId) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1538,15 +1538,12 @@ private[lf] final class Compiler(
ref -> SDefinition(withLabel(ref, unsafeCompile(method.value)))
}

@nowarn("msg=parameter value tokenPos in method compileCreateBody is never used")
private[this] def compileCreateBody(
tmplId: Identifier,
tmpl: Template,
byInterface: Option[Identifier],
)(
tmplArgPos: Position,
tokenPos: Position,
env: Env
tmplArgPos: Position,
env: Env,
) = {
val precondsArray =
(Iterator(tmpl.precond) ++ (tmpl.implements.iterator.map(impl => impl._2.precond)))
Expand Down Expand Up @@ -1576,7 +1573,9 @@ private[lf] final class Compiler(
// CreateDefRef(tmplId) = \ <tmplArg> <token> ->
// let _ = $checkPrecond(tmplId)(<tmplArg> [tmpl.precond ++ [precond | precond <- tmpl.implements]]
// in $create <tmplArg> [tmpl.agreementText] [tmpl.signatories] [tmpl.observers] [tmpl.key]
topLevelFunction2(CreateDefRef(tmplId)) (compileCreateBody(tmplId, tmpl, None))
topLevelFunction2(CreateDefRef(tmplId))((tmplArgPos, _, env) =>
compileCreateBody(tmplId, tmpl, None, tmplArgPos, env)
)
}

private[this] def compileCreateByInterface(
Expand All @@ -1585,14 +1584,20 @@ private[lf] final class Compiler(
ifaceId: Identifier,
): (SDefinitionRef, SDefinition) = {
// Similar to compileCreate, but sets the 'byInterface' field in the transaction.
topLevelFunction2(CreateByInterfaceDefRef(tmplId, ifaceId)) (compileCreateBody(tmplId, tmpl, Some(ifaceId)))
topLevelFunction2(CreateByInterfaceDefRef(tmplId, ifaceId))((tmplArgPos, _, env) =>
compileCreateBody(tmplId, tmpl, Some(ifaceId), tmplArgPos, env)
)
}

private[this] def compileCreateInterface(
ifaceId: Identifier,
ifaceId: Identifier
): (SDefinitionRef, SDefinition) = {
topLevelFunction2(CreateDefRef(ifaceId)) { (tmplArgPos, tokenPos, env) =>
SBResolveCreateByInterface(ifaceId) (env.toSEVar(tmplArgPos), env.toSEVar(tmplArgPos), env.toSEVar(tokenPos))
SBResolveCreateByInterface(ifaceId)(
env.toSEVar(tmplArgPos),
env.toSEVar(tmplArgPos),
env.toSEVar(tokenPos),
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,9 @@ private[lf] object Pretty {
case SBUCreate(ref, None) =>
text("$create") + char('[') + text(ref.qualifiedName.toString) + char(']')
case SBUCreate(ref, Some(iface)) =>
text("$createByInterface") + char('[') + text(ref.qualifiedName.toString) + char(',') + text(iface.qualifiedName.toString) + char(']')
text("$createByInterface") + char('[') + text(ref.qualifiedName.toString) + char(
','
) + text(iface.qualifiedName.toString) + char(']')
case SBUFetch(ref) =>
text("$fetch") + char('[') + text(ref.qualifiedName.toString) + char(']')
case SBGetTime => text("$getTime")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ object Profile {
case AnonymousClosure => "<lambda>"
case LfDefRef(ref) => ref.qualifiedName.toString()
case CreateDefRef(tmplRef) => s"create @${tmplRef.qualifiedName}"
case CreateByInterfaceDefRef(tmplRef,iface) => s"creatByInterface @${tmplRef.qualifiedName} @${iface.qualifiedName}"
case CreateByInterfaceDefRef(tmplRef, iface) =>
s"creatByInterface @${tmplRef.qualifiedName} @${iface.qualifiedName}"
case KeyDefRef(tmplRef) => s"keyAndMaintainers @${tmplRef.qualifiedName}"
case SignatoriesDefRef(tmplRef) => s"signatories @${tmplRef.qualifiedName}"
case ObserversDefRef(tmplRef) => s"observers @${tmplRef.qualifiedName}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,8 @@ private[lf] object SBuiltin {
* -> Optional {key: key, maintainers: List Party} (template key, if present)
* -> ContractId arg
*/
final case class SBUCreate(templateId: TypeConName, byInterface: Option[TypeConName]) extends OnLedgerBuiltin(5) {
final case class SBUCreate(templateId: TypeConName, byInterface: Option[TypeConName])
extends OnLedgerBuiltin(5) {
override protected def execute(
args: util.ArrayList[SValue],
machine: Machine,
Expand Down Expand Up @@ -1176,8 +1177,8 @@ private[lf] object SBuiltin {
machine.ctrl = SEVal(toDef(getSRecord(args, 0).id))
}

final case class SBResolveCreateByInterface(ifaceId: TypeConName) extends
SBResolveVirtual(ref => CreateByInterfaceDefRef(ref, ifaceId))
final case class SBResolveCreateByInterface(ifaceId: TypeConName)
extends SBResolveVirtual(ref => CreateByInterfaceDefRef(ref, ifaceId))

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ object SExpr {
final case class ChoiceByKeyDefRef(ref: DefinitionRef, choiceName: ChoiceName)
extends SDefinitionRef
final case class CreateDefRef(ref: DefinitionRef) extends SDefinitionRef
final case class CreateByInterfaceDefRef(ref: DefinitionRef, iface: TypeConName) extends SDefinitionRef
final case class CreateByInterfaceDefRef(ref: DefinitionRef, iface: TypeConName)
extends SDefinitionRef
final case class FetchDefRef(ref: DefinitionRef) extends SDefinitionRef
final case class FetchByKeyDefRef(ref: DefinitionRef) extends SDefinitionRef
final case class LookupByKeyDefRef(ref: DefinitionRef) extends SDefinitionRef
Expand Down

0 comments on commit 945922d

Please sign in to comment.