1
Fork 0

rustc_metadata: parametrize schema::CrateRoot by 'tcx.

This commit is contained in:
Eduard-Mihai Burtescu 2019-04-11 10:22:02 +03:00
parent 1cc822c261
commit c99090761c
9 changed files with 36 additions and 46 deletions

View file

@ -162,7 +162,7 @@ impl<'a> CrateLoader<'a> {
fn verify_no_symbol_conflicts(&self, fn verify_no_symbol_conflicts(&self,
span: Span, span: Span,
root: &CrateRoot) { root: &CrateRoot<'_>) {
// Check for (potential) conflicts with the local crate // Check for (potential) conflicts with the local crate
if self.local_crate_name == root.name && if self.local_crate_name == root.name &&
self.sess.local_crate_disambiguator() == root.disambiguator { self.sess.local_crate_disambiguator() == root.disambiguator {
@ -476,7 +476,7 @@ impl<'a> CrateLoader<'a> {
// Go through the crate metadata and load any crates that it references // Go through the crate metadata and load any crates that it references
fn resolve_crate_deps(&mut self, fn resolve_crate_deps(&mut self,
root: &Option<CratePaths>, root: &Option<CratePaths>,
crate_root: &CrateRoot, crate_root: &CrateRoot<'_>,
metadata: &MetadataBlob, metadata: &MetadataBlob,
krate: CrateNum, krate: CrateNum,
span: Span, span: Span,
@ -582,7 +582,7 @@ impl<'a> CrateLoader<'a> {
/// implemented as dynamic libraries, but we have a possible future where /// implemented as dynamic libraries, but we have a possible future where
/// custom derive (and other macro-1.1 style features) are implemented via /// custom derive (and other macro-1.1 style features) are implemented via
/// executables and custom IPC. /// executables and custom IPC.
fn load_derive_macros(&mut self, root: &CrateRoot, dylib: Option<PathBuf>, span: Span) fn load_derive_macros(&mut self, root: &CrateRoot<'_>, dylib: Option<PathBuf>, span: Span)
-> Vec<(ast::Name, Lrc<SyntaxExtension>)> { -> Vec<(ast::Name, Lrc<SyntaxExtension>)> {
use std::{env, mem}; use std::{env, mem};
use crate::dynamic_lib::DynamicLibrary; use crate::dynamic_lib::DynamicLibrary;

View file

@ -64,7 +64,11 @@ pub struct CrateMetadata {
/// Used for decoding interpret::AllocIds in a cached & thread-safe manner. /// Used for decoding interpret::AllocIds in a cached & thread-safe manner.
pub alloc_decoding_state: AllocDecodingState, pub alloc_decoding_state: AllocDecodingState,
pub root: schema::CrateRoot, // NOTE(eddyb) we pass `'static` to a `'tcx` parameter because this
// lifetime is only used behind `Lazy` / `LazySeq`, and therefore
// acts like an universal (`for<'tcx>`), that is paired up with
// whichever `TyCtxt` is being used to decode those values.
pub root: schema::CrateRoot<'static>,
/// For each public item in this crate, we encode a key. When the /// For each public item in this crate, we encode a key. When the
/// crate is loaded, we read all the keys and put them in this /// crate is loaded, we read all the keys and put them in this

View file

@ -246,12 +246,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
used_crate_source => { Lrc::new(cdata.source.clone()) } used_crate_source => { Lrc::new(cdata.source.clone()) }
exported_symbols => { exported_symbols => { Arc::new(cdata.exported_symbols(tcx)) }
let cnum = cdata.cnum;
assert!(cnum != LOCAL_CRATE);
Arc::new(cdata.exported_symbols(tcx))
}
} }
pub fn provide<'tcx>(providers: &mut Providers<'tcx>) { pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {

View file

@ -365,7 +365,7 @@ for DecodeContext<'a, 'tcx> {
implement_ty_decoder!( DecodeContext<'a, 'tcx> ); implement_ty_decoder!( DecodeContext<'a, 'tcx> );
impl<'a, 'tcx> MetadataBlob { impl<'tcx> MetadataBlob {
pub fn is_compatible(&self) -> bool { pub fn is_compatible(&self) -> bool {
self.raw_bytes().starts_with(METADATA_HEADER) self.raw_bytes().starts_with(METADATA_HEADER)
} }
@ -374,7 +374,7 @@ impl<'a, 'tcx> MetadataBlob {
Lazy::with_position(METADATA_HEADER.len() + 4).decode(self) Lazy::with_position(METADATA_HEADER.len() + 4).decode(self)
} }
pub fn get_root(&self) -> CrateRoot { pub fn get_root(&self) -> CrateRoot<'tcx> {
let slice = self.raw_bytes(); let slice = self.raw_bytes();
let offset = METADATA_HEADER.len(); let offset = METADATA_HEADER.len();
let pos = (((slice[offset + 0] as u32) << 24) | ((slice[offset + 1] as u32) << 16) | let pos = (((slice[offset + 0] as u32) << 24) | ((slice[offset + 1] as u32) << 16) |
@ -444,7 +444,7 @@ impl<'tcx> EntryKind<'tcx> {
/// |- proc macro #0 (DefIndex 1:N) /// |- proc macro #0 (DefIndex 1:N)
/// |- proc macro #1 (DefIndex 1:N+1) /// |- proc macro #1 (DefIndex 1:N+1)
/// \- ... /// \- ...
crate fn proc_macro_def_path_table(crate_root: &CrateRoot, crate fn proc_macro_def_path_table(crate_root: &CrateRoot<'_>,
proc_macros: &[(ast::Name, Lrc<SyntaxExtension>)]) proc_macros: &[(ast::Name, Lrc<SyntaxExtension>)])
-> DefPathTable -> DefPathTable
{ {
@ -1126,10 +1126,7 @@ impl<'a, 'tcx> CrateMetadata {
// link those in so we skip those crates. // link those in so we skip those crates.
vec![] vec![]
} else { } else {
let lazy_seq: LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)> = self.root.exported_symbols.decode((self, tcx)).collect()
LazySeq::with_position_and_length(self.root.exported_symbols.position,
self.root.exported_symbols.len);
lazy_seq.decode((self, tcx)).collect()
} }
} }

View file

@ -309,7 +309,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
op(&mut IsolatedEncoder::new(self), data) op(&mut IsolatedEncoder::new(self), data)
} }
fn encode_info_for_items(&mut self) -> Index { fn encode_info_for_items(&mut self) -> Index<'tcx> {
let krate = self.tcx.hir().krate(); let krate = self.tcx.hir().krate();
let mut index = IndexBuilder::new(self); let mut index = IndexBuilder::new(self);
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public }; let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public };
@ -371,7 +371,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.lazy_seq_ref(adapted.iter().map(|rc| &**rc)) self.lazy_seq_ref(adapted.iter().map(|rc| &**rc))
} }
fn encode_crate_root(&mut self) -> Lazy<CrateRoot> { fn encode_crate_root(&mut self) -> Lazy<CrateRoot<'tcx>> {
let mut i = self.position(); let mut i = self.position();
let crate_deps = self.tracked(IsolatedEncoder::encode_crate_deps, ()); let crate_deps = self.tracked(IsolatedEncoder::encode_crate_deps, ());
@ -1595,13 +1595,13 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
// symbol associated with them (they weren't translated) or if they're an FFI // symbol associated with them (they weren't translated) or if they're an FFI
// definition (as that's not defined in this crate). // definition (as that's not defined in this crate).
fn encode_exported_symbols(&mut self, fn encode_exported_symbols(&mut self,
exported_symbols: &[(ExportedSymbol<'_>, SymbolExportLevel)]) exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportLevel)])
-> EncodedExportedSymbols { -> LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)> {
// The metadata symbol name is special. It should not show up in // The metadata symbol name is special. It should not show up in
// downstream crates. // downstream crates.
let metadata_symbol_name = SymbolName::new(&metadata_symbol_name(self.tcx)); let metadata_symbol_name = SymbolName::new(&metadata_symbol_name(self.tcx));
let lazy_seq = self.lazy_seq(exported_symbols self.lazy_seq(exported_symbols
.iter() .iter()
.filter(|&&(ref exported_symbol, _)| { .filter(|&&(ref exported_symbol, _)| {
match *exported_symbol { match *exported_symbol {
@ -1611,12 +1611,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
_ => true, _ => true,
} }
}) })
.cloned()); .cloned())
EncodedExportedSymbols {
len: lazy_seq.len,
position: lazy_seq.position,
}
} }
fn encode_dylib_dependency_formats(&mut self, _: ()) -> LazySeq<Option<LinkagePreference>> { fn encode_dylib_dependency_formats(&mut self, _: ()) -> LazySeq<Option<LinkagePreference>> {

View file

@ -2,6 +2,7 @@ use crate::schema::*;
use rustc::hir::def_id::{DefId, DefIndex}; use rustc::hir::def_id::{DefId, DefIndex};
use rustc_serialize::opaque::Encoder; use rustc_serialize::opaque::Encoder;
use std::marker::PhantomData;
use std::u32; use std::u32;
use log::debug; use log::debug;
@ -74,23 +75,25 @@ impl FixedSizeEncoding for u32 {
/// `u32::MAX`. Whenever an index is visited, we fill in the /// `u32::MAX`. Whenever an index is visited, we fill in the
/// appropriate spot by calling `record_position`. We should never /// appropriate spot by calling `record_position`. We should never
/// visit the same index twice. /// visit the same index twice.
pub struct Index { pub struct Index<'tcx> {
positions: Vec<u8>, positions: Vec<u8>,
_marker: PhantomData<&'tcx ()>,
} }
impl Index { impl Index<'tcx> {
pub fn new(max_index: usize) -> Index { pub fn new(max_index: usize) -> Self {
Index { Index {
positions: vec![0xff; max_index * 4], positions: vec![0xff; max_index * 4],
_marker: PhantomData,
} }
} }
pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry<'_>>) { pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry<'tcx>>) {
assert!(def_id.is_local()); assert!(def_id.is_local());
self.record_index(def_id.index, entry); self.record_index(def_id.index, entry);
} }
pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'_>>) { pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'tcx>>) {
assert!(entry.position < (u32::MAX as usize)); assert!(entry.position < (u32::MAX as usize));
let position = entry.position as u32; let position = entry.position as u32;
let array_index = item.index(); let array_index = item.index();
@ -105,7 +108,7 @@ impl Index {
position.write_to_bytes_at(positions, array_index) position.write_to_bytes_at(positions, array_index)
} }
pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Index> { pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Self> {
let pos = buf.position(); let pos = buf.position();
// First we write the length of the lower range ... // First we write the length of the lower range ...
@ -116,7 +119,7 @@ impl Index {
} }
} }
impl<'tcx> LazySeq<Index> { impl LazySeq<Index<'tcx>> {
/// Given the metadata, extract out the offset of a particular /// Given the metadata, extract out the offset of a particular
/// DefIndex (if any). /// DefIndex (if any).
#[inline(never)] #[inline(never)]

View file

@ -60,7 +60,7 @@ use std::ops::{Deref, DerefMut};
/// Builder that can encode new items, adding them into the index. /// Builder that can encode new items, adding them into the index.
/// Item encoding cannot be nested. /// Item encoding cannot be nested.
pub struct IndexBuilder<'a, 'b: 'a, 'tcx: 'b> { pub struct IndexBuilder<'a, 'b: 'a, 'tcx: 'b> {
items: Index, items: Index<'tcx>,
pub ecx: &'a mut EncodeContext<'b, 'tcx>, pub ecx: &'a mut EncodeContext<'b, 'tcx>,
} }
@ -123,7 +123,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
}) })
} }
pub fn into_items(self) -> Index { pub fn into_items(self) -> Index<'tcx> {
self.items self.items
} }
} }

View file

@ -2,6 +2,7 @@
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(drain_filter)] #![feature(drain_filter)]
#![feature(in_band_lifetimes)]
#![feature(libc)] #![feature(libc)]
#![feature(nll)] #![feature(nll)]
#![feature(proc_macro_internals)] #![feature(proc_macro_internals)]

View file

@ -4,6 +4,7 @@ use rustc::hir;
use rustc::hir::def::{self, CtorKind}; use rustc::hir::def::{self, CtorKind};
use rustc::hir::def_id::{DefIndex, DefId, CrateNum}; use rustc::hir::def_id::{DefIndex, DefId, CrateNum};
use rustc::ich::StableHashingContext; use rustc::ich::StableHashingContext;
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
use rustc::middle::cstore::{DepKind, LinkagePreference, NativeLibrary, ForeignModule}; use rustc::middle::cstore::{DepKind, LinkagePreference, NativeLibrary, ForeignModule};
use rustc::middle::lang_items; use rustc::middle::lang_items;
use rustc::mir; use rustc::mir;
@ -174,7 +175,7 @@ pub enum LazyState {
} }
#[derive(RustcEncodable, RustcDecodable)] #[derive(RustcEncodable, RustcDecodable)]
pub struct CrateRoot { pub struct CrateRoot<'tcx> {
pub name: Symbol, pub name: Symbol,
pub triple: TargetTriple, pub triple: TargetTriple,
pub extra_filename: String, pub extra_filename: String,
@ -199,10 +200,10 @@ pub struct CrateRoot {
pub source_map: LazySeq<syntax_pos::SourceFile>, pub source_map: LazySeq<syntax_pos::SourceFile>,
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>, pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
pub impls: LazySeq<TraitImpls>, pub impls: LazySeq<TraitImpls>,
pub exported_symbols: EncodedExportedSymbols, pub exported_symbols: LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)>,
pub interpret_alloc_index: LazySeq<u32>, pub interpret_alloc_index: LazySeq<u32>,
pub index: LazySeq<index::Index>, pub index: LazySeq<index::Index<'tcx>>,
pub compiler_builtins: bool, pub compiler_builtins: bool,
pub needs_allocator: bool, pub needs_allocator: bool,
@ -577,9 +578,3 @@ impl_stable_hash_for!(struct GeneratorData<'tcx> { layout });
// Tags used for encoding Spans: // Tags used for encoding Spans:
pub const TAG_VALID_SPAN: u8 = 0; pub const TAG_VALID_SPAN: u8 = 0;
pub const TAG_INVALID_SPAN: u8 = 1; pub const TAG_INVALID_SPAN: u8 = 1;
#[derive(RustcEncodable, RustcDecodable)]
pub struct EncodedExportedSymbols {
pub position: usize,
pub len: usize,
}