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

PlutusIR.Transform.Inline.Utils

Description

Types and their functions, and general utility (including heuristics) for inlining.

Synopsis

Documentation

type ExternalConstraints tyname name uni fun m = (HasUnique name TermUnique, HasUnique tyname TypeUnique, Eq name, Eq tyname, ToBuiltinMeaning uni fun, MonadQuote m) Source #

type InliningConstraints tyname name uni fun = (HasUnique name TermUnique, HasUnique tyname TypeUnique, Eq name, Eq tyname, ToBuiltinMeaning uni fun) Source #

data InlineInfo tyname name uni fun ann Source #

Information used by the inliner that is constant across its operation. This includes some contextual and configuration information, and also some pre-computed information about the program.

See [Inlining and global uniqueness] for caveats about this information.

Constructors

InlineInfo 

Fields

iiVarInfo ∷ ∀ tyname name uni fun ann tyname. Lens (InlineInfo tyname name uni fun ann) (InlineInfo tyname name uni fun ann) (VarsInfo tyname name uni ann) (VarsInfo tyname name uni ann) Source #

iiUsages ∷ ∀ tyname name uni fun ann. Lens' (InlineInfo tyname name uni fun ann) Usages Source #

iiInlineConstants ∷ ∀ tyname name uni fun ann. Lens' (InlineInfo tyname name uni fun ann) Bool Source #

iiHints ∷ ∀ tyname name uni fun ann. Lens' (InlineInfo tyname name uni fun ann) (InlineHints name ann) Source #

iiBuiltinsInfo ∷ ∀ tyname name uni fun ann fun. Lens (InlineInfo tyname name uni fun ann) (InlineInfo tyname name uni fun ann) (BuiltinsInfo uni fun) (BuiltinsInfo uni fun) Source #

type InlineM tyname name uni fun ann = ReaderT (InlineInfo tyname name uni fun ann) (StateT (InlinerState tyname name uni fun ann) Quote) Source #

The monad the inliner runs in.

newtype InlineTerm tyname name uni fun ann Source #

Substitution range, SubstRng in the paper but no Susp case. See Note [Inlining approach and 'Secrets of the GHC Inliner']

Constructors

Done (Dupable (Term tyname name uni fun ann)) 

newtype TermSubst tyname name uni fun ann Source #

Term substitution, Subst in the paper. A map of unprocessed variable and its substitution range.

Constructors

TermSubst 

Fields

Instances

Instances details
Monoid (TermSubst tyname name uni fun ann) Source # 
Instance details

Defined in PlutusIR.Transform.Inline.Utils

Methods

memptyTermSubst tyname name uni fun ann Source #

mappendTermSubst tyname name uni fun ann → TermSubst tyname name uni fun ann → TermSubst tyname name uni fun ann Source #

mconcat ∷ [TermSubst tyname name uni fun ann] → TermSubst tyname name uni fun ann Source #

Semigroup (TermSubst tyname name uni fun ann) Source # 
Instance details

Defined in PlutusIR.Transform.Inline.Utils

Methods

(<>)TermSubst tyname name uni fun ann → TermSubst tyname name uni fun ann → TermSubst tyname name uni fun ann Source #

sconcatNonEmpty (TermSubst tyname name uni fun ann) → TermSubst tyname name uni fun ann Source #

stimesIntegral b ⇒ b → TermSubst tyname name uni fun ann → TermSubst tyname name uni fun ann Source #

newtype TypeSubst tyname uni ann Source #

Type substitution, similar to TermSubst but for types. A map of unprocessed type variable and its substitution range.

Constructors

TypeSubst 

Fields

Instances

Instances details
Monoid (TypeSubst tyname uni ann) Source # 
Instance details

Defined in PlutusIR.Transform.Inline.Utils

Methods

memptyTypeSubst tyname uni ann Source #

mappendTypeSubst tyname uni ann → TypeSubst tyname uni ann → TypeSubst tyname uni ann Source #

mconcat ∷ [TypeSubst tyname uni ann] → TypeSubst tyname uni ann Source #

Semigroup (TypeSubst tyname uni ann) Source # 
Instance details

Defined in PlutusIR.Transform.Inline.Utils

Methods

(<>)TypeSubst tyname uni ann → TypeSubst tyname uni ann → TypeSubst tyname uni ann Source #

sconcatNonEmpty (TypeSubst tyname uni ann) → TypeSubst tyname uni ann Source #

stimesIntegral b ⇒ b → TypeSubst tyname uni ann → TypeSubst tyname uni ann Source #

newtype NonRecInScopeSet tyname name uni fun ann Source #

A mapping including all non-recursive in scope variables.

Constructors

NonRecInScopeSet 

Fields

Instances

Instances details
Monoid (NonRecInScopeSet tyname name uni fun ann) Source # 
Instance details

Defined in PlutusIR.Transform.Inline.Utils

Methods

memptyNonRecInScopeSet tyname name uni fun ann Source #

mappendNonRecInScopeSet tyname name uni fun ann → NonRecInScopeSet tyname name uni fun ann → NonRecInScopeSet tyname name uni fun ann Source #

mconcat ∷ [NonRecInScopeSet tyname name uni fun ann] → NonRecInScopeSet tyname name uni fun ann Source #

Semigroup (NonRecInScopeSet tyname name uni fun ann) Source # 
Instance details

Defined in PlutusIR.Transform.Inline.Utils

Methods

(<>)NonRecInScopeSet tyname name uni fun ann → NonRecInScopeSet tyname name uni fun ann → NonRecInScopeSet tyname name uni fun ann Source #

sconcatNonEmpty (NonRecInScopeSet tyname name uni fun ann) → NonRecInScopeSet tyname name uni fun ann Source #

stimesIntegral b ⇒ b → NonRecInScopeSet tyname name uni fun ann → NonRecInScopeSet tyname name uni fun ann Source #

data InlineVarInfo tyname name uni fun ann Source #

Info attached to a let-binding needed for call site inlining.

Constructors

MkVarInfo 

Fields

data InlinerState tyname name uni fun ann Source #

Inliner context for both unconditional inlining and call site inlining. It includes substitution for both terms and types, which is similar to Subst in the paper. It also includes the non recursive in-scope set for call site inlining.

Constructors

InlinerState 

Fields

Instances

Instances details
Monoid (InlinerState tyname name uni fun ann) Source # 
Instance details

Defined in PlutusIR.Transform.Inline.Utils

Methods

memptyInlinerState tyname name uni fun ann Source #

mappendInlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann Source #

mconcat ∷ [InlinerState tyname name uni fun ann] → InlinerState tyname name uni fun ann Source #

Semigroup (InlinerState tyname name uni fun ann) Source # 
Instance details

Defined in PlutusIR.Transform.Inline.Utils

Methods

(<>)InlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann Source #

sconcatNonEmpty (InlinerState tyname name uni fun ann) → InlinerState tyname name uni fun ann Source #

stimesIntegral b ⇒ b → InlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann Source #

Generic (InlinerState tyname name uni fun ann) Source # 
Instance details

Defined in PlutusIR.Transform.Inline.Utils

Associated Types

type Rep (InlinerState tyname name uni fun ann) ∷ TypeType Source #

Methods

fromInlinerState tyname name uni fun ann → Rep (InlinerState tyname name uni fun ann) x Source #

toRep (InlinerState tyname name uni fun ann) x → InlinerState tyname name uni fun ann Source #

type Rep (InlinerState tyname name uni fun ann) Source # 
Instance details

Defined in PlutusIR.Transform.Inline.Utils

type Rep (InlinerState tyname name uni fun ann) = D1 ('MetaData "InlinerState" "PlutusIR.Transform.Inline.Utils" "plutus-core-1.38.0.0-inplace-plutus-ir" 'False) (C1 ('MetaCons "InlinerState" 'PrefixI 'True) (S1 ('MetaSel ('Just "_termSubst") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (TermSubst tyname name uni fun ann)) :*: (S1 ('MetaSel ('Just "_typeSubst") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (TypeSubst tyname uni ann)) :*: S1 ('MetaSel ('Just "_nonRecInScopeSet") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (NonRecInScopeSet tyname name uni fun ann)))))

unTermSubst ∷ ∀ tyname name uni fun ann tyname name uni fun ann. Iso (TermSubst tyname name uni fun ann) (TermSubst tyname name uni fun ann) (UniqueMap TermUnique (InlineTerm tyname name uni fun ann)) (UniqueMap TermUnique (InlineTerm tyname name uni fun ann)) Source #

unTypeSubst ∷ ∀ tyname uni ann tyname uni ann. Iso (TypeSubst tyname uni ann) (TypeSubst tyname uni ann) (UniqueMap TypeUnique (Dupable (Type tyname uni ann))) (UniqueMap TypeUnique (Dupable (Type tyname uni ann))) Source #

unNonRecInScopeSet ∷ ∀ tyname name uni fun ann tyname name uni fun ann. Iso (NonRecInScopeSet tyname name uni fun ann) (NonRecInScopeSet tyname name uni fun ann) (UniqueMap TermUnique (InlineVarInfo tyname name uni fun ann)) (UniqueMap TermUnique (InlineVarInfo tyname name uni fun ann)) Source #

typeSubst ∷ ∀ tyname name uni fun ann. Lens' (InlinerState tyname name uni fun ann) (TypeSubst tyname uni ann) Source #

termSubst ∷ ∀ tyname name uni fun ann. Lens' (InlinerState tyname name uni fun ann) (TermSubst tyname name uni fun ann) Source #

nonRecInScopeSet ∷ ∀ tyname name uni fun ann. Lens' (InlinerState tyname name uni fun ann) (NonRecInScopeSet tyname name uni fun ann) Source #

lookupTerm Source #

Arguments

HasUnique name TermUnique 
⇒ name

The name of the variable.

InlinerState tyname name uni fun ann 
Maybe (InlineTerm tyname name uni fun ann) 

Look up the unprocessed variable in the term substitution.

extendTerm Source #

Arguments

HasUnique name TermUnique 
⇒ name

The name of the variable.

InlineTerm tyname name uni fun ann

The substitution range.

InlinerState tyname name uni fun ann 
InlinerState tyname name uni fun ann 

Insert the unprocessed variable into the term substitution.

lookupTypeHasUnique tyname TypeUnique ⇒ tyname → InlinerState tyname name uni fun ann → Maybe (Dupable (Type tyname uni ann)) Source #

Look up the unprocessed type variable in the type substitution.

isTypeSubstEmptyInlinerState tyname name uni fun ann → Bool Source #

Check if the type substitution is empty.

extendType Source #

Arguments

HasUnique tyname TypeUnique 
⇒ tyname

The name of the type variable.

Type tyname uni ann

Its type.

InlinerState tyname name uni fun ann 
InlinerState tyname name uni fun ann 

Insert the unprocessed type variable into the type substitution.

lookupVarInfo Source #

Arguments

HasUnique name TermUnique 
⇒ name

The name of the variable.

InlinerState tyname name uni fun ann 
Maybe (InlineVarInfo tyname name uni fun ann) 

Look up a variable in the in scope set.

extendVarInfo Source #

Arguments

HasUnique name TermUnique 
⇒ name

The name of the variable.

InlineVarInfo tyname name uni fun ann

The variable's info.

InlinerState tyname name uni fun ann 
InlinerState tyname name uni fun ann 

Insert a variable into the substitution.

applyTypeSubstitution ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ Type tyname uni ann → InlineM tyname name uni fun ann (Type tyname uni ann) Source #

substTyName ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ tyname → InlineM tyname name uni fun ann (Maybe (Type tyname uni ann)) Source #

substName ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ name → InlineM tyname name uni fun ann (Maybe (Term tyname name uni fun ann)) Source #

renameTerm ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ InlineTerm tyname name uni fun ann → InlineM tyname name uni fun ann (Term tyname name uni fun ann) Source #

checkPurity ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ Term tyname name uni fun ann → InlineM tyname name uni fun ann Bool Source #

Check if term is pure. See Note [Inlining and purity]

isFirstVarBeforeEffects ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ name → Term tyname name uni fun ann → InlineM tyname name uni fun ann Bool Source #

isTermBindingPure ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ StrictnessTerm tyname name uni fun ann → InlineM tyname name uni fun ann Bool Source #

Checks if a binding is pure, i.e. will evaluating it have effects

nameUsedAtMostOnce ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ name → InlineM tyname name uni fun ann Bool Source #

effectSafe Source #

Arguments

∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun 
Term tyname name uni fun ann 
Strictness 
→ name 
Bool

is it pure?

InlineM tyname name uni fun ann Bool 

costIsAcceptableTerm tyname name uni fun ann → Bool Source #

Is the cost increase (in terms of evaluation work) of inlining a variable whose RHS is the given term acceptable?

sizeIsAcceptableBoolTerm tyname name uni fun ann → Bool Source #

Is the size increase (in the AST) of inlining a variable whose RHS is the given term acceptable?

trivialTypeType tyname uni ann → Bool Source #

Is this an utterly trivial type which might as well be inlined?

shouldUnconditionallyInlineInliningConstraints tyname name uni fun ⇒ Strictness → name → Term tyname name uni fun ann → Term tyname name uni fun ann → InlineM tyname name uni fun ann Bool Source #