Skip to content

Dynamic entries V3

Rémi requested to merge dynamic_entries_v3 into dev

Motivation and Context

Helpers to define initial dynamic entries and an interface for update.

To define a contract with dynamic entries:

  • define a storage type of the form {dynamic_entries ; storage = <ty> } (using type puning)
  • if any, define initial dynamic entries using attribute @dyn_entry

closes #1791 (closed)

Description

Following @alistair.obrien design here

New entry in std_lib:

  • the dynamic_entrypoints type: just (nat,bytes) big_map
  • the (p,s) dynamic_entrypoint type: an abstract type used as a typed key into dynamic_entrypoints which winds up being casted to nat
  • two helping function in module Dynamic_entrypoints letting you set and get dynamic entries directly from the @dyn_entry declarations:
    • val set_entrypoint (type p s) : (p, s) dynamic_entrypoint -> (p, s) entrypoint option -> dynamic_entrypoints -> dynamic_entrypoints
    • val get_entrypoint (type p s) : (p, s) dynamic_entrypoint -> dynamic_entrypoints -> (p, s) entrypoint option

Changes in the typechecking:

  • C_CAST_DYNAMIC_ENTRYPOINT used to cast any (p, s) dynamic_entrypoint to a nat

  • C_OPT_OUT_ENTRY used as a placeholder for entries which should not appear in the initial storage

    [%external ("OPT_OUT_ENTRY", ())]
  • storage types holding a dynamic_entrypoints field must only have one other field storage

  • [@dyn_entry] let x = e is type checked as:

    e : ('param, 'storage) entrypoint
    x : ('param, 'storage) dynamic_entrypoint 

In a dedicated pass (self_ast_typed) and for each module with a contract sort:

  • Generate a binder $initial_dynamic_entrypoints of type dyn_entrypoints holding inital dynamic entrypoints definition
  • Morph @dyn_entry declarations right-end sides into natural numbers
  • Morph all applications C_CAST_DYNAMIC_ENTRYPOINT x to x

LIGO CLI:

If a contract storage has two fields: dynamic_entrypoints and storage then compile storage command expects an expression of type storage and will automatically fill up the dynamic_entrypoints field

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

Dynamic entrypoints helpers in 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