Skip to content

[TM-64] Retain notes in typed contract

Sandeep.C.R requested to merge sras/tm64-typed-contract-annotations-2 into master

Description

Problem: Typed Instr does not have fields to store annotations

Solution: This change just extracts type checked annotations returned by each iteration of the instruction type checker and wraps it along with the typed instruction. To do this a new constructor and a wrapper type, shown below was added to the typed instruction data type. By this method, we are able to preserve type annotations and field annotation, but not variable annotations.

  InstrWithNotes :: PackedNotes b  -> Instr a b -> Instr a b

  data PackedNotes a where
    PackedNotes :: Notes a -> Sing a -> PackedNotes (a ': s)

As it can be seen, this constructor wraps the annotations for the type that is top on the result stack.

Apart from this, the CAR/CDR instructions were modified to include field annotations since these annotations were part of the input stack. These new constructors are AnnCAR/AnnCDR. A pattern synonym was added so that the CAR/CDR constructors will still work when used as expressions.

Since we are only storing annotations for the result stack top, we will not have the annotations for parameter and storage types. This is solved by extracting annotations for the storage and parameter from the type checker end result's (SomeContract) input stack type (HST), and adding it to the untyped contract's storage and parameter fields.

Known Issues: TM-287

Tests: A test was added that read a contract with some annotations for contract parameters and instructions with annotations, converted it to typed version, and printed it and checked that the output contains the annotations for contract parameters.

Related issue(s)

https://issues.serokell.io/issue/TM-64

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 Sandeep.C.R

Merge request reports