From b003f0a6369b14de34325d7f646b95ff640f1943 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Wed, 10 Jan 2024 18:40:32 +0000 Subject: [PATCH] chore: add test case showing reexports (#4001) # Description ## Problem\* Resolves ## Summary\* This PR adds a test case to just show the current state of reexports across libraries. ## 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. --- compiler/noirc_frontend/src/hir/def_map/mod.rs | 1 + .../compile_success_empty/reexports/Nargo.toml | 7 +++++++ .../compile_success_empty/reexports/src/main.nr | 8 ++++++++ test_programs/test_libraries/exporting_lib/Nargo.toml | 6 ++++++ test_programs/test_libraries/exporting_lib/src/lib.nr | 10 ++++++++++ .../test_libraries/reexporting_lib/Nargo.toml | 7 +++++++ .../test_libraries/reexporting_lib/src/lib.nr | 3 +++ 7 files changed, 42 insertions(+) create mode 100644 test_programs/compile_success_empty/reexports/Nargo.toml create mode 100644 test_programs/compile_success_empty/reexports/src/main.nr create mode 100644 test_programs/test_libraries/exporting_lib/Nargo.toml create mode 100644 test_programs/test_libraries/exporting_lib/src/lib.nr create mode 100644 test_programs/test_libraries/reexporting_lib/Nargo.toml create mode 100644 test_programs/test_libraries/reexporting_lib/src/lib.nr diff --git a/compiler/noirc_frontend/src/hir/def_map/mod.rs b/compiler/noirc_frontend/src/hir/def_map/mod.rs index 9c46ef3585..fbf94468c4 100644 --- a/compiler/noirc_frontend/src/hir/def_map/mod.rs +++ b/compiler/noirc_frontend/src/hir/def_map/mod.rs @@ -64,6 +64,7 @@ pub struct CrateDefMap { pub(crate) krate: CrateId, + /// Maps an external dependency's name to its root module id. pub(crate) extern_prelude: BTreeMap, } diff --git a/test_programs/compile_success_empty/reexports/Nargo.toml b/test_programs/compile_success_empty/reexports/Nargo.toml new file mode 100644 index 0000000000..4a87f28fd8 --- /dev/null +++ b/test_programs/compile_success_empty/reexports/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "reexports" +type = "bin" +authors = [""] + +[dependencies] +reexporting_lib = { path = "../../test_libraries/reexporting_lib" } diff --git a/test_programs/compile_success_empty/reexports/src/main.nr b/test_programs/compile_success_empty/reexports/src/main.nr new file mode 100644 index 0000000000..bb94b21b22 --- /dev/null +++ b/test_programs/compile_success_empty/reexports/src/main.nr @@ -0,0 +1,8 @@ +use dep::reexporting_lib::{FooStruct, MyStruct, lib}; + +fn main() { + let x: FooStruct = MyStruct { + inner: 0 + }; + assert(lib::is_struct_zero(x)); +} diff --git a/test_programs/test_libraries/exporting_lib/Nargo.toml b/test_programs/test_libraries/exporting_lib/Nargo.toml new file mode 100644 index 0000000000..628418c060 --- /dev/null +++ b/test_programs/test_libraries/exporting_lib/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "exporting_lib" +type = "lib" +authors = [""] + +[dependencies] diff --git a/test_programs/test_libraries/exporting_lib/src/lib.nr b/test_programs/test_libraries/exporting_lib/src/lib.nr new file mode 100644 index 0000000000..af1fd7a32d --- /dev/null +++ b/test_programs/test_libraries/exporting_lib/src/lib.nr @@ -0,0 +1,10 @@ + +struct MyStruct { + inner: Field +} + +type FooStruct = MyStruct; + +fn is_struct_zero(val: MyStruct) -> bool { + val.inner == 0 +} diff --git a/test_programs/test_libraries/reexporting_lib/Nargo.toml b/test_programs/test_libraries/reexporting_lib/Nargo.toml new file mode 100644 index 0000000000..c26ce501e5 --- /dev/null +++ b/test_programs/test_libraries/reexporting_lib/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "reexporting_lib" +type = "lib" +authors = [""] + +[dependencies] +exporting_lib = { path = "../exporting_lib" } diff --git a/test_programs/test_libraries/reexporting_lib/src/lib.nr b/test_programs/test_libraries/reexporting_lib/src/lib.nr new file mode 100644 index 0000000000..f12dfe01ec --- /dev/null +++ b/test_programs/test_libraries/reexporting_lib/src/lib.nr @@ -0,0 +1,3 @@ +use dep::exporting_lib::{MyStruct, FooStruct}; + +use dep::exporting_lib as lib;