You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here are some other notable data structures involved in expansion and integration:
122
146
-[`Resolver`] - a trait used to break crate dependencies. This allows the resolver services to be used in [`rustc_ast`], despite [`rustc_resolve`] and pretty much everything else depending on [`rustc_ast`].
123
147
-[`ExtCtxt`]/[`ExpansionData`] - various intermediate data kept and used by expansion
@@ -217,9 +241,9 @@ an integer ID, assigned continuously starting from 0 as we discover new macro
217
241
calls. All heirarchies start at [`ExpnId::root()`][rootid], which is its own
218
242
parent.
219
243
220
-
All of the hygiene-related algorithms are implemented in
221
-
[`rustc_span::hygiene`][hy], with the exception of some hacks
222
-
[`Resolver::resolve_crate_root`][hacks].
244
+
[`rustc_span::hygiene`][hy] contains all of the hygiene-related algorithms
245
+
(with the exception of some hacks in [`Resolver::resolve_crate_root`][hacks])
246
+
and structures related to hygiene and expansion that are kept in global data.
223
247
224
248
The actual heirarchies are stored in [`HygieneData`][hd]. This is a global
225
249
piece of data containing hygiene and expansion info that can be accessed from
@@ -362,6 +386,13 @@ foo!(bar!(baz));
362
386
For the `baz` AST node in the final output, the first heirarchy is `ROOT ->
363
387
id(foo) -> id(bar) -> baz`, while the third heirarchy is `ROOT -> baz`.
364
388
389
+
### Macro Backtraces
390
+
391
+
Macro backtraces are implemented in [`rustc_span`] using the hygiene machinery
TODO: sprinkle these throughout the chapter as much as possible...
567
-
568
-
- librustc_span/hygiene.rs - structures related to hygiene and expansion that are kept in global data (can be accessed from any Ident without any context)
569
-
- librustc_span/lib.rs - some secondary methods like macro backtrace using primary methods from hygiene.rs
570
-
- librustc_builtin_macros - implementations of built-in macros (including macro attributes and derives) and some other early code generation facilities like injection of standard library imports or generation of test harness.
571
-
- librustc_ast/config.rs - implementation of cfg/cfg_attr (they treated specially from other macros), should probably be moved into librustc_ast/ext.
572
-
- librustc_ast/tokenstream.rs + librustc_ast/parse/token.rs - structures for compiler-side tokens, token trees, and token streams.
573
-
- librustc_ast/ext - various expansion-related stuff
574
-
- librustc_ast/ext/base.rs - basic structures used by expansion
575
-
- librustc_ast/ext/expand.rs - some expansion structures and the bulk of expansion infrastructure code - collecting macro invocations, calling into resolve for them, calling their expanding functions, and integrating the results back into AST
576
-
- librustc_ast/ext/placeholder.rs - the part of expand.rs responsible for "integrating the results back into AST" basicallly, "placeholder" is a temporary AST node replaced with macro expansion result nodes
577
-
- librustc_ast/ext/builer.rs - helper functions for building AST for built-in macros in librustc_builtin_macros (and user-defined syntactic plugins previously), can probably be moved into librustc_builtin_macros these days
578
-
- librustc_ast/ext/proc_macro.rs + librustc_ast/ext/proc_macro_server.rs - interfaces between the compiler and the stable proc_macro library, converting tokens and token streams between the two representations and sending them through C ABI
579
-
- librustc_ast/ext/tt - implementation of macro_rules, turns macro_rules DSL into something with signature Fn(TokenStream) -> TokenStream that can eat and produce tokens, @mark-i-m knows more about this
580
-
- librustc_resolve/macros.rs - resolving macro paths, validating those resolutions, reporting various "not found"/"found, but it's unstable"/"expected x, found y" errors
581
-
- librustc_middle/hir/map/def_collector.rs + librustc_resolve/build_reduced_graph.rs - integrate an AST fragment freshly expanded from a macro into various parent/child structures like module hierarchy or "definition paths"
0 commit comments