Skip to content

[TM-262] Improve optimiser

Description

Description

Following problems exist:

  1. linearizeRight has poor performance;
  2. Seq a b is not recognised by (Seq a (Seq b c)) rule where c is free;
  3. Some non-leaf instructions (MAP) are left unoptimised;
  4. optimizeWithRule is not entirely correct;
  5. We need type-directed optimisations, like forall (op :: s -> a s). op DROP ==> NOP. These shouldn't erase any possible side-effects.
  6. 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

    • I checked whether I should update the docs and did so if necessary:

Stylistic guide (mandatory)

Edited by Андреев Кирилл

Merge request reports