Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expansion info to crate metadata #43847

Closed
wants to merge 13 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed the on-demand decoding mechanism for hygiene data.
  • Loading branch information
ibabushkin committed Oct 7, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 214fb564e0fb917580056bdc5d6a1b55acd4cd5f
1 change: 1 addition & 0 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
@@ -294,6 +294,7 @@ impl<'a> CrateLoader<'a> {
// after we were able to deserialize its contents.
dllimport_foreign_items: FxHashSet(),
hygiene_data_import_info: RefCell::new(None),
hygiene_data_being_decoded: Cell::new(false),
};

let dllimports: FxHashSet<_> = cmeta
1 change: 1 addition & 0 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
@@ -89,6 +89,7 @@ pub struct CrateMetadata {
pub dllimport_foreign_items: FxHashSet<DefIndex>,

pub hygiene_data_import_info: RefCell<Option<hygiene::ImportedHygieneData>>,
pub hygiene_data_being_decoded: Cell<bool>,
}

pub struct CStore {
18 changes: 7 additions & 11 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
@@ -241,11 +241,7 @@ impl<'a, 'tcx> SpecializedDecoder<hygiene::Mark> for DecodeContext<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<hygiene::Mark, Self::Error> {
let mark = u32::decode(self)?;

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

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

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

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

self.hygiene_data_being_decoded.set(true);

let external_hygiene_data = self.root.hygiene_data.decode(self);

// This shouldn't borrow twice, but there is no way to downgrade RefMut to Ref.
*self.hygiene_data_import_info.borrow_mut() =
Some(hygiene::extend_hygiene_data(external_hygiene_data));
Ref::map(self.hygiene_data_import_info.borrow(), |d| d.as_ref().unwrap())
self.hygiene_data_being_decoded.set(false);

Ref::map(self.hygiene_data_import_info.borrow(), |d| d.as_ref().unwrap());
}
}