-
Notifications
You must be signed in to change notification settings - Fork 219
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
feat(std_lib): println statements #630
Conversation
…rings currently mock array functionality
…. need to create Log directive for more accurate logging logic
|
I agree. I will change this |
…to move log stmts to builtin rather than separate OP
…inal testing and cleanup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thank you
Corresponding ACVM issue stemming from this PR: noir-lang/acvm#94 Will push something update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. My main issue with the printing during tests was that you'd get output on the same line as the test name instead than the one below, rather than the test status being printed afterwards. I see that's fixed so happy to merge this now.
@Globallager @signorecello Forgot to label this doc needed, just pinging y'all that this is now merged |
Related issue(s)
Resolves #383
Description
The new
Directive::Log
was added inacvm
release0.4.1
. The backend has been already updated to reflect this newacvm
release.This PR adds logging statements to Noir. This will enable developers to print out respective variables as they are computed, arrays, and string literals. This will greatly help improve the developer experience as Noir devs will now have an easy (and popular) debugging tool available until more complex debugging is possible with Noir.
Currently, for dev purposes I am restricting the number of arguments in a log statement to one. This can be expanded in a separate PR.
Summary of changes
A builtin function called
println
has been added to the Noir std lib. There are some differences between println our existing builtin functions as println does not return anything and should not be optimized out.The majority of the changes are in the
noirc_evaluator
as logs need to be able to print out the variables according to how they are used in the program. The most significant addition is theevaluate_println
where the final string to be logged is constructed and a gate with a newDirective::Log
is added to the evaluator. The directive in the acvm can be found here: noir-lang/acvm#61. This new directive can contain either a single string or a vector of witnesses. In the case of a finalized output string the directive simply prints the string it contains and always resolves in the PWG. For the case where our output is witnesses we must fetch the witness values to output when solving the PWG and construct the final string there.evaluate_println
needs some extra information that other builtin methods don't require. It must determine whether to print an array as field elements or a utf8 and thus must know if the expression passed to it is a string. I addedPrintln(bool)
to thebuiltin::Opcode
enum. The bool contained in this enum specifies whether the argument to be printed in a string. If a future PR expands println's to accept multiple variables this will have to be changed.Dependency additions / changes
This is branched off of
mv/strings
and will re-use some of the decoding information from this PR for printing string arrays.mv/strings
is now in master so no heavy dependency changes here.Test additions / changes
I am adding usage of
std::println
to thestrings
test.Checklist
cargo fmt
with default settings.Additional context
(If applicable.)