From 8c46559163d85a42cf20a8f2ed7c234dd7b9d8ec Mon Sep 17 00:00:00 2001 From: nickchapman-da <49153372+nickchapman-da@users.noreply.github.com> Date: Fri, 12 Nov 2021 12:40:52 +0000 Subject: [PATCH] Remove unnecessary constructors: SEDamlException, SEImportValue, from SExpr{0,1} (#11668) CHANGELOG_BEGIN CHANGELOG_END --- .../scala/com/digitalasset/daml/lf/speedy/Anf.scala | 5 ----- .../daml/lf/speedy/ClosureConversion.scala | 5 +---- .../com/digitalasset/daml/lf/speedy/SExpr.scala | 6 ++++++ .../com/digitalasset/daml/lf/speedy/SExpr0.scala | 13 +++---------- .../com/digitalasset/daml/lf/speedy/SExpr1.scala | 9 --------- 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Anf.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Anf.scala index 65e2ba78f909..8692e0a8d878 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Anf.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Anf.scala @@ -301,8 +301,6 @@ private[lf] object Anf { Bounce(() => transform(depth, atom, k)) case source.SEVal(x) => Bounce(() => transform(depth, target.SEVal(x), k)) - case source.SEImportValue(ty, v) => - Bounce(() => transform(depth, target.SEImportValue(ty, v), k)) case source.SEAppGeneral(func, args) => // It's safe to perform ANF if the func-expression has no effects when evaluated. @@ -373,9 +371,6 @@ private[lf] object Anf { case source.SEScopeExercise(body0) => val body: target.SExpr = flattenExp(depth, env, body0)(anf => Land(anf.wrapped)).bounce Bounce(() => transform(depth, target.SEScopeExercise(body), k)) - - case _: source.SEDamlException => - throw CompilationError(s"flatten: unexpected: $exp") } private[this] def atomizeExps[A]( diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/ClosureConversion.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/ClosureConversion.scala index 1130d181c228..01a02e682522 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/ClosureConversion.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/ClosureConversion.scala @@ -120,9 +120,6 @@ private[speedy] object ClosureConversion { case source.SELet1General(bound, body) => target.SELet1General(closureConvert(remaps, bound), closureConvert(shift(remaps, 1), body)) - - case _: source.SEDamlException | _: source.SEImportValue => - throw CompilationError(s"closureConvert: unexpected $expr") } } @@ -184,7 +181,7 @@ private[speedy] object ClosureConversion { case source.SEScopeExercise(body) => go(body, bound, free) - case _: source.SEDamlException | _: source.SEImportValue | _: source.SELet1General => + case _: source.SELet1General => throw CompilationError(s"freeVars: unexpected $expr") } diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr.scala index 993fcc9c8967..1a8b30e31879 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr.scala @@ -327,6 +327,9 @@ object SExpr { /** We cannot crash in the engine call back. * Rather, we set the control to this expression and then crash when executing. + * + * The SEDamlException form is never constructed when compiling user LF. + * It is only constructed at runtime by certain builtin-ops. */ final case class SEDamlException(error: interpretation.Error) extends SExpr { def execute(machine: Machine): Unit = { @@ -334,6 +337,9 @@ object SExpr { } } + /** The SEImportValue form is never constructed when compiling user LF. + * It is only constructed at runtime by certain builtin-ops. + */ final case class SEImportValue(typ: Ast.Type, value: V) extends SExpr { def execute(machine: Machine): Unit = { machine.importValue(typ, value) diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr0.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr0.scala index 8363dd76f864..65c502ef77be 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr0.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr0.scala @@ -31,7 +31,7 @@ package speedy * Summary of which constructors are contained by: SExp0, SExpr1 and SExpr: * * - In SExpr{0,1,} (everywhere): SEAppGeneral, SEBuiltin, SEBuiltinRecursiveDefinition, - * SEDamlException, SEImportValue, SELabelClosure, SELet1General, SELocation, + * SELabelClosure, SELet1General, SELocation, * SEScopeExercise, SETryCatch, SEVal, SEValue, * * - In SExpr0: SEAbs, SEVar @@ -42,11 +42,11 @@ package speedy * * - In SExpr: SEAppAtomicFun, SEAppAtomicGeneral, SEAppAtomicSaturatedBuiltin, * SECaseAtomic, SELet1Builtin, SELet1BuiltinArithmetic + * + * - In SExpr (runtime only, i.e. rejected by validate): SEDamlException, SEImportValue */ import com.daml.lf.data.Ref._ -import com.daml.lf.language.Ast -import com.daml.lf.value.{Value => V} import com.daml.lf.speedy.SValue._ import com.daml.lf.speedy.SExpr.{SDefinitionRef, SCasePat} import com.daml.lf.speedy.{SExpr => runTime} @@ -129,13 +129,6 @@ private[speedy] object SExpr0 { */ final case class SELabelClosure(label: Profile.Label, expr: SExpr) extends SExpr - /** We cannot crash in the engine call back. - * Rather, we set the control to this expression and then crash when executing. - */ - final case class SEDamlException(error: interpretation.Error) extends SExpr - - final case class SEImportValue(typ: Ast.Type, value: V) extends SExpr - /** Exception handler */ final case class SETryCatch(body: SExpr, handler: SExpr) extends SExpr diff --git a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr1.scala b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr1.scala index 0863d6587744..53d840675b49 100644 --- a/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr1.scala +++ b/daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/SExpr1.scala @@ -10,8 +10,6 @@ package speedy */ import com.daml.lf.data.Ref._ -import com.daml.lf.language.Ast -import com.daml.lf.value.{Value => V} import com.daml.lf.speedy.SValue._ import com.daml.lf.speedy.SExpr.{SDefinitionRef, SCasePat} import com.daml.lf.speedy.{SExpr => runTime} @@ -101,13 +99,6 @@ private[speedy] object SExpr1 { */ final case class SELabelClosure(label: Profile.Label, expr: SExpr) extends SExpr - /** We cannot crash in the engine call back. - * Rather, we set the control to this expression and then crash when executing. - */ - final case class SEDamlException(error: interpretation.Error) extends SExpr - - final case class SEImportValue(typ: Ast.Type, value: V) extends SExpr - /** Exception handler */ final case class SETryCatch(body: SExpr, handler: SExpr) extends SExpr