Skip to content
Snippets Groups Projects

[#856] Add Lorentz emit instructions

Merged [#856] Add Lorentz emit instructions
2 unresolved threads
Merged Nikolay Yakimov requested to merge lierdakil/#856-lorentz-emit-instr into master
2 unresolved threads

Description

Problem: we support contract events, but lorentz lacks corresponding instructions.

Solution: add emit and emit' instructions, the latter omitting the type annotation.

Related issue(s)

Resolves None

:white_check_mark: 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)

Merge request reports

Merge request pipeline #646587070 passed with warnings

Merge request pipeline passed with warnings for 542a0d89

Merged by Nikolay YakimovNikolay Yakimov 2 years ago (Sep 21, 2022 12:48pm UTC)

Loading

Pipeline #646627131 passed

Pipeline passed for d22607fb on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
847 851 openChest :: ChestKey : Chest : Natural : s :-> OpenChest : s
848 852 openChest = I OPEN_CHEST
849 853
854 emit :: forall t s. (NicePackedValue t, HasAnnotation t) => FieldAnn -> t : s :-> Operation : s
855 emit tag = I $ EMIT tag ann' \\ nicePackedValueEvi @t
856 where
857 ann = getAnnotation @t NotFollowEntrypoint
858 ann' | ann == starNotes = Nothing
859 | otherwise = Just ann
  • Comment on lines +857 to +859

    :thinking: this is done for efficiency, right?

    as we discussed Just startNotes and Nothing result in different Michelson instructions, but in practice they behave the same (except that one is heavier because of the type annotation).

    If this is the case, could you please add a comment to clarify that this is the reason?

  • Please register or sign in to reply
  • 847 851 openChest :: ChestKey : Chest : Natural : s :-> OpenChest : s
    848 852 openChest = I OPEN_CHEST
    849 853
    854 emit :: forall t s. (NicePackedValue t, HasAnnotation t) => FieldAnn -> t : s :-> Operation : s
    855 emit tag = I $ EMIT tag ann' \\ nicePackedValueEvi @t
    856 where
    857 ann = getAnnotation @t NotFollowEntrypoint
    858 ann' | ann == starNotes = Nothing
    859 | otherwise = Just ann
    860
    861 -- | Version of 'emit' that omits the type annotation, letting the runtime infer
    862 -- it instead.
    863 emit' :: forall t s. (NicePackedValue t) => FieldAnn -> t : s :-> Operation : s
    864 emit' tag = I $ EMIT tag Nothing \\ nicePackedValueEvi @t
    • Comment on lines +854 to +864

      Only one suggestion from me because:

      1. these two are mostly the same
      2. I could see a rare case in which one would want to specify the Notes directly (e.g. this would be the only way to use Just starNotes if one wants it for whatever reason)

      So I think it would be nice to add a third variant with the additional argument, e.g.

      Suggested change
      854 emit :: forall t s. (NicePackedValue t, HasAnnotation t) => FieldAnn -> t : s :-> Operation : s
      855 emit tag = I $ EMIT tag ann' \\ nicePackedValueEvi @t
      856 where
      857 ann = getAnnotation @t NotFollowEntrypoint
      858 ann' | ann == starNotes = Nothing
      859 | otherwise = Just ann
      860
      861 -- | Version of 'emit' that omits the type annotation, letting the runtime infer
      862 -- it instead.
      863 emit' :: forall t s. (NicePackedValue t) => FieldAnn -> t : s :-> Operation : s
      864 emit' tag = I $ EMIT tag Nothing \\ nicePackedValueEvi @t
      854 -- | Version of 'emit' that adds the type annotation, only when @t@ has annotations.
      855 emit :: forall t s. (NicePackedValue t, HasAnnotation t) => FieldAnn -> t : s :-> Operation : s
      856 emit tag = emit' tag ann'
      857 where
      858 ann = getAnnotation @t NotFollowEntrypoint
      859 ann' | ann == starNotes = Nothing
      860 | otherwise = Just ann
      861
      862 -- | Version of 'emit' that omits the type annotation, letting the runtime infer
      863 -- it instead.
      864 emitAuto :: forall t s. (NicePackedValue t) => FieldAnn -> t : s :-> Operation : s
      865 emitAuto tag = emit' tag Nothing
      866
      867 emit'
      868 :: forall t s. (NicePackedValue t)
      869 => FieldAnn
      870 -> Maybe (Notes (ToT t))
      871 -> t : s :-> Operation : s
      872 emit' tag mNotes = I $ EMIT tag mNotes \\ nicePackedValueEvi @t
    • Nikolay Yakimov changed this line in version 2 of the diff

      changed this line in version 2 of the diff

    • Please register or sign in to reply
  • Only two minor suggestions, I'm approving already to avoid the back-and-forth.

  • Pinto Pasquale approved this merge request

    approved this merge request

  • added 1 commit

    Compare with previous version

  • Nikolay Yakimov marked this merge request as draft from 3718da4f

    marked this merge request as draft from 3718da4f

  • Nikolay Yakimov added 7 commits

    added 7 commits

    Compare with previous version

  • Nikolay Yakimov approved this merge request

    approved this merge request

  • Nikolay Yakimov marked this merge request as ready

    marked this merge request as ready

  • Nikolay Yakimov enabled an automatic merge when the pipeline for 542a0d89 succeeds

    enabled an automatic merge when the pipeline for 542a0d89 succeeds

  • Nikolay Yakimov mentioned in commit d22607fb

    mentioned in commit d22607fb

  • Please register or sign in to reply
    Loading