Skip to content

Consider an AST validation function/pass to assist with debugging user-defined macros #15819

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

Closed
huonw opened this issue Jul 20, 2014 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-plugins Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html A-syntaxext Area: Syntax extensions C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@huonw
Copy link
Member

huonw commented Jul 20, 2014

There's a variety of invariants in the AST, e.g. the Expr in a PatLit should (AFAIK) be an ExprLit, and the Option<Expr> in an ExprIf should be either a ExprBlock or ExprIf. It would be convenient if the compiler either had a AST validation pass run after macro expansion (could include verifying that there are no macros left in the AST), a validation function called on the resulting AST after each macro is expanded or just a series of manual functions that syntax extension authors can call on the code they generate to help debugging.

(The first two should, IMO, be opt-in, since most users won't want to be wasting the compilation time on something that should never trigger if they're not writing their own macros.)

@huonw
Copy link
Member Author

huonw commented Jul 20, 2014

(@kvark: this was prompted by our discussion on IRC, but you left before I could point it out. :) )

@kmcallister
Copy link
Contributor

It seems like this could be a lint, although we may need a way to run it earlier in the pipeline. That opens up the possibility of reusing some of the machinery in plugins to enforce style and code structure. Perhaps there's a nice declarative language for describing valid and invalid AST shapes.

The first two should, IMO, be opt-in, since most users won't want to be wasting the compilation time on something that should never trigger if they're not writing their own macros.

My hunch is that the compile time won't be significant, unless our invariants are really complex. Converting the lint system from one pass to several dozen increased the compile time for librustc (before it was split up) by about half a second. It's hard to do anything syntax-focused that takes significant time compared to trans and LLVM. (edit: sorry, not dozens of passes, but a bunch of virtual calls at each step of the traversal)

@steveklabnik
Copy link
Member

Triage: I think that this solution here is HIR/MIR, @nrc?

@nrc
Copy link
Member

nrc commented Jan 4, 2016

This is not addressed by the HIR/MIR, but it is likely that this would be a totally different concept in an AST-less macro world. Let's see how that pans out, I guess.

@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 21, 2017
@steveklabnik
Copy link
Member

This is an interesting idea, but has gotten basically no comments in years. I don't think keeping this issue open is helpful, and so I'm going to close. If you'd like to work on fixing this, please let me know and we can re-open!

bors added a commit to rust-lang-ci/rust that referenced this issue Nov 13, 2023
…, r=lnicola

feat: skip checking token tree count for include! macro call

fix rust-lang#15335 rust-lang#15648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-plugins Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html A-syntaxext Area: Syntax extensions C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants