feat: catch imports of private definitions in resolution#4491
feat: catch imports of private definitions in resolution#4491TomAFrench wants to merge 24 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Note that we're breaking a bunch of Rust visibility rules here. The prelude is importing things from private modules.
6dfc2f1 to
36b48f4
Compare
|
Heads up that I'm going to be chopping this PR up into chunks to get some less potentially controversial sections through quicker and reduce the diff. You're welcome to look and comment on it but reviews may become obsolete. |
# Description ## Problem\* Resolves <!-- Link to GitHub Issue --> ## Summary\* This is some groundwork pulled out from #4491 We're going to want to apply visibility modifiers to module declarations so this PR creates a proper struct for these so it's easier for us to add an extra field to hold the visibility. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
83f5320 to
b8e59ff
Compare
b8e59ff to
1e557bb
Compare
|
Nope this is an equivalent of https://doc.rust-lang.org/reference/visibility-and-privacy.html |
# Description ## Problem\* Resolves <!-- Link to GitHub Issue --> ## Summary\* This pulls out a renaming from #4491. We have the concept of `FunctionVisibility` which determines whether a function can be called from other modules in the same crate/other crates. If we're expanding the same concept of visibility to items other than functions we need a generic name for this which doesn't mention functions. I've then renamed it to `ModuleVisibility` to reflect that it shows how this item is visible in other modules but I'm open to suggestions. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
1e557bb to
5aaa6fe
Compare
#4559) # Description ## Problem\* Resolves <!-- Link to GitHub Issue --> ## Summary\* I just had a test pass when it should have failed in #4491 because despite compiling when it shouldn't have, it failed in execution (because I didn't provide a `Prover.toml` but the circuit took arguments). We're then masking potential test failures by not separating circuits which we expect to fail to compile vs fail to execute. I've created an `execution_failure` directory to hold all of the latter and updated the `compile_failure` tests to only compile the circuit rather than executing it. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
* master: chore: separate tests for execution failures from compilation failures (#4559) feat: remove curly braces with fmt (#4529) fix: Make `nargo` the default binary for cargo run (#4554) fix: Evaluate operators in globals in types (#4537) chore: Add more `Hash` impls to stdlib (#4470) feat: Sync from aztec-packages (#4546) chore: Add `Instruction::DecrementRc` (#4525) feat: add `nargo compile --watch` command (#4464) fix: Substitute generics when checking the field count of a type (#4547) feat: optimize sha2 implementation (#4441)
# Description ## Problem\* Resolves <!-- Link to GitHub Issue --> ## Summary\* Running tests within the Noir stdlib is a little complicated as nargo will not accept it as a regular crate as the stdlib uses features which are disallowed in other crates. This means that in a number of cases we're placing stdlib unit tests inside of the `test_programs` instead of just using the `#[test]` format inside of the stdlib itself. This is suboptimal as it separates the implementation from the tests in the repository and once #4491 is merged, it will be impossible to use this method to test any private functions within the stdlib. This PR then adds a new integration test which is equivalent to running `nargo test` on the stdlib and moves some tests over to the stdlib as an example. ## Additional Context ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [ ] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
|
I think that this is close enough to be ready for reviews now. |
| fn import_visibility() -> impl NoirParser<ItemVisibility> { | ||
| let is_pub_crate = (keyword(Keyword::Pub) | ||
| .then_ignore(just(Token::LeftParen)) | ||
| .then_ignore(keyword(Keyword::Crate)) | ||
| .then_ignore(just(Token::RightParen))) | ||
| .map(|_| ItemVisibility::PublicCrate); | ||
|
|
||
| let is_pub_super = (keyword(Keyword::Pub) | ||
| .then_ignore(just(Token::LeftParen)) | ||
| .then_ignore(keyword(Keyword::Super)) | ||
| .then_ignore(just(Token::RightParen))) | ||
| .map(|_| ItemVisibility::PublicSuper); | ||
|
|
||
| let is_pub = keyword(Keyword::Pub).map(|_| ItemVisibility::Public); | ||
|
|
||
| let is_private = empty().map(|_| ItemVisibility::Private); | ||
|
|
||
| choice((is_pub_crate, is_pub_super, is_pub, is_private)) | ||
| } |
There was a problem hiding this comment.
This is a bit confusing as we're overloading pub for both zk visibiilty and standard programming language visibility.
An alternative would be to rename this to export so we'd have export(super) and export(crate) to avoid this overloading.
There was a problem hiding this comment.
It's a break from rust but a relatively weak one as it's just a keyword change.
There was a problem hiding this comment.
a break from rust
pub for ZK is a break anyway; the benefits of more intuitive keywords almost always outweigh the costs.
There was a problem hiding this comment.
It sounds like using pub is a compromise either way. pub for item visibility is much more common within Noir while pub for zk is only used on entry-point function parameters. Changing either would be breaking but changing pub visibility may be less so just because it is newer. Using export fn, export(crate) fn, etc would make Noir less rust-like which could be a stumbling block. I'm fine with both uses of pub for now but if there's ever a future scenario where we could want to apply pub (zk) to a function somehow then things would get confusing real fast.
Co-authored-by: jfecher <jake@aztecprotocol.com>
Co-authored-by: jfecher <jake@aztecprotocol.com>
Co-authored-by: jfecher <jake@aztecprotocol.com>
…than a namespace
…on (#4622) # Description ## Problem\* Resolves <!-- Link to GitHub Issue --> ## Summary\* This PR pulls out the actual changes to path resolution from #4491, omitting the changes which add visibility modifiers to modules. We now determine whether a function is private (and so a warning or error should be emitted) during def collection. This is necessary as to properly determine whether a function is public or private we need information on whether all the modules in the function's path relative to where it's being used allow its contents to be used from this module - information which doesn't exist in the typechecking pass. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
…on (#4622) # Description ## Problem\* Resolves <!-- Link to GitHub Issue --> ## Summary\* This PR pulls out the actual changes to path resolution from #4491, omitting the changes which add visibility modifiers to modules. We now determine whether a function is private (and so a warning or error should be emitted) during def collection. This is necessary as to properly determine whether a function is public or private we need information on whether all the modules in the function's path relative to where it's being used allow its contents to be used from this module - information which doesn't exist in the typechecking pass. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
|
@TomAFrench would you like to supplement docs before merging the PR in? |
|
Also will this be a breaking change in terms of libraries without |
* master: (105 commits) chore: unbundle `check_array_is_initialized` (#5451) feat: Sync from aztec-packages (#5467) chore: bump bb to 0.45.1 (#5469) feat: prefix operator overload trait dispatch (#5423) feat: add CLI argument for debugging comptime blocks (#5192) chore: document EmbeddedCurvePoint (#5468) feat: lsp rename/find-all-references for struct members (#5443) feat(optimization): Deduplicate more instructions (#5457) fix: remove compile-time error for invalid indices (#5466) feat: lsp rename/find-all-references for local variables (#5439) feat: remove duplicated array reads at constant indices (#5445) fix: Account for the expected kind when resolving turbofish generics (#5448) fix: Fix issue with unresolved results (#5453) feat: apply `no_predicates` in stdlib (#5454) fix: prevent `no_predicates` from removing predicates in calling function (#5452) feat: lsp rename/find-all-references for globals (#5415) feat: remove redundant `EnableSideEffects` instructions (#5440) fix: Change panic to error in interpreter (#5446) feat: Add more slice methods to the stdlib (#5424) feat: Unquote multiple items from annotations (#5441) ...
|
Closing as superceded by more recent work. |
Description
Problem*
Resolves
Summary*
Currently Noir only defines import visibility for functions, while everything else is implicitly public. This PR is an experiment on adding proper import visibility to Noir so that we can.
I've modified
ItemScopeso that it can hold both public and private definitions and during as we traverse modules in resolution we check thatdep::paths don't enter any private modules. I've addedpub modsyntax to allow this to be shown.I've set the prelude to be
pub modso that we can compile most programs but all other modules within the stdlib are private to show how errors look like.Additional Context
Documentation*
Check one:
I'll document this closer to the time of this being merged.
PR Checklist*
cargo fmton default settings.