noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
905 stars 206 forks source link

feat: Add `array_refcount` and `slice_refcount` builtins for debugging #6584

Closed jfecher closed 3 days ago

jfecher commented 4 days ago

Description

Problem*

Resolves

Summary*

Added debug functions to retrieve the hidden reference count field on arrays and slices in unconstrained code. This always returns 0 in constrained and comptime code.

Additional Context

Documentation*

Check one:

PR Checklist*

jfecher commented 4 days ago

This is failing under different inliner aggressiveness settings due to https://github.com/noir-lang/noir/issues/6583.

Currently it isn't possible to write the reference_counts test since the count differs depending on the inliner level.

Edit: I excluded the i64 min inliner setting from this test - fixing it is a separate issue (https://github.com/noir-lang/noir/issues/6583). With this test in we'll be able to get faster failures when rc counts change unexpectantly.

github-actions[bot] commented 3 days ago

🚀 Deployed on https://6740b13f3dbe5c00fe1d2512--noir-docs.netlify.app

github-actions[bot] commented 3 days ago

FYI @noir-lang/developerrelations on Noir doc changes.

jfecher commented 3 days ago

This PR is passing and ready for review now.

I recommend using the "hide whitespace" option since most of the changes in this PR are just me reorganizing a match statement in compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs