mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
Tidy up of Compiler.scala to ensure translate and compile naming conventions are used throughout
CHANGELOG_BEGIN * Tidy up of Compiler.scala to ensure translate and compile naming conventions are used throughout. CHANGELOG_END
This commit is contained in:
parent
a7ed284815
commit
0bf28176a7
@ -14,8 +14,8 @@ import com.daml.lf.speedy.PhaseOne.{Env, Position}
|
|||||||
import com.daml.lf.speedy.Profile.LabelModule
|
import com.daml.lf.speedy.Profile.LabelModule
|
||||||
import com.daml.lf.speedy.SBuiltin._
|
import com.daml.lf.speedy.SBuiltin._
|
||||||
import com.daml.lf.speedy.SValue._
|
import com.daml.lf.speedy.SValue._
|
||||||
import com.daml.lf.speedy.{SExpr => t}
|
import com.daml.lf.speedy.{SExpr => t} // target expressions
|
||||||
import com.daml.lf.speedy.{SExpr0 => s}
|
import com.daml.lf.speedy.{SExpr0 => s} // source expressions
|
||||||
import com.daml.lf.validation.{Validation, ValidationError}
|
import com.daml.lf.validation.{Validation, ValidationError}
|
||||||
import com.daml.scalautil.Statement.discard
|
import com.daml.scalautil.Statement.discard
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ private[lf] final class Compiler(
|
|||||||
|
|
||||||
private[this] val logger = LoggerFactory.getLogger(this.getClass)
|
private[this] val logger = LoggerFactory.getLogger(this.getClass)
|
||||||
|
|
||||||
// We add labels before and after flattenning
|
// We add labels before and after flattening
|
||||||
|
|
||||||
private[this] val withLabelS: (Profile.Label, s.SExpr) => s.SExpr =
|
private[this] val withLabelS: (Profile.Label, s.SExpr) => s.SExpr =
|
||||||
config.profiling match {
|
config.profiling match {
|
||||||
@ -197,7 +197,7 @@ private[lf] final class Compiler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private[this] def app(f: s.SExpr, a: s.SExpr) = s.SEApp(f, List(a))
|
private[this] def app(f: s.SExpr, a: s.SExpr): s.SExpr = s.SEApp(f, List(a))
|
||||||
|
|
||||||
private[this] def let(env: Env, bound: s.SExpr)(f: (Position, Env) => s.SExpr): s.SELet =
|
private[this] def let(env: Env, bound: s.SExpr)(f: (Position, Env) => s.SExpr): s.SELet =
|
||||||
f(env.nextPosition, env.pushVar) match {
|
f(env.nextPosition, env.pushVar) match {
|
||||||
@ -235,16 +235,16 @@ private[lf] final class Compiler(
|
|||||||
private val Pos4 = Env3.nextPosition
|
private val Pos4 = Env3.nextPosition
|
||||||
private val Env4 = Env3.pushVar
|
private val Env4 = Env3.pushVar
|
||||||
|
|
||||||
private[this] def fun1(body: (Position, Env) => s.SExpr) =
|
private[this] def fun1(body: (Position, Env) => s.SExpr): s.SExpr =
|
||||||
s.SEAbs(1, body(Pos1, Env1))
|
s.SEAbs(1, body(Pos1, Env1))
|
||||||
|
|
||||||
private[this] def fun2(body: (Position, Position, Env) => s.SExpr) =
|
private[this] def fun2(body: (Position, Position, Env) => s.SExpr): s.SExpr =
|
||||||
s.SEAbs(2, body(Pos1, Pos2, Env2))
|
s.SEAbs(2, body(Pos1, Pos2, Env2))
|
||||||
|
|
||||||
private[this] def fun3(body: (Position, Position, Position, Env) => s.SExpr) =
|
private[this] def fun3(body: (Position, Position, Position, Env) => s.SExpr): s.SExpr =
|
||||||
s.SEAbs(3, body(Pos1, Pos2, Pos3, Env3))
|
s.SEAbs(3, body(Pos1, Pos2, Pos3, Env3))
|
||||||
|
|
||||||
private[this] def fun4(body: (Position, Position, Position, Position, Env) => s.SExpr) =
|
private[this] def fun4(body: (Position, Position, Position, Position, Env) => s.SExpr): s.SExpr =
|
||||||
s.SEAbs(4, body(Pos1, Pos2, Pos3, Pos4, Env4))
|
s.SEAbs(4, body(Pos1, Pos2, Pos3, Pos4, Env4))
|
||||||
|
|
||||||
private[this] def topLevelFunction1[SDefRef <: t.SDefinitionRef: LabelModule.Allowed](
|
private[this] def topLevelFunction1[SDefRef <: t.SDefinitionRef: LabelModule.Allowed](
|
||||||
@ -280,7 +280,7 @@ private[lf] final class Compiler(
|
|||||||
): (SDefRef, SDefinition) =
|
): (SDefRef, SDefinition) =
|
||||||
topLevelFunction(ref)(fun4(body))
|
topLevelFunction(ref)(fun4(body))
|
||||||
|
|
||||||
val phaseOne = {
|
val phaseOne: PhaseOne = {
|
||||||
val config1 =
|
val config1 =
|
||||||
PhaseOne.Config(
|
PhaseOne.Config(
|
||||||
profiling = config.profiling,
|
profiling = config.profiling,
|
||||||
@ -312,7 +312,7 @@ private[lf] final class Compiler(
|
|||||||
module: Module,
|
module: Module,
|
||||||
): Iterable[(t.SDefinitionRef, SDefinition)] = {
|
): Iterable[(t.SDefinitionRef, SDefinition)] = {
|
||||||
val builder = Iterable.newBuilder[(t.SDefinitionRef, SDefinition)]
|
val builder = Iterable.newBuilder[(t.SDefinitionRef, SDefinition)]
|
||||||
def addDef(binding: (t.SDefinitionRef, SDefinition)) = discard(builder += binding)
|
def addDef(binding: (t.SDefinitionRef, SDefinition)): Unit = discard(builder += binding)
|
||||||
|
|
||||||
module.exceptions.foreach { case (defName, GenDefException(message)) =>
|
module.exceptions.foreach { case (defName, GenDefException(message)) =>
|
||||||
val ref = t.ExceptionMessageDefRef(Identifier(pkgId, QualifiedName(module.name, defName)))
|
val ref = t.ExceptionMessageDefRef(Identifier(pkgId, QualifiedName(module.name, defName)))
|
||||||
@ -431,7 +431,7 @@ private[lf] final class Compiler(
|
|||||||
cidPos: Position,
|
cidPos: Position,
|
||||||
mbKey: Option[Position], // defined for byKey operation
|
mbKey: Option[Position], // defined for byKey operation
|
||||||
tokenPos: Position,
|
tokenPos: Position,
|
||||||
) =
|
): s.SExpr =
|
||||||
let(
|
let(
|
||||||
env,
|
env,
|
||||||
SBCastAnyContract(typeId)(
|
SBCastAnyContract(typeId)(
|
||||||
@ -482,7 +482,7 @@ private[lf] final class Compiler(
|
|||||||
cidPos: Position,
|
cidPos: Position,
|
||||||
choiceArgPos: Position,
|
choiceArgPos: Position,
|
||||||
tokenPos: Position,
|
tokenPos: Position,
|
||||||
) =
|
): s.SExpr =
|
||||||
let(
|
let(
|
||||||
env,
|
env,
|
||||||
SBCastAnyInterface(ifaceId)(
|
SBCastAnyInterface(ifaceId)(
|
||||||
@ -570,7 +570,7 @@ private[lf] final class Compiler(
|
|||||||
// Compiles a choice into:
|
// Compiles a choice into:
|
||||||
// ChoiceByKeyDefRef(SomeTemplate, SomeChoice) = \ <actors> <key> <choiceArg> <token> ->
|
// ChoiceByKeyDefRef(SomeTemplate, SomeChoice) = \ <actors> <key> <choiceArg> <token> ->
|
||||||
// let <keyWithM> = { key = <key> ; maintainers = [tmpl.maintainers] <key> }
|
// let <keyWithM> = { key = <key> ; maintainers = [tmpl.maintainers] <key> }
|
||||||
// <cid> = $fecthKey(tmplId) <keyWithM>
|
// <cid> = $fetchKey(tmplId) <keyWithM>
|
||||||
// targ = fetch <cid>
|
// targ = fetch <cid>
|
||||||
// _ = $beginExercise[tmplId, choice.name, choice.consuming, true] <choiceArg> <cid> <actors> [tmpl.signatories] [tmpl.observers] [choice.controllers] (Some <keyWithM>)
|
// _ = $beginExercise[tmplId, choice.name, choice.consuming, true] <choiceArg> <cid> <actors> [tmpl.signatories] [tmpl.observers] [choice.controllers] (Some <keyWithM>)
|
||||||
// <retValue> = <updateE> <token>
|
// <retValue> = <updateE> <token>
|
||||||
@ -591,11 +591,11 @@ private[lf] final class Compiler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nowarn("msg=parameter value tokenPos.* is never used")
|
@nowarn("msg=parameter value tokenPos.* is never used")
|
||||||
private[this] def compileFetchTemplateBody(env: Env, tmplId: Identifier, tmpl: Template)(
|
private[this] def translateFetchTemplateBody(env: Env, tmplId: Identifier, tmpl: Template)(
|
||||||
cidPos: Position,
|
cidPos: Position,
|
||||||
mbKey: Option[Position], // defined for byKey operation
|
mbKey: Option[Position], // defined for byKey operation
|
||||||
tokenPos: Position,
|
tokenPos: Position,
|
||||||
) =
|
): s.SExpr =
|
||||||
let(
|
let(
|
||||||
env,
|
env,
|
||||||
SBCastAnyContract(tmplId)(
|
SBCastAnyContract(tmplId)(
|
||||||
@ -625,7 +625,7 @@ private[lf] final class Compiler(
|
|||||||
// _ = $insertFetch(tmplId, false) coid [tmpl.signatories] [tmpl.observers] [tmpl.key]
|
// _ = $insertFetch(tmplId, false) coid [tmpl.signatories] [tmpl.observers] [tmpl.key]
|
||||||
// in <tmplArg>
|
// in <tmplArg>
|
||||||
topLevelFunction2(t.FetchTemplateDefRef(tmplId)) { (cidPos, tokenPos, env) =>
|
topLevelFunction2(t.FetchTemplateDefRef(tmplId)) { (cidPos, tokenPos, env) =>
|
||||||
compileFetchTemplateBody(env, tmplId, tmpl)(cidPos, None, tokenPos)
|
translateFetchTemplateBody(env, tmplId, tmpl)(cidPos, None, tokenPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
private[this] def compileFetchInterface(ifaceId: Identifier): (t.SDefinitionRef, SDefinition) =
|
private[this] def compileFetchInterface(ifaceId: Identifier): (t.SDefinitionRef, SDefinition) =
|
||||||
@ -650,7 +650,7 @@ private[lf] final class Compiler(
|
|||||||
iface: Identifier,
|
iface: Identifier,
|
||||||
param: ExprVarName,
|
param: ExprVarName,
|
||||||
expr: Expr,
|
expr: Expr,
|
||||||
) =
|
): (t.SDefinitionRef, SDefinition) =
|
||||||
topLevelFunction1(t.InterfacePrecondDefRef(iface))((argPos, env) =>
|
topLevelFunction1(t.InterfacePrecondDefRef(iface))((argPos, env) =>
|
||||||
translateExp(env.bindExprVar(param, argPos), expr)
|
translateExp(env.bindExprVar(param, argPos), expr)
|
||||||
)
|
)
|
||||||
@ -749,7 +749,7 @@ private[lf] final class Compiler(
|
|||||||
tmpl: Template,
|
tmpl: Template,
|
||||||
tmplArgPos: Position,
|
tmplArgPos: Position,
|
||||||
env: Env,
|
env: Env,
|
||||||
) = {
|
): s.SExpr = {
|
||||||
val env2 = env.bindExprVar(tmpl.param, tmplArgPos)
|
val env2 = env.bindExprVar(tmpl.param, tmplArgPos)
|
||||||
val implementsPrecondsIterator = tmpl.implements.iterator.map[s.SExpr](impl =>
|
val implementsPrecondsIterator = tmpl.implements.iterator.map[s.SExpr](impl =>
|
||||||
// `SBToInterface` is needed because interfaces do not have the same representation as the underlying template
|
// `SBToInterface` is needed because interfaces do not have the same representation as the underlying template
|
||||||
@ -784,7 +784,7 @@ private[lf] final class Compiler(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private[this] def compileCreateAndExercise(
|
private[this] def translateCreateAndExercise(
|
||||||
env: Env,
|
env: Env,
|
||||||
tmplId: Identifier,
|
tmplId: Identifier,
|
||||||
createArg: SValue,
|
createArg: SValue,
|
||||||
@ -846,7 +846,7 @@ private[lf] final class Compiler(
|
|||||||
let(env, SBUFetchKey(tmplId)(env.toSEVar(keyWithMPos))) { (cidPos, env) =>
|
let(env, SBUFetchKey(tmplId)(env.toSEVar(keyWithMPos))) { (cidPos, env) =>
|
||||||
let(
|
let(
|
||||||
env,
|
env,
|
||||||
compileFetchTemplateBody(env, tmplId, tmpl)(cidPos, Some(keyWithMPos), tokenPos),
|
translateFetchTemplateBody(env, tmplId, tmpl)(cidPos, Some(keyWithMPos), tokenPos),
|
||||||
) { (contractPos, env) =>
|
) { (contractPos, env) =>
|
||||||
FetchByKeyResult(env.toSEVar(cidPos), env.toSEVar(contractPos))
|
FetchByKeyResult(env.toSEVar(cidPos), env.toSEVar(contractPos))
|
||||||
}
|
}
|
||||||
@ -854,7 +854,7 @@ private[lf] final class Compiler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private[this] def compileExerciseByInterface(
|
private[this] def translateExerciseByInterface(
|
||||||
env: Env,
|
env: Env,
|
||||||
interfaceId: TypeConName,
|
interfaceId: TypeConName,
|
||||||
templateId: TypeConName,
|
templateId: TypeConName,
|
||||||
@ -871,7 +871,7 @@ private[lf] final class Compiler(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private[this] def compileExerciseByInheritedInterface(
|
private[this] def translateExerciseByInheritedInterface(
|
||||||
env: Env,
|
env: Env,
|
||||||
requiredIfaceId: TypeConName,
|
requiredIfaceId: TypeConName,
|
||||||
requiringIfaceId: TypeConName,
|
requiringIfaceId: TypeConName,
|
||||||
@ -897,7 +897,7 @@ private[lf] final class Compiler(
|
|||||||
case Command.ExerciseTemplate(templateId, contractId, choiceId, argument) =>
|
case Command.ExerciseTemplate(templateId, contractId, choiceId, argument) =>
|
||||||
t.TemplateChoiceDefRef(templateId, choiceId)(s.SEValue(contractId), s.SEValue(argument))
|
t.TemplateChoiceDefRef(templateId, choiceId)(s.SEValue(contractId), s.SEValue(argument))
|
||||||
case Command.ExerciseByInterface(interfaceId, templateId, contractId, choiceId, argument) =>
|
case Command.ExerciseByInterface(interfaceId, templateId, contractId, choiceId, argument) =>
|
||||||
compileExerciseByInterface(env, interfaceId, templateId, contractId, choiceId, argument)
|
translateExerciseByInterface(env, interfaceId, templateId, contractId, choiceId, argument)
|
||||||
case Command.ExerciseInterface(interfaceId, contractId, choiceId, argument) =>
|
case Command.ExerciseInterface(interfaceId, contractId, choiceId, argument) =>
|
||||||
t.InterfaceChoiceDefRef(interfaceId, choiceId)(
|
t.InterfaceChoiceDefRef(interfaceId, choiceId)(
|
||||||
s.SEBuiltin(SBGuardConstTrue),
|
s.SEBuiltin(SBGuardConstTrue),
|
||||||
@ -911,7 +911,7 @@ private[lf] final class Compiler(
|
|||||||
choiceId,
|
choiceId,
|
||||||
argument,
|
argument,
|
||||||
) =>
|
) =>
|
||||||
compileExerciseByInheritedInterface(
|
translateExerciseByInheritedInterface(
|
||||||
env,
|
env,
|
||||||
requiredIfaceId,
|
requiredIfaceId,
|
||||||
requiringIfaceId,
|
requiringIfaceId,
|
||||||
@ -928,7 +928,7 @@ private[lf] final class Compiler(
|
|||||||
case Command.FetchByKey(templateId, key) =>
|
case Command.FetchByKey(templateId, key) =>
|
||||||
t.FetchByKeyDefRef(templateId)(s.SEValue(key))
|
t.FetchByKeyDefRef(templateId)(s.SEValue(key))
|
||||||
case Command.CreateAndExercise(templateId, createArg, choice, choiceArg) =>
|
case Command.CreateAndExercise(templateId, createArg, choice, choiceArg) =>
|
||||||
compileCreateAndExercise(
|
translateCreateAndExercise(
|
||||||
env,
|
env,
|
||||||
templateId,
|
templateId,
|
||||||
createArg,
|
createArg,
|
||||||
|
Loading…
Reference in New Issue
Block a user