Skip to content
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

Multiple mod foo; declarations of the same module will duplicate the module #2658

Closed
huangliang-hl opened this issue Sep 12, 2023 · 2 comments · Fixed by #2801
Closed

Multiple mod foo; declarations of the same module will duplicate the module #2658

huangliang-hl opened this issue Sep 12, 2023 · 2 comments · Fixed by #2801
Assignees
Labels
bug Something isn't working compiler frontend `noirc_frontend` crate

Comments

@huangliang-hl
Copy link

Aim

Embedding one struct as a property of another struct.

Expected Behavior

It should be able to compile and run successfully, declaring this struct object.

Bug

error: Expected type Tensor<_, 2>, found type Tensor<100, 2>
   ┌─ /mnt/code/convolution/test/linear/src/main.nr:17:36
   │
17 │     let linear_layer = Linear::new(weight1, bias1);
   │                                    -------

error: Expected type Tensor<_, 2>, found type Tensor<10, 2>
   ┌─ /mnt/code/convolution/test/linear/src/main.nr:17:45
   │
17 │     let linear_layer = Linear::new(weight1, bias1);
   │                                             -----

error: Expected type Tensor<_, 2>, found type Tensor<10, 2>
   ┌─ /mnt/code/convolution/test/linear/src/main.nr:21:46
   │
21 │     let linear_output = linear_layer.forward(input);
   │                                              -----

Error: Aborting due to 3 previous errors

Location:
    crates/nargo_cli/src/cli/mod.rs:74:5

To Reproduce

1.git clone https://github.com/storswiftlabs/convolution.git
2.cd convolution/test/linear
3.nargo execute
4.

Installation Method

None

Nargo Version

nargo 0.11.1 (git version hash: 9da822f, is dirty: false)

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@huangliang-hl huangliang-hl added the bug Something isn't working label Sep 12, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 12, 2023
@jfecher jfecher added compiler frontend `noirc_frontend` crate P-MEDIUM labels Sep 18, 2023
@jfecher jfecher self-assigned this Sep 18, 2023
@jfecher jfecher added E-MEDIUM and removed E-LOW labels Sep 22, 2023
@jfecher
Copy link
Contributor

jfecher commented Sep 22, 2023

I'm upgrading this from E-LOW to E-MEDIUM. After some investigation, the issue is that the type checker sees the "Tensor" in the parameter and the argument as two separate types. They're assigned different unique type ids, but the internal fields are identical, including their source spans.

@jfecher
Copy link
Contributor

jfecher commented Sep 22, 2023

Alright, so this issue is because in conv.nr you have:

mod quantize;
mod tensor;

Despite you also declaring mod tensor; in main.nr and mod quantize; elsewhere as well. This is not importing these modules, this is actually creating an identical copy of these modules each time, hence the types within being the same but mutually incompatible.

We should have a better check in the compiler to prevent this, but for now remove the extra mod declarations and use mod foo; only for declaring submodules in the future. Note that without mod tensor; in conv.nr, you can still reference tensor's functions with use crate::tensor; or just prefixing crate::tensor:: in front of each function name each time you call them.

@jfecher jfecher changed the title Expected type T<_, N2>, found type T<N1, N2> Multiple mod foo; declarations of the same module will duplicate the module Sep 22, 2023
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler frontend `noirc_frontend` crate
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants