Skip to content

refactor: cleaning up macros::functions::utils#17840

Merged
benesjan merged 1 commit intonextfrom
10-21-refactor_cleaning_up_macros_functions_utils
Oct 24, 2025
Merged

refactor: cleaning up macros::functions::utils#17840
benesjan merged 1 commit intonextfrom
10-21-refactor_cleaning_up_macros_functions_utils

Conversation

@benesjan
Copy link
Contributor

@benesjan benesjan commented Oct 21, 2025

This PR was quite a journey:

Step 1

When trying to figure out how to rename the incorrectly named get_fn_visibility in a PR down the stack I realized that it's better to just drop it because:

  • it was only used by create_assert_correct_initializer_args, create_mark_as_initialized and create_init_check functions which in turn where only called in transfrom_private and transform_public,
  • these functions contained only 2 lines of code.

Because of this ^ it's better to just directly inline contents of these funcs into the transform_* functions.

When I finished this I checked where are the is is_fn_private and is_fn_public utils used which led me to step 2:

Step 2

When checking when are the above mentioned functions used I realized that we use them in create_authorize_once_check and in the stub_fn. In both of these cases the code was just terrible because these functions are called from transform_private and transform_public functions hence the flow was:

transform_private --> stub_fn --> are we in private? --> if yes call create_private_stub

which I could replace with:

transform_private --> create_private_stub

So I dropped the stub_fn and just called the create_private_stub directly.

The similar was the case for create_authorize_once_check where I could simply pass in an is_private arg to the function and get rid of the is_fn_private dependency.

Step 3

Once I did this I realized that I don't need the EXTERNAL_REGISTRY I introduced in the PR down the stack at all, removing a lot of the sad ugly complexity I needed to introduce there 🎉

Future work

  • The whole noir-projects/aztec-nr/aztec/src/macros/functions directory is very messy and I plan on move the code around into more logical places in the dir once this stack of PRs is merged.
  • I think the stub name is non-descriptive enough so will try to come up with something better.

@benesjan benesjan force-pushed the 10-20-refactor_introducing_external_._ branch from e0c28ff to c55306a Compare October 21, 2025 13:12
@benesjan benesjan force-pushed the 10-21-refactor_cleaning_up_macros_functions_utils branch 3 times, most recently from 670931d to f3f7fbd Compare October 21, 2025 14:26
@benesjan benesjan marked this pull request as ready for review October 21, 2025 15:22
@benesjan benesjan requested a review from nventuro October 21, 2025 15:48
@benesjan benesjan force-pushed the 10-20-refactor_introducing_external_._ branch from c977176 to 1c35ebe Compare October 22, 2025 17:51
@benesjan benesjan requested a review from a team as a code owner October 22, 2025 17:51
@benesjan benesjan force-pushed the 10-21-refactor_cleaning_up_macros_functions_utils branch 2 times, most recently from 95f7457 to 17acac1 Compare October 22, 2025 17:53
Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with your comments re. how this simplifies things. Also greatly appreciate how in the description you went over your thinking process, it made reading this much easier. Thanks!

@benesjan benesjan marked this pull request as draft October 23, 2025 12:29
@benesjan benesjan force-pushed the 10-20-refactor_introducing_external_._ branch from b2aacae to f77b39a Compare October 23, 2025 12:30
@benesjan benesjan force-pushed the 10-21-refactor_cleaning_up_macros_functions_utils branch 3 times, most recently from 8a7cbc8 to abe4d5c Compare October 23, 2025 13:10
@benesjan benesjan force-pushed the 10-20-refactor_introducing_external_._ branch from 7ecca22 to 24854f2 Compare October 23, 2025 13:10
@benesjan benesjan marked this pull request as ready for review October 23, 2025 13:13
AztecBot pushed a commit that referenced this pull request Oct 23, 2025
Closes https://linear.app/aztec-labs/issue/F-19/rename-privateorpublicorutility-to-externalprivateorpublicorutility

Having `#[private]` and `#[public]` macros was misleading because in Solidity these define function visibility while in Aztec's case they define the environment in which the functions are executed. For this reason I introduce `#[external(...)]` macro while the argument of the attribute defines the execution environment: `private`, `public` or `utility`.

## Notes for reviewer
- I did a refactor in a [PR up the stack](#17840) which allowed me to drop a lot of the complexity introduced in this PR. For this reason I encourage you to check that one first to have context on what in this PR is a problem and what is not. It might make sense to just merge these 2 PRs into 1 but I think that would make it all harder to review.
- This PR touches a lot of files but all the juicy bits are in the `noir-projects/aztec-nr/aztec/src/macros/` directory so I encourage you to just check that first. The `noir-contracts` dir can be completely ignored as there I just update the imports and the macros.
- The new naming is now in conflict with the `#[internal]` macro as having both external and internal applied to a function is valid:

<img width="874" height="182" alt="image" src="https://github.com/user-attachments/assets/4582a51a-225c-4a4c-9b9a-d2c2d413d927" />

This issue will be tackled in the near future.

Co-authored-by: Jan Beneš <janbenes1234@gmail.com>
@AztecBot AztecBot force-pushed the 10-20-refactor_introducing_external_._ branch from 24854f2 to 711bbee Compare October 23, 2025 22:18
github-merge-queue bot pushed a commit that referenced this pull request Oct 24, 2025
Closes
https://linear.app/aztec-labs/issue/F-19/rename-privateorpublicorutility-to-externalprivateorpublicorutility

Having `#[private]` and `#[public]` macros was misleading because in
Solidity these define function visibility while in Aztec's case they
define the environment in which the functions are executed. For this
reason I introduce `#[external(...)]` macro while the argument of the
attribute defines the execution environment: `private`, `public` or
`utility`.

## Notes for reviewer
- I did a refactor in a [PR up the
stack](#17840) which
allowed me to drop a lot of the complexity introduced in this PR. For
this reason I encourage you to check that one first to have context on
what in this PR is a problem and what is not. It might make sense to
just merge these 2 PRs into 1 but I think that would make it all harder
to review.
- This PR touches a lot of files but all the juicy bits are in the
`noir-projects/aztec-nr/aztec/src/macros/` directory so I encourage you
to just check that first. The `noir-contracts` dir can be completely
ignored as there I just update the imports and the macros.
- The new naming is now in conflict with the `#[internal]` macro as
having both external and internal applied to a function is valid:

<img width="874" height="182" alt="image"
src="https://github.com/user-attachments/assets/4582a51a-225c-4a4c-9b9a-d2c2d413d927"
/>

This issue will be tackled in the near future.
Base automatically changed from 10-20-refactor_introducing_external_._ to next October 24, 2025 00:21
@benesjan benesjan force-pushed the 10-21-refactor_cleaning_up_macros_functions_utils branch from abe4d5c to caa7589 Compare October 24, 2025 00:47
@benesjan benesjan enabled auto-merge October 24, 2025 00:48
This PR was quite a journey:

## Step 1

When trying to figure out how to rename the incorrectly named `get_fn_visibility` in a PR down the stack I realized that it's better to just drop it because:
- it was only used by `create_assert_correct_initializer_args`, `create_mark_as_initialized` and `create_init_check` functions which in turn where only called in `transfrom_private` and `transform_public`,
- these functions contained only 2 lines of code.

Because of this ^ it's better to just directly inline contents of these funcs into the `transform_*` functions.

When I finished this I checked where are the is `is_fn_private` and `is_fn_public` utils used which led me to step 2:

## Step 2
When checking when are the above mentioned functions used I realized that we use them in `create_authorize_once_check` and in the `stub_fn`. In both of these cases the code was just terrible because these functions are called from `transform_private` and `transform_public` functions hence the flow was:

`transform_private` --> `stub_fn` --> are we in private? --> if yes call `create_private_stub`

which I could replace with:

`transform_private` --> `create_private_stub`

So I dropped the `stub_fn` and just called the `create_private_stub` directly.

The similar was the case for `create_authorize_once_check` where I could simply pass in an `is_private` arg to the function and get rid of the `is_fn_private` dependency.

## Step 3
Once I did this I realized that I don't need the `EXTERNAL_REGISTRY` I introduced in the PR down the stack at all, removing a lot of the sad ugly complexity I needed to introduce there 🎉

## Future work
- The whole `noir-projects/aztec-nr/aztec/src/macros/functions` directory is very messy and I plan on move the code around into more logical places in the dir once this stack of PRs is merged.
- I think the `stub` name is non-descriptive enough so will try to come up with something better.

Co-authored-by: Jan Beneš <janbenes1234@gmail.com>
@AztecBot AztecBot force-pushed the 10-21-refactor_cleaning_up_macros_functions_utils branch from caa7589 to 5250359 Compare October 24, 2025 01:12
@benesjan benesjan added this pull request to the merge queue Oct 24, 2025
Merged via the queue into next with commit 888d73d Oct 24, 2025
16 checks passed
@benesjan benesjan deleted the 10-21-refactor_cleaning_up_macros_functions_utils branch October 24, 2025 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants