Script: infer the typeId of Choice in daml (#13971)

part of #13653

goes with digital-asset/ghc#122

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Remy 2022-06-02 16:02:12 +02:00 committed by GitHub
parent 4caba375e5
commit 7638e086ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 325 additions and 230 deletions

View File

@ -9,7 +9,7 @@ GHC_LIB_PATCHES = [
]
GHC_REPO_URL = "https://github.com/digital-asset/ghc"
GHC_REV = "0ec72694dc563bba1830d98a03e52042777ee844"
GHC_REV = "463da30a622cc1b675892fe68e763ec8f614d291"
GHC_PATCHES = [
]

View File

@ -290,8 +290,8 @@ convertPrim _ "UExerciseInterface"
choiceName = ChoiceName (T.intercalate "." $ unTypeConName $ qualObject choice)
convertPrim _ "UExerciseByKey"
(TApp proxy (TCon template) :-> key :-> TCon choice :-> TUpdate _returnTy) =
ETmLam (mkVar "_", TApp proxy (TCon template)) $
(tProxy@(TApp _ (TCon template)) :-> key :-> TCon choice :-> TUpdate _returnTy) =
ETmLam (mkVar "_", tProxy) $
ETmLam (mkVar "key", key) $
ETmLam (mkVar "arg", TCon choice) $
EUpdate $ UExerciseByKey template choiceName (EVar (mkVar "key")) (EVar (mkVar "arg"))
@ -317,24 +317,32 @@ convertPrim _ "UFetchByKey"
])
convertPrim _ "ETemplateTypeRep"
(TApp proxy (TCon template) :-> TTypeRep) =
ETmLam (mkVar "_", TApp proxy (TCon template)) $
ETypeRep (TCon template)
(tProxy@(TApp _ tCon@(TCon _)) :-> TTypeRep) =
ETmLam (mkVar "_", tProxy) $
ETypeRep tCon
convertPrim _ "EFromAnyTemplate"
(TAny :-> TOptional (TCon template)) =
ETmLam (mkVar "any", TAny) $
EFromAny (TCon template) (EVar $ mkVar "any")
convertPrim _ "EFromAnyChoice"
convertPrim _ "EFromAnyTemplateChoice"
(tProxy :-> TAny :-> TOptional choice) =
ETmLam (mkVar "_", tProxy) $
ETmLam (mkVar "any", TAny) $
EFromAny choice (EVar $ mkVar "any")
convertPrim _ "EFromAnyInterfaceChoice"
(tProxy :-> TAny :-> TOptional choice) =
ETmLam (mkVar "_", tProxy) $
ETmLam (mkVar "any", TAny) $
ECase (EFromAny (mkTAnyInterfaceChoice choice) (EVar $ mkVar "any"))
[ CaseAlternative (CPSome $ mkVar "x") (ESome choice $ projChoice choice (EVar $ mkVar "x"))
, CaseAlternative CPDefault (ENone choice) ]
convertPrim _ "EFromAnyContractKey"
(TApp proxy (TCon template) :-> TAny :-> TOptional key) =
ETmLam (mkVar "_", TApp proxy (TCon template)) $
(tProxy@(TApp _ (TCon _)) :-> TAny :-> TOptional key) =
ETmLam (mkVar "_", tProxy) $
ETmLam (mkVar "any", TAny) $
EFromAny key (EVar $ mkVar "any")
@ -343,15 +351,21 @@ convertPrim _ "EToAnyTemplate"
ETmLam (mkVar "template", TCon template) $
EToAny (TCon template) (EVar $ mkVar "template")
convertPrim _ "EToAnyChoice"
convertPrim _ "EToAnyTemplateChoice"
(tProxy :-> choice :-> TAny) =
ETmLam (mkVar "_", tProxy) $
ETmLam (mkVar "choice", choice) $
EToAny choice (EVar $ mkVar "choice")
convertPrim _ "EToAnyInterfaceChoice"
(tProxy@(TApp _ (TCon typeId)) :-> choice :-> TAny) =
ETmLam (mkVar "_", tProxy) $
ETmLam (mkVar "choice", choice) $
EToAny (mkTAnyInterfaceChoice choice) (mkEAnyInterfaceChoice choice typeId $ EVar $ mkVar "choice")
convertPrim _ "EToAnyContractKey"
(TApp proxy (TCon template) :-> key :-> TAny) =
ETmLam (mkVar "_", TApp proxy (TCon template)) $
(tProxy@(TApp _ (TCon _)) :-> key :-> TAny) =
ETmLam (mkVar "_", tProxy) $
ETmLam (mkVar "key", key) $
EToAny key (EVar $ mkVar "key")
@ -424,6 +438,19 @@ convertPrim (V1 PointDev) (L.stripPrefix "$" -> Just builtin) typ =
-- Unknown primitive.
convertPrim _ x ty = error $ "Unknown primitive " ++ show x ++ " at type " ++ renderPretty ty
typeRepField, choiceField :: FieldName
typeRepField = FieldName "choiceInterfaceIdRep"
choiceField = FieldName "choice"
mkTAnyInterfaceChoice :: Type -> Type
mkTAnyInterfaceChoice t = TStruct [(typeRepField, TTypeRep), (choiceField, t)]
mkEAnyInterfaceChoice :: Type -> Qualified TypeConName -> Expr -> Expr
mkEAnyInterfaceChoice _ typeId e = EStructCon [(typeRepField, ETypeRep (TCon typeId)), (choiceField, e)]
projChoice :: Type -> Expr -> Expr
projChoice _ = EStructProj choiceField
-- | Some builtins are only supported in specific versions of Daml-LF.
whenRuntimeSupports :: Version -> Feature -> Type -> Expr -> Expr
whenRuntimeSupports version feature t e

View File

@ -51,9 +51,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType MyTemplate where
instance DA.Internal.Desugar.HasExercise MyTemplate DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice MyTemplate DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice MyTemplate DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_MyTemplateArchive :
(MyTemplate
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],

View File

@ -65,9 +65,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType K where
instance DA.Internal.Desugar.HasExercise K DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice K DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice K DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_KArchive :
(K -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId K
@ -210,69 +210,69 @@ instance DA.Internal.Desugar.HasIsInterfaceType T where
instance DA.Internal.Desugar.HasExercise T DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise T Throw (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T Throw (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T Throw (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise T Catch (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T Catch (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T Catch (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise T ThrowArithmeticError (Int) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T ThrowArithmeticError (Int) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T ThrowArithmeticError (Int) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise T CatchArithmeticError (Int) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T CatchArithmeticError (Int) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T CatchArithmeticError (Int) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise T UncatchableTry (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T UncatchableTry (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T UncatchableTry (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise T TransientDuplicate (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T TransientDuplicate (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T TransientDuplicate (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise T NonTransientDuplicate (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T NonTransientDuplicate (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T NonTransientDuplicate (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise T RollbackKey (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T RollbackKey (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T RollbackKey (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise T RollbackArchive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T RollbackArchive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T RollbackArchive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise T NonRollbackArchive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T NonRollbackArchive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T NonRollbackArchive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_TArchive :
(T -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T
@ -574,21 +574,21 @@ instance DA.Internal.Desugar.HasIsInterfaceType Fetcher where
instance DA.Internal.Desugar.HasExercise Fetcher DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Fetcher DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Fetcher DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise Fetcher Fetch (K) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Fetcher Fetch (K) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Fetcher Fetch (K) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
instance DA.Internal.Desugar.HasExercise Fetcher RollbackFetch (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Fetcher RollbackFetch (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Fetcher RollbackFetch (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_FetcherArchive :
(Fetcher
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],

View File

@ -77,11 +77,13 @@ instance DA.Internal.Desugar.Eq Token where
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasToAnyChoice t Split ((ContractId Token,
ContractId Token)) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Token])
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasFromAnyChoice t Split ((ContractId Token,
ContractId Token)) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Token])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Token)) =>
@ -101,10 +103,12 @@ instance ((DA.Internal.Desugar.HasIsInterfaceType t),
exercise = DA.Internal.Desugar._exerciseDefault
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasToAnyChoice t Transfer (ContractId Token) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Token])
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasFromAnyChoice t Transfer (ContractId Token) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Token])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Token)) =>
@ -122,10 +126,12 @@ instance ((DA.Internal.Desugar.HasIsInterfaceType t),
exercise = DA.Internal.Desugar._exerciseDefault
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasToAnyChoice t Noop (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Token])
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasFromAnyChoice t Noop (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Token])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Token)) =>
@ -143,10 +149,12 @@ instance ((DA.Internal.Desugar.HasIsInterfaceType t),
exercise = DA.Internal.Desugar._exerciseDefault
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasToAnyChoice t GetRich (ContractId Token) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Token])
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasFromAnyChoice t GetRich (ContractId Token) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Token])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Token)) =>
@ -319,9 +327,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType Asset where
instance DA.Internal.Desugar.HasExercise Asset DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Asset DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Asset DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_AssetArchive :
(Asset
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],

View File

@ -51,9 +51,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T where
instance DA.Internal.Desugar.HasExercise T DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_TArchive :
(T -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T

View File

@ -50,10 +50,12 @@ instance DA.Internal.Desugar.Eq Interface where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t Interface) =>
DA.Internal.Desugar.HasToAnyChoice t MyArchive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Interface])
instance (DA.Internal.Desugar.Implements t Interface) =>
DA.Internal.Desugar.HasFromAnyChoice t MyArchive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Interface])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Interface)) =>

View File

@ -39,10 +39,12 @@ instance DA.Internal.Desugar.Eq I where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t I) =>
DA.Internal.Desugar.HasToAnyChoice t IChoice (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [I])
instance (DA.Internal.Desugar.Implements t I) =>
DA.Internal.Desugar.HasFromAnyChoice t IChoice (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [I])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t I)) =>
@ -121,9 +123,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T where
instance DA.Internal.Desugar.HasExercise T DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_TArchive :
(T -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T

View File

@ -76,10 +76,12 @@ instance DA.Internal.Desugar.Eq J where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t J) =>
DA.Internal.Desugar.HasToAnyChoice t JChoice (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [J])
instance (DA.Internal.Desugar.Implements t J) =>
DA.Internal.Desugar.HasFromAnyChoice t JChoice (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [J])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t J)) =>
@ -158,9 +160,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T where
instance DA.Internal.Desugar.HasExercise T DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_TArchive :
(T -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T

View File

@ -41,10 +41,12 @@ instance DA.Internal.Desugar.Eq Iface where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t Iface) =>
DA.Internal.Desugar.HasToAnyChoice t MyChoice (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Iface])
instance (DA.Internal.Desugar.Implements t Iface) =>
DA.Internal.Desugar.HasFromAnyChoice t MyChoice (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Iface])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Iface)) =>
@ -130,9 +132,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType Template1 where
instance DA.Internal.Desugar.HasExercise Template1 DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Template1 DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Template1 DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_Template1Archive :
(Template1
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
@ -216,9 +218,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType Template2 where
instance DA.Internal.Desugar.HasExercise Template2 DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Template2 DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Template2 DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_Template2Archive :
(Template2
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],

View File

@ -57,10 +57,12 @@ instance DA.Internal.Desugar.Eq Token where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasToAnyChoice t Transfer (ContractId Token) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Token])
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasFromAnyChoice t Transfer (ContractId Token) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Token])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Token)) =>
@ -152,9 +154,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType Asset where
instance DA.Internal.Desugar.HasExercise Asset DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Asset DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Asset DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_AssetArchive :
(Asset
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],

View File

@ -80,9 +80,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T where
instance DA.Internal.Desugar.HasExercise T DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_TArchive :
(T -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T

View File

@ -50,9 +50,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T where
instance DA.Internal.Desugar.HasExercise T DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_TArchive :
(T -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T

View File

@ -81,9 +81,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T where
instance DA.Internal.Desugar.HasExercise T DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_TArchive :
(T -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T
@ -152,9 +152,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType U where
instance DA.Internal.Desugar.HasExercise U DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice U DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice U DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_UArchive :
(U -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId U

View File

@ -42,10 +42,13 @@ instance DA.Internal.Desugar.Eq MyInterface where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t MyInterface) =>
DA.Internal.Desugar.HasToAnyChoice t MyVirtualChoice (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [MyInterface])
instance (DA.Internal.Desugar.Implements t MyInterface) =>
DA.Internal.Desugar.HasFromAnyChoice t MyVirtualChoice (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive
@"EFromAnyInterfaceChoice" ([] : [MyInterface])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t MyInterface)) =>
@ -126,9 +129,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType MyTemplate where
instance DA.Internal.Desugar.HasExercise MyTemplate DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice MyTemplate DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice MyTemplate DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_MyTemplateArchive :
(MyTemplate
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],

View File

@ -92,9 +92,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType Asset where
instance DA.Internal.Desugar.HasExercise Asset DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Asset DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Asset DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_AssetArchive :
(Asset
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],

View File

@ -52,10 +52,12 @@ instance DA.Internal.Desugar.Eq Token where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasToAnyChoice t GetRich (ContractId Token) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Token])
instance (DA.Internal.Desugar.Implements t Token) =>
DA.Internal.Desugar.HasFromAnyChoice t GetRich (ContractId Token) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Token])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Token)) =>
@ -190,9 +192,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType Asset where
instance DA.Internal.Desugar.HasExercise Asset DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Asset DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Asset DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_AssetArchive :
(Asset
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
@ -296,9 +298,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType AnotherAsset where
instance DA.Internal.Desugar.HasExercise AnotherAsset DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice AnotherAsset DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice AnotherAsset DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_AnotherAssetArchive :
(AnotherAsset
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],

View File

@ -44,10 +44,12 @@ instance DA.Internal.Desugar.Eq Iface where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t Iface) =>
DA.Internal.Desugar.HasToAnyChoice t FooBar (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Iface])
instance (DA.Internal.Desugar.Implements t Iface) =>
DA.Internal.Desugar.HasFromAnyChoice t FooBar (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Iface])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Iface)) =>

View File

@ -62,11 +62,13 @@ instance DA.Internal.Desugar.Eq Token1 where
instance (DA.Internal.Desugar.Implements t Token1) =>
DA.Internal.Desugar.HasToAnyChoice t Split ((ContractId Token1,
ContractId Token1)) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Token1])
instance (DA.Internal.Desugar.Implements t Token1) =>
DA.Internal.Desugar.HasFromAnyChoice t Split ((ContractId Token1,
ContractId Token1)) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Token1])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Token1)) =>
@ -86,10 +88,12 @@ instance ((DA.Internal.Desugar.HasIsInterfaceType t),
exercise = DA.Internal.Desugar._exerciseDefault
instance (DA.Internal.Desugar.Implements t Token1) =>
DA.Internal.Desugar.HasToAnyChoice t Transfer (ContractId Token1) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Token1])
instance (DA.Internal.Desugar.Implements t Token1) =>
DA.Internal.Desugar.HasFromAnyChoice t Transfer (ContractId Token1) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Token1])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Token1)) =>
@ -207,10 +211,12 @@ instance DA.Internal.Desugar.Eq Token2 where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t Token2) =>
DA.Internal.Desugar.HasToAnyChoice t Noop (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Token2])
instance (DA.Internal.Desugar.Implements t Token2) =>
DA.Internal.Desugar.HasFromAnyChoice t Noop (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Token2])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Token2)) =>
@ -335,9 +341,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType Asset where
instance DA.Internal.Desugar.HasExercise Asset DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Asset DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Asset DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_AssetArchive :
(Asset
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
@ -498,9 +504,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType Asset2 where
instance DA.Internal.Desugar.HasExercise Asset2 DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Asset2 DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Asset2 DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_Asset2Archive :
(Asset2
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
@ -678,9 +684,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType Asset3 where
instance DA.Internal.Desugar.HasExercise Asset3 DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Asset3 DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Asset3 DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_Asset3Archive :
(Asset3
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
@ -858,9 +864,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType Asset4 where
instance DA.Internal.Desugar.HasExercise Asset4 DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice Asset4 DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice Asset4 DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_Asset4Archive :
(Asset4
-> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],

View File

@ -115,9 +115,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T where
instance DA.Internal.Desugar.HasExercise T DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_TArchive :
(T -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T

View File

@ -44,10 +44,12 @@ instance DA.Internal.Desugar.Eq I where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t I) =>
DA.Internal.Desugar.HasToAnyChoice t NonSerializableArgument (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [I])
instance (DA.Internal.Desugar.Implements t I) =>
DA.Internal.Desugar.HasFromAnyChoice t NonSerializableArgument (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [I])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t I)) =>

View File

@ -35,10 +35,12 @@ instance DA.Internal.Desugar.Eq Gettable where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t Gettable) =>
DA.Internal.Desugar.HasToAnyChoice t Get (Gettable) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [Gettable])
instance (DA.Internal.Desugar.Implements t Gettable) =>
DA.Internal.Desugar.HasFromAnyChoice t Get (Gettable) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [Gettable])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t Gettable)) =>

View File

@ -44,10 +44,12 @@ instance DA.Internal.Desugar.Eq I where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t I) =>
DA.Internal.Desugar.HasToAnyChoice t NonSerializableResult (NonSerializable) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [I])
instance (DA.Internal.Desugar.Implements t I) =>
DA.Internal.Desugar.HasFromAnyChoice t NonSerializableResult (NonSerializable) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [I])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t I)) =>

View File

@ -214,9 +214,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T where
instance DA.Internal.Desugar.HasExercise T DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_TArchive :
(T -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T

View File

@ -39,10 +39,12 @@ instance DA.Internal.Desugar.Eq I where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t I) =>
DA.Internal.Desugar.HasToAnyChoice t MyArchive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [I])
instance (DA.Internal.Desugar.Implements t I) =>
DA.Internal.Desugar.HasFromAnyChoice t MyArchive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [I])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t I)) =>
@ -121,9 +123,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T1 where
instance DA.Internal.Desugar.HasExercise T1 DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T1 DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T1 DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_T1Archive :
(T1 -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T1
@ -197,9 +199,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T2 where
instance DA.Internal.Desugar.HasExercise T2 DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T2 DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T2 DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_T2Archive :
(T2 -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T2

View File

@ -42,10 +42,12 @@ instance DA.Internal.Desugar.Eq A where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t A) =>
DA.Internal.Desugar.HasToAnyChoice t ChoiceA (Int) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [A])
instance (DA.Internal.Desugar.Implements t A) =>
DA.Internal.Desugar.HasFromAnyChoice t ChoiceA (Int) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [A])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t A)) =>
@ -122,10 +124,12 @@ instance DA.Internal.Desugar.Eq B where
(==) = GHC.Types.primitive @"BEEqual"
instance (DA.Internal.Desugar.Implements t B) =>
DA.Internal.Desugar.HasToAnyChoice t ChoiceB (Int) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice _
= GHC.Types.primitive @"EToAnyInterfaceChoice" ([] : [B])
instance (DA.Internal.Desugar.Implements t B) =>
DA.Internal.Desugar.HasFromAnyChoice t ChoiceB (Int) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice _
= GHC.Types.primitive @"EFromAnyInterfaceChoice" ([] : [B])
instance ((DA.Internal.Desugar.HasIsInterfaceType t),
(DA.Internal.Desugar.HasTemplateTypeRep t),
(DA.Internal.Desugar.Implements t B)) =>
@ -205,9 +209,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T1 where
instance DA.Internal.Desugar.HasExercise T1 DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T1 DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T1 DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_T1Archive :
(T1 -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T1
@ -296,9 +300,9 @@ instance DA.Internal.Desugar.HasIsInterfaceType T2 where
instance DA.Internal.Desugar.HasExercise T2 DA.Internal.Desugar.Archive (()) where
exercise = GHC.Types.primitive @"UExercise"
instance DA.Internal.Desugar.HasToAnyChoice T2 DA.Internal.Desugar.Archive (()) where
_toAnyChoice = GHC.Types.primitive @"EToAnyChoice"
_toAnyChoice = GHC.Types.primitive @"EToAnyTemplateChoice"
instance DA.Internal.Desugar.HasFromAnyChoice T2 DA.Internal.Desugar.Archive (()) where
_fromAnyChoice = GHC.Types.primitive @"EFromAnyChoice"
_fromAnyChoice = GHC.Types.primitive @"EFromAnyTemplateChoice"
_choice_T2Archive :
(T2 -> DA.Internal.Desugar.Archive -> [DA.Internal.Desugar.Party],
DA.Internal.Desugar.ContractId T2

View File

@ -69,6 +69,9 @@ final class Struct[+X] private (protected val sortedFields: ArraySeq[(Ref.Name,
object Struct {
def unapplySeq[X](v: Struct[X]): Some[Seq[(Ref.Name, X)]] =
Some(v.sortedFields)
/** Constructs a Struct.
* In case one of the field name is duplicated, return it as Left.
* O(n log n)

View File

@ -65,7 +65,14 @@ object ScriptIds {
}
final case class AnyTemplate(ty: Identifier, arg: SValue)
final case class AnyChoice(typeId: Identifier, name: ChoiceName, arg: SValue)
sealed abstract class AnyChoice extends Product with Serializable {
def name: ChoiceName
def arg: SValue
}
object AnyChoice {
final case class Template(name: ChoiceName, arg: SValue) extends AnyChoice
final case class Interface(ifaceId: Identifier, name: ChoiceName, arg: SValue) extends AnyChoice
}
final case class AnyContractKey(key: SValue)
// frames ordered from most-recent to least-recent
final case class StackTrace(frames: Vector[Location]) {
@ -185,20 +192,33 @@ object Converter {
)
}
def toAnyChoice(
v: SValue,
lookupChoiceByArgType: Identifier => Either[String, Identifier],
): Either[String, AnyChoice] = {
v match {
case SRecord(_, _, ArrayList(SAny(TTyCon(tyCon), choiceVal), _)) =>
for {
choiceTypeId <- lookupChoiceByArgType(tyCon)
chName <- ChoiceName.fromString(tyCon.qualifiedName.name.toString)
} yield AnyChoice(choiceTypeId, chName, choiceVal)
case _ => Left(s"Expected AnyChoice but got $v")
}
private[this] def choiceArgTypeToChoiceName(choiceCons: TypeConName) = {
// This exploits the fact that in Daml, choice argument type names
// and choice names match up.
assert(choiceCons.qualifiedName.name.segments.length == 1)
choiceCons.qualifiedName.name.segments.head
}
private[this] def toAnyChoice(v: SValue): Either[String, AnyChoice] =
v match {
case SRecord(_, _, ArrayList(SAny(TTyCon(choiceCons), choiceVal), _)) =>
Right(AnyChoice.Template(choiceArgTypeToChoiceName(choiceCons), choiceVal))
case SRecord(
_,
_,
ArrayList(
SAny(
TStruct(Struct((_, TTyCon(choiceCons)), _)),
SStruct(_, ArrayList(choiceVal, STypeRep(TTyCon(ifaceId)))),
),
_,
),
) =>
Right(AnyChoice.Interface(ifaceId, choiceArgTypeToChoiceName(choiceCons), choiceVal))
case _ =>
Left(s"Expected AnyChoice but got $v")
}
def toAnyContractKey(v: SValue): Either[String, AnyContractKey] = {
v match {
case SRecord(_, _, vals) if vals.size == 2 => {
@ -237,54 +257,61 @@ object Converter {
case _ => Left(s"Expected Create but got $v")
}
def toExerciseCommand(
v: SValue,
lookupChoiceByArgType: (Identifier, Identifier) => Either[String, Identifier],
): Either[String, command.ApiCommand] =
def toExerciseCommand(v: SValue): Either[String, command.ApiCommand] =
v match {
// typerep, contract id, choice argument and continuation
case SRecord(_, _, vals) if vals.size == 4 => {
case SRecord(_, _, vals) if vals.size == 4 =>
for {
tplId <- typeRepToIdentifier(vals.get(0))
cid <- toContractId(vals.get(1))
anyChoice <- toAnyChoice(vals.get(2), lookupChoiceByArgType(tplId, _))
} yield command.ApiCommand.Exercise(
typeId = anyChoice.typeId,
contractId = cid,
choiceId = anyChoice.name,
argument = anyChoice.arg.toUnnormalizedValue,
)
}
anyChoice <- toAnyChoice(vals.get(2))
} yield anyChoice match {
case AnyChoice.Template(name, arg) =>
command.ApiCommand.Exercise(
typeId = tplId,
contractId = cid,
choiceId = name,
argument = arg.toUnnormalizedValue,
)
case AnyChoice.Interface(ifaceId, name, arg) =>
command.ApiCommand.Exercise(
typeId = ifaceId,
contractId = cid,
choiceId = name,
argument = arg.toUnnormalizedValue,
)
}
case _ => Left(s"Expected Exercise but got $v")
}
def toExerciseByKeyCommand(v: SValue): Either[String, command.ApiCommand] =
v match {
// typerep, contract id, choice argument and continuation
case SRecord(_, _, vals) if vals.size == 4 => {
case SRecord(_, _, vals) if vals.size == 4 =>
for {
tplId <- typeRepToIdentifier(vals.get(0))
anyKey <- toAnyContractKey(vals.get(1))
anyChoice <- toAnyChoice(vals.get(2), _ => Right(tplId))
anyChoice <- toAnyChoice(vals.get(2))
typeId <- anyChoice match {
case _: AnyChoice.Template =>
typeRepToIdentifier(vals.get(0))
case AnyChoice.Interface(ifaceId, _, _) =>
Right(ifaceId)
}
} yield command.ApiCommand.ExerciseByKey(
templateId = tplId,
templateId = typeId,
contractKey = anyKey.key.toUnnormalizedValue,
choiceId = anyChoice.name,
argument = anyChoice.arg.toUnnormalizedValue,
)
}
case _ => Left(s"Expected ExerciseByKey but got $v")
}
def toCreateAndExerciseCommand(
v: SValue,
lookupChoiceByArgType: (Identifier, Identifier) => Either[String, Identifier],
): Either[String, command.ApiCommand.CreateAndExercise] =
def toCreateAndExerciseCommand(v: SValue): Either[String, command.ApiCommand.CreateAndExercise] =
v match {
case SRecord(_, _, vals) if vals.size == 3 => {
for {
anyTemplate <- toAnyTemplate(vals.get(0))
anyChoice <- toAnyChoice(vals.get(1), lookupChoiceByArgType(anyTemplate.ty, _))
anyChoice <- toAnyChoice(vals.get(1))
} yield command.ApiCommand.CreateAndExercise(
templateId = anyTemplate.ty,
createArgument = anyTemplate.arg.toUnnormalizedValue,
@ -333,7 +360,6 @@ object Converter {
def toCommands(
compiledPackages: CompiledPackages,
freeAp: SValue,
lookupChoiceByArgType: (Identifier, Identifier) => Either[String, Identifier],
): Either[String, List[command.ApiCommand]] = {
@tailrec
def iter(
@ -352,7 +378,7 @@ object Converter {
}
case Right((SVariant(_, "Exercise", _, exercise), v)) =>
// This cant be a for-comprehension since it trips up tailrec optimization.
toExerciseCommand(exercise, lookupChoiceByArgType) match {
toExerciseCommand(exercise) match {
case Left(err) => Left(err)
case Right(r) => iter(v, r :: commands)
}
@ -362,7 +388,7 @@ object Converter {
case Right(r) => iter(v, r :: commands)
}
case Right((SVariant(_, "CreateAndExercise", _, createAndExercise), v)) =>
toCreateAndExerciseCommand(createAndExercise, lookupChoiceByArgType) match {
toCreateAndExerciseCommand(createAndExercise) match {
case Left(err) => Left(err)
case Right(r) => iter(v, r :: commands)
}

View File

@ -64,7 +64,6 @@ import scalaz.syntax.traverse._
import scalaz.{Applicative, NonEmptyList, OneAnd, Traverse, \/-}
import spray.json._
import scala.annotation.nowarn
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
@ -426,7 +425,6 @@ private[lf] class Runner(
ScriptF.Ctx(knownPackages, extendedCompiledPackages),
vv,
v,
env.lookupChoiceByArgType: @nowarn("msg=deprecated"),
)
)
.flatMap { scriptF =>

View File

@ -11,7 +11,7 @@ import com.daml.ledger.api.domain.{User, UserRight}
import com.daml.lf.data.FrontStack
import com.daml.lf.{CompiledPackages, command}
import com.daml.lf.engine.preprocessing.ValueTranslator
import com.daml.lf.data.Ref.{Identifier, Name, PackageId, Party, QualifiedName, UserId}
import com.daml.lf.data.Ref.{Identifier, Name, PackageId, Party, UserId}
import com.daml.lf.data.Time.Timestamp
import com.daml.lf.engine.script.ledgerinteraction.{ScriptLedgerClient, ScriptTimeMode}
import com.daml.lf.language.Ast
@ -80,40 +80,6 @@ object ScriptF {
): Either[String, Ast.TemplateChoiceSignature] =
compiledPackages.interface.lookupChoice(tmplId, ifaceId, choice).left.map(_.pretty)
private[this] val archiveId: Identifier = Identifier.assertFromString(
"d14e08374fc7197d6a0de468c968ae8ba3aadbf9315476fd39071831f5923662:DA.Internal.Template:Archive"
)
// TODO: https://github.com/digital-asset/daml/issues/13653
// infer interface ID of choice in DAML
// This is a workaround to infer the template/interface id where the choice is defined
// using the choice argument type. The inference should be done in daml.
@deprecated
def lookupChoiceByArgType(
tmplId: Identifier,
argTypeId: Identifier,
): Either[String, Identifier] =
if (argTypeId == archiveId)
Right(tmplId)
else {
val Identifier(argPkg, QualifiedName(argMod, _)) = argTypeId
val choiceName = argTypeId.qualifiedName.name.segments.head
val argTyp = Ast.TTyCon(argTypeId)
compiledPackages.interface
.lookupModule(argPkg, argMod)
.left
.map(_.pretty)
.flatMap(mod =>
(mod.templates.view.mapValues(_.choices) ++ mod.interfaces.view.mapValues(_.choices))
.collectFirst {
case (typeName, choices)
if choices.get(choiceName).exists(_.argBinder._2 == argTyp) =>
Identifier(argPkg, QualifiedName(argMod, typeName))
}
.toRight(s"cannot find choice with argument type $argTypeId")
)
}
def lookupKeyTy(id: Identifier): Either[String, Ast.Type] =
compiledPackages.interface.lookupTemplateKey(id) match {
case Right(key) => Right(key.typ)
@ -652,7 +618,6 @@ object ScriptF {
private def parseSubmit(
ctx: Ctx,
v: SValue,
lookupChoiceByArgType: (Identifier, Identifier) => Either[String, Identifier],
): Either[String, SubmitData] = {
def convert(
actAs: OneAnd[List, SValue],
@ -664,7 +629,7 @@ object ScriptF {
for {
actAs <- actAs.traverse(Converter.toParty(_)).map(toOneAndSet(_))
readAs <- readAs.traverse(Converter.toParty(_))
cmds <- Converter.toCommands(ctx.compiledPackages, freeAp, lookupChoiceByArgType)
cmds <- Converter.toCommands(ctx.compiledPackages, freeAp)
stackTrace <- toStackTrace(ctx, stackTrace)
} yield SubmitData(actAs, readAs.toSet, cmds, freeAp, stackTrace, continue)
v match {
@ -962,16 +927,11 @@ object ScriptF {
case _ => Left(s"Expected ListUserRights payload but got $v")
}
def parse(
ctx: Ctx,
constr: Ast.VariantConName,
v: SValue,
lookupChoiceByArgType: (Identifier, Identifier) => Either[String, Identifier],
): Either[String, ScriptF] =
def parse(ctx: Ctx, constr: Ast.VariantConName, v: SValue): Either[String, ScriptF] =
constr match {
case "Submit" => parseSubmit(ctx, v, lookupChoiceByArgType).map(Submit(_))
case "SubmitMustFail" => parseSubmit(ctx, v, lookupChoiceByArgType).map(SubmitMustFail(_))
case "SubmitTree" => parseSubmit(ctx, v, lookupChoiceByArgType).map(SubmitTree(_))
case "Submit" => parseSubmit(ctx, v).map(Submit(_))
case "SubmitMustFail" => parseSubmit(ctx, v).map(SubmitMustFail(_))
case "SubmitTree" => parseSubmit(ctx, v).map(SubmitTree(_))
case "Query" => parseQuery(ctx, v)
case "QueryContractId" => parseQueryContractId(ctx, v)
case "QueryContractKey" => parseQueryContractKey(ctx, v)

View File

@ -7,7 +7,7 @@ package trigger
import scalaz.std.either._
import scalaz.syntax.traverse._
import com.daml.lf.data.{FrontStack, ImmArray}
import com.daml.lf.data.{FrontStack, ImmArray, Struct}
import com.daml.lf.data.Ref._
import com.daml.lf.language.Ast._
import com.daml.lf.speedy.{ArrayList, SValue}
@ -74,7 +74,14 @@ object Converter {
private case class AnyContractId(templateId: Identifier, contractId: ContractId)
private case class AnyTemplate(ty: Identifier, arg: SValue)
private case class AnyChoice(name: ChoiceName, arg: SValue)
sealed abstract class AnyChoice extends Product with Serializable {
def name: ChoiceName
def arg: SValue
}
object AnyChoice {
final case class Template(name: ChoiceName, arg: SValue) extends AnyChoice
final case class Interface(ifaceId: Identifier, name: ChoiceName, arg: SValue) extends AnyChoice
}
private case class AnyContractKey(key: SValue)
private def toLedgerRecord(v: SValue): Either[String, value.Record] =
@ -371,12 +378,29 @@ object Converter {
}
}
private[this] def choiceArgTypeToChoiceName(choiceCons: TypeConName) = {
// This exploits the fact that in Daml, choice argument type names
// and choice names match up.
assert(choiceCons.qualifiedName.name.segments.length == 1)
choiceCons.qualifiedName.name.segments.head
}
private[this] def toAnyChoice(v: SValue): Either[String, AnyChoice] =
v match {
case SRecord(_, _, ArrayList(SAny(TTyCon(tycon), value), _)) =>
// This exploits the fact that in Daml, choice argument type names
// and choice names match up.
ChoiceName.fromString(tycon.qualifiedName.name.toString).map(AnyChoice(_, value))
case SRecord(_, _, ArrayList(SAny(TTyCon(choiceCons), choiceVal), _)) =>
Right(AnyChoice.Template(choiceArgTypeToChoiceName(choiceCons), choiceVal))
case SRecord(
_,
_,
ArrayList(
SAny(
TStruct(Struct((_, TTyCon(choiceCons)), _)),
SStruct(_, ArrayList(choiceVal, STypeRep(TTyCon(ifaceId)))),
),
_,
),
) =>
Right(AnyChoice.Interface(ifaceId, choiceArgTypeToChoiceName(choiceCons), choiceVal))
case _ =>
Left(s"Expected AnyChoice but got $v")
}
@ -407,9 +431,13 @@ object Converter {
for {
anyContractId <- toAnyContractId(sAnyContractId)
anyChoice <- toAnyChoice(sChoiceVal)
choiceTypeId = anyChoice match {
case _: AnyChoice.Template => anyContractId.templateId
case AnyChoice.Interface(ifaceId, _, _) => ifaceId
}
choiceArg <- toLedgerValue(anyChoice.arg)
} yield ExerciseCommand(
Some(toApiIdentifier(anyContractId.templateId)),
Some(toApiIdentifier(choiceTypeId)),
anyContractId.contractId.coid,
anyChoice.name,
Some(choiceArg),
@ -426,6 +454,11 @@ object Converter {
keyVal <- toAnyContractKey(skeyVal)
keyArg <- toLedgerValue(keyVal.key)
anyChoice <- toAnyChoice(sChoiceVal)
_ <- anyChoice match {
case _: AnyChoice.Template => Right(())
case _: AnyChoice.Interface =>
Left("Cannot run a ExerciseByKey over a interface choice")
}
choiceArg <- toLedgerValue(anyChoice.arg)
} yield ExerciseByKeyCommand(
Some(toApiIdentifier(tplId)),
@ -444,6 +477,11 @@ object Converter {
anyTmpl <- toAnyTemplate(sTpl)
templateArg <- toLedgerRecord(anyTmpl.arg)
anyChoice <- toAnyChoice(sChoiceVal)
_ <- anyChoice match {
case _: AnyChoice.Template => Right(())
case _: AnyChoice.Interface =>
Left("Cannot run a CreateAndExercise over a interface choice")
}
choiceArg <- toLedgerValue(anyChoice.arg)
} yield CreateAndExerciseCommand(
Some(toApiIdentifier(anyTmpl.ty)),