@@ -93,7 +93,7 @@ iteration, this represents a compile error. Here is the [algorithm][original]:
9393 proper set-in-stone AST with side-tables. It happens as follows:
9494 - If the macro produces tokens (e.g. a proc macro), we parse into
9595 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
9797 [ the "Hygiene" section below] [ hybelow ] )
9898 - These three passes happen one after another on every AST fragment
9999 freshly expanded from a macro:
@@ -116,7 +116,7 @@ iteration, this represents a compile error. Here is the [algorithm][original]:
116116[ `DefId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html
117117[ `DefCollector` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/def_collector/struct.DefCollector.html
118118[ `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
120120[ tt ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/tokenstream/enum.TokenTree.html
121121[ `TokenStream` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/tokenstream/struct.TokenStream.html
122122[ 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
165165[ `AstFragmentKind` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/expand/enum.AstFragmentKind.html
166166
167167
168- ## Hygiene and Heirarchies
168+ ## Hygiene and Hierarchies
169169
170170If you have ever used C/C++ preprocessor macros, you know that there are some
171171annoying 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.
228228[span]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html
229229
230230Because 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
232232another macro invocation or definition in the generated output, then the syntax
233233context should reflex the nesting.
234234
235235However, 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
238238crate.
239239
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
241241elements in the chain of expansions. This ID is [`ExpnId`]. All macros receive
242242an 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
244244parent.
245245
246246[`rustc_span::hygiene`][hy] contains all of the hygiene-related algorithms
247247(with the exception of some hacks in [`Resolver::resolve_crate_root`][hacks])
248248and structures related to hygiene and expansion that are kept in global data.
249249
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
251251piece of data containing hygiene and expansion info that can be accessed from
252252any [`Ident`] without any context.
253253
@@ -259,15 +259,15 @@ any [`Ident`] without any context.
259259[hacks]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/struct.Resolver.html#method.resolve_crate_root
260260[`Ident`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Ident.html
261261
262- ### The Expansion Order Heirarchy
262+ ### The Expansion Order Hierarchy
263263
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
265265invocation is in the output of another macro.
266266
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
268268[`ExpnData`] struct itself contains a subset of properties from both macro
269269definition 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 .
271271
272272[`ExpnData`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/hygiene/struct.ExpnData.html
273273[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!(); } }
280280fn main() { foo!(); }
281281```
282282
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 :
284284
285285```
286286root
287287 expn_id_foo
288288 expn_id_println
289289```
290290
291- ### The Macro Definition Heirarchy
291+ ### The Macro Definition Hierarchy
292292
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
294294expanding 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 .
296296
297297[ ` SyntaxContext ` ] [ sc ] represents a whole chain in this hierarchy via an ID.
298298[ ` SyntaxContextData ` ] [ scd ] contains data associated with the given
@@ -315,7 +315,7 @@ a code location and `SyntaxContext`. Likewise, an [`Ident`] is just an interned
315315
316316For built-in macros, we use the context:
317317` 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
319319haven't implemented cross-crate hygiene yet.
320320
321321If the token had context ` X ` before being produced by a macro then after being
@@ -360,19 +360,19 @@ m!(foo);
360360After all expansions, ` foo ` has context ` ROOT -> id(n) ` and ` bar ` has context
361361` ROOT -> id(m) -> id(n) ` .
362362
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
364364to the [ "context transplantation hack"] [ hack ] . Basically, the more modern (and
365365experimental) ` macro ` macros have stronger hygiene than the older MBE system,
366366but this can result in weird interactions between the two. The hack is intended
367367to make things "just work" for now.
368368
369369[ hack ] : https://github.com/rust-lang/rust/pull/51762#issuecomment-401400732
370370
371- ### The Call-site Heirarchy
371+ ### The Call-site Hierarchy
372372
373- The third and final heirarchy tracks the location of macro invocations.
373+ The third and final hierarchy tracks the location of macro invocations.
374374
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.
376376
377377[ callsite ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/hygiene/struct.ExpnData.html#structfield.call_site
378378
@@ -385,8 +385,8 @@ macro foo($i: ident) { $i }
385385foo!(bar!(baz));
386386```
387387
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`.
390390
391391### Macro Backtraces
392392
0 commit comments