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

Failed assertions in macros are reported in the comptime code, but not the annotation #6272

Closed
Thunkar opened this issue Oct 10, 2024 · 7 comments · Fixed by #6277
Closed
Labels
bug Something isn't working

Comments

@Thunkar
Copy link
Contributor

Thunkar commented Oct 10, 2024

Aim

Given:

use std::{collections::umap::UHashMap, hash::{BuildHasherDefault, poseidon2::Poseidon2Hasher}};

comptime mut global ARG_STORAGE: UHashMap<FunctionDefinition, str<7>, BuildHasherDefault<Poseidon2Hasher>> = UHashMap::default();

comptime fn this_has_to_run_first(f: FunctionDefinition, arg: str<7>) {
    ARG_STORAGE.insert(f, arg);
}

comptime fn this_has_to_run_after(f: FunctionDefinition) {
    let maybe_arg = ARG_STORAGE.get(f);
    assert(maybe_arg.is_some(), "Function has to run last, please invert the annotation order");
    // Do something with arg
}

#[this_has_to_run_after]
#[this_has_to_run_first("oh noes")]
fn main() {}

I would like a hint in the main function that the attribute that failed to run was this_has_to_run_after

Expected Behavior

LSP should show a squiggly red line on #[this_has_to_run_after]

Bug

Image

LSP shows the error at the failed assertion

To Reproduce

Use the example above

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@Thunkar Thunkar added the bug Something isn't working label Oct 10, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Oct 10, 2024
@Thunkar Thunkar changed the title failed assertions in macros are reported in the comptime code, but not the annotation Failed assertions in macros are reported in the comptime code, but not the annotation Oct 10, 2024
@asterite
Copy link
Collaborator

In #6277 it'll be like this:

Image

Does that look good?

@Thunkar
Copy link
Contributor Author

Thunkar commented Oct 10, 2024

Does that look good?

Certainly an improvement! However, even when running just nargo compile, would it be possible to have some pointer in the annotation "call site" (on top of main in this case)?

This annotation can potentially be used in a lot of functions and the actual comptime fn is probably defined in a different place, which makes the error a lot less useful.

@jfecher
Copy link
Contributor

jfecher commented Oct 11, 2024

@asterite I'll also note that if a user doesn't know to bring up the error list (I had to google it) then they may not know there is even more context to see to begin with.

When I first tried in neovim as well I didn't see any change due to the lack of a details list.

@asterite
Copy link
Collaborator

However, even when running just nargo compile, would it be possible to have some pointer in the annotation "call site" (on top of main in this case)?

What do you mean? Here's the error I currently get:

error: Function has to run last, please invert the annotation order
   ┌─ src/main.nr:15:12
   │
15 │     assert(maybe_arg.is_some(), "Function has to run last, please invert the annotation order");
   │            ------------------- Assertion failed
   │
   = Call stack:
     1. src/main.nr:19:3
     2. src/main.nr:10:5

The last lines show the callstack, and from it you can see where it was called from.

Or do you mean something like this? #5842

@asterite
Copy link
Collaborator

I'll also note that if a user doesn't know to bring up the error list (I had to google it) then they may not know there is even more context to see to begin with.

Should each call stack frame be reported as a separate error then?

@jfecher
Copy link
Contributor

jfecher commented Oct 11, 2024

Should each call stack frame be reported as a separate error then?

Possibly? I'm not sure if it'd be confusing or excessive for large call stacks.

@asterite
Copy link
Collaborator

The problem is that if you have multiple macro errors, if they are reported separately you wouldn't know how to related all of them. I think showing them as related to the main error is better.

github-merge-queue bot pushed a commit that referenced this issue Oct 11, 2024
# Description

## Problem

Errors shown in LSP didn't show the "secondaries" we capture, nor the
notes.

Resolves #6272

## Summary

Now secondaries and notes are shown as details to the primary error,
like in Rust Analyzer:


![lsp-related-information-1](https://github.com/user-attachments/assets/bc307cb0-e314-4e40-97a2-a5a57abed717)


![lsp-related-information-2](https://github.com/user-attachments/assets/a79e379e-dc06-4f74-ab51-8c4b4f868899)

## Additional Context

## Documentation

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** 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.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants