plutus-core
Safe HaskellNone
LanguageHaskell2010

PlutusCore.Builtin.Debug

Description

This module helps to visualize and debug the BuiltinMeaning inference machinery from the Elaborate and Meaning modules.

Synopsis

Documentation

elaborateDebug :: forall a (j :: Nat). ElaborateFromTo DefaultUni 0 j (Term TyName Name DefaultUni DefaultFun ()) a => a -> a Source #

Instantiate type variables in the type of a value using ElaborateFromTo. Example usages:

>>> :t elaborateDebug False
elaborateDebug False :: Bool
>>> :t elaborateDebug fst
elaborateDebug fst
  :: (TyVarRep ('TyNameRep "a" 0), TyVarRep ('TyNameRep "b" 1))
     -> TyVarRep ('TyNameRep "a" 0) 

newtype Opaque val rep Source #

The AST of a value with a Plutus type attached to it. The type is for the Plutus type checker to look at. Opaque can appear in the type of the denotation of a builtin.

Constructors

Opaque 

Fields

Instances

Instances details
KnownTypeAst tyname uni rep => KnownTypeAst tyname uni (Opaque val rep :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

Associated Types

type IsBuiltin uni (Opaque val rep :: Type) 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (Opaque val rep :: Type) = 'False

Methods

typeAst :: Type tyname uni () Source #

uni ~ UniOf val => MakeKnownIn uni val (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownType

Methods

makeKnown :: Opaque val rep -> BuiltinResult val Source #

uni ~ UniOf val => ReadKnownIn uni val (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownType

Methods

readKnown :: val -> ReadKnownM (Opaque val rep) Source #

(TypeError NoConstraintsErrMsg :: Constraint) => Monoid (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

mempty :: Opaque val rep Source #

mappend :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

mconcat :: [Opaque val rep] -> Opaque val rep Source #

(TypeError NoConstraintsErrMsg :: Constraint) => Semigroup (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

(<>) :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

sconcat :: NonEmpty (Opaque val rep) -> Opaque val rep Source #

stimes :: Integral b => b -> Opaque val rep -> Opaque val rep Source #

(TypeError NoConstraintsErrMsg :: Constraint) => Bounded (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

minBound :: Opaque val rep Source #

maxBound :: Opaque val rep Source #

(TypeError NoConstraintsErrMsg :: Constraint) => Enum (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

succ :: Opaque val rep -> Opaque val rep Source #

pred :: Opaque val rep -> Opaque val rep Source #

toEnum :: Int -> Opaque val rep Source #

fromEnum :: Opaque val rep -> Int Source #

enumFrom :: Opaque val rep -> [Opaque val rep] Source #

enumFromThen :: Opaque val rep -> Opaque val rep -> [Opaque val rep] Source #

enumFromTo :: Opaque val rep -> Opaque val rep -> [Opaque val rep] Source #

enumFromThenTo :: Opaque val rep -> Opaque val rep -> Opaque val rep -> [Opaque val rep] Source #

(TypeError NoConstraintsErrMsg :: Constraint) => Ix (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

range :: (Opaque val rep, Opaque val rep) -> [Opaque val rep] Source #

index :: (Opaque val rep, Opaque val rep) -> Opaque val rep -> Int Source #

unsafeIndex :: (Opaque val rep, Opaque val rep) -> Opaque val rep -> Int Source #

inRange :: (Opaque val rep, Opaque val rep) -> Opaque val rep -> Bool Source #

rangeSize :: (Opaque val rep, Opaque val rep) -> Int Source #

unsafeRangeSize :: (Opaque val rep, Opaque val rep) -> Int Source #

(TypeError NoConstraintsErrMsg :: Constraint) => Num (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

(+) :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

(-) :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

(*) :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

negate :: Opaque val rep -> Opaque val rep Source #

abs :: Opaque val rep -> Opaque val rep Source #

signum :: Opaque val rep -> Opaque val rep Source #

fromInteger :: Integer -> Opaque val rep Source #

(TypeError NoConstraintsErrMsg :: Constraint) => Integral (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

quot :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

rem :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

div :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

mod :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

quotRem :: Opaque val rep -> Opaque val rep -> (Opaque val rep, Opaque val rep) Source #

divMod :: Opaque val rep -> Opaque val rep -> (Opaque val rep, Opaque val rep) Source #

toInteger :: Opaque val rep -> Integer Source #

(TypeError NoConstraintsErrMsg :: Constraint) => Real (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

toRational :: Opaque val rep -> Rational Source #

(TypeError NoConstraintsErrMsg :: Constraint) => Eq (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

(==) :: Opaque val rep -> Opaque val rep -> Bool Source #

(/=) :: Opaque val rep -> Opaque val rep -> Bool Source #

(TypeError NoConstraintsErrMsg :: Constraint) => Ord (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

compare :: Opaque val rep -> Opaque val rep -> Ordering Source #

(<) :: Opaque val rep -> Opaque val rep -> Bool Source #

(<=) :: Opaque val rep -> Opaque val rep -> Bool Source #

(>) :: Opaque val rep -> Opaque val rep -> Bool Source #

(>=) :: Opaque val rep -> Opaque val rep -> Bool Source #

max :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

min :: Opaque val rep -> Opaque val rep -> Opaque val rep Source #

HasConstant val => HasConstant (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

asConstant :: Opaque val rep -> Either BuiltinError (Some (ValueOf (UniOf (Opaque val rep)))) Source #

fromConstant :: Some (ValueOf (UniOf (Opaque val rep))) -> Opaque val rep Source #

ExMemoryUsage val => ExMemoryUsage (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

memoryUsage :: Opaque val rep -> CostRose Source #

type ToBinds uni acc (Opaque val rep :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToBinds uni acc (Opaque val rep :: Type) = ToBinds uni acc rep
type ToHoles uni _1 (Opaque val rep :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToHoles uni _1 (Opaque val rep :: Type) = '[RepHole rep :: Hole]
type IsBuiltin uni (Opaque val rep :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (Opaque val rep :: Type) = 'False
type UniOf (Opaque val rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

type UniOf (Opaque val rep) = UniOf val

class (Typeable uni, Typeable fun, Bounded fun, Enum fun, Ix fun, Default (BuiltinSemanticsVariant fun)) => ToBuiltinMeaning (uni :: Type -> Type) fun where Source #

A type class for "each function from a set of built-in functions has a BuiltinMeaning".

Associated Types

type CostingPart (uni :: Type -> Type) fun Source #

The cost part of BuiltinMeaning.

Methods

toBuiltinMeaning :: HasMeaningIn uni val => BuiltinSemanticsVariant fun -> fun -> BuiltinMeaning val (CostingPart uni fun) Source #

Get the BuiltinMeaning of a built-in function.

Instances

Instances details
uni ~ DefaultUni => ToBuiltinMeaning uni DefaultFun Source # 
Instance details

Defined in PlutusCore.Default.Builtins

uni ~ DefaultUni => ToBuiltinMeaning uni ExtensionFun Source # 
Instance details

Defined in PlutusCore.Examples.Builtins

(ToBuiltinMeaning uni fun1, ToBuiltinMeaning uni fun2, Default (BuiltinSemanticsVariant fun1), Default (BuiltinSemanticsVariant fun2)) => ToBuiltinMeaning uni (Either fun1 fun2) Source # 
Instance details

Defined in PlutusCore.Examples.Builtins

Associated Types

type CostingPart uni (Either fun1 fun2) 
Instance details

Defined in PlutusCore.Examples.Builtins

type CostingPart uni (Either fun1 fun2) = (CostingPart uni fun1, CostingPart uni fun2)
data BuiltinSemanticsVariant (Either fun1 fun2) 
Instance details

Defined in PlutusCore.Examples.Builtins

Methods

toBuiltinMeaning :: HasMeaningIn uni val => BuiltinSemanticsVariant (Either fun1 fun2) -> Either fun1 fun2 -> BuiltinMeaning val (CostingPart uni (Either fun1 fun2)) Source #

data TyNameRep kind Source #

Representation of a type variable: its name and unique and an implicit kind.

Constructors

TyNameRep Symbol Nat 

Instances

Instances details
(name ~ ('TyNameRep text uniq :: TyNameRep kind), KnownSymbol text, KnownNat uniq, KnownKind kind, KnownTypeAst tyname uni a) => KnownTypeAst tyname uni (MetaForall name a :: Type) Source # 
Instance details

Defined in PlutusCore.Examples.Builtins

Associated Types

type IsBuiltin uni (MetaForall name a :: Type) 
Instance details

Defined in PlutusCore.Examples.Builtins

type IsBuiltin uni (MetaForall name a :: Type) = 'False

Methods

typeAst :: Type tyname uni () Source #

KnownMonotype val args res => KnownPolytype ('[] :: [Some TyNameRep]) val args res Source #

Once we've run out of type-level arguments, we start handling term-level ones.

Instance details

Defined in PlutusCore.Builtin.Meaning

(TypeError NoStandalonePolymorphicDataErrMsg :: Constraint) => Contains uni (TyVarRep :: TyNameRep kind -> kind) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

knownUni :: uni (Esc (TyVarRep :: TyNameRep kind -> kind)) Source #

(KnownSymbol name, KnownNat uniq, KnownKind kind, KnownPolytype binds val args res) => KnownPolytype ('Some ('TyNameRep name uniq :: TyNameRep kind) ': binds) val args res Source #

Every type-level argument becomes a TypeSchemeAll.

Instance details

Defined in PlutusCore.Builtin.Meaning

type ToBinds uni acc (MetaForall name a :: Type) Source # 
Instance details

Defined in PlutusCore.Examples.Builtins

type ToBinds uni acc (MetaForall name a :: Type) = ToBinds uni (Insert ('Some name) acc) a
type ToHoles uni _1 (MetaForall name a :: Type) Source # 
Instance details

Defined in PlutusCore.Examples.Builtins

type ToHoles uni _1 (MetaForall name a :: Type) = '[TypeHole a :: Hole]
type IsBuiltin uni (MetaForall name a :: Type) Source # 
Instance details

Defined in PlutusCore.Examples.Builtins

type IsBuiltin uni (MetaForall name a :: Type) = 'False

data family TyVarRep (name :: TyNameRep kind) :: kind Source #

Representation of an intrinsically-kinded type variable: a name.

Instances

Instances details
(tyname ~ TyName, name ~ ('TyNameRep text uniq :: TyNameRep a), KnownSymbol text, KnownNat uniq) => KnownTypeAst tyname uni (TyVarRep name :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

Associated Types

type IsBuiltin uni (TyVarRep name :: a) 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (TyVarRep name :: a) = 'False

Methods

typeAst :: Type tyname uni () Source #

(TypeError NoStandalonePolymorphicDataErrMsg :: Constraint) => Contains uni (TyVarRep :: TyNameRep kind -> kind) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

Methods

knownUni :: uni (Esc (TyVarRep :: TyNameRep kind -> kind)) Source #

type ToBinds uni acc (TyVarRep name :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToBinds uni acc (TyVarRep name :: a) = Insert ('Some name) acc
type ToHoles uni _1 (TyVarRep name :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToHoles uni _1 (TyVarRep name :: a) = '[] :: [Hole]
type IsBuiltin uni (TyVarRep name :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (TyVarRep name :: a) = 'False

data family TyAppRep (fun :: dom -> cod) (arg :: dom) :: cod Source #

Representation of an intrinsically-kinded type application: a function and an argument.

Instances

Instances details
(KnownTypeAst tyname uni fun, KnownTypeAst tyname uni arg) => KnownTypeAst tyname uni (TyAppRep fun arg :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

Associated Types

type IsBuiltin uni (TyAppRep fun arg :: a) 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (TyAppRep fun arg :: a) = IsBuiltin uni fun && IsBuiltin uni arg

Methods

typeAst :: Type tyname uni () Source #

type ToBinds uni acc (TyAppRep fun arg :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToBinds uni acc (TyAppRep fun arg :: a) = ToBinds uni (ToBinds uni acc fun) arg
type ToHoles uni _1 (TyAppRep fun arg :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToHoles uni _1 (TyAppRep fun arg :: a) = '[RepHole fun :: Hole, RepHole arg :: Hole]
type IsBuiltin uni (TyAppRep fun arg :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (TyAppRep fun arg :: a) = IsBuiltin uni fun && IsBuiltin uni arg

data family TyForallRep (name :: TyNameRep kind) a Source #

Representation of of an intrinsically-kinded universal quantifier: a bound name and a body.

Instances

Instances details
(tyname ~ TyName, name ~ ('TyNameRep text uniq :: TyNameRep kind), KnownSymbol text, KnownNat uniq, KnownKind kind, KnownTypeAst tyname uni a) => KnownTypeAst tyname uni (TyForallRep name a :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

Associated Types

type IsBuiltin uni (TyForallRep name a :: Type) 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (TyForallRep name a :: Type) = 'False

Methods

typeAst :: Type tyname uni () Source #

type ToBinds uni acc (TyForallRep name a :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToBinds uni acc (TyForallRep name a :: Type) = Delete ('Some name) (ToBinds uni acc a)
type ToHoles uni _1 (TyForallRep name a :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToHoles uni _1 (TyForallRep name a :: Type) = '[RepHole a :: Hole]
type IsBuiltin uni (TyForallRep name a :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (TyForallRep name a :: Type) = 'False

type family FoldArgs (args :: [Type]) res where ... Source #

Turn a list of Haskell types args into a functional type ending in res.

>>> :set -XDataKinds
>>> :kind! FoldArgs [(), Bool] Integer
FoldArgs [(), Bool] Integer :: *
= () -> Bool -> Integer 

Equations

FoldArgs ('[] :: [Type]) res = res 
FoldArgs (arg ': args) res = arg -> FoldArgs args res 

newtype SomeConstant (uni :: Type -> Type) rep Source #

For unlifting from the Constant constructor when the stored value is of a monomorphic built-in type

The rep parameter specifies how the type looks on the PLC side (i.e. just like with Opaque val rep).

Constructors

SomeConstant 

Fields

Instances

Instances details
KnownTypeAst tyname uni rep => KnownTypeAst tyname uni (SomeConstant uni rep :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

Associated Types

type IsBuiltin uni (SomeConstant uni rep :: Type) 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (SomeConstant uni rep :: Type) = 'False

Methods

typeAst :: Type tyname uni () Source #

HasConstantIn uni val => MakeKnownIn uni val (SomeConstant uni rep) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownType

Methods

makeKnown :: SomeConstant uni rep -> BuiltinResult val Source #

HasConstantIn uni val => ReadKnownIn uni val (SomeConstant uni rep) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownType

Methods

readKnown :: val -> ReadKnownM (SomeConstant uni rep) Source #

HasConstant (SomeConstant uni rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

(Everywhere uni ExMemoryUsage, Closed uni) => ExMemoryUsage (SomeConstant uni rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

type ToBinds uni acc (SomeConstant uni rep :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToBinds uni acc (SomeConstant uni rep :: Type) = ToBinds uni acc rep
type ToHoles uni _1 (SomeConstant uni rep :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToHoles uni _1 (SomeConstant uni rep :: Type) = '[RepHole rep :: Hole]
type IsBuiltin uni (SomeConstant uni rep :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (SomeConstant uni rep :: Type) = 'False
type UniOf (SomeConstant uni rep) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

type UniOf (SomeConstant uni rep) = uni

data family BuiltinHead (x :: a) :: a Source #

For annotating an uninstantiated built-in type, so that it gets handled by the right instance or type family.

Instances

Instances details
Contains uni f => KnownTypeAst tyname uni (BuiltinHead f :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

Associated Types

type IsBuiltin uni (BuiltinHead f :: a) 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (BuiltinHead f :: a) = 'True

Methods

typeAst :: Type tyname uni () Source #

type ToBinds uni acc (BuiltinHead f :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToBinds uni acc (BuiltinHead f :: a) = acc
type ToHoles uni _1 (BuiltinHead f :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToHoles uni _1 (BuiltinHead f :: a) = '[] :: [Hole]
type IsBuiltin uni (BuiltinHead f :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (BuiltinHead f :: a) = 'True

data family LastArg x y Source #

LastArg x y is the same thing as y in the signature of the denotation of a built-in functions and this type is only used for referencing x before y, so that the elaboration machinery generates x before y in the all part of the Plutus signature of the builtin. This is a very hacky and indirect way of specifying the ordering of type variables in a Plutus signature, in future we'll do it explicitly by introducing a Forall binder for use in type signatures of denotations of builtins.

Instances

Instances details
KnownTypeAst tyname uni y => KnownTypeAst tyname uni (LastArg x y :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

Associated Types

type IsBuiltin uni (LastArg x y :: Type) 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (LastArg x y :: Type) = IsBuiltin uni y

Methods

typeAst :: Type tyname uni () Source #

type ToBinds uni acc (LastArg x y :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToBinds uni acc (LastArg x y :: Type) = ToBinds uni (ToBinds uni acc x) y
type ToHoles uni hole (LastArg x y :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type ToHoles uni hole (LastArg x y :: Type) = '[RunHole hole x, RunHole hole y]
type IsBuiltin uni (LastArg x y :: Type) Source # 
Instance details

Defined in PlutusCore.Builtin.KnownTypeAst

type IsBuiltin uni (LastArg x y :: Type) = IsBuiltin uni y

type family ElaborateBuiltin (uni :: Type -> Type) (x :: a) :: a Source #

Take an iterated application of a built-in type and elaborate every function application inside of it to TyAppRep and annotate the head with BuiltinHead.

The idea is that we don't need to process built-in types manually if we simply add some annotations for instance resolution to look for. Think what we'd have to do manually for, say, ToHoles: traverse the spine of the application and collect all the holes into a list, which is troubling, because type applications are left-nested and lists are right-nested, so we'd have to use accumulators or an explicit Reverse type family. And then we also have KnownTypeAst and ToBinds, so handling built-in types in a special way for each of those would be a hassle, especially given the fact that type-level Haskell is not exactly good at computing things. With the ElaborateBuiltin approach we get KnownTypeAst, ToHoles and ToBinds for free.

We make this an open type family, so that elaboration is customizable for each universe.

Instances

Instances details
type ElaborateBuiltin DefaultUni (x :: a) Source # 
Instance details

Defined in PlutusCore.Default.Universe

type family AllElaboratedArgs (constr :: Type -> Constraint) (x :: a) where ... Source #

Take a constraint and use it to constrain every argument of a possibly 0-ary elaborated application of a built-in type.

Equations

AllElaboratedArgs constr (TyAppRep f x :: a) = (constr x, AllElaboratedArgs constr f) 
AllElaboratedArgs _1 (BuiltinHead _2 :: a) = () 

class AllElaboratedArgs constr (ElaborateBuiltin uni x) => AllBuiltinArgs (uni :: Type -> Type) (constr :: Type -> Constraint) (x :: a) Source #

Take a constraint and use it to constrain every argument of a possibly 0-ary application of a built-in type.

Instances

Instances details
AllElaboratedArgs constr (ElaborateBuiltin uni x) => AllBuiltinArgs uni constr (x :: a) Source # 
Instance details

Defined in PlutusCore.Builtin.Polymorphism

class MakeBuiltinMeaning a val where Source #

A function turned into a type class with exactly one fully general instance. We can't package up the constraints of makeBuiltinMeaning (see the instance) into a type or class synonym, because they contain a bunch of variables defined by ~ or determined via functional dependencies and neither class nor type definitions can handle that (see https://gitlab.haskell.org/ghc/ghc/-/issues/7100). Inlining three lines of constraints whenever we need to call makeBuiltinMeaning over a non-concrete type is a bad option and this abstraction is free anyway, hence its existence.

The a type variable goes first, because makeBuiltinMeaning @A is a common pattern.

Methods

makeBuiltinMeaning :: a -> (cost -> FoldArgs (GetArgs a) ExBudgetStream) -> BuiltinMeaning val cost Source #

Construct the meaning for a built-in function by automatically deriving its TypeScheme, given

  1. the denotation of the builtin
  2. an uninstantiated costing function

Instances

Instances details
(uni ~ UniOf val, binds ~ ToBinds uni ('[] :: [Some TyNameRep]) a, args ~ GetArgs a, a ~ FoldArgs args res, ThrowOnBothEmpty binds args (IsBuiltin uni a) a, ElaborateFromTo uni 0 j val a, KnownPolytype binds val args res) => MakeBuiltinMeaning a val Source # 
Instance details

Defined in PlutusCore.Builtin.Meaning

Methods

makeBuiltinMeaning :: a -> (cost -> FoldArgs (GetArgs a) ExBudgetStream) -> BuiltinMeaning val cost Source #

data BuiltinMeaning val cost Source #

The meaning of a built-in function consists of its type represented as a TypeScheme, its Haskell denotation and its uninstantiated runtime denotation.

The TypeScheme of a built-in function is used for example for

  1. computing the PLC type of the function to be used during type checking
  2. getting arity information
  3. generating arbitrary values to apply the function to in tests

The denotation is lazy, so that we don't need to worry about a builtin being bottom (happens in tests). The production path is not affected by that, since only runtime denotations are used for evaluation.

Constructors

BuiltinMeaning (TypeScheme val args res) ~(FoldArgs args res) (cost -> BuiltinRuntime val) 

type HasMeaningIn (uni :: Type -> Type) val = (Typeable val, ExMemoryUsage val, HasConstantIn uni val) Source #

Constraints available when defining a built-in function.

type family CostingPart (uni :: Type -> Type) fun Source #

The cost part of BuiltinMeaning.

Instances

Instances details
type CostingPart uni DefaultFun Source # 
Instance details

Defined in PlutusCore.Default.Builtins

type CostingPart uni ExtensionFun Source # 
Instance details

Defined in PlutusCore.Examples.Builtins

type CostingPart uni (Either fun1 fun2) Source # 
Instance details

Defined in PlutusCore.Examples.Builtins

type CostingPart uni (Either fun1 fun2) = (CostingPart uni fun1, CostingPart uni fun2)

withTypeSchemeOfBuiltinFunction :: (ToBuiltinMeaning (UniOf val) fun, ExMemoryUsage val, Typeable val, HasConstant val) => BuiltinSemanticsVariant fun -> fun -> (forall (args :: [Type]) res. TypeScheme val args res -> r) -> r Source #

Feed the TypeScheme of the given built-in function to the continuation.

typeOfBuiltinFunction :: forall (uni :: Type -> Type) fun. ToBuiltinMeaning uni fun => BuiltinSemanticsVariant fun -> fun -> Type TyName uni () Source #

Get the type of a built-in function.

type family GetArgs a :: [Type] where ... Source #

Chop a function type to get a list of its argument types.

Equations

GetArgs (a -> b) = a ': GetArgs b 
GetArgs _1 = '[] :: [Type] 

class KnownMonotype val (args :: [Type]) res where Source #

A class that allows us to derive a monotype for a builtin. We could've computed the runtime denotation from the TypeScheme and the denotation of the builtin, but not statically (due to unfolding not working for recursive functions and TypeScheme being recursive, i.e. requiring the conversion function to be recursive), and so it would cause us to retain a lot of evaluation-irrelevant stuff in the constructors of BuiltinRuntime, which has to make evaluation slower (we didn't check) and certainly makes the generated Core much harder to read. Technically speaking, we could get a RuntimeScheme from the TypeScheme and the denotation statically if we changed the definition of TypeScheme and made it a singleton, but then the conversion function would have to become a class anyway and we'd just replicate what we have here, except in a much more complicated way.

Methods

knownMonotype :: TypeScheme val args res Source #

toMonoF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val Source #

Convert the denotation of a builtin to its runtime counterpart. The argument is in ReadKnownM, because that's what deferred unlifting amounts to: passing the action returning the builtin application around until full saturation, which is when the action actually gets run.

Instances

Instances details
(Typeable res, KnownTypeAst TyName (UniOf val) res, MakeKnown val res) => KnownMonotype val ('[] :: [Type]) res Source #

Once we've run out of term-level arguments, we return a TypeSchemeResult/RuntimeSchemeResult.

Instance details

Defined in PlutusCore.Builtin.Meaning

Methods

knownMonotype :: TypeScheme val ('[] :: [Type]) res Source #

toMonoF :: ReadKnownM (FoldArgs ('[] :: [Type]) res, FoldArgs ('[] :: [Type]) ExBudgetStream) -> BuiltinRuntime val Source #

(Typeable arg, KnownTypeAst TyName (UniOf val) arg, MakeKnown val arg, ReadKnown val arg, KnownMonotype val args res) => KnownMonotype val (arg ': args) res Source #

Every term-level argument becomes a TypeSchemeArrow/RuntimeSchemeArrow.

Instance details

Defined in PlutusCore.Builtin.Meaning

Methods

knownMonotype :: TypeScheme val (arg ': args) res Source #

toMonoF :: ReadKnownM (FoldArgs (arg ': args) res, FoldArgs (arg ': args) ExBudgetStream) -> BuiltinRuntime val Source #

class KnownMonotype val args res => KnownPolytype (binds :: [Some TyNameRep]) val (args :: [Type]) res where Source #

A class that allows us to derive a polytype for a builtin.

Methods

knownPolytype :: TypeScheme val args res Source #

toPolyF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val Source #

Convert the denotation of a builtin to its runtime counterpart. The argument is in ReadKnownM, because that's what we need to do: passing the action returning the builtin application around until full saturation, which is when the action actually gets run.

Instances

Instances details
KnownMonotype val args res => KnownPolytype ('[] :: [Some TyNameRep]) val args res Source #

Once we've run out of type-level arguments, we start handling term-level ones.

Instance details

Defined in PlutusCore.Builtin.Meaning

(KnownSymbol name, KnownNat uniq, KnownKind kind, KnownPolytype binds val args res) => KnownPolytype ('Some ('TyNameRep name uniq :: TyNameRep kind) ': binds) val args res Source #

Every type-level argument becomes a TypeSchemeAll.

Instance details

Defined in PlutusCore.Builtin.Meaning

type family ThrowOnBothEmpty (binds :: [Some TyNameRep]) (args :: [Type]) (isBuiltin :: Bool) a where ... Source #

Ensure a built-in function is not nullary and throw a nice error otherwise.

Equations

ThrowOnBothEmpty ('[] :: [Some TyNameRep]) ('[] :: [Type]) 'True a = TypeError (('Text "A built-in function must take at least one type or term argument" ':$$: ((('Text "\8216" ':<>: 'ShowType a) ':<>: 'Text "\8217 is a built-in type") ':<>: 'Text " so you can embed any of its values as a constant")) ':$$: 'Text "If you still want a built-in function, add a dummy \8216()\8217 argument") :: Constraint 
ThrowOnBothEmpty ('[] :: [Some TyNameRep]) ('[] :: [Type]) 'False a = TypeError ('Text "A built-in function must take at least one type or term argument" ':$$: 'Text "To fix this error add a dummy \8216()\8217 argument") :: Constraint 
ThrowOnBothEmpty _1 _2 _3 _4 = () 

toBuiltinRuntime :: cost -> BuiltinMeaning val cost -> BuiltinRuntime val Source #

Convert a BuiltinMeaning to a BuiltinRuntime given a cost model.

toBuiltinsRuntime :: forall cost (uni :: Type -> Type) fun val. (cost ~ CostingPart uni fun, ToBuiltinMeaning uni fun, HasMeaningIn uni val) => BuiltinSemanticsVariant fun -> cost -> BuiltinsRuntime fun val Source #

Calculate runtime info for all built-in functions given meanings of builtins (as a constraint), the semantics variant of the set of builtins and a cost model.