morley-1.19.1: Developer tools for the Michelson Language
Safe HaskellSafe-Inferred
LanguageHaskell2010

Morley.Michelson.Optimizer

Description

Optimizer for typed instructions.

It's quite experimental and incomplete.

Synopsis

Documentation

optimize :: Instr inp out -> Instr inp out Source #

Optimize a typed instruction by replacing some sequences of instructions with smaller equivalent sequences. Applies default set of rewrite rules.

optimizeWithConf :: OptimizerConf -> Instr inp out -> Instr inp out Source #

Optimize a typed instruction using a custom set of rules. The set is divided into several stages, as applying some rules can prevent others to be performed.

If any stage resulted in optimizations, we apply it again until we reach fixpoint, but no more than ocMaxIterations times.

optimizeVerboseWithConf :: OptimizerConf -> Instr inp out -> ([OptimizerStageStats], Instr inp out) Source #

Returns some optimizer statistics in addition to optimized instruction. Mostly useful for testing and debugging.

defaultOptimizerConf :: OptimizerConf Source #

Default config - all commonly useful rules will be applied to all the code.

defaultRules :: Ruleset Source #

Default optimization rules.

defaultRulesAndPushPack :: Ruleset Source #

We do not enable pushPack rule by default because it is potentially dangerous. There are various code processing functions that may depend on constants, e. g. string transformations.

orRule :: (Rule -> Rule) -> (Rule -> Rule) -> Rule -> Rule Source #

Combine two rule fixpoints.

orSimpleRule :: (Rule -> Rule) -> Rule -> Rule -> Rule Source #

Combine a rule fixpoint and a simple rule.

newtype Rule Source #

Constructors

Rule 

Fields

data OptimizerConf Source #

Instances

Instances details
Default OptimizerConf Source # 
Instance details

Defined in Morley.Michelson.Optimizer

Methods

def :: OptimizerConf #

Ruleset manipulation

data OptimizationStage Source #

Optimization stages. Stages are run in first to last order, each stage has an Int argument, which allows splitting each stage into sub-stages, which will run lowest index to highest. All default rules use sub-stage 0.

Constructors

OptimizationStagePrepare Int 
OptimizationStageMain Int

Main optimisation stage, except rules that would interfere with other rules.

OptimizationStageMainExtended Int

All main stage rules.

OptimizationStageRollAdjacent Int

Main stage rules unroll DROP n, PAIR n, etc into their primitive counterparts to simplify some optimisations. This stages coalesces them back.

data Ruleset Source #

A set of optimization stages. Rules at the same sub-stage are applied in arbitrary order. See OptimizationStage for explanation of sub-stages.

Default ruleset is empty.

Instances

Instances details
Monoid Ruleset Source # 
Instance details

Defined in Morley.Michelson.Optimizer

Semigroup Ruleset Source # 
Instance details

Defined in Morley.Michelson.Optimizer

Default Ruleset Source # 
Instance details

Defined in Morley.Michelson.Optimizer

Methods

def :: Ruleset #

rulesAtPrio :: OptimizationStage -> Ruleset -> [Rule] Source #

Get rules for a given priority as a list.

insertRuleAtPrio :: OptimizationStage -> Rule -> Ruleset -> Ruleset Source #

Insert a single rule at a given priority without touching other rules.

clearRulesAtPrio :: OptimizationStage -> Ruleset -> Ruleset Source #

Remove the stage with the given priority.

alterRulesAtPrio :: ([Rule] -> [Rule]) -> OptimizationStage -> Ruleset -> Ruleset Source #

Alter all stage rules for a given priority.