@@ -93,7 +93,7 @@ iteration, this represents a compile error. Here is the [algorithm][original]:
93
93
proper set-in-stone AST with side-tables. It happens as follows:
94
94
- If the macro produces tokens (e.g. a proc macro), we parse into
95
95
an AST, which may produce parse errors.
96
- - During expansion, we create ` SyntaxContext ` s (heirarchy 2). (See
96
+ - During expansion, we create ` SyntaxContext ` s (hierarchy 2). (See
97
97
[ the "Hygiene" section below] [ hybelow ] )
98
98
- These three passes happen one after another on every AST fragment
99
99
freshly expanded from a macro:
@@ -116,7 +116,7 @@ iteration, this represents a compile error. Here is the [algorithm][original]:
116
116
[ `DefId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html
117
117
[ `DefCollector` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/def_collector/struct.DefCollector.html
118
118
[ `BuildReducedGraphVisitor` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/build_reduced_graph/struct.BuildReducedGraphVisitor.html
119
- [ hybelow ] : #hygiene-and-heirarchies
119
+ [ hybelow ] : #hygiene-and-hierarchies
120
120
[ tt ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/tokenstream/enum.TokenTree.html
121
121
[ `TokenStream` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/tokenstream/struct.TokenStream.html
122
122
[ inv ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/expand/struct.Invocation.html
@@ -165,7 +165,7 @@ Here are some other notable data structures involved in expansion and integratio
165
165
[ `AstFragmentKind` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/expand/enum.AstFragmentKind.html
166
166
167
167
168
- ## Hygiene and Heirarchies
168
+ ## Hygiene and Hierarchies
169
169
170
170
If you have ever used C/C++ preprocessor macros, you know that there are some
171
171
annoying and hard-to-debug gotchas! For example, consider the following C code:
@@ -228,26 +228,26 @@ This struct also has hygiene information attached to it, as we will see later.
228
228
[span]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html
229
229
230
230
Because macros invocations and definitions can be nested, the syntax context of
231
- a node must be a heirarchy . For example, if we expand a macro and there is
231
+ a node must be a hierarchy . For example, if we expand a macro and there is
232
232
another macro invocation or definition in the generated output, then the syntax
233
233
context should reflex the nesting.
234
234
235
235
However, it turns out that there are actually a few types of context we may
236
- want to track for different purposes. Thus, there not just one but _three_
237
- expansion heirarchies that together comprise the hygiene information for a
236
+ want to track for different purposes. Thus, there are not just one but _three_
237
+ expansion hierarchies that together comprise the hygiene information for a
238
238
crate.
239
239
240
- All of these heirarchies need some sort of "macro ID" to identify individual
240
+ All of these hierarchies need some sort of "macro ID" to identify individual
241
241
elements in the chain of expansions. This ID is [`ExpnId`]. All macros receive
242
242
an integer ID, assigned continuously starting from 0 as we discover new macro
243
- calls. All heirarchies start at [`ExpnId::root()`][rootid], which is its own
243
+ calls. All hierarchies start at [`ExpnId::root()`][rootid], which is its own
244
244
parent.
245
245
246
246
[`rustc_span::hygiene`][hy] contains all of the hygiene-related algorithms
247
247
(with the exception of some hacks in [`Resolver::resolve_crate_root`][hacks])
248
248
and structures related to hygiene and expansion that are kept in global data.
249
249
250
- The actual heirarchies are stored in [`HygieneData`][hd]. This is a global
250
+ The actual hierarchies are stored in [`HygieneData`][hd]. This is a global
251
251
piece of data containing hygiene and expansion info that can be accessed from
252
252
any [`Ident`] without any context.
253
253
@@ -259,15 +259,15 @@ any [`Ident`] without any context.
259
259
[hacks]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/struct.Resolver.html#method.resolve_crate_root
260
260
[`Ident`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Ident.html
261
261
262
- ### The Expansion Order Heirarchy
262
+ ### The Expansion Order Hierarchy
263
263
264
- The first heirarchy tracks the order of expansions, i.e., when a macro
264
+ The first hierarchy tracks the order of expansions, i.e., when a macro
265
265
invocation is in the output of another macro.
266
266
267
- Here, the children in the heirarchy will be the "innermost" tokens. The
267
+ Here, the children in the hierarchy will be the "innermost" tokens. The
268
268
[`ExpnData`] struct itself contains a subset of properties from both macro
269
269
definition and macro call available through global data.
270
- [`ExpnData::parent`][edp] tracks the child -> parent link in this heirarchy .
270
+ [`ExpnData::parent`][edp] tracks the child -> parent link in this hierarchy .
271
271
272
272
[`ExpnData`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/hygiene/struct.ExpnData.html
273
273
[edp]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/hygiene/struct.ExpnData.html#structfield.parent
@@ -280,19 +280,19 @@ macro_rules! foo { () => { println!(); } }
280
280
fn main() { foo!(); }
281
281
```
282
282
283
- In this code, the AST nodes that are finally generated would have heirarchy :
283
+ In this code, the AST nodes that are finally generated would have hierarchy :
284
284
285
285
```
286
286
root
287
287
expn_id_foo
288
288
expn_id_println
289
289
```
290
290
291
- ### The Macro Definition Heirarchy
291
+ ### The Macro Definition Hierarchy
292
292
293
- The second heirarchy tracks the order of macro definitions, i.e., when we are
293
+ The second hierarchy tracks the order of macro definitions, i.e., when we are
294
294
expanding one macro another macro definition is revealed in its output. This
295
- one is a bit tricky and more complex than the other two heirarchies .
295
+ one is a bit tricky and more complex than the other two hierarchies .
296
296
297
297
[ ` SyntaxContext ` ] [ sc ] represents a whole chain in this hierarchy via an ID.
298
298
[ ` SyntaxContextData ` ] [ scd ] contains data associated with the given
@@ -315,7 +315,7 @@ a code location and `SyntaxContext`. Likewise, an [`Ident`] is just an interned
315
315
316
316
For built-in macros, we use the context:
317
317
` SyntaxContext::empty().apply_mark(expn_id) ` , and such macros are considered to
318
- be defined at the heirarchy root. We do the same for proc-macros because we
318
+ be defined at the hierarchy root. We do the same for proc-macros because we
319
319
haven't implemented cross-crate hygiene yet.
320
320
321
321
If the token had context ` X ` before being produced by a macro then after being
@@ -360,19 +360,19 @@ m!(foo);
360
360
After all expansions, ` foo ` has context ` ROOT -> id(n) ` and ` bar ` has context
361
361
` ROOT -> id(m) -> id(n) ` .
362
362
363
- Finally, one last thing to mention is that currently, this heirarchy is subject
363
+ Finally, one last thing to mention is that currently, this hierarchy is subject
364
364
to the [ "context transplantation hack"] [ hack ] . Basically, the more modern (and
365
365
experimental) ` macro ` macros have stronger hygiene than the older MBE system,
366
366
but this can result in weird interactions between the two. The hack is intended
367
367
to make things "just work" for now.
368
368
369
369
[ hack ] : https://github.com/rust-lang/rust/pull/51762#issuecomment-401400732
370
370
371
- ### The Call-site Heirarchy
371
+ ### The Call-site Hierarchy
372
372
373
- The third and final heirarchy tracks the location of macro invocations.
373
+ The third and final hierarchy tracks the location of macro invocations.
374
374
375
- In this heirarchy [ ` ExpnData::call_site ` ] [ callsite ] is the child -> parent link.
375
+ In this hierarchy [ ` ExpnData::call_site ` ] [ callsite ] is the child -> parent link.
376
376
377
377
[ callsite ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/hygiene/struct.ExpnData.html#structfield.call_site
378
378
@@ -385,8 +385,8 @@ macro foo($i: ident) { $i }
385
385
foo!(bar!(baz));
386
386
```
387
387
388
- For the ` baz ` AST node in the final output, the first heirarchy is `ROOT ->
389
- id(foo) -> id(bar) -> baz` , while the third heirarchy is ` ROOT -> baz`.
388
+ For the ` baz ` AST node in the final output, the first hierarchy is `ROOT ->
389
+ id(foo) -> id(bar) -> baz` , while the third hierarchy is ` ROOT -> baz`.
390
390
391
391
### Macro Backtraces
392
392
0 commit comments