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
Next Next commit
Implemented span expansion info encoding in metadata.
This change adds an encoded version of hygiene related datastructures to
the metadata of a crate. It is then decoded on-demand when spans and AST
items from a foreign crate are accessed. Some changes might still be
necessary to implement the correct behaviour, however.
  • Loading branch information
ibabushkin committed Oct 7, 2017

Verified

This commit was signed with the committer’s verified signature.
commit dad587bc7dc7099e3f4c7f04f149c23b9ea7ed84
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 53 files
+0 −1 .travis.yml
+0 −29 second-edition/dictionary.txt
+99 −111 second-edition/nostarch/chapter05.md
+360 −469 second-edition/nostarch/chapter08.md
+399 −413 second-edition/nostarch/chapter09.md
+764 −1,834 second-edition/nostarch/chapter15.md
+ second-edition/nostarch/odt/chapter05.docx
+ second-edition/nostarch/odt/chapter08.docx
+ second-edition/nostarch/odt/chapter09.docx
+22 −22 second-edition/src/appendix-02-operators.md
+1 −1 second-edition/src/ch01-02-hello-world.md
+12 −8 second-edition/src/ch03-02-data-types.md
+4 −4 second-edition/src/ch05-00-structs.md
+45 −57 second-edition/src/ch05-01-defining-structs.md
+30 −30 second-edition/src/ch05-02-example-structs.md
+17 −17 second-edition/src/ch05-03-method-syntax.md
+1 −1 second-edition/src/ch06-01-defining-an-enum.md
+1 −1 second-edition/src/ch06-02-match.md
+1 −1 second-edition/src/ch07-01-mod-and-the-filesystem.md
+9 −9 second-edition/src/ch08-00-common-collections.md
+103 −159 second-edition/src/ch08-01-vectors.md
+157 −192 second-edition/src/ch08-02-strings.md
+90 −117 second-edition/src/ch08-03-hash-maps.md
+13 −14 second-edition/src/ch09-00-error-handling.md
+69 −80 second-edition/src/ch09-01-unrecoverable-errors-with-panic.md
+119 −150 second-edition/src/ch09-02-recoverable-errors-with-result.md
+94 −94 second-edition/src/ch09-03-to-panic-or-not-to-panic.md
+3 −3 second-edition/src/ch10-02-traits.md
+1 −1 second-edition/src/ch10-03-lifetime-syntax.md
+6 −5 second-edition/src/ch11-01-writing-tests.md
+1 −1 second-edition/src/ch11-02-running-tests.md
+1 −1 second-edition/src/ch12-04-testing-the-librarys-functionality.md
+1 −1 second-edition/src/ch12-06-writing-to-stderr-instead-of-stdout.md
+1 −1 second-edition/src/ch13-02-iterators.md
+1 −1 second-edition/src/ch13-04-performance.md
+31 −87 second-edition/src/ch15-00-smart-pointers.md
+85 −233 second-edition/src/ch15-01-box.md
+143 −394 second-edition/src/ch15-02-deref.md
+88 −183 second-edition/src/ch15-03-drop.md
+89 −142 second-edition/src/ch15-04-rc.md
+161 −425 second-edition/src/ch15-05-interior-mutability.md
+185 −354 second-edition/src/ch15-06-reference-cycles.md
+4 −4 second-edition/src/ch16-02-message-passing.md
+2 −2 second-edition/src/ch16-03-shared-state.md
+1 −1 second-edition/src/ch19-02-advanced-lifetimes.md
+76 −253 second-edition/src/ch19-03-advanced-traits.md
+7 −7 second-edition/src/ch19-04-advanced-types.md
+2 −2 second-edition/src/ch19-05-advanced-functions-and-closures.md
+1 −1 second-edition/src/ch20-01-single-threaded.md
+1 −1 second-edition/src/ch20-05-sending-requests-via-channels.md
+1 −1 second-edition/src/ch20-06-graceful-shutdown-and-cleanup.md
+11 −56 second-edition/theme/index.hbs
+0 −1 second-edition/tools/docx-to-md.xsl
2 changes: 1 addition & 1 deletion src/doc/nomicon
2 changes: 1 addition & 1 deletion src/doc/reference
2 changes: 1 addition & 1 deletion src/libcompiler_builtins
2 changes: 1 addition & 1 deletion src/liblibc
Submodule liblibc updated 90 files
+5 −14 .travis.yml
+30 −222 Cargo.lock
+2 −2 Cargo.toml
+1 −1 README.md
+1 −1 appveyor.yml
+0 −13 ci/docker/aarch64-linux-android/Dockerfile
+2 −2 ci/docker/aarch64-unknown-linux-gnu/Dockerfile
+0 −13 ci/docker/arm-linux-androideabi/Dockerfile
+2 −2 ci/docker/arm-unknown-linux-gnueabihf/Dockerfile
+0 −20 ci/docker/asmjs-unknown-emscripten/Dockerfile
+0 −13 ci/docker/i686-linux-android/Dockerfile
+1 −1 ci/docker/i686-unknown-linux-gnu/Dockerfile
+2 −2 ci/docker/mips-unknown-linux-gnu/Dockerfile
+4 −4 ci/docker/mips-unknown-linux-musl/Dockerfile
+2 −2 ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile
+4 −4 ci/docker/mipsel-unknown-linux-musl/Dockerfile
+2 −2 ci/docker/powerpc-unknown-linux-gnu/Dockerfile
+2 −2 ci/docker/powerpc64-unknown-linux-gnu/Dockerfile
+0 −3 ci/docker/s390x-unknown-linux-gnu/Dockerfile
+0 −21 ci/docker/wasm32-unknown-emscripten/Dockerfile
+0 −11 ci/docker/wasm32-unknown-emscripten/node-wrapper.sh
+1 −5 ci/docker/x86_64-rumprun-netbsd/Dockerfile
+0 −54 ci/docker/x86_64-rumprun-netbsd/runtest.rs
+2 −2 ci/docker/x86_64-unknown-freebsd/Dockerfile
+1 −1 ci/docker/x86_64-unknown-linux-gnu/Dockerfile
+8 −0 ci/docker/x86_64-unknown-openbsd/Dockerfile
+0 −19 ci/emscripten-entry.sh
+0 −54 ci/emscripten.sh
+0 −1 ci/run-docker.sh
+124 −8 ci/run.sh
+0 −41 ci/runtest-android.rs
+1 −11 libc-test/Cargo.toml
+16 −0 libc-test/build-generated.rs
+17 −65 libc-test/build.rs
+16 −0 libc-test/generate-files/Cargo.toml
+19 −0 libc-test/run-generated-Cargo.toml
+9 −0 libc-test/src/main-generated.rs
+1 −1 libc-test/src/main.rs
+0 −7 libc-test/test/linux_fcntl.rs
+7 −16 src/lib.rs
+37 −0 src/macros.rs
+0 −31 src/redox.rs
+3 −328 src/unix/bsd/apple/mod.rs
+17 −242 src/unix/bsd/freebsdlike/dragonfly/mod.rs
+0 −2 src/unix/bsd/freebsdlike/freebsd/aarch64.rs
+17 −254 src/unix/bsd/freebsdlike/freebsd/mod.rs
+0 −2 src/unix/bsd/freebsdlike/freebsd/x86_64.rs
+2 −13 src/unix/bsd/freebsdlike/mod.rs
+12 −66 src/unix/bsd/mod.rs
+6 −15 src/unix/bsd/netbsdlike/mod.rs
+1 −87 src/unix/bsd/netbsdlike/netbsd/mod.rs
+0 −78 src/unix/bsd/netbsdlike/openbsdlike/mod.rs
+0 −1 src/unix/haiku/b32.rs
+0 −1 src/unix/haiku/b64.rs
+66 −145 src/unix/haiku/mod.rs
+45 −8 src/unix/mod.rs
+0 −58 src/unix/newlib/mod.rs
+0 −3 src/unix/notbsd/android/b32/arm.rs
+0 −29 src/unix/notbsd/android/b32/mod.rs
+0 −3 src/unix/notbsd/android/b64/aarch64.rs
+0 −30 src/unix/notbsd/android/b64/mod.rs
+3 −167 src/unix/notbsd/android/mod.rs
+0 −1,667 src/unix/notbsd/emscripten.rs
+1 −39 src/unix/notbsd/linux/mips/mips32.rs
+1 −34 src/unix/notbsd/linux/mips/mips64.rs
+7 −244 src/unix/notbsd/linux/mod.rs
+0 −33 src/unix/notbsd/linux/musl/b32/arm.rs
+348 −0 src/unix/notbsd/linux/musl/b32/asmjs.rs
+2 −39 src/unix/notbsd/linux/musl/b32/mips.rs
+5 −0 src/unix/notbsd/linux/musl/b32/mod.rs
+0 −31 src/unix/notbsd/linux/musl/b32/x86.rs
+0 −3 src/unix/notbsd/linux/musl/b64/aarch64.rs
+0 −30 src/unix/notbsd/linux/musl/b64/mod.rs
+0 −3 src/unix/notbsd/linux/musl/b64/powerpc64.rs
+18 −7 src/unix/notbsd/linux/musl/mod.rs
+0 −33 src/unix/notbsd/linux/other/b32/arm.rs
+0 −33 src/unix/notbsd/linux/other/b32/powerpc.rs
+0 −31 src/unix/notbsd/linux/other/b32/x86.rs
+0 −32 src/unix/notbsd/linux/other/b64/aarch64.rs
+0 −32 src/unix/notbsd/linux/other/b64/powerpc64.rs
+0 −30 src/unix/notbsd/linux/other/b64/sparc64.rs
+0 −30 src/unix/notbsd/linux/other/b64/x86_64.rs
+7 −0 src/unix/notbsd/linux/other/mod.rs
+7 −32 src/unix/notbsd/linux/s390x.rs
+135 −53 src/unix/notbsd/mod.rs
+20 −72 src/unix/solaris/mod.rs
+24 −135 src/unix/uclibc/mod.rs
+0 −46 src/unix/uclibc/x86_64/l4re.rs
+90 −86 src/unix/uclibc/x86_64/mod.rs
+1 −2 src/windows.rs
1 change: 1 addition & 0 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
@@ -293,6 +293,7 @@ impl<'a> CrateLoader<'a> {
// Initialize this with an empty set. The field is populated below
// after we were able to deserialize its contents.
dllimport_foreign_items: FxHashSet(),
hygiene_data_import_info: RefCell::new(None),
};

let dllimports: FxHashSet<_> = cmeta
4 changes: 3 additions & 1 deletion src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ use owning_ref::ErasedBoxRef;
use syntax::{ast, attr};
use syntax::ext::base::SyntaxExtension;
use syntax::symbol::Symbol;
use syntax_pos;
use syntax_pos::{self, hygiene};

pub use rustc::middle::cstore::{NativeLibrary, NativeLibraryKind, LinkagePreference};
pub use rustc::middle::cstore::NativeLibraryKind::*;
@@ -87,6 +87,8 @@ pub struct CrateMetadata {
pub proc_macros: Option<Vec<(ast::Name, Rc<SyntaxExtension>)>>,
// Foreign items imported from a dylib (Windows only)
pub dllimport_foreign_items: FxHashSet<DefIndex>,

pub hygiene_data_import_info: RefCell<Option<hygiene::ImportedHygieneData>>,
}

pub struct CStore {
50 changes: 47 additions & 3 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
@@ -45,7 +45,8 @@ use syntax::ast::{self, Ident};
use syntax::codemap;
use syntax::symbol::{InternedString, Symbol};
use syntax::ext::base::MacroKind;
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION};
use syntax_pos::{self, Span, SyntaxContext, BytePos, Pos, DUMMY_SP};
use syntax_pos::hygiene;

pub struct DecodeContext<'a, 'tcx: 'a> {
opaque: opaque::Decoder<'a>,
@@ -237,15 +238,42 @@ impl<'a, 'tcx> SpecializedDecoder<CrateNum> for DecodeContext<'a, 'tcx> {
}
}

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)?;
if self.cdata().hygiene_data_import_info.borrow().is_some() && mark != 0 {
let imported_hygiene = self.cdata().imported_hygiene_data();

Ok(hygiene::Mark::from_u32(mark + imported_hygiene.mark_translation_offset))
} else {
Ok(hygiene::Mark::from_u32(mark))
}
}
}

impl<'a, 'tcx> SpecializedDecoder<SyntaxContext> for DecodeContext<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<SyntaxContext, Self::Error> {
let ctxt = u32::decode(self)?;
if self.cdata().hygiene_data_import_info.borrow().is_some() && ctxt != 0 {
let imported_hygiene = self.cdata().imported_hygiene_data();

Ok(SyntaxContext::from_u32(ctxt + imported_hygiene.ctxt_translation_offset))
} else {
Ok(SyntaxContext::from_u32(ctxt))
}
}
}

impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<Span, Self::Error> {
let lo = BytePos::decode(self)?;
let hi = BytePos::decode(self)?;
let ctxt = SyntaxContext::decode(self)?;

let sess = if let Some(sess) = self.sess {
sess
} else {
return Ok(Span::new(lo, hi, NO_EXPANSION));
return Ok(Span { lo, hi, ctxt });
};

let (lo, hi) = if lo > hi {
@@ -292,7 +320,7 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
let lo = (lo - filemap.original_start_pos) + filemap.translated_filemap.start_pos;
let hi = (hi - filemap.original_start_pos) + filemap.translated_filemap.start_pos;

Ok(Span::new(lo, hi, NO_EXPANSION))
Ok(Span::new(lo, hi, ctxt))
}
}

@@ -1224,4 +1252,20 @@ impl<'a, 'tcx> CrateMetadata {
*self.codemap_import_info.borrow_mut() = imported_filemaps;
self.codemap_import_info.borrow()
}

pub fn imported_hygiene_data(&'a self) -> Ref<'a, hygiene::ImportedHygieneData> {
{
let hygiene_data = self.hygiene_data_import_info.borrow();
if hygiene_data.is_some() {
return Ref::map(hygiene_data, |d| d.as_ref().unwrap());
}
}

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())
}
}
14 changes: 12 additions & 2 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ use syntax::ast::{self, CRATE_NODE_ID};
use syntax::codemap::Spanned;
use syntax::attr;
use syntax::symbol::Symbol;
use syntax_pos;
use syntax_pos::{self, hygiene};

use rustc::hir::{self, PatKind};
use rustc::hir::itemlikevisit::ItemLikeVisitor;
@@ -323,6 +323,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.lazy_seq_ref(adapted.iter().map(|rc| &**rc))
}

fn encode_hygiene_data(&mut self) -> Lazy<hygiene::HygieneData> {
hygiene::HygieneData::safe_with(|data| self.lazy(data))
}

fn encode_crate_root(&mut self) -> Lazy<CrateRoot> {
let mut i = self.position();

@@ -367,6 +371,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let codemap = self.encode_codemap();
let codemap_bytes = self.position() - i;

// Encode hygiene data
i = self.position();
let hygiene_data = self.encode_hygiene_data();
let hygiene_data_bytes = self.position() - i;

// Encode DefPathTable
i = self.position();
let def_path_table = self.encode_def_path_table();
@@ -421,13 +430,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
} else {
None
},

crate_deps,
dylib_dependency_formats,
lang_items,
lang_items_missing,
native_libraries,
codemap,
hygiene_data,
def_path_table,
impls,
exported_symbols,
@@ -456,6 +465,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
println!(" codemap bytes: {}", codemap_bytes);
println!(" impl bytes: {}", impl_bytes);
println!(" exp. symbols bytes: {}", exported_symbols_bytes);
println!(" hygiene data bytes: {}", hygiene_data_bytes);
println!(" def-path table bytes: {}", def_path_table_bytes);
println!(" item bytes: {}", item_bytes);
println!(" index bytes: {}", index_bytes);
3 changes: 2 additions & 1 deletion src/librustc_metadata/schema.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ use rustc_back::PanicStrategy;
use rustc_serialize as serialize;
use syntax::{ast, attr};
use syntax::symbol::Symbol;
use syntax_pos::{self, Span};
use syntax_pos::{self, hygiene, Span};

use std::marker::PhantomData;
use std::mem;
@@ -204,6 +204,7 @@ pub struct CrateRoot {
pub lang_items_missing: LazySeq<lang_items::LangItem>,
pub native_libraries: LazySeq<NativeLibrary>,
pub codemap: LazySeq<syntax_pos::FileMap>,
pub hygiene_data: Lazy<hygiene::HygieneData>,
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
pub impls: LazySeq<TraitImpls>,
pub exported_symbols: LazySeq<DefIndex>,
Loading