Skip to content

Commit 425736d

Browse files
committed
Add a useful comment about this file.
1 parent dc807a9 commit 425736d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libsyntax_pos/hygiene.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@
55
//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
66
//! DOI=10.1017/S0956796812000093 <https://doi.org/10.1017/S0956796812000093>
77
8+
// Hygiene data is stored in a global variable and accessed via TLS, which
9+
// means that accesses are somewhat expensive. (`HygieneData::with`
10+
// encapsulates a single access.) Therefore, on hot code paths it is worth
11+
// ensuring that multiple HygieneData accesses are combined into a single
12+
// `HygieneData::with`.
13+
//
14+
// This explains why `HygieneData`, `SyntaxContext` and `Mark` have interfaces
15+
// with a certain amount of redundancy in them. For example,
16+
// `SyntaxContext::outer_expn_info` combines `SyntaxContext::outer` and
17+
// `Mark::expn_info` so that two `HygieneData` accesses can be performed within
18+
// a single `HygieneData::with` call.
19+
//
20+
// It also explains why many functions appear in `HygieneData` and again in
21+
// `SyntaxContext` or `Mark`. For example, `HygieneData::outer` and
22+
// `SyntaxContext::outer` do the same thing, but the former is for use within a
23+
// `HygieneData::with` call while the latter is for use outside such a call.
24+
// When modifying this file it is important to understand this distinction,
25+
// because getting it wrong can lead to nested `HygieneData::with` calls that
26+
// trigger runtime aborts. (Fortunately these are obvious and easy to fix.)
27+
828
use crate::GLOBALS;
929
use crate::Span;
1030
use crate::edition::Edition;

0 commit comments

Comments
 (0)