Skip to content

Commit b0c4d0f

Browse files
committed
incremental: Do not rely on default transparency when decoding syntax contexts
Using `ExpnId`s default transparency here instead of the mark's real transparency was actually incorrect.
1 parent bf345dd commit b0c4d0f

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::mem;
2323
use syntax::ast::NodeId;
2424
use syntax::source_map::{SourceMap, StableSourceFileId};
2525
use syntax_pos::{BytePos, Span, DUMMY_SP, SourceFile};
26-
use syntax_pos::hygiene::{ExpnId, SyntaxContext, ExpnData};
26+
use syntax_pos::hygiene::{ExpnId, SyntaxContext};
2727

2828
const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
2929

@@ -593,8 +593,8 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
593593
// don't seem to be used after HIR lowering, so everything should be fine
594594
// as long as incremental compilation does not kick in before that.
595595
let location = || Span::with_root_ctxt(lo, hi);
596-
let recover_from_expn_data = |this: &Self, expn_data, pos| {
597-
let span = location().fresh_expansion(expn_data);
596+
let recover_from_expn_data = |this: &Self, expn_data, transparency, pos| {
597+
let span = location().fresh_expansion_with_transparency(expn_data, transparency);
598598
this.synthetic_syntax_contexts.borrow_mut().insert(pos, span.ctxt());
599599
span
600600
};
@@ -603,9 +603,9 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
603603
location()
604604
}
605605
TAG_EXPN_DATA_INLINE => {
606-
let expn_data = Decodable::decode(self)?;
606+
let (expn_data, transparency) = Decodable::decode(self)?;
607607
recover_from_expn_data(
608-
self, expn_data, AbsoluteBytePos::new(self.opaque.position())
608+
self, expn_data, transparency, AbsoluteBytePos::new(self.opaque.position())
609609
)
610610
}
611611
TAG_EXPN_DATA_SHORTHAND => {
@@ -614,9 +614,9 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
614614
if let Some(ctxt) = cached_ctxt {
615615
Span::new(lo, hi, ctxt)
616616
} else {
617-
let expn_data =
618-
self.with_position(pos.to_usize(), |this| ExpnData::decode(this))?;
619-
recover_from_expn_data(self, expn_data, pos)
617+
let (expn_data, transparency) =
618+
self.with_position(pos.to_usize(), |this| Decodable::decode(this))?;
619+
recover_from_expn_data(self, expn_data, transparency, pos)
620620
}
621621
}
622622
_ => {
@@ -819,15 +819,15 @@ where
819819
if span_data.ctxt == SyntaxContext::root() {
820820
TAG_NO_EXPN_DATA.encode(self)
821821
} else {
822-
let (expn_id, expn_data) = span_data.ctxt.outer_expn_with_data();
822+
let (expn_id, transparency, expn_data) = span_data.ctxt.outer_mark_with_data();
823823
if let Some(pos) = self.expn_data_shorthands.get(&expn_id).cloned() {
824824
TAG_EXPN_DATA_SHORTHAND.encode(self)?;
825825
pos.encode(self)
826826
} else {
827827
TAG_EXPN_DATA_INLINE.encode(self)?;
828828
let pos = AbsoluteBytePos::new(self.position());
829829
self.expn_data_shorthands.insert(expn_id, pos);
830-
expn_data.encode(self)
830+
(expn_data, transparency).encode(self)
831831
}
832832
}
833833
}

src/libsyntax_pos/hygiene.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ impl HygieneData {
183183
self.syntax_context_data[ctxt.0 as usize].outer_expn
184184
}
185185

186-
fn outer_transparency(&self, ctxt: SyntaxContext) -> Transparency {
187-
self.syntax_context_data[ctxt.0 as usize].outer_transparency
186+
fn outer_mark(&self, ctxt: SyntaxContext) -> (ExpnId, Transparency) {
187+
let data = &self.syntax_context_data[ctxt.0 as usize];
188+
(data.outer_expn, data.outer_transparency)
188189
}
189190

190191
fn parent_ctxt(&self, ctxt: SyntaxContext) -> SyntaxContext {
@@ -200,7 +201,7 @@ impl HygieneData {
200201
fn marks(&self, mut ctxt: SyntaxContext) -> Vec<(ExpnId, Transparency)> {
201202
let mut marks = Vec::new();
202203
while ctxt != SyntaxContext::root() {
203-
marks.push((self.outer_expn(ctxt), self.outer_transparency(ctxt)));
204+
marks.push(self.outer_mark(ctxt));
204205
ctxt = self.parent_ctxt(ctxt);
205206
}
206207
marks.reverse();
@@ -535,13 +536,11 @@ impl SyntaxContext {
535536
HygieneData::with(|data| data.expn_data(data.outer_expn(self)).clone())
536537
}
537538

538-
/// `ctxt.outer_expn_with_data()` is equivalent to but faster than
539-
/// `{ let outer = ctxt.outer_expn(); (outer, outer.expn_data()) }`.
540539
#[inline]
541-
pub fn outer_expn_with_data(self) -> (ExpnId, ExpnData) {
540+
pub fn outer_mark_with_data(self) -> (ExpnId, Transparency, ExpnData) {
542541
HygieneData::with(|data| {
543-
let outer = data.outer_expn(self);
544-
(outer, data.expn_data(outer).clone())
542+
let (expn_id, transparency) = data.outer_mark(self);
543+
(expn_id, transparency, data.expn_data(expn_id).clone())
545544
})
546545
}
547546

@@ -563,9 +562,18 @@ impl Span {
563562
/// The returned span belongs to the created expansion and has the new properties,
564563
/// but its location is inherited from the current span.
565564
pub fn fresh_expansion(self, expn_data: ExpnData) -> Span {
565+
let transparency = expn_data.default_transparency;
566+
self.fresh_expansion_with_transparency(expn_data, transparency)
567+
}
568+
569+
pub fn fresh_expansion_with_transparency(
570+
self, expn_data: ExpnData, transparency: Transparency
571+
) -> Span {
566572
HygieneData::with(|data| {
567573
let expn_id = data.fresh_expn(Some(expn_data));
568-
self.with_ctxt(data.apply_mark(SyntaxContext::root(), expn_id))
574+
self.with_ctxt(data.apply_mark_with_transparency(
575+
SyntaxContext::root(), expn_id, transparency
576+
))
569577
})
570578
}
571579
}

0 commit comments

Comments
 (0)