mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-19 16:57:40 +03:00
parent
53b24793f4
commit
861724e4fd
@ -201,8 +201,7 @@ class ReplService(
|
|||||||
|
|
||||||
var scriptExpr: SExpr = SEVal(
|
var scriptExpr: SExpr = SEVal(
|
||||||
LfDefRef(
|
LfDefRef(
|
||||||
Identifier(homePackageId, QualifiedName(mod.name, DottedName.assertFromString("expr")))),
|
Identifier(homePackageId, QualifiedName(mod.name, DottedName.assertFromString("expr")))))
|
||||||
None)
|
|
||||||
if (!results.isEmpty) {
|
if (!results.isEmpty) {
|
||||||
scriptExpr = SEApp(scriptExpr, results.map(SEValue(_)).toArray)
|
scriptExpr = SEApp(scriptExpr, results.map(SEValue(_)).toArray)
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ private[lf] final case class Compiler(packages: PackageId PartialFunction Packag
|
|||||||
private def translate(expr0: Expr): SExpr =
|
private def translate(expr0: Expr): SExpr =
|
||||||
expr0 match {
|
expr0 match {
|
||||||
case EVar(name) => SEVar(env.lookUpExprVar(name))
|
case EVar(name) => SEVar(env.lookUpExprVar(name))
|
||||||
case EVal(ref) => SEVal(LfDefRef(ref), None)
|
case EVal(ref) => SEVal(LfDefRef(ref))
|
||||||
case EBuiltin(bf) =>
|
case EBuiltin(bf) =>
|
||||||
bf match {
|
bf match {
|
||||||
case BFoldl => SEBuiltinRecursiveDefinition.FoldL
|
case BFoldl => SEBuiltinRecursiveDefinition.FoldL
|
||||||
@ -1236,7 +1236,7 @@ private[lf] final case class Compiler(packages: PackageId PartialFunction Packag
|
|||||||
case Some(actors) => SEApp(SEBuiltin(SBSome), Array(actors))
|
case Some(actors) => SEApp(SEBuiltin(SBSome), Array(actors))
|
||||||
}
|
}
|
||||||
SEApp(
|
SEApp(
|
||||||
SEVal(ChoiceDefRef(tmplId, choiceId), None),
|
SEVal(ChoiceDefRef(tmplId, choiceId)),
|
||||||
Array(SEValue.bool(byKey), actors, contractId, argument))
|
Array(SEValue.bool(byKey), actors, contractId, argument))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,7 +457,7 @@ object Pretty {
|
|||||||
def prettySExpr(index: Int)(e: SExpr): Doc =
|
def prettySExpr(index: Int)(e: SExpr): Doc =
|
||||||
e match {
|
e match {
|
||||||
case SEVar(i) => char('@') + str(index - i)
|
case SEVar(i) => char('@') + str(index - i)
|
||||||
case SEVal(defId, _) =>
|
case SEVal(defId) =>
|
||||||
str(defId)
|
str(defId)
|
||||||
case SEValue(lit) =>
|
case SEValue(lit) =>
|
||||||
lit match {
|
lit match {
|
||||||
|
@ -51,11 +51,27 @@ object SExpr {
|
|||||||
*/
|
*/
|
||||||
final case class SEVal(
|
final case class SEVal(
|
||||||
ref: SDefinitionRef,
|
ref: SDefinitionRef,
|
||||||
var cached: Option[(SValue, List[Location])],
|
|
||||||
) extends SExpr {
|
) extends SExpr {
|
||||||
def execute(machine: Machine): Unit = {
|
|
||||||
|
// The variable `_cached` is used to cache the evaluation of the
|
||||||
|
// LF value defined by `ref` once it has been computed. Hence we
|
||||||
|
// avoid both the lookup in the package definition HashMap and the
|
||||||
|
// full reevaluation of the body of the definition.
|
||||||
|
// Here we take advantage of the Java memory model
|
||||||
|
// (https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.7)
|
||||||
|
// that guarantees the write of `_cache` (in the method
|
||||||
|
// `setCached`) is done atomically.
|
||||||
|
// This is similar how hashcode evaluation is cached in String
|
||||||
|
// http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/java/lang/String.java
|
||||||
|
private var _cached: Option[(SValue, List[Location])] = None
|
||||||
|
|
||||||
|
def cached: Option[(SValue, List[Location])] = _cached
|
||||||
|
|
||||||
|
def setCached(sValue: SValue, stack_trace: List[Location]): Unit =
|
||||||
|
_cached = Some((sValue, stack_trace))
|
||||||
|
|
||||||
|
def execute(machine: Machine): Unit =
|
||||||
machine.lookupVal(this)
|
machine.lookupVal(this)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reference to a builtin function */
|
/** Reference to a builtin function */
|
||||||
|
@ -685,9 +685,9 @@ object Speedy {
|
|||||||
* updates this solves the blow-up which would happen when a large record is
|
* updates this solves the blow-up which would happen when a large record is
|
||||||
* updated multiple times. */
|
* updated multiple times. */
|
||||||
final case class KCacheVal(v: SEVal, stack_trace: List[Location]) extends Kont {
|
final case class KCacheVal(v: SEVal, stack_trace: List[Location]) extends Kont {
|
||||||
def execute(sv: SValue, machine: Machine) = {
|
def execute(sv: SValue, machine: Machine): Unit = {
|
||||||
machine.pushStackTrace(stack_trace)
|
machine.pushStackTrace(stack_trace)
|
||||||
v.cached = Some((sv, stack_trace))
|
v.setCached(sv, stack_trace)
|
||||||
machine.returnValue = sv
|
machine.returnValue = sv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ object Script {
|
|||||||
def fromIdentifier(
|
def fromIdentifier(
|
||||||
compiledPackages: CompiledPackages,
|
compiledPackages: CompiledPackages,
|
||||||
scriptId: Identifier): Either[String, Script] = {
|
scriptId: Identifier): Either[String, Script] = {
|
||||||
val scriptExpr = SEVal(LfDefRef(scriptId), None)
|
val scriptExpr = SEVal(LfDefRef(scriptId))
|
||||||
val scriptTy = compiledPackages
|
val scriptTy = compiledPackages
|
||||||
.getPackage(scriptId.packageId)
|
.getPackage(scriptId.packageId)
|
||||||
.flatMap(_.lookupIdentifier(scriptId.qualifiedName).toOption) match {
|
.flatMap(_.lookupIdentifier(scriptId.qualifiedName).toOption) match {
|
||||||
|
Loading…
Reference in New Issue
Block a user