Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Types and their functions, and general utility (including heuristics) for inlining.
Synopsis
- type ExternalConstraints tyname name uni fun m = (HasUnique name TermUnique, HasUnique tyname TypeUnique, Eq name, Eq tyname, ToBuiltinMeaning uni fun, MonadQuote m)
- type InliningConstraints tyname name uni fun = (HasUnique name TermUnique, HasUnique tyname TypeUnique, Eq name, Eq tyname, ToBuiltinMeaning uni fun)
- data InlineInfo tyname name uni fun ann = InlineInfo {
- _iiVarInfo ∷ VarsInfo tyname name uni ann
- _iiUsages ∷ Usages
- _iiHints ∷ InlineHints name ann
- _iiBuiltinsInfo ∷ BuiltinsInfo uni fun
- _iiInlineConstants ∷ Bool
- 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)
- iiUsages ∷ ∀ tyname name uni fun ann. Lens' (InlineInfo tyname name uni fun ann) Usages
- iiInlineConstants ∷ ∀ tyname name uni fun ann. Lens' (InlineInfo tyname name uni fun ann) Bool
- iiHints ∷ ∀ tyname name uni fun ann. Lens' (InlineInfo tyname name uni fun ann) (InlineHints name ann)
- 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)
- type InlineM tyname name uni fun ann = ReaderT (InlineInfo tyname name uni fun ann) (StateT (InlinerState tyname name uni fun ann) Quote)
- newtype InlineTerm tyname name uni fun ann = Done (Dupable (Term tyname name uni fun ann))
- newtype TermSubst tyname name uni fun ann = TermSubst {
- _unTermSubst ∷ UniqueMap TermUnique (InlineTerm tyname name uni fun ann)
- newtype TypeSubst tyname uni ann = TypeSubst {
- _unTypeSubst ∷ UniqueMap TypeUnique (Dupable (Type tyname uni ann))
- newtype NonRecInScopeSet tyname name uni fun ann = NonRecInScopeSet {
- _unNonRecInScopeSet ∷ UniqueMap TermUnique (InlineVarInfo tyname name uni fun ann)
- data InlineVarInfo tyname name uni fun ann = MkVarInfo {
- varStrictness ∷ Strictness
- varRhs ∷ InlineTerm tyname name uni fun ann
- data InlinerState tyname name uni fun ann = InlinerState {
- _termSubst ∷ TermSubst tyname name uni fun ann
- _typeSubst ∷ TypeSubst tyname uni ann
- _nonRecInScopeSet ∷ 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))
- 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)))
- 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))
- typeSubst ∷ ∀ tyname name uni fun ann. Lens' (InlinerState tyname name uni fun ann) (TypeSubst tyname uni ann)
- termSubst ∷ ∀ tyname name uni fun ann. Lens' (InlinerState tyname name uni fun ann) (TermSubst tyname name uni fun ann)
- nonRecInScopeSet ∷ ∀ tyname name uni fun ann. Lens' (InlinerState tyname name uni fun ann) (NonRecInScopeSet tyname name uni fun ann)
- lookupTerm ∷ HasUnique name TermUnique ⇒ name → InlinerState tyname name uni fun ann → Maybe (InlineTerm tyname name uni fun ann)
- extendTerm ∷ HasUnique name TermUnique ⇒ name → InlineTerm tyname name uni fun ann → InlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann
- lookupType ∷ HasUnique tyname TypeUnique ⇒ tyname → InlinerState tyname name uni fun ann → Maybe (Dupable (Type tyname uni ann))
- isTypeSubstEmpty ∷ InlinerState tyname name uni fun ann → Bool
- extendType ∷ HasUnique tyname TypeUnique ⇒ tyname → Type tyname uni ann → InlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann
- lookupVarInfo ∷ HasUnique name TermUnique ⇒ name → InlinerState tyname name uni fun ann → Maybe (InlineVarInfo tyname name uni fun ann)
- extendVarInfo ∷ HasUnique name TermUnique ⇒ name → InlineVarInfo tyname name uni fun ann → InlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann
- 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)
- substTyName ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ tyname → InlineM tyname name uni fun ann (Maybe (Type tyname uni ann))
- 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))
- 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)
- checkPurity ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ Term tyname name uni fun ann → InlineM tyname name uni fun ann Bool
- 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
- isTermBindingPure ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ Strictness → Term tyname name uni fun ann → InlineM tyname name uni fun ann Bool
- nameUsedAtMostOnce ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ name → InlineM tyname name uni fun ann Bool
- effectSafe ∷ ∀ tyname name uni fun ann. InliningConstraints tyname name uni fun ⇒ Term tyname name uni fun ann → Strictness → name → Bool → InlineM tyname name uni fun ann Bool
- costIsAcceptable ∷ Term tyname name uni fun ann → Bool
- sizeIsAcceptable ∷ Bool → Term tyname name uni fun ann → Bool
- trivialType ∷ Type tyname uni ann → Bool
- shouldUnconditionallyInline ∷ InliningConstraints 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
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.
InlineInfo | |
|
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 #
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']
newtype TermSubst tyname name uni fun ann Source #
Term substitution, Subst
in the paper.
A map of unprocessed variable and its substitution range.
TermSubst | |
|
Instances
Monoid (TermSubst tyname name uni fun ann) Source # | |
Defined in PlutusIR.Transform.Inline.Utils | |
Semigroup (TermSubst tyname name uni fun ann) Source # | |
Defined in PlutusIR.Transform.Inline.Utils (<>) ∷ TermSubst tyname name uni fun ann → TermSubst tyname name uni fun ann → TermSubst tyname name uni fun ann Source # sconcat ∷ NonEmpty (TermSubst tyname name uni fun ann) → TermSubst tyname name uni fun ann Source # stimes ∷ Integral 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.
TypeSubst | |
|
newtype NonRecInScopeSet tyname name uni fun ann Source #
A mapping including all non-recursive in scope variables.
NonRecInScopeSet | |
|
Instances
Monoid (NonRecInScopeSet tyname name uni fun ann) Source # | |
Defined in PlutusIR.Transform.Inline.Utils mempty ∷ NonRecInScopeSet tyname name uni fun ann Source # mappend ∷ NonRecInScopeSet 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 # | |
Defined in PlutusIR.Transform.Inline.Utils (<>) ∷ NonRecInScopeSet tyname name uni fun ann → NonRecInScopeSet tyname name uni fun ann → NonRecInScopeSet tyname name uni fun ann Source # sconcat ∷ NonEmpty (NonRecInScopeSet tyname name uni fun ann) → NonRecInScopeSet tyname name uni fun ann Source # stimes ∷ Integral 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.
MkVarInfo | |
|
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.
InlinerState | |
|
Instances
Monoid (InlinerState tyname name uni fun ann) Source # | |
Defined in PlutusIR.Transform.Inline.Utils mempty ∷ InlinerState tyname name uni fun ann Source # mappend ∷ InlinerState 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 # | |
Defined in PlutusIR.Transform.Inline.Utils (<>) ∷ InlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann Source # sconcat ∷ NonEmpty (InlinerState tyname name uni fun ann) → InlinerState tyname name uni fun ann Source # stimes ∷ Integral b ⇒ b → InlinerState tyname name uni fun ann → InlinerState tyname name uni fun ann Source # | |
Generic (InlinerState tyname name uni fun ann) Source # | |
Defined in PlutusIR.Transform.Inline.Utils from ∷ InlinerState tyname name uni fun ann → Rep (InlinerState tyname name uni fun ann) x Source # to ∷ Rep (InlinerState tyname name uni fun ann) x → InlinerState tyname name uni fun ann Source # | |
type Rep (InlinerState tyname name uni fun ann) Source # | |
Defined in PlutusIR.Transform.Inline.Utils type Rep (InlinerState tyname name uni fun ann) = D1 ('MetaData "InlinerState" "PlutusIR.Transform.Inline.Utils" "plutus-core-1.39.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 #
∷ 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.
∷ 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.
lookupType ∷ HasUnique 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.
isTypeSubstEmpty ∷ InlinerState tyname name uni fun ann → Bool Source #
Check if the type substitution is empty.
∷ 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.
∷ 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.
∷ 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 ⇒ Strictness → Term 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 #
∷ ∀ 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 |
costIsAcceptable ∷ Term 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?
sizeIsAcceptable ∷ Bool → Term 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?
trivialType ∷ Type tyname uni ann → Bool Source #
Is this an utterly trivial type which might as well be inlined?
shouldUnconditionallyInline ∷ InliningConstraints 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 #