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

Compiler prints entire macro output to terminal if any warnings are emitted when parsing it. #7208

Open
TomAFrench opened this issue Jan 28, 2025 · 4 comments
Assignees

Comments

@TomAFrench
Copy link
Member

TomAFrench commented Jan 28, 2025

In #6969 we made the compiler tolerate compiler warnings thrown by macro generated code. However this still prints the whole macro output into the terminal.

e.g.

warning: Failed to parse macro's token stream into top-level item
    ┌─ /home/tom/nargo/github.com/noir-lang/noir-bignum/v0.5.0/src/tests/runtime_bignum_test.nr:515:1
    │
515 │ #[make_test(3, 254, quote {crate::fields::bn254Fq::BN254_Fq_Params})]
    │ ---------------------------------------------------------------------
    │ │
    │ Unsafe block must start with a safety comment: //@safety
    │ Missing Safety Comment
    │
    = The resulting token stream was: (stream starts on next line)

// Proceeds to print the entirety of the macro result being inserted.

We shouldn't need to print the whole macro output for warnings as this just results in unreadable output. I think that we should be able to remove the = The resulting token stream was: (stream starts on next line) line and everything below it.

@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jan 28, 2025
@jfecher
Copy link
Contributor

jfecher commented Jan 28, 2025

I agree, as long as its just a warning we shouldn't actually fail to parse the token stream either.

@asterite
Copy link
Collaborator

asterite commented Feb 4, 2025

I can't reproduce this. I checked out noir-bignum, ran nargo test and I can see the warnings but I don't see the macro output.

@TomAFrench
Copy link
Member Author

I think we've since removed the //@safety comments. Any parser warning should reproduce this but you can probably re-add that style of safety comments most easily.

@asterite
Copy link
Collaborator

asterite commented Feb 4, 2025

I get warnings like this:

warning: Unsafe block must have a safety doc comment above it
    ┌─ src/tests/runtime_bignum_test.nr:529:1
    │
529 │ #[make_test(3, 253, quote {crate::fields::bls12_377Fr::BLS12_377_Fr_Params})]
    │ ----------------------------------------------------------------------------- The doc comment must start with the "Safety: " word

but I don't get the full macro code printed.

I also tried with this program:

fn main() {
    comptime {
        let _ = quote { { loop {}; 2 } }.as_expr();
    }
}

The output is just this:

warning: loops are experimental and aren't fully supported yet
  ┌─ src/main.nr:3:17
  │
3 │         let _ = quote { { loop {}; 2 } }.as_expr();
  │                 ------------------------

I also tried this code:

fn main() {
    comptime {
        let _ = quote { { loop {}; 2 } }.as_expr();
    }
}

#[foo]
pub comptime fn foo(_: FunctionDefinition) -> Quoted {
    quote { pub unconstrained fn bar() { loop { break; } } }
}

This is the output:

warning: loops are experimental and aren't fully supported yet
  ┌─ src/main.nr:7:1
  │
7 │ #[foo]
  │ ------
  │

warning: loops are experimental and aren't fully supported yet
  ┌─ src/main.nr:3:17
  │
3 │         let _ = quote { { loop {}; 2 } }.as_expr();
  │                 ------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants