Draft: Dynamic entries v2

Motivation and Context

Helpers for dynamic entries in ligo.

To define a contract with dynamic entries:

  • define a storage type of the form {dynamic_entries ; storage = <ty> } (using type puning)
  • if any intial dynamic entries: define a Dynamic_entries module holding [@dyn_entry] declarations

Ligo will generate

  • the dynamic_entries type : (nat,bytes) big_map
  • for each [@dyn_entry] of name x expose the corresponding big_map key key_x
  • for each [@dyn_entry] a setter : <dyn_entry type> -> dynamic_entries -> dynamic_entries
  • for each [@dyn_entry] a getter : dynamic_entries -> <dyn_entry type> option
  • the initial dynamic_entry field in storage type holding all [@dyn_entry]

The code generation folows the same architecture as the one defined in

Description

Future:

  • generating code after typing is very bad: current idea (cc @er433) is to create a "while typing" pass in checking). If we get this, we can define [@dyn_entry]'s at top level instead of using a module..
  • the nanopass is here to perform checks

Testing:

ligo compile contract src/test/contracts/dynamic_entries_example.mligo -m My_contract
ligo compile storage src/test/contracts/dynamic_entries_example.mligo '{dynamic_entries = My_contract.Dynamic_entries.initial ; storage = 2}' -m My_contract

closes #1791 (closed)

Component

  • compiler
  • website
  • webide
  • vscode-plugin
  • debugger

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (non-breaking change that improves performance)
  • None (change with no changelog)

Changelog

First version of dynamic entries helpers for LIGO

Checklist:

  • If a new syntax has been introduced, put a message on slack ligo-lsp
  • Changes follow the existing coding style (use dune @fmt to check).
  • Tests for the changes have been added (for bug fixes / feature).
  • Documentation has been updated.
  • Changelog description has been added (if appropriate).
  • Start titles under ## Changelog section with #### (if appropriate).
  • There is no image or uploaded file in changelog
  • Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by Rémi

Merge request reports

Loading