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
If we make no progress in an iteration, then we have reached a compilation
99
107
error (e.g. an undefined macro). We attempt to recover from failures
@@ -110,6 +118,27 @@ macro names in the above algorithm. However, we don't try to resolve other
110
118
names yet. This happens later, as we will see in the [next
111
119
chapter](./name-resolution.md).
112
120
121
+
Here are some other notable data structures involved in expansion and integration:
122
+
-[`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
+
-[`ExtCtxt`]/[`ExpansionData`] - various intermediate data kept and used by expansion
124
+
infrastructure in the process of its work
125
+
-[`Annotatable`] - a piece of AST that can be an attribute target, almost same
126
+
thing as AstFragment except for types and patterns that can be produced by
127
+
macros but cannot be annotated with attributes
128
+
-[`MacResult`] - a "polymorphic" AST fragment, something that can turn into a
129
+
different `AstFragment` depending on its [`AstFragmentKind`] - item,
MBEs have their own parser distinct from the normal Rust parser. When macros
@@ -492,11 +561,10 @@ Custom derives are a special type of proc macro.
492
561
493
562
TODO: more?
494
563
495
-
## Notes from petrochenkov discussion
564
+
## Important Modules and Data Structures
496
565
497
-
TODO: sprinkle these links around the chapter...
566
+
TODO: sprinkle these throughout the chapter as much as possible...
498
567
499
-
Where to find the code:
500
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)
501
569
- librustc_span/lib.rs - some secondary methods like macro backtrace using primary methods from hygiene.rs
502
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.
@@ -511,23 +579,3 @@ Where to find the code:
511
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
512
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
513
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"
514
-
515
-
Primary structures:
516
-
- HygieneData - global piece of data containing hygiene and expansion info that can be accessed from any Ident without any context
517
-
- ExpnId - ID of a macro call or desugaring (and also expansion of that call/desugaring, depending on context)
518
-
- ExpnInfo/InternalExpnData - a subset of properties from both macro definition and macro call available through global data
519
-
- SyntaxContext - ID of a chain of nested macro definitions (identified by ExpnIds)
520
-
- SyntaxContextData - data associated with the given SyntaxContext, mostly a cache for results of filtering that chain in different ways
521
-
- Span - a code location + SyntaxContext
522
-
- Ident - interned string (Symbol) + Span, i.e. a string with attached hygiene data
523
-
- TokenStream - a collection of TokenTrees
524
-
- TokenTree - a token (punctuation, identifier, or literal) or a delimited group (anything inside ()/[]/{})
525
-
- SyntaxExtension - a lowered macro representation, contains its expander function transforming a tokenstream or AST into tokenstream or AST + some additional data like stability, or a list of unstable features allowed inside the macro.
526
-
- SyntaxExtensionKind - expander functions may have several different signatures (take one token stream, or two, or a piece of AST, etc), this is an enum that lists them
527
-
- ProcMacro/TTMacroExpander/AttrProcMacro/MultiItemModifier - traits representing the expander signatures (TODO: change and rename the signatures into something more consistent)
528
-
- Resolver - a trait used to break crate dependencies (so resolver services can be used in librustc_ast, despite librustc_resolve and pretty much everything else depending on librustc_ast)
529
-
- ExtCtxt/ExpansionData - various intermediate data kept and used by expansion infra in the process of its work
530
-
- AstFragment - a piece of AST that can be produced by a macro (may include multiple homogeneous AST nodes, like e.g. a list of items)
531
-
- Annotatable - a piece of AST that can be an attribute target, almost same thing as AstFragment except for types and patterns that can be produced by macros but cannot be annotated with attributes (TODO: Merge into AstFragment)
532
-
- MacResult - a "polymorphic" AST fragment, something that can turn into a different AstFragment depending on its context (aka AstFragmentKind - item, or expression, or pattern etc.)
533
-
- Invocation/InvocationKind - a structure describing a macro call, these structures are collected by the expansion infra (InvocationCollector), queued, resolved, expanded when resolved, etc.
0 commit comments