From 3f163e8e2e767700bfa80dedbbab7412919f89e3 Mon Sep 17 00:00:00 2001 From: Remy Date: Wed, 21 Sep 2022 18:48:05 +0200 Subject: [PATCH] [engine] drop deprecated LenientExercise Command (#15059) CHANGELOG_BEGIN CHANGELOG_END --- .../preprocessing/CommandPreprocessor.scala | 35 +-------------- .../daml/lf/language/PackageInterface.scala | 43 +++++-------------- .../digitalasset/daml/lf/ReplayCommand.scala | 10 ----- 3 files changed, 11 insertions(+), 77 deletions(-) diff --git a/daml-lf/engine/src/main/scala/com/digitalasset/daml/lf/engine/preprocessing/CommandPreprocessor.scala b/daml-lf/engine/src/main/scala/com/digitalasset/daml/lf/engine/preprocessing/CommandPreprocessor.scala index 6607e2483c..f41959b39b 100644 --- a/daml-lf/engine/src/main/scala/com/digitalasset/daml/lf/engine/preprocessing/CommandPreprocessor.scala +++ b/daml-lf/engine/src/main/scala/com/digitalasset/daml/lf/engine/preprocessing/CommandPreprocessor.scala @@ -5,15 +5,12 @@ package com.daml.lf package engine package preprocessing -import com.daml.lf.data import com.daml.lf.data._ -import com.daml.lf.language.{Ast, PackageInterface} +import com.daml.lf.language.Ast import com.daml.lf.transaction.TransactionVersion import com.daml.lf.value.Value import com.daml.scalautil.Statement.discard -import scala.annotation.nowarn - private[lf] final class CommandPreprocessor( pkgInterface: language.PackageInterface, requireV1ContractIdSuffix: Boolean, @@ -52,33 +49,6 @@ private[lf] final class CommandPreprocessor( speedy.Command.Create(templateId, arg) } - // TODO: https://github.com/digital-asset/daml/issues/12051 - // Drop this once Canton support ambiguous choices properly - @throws[Error.Preprocessing.Error] - @deprecated - private def unsafePreprocessLenientExercise( - templateId: Ref.Identifier, - contractId: Value.ContractId, - choiceId: Ref.ChoiceName, - argument: Value, - ): speedy.Command = - handleLookup(pkgInterface.lookupLenientChoice(templateId, choiceId)) match { - case PackageInterface.ChoiceInfo.Template(choice) => - speedy.Command.ExerciseTemplate( - templateId = templateId, - contractId = valueTranslator.unsafeTranslateCid(contractId), - choiceId = choiceId, - argument = valueTranslator.unsafeTranslateValue(choice.argBinder._2, argument), - ) - case PackageInterface.ChoiceInfo.Inherited(ifaceId, choice) => - speedy.Command.ExerciseInterface( - interfaceId = ifaceId, - contractId = valueTranslator.unsafeTranslateCid(contractId), - choiceId = choiceId, - argument = valueTranslator.unsafeTranslateValue(choice.argBinder._2, argument), - ) - } - def unsafePreprocessExercise( typeId: data.TemplateOrInterface[Ref.Identifier, Ref.Identifier], contractId: Value.ContractId, @@ -206,15 +176,12 @@ private[lf] final class CommandPreprocessor( // returns the speedy translation of an Replay command. @throws[Error.Preprocessing.Error] - @nowarn("msg=deprecated") private[preprocessing] def unsafePreprocessReplayCommand( cmd: command.ReplayCommand ): speedy.Command = cmd match { case command.ReplayCommand.Create(templateId, argument) => unsafePreprocessCreate(templateId, argument) - case command.ReplayCommand.LenientExercise(typeId, coid, choiceId, argument) => - unsafePreprocessLenientExercise(typeId, coid, choiceId, argument) case command.ReplayCommand.Exercise(templateId, mbIfaceId, coid, choiceId, argument) => mbIfaceId match { case Some(ifaceId) => diff --git a/daml-lf/language/src/main/scala/com/digitalasset/daml/lf/language/PackageInterface.scala b/daml-lf/language/src/main/scala/com/digitalasset/daml/lf/language/PackageInterface.scala index b8198e5edf..0cc7ab48d3 100644 --- a/daml-lf/language/src/main/scala/com/digitalasset/daml/lf/language/PackageInterface.scala +++ b/daml-lf/language/src/main/scala/com/digitalasset/daml/lf/language/PackageInterface.scala @@ -215,6 +215,16 @@ private[lf] class PackageInterface(signatures: PartialFunction[PackageId, Packag ): Either[LookupError, TemplateChoiceSignature] = lookupTemplateChoice(tmpName, chName, Reference.TemplateChoice(tmpName, chName)) + private[lf] def lookupChoice( + templateId: TypeConName, + mbInterfaceId: Option[TypeConName], + chName: ChoiceName, + ): Either[LookupError, TemplateChoiceSignature] = + mbInterfaceId match { + case None => lookupTemplateChoice(templateId, chName) + case Some(ifaceId) => lookupInterfaceChoice(ifaceId, chName) + } + private[this] def lookupInterfaceInstance( interfaceName: TypeConName, templateName: TypeConName, @@ -287,39 +297,6 @@ private[lf] class PackageInterface(signatures: PartialFunction[PackageId, Packag } ) - // TODO: https://github.com/digital-asset/daml/issues/12051 - // Drop this, once Canton support ambiguous choices properly - @deprecated - private[lf] def lookupLenientChoice( - templateId: TypeConName, - chName: ChoiceName, - ): Either[LookupError, PackageInterface.ChoiceInfo] = { - lazy val context = Reference.Choice(templateId, chName) - lookupTemplate(templateId, context).flatMap { template => - template.choices.get(chName) match { - case Some(choice) => - Right(PackageInterface.ChoiceInfo.Template(choice)) - case None => - val matchingChoices = for { - ifaceId <- template.implements.keysIterator - iface <- lookupInterface(ifaceId, context).toSeq - choice <- iface.choices.get(chName).iterator - } yield PackageInterface.ChoiceInfo.Inherited(ifaceId, choice) - matchingChoices.nextOption().toRight(LookupError(context, context)) - } - } - } - - private[lf] def lookupChoice( - templateId: TypeConName, - mbInterfaceId: Option[TypeConName], - chName: ChoiceName, - ): Either[LookupError, TemplateChoiceSignature] = - mbInterfaceId match { - case None => lookupTemplateChoice(templateId, chName) - case Some(ifaceId) => lookupInterfaceChoice(ifaceId, chName) - } - def lookupTemplateOrInterface( name: TypeConName ): Either[LookupError, TemplateOrInterface[TemplateSignature, DefInterfaceSignature]] = diff --git a/daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/ReplayCommand.scala b/daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/ReplayCommand.scala index 904104f44a..879ac58753 100644 --- a/daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/ReplayCommand.scala +++ b/daml-lf/transaction/src/main/scala/com/digitalasset/daml/lf/ReplayCommand.scala @@ -20,16 +20,6 @@ object ReplayCommand { argument: Value, ) extends ReplayCommand - // TODO: https://github.com/digital-asset/daml/issues/12051 - // Drop this, once Canton support ambiguous choices properly - @deprecated("use Exercise") - final case class LenientExercise( - templateId: TypeConName, - contractId: Value.ContractId, - choiceId: ChoiceName, - argument: Value, - ) extends ReplayCommand - /** Exercise a template choice, by template Id or interface Id. */ final case class Exercise( templateId: TypeConName,