Skip to content

Commit 8f30d26

Browse files
committed
hygiene: Tweak naming some more
1 parent 09703e3 commit 8f30d26

File tree

7 files changed

+65
-64
lines changed

7 files changed

+65
-64
lines changed

Diff for: src/librustc/ich/hcx.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,17 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
363363
}
364364

365365
let sub_hash: u64 = CACHE.with(|cache| {
366-
let mark = span.ctxt.outer();
366+
let expn_id = span.ctxt.outer_expn();
367367

368-
if let Some(&sub_hash) = cache.borrow().get(&mark) {
368+
if let Some(&sub_hash) = cache.borrow().get(&expn_id) {
369369
return sub_hash;
370370
}
371371

372372
let mut hasher = StableHasher::new();
373-
mark.expn_info().hash_stable(hcx, &mut hasher);
373+
expn_id.expn_info().hash_stable(hcx, &mut hasher);
374374
let sub_hash: Fingerprint = hasher.finish();
375375
let sub_hash = sub_hash.to_smaller_hash();
376-
cache.borrow_mut().insert(mark, sub_hash);
376+
cache.borrow_mut().insert(expn_id, sub_hash);
377377
sub_hash
378378
});
379379

Diff for: src/librustc/ty/query/on_disk_cache.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -819,15 +819,15 @@ where
819819
if span_data.ctxt == SyntaxContext::empty() {
820820
TAG_NO_EXPANSION_INFO.encode(self)
821821
} else {
822-
let (mark, expn_info) = span_data.ctxt.outer_and_expn_info();
822+
let (expn_id, expn_info) = span_data.ctxt.outer_expn_with_info();
823823
if let Some(expn_info) = expn_info {
824-
if let Some(pos) = self.expn_info_shorthands.get(&mark).cloned() {
824+
if let Some(pos) = self.expn_info_shorthands.get(&expn_id).cloned() {
825825
TAG_EXPANSION_INFO_SHORTHAND.encode(self)?;
826826
pos.encode(self)
827827
} else {
828828
TAG_EXPANSION_INFO_INLINE.encode(self)?;
829829
let pos = AbsoluteBytePos::new(self.position());
830-
self.expn_info_shorthands.insert(mark, pos);
830+
self.expn_info_shorthands.insert(expn_id, pos);
831831
expn_info.encode(self)
832832
}
833833
} else {

Diff for: src/librustc_codegen_llvm/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
102102
let kind = llvm::LLVMGetMDKindIDInContext(self.llcx,
103103
key.as_ptr() as *const c_char, key.len() as c_uint);
104104

105-
let val: &'ll Value = self.const_i32(ia.ctxt.outer().as_u32() as i32);
105+
let val: &'ll Value = self.const_i32(ia.ctxt.outer_expn().as_u32() as i32);
106106

107107
llvm::LLVMSetMetadata(r, kind,
108108
llvm::LLVMMDNodeInContext(self.llcx, &val, 1));

Diff for: src/librustc_interface/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ pub fn lower_to_hir(
572572

573573
// Discard hygiene data, which isn't required after lowering to HIR.
574574
if !sess.opts.debugging_opts.keep_hygiene_data {
575-
syntax::ext::hygiene::syntax_context_map();
575+
syntax::ext::hygiene::clear_syntax_context_map();
576576
}
577577

578578
Ok(hir_forest)

Diff for: src/librustc_resolve/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ impl<'a> Resolver<'a> {
20702070

20712071
fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId {
20722072
loop {
2073-
match self.macro_defs.get(&ctxt.outer()) {
2073+
match self.macro_defs.get(&ctxt.outer_expn()) {
20742074
Some(&def_id) => return def_id,
20752075
None => ctxt.remove_mark(),
20762076
};
@@ -2428,7 +2428,7 @@ impl<'a> Resolver<'a> {
24282428

24292429
fn hygienic_lexical_parent(&mut self, module: Module<'a>, span: &mut Span)
24302430
-> Option<Module<'a>> {
2431-
if !module.expansion.outer_is_descendant_of(span.ctxt()) {
2431+
if !module.expansion.outer_expn_is_descendant_of(span.ctxt()) {
24322432
return Some(self.macro_def_scope(span.remove_mark()));
24332433
}
24342434

@@ -2464,7 +2464,7 @@ impl<'a> Resolver<'a> {
24642464
module.expansion.is_descendant_of(parent.expansion) {
24652465
// The macro is a proc macro derive
24662466
if module.expansion.looks_like_proc_macro_derive() {
2467-
if parent.expansion.outer_is_descendant_of(span.ctxt()) {
2467+
if parent.expansion.outer_expn_is_descendant_of(span.ctxt()) {
24682468
*poisoned = Some(node_id);
24692469
return module.parent;
24702470
}

Diff for: src/librustc_resolve/macros.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ impl<'a> base::Resolver for Resolver<'a> {
139139
let span = DUMMY_SP.fresh_expansion(ExpnId::root(), ExpnInfo::default(
140140
ExpnKind::Macro(MacroKind::Attr, sym::test_case), DUMMY_SP, self.session.edition()
141141
));
142-
let mark = span.ctxt().outer();
142+
let expn_id = span.ctxt().outer_expn();
143143
let module = self.module_map[&self.definitions.local_def_id(id)];
144-
self.definitions.set_invocation_parent(mark, module.def_id().unwrap().index);
145-
self.invocations.insert(mark, self.arenas.alloc_invocation_data(InvocationData {
144+
self.definitions.set_invocation_parent(expn_id, module.def_id().unwrap().index);
145+
self.invocations.insert(expn_id, self.arenas.alloc_invocation_data(InvocationData {
146146
module,
147147
parent_legacy_scope: LegacyScope::Empty,
148148
output_legacy_scope: Cell::new(None),
149149
}));
150-
mark
150+
expn_id
151151
}
152152

153153
fn resolve_dollar_crates(&mut self) {

Diff for: src/libsyntax_pos/hygiene.rs

+49-48
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ pub struct SyntaxContext(u32);
4242
#[derive(Debug)]
4343
struct SyntaxContextData {
4444
outer_expn: ExpnId,
45-
transparency: Transparency,
46-
prev_ctxt: SyntaxContext,
45+
outer_transparency: Transparency,
46+
parent: SyntaxContext,
4747
/// This context, but with all transparent and semi-transparent expansions filtered away.
4848
opaque: SyntaxContext,
4949
/// This context, but with all transparent expansions filtered away.
@@ -108,7 +108,7 @@ impl ExpnId {
108108

109109
#[inline]
110110
pub fn parent(self) -> ExpnId {
111-
HygieneData::with(|data| data.expn_data[self.0 as usize].parent)
111+
HygieneData::with(|data| data.parent_expn(self))
112112
}
113113

114114
#[inline]
@@ -129,10 +129,10 @@ impl ExpnId {
129129
HygieneData::with(|data| data.is_descendant_of(self, ancestor))
130130
}
131131

132-
/// `expn_id.outer_is_descendant_of(ctxt)` is equivalent to but faster than
133-
/// `expn_id.is_descendant_of(ctxt.outer())`.
134-
pub fn outer_is_descendant_of(self, ctxt: SyntaxContext) -> bool {
135-
HygieneData::with(|data| data.is_descendant_of(self, data.outer(ctxt)))
132+
/// `expn_id.outer_expn_is_descendant_of(ctxt)` is equivalent to but faster than
133+
/// `expn_id.is_descendant_of(ctxt.outer_expn())`.
134+
pub fn outer_expn_is_descendant_of(self, ctxt: SyntaxContext) -> bool {
135+
HygieneData::with(|data| data.is_descendant_of(self, data.outer_expn(ctxt)))
136136
}
137137

138138
// Used for enabling some compatibility fallback in resolve.
@@ -167,8 +167,8 @@ impl HygieneData {
167167
}],
168168
syntax_context_data: vec![SyntaxContextData {
169169
outer_expn: ExpnId::root(),
170-
transparency: Transparency::Opaque,
171-
prev_ctxt: SyntaxContext(0),
170+
outer_transparency: Transparency::Opaque,
171+
parent: SyntaxContext(0),
172172
opaque: SyntaxContext(0),
173173
opaque_and_semitransparent: SyntaxContext(0),
174174
dollar_crate_name: kw::DollarCrate,
@@ -186,6 +186,10 @@ impl HygieneData {
186186
ExpnId(self.expn_data.len() as u32 - 1)
187187
}
188188

189+
fn parent_expn(&self, expn_id: ExpnId) -> ExpnId {
190+
self.expn_data[expn_id.0 as usize].parent
191+
}
192+
189193
fn expn_info(&self, expn_id: ExpnId) -> Option<&ExpnInfo> {
190194
if expn_id != ExpnId::root() {
191195
Some(self.expn_data[expn_id.0 as usize].expn_info.as_ref()
@@ -203,7 +207,7 @@ impl HygieneData {
203207
if expn_id == ExpnId::root() {
204208
return false;
205209
}
206-
expn_id = self.expn_data[expn_id.0 as usize].parent;
210+
expn_id = self.parent_expn(expn_id);
207211
}
208212
true
209213
}
@@ -222,40 +226,37 @@ impl HygieneData {
222226
self.syntax_context_data[ctxt.0 as usize].opaque_and_semitransparent
223227
}
224228

225-
fn outer(&self, ctxt: SyntaxContext) -> ExpnId {
229+
fn outer_expn(&self, ctxt: SyntaxContext) -> ExpnId {
226230
self.syntax_context_data[ctxt.0 as usize].outer_expn
227231
}
228232

229-
fn transparency(&self, ctxt: SyntaxContext) -> Transparency {
230-
self.syntax_context_data[ctxt.0 as usize].transparency
233+
fn outer_transparency(&self, ctxt: SyntaxContext) -> Transparency {
234+
self.syntax_context_data[ctxt.0 as usize].outer_transparency
231235
}
232236

233-
fn prev_ctxt(&self, ctxt: SyntaxContext) -> SyntaxContext {
234-
self.syntax_context_data[ctxt.0 as usize].prev_ctxt
237+
fn parent_ctxt(&self, ctxt: SyntaxContext) -> SyntaxContext {
238+
self.syntax_context_data[ctxt.0 as usize].parent
235239
}
236240

237241
fn remove_mark(&self, ctxt: &mut SyntaxContext) -> ExpnId {
238-
let outer_expn = self.syntax_context_data[ctxt.0 as usize].outer_expn;
239-
*ctxt = self.prev_ctxt(*ctxt);
242+
let outer_expn = self.outer_expn(*ctxt);
243+
*ctxt = self.parent_ctxt(*ctxt);
240244
outer_expn
241245
}
242246

243247
fn marks(&self, mut ctxt: SyntaxContext) -> Vec<(ExpnId, Transparency)> {
244248
let mut marks = Vec::new();
245249
while ctxt != SyntaxContext::empty() {
246-
let outer_expn = self.outer(ctxt);
247-
let transparency = self.transparency(ctxt);
248-
let prev_ctxt = self.prev_ctxt(ctxt);
249-
marks.push((outer_expn, transparency));
250-
ctxt = prev_ctxt;
250+
marks.push((self.outer_expn(ctxt), self.outer_transparency(ctxt)));
251+
ctxt = self.parent_ctxt(ctxt);
251252
}
252253
marks.reverse();
253254
marks
254255
}
255256

256257
fn walk_chain(&self, mut span: Span, to: SyntaxContext) -> Span {
257258
while span.ctxt() != crate::NO_EXPANSION && span.ctxt() != to {
258-
if let Some(info) = self.expn_info(self.outer(span.ctxt())) {
259+
if let Some(info) = self.expn_info(self.outer_expn(span.ctxt())) {
259260
span = info.call_site;
260261
} else {
261262
break;
@@ -266,7 +267,7 @@ impl HygieneData {
266267

267268
fn adjust(&self, ctxt: &mut SyntaxContext, expn_id: ExpnId) -> Option<ExpnId> {
268269
let mut scope = None;
269-
while !self.is_descendant_of(expn_id, self.outer(*ctxt)) {
270+
while !self.is_descendant_of(expn_id, self.outer_expn(*ctxt)) {
270271
scope = Some(self.remove_mark(ctxt));
271272
}
272273
scope
@@ -320,14 +321,14 @@ impl HygieneData {
320321
syntax_context_data[ctxt.0 as usize].opaque_and_semitransparent;
321322

322323
if transparency >= Transparency::Opaque {
323-
let prev_ctxt = opaque;
324-
opaque = *self.syntax_context_map.entry((prev_ctxt, expn_id, transparency))
324+
let parent = opaque;
325+
opaque = *self.syntax_context_map.entry((parent, expn_id, transparency))
325326
.or_insert_with(|| {
326327
let new_opaque = SyntaxContext(syntax_context_data.len() as u32);
327328
syntax_context_data.push(SyntaxContextData {
328329
outer_expn: expn_id,
329-
transparency,
330-
prev_ctxt,
330+
outer_transparency: transparency,
331+
parent,
331332
opaque: new_opaque,
332333
opaque_and_semitransparent: new_opaque,
333334
dollar_crate_name: kw::DollarCrate,
@@ -337,16 +338,16 @@ impl HygieneData {
337338
}
338339

339340
if transparency >= Transparency::SemiTransparent {
340-
let prev_ctxt = opaque_and_semitransparent;
341+
let parent = opaque_and_semitransparent;
341342
opaque_and_semitransparent =
342-
*self.syntax_context_map.entry((prev_ctxt, expn_id, transparency))
343+
*self.syntax_context_map.entry((parent, expn_id, transparency))
343344
.or_insert_with(|| {
344345
let new_opaque_and_semitransparent =
345346
SyntaxContext(syntax_context_data.len() as u32);
346347
syntax_context_data.push(SyntaxContextData {
347348
outer_expn: expn_id,
348-
transparency,
349-
prev_ctxt,
349+
outer_transparency: transparency,
350+
parent,
350351
opaque,
351352
opaque_and_semitransparent: new_opaque_and_semitransparent,
352353
dollar_crate_name: kw::DollarCrate,
@@ -355,14 +356,14 @@ impl HygieneData {
355356
});
356357
}
357358

358-
let prev_ctxt = ctxt;
359-
*self.syntax_context_map.entry((prev_ctxt, expn_id, transparency)).or_insert_with(|| {
359+
let parent = ctxt;
360+
*self.syntax_context_map.entry((parent, expn_id, transparency)).or_insert_with(|| {
360361
let new_opaque_and_semitransparent_and_transparent =
361362
SyntaxContext(syntax_context_data.len() as u32);
362363
syntax_context_data.push(SyntaxContextData {
363364
outer_expn: expn_id,
364-
transparency,
365-
prev_ctxt,
365+
outer_transparency: transparency,
366+
parent,
366367
opaque,
367368
opaque_and_semitransparent,
368369
dollar_crate_name: kw::DollarCrate,
@@ -372,7 +373,7 @@ impl HygieneData {
372373
}
373374
}
374375

375-
pub fn syntax_context_map() {
376+
pub fn clear_syntax_context_map() {
376377
HygieneData::with(|data| data.syntax_context_map = FxHashMap::default());
377378
}
378379

@@ -513,7 +514,7 @@ impl SyntaxContext {
513514
HygieneData::with(|data| {
514515
let mut scope = None;
515516
let mut glob_ctxt = data.modern(glob_span.ctxt());
516-
while !data.is_descendant_of(expn_id, data.outer(glob_ctxt)) {
517+
while !data.is_descendant_of(expn_id, data.outer_expn(glob_ctxt)) {
517518
scope = Some(data.remove_mark(&mut glob_ctxt));
518519
if data.remove_mark(self) != scope.unwrap() {
519520
return None;
@@ -542,7 +543,7 @@ impl SyntaxContext {
542543

543544
let mut glob_ctxt = data.modern(glob_span.ctxt());
544545
let mut marks = Vec::new();
545-
while !data.is_descendant_of(expn_id, data.outer(glob_ctxt)) {
546+
while !data.is_descendant_of(expn_id, data.outer_expn(glob_ctxt)) {
546547
marks.push(data.remove_mark(&mut glob_ctxt));
547548
}
548549

@@ -573,23 +574,23 @@ impl SyntaxContext {
573574
}
574575

575576
#[inline]
576-
pub fn outer(self) -> ExpnId {
577-
HygieneData::with(|data| data.outer(self))
577+
pub fn outer_expn(self) -> ExpnId {
578+
HygieneData::with(|data| data.outer_expn(self))
578579
}
579580

580581
/// `ctxt.outer_expn_info()` is equivalent to but faster than
581-
/// `ctxt.outer().expn_info()`.
582+
/// `ctxt.outer_expn().expn_info()`.
582583
#[inline]
583584
pub fn outer_expn_info(self) -> Option<ExpnInfo> {
584-
HygieneData::with(|data| data.expn_info(data.outer(self)).cloned())
585+
HygieneData::with(|data| data.expn_info(data.outer_expn(self)).cloned())
585586
}
586587

587-
/// `ctxt.outer_and_expn_info()` is equivalent to but faster than
588-
/// `{ let outer = ctxt.outer(); (outer, outer.expn_info()) }`.
588+
/// `ctxt.outer_expn_with_info()` is equivalent to but faster than
589+
/// `{ let outer = ctxt.outer_expn(); (outer, outer.expn_info()) }`.
589590
#[inline]
590-
pub fn outer_and_expn_info(self) -> (ExpnId, Option<ExpnInfo>) {
591+
pub fn outer_expn_with_info(self) -> (ExpnId, Option<ExpnInfo>) {
591592
HygieneData::with(|data| {
592-
let outer = data.outer(self);
593+
let outer = data.outer_expn(self);
593594
(outer, data.expn_info(outer).cloned())
594595
})
595596
}
@@ -613,7 +614,7 @@ impl Span {
613614
/// but its location is inherited from the current span.
614615
pub fn fresh_expansion(self, parent: ExpnId, expn_info: ExpnInfo) -> Span {
615616
HygieneData::with(|data| {
616-
let expn_id = data.fresh_expn_id(parent, Some(expn_info));
617+
let expn_id = data.fresh_expn(parent, Some(expn_info));
617618
self.with_ctxt(data.apply_mark(SyntaxContext::empty(), expn_id))
618619
})
619620
}

0 commit comments

Comments
 (0)