The previous macro_rules! parsers failed when an additional modifier was added
with ambiguity errors. The error is pretty unclear as to what exactly the cause
here is, but this change simplifies the argument parsing code such that the
error is avoided.
Using symbol::Interner makes it very easy to mixup UniqueTypeId symbols
with the global interner. In fact the Debug implementation of
UniqueTypeId did exactly this.
Using a separate interner type also avoids prefilling the interner with
unused symbols and allow for optimizing the symbol interner for parallel
access without negatively affecting the single threaded module codegen.
Preserve more spans in internal `rustc_queries!` macro
We now preserve the span of the various query modifiers, and
use the span of the query's name for the commas that we
generate to separate the modifiers. This makes debugging issues with the
internal query macro infrastructure much nicer - previously, we
would get errors messages pointing at the entire call site
(the `rustc_queries!` invocation), which isn't very useful.
This should have no effect when compilation succeeds.
A concrete example of an error message produced after this changed:
```
error: local ambiguity: multiple parsing options: built-in NTs tt ('modifiers') or 1 other option.
--> /home/aaron/repos/rust/compiler/rustc_middle/src/query/mod.rs:23:11
|
12 | / rustc_queries! {
13 | | query trigger_delay_span_bug(key: DefId) -> () {
14 | | desc { "trigger a delay span bug" }
15 | | }
... |
23 | | query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
| | ^^^^^^^^^
... |
1715 | | }
1716 | | }
| |_- in this expansion of `rustc_query_append!`
|
::: compiler/rustc_query_impl/src/lib.rs:51:1
|
51 | rustc_query_append! { [define_queries!][<'tcx>] }
| ------------------------------------------------- in this macro invocation
```
The particular bug shown in this error message will be fixed
in a separate PR.
rfc3052 followup: Remove authors field from Cargo manifests
Since RFC 3052 soft deprecated the authors field, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information for contributors, we may as well
remove it from crates in this repo.
Since RFC 3052 soft deprecated the authors field anyway, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information, we should remove it from
crates in this repo.
We now preserve the span of the various query modifiers, and
use the span of the query's name for the commas that we
generate to separate the modifiers. This makes debugging issues with the
internal query macro infrastructure much nicer - previously, we
would get errors messages pointing at the entire call site
(the `rustc_queries!` invocation), which isn't very useful.
This should have no effect when compilation succeeds.
A concrete example of an error message produced after this changed:
```
error: local ambiguity: multiple parsing options: built-in NTs tt ('modifiers') or 1 other option.
--> /home/aaron/repos/rust/compiler/rustc_middle/src/query/mod.rs:23:11
|
12 | / rustc_queries! {
13 | | query trigger_delay_span_bug(key: DefId) -> () {
14 | | desc { "trigger a delay span bug" }
15 | | }
... |
23 | | query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
| | ^^^^^^^^^
... |
1715 | | }
1716 | | }
| |_- in this expansion of `rustc_query_append!`
|
::: compiler/rustc_query_impl/src/lib.rs:51:1
|
51 | rustc_query_append! { [define_queries!][<'tcx>] }
| ------------------------------------------------- in this macro invocation
```
The particular bug shown in this error message will be fixed
in a separate PR.
- Replace {} with the stringified expr
Giant thank you to `@danielhenrymantilla` for figuring out how to make
this work ❤️
- Note that this is just an approximation and it would be better to add
a doc-comment
Currently, the rustc_macros::symbols macro generates two
`macro_rules!` macros as its output. These two macros are
used in rustc_span/src/symbol.rs.
This means that each Symbol that we define is represented
in the AST of rustc_symbols twice: once in the definition
of the `define_symbols!` macro (similarly for the
`keywords! macro), and once in the rustc_span::symbols
definition.
That would be OK if there were only a handful of symbols,
but currently we define over 1100 symbols. The definition
of the `define_symbols!` macro contains the expanded definition
of each symbol, so that's a lot of AST storage wasted on a
macro that is used exactly once.
This commit removes the `define_symbols` macro, and simply
allows the proc macro to directly generate the
`rustc_symbols::symbol::sym` module.
The benefit is mainly in reducing memory wasted during
compilation of rustc itself. It should also reduce memory used
by Rust Analyzer.
This commit also reduces the size of the AST for symbol
definitions, by moving two `#[allow(...)]` attributes from
the symbol constants to the `sym` module. This eliminates 2200+
attribute nodes.
This commit also eliminates the need for the `digits_array`
constant. There's no need to store an array of Symbol values
for digits. We can simply define a constant of the base value,
and add to that base value.
This improves how the `symbols` proc-macro handles errors.
If it finds an error in its input, the macro does not panic.
Instead, it still produces an output token stream. That token
stream will contain `compile_error!(...)` macro invocations.
This will still cause compilation to fail (which is what we want),
but it will prevent meaningless errors caused by the output not
containing symbols that the macro normally generates.
This solves a small (but annoying) problem. When you're editing
rustc_span/src/symbol.rs, and you get something wrong (dup
symbol name, misordered symbol), you want to get only the errors
that are relevant, not a burst of errors that are irrelevant.
This change also uses the correct Span when reporting errors,
so you get errors that point to the correct place in
rustc_span/src/symbol.rs where something is wrong.
This also adds several unit tests which test the `symbols` proc-macro.
This commit also makes it easy to run the `symbols` proc-macro
as an ordinary Cargo test. Just run `cargo test`. This makes it
easier to do development on the macro itself, such as running it
under a debugger.
This commit also uses the `Punctuated` type in `syn` for parsing
comma-separated lists, rather than doing it manually.
The output of the macro is not changed at all by this commit,
so rustc should be completely unchanged. This just improves
quality of life during development.
Introduce `TypeVisitor::BreakTy`
Implements MCP rust-lang/compiler-team#383.
r? `@ghost`
cc `@lcnr` `@oli-obk`
~~Blocked on FCP in rust-lang/compiler-team#383.~~