plutus-core-1.34.0.0: Language library for Plutus Core
Safe HaskellSafe-Inferred
LanguageHaskell2010

PlutusIR.Compiler

Synopsis

Documentation

compileProgramCompiling m e uni fun a ⇒ Program TyName Name uni fun a → m (PLCProgram uni fun a) Source #

compileToReadable ∷ ∀ m e uni fun a b. (Compiling m e uni fun a, b ~ Provenance a) ⇒ Program TyName Name uni fun b → m (Program TyName Name uni fun b) Source #

The 1st half of the PIR compiler pipeline up to floating/merging the lets. We stop momentarily here to give a chance to the tx-plugin to dump a "readable" version of pir (i.e. floated).

compileReadableToPlc ∷ ∀ m e uni fun a b. (Compiling m e uni fun a, b ~ Provenance a) ⇒ Program TyName Name uni fun b → m (PLCProgram uni fun a) Source #

The 2nd half of the PIR compiler pipeline. Compiles a Term into a PLC Term, by removing/translating step-by-step the PIR's language constructs to PLC. Note: the result *does* have globally unique names.

type Compiling m e uni fun a = (Monad m, MonadReader (CompilationCtx uni fun a) m, AsTypeError e (Term TyName Name uni fun ()) uni fun (Provenance a), AsTypeErrorExt e uni (Provenance a), AsError e uni fun (Provenance a), MonadError e m, MonadQuote m, Ord a, Typecheckable uni fun, GEq uni, PrettyUni uni, Pretty fun, Pretty a) Source #

data Error uni fun a Source #

Constructors

CompilationError !a !Text

A generic compilation error.

UnsupportedError !a !Text

An error relating specifically to an unsupported feature.

OptionsError !Text

An error relating to compilation options.

PLCError !(Error uni fun a)

An error from running some PLC function, lifted into this error type for convenience.

PLCTypeError !(TypeError (Term TyName Name uni fun ()) uni fun a) 
PIRTypeError !(TypeErrorExt uni a) 

Instances

Instances details
(PrettyUni uni, Pretty fun, Pretty ann) ⇒ PrettyBy PrettyConfigPlc (Error uni fun ann) Source # 
Instance details

Defined in PlutusIR.Error

Methods

prettyByPrettyConfigPlcError uni fun ann → Doc ann0 Source #

prettyListByPrettyConfigPlc → [Error uni fun ann] → Doc ann0 Source #

Functor (Error uni fun) Source # 
Instance details

Defined in PlutusIR.Error

Methods

fmap ∷ (a → b) → Error uni fun a → Error uni fun b Source #

(<$) ∷ a → Error uni fun b → Error uni fun a Source #

(ThrowableBuiltins uni fun, Pretty ann, Typeable ann) ⇒ Exception (Error uni fun ann) Source # 
Instance details

Defined in PlutusIR.Error

Methods

toExceptionError uni fun ann → SomeException Source #

fromExceptionSomeExceptionMaybe (Error uni fun ann) Source #

displayExceptionError uni fun ann → String Source #

(PrettyUni uni, Pretty fun, Pretty ann) ⇒ Show (Error uni fun ann) Source # 
Instance details

Defined in PlutusIR.Error

Methods

showsPrecIntError uni fun ann → ShowS Source #

showError uni fun ann → String Source #

showList ∷ [Error uni fun ann] → ShowS Source #

AsFreeVariableError (Error uni fun a) Source # 
Instance details

Defined in PlutusIR.Error

Methods

_FreeVariableError ∷ Prism' (Error uni fun a) FreeVariableError Source #

_FreeUnique ∷ Prism' (Error uni fun a) Unique Source #

_FreeIndex ∷ Prism' (Error uni fun a) Index Source #

AsParserErrorBundle (Error uni fun a) Source # 
Instance details

Defined in PlutusIR.Error

(PrettyUni uni, Pretty fun, Pretty ann) ⇒ Pretty (Error uni fun ann) Source # 
Instance details

Defined in PlutusIR.Error

Methods

prettyError uni fun ann → Doc ann0 Source #

prettyList ∷ [Error uni fun ann] → Doc ann0 Source #

AsUniqueError (Error uni fun a) a Source # 
Instance details

Defined in PlutusIR.Error

Methods

_UniqueError ∷ Prism' (Error uni fun a) (UniqueError a) Source #

_MultiplyDefined ∷ Prism' (Error uni fun a) (Unique, a, a) Source #

_IncoherentUsage ∷ Prism' (Error uni fun a) (Unique, a, a) Source #

_FreeVariable ∷ Prism' (Error uni fun a) (Unique, a) Source #

AsTypeErrorExt (Error uni fun a) uni a Source # 
Instance details

Defined in PlutusIR.Error

Methods

_TypeErrorExt ∷ Prism' (Error uni fun a) (TypeErrorExt uni a) Source #

_MalformedDataConstrResType ∷ Prism' (Error uni fun a) (a, Type TyName uni a) Source #

AsError (Error uni fun a) uni fun a Source # 
Instance details

Defined in PlutusIR.Error

Methods

_Error ∷ Prism' (Error uni fun a) (Error uni fun a) Source #

_CompilationError ∷ Prism' (Error uni fun a) (a, Text) Source #

_UnsupportedError ∷ Prism' (Error uni fun a) (a, Text) Source #

_OptionsError ∷ Prism' (Error uni fun a) Text Source #

_PLCError ∷ Prism' (Error uni fun a) (Error0 uni fun a) Source #

_PLCTypeError ∷ Prism' (Error uni fun a) (TypeError (Term TyName Name uni fun ()) uni fun a) Source #

_PIRTypeError ∷ Prism' (Error uni fun a) (TypeErrorExt uni a) Source #

AsTypeError (Error uni fun a) (Term TyName Name uni fun ()) uni fun a Source # 
Instance details

Defined in PlutusIR.Error

Methods

_TypeError ∷ Prism' (Error uni fun a) (TypeError (Term TyName Name uni fun ()) uni fun a) Source #

_KindMismatch ∷ Prism' (Error uni fun a) (a, Type TyName uni (), ExpectedShapeOr (Kind ()), Kind ()) Source #

_TypeMismatch ∷ Prism' (Error uni fun a) (a, Term TyName Name uni fun (), ExpectedShapeOr (Type TyName uni ()), Normalized (Type TyName uni ())) Source #

_TyNameMismatch ∷ Prism' (Error uni fun a) (a, TyName, TyName) Source #

_NameMismatch ∷ Prism' (Error uni fun a) (a, Name, Name) Source #

_FreeTypeVariableE ∷ Prism' (Error uni fun a) (a, TyName) Source #

_FreeVariableE ∷ Prism' (Error uni fun a) (a, Name) Source #

_UnknownBuiltinFunctionE ∷ Prism' (Error uni fun a) (a, fun) Source #

class AsError r uni fun a | r → uni fun a where Source #

Minimal complete definition

_Error

Methods

_Error ∷ Prism' r (Error uni fun a) Source #

_CompilationError ∷ Prism' r (a, Text) Source #

_UnsupportedError ∷ Prism' r (a, Text) Source #

_OptionsError ∷ Prism' r Text Source #

_PLCError ∷ Prism' r (Error uni fun a) Source #

_PLCTypeError ∷ Prism' r (TypeError (Term TyName Name uni fun ()) uni fun a) Source #

_PIRTypeError ∷ Prism' r (TypeErrorExt uni a) Source #

Instances

Instances details
AsError (Error uni fun a) uni fun a Source # 
Instance details

Defined in PlutusIR.Error

Methods

_Error ∷ Prism' (Error uni fun a) (Error uni fun a) Source #

_CompilationError ∷ Prism' (Error uni fun a) (a, Text) Source #

_UnsupportedError ∷ Prism' (Error uni fun a) (a, Text) Source #

_OptionsError ∷ Prism' (Error uni fun a) Text Source #

_PLCError ∷ Prism' (Error uni fun a) (Error0 uni fun a) Source #

_PLCTypeError ∷ Prism' (Error uni fun a) (TypeError (Term TyName Name uni fun ()) uni fun a) Source #

_PIRTypeError ∷ Prism' (Error uni fun a) (TypeErrorExt uni a) Source #

class AsTypeError r term (uni ∷ TypeType) fun ann | r → term uni fun ann where Source #

Minimal complete definition

_TypeError

Methods

_TypeError ∷ Prism' r (TypeError term uni fun ann) Source #

_KindMismatch ∷ Prism' r (ann, Type TyName uni (), ExpectedShapeOr (Kind ()), Kind ()) Source #

_TypeMismatch ∷ Prism' r (ann, term, ExpectedShapeOr (Type TyName uni ()), Normalized (Type TyName uni ())) Source #

_TyNameMismatch ∷ Prism' r (ann, TyName, TyName) Source #

_NameMismatch ∷ Prism' r (ann, Name, Name) Source #

_FreeTypeVariableE ∷ Prism' r (ann, TyName) Source #

_FreeVariableE ∷ Prism' r (ann, Name) Source #

_UnknownBuiltinFunctionE ∷ Prism' r (ann, fun) Source #

Instances

Instances details
AsTypeError (Error uni fun ann) (Term TyName Name uni fun ()) uni fun ann 
Instance details

Defined in PlutusCore.Error

Methods

_TypeError ∷ Prism' (Error uni fun ann) (TypeError (Term TyName Name uni fun ()) uni fun ann) Source #

_KindMismatch ∷ Prism' (Error uni fun ann) (ann, Type TyName uni (), ExpectedShapeOr (Kind ()), Kind ()) Source #

_TypeMismatch ∷ Prism' (Error uni fun ann) (ann, Term TyName Name uni fun (), ExpectedShapeOr (Type TyName uni ()), Normalized (Type TyName uni ())) Source #

_TyNameMismatch ∷ Prism' (Error uni fun ann) (ann, TyName, TyName) Source #

_NameMismatch ∷ Prism' (Error uni fun ann) (ann, Name, Name) Source #

_FreeTypeVariableE ∷ Prism' (Error uni fun ann) (ann, TyName) Source #

_FreeVariableE ∷ Prism' (Error uni fun ann) (ann, Name) Source #

_UnknownBuiltinFunctionE ∷ Prism' (Error uni fun ann) (ann, fun) Source #

AsTypeError (Error uni fun ann) (Term TyName Name uni fun ()) uni fun ann Source # 
Instance details

Defined in PlutusIR.Compiler.Error

Methods

_TypeError ∷ Prism' (Error uni fun ann) (TypeError (Term TyName Name uni fun ()) uni fun ann) Source #

_KindMismatch ∷ Prism' (Error uni fun ann) (ann, Type TyName uni (), ExpectedShapeOr (Kind ()), Kind ()) Source #

_TypeMismatch ∷ Prism' (Error uni fun ann) (ann, Term TyName Name uni fun (), ExpectedShapeOr (Type TyName uni ()), Normalized (Type TyName uni ())) Source #

_TyNameMismatch ∷ Prism' (Error uni fun ann) (ann, TyName, TyName) Source #

_NameMismatch ∷ Prism' (Error uni fun ann) (ann, Name, Name) Source #

_FreeTypeVariableE ∷ Prism' (Error uni fun ann) (ann, TyName) Source #

_FreeVariableE ∷ Prism' (Error uni fun ann) (ann, Name) Source #

_UnknownBuiltinFunctionE ∷ Prism' (Error uni fun ann) (ann, fun) Source #

AsTypeError (Error uni fun a) (Term TyName Name uni fun ()) uni fun a Source # 
Instance details

Defined in PlutusIR.Error

Methods

_TypeError ∷ Prism' (Error uni fun a) (TypeError (Term TyName Name uni fun ()) uni fun a) Source #

_KindMismatch ∷ Prism' (Error uni fun a) (a, Type TyName uni (), ExpectedShapeOr (Kind ()), Kind ()) Source #

_TypeMismatch ∷ Prism' (Error uni fun a) (a, Term TyName Name uni fun (), ExpectedShapeOr (Type TyName uni ()), Normalized (Type TyName uni ())) Source #

_TyNameMismatch ∷ Prism' (Error uni fun a) (a, TyName, TyName) Source #

_NameMismatch ∷ Prism' (Error uni fun a) (a, Name, Name) Source #

_FreeTypeVariableE ∷ Prism' (Error uni fun a) (a, TyName) Source #

_FreeVariableE ∷ Prism' (Error uni fun a) (a, Name) Source #

_UnknownBuiltinFunctionE ∷ Prism' (Error uni fun a) (a, fun) Source #

AsTypeError (TypeError term uni fun ann) term uni fun ann 
Instance details

Defined in PlutusCore.Error

Methods

_TypeError ∷ Prism' (TypeError term uni fun ann) (TypeError term uni fun ann) Source #

_KindMismatch ∷ Prism' (TypeError term uni fun ann) (ann, Type TyName uni (), ExpectedShapeOr (Kind ()), Kind ()) Source #

_TypeMismatch ∷ Prism' (TypeError term uni fun ann) (ann, term, ExpectedShapeOr (Type TyName uni ()), Normalized (Type TyName uni ())) Source #

_TyNameMismatch ∷ Prism' (TypeError term uni fun ann) (ann, TyName, TyName) Source #

_NameMismatch ∷ Prism' (TypeError term uni fun ann) (ann, Name, Name) Source #

_FreeTypeVariableE ∷ Prism' (TypeError term uni fun ann) (ann, TyName) Source #

_FreeVariableE ∷ Prism' (TypeError term uni fun ann) (ann, Name) Source #

_UnknownBuiltinFunctionE ∷ Prism' (TypeError term uni fun ann) (ann, fun) Source #

class AsTypeErrorExt r uni ann | r → uni ann where Source #

Minimal complete definition

_TypeErrorExt

Methods

_TypeErrorExt ∷ Prism' r (TypeErrorExt uni ann) Source #

_MalformedDataConstrResType ∷ Prism' r (ann, Type TyName uni ann) Source #

Instances

Instances details
AsTypeErrorExt (TypeErrorExt uni ann) uni ann Source # 
Instance details

Defined in PlutusIR.Error

Methods

_TypeErrorExt ∷ Prism' (TypeErrorExt uni ann) (TypeErrorExt uni ann) Source #

_MalformedDataConstrResType ∷ Prism' (TypeErrorExt uni ann) (ann, Type TyName uni ann) Source #

AsTypeErrorExt (Error uni fun a) uni a Source # 
Instance details

Defined in PlutusIR.Error

Methods

_TypeErrorExt ∷ Prism' (Error uni fun a) (TypeErrorExt uni a) Source #

_MalformedDataConstrResType ∷ Prism' (Error uni fun a) (a, Type TyName uni a) Source #

data Provenance a Source #

Indicates where a value comes from.

This is either an original annotation or a pieces of context explaining how the term relates to a previous Provenance. We also provide noProvenance for convenience.

The provenance should always be just the original annotation, if we have one. It should only be another kind of provenance if we're in the process of generating some term that doesn't correspond directly to a term in the original AST.

Constructors

Original a 
LetBinding Recursivity (Provenance a) 
TermBinding String (Provenance a) 
TypeBinding String (Provenance a) 
DatatypeComponent DatatypeComponent (Provenance a) 
MultipleSources (Set (Provenance a))

Added for accumulating difference provenances when floating lets

Instances

Instances details
Foldable Provenance Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Methods

foldMonoid m ⇒ Provenance m → m Source #

foldMapMonoid m ⇒ (a → m) → Provenance a → m Source #

foldMap'Monoid m ⇒ (a → m) → Provenance a → m Source #

foldr ∷ (a → b → b) → b → Provenance a → b Source #

foldr' ∷ (a → b → b) → b → Provenance a → b Source #

foldl ∷ (b → a → b) → b → Provenance a → b Source #

foldl' ∷ (b → a → b) → b → Provenance a → b Source #

foldr1 ∷ (a → a → a) → Provenance a → a Source #

foldl1 ∷ (a → a → a) → Provenance a → a Source #

toListProvenance a → [a] Source #

nullProvenance a → Bool Source #

lengthProvenance a → Int Source #

elemEq a ⇒ a → Provenance a → Bool Source #

maximumOrd a ⇒ Provenance a → a Source #

minimumOrd a ⇒ Provenance a → a Source #

sumNum a ⇒ Provenance a → a Source #

productNum a ⇒ Provenance a → a Source #

Ord a ⇒ Monoid (Provenance a) Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Ord a ⇒ Semigroup (Provenance a) Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Generic (Provenance a) Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Associated Types

type Rep (Provenance a) ∷ TypeType Source #

Methods

fromProvenance a → Rep (Provenance a) x Source #

toRep (Provenance a) x → Provenance a Source #

Show a ⇒ Show (Provenance a) Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Eq a ⇒ Eq (Provenance a) Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Methods

(==)Provenance a → Provenance a → Bool Source #

(/=)Provenance a → Provenance a → Bool Source #

Ord a ⇒ Ord (Provenance a) Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Hashable a ⇒ Hashable (Provenance a) Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Methods

hashWithSaltIntProvenance a → Int Source #

hashProvenance a → Int Source #

Pretty a ⇒ Pretty (Provenance a) Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Methods

prettyProvenance a → Doc ann Source #

prettyList ∷ [Provenance a] → Doc ann Source #

type Rep (Provenance a) Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

type Rep (Provenance a) = D1 ('MetaData "Provenance" "PlutusIR.Compiler.Provenance" "plutus-core-1.34.0.0-inplace-plutus-ir" 'False) ((C1 ('MetaCons "Original" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: (C1 ('MetaCons "LetBinding" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Recursivity) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Provenance a))) :+: C1 ('MetaCons "TermBinding" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Provenance a))))) :+: (C1 ('MetaCons "TypeBinding" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Provenance a))) :+: (C1 ('MetaCons "DatatypeComponent" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DatatypeComponent) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Provenance a))) :+: C1 ('MetaCons "MultipleSources" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set (Provenance a)))))))

data DatatypeComponent Source #

Instances

Instances details
Generic DatatypeComponent Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Associated Types

type Rep DatatypeComponentTypeType Source #

Show DatatypeComponent Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Eq DatatypeComponent Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Ord DatatypeComponent Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Hashable DatatypeComponent Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

Pretty DatatypeComponent Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

type Rep DatatypeComponent Source # 
Instance details

Defined in PlutusIR.Compiler.Provenance

type Rep DatatypeComponent = D1 ('MetaData "DatatypeComponent" "PlutusIR.Compiler.Provenance" "plutus-core-1.34.0.0-inplace-plutus-ir" 'False) ((C1 ('MetaCons "Constructor" 'PrefixI 'False) (U1TypeType) :+: (C1 ('MetaCons "ConstructorType" 'PrefixI 'False) (U1TypeType) :+: C1 ('MetaCons "Destructor" 'PrefixI 'False) (U1TypeType))) :+: (C1 ('MetaCons "DestructorType" 'PrefixI 'False) (U1TypeType) :+: (C1 ('MetaCons "DatatypeType" 'PrefixI 'False) (U1TypeType) :+: C1 ('MetaCons "PatternFunctor" 'PrefixI 'False) (U1TypeType))))

data DatatypeStyle Source #

What style to use when encoding datatypes. Generally, SumsOfProducts is superior, unless you are targeting an old Plutus Core language version.

See Note [Encoding of datatypes]

data CompilationCtx uni fun a Source #

ccOpts ∷ ∀ uni fun a. Lens' (CompilationCtx uni fun a) (CompilationOpts a) Source #

ccEnclosing ∷ ∀ uni fun a. Lens' (CompilationCtx uni fun a) (Provenance a) Source #

ccTypeCheckConfig ∷ ∀ uni fun a. Lens' (CompilationCtx uni fun a) (PirTCConfig uni fun) Source #

ccBuiltinsInfo ∷ ∀ uni fun a. Lens' (CompilationCtx uni fun a) (BuiltinsInfo uni fun) Source #

ccBuiltinCostModel ∷ ∀ uni fun a. Lens' (CompilationCtx uni fun a) (CostingPart uni fun) Source #

data PirTCConfig uni fun Source #

extending the plc typecheck config with AllowEscape

data AllowEscape Source #

Extra flag to be passed in the TypeCheckM Reader context, to signal if the PIR expression currently being typechecked is at the top-level and thus its type can escape, or nested and thus not allowed to escape.

Constructors

YesEscape 
NoEscape 

runCompilerPass ∷ (Compiling m e uni fun a, b ~ Provenance a) ⇒ m (Pass m tyname name uni fun b) → Term tyname name uni fun b → m (Term tyname name uni fun b) Source #

simplifierCompiling m e uni fun a ⇒ m (Pass m TyName Name uni fun (Provenance a)) Source #