Skip to content

[#698] Handle view ordering properly and some refactoring

Nikolay Yakimov requested to merge lierdakil/#698-fix-views-ordering into master

This should mostly be okay, but I want to give it another look when I don't have a headache, hence marking as wip.

Description

Problem: parser doesn't remember ordering of view blocks

Solution: change EntriesOrder to be a newtype over Map Entry Word, where Entry is unique block identifier (for views that includes view name, otherwise just block type), and Word is the sort key for ordering.

Remove entriesOrderToInt (afaict not used downstream, we can deprecate it if we have to, but its behaviour will be wonky).

Modify orderContractBlock to check for duplicated views. Add error handling for duplicated views in ensureNotDuplicate.

Contracts with duplicated views now fail to parse, so move and adjust relevant tests.

Furthermore, use Map ViewName a to represent typed and untyped views (mostly to optimize view lookups and enforce "no duplicates" invariant).

Finally, I noticed some not great code in Morley.Michelson.Macro, so polished it a bit.

Related issue(s)

Resolves #698 (closed)

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:
    • I updated changelog files of all affected packages released to Hackage if my changes are externally visible.

Stylistic guide (mandatory)

Edited by Nikolay Yakimov

Merge request reports