Skip to content

Commit

Permalink
LF: Rename GenNode to Node
Browse files Browse the repository at this point in the history
Following up #10827 and #10921 that drop type parameters from GenNode,
we rename GenNode into Node.

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da committed Nov 2, 2021
1 parent 565dfac commit 7a8558c
Show file tree
Hide file tree
Showing 49 changed files with 723 additions and 686 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.daml.lf.data.{ImmArray, Numeric, Ref}
import com.daml.lf.ledger.EventId
import com.daml.lf.scenario.api.{v1 => proto}
import com.daml.lf.speedy.{SError, SValue, TraceLog, Warning, WarningLog}
import com.daml.lf.transaction.{GlobalKey, IncompleteTransaction, Node => N, NodeId}
import com.daml.lf.transaction.{GlobalKey, IncompleteTransaction, Node, NodeId}
import com.daml.lf.ledger._
import com.daml.lf.value.{Value => V}

Expand All @@ -34,7 +34,7 @@ final class Conversions(
private val ptxCoidToNodeId = incomplete
.map(_.transaction.nodes)
.getOrElse(Map.empty)
.collect { case (nodeId, node: N.NodeCreate) =>
.collect { case (nodeId, node: Node.Create) =>
node.coid -> ledger.ptxEventId(nodeId)
}

Expand Down Expand Up @@ -480,13 +480,13 @@ final class Conversions(
.map(eventId => builder.setParent(convertEventId(eventId)))

nodeInfo.node match {
case rollback: N.NodeRollback =>
case rollback: Node.Rollback =>
val rollbackBuilder = proto.Node.Rollback.newBuilder
.addAllChildren(
rollback.children.map(convertNodeId(eventId.transactionId, _)).toSeq.asJava
)
builder.setRollback(rollbackBuilder.build)
case create: N.NodeCreate =>
case create: Node.Create =>
val createBuilder =
proto.Node.Create.newBuilder
.setContractInstance(
Expand All @@ -500,7 +500,7 @@ final class Conversions(

nodeInfo.optLocation.map(loc => builder.setLocation(convertLocation(loc)))
builder.setCreate(createBuilder.build)
case fetch: N.NodeFetch =>
case fetch: Node.Fetch =>
builder.setFetch(
proto.Node.Fetch.newBuilder
.setContractId(coidToEventId(fetch.coid).toLedgerString)
Expand All @@ -509,7 +509,7 @@ final class Conversions(
.addAllStakeholders(fetch.stakeholders.map(convertParty).asJava)
.build
)
case ex: N.NodeExercises =>
case ex: Node.Exercise =>
nodeInfo.optLocation.map(loc => builder.setLocation(convertLocation(loc)))
val exerciseBuilder =
proto.Node.Exercise.newBuilder
Expand All @@ -534,7 +534,7 @@ final class Conversions(

builder.setExercise(exerciseBuilder.build)

case lbk: N.NodeLookupByKey =>
case lbk: Node.LookupByKey =>
nodeInfo.optLocation.foreach(loc => builder.setLocation(convertLocation(loc)))
val lbkBuilder = proto.Node.LookupByKey.newBuilder
.setTemplateId(convertIdentifier(lbk.templateId))
Expand All @@ -547,7 +547,7 @@ final class Conversions(
}

def convertKeyWithMaintainers(
key: N.KeyWithMaintainers[V.VersionedValue]
key: Node.KeyWithMaintainers[V.VersionedValue]
): proto.KeyWithMaintainers = {
proto.KeyWithMaintainers
.newBuilder()
Expand All @@ -558,15 +558,15 @@ final class Conversions(

def convertIncompleteTransactionNode(
locationInfo: Map[NodeId, Ref.Location]
)(nodeWithId: (NodeId, N.GenNode)): proto.Node = {
)(nodeWithId: (NodeId, Node)): proto.Node = {
val (nodeId, node) = nodeWithId
val optLocation = locationInfo.get(nodeId)
val builder = proto.Node.newBuilder
builder
.setNodeId(proto.NodeId.newBuilder.setId(nodeId.index.toString).build)
// FIXME(JM): consumedBy, parent, ...
node match {
case rollback: N.NodeRollback =>
case rollback: Node.Rollback =>
val rollbackBuilder =
proto.Node.Rollback.newBuilder
.addAllChildren(
Expand All @@ -576,7 +576,7 @@ final class Conversions(
.asJava
)
builder.setRollback(rollbackBuilder.build)
case create: N.NodeCreate =>
case create: Node.Create =>
val createBuilder =
proto.Node.Create.newBuilder
.setContractInstance(
Expand All @@ -592,7 +592,7 @@ final class Conversions(
)
optLocation.map(loc => builder.setLocation(convertLocation(loc)))
builder.setCreate(createBuilder.build)
case fetch: N.NodeFetch =>
case fetch: Node.Fetch =>
builder.setFetch(
proto.Node.Fetch.newBuilder
.setContractId(coidToEventId(fetch.coid).toLedgerString)
Expand All @@ -601,7 +601,7 @@ final class Conversions(
.addAllStakeholders(fetch.stakeholders.map(convertParty).asJava)
.build
)
case ex: N.NodeExercises =>
case ex: Node.Exercise =>
optLocation.map(loc => builder.setLocation(convertLocation(loc)))
builder.setExercise(
proto.Node.Exercise.newBuilder
Expand All @@ -622,7 +622,7 @@ final class Conversions(
.build
)

case lookup: N.NodeLookupByKey =>
case lookup: Node.LookupByKey =>
optLocation.map(loc => builder.setLocation(convertLocation(loc)))
builder.setLookupByKey({
val builder = proto.Node.LookupByKey.newBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ package com.daml.lf.engine

import com.daml.lf.data._
import com.daml.lf.data.Ref.Party
import com.daml.lf.transaction.Node.{
NodeRollback,
NodeCreate,
NodeExercises,
NodeFetch,
NodeLookupByKey,
}
import com.daml.lf.transaction.Node
import com.daml.lf.transaction.{BlindingInfo, GenTransaction, NodeId, VersionedTransaction}
import com.daml.lf.ledger._
import com.daml.lf.data.Relation.Relation
Expand Down Expand Up @@ -69,11 +63,11 @@ object Blinding {
go(filteredRoots :+ root, remainingRoots)
} else {
tx.nodes(root) match {
case nr: NodeRollback =>
case nr: Node.Rollback =>
go(filteredRoots, nr.children ++: remainingRoots)
case _: NodeFetch | _: NodeCreate | _: NodeLookupByKey =>
case _: Node.Fetch | _: Node.Create | _: Node.LookupByKey =>
go(filteredRoots, remainingRoots)
case ne: NodeExercises =>
case ne: Node.Exercise =>
go(filteredRoots, ne.children ++: remainingRoots)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package engine

import com.daml.lf.data.Ref.{Identifier, Name, PackageId}
import com.daml.lf.language.{Ast, LookupError}
import com.daml.lf.transaction.Node.{GenNode, KeyWithMaintainers}
import com.daml.lf.transaction.{
IncompleteTransaction,
GenTransaction,
Expand Down Expand Up @@ -113,14 +112,14 @@ final class ValueEnricher(

def enrichContractKey(
tyCon: Identifier,
key: KeyWithMaintainers[Value],
): Result[KeyWithMaintainers[Value]] =
key: Node.KeyWithMaintainers[Value],
): Result[Node.KeyWithMaintainers[Value]] =
enrichContractKey(tyCon, key.key).map(normalizedKey => key.copy(key = normalizedKey))

def enrichContractKey(
tyCon: Identifier,
key: Option[KeyWithMaintainers[Value]],
): Result[Option[KeyWithMaintainers[Value]]] =
key: Option[Node.KeyWithMaintainers[Value]],
): Result[Option[Node.KeyWithMaintainers[Value]]] =
key match {
case Some(k) =>
enrichContractKey(tyCon, k).map(Some(_))
Expand All @@ -130,39 +129,39 @@ final class ValueEnricher(

def enrichVersionedContractKey(
tyCon: Identifier,
key: KeyWithMaintainers[VersionedValue],
): Result[KeyWithMaintainers[VersionedValue]] =
key: Node.KeyWithMaintainers[VersionedValue],
): Result[Node.KeyWithMaintainers[VersionedValue]] =
enrichVersionedContractKey(tyCon, key.key).map(normalizedKey => key.copy(key = normalizedKey))

def enrichVersionedContractKey(
tyCon: Identifier,
key: Option[KeyWithMaintainers[VersionedValue]],
): Result[Option[KeyWithMaintainers[VersionedValue]]] =
key: Option[Node.KeyWithMaintainers[VersionedValue]],
): Result[Option[Node.KeyWithMaintainers[VersionedValue]]] =
key match {
case Some(k) =>
enrichVersionedContractKey(tyCon, k).map(Some(_))
case None =>
ResultNone
}

def enrichNode(node: GenNode): Result[GenNode] =
def enrichNode(node: Node): Result[Node] =
node match {
case rb @ Node.NodeRollback(_) =>
case rb @ Node.Rollback(_) =>
ResultDone(rb)
case create: Node.NodeCreate =>
case create: Node.Create =>
for {
arg <- enrichValue(Ast.TTyCon(create.templateId), create.arg)
key <- enrichContractKey(create.templateId, create.key)
} yield create.copy(arg = arg, key = key)
case fetch: Node.NodeFetch =>
case fetch: Node.Fetch =>
for {
key <- enrichContractKey(fetch.templateId, fetch.key)
} yield fetch.copy(key = key)
case lookup: Node.NodeLookupByKey =>
case lookup: Node.LookupByKey =>
for {
key <- enrichContractKey(lookup.templateId, lookup.key)
} yield lookup.copy(key = key)
case exe: Node.NodeExercises =>
case exe: Node.Exercise =>
for {
choiceArg <- enrichChoiceArgument(exe.templateId, exe.choiceId, exe.chosenValue)
result <- exe.exerciseResult match {
Expand All @@ -178,7 +177,7 @@ final class ValueEnricher(
def enrichTransaction(tx: GenTransaction): Result[GenTransaction] =
for {
normalizedNodes <-
tx.nodes.foldLeft[Result[Map[NodeId, GenNode]]](ResultDone(Map.empty)) {
tx.nodes.foldLeft[Result[Map[NodeId, Node]]](ResultDone(Map.empty)) {
case (acc, (nid, node)) =>
for {
nodes <- acc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ private[preprocessing] final class TransactionPreprocessor(

val result = tx.roots.foldLeft(BackStack.empty[speedy.Command]) { (acc, id) =>
tx.nodes.get(id) match {
case Some(node: Node.GenActionNode) =>
case Some(node: Node.Action) =>
node match {
case create: Node.NodeCreate =>
case create: Node.Create =>
val cmd = commandPreprocessor.unsafePreprocessCreate(create.templateId, create.arg)
acc :+ cmd
case exe: Node.NodeExercises =>
case exe: Node.Exercise =>
val cmd = exe.key match {
case Some(key) if exe.byKey =>
commandPreprocessor.unsafePreprocessExerciseByKey(
Expand All @@ -91,12 +91,12 @@ private[preprocessing] final class TransactionPreprocessor(
)
}
acc :+ cmd
case _: Node.NodeFetch =>
case _: Node.Fetch =>
invalidRootNode(id, s"Transaction contains a fetch root node $id")
case _: Node.NodeLookupByKey =>
case _: Node.LookupByKey =>
invalidRootNode(id, s"Transaction contains a lookup by key root node $id")
}
case Some(_: Node.NodeRollback) =>
case Some(_: Node.Rollback) =>
invalidRootNode(id, s"invalid transaction, root refers to a rollback node $id")
case None =>
invalidRootNode(id, s"invalid transaction, root refers to non-existing node $id")
Expand Down
Loading

0 comments on commit 7a8558c

Please sign in to comment.