-
Notifications
You must be signed in to change notification settings - Fork 380
feat: catch imports of private definitions in resolution #4491
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
Changes from all commits
5aaa6fe
166dc3f
04c7203
6285007
557f9e3
e6bb6b7
bb95692
a08090c
bf3a540
16048c9
424fbee
8633239
0e21701
352cfa6
564a067
5deda19
72151b8
83198ac
b7d57bf
c389a55
90ee97a
32f5246
b2d1f77
bd04dc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -461,10 +461,37 @@ fn optional_type_annotation<'a>() -> impl NoirParser<UnresolvedType> + 'a { | |
| .map(|r#type| r#type.unwrap_or_else(UnresolvedType::unspecified)) | ||
| } | ||
|
|
||
| /// import_visibility: 'pub(crate)' | 'pub' | %empty | ||
| 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)) | ||
| } | ||
|
Comment on lines
+465
to
+483
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit confusing as we're overloading An alternative would be to rename this to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a break from rust but a relatively weak one as it's just a keyword change.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jfecher what are your thoughts on this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds like using |
||
|
|
||
| fn module_declaration() -> impl NoirParser<TopLevelStatement> { | ||
| keyword(Keyword::Mod) | ||
| .ignore_then(ident()) | ||
| .map(|ident| TopLevelStatement::Module(ModuleDeclaration { ident })) | ||
| import_visibility().then_ignore(keyword(Keyword::Mod)).then(ident()).map( | ||
| |(mut visibility, ident)| { | ||
| // A module's contents are visible to the parent module unless they themselves are marked private. | ||
| if visibility == ItemVisibility::Private { | ||
| visibility = ItemVisibility::PublicSuper; | ||
| } | ||
| TopLevelStatement::Module(ModuleDeclaration { ident, visibility }) | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| fn use_statement() -> impl NoirParser<TopLevelStatement> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| mod module; | ||
| pub mod module; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| mod foo; | ||
| pub mod foo; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| mod vec; | ||
| mod bounded_vec; | ||
| mod map; | ||
| pub mod vec; | ||
| pub mod bounded_vec; | ||
| pub mod map; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| mod te; | ||
| pub mod te; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| mod bn254; | ||
| pub mod bn254; | ||
| use bn254::lt as bn254_lt; | ||
|
|
||
| impl Field { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| mod bar; | ||
| pub(crate) mod bar; | ||
|
|
||
| global N: u64 = 5; | ||
| global MAGIC_NUMBER: u64 = 3; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| pub fn hello(x: Field) -> Field { | ||
| pub(crate) mod foo; | ||
|
|
||
| pub(crate) fn hello(x: Field) -> Field { | ||
| x | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| pub fn goodbye(x: Field) -> Field { | ||
| x | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| mod import; | ||
| use crate::import::hello; | ||
| use import::foo::goodbye; | ||
|
|
||
| fn main(x: Field, y: Field) { | ||
| let _k = std::hash::pedersen_commitment([x]); | ||
| let _l = hello(x); | ||
| let _l = goodbye(x); | ||
|
|
||
| assert(x != import::hello(y)); | ||
| assert(x != goodbye(y)); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| mod bar; | ||
| pub(crate) mod bar; | ||
|
|
||
| fn hello(x: Field) -> Field { | ||
| x | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| mod bar; | ||
| pub(crate) mod bar; | ||
|
|
||
| struct fooStruct { | ||
| bar_struct: bar::barStruct, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.