Skip to content

refactor!: introducing #[external(...)] macro#17827

Merged
benesjan merged 1 commit intonextfrom
10-20-refactor_introducing_external_._
Oct 24, 2025
Merged

refactor!: introducing #[external(...)] macro#17827
benesjan merged 1 commit intonextfrom
10-20-refactor_introducing_external_._

Conversation

@benesjan
Copy link
Contributor

@benesjan benesjan commented Oct 20, 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 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:
image

This issue will be tackled in the near future.

@benesjan benesjan force-pushed the 10-20-refactor_introducing_external_._ branch 2 times, most recently from 5d0728d to bf0af9e Compare October 20, 2025 21:44
@benesjan benesjan marked this pull request as ready for review October 20, 2025 21:44
@benesjan benesjan requested review from a team, dbanks12 and fcarreiro as code owners October 20, 2025 21:44
@benesjan benesjan changed the title refactor: introducing #[external(...)] refactor!: introducing #[external(...)] Oct 20, 2025
@benesjan benesjan marked this pull request as draft October 21, 2025 00:47
@benesjan benesjan force-pushed the 10-20-refactor_introducing_external_._ branch from ab78fd8 to 51c1f55 Compare October 21, 2025 11:34
// Marker attribute - see the comment above

if !is_fn_private(f) & !is_fn_public(f) {
if !is_fn_external(f) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main sad thing about this PR. Now I am unable to evaluate here if the function is not utility because I don't have the guarantee if the external macro function has already been run. So I only perform this check here and then in utility macro I check if these attributes are not applied.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea this is quite sad. What might be a direction long term? Would we keep doing

#[initializer]
#[external("private")
fn foo

or might we move to e.g.

#[external("private", "initializer")]
fn bar

#[external("private", "no_init_check", "view")]
fn qux

In that scenario we'd not need to worry about macro order or not having the full picture.

Copy link
Contributor Author

@benesjan benesjan Oct 23, 2025

Choose a reason for hiding this comment

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

I would go with the second approach as it will make the macros much clearer.

The only bad thing about it is that invalid attribute args currently don't play well with LSP:

image

But I assume that Noir team could improve that and give us a nice error message at which point all seems fine.

@benesjan benesjan force-pushed the 10-20-refactor_introducing_external_._ branch from e0c28ff to c55306a Compare October 21, 2025 13:12
@benesjan benesjan marked this pull request as ready for review October 21, 2025 13:18
@benesjan benesjan changed the title refactor!: introducing #[external(...)] refactor!: introducing #[external(...)] macro Oct 21, 2025
@benesjan benesjan requested review from Thunkar and nventuro October 21, 2025 15:22
@benesjan benesjan force-pushed the 10-20-refactor_introducing_external_._ branch from c977176 to 1c35ebe Compare October 22, 2025 17:51
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.

Very nice, thanks a lot! Leaving the review as a comment as I want to a) confirm with product we'll not accidentally release this until we're ready, and b) discuss a bit how we'll deal with other fn attributes like view, initializer, etc.

// Marker attribute - see the comment above

if !is_fn_private(f) & !is_fn_public(f) {
if !is_fn_external(f) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yea this is quite sad. What might be a direction long term? Would we keep doing

#[initializer]
#[external("private")
fn foo

or might we move to e.g.

#[external("private", "initializer")]
fn bar

#[external("private", "no_init_check", "view")]
fn qux

In that scenario we'd not need to worry about macro order or not having the full picture.

@benesjan benesjan marked this pull request as draft October 23, 2025 12:25
@benesjan benesjan force-pushed the 10-20-refactor_introducing_external_._ branch from b2aacae to f77b39a Compare October 23, 2025 12:30
@benesjan benesjan marked this pull request as ready for review October 23, 2025 12:49
@benesjan benesjan force-pushed the 10-20-refactor_introducing_external_._ branch from 7ecca22 to 24854f2 Compare October 23, 2025 13:10
@benesjan
Copy link
Contributor Author

Seems to have been accidentally closed by Jake so reopening

@nventuro nventuro reopened this 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
@benesjan benesjan added this pull request to the merge queue Oct 23, 2025
Merged via the queue into next with commit 93a47fc Oct 24, 2025
15 checks passed
@benesjan benesjan deleted the 10-20-refactor_introducing_external_._ branch October 24, 2025 00:21
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