Skip to content

Commit 214fb56

Browse files
committed
Fixed the on-demand decoding mechanism for hygiene data.
1 parent 7bb56bf commit 214fb56

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/librustc_metadata/creader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ impl<'a> CrateLoader<'a> {
294294
// after we were able to deserialize its contents.
295295
dllimport_foreign_items: FxHashSet(),
296296
hygiene_data_import_info: RefCell::new(None),
297+
hygiene_data_being_decoded: Cell::new(false),
297298
};
298299

299300
let dllimports: FxHashSet<_> = cmeta

src/librustc_metadata/cstore.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub struct CrateMetadata {
8989
pub dllimport_foreign_items: FxHashSet<DefIndex>,
9090

9191
pub hygiene_data_import_info: RefCell<Option<hygiene::ImportedHygieneData>>,
92+
pub hygiene_data_being_decoded: Cell<bool>,
9293
}
9394

9495
pub struct CStore {

src/librustc_metadata/decoder.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,7 @@ impl<'a, 'tcx> SpecializedDecoder<hygiene::Mark> for DecodeContext<'a, 'tcx> {
241241
fn specialized_decode(&mut self) -> Result<hygiene::Mark, Self::Error> {
242242
let mark = u32::decode(self)?;
243243

244-
// We only perform translation if hygiene info is already available and if the
245-
// mark actually needs translation. That way we avoid loops (as obtaining hygiene
246-
// info for an external crate involves decoding marks) and avoid incorrectly translated
247-
// default marks.
248-
if self.cdata().hygiene_data_import_info.borrow().is_some() && mark != 0 {
244+
if !self.cdata().hygiene_data_being_decoded.get() && mark != 0 {
249245
let imported_hygiene = self.cdata().imported_hygiene_data();
250246

251247
Ok(hygiene::Mark::from_u32(mark + imported_hygiene.mark_translation_offset))
@@ -259,11 +255,7 @@ impl<'a, 'tcx> SpecializedDecoder<SyntaxContext> for DecodeContext<'a, 'tcx> {
259255
fn specialized_decode(&mut self) -> Result<SyntaxContext, Self::Error> {
260256
let ctxt = u32::decode(self)?;
261257

262-
// We only perform translation if hygiene info is already available and if the
263-
// syntax context actually needs translation. That way we avoid loops (as obtaining
264-
// hygiene info for an external crate involves decoding syntax contexts) and avoid
265-
// incorrectly translated default contexts.
266-
if self.cdata().hygiene_data_import_info.borrow().is_some() && ctxt != 0 {
258+
if !self.cdata().hygiene_data_being_decoded.get() && ctxt != 0 {
267259
let imported_hygiene = self.cdata().imported_hygiene_data();
268260

269261
Ok(SyntaxContext::from_u32(ctxt + imported_hygiene.ctxt_translation_offset))
@@ -1270,11 +1262,15 @@ impl<'a, 'tcx> CrateMetadata {
12701262
}
12711263
}
12721264

1265+
self.hygiene_data_being_decoded.set(true);
1266+
12731267
let external_hygiene_data = self.root.hygiene_data.decode(self);
12741268

12751269
// This shouldn't borrow twice, but there is no way to downgrade RefMut to Ref.
12761270
*self.hygiene_data_import_info.borrow_mut() =
12771271
Some(hygiene::extend_hygiene_data(external_hygiene_data));
1278-
Ref::map(self.hygiene_data_import_info.borrow(), |d| d.as_ref().unwrap())
1272+
self.hygiene_data_being_decoded.set(false);
1273+
1274+
Ref::map(self.hygiene_data_import_info.borrow(), |d| d.as_ref().unwrap());
12791275
}
12801276
}

0 commit comments

Comments
 (0)