Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support compilation of Anoma transactions in nockma backend #2693

Merged
merged 37 commits into from
Mar 22, 2024

Conversation

paulcadman
Copy link
Collaborator

@paulcadman paulcadman commented Mar 19, 2024

When we first implemented the Nockma backend we wrongly assumed that the only entry point for Juvix compiled Nockma modules would be the main function. Using this assumption we could add a setup step in the main function that put the Anoma stdlib and compiled functions from the Juvix module in a static place in the Nockma subject. References to the Anoma stdlib and functions in the module could then be resolved statically.

However, one of the use cases for Juvix -> Nockma compilation is for Anoma to run logic functions that are fields of a transaction. So the user writes a Juvix program with main function that returns a transaction. The result of the main function is passed to Anoma. When Anoma calls the logic function on a field of the transaction, the setup part of the main function is not run so the subject is not in the required state. In fact, the logic function is not even callable by Anoma because non-main functions in the Juvix module use a calling convention that assumes the subject has a particular shape.

This PR solves the problem by making all functions in the Juvix module use the Anoma calling convention. We make all compiled closures (including, for example, the logic functions stored on resources in a transaction) self contained, i.e they contain the functions library and anoma standard library.

Modules that contain many closures produce large nockma output files which slows down the evaluator. This will need to be fixed in the future either with Nockma compression (jam serialization) or otherwise. But it does not block the compilation and execution of Anoma transactions.

Other fixes / additions:

  • Extra tracing. You can now annotate output cells with a tag that will be displayed in the output
  • Unittests for listToTuple, appendRights helper functions
  • Fixes for the nockma parser when parsing 'pretty nockma', specifically stdlib calls, tags and functions_library atom.
  • Adds juvix dev nock run command that can run a program output with the anoma target.
  • Remove the nockma target. As described above we always use the Anoma calling convention so there's no need for a separate target for the 'juvix calling convention'
  • Adds a --profile flag to juvix dev nock run which outputs a count of Nockma ops used in the evaluation
  • In tests we no longer serialise the compiled program to force full evaluation of the compiled code. We added a negative test to check that strings are not allowed in Nockma/Anoma programs,

it is output in a file OUTPUT.profile and has the following form:

quote : 15077
apply : 0
isCell : 0
suc : 0
= : 4517
if : 5086
seq : 5086
push : 0
call : 4896
replace : 1
hint : 8
scry : 0
trace : 0

@paulcadman paulcadman changed the title Inline the functions library at every closure Support compilation of Anoma transactions in nockma backend Mar 22, 2024
@paulcadman paulcadman marked this pull request as ready for review March 22, 2024 17:24
@janmasrovira janmasrovira merged commit b981405 into main Mar 22, 2024
4 checks passed
@janmasrovira janmasrovira deleted the reinline-env branch March 22, 2024 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants