[TM-262] Improve optimiser
Description
Description
Following problems exist:
-
linearizeRight
has poor performance; -
Seq a b
is not recognised by(Seq a (Seq b c))
rule wherec
is free; - Some non-leaf instructions (
MAP
) are left unoptimised; -
optimizeWithRule
is not entirely correct; - We need type-directed optimisations, like
forall (op :: s -> a s). op DROP ==> NOP
. These shouldn't erase any possible side-effects. - We need more rules (
MAP/MAP
fusion,MAP/ITER
fusion,IF [x] [x] -> DROP x
, etc).
I will try to fix these problems.
Related issue(s)
https://issues.serokell.io/issue/TM-262
Changes
I converted recursive application to bottom-up, which frees us from descent into the AST, since all sub-branches are already optimised.
The lineariseRight
now goes as far as last Seq (Seq _ _) _
node and reapplies ruleset on each node re-appended from LHS to RHS.
✅ Checklist for your Merge Request
Related changes (conditional)
-
Tests (see short guidelines)
-
If I added new functionality, I added tests covering it. -
If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
-
-
Documentation
Stylistic guide (mandatory)
-
My commits comply with the following policy. -
My code complies with the style guide.
Edited by Андреев Кирилл