Skip to content

Commit c990907

Browse files
committed
rustc_metadata: parametrize schema::CrateRoot by 'tcx.
1 parent 1cc822c commit c990907

File tree

9 files changed

+36
-46
lines changed

9 files changed

+36
-46
lines changed

Diff for: src/librustc_metadata/creader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a> CrateLoader<'a> {
162162

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

Diff for: src/librustc_metadata/cstore.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ pub struct CrateMetadata {
6464
/// Used for decoding interpret::AllocIds in a cached & thread-safe manner.
6565
pub alloc_decoding_state: AllocDecodingState,
6666

67-
pub root: schema::CrateRoot,
67+
// NOTE(eddyb) we pass `'static` to a `'tcx` parameter because this
68+
// lifetime is only used behind `Lazy` / `LazySeq`, and therefore
69+
// acts like an universal (`for<'tcx>`), that is paired up with
70+
// whichever `TyCtxt` is being used to decode those values.
71+
pub root: schema::CrateRoot<'static>,
6872

6973
/// For each public item in this crate, we encode a key. When the
7074
/// crate is loaded, we read all the keys and put them in this

Diff for: src/librustc_metadata/cstore_impl.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
246246

247247
used_crate_source => { Lrc::new(cdata.source.clone()) }
248248

249-
exported_symbols => {
250-
let cnum = cdata.cnum;
251-
assert!(cnum != LOCAL_CRATE);
252-
253-
Arc::new(cdata.exported_symbols(tcx))
254-
}
249+
exported_symbols => { Arc::new(cdata.exported_symbols(tcx)) }
255250
}
256251

257252
pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {

Diff for: src/librustc_metadata/decoder.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ for DecodeContext<'a, 'tcx> {
365365

366366
implement_ty_decoder!( DecodeContext<'a, 'tcx> );
367367

368-
impl<'a, 'tcx> MetadataBlob {
368+
impl<'tcx> MetadataBlob {
369369
pub fn is_compatible(&self) -> bool {
370370
self.raw_bytes().starts_with(METADATA_HEADER)
371371
}
@@ -374,7 +374,7 @@ impl<'a, 'tcx> MetadataBlob {
374374
Lazy::with_position(METADATA_HEADER.len() + 4).decode(self)
375375
}
376376

377-
pub fn get_root(&self) -> CrateRoot {
377+
pub fn get_root(&self) -> CrateRoot<'tcx> {
378378
let slice = self.raw_bytes();
379379
let offset = METADATA_HEADER.len();
380380
let pos = (((slice[offset + 0] as u32) << 24) | ((slice[offset + 1] as u32) << 16) |
@@ -444,7 +444,7 @@ impl<'tcx> EntryKind<'tcx> {
444444
/// |- proc macro #0 (DefIndex 1:N)
445445
/// |- proc macro #1 (DefIndex 1:N+1)
446446
/// \- ...
447-
crate fn proc_macro_def_path_table(crate_root: &CrateRoot,
447+
crate fn proc_macro_def_path_table(crate_root: &CrateRoot<'_>,
448448
proc_macros: &[(ast::Name, Lrc<SyntaxExtension>)])
449449
-> DefPathTable
450450
{
@@ -1126,10 +1126,7 @@ impl<'a, 'tcx> CrateMetadata {
11261126
// link those in so we skip those crates.
11271127
vec![]
11281128
} else {
1129-
let lazy_seq: LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)> =
1130-
LazySeq::with_position_and_length(self.root.exported_symbols.position,
1131-
self.root.exported_symbols.len);
1132-
lazy_seq.decode((self, tcx)).collect()
1129+
self.root.exported_symbols.decode((self, tcx)).collect()
11331130
}
11341131
}
11351132

Diff for: src/librustc_metadata/encoder.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
309309
op(&mut IsolatedEncoder::new(self), data)
310310
}
311311

312-
fn encode_info_for_items(&mut self) -> Index {
312+
fn encode_info_for_items(&mut self) -> Index<'tcx> {
313313
let krate = self.tcx.hir().krate();
314314
let mut index = IndexBuilder::new(self);
315315
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public };
@@ -371,7 +371,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
371371
self.lazy_seq_ref(adapted.iter().map(|rc| &**rc))
372372
}
373373

374-
fn encode_crate_root(&mut self) -> Lazy<CrateRoot> {
374+
fn encode_crate_root(&mut self) -> Lazy<CrateRoot<'tcx>> {
375375
let mut i = self.position();
376376

377377
let crate_deps = self.tracked(IsolatedEncoder::encode_crate_deps, ());
@@ -1595,13 +1595,13 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
15951595
// symbol associated with them (they weren't translated) or if they're an FFI
15961596
// definition (as that's not defined in this crate).
15971597
fn encode_exported_symbols(&mut self,
1598-
exported_symbols: &[(ExportedSymbol<'_>, SymbolExportLevel)])
1599-
-> EncodedExportedSymbols {
1598+
exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportLevel)])
1599+
-> LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)> {
16001600
// The metadata symbol name is special. It should not show up in
16011601
// downstream crates.
16021602
let metadata_symbol_name = SymbolName::new(&metadata_symbol_name(self.tcx));
16031603

1604-
let lazy_seq = self.lazy_seq(exported_symbols
1604+
self.lazy_seq(exported_symbols
16051605
.iter()
16061606
.filter(|&&(ref exported_symbol, _)| {
16071607
match *exported_symbol {
@@ -1611,12 +1611,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
16111611
_ => true,
16121612
}
16131613
})
1614-
.cloned());
1615-
1616-
EncodedExportedSymbols {
1617-
len: lazy_seq.len,
1618-
position: lazy_seq.position,
1619-
}
1614+
.cloned())
16201615
}
16211616

16221617
fn encode_dylib_dependency_formats(&mut self, _: ()) -> LazySeq<Option<LinkagePreference>> {

Diff for: src/librustc_metadata/index.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::schema::*;
22

33
use rustc::hir::def_id::{DefId, DefIndex};
44
use rustc_serialize::opaque::Encoder;
5+
use std::marker::PhantomData;
56
use std::u32;
67
use log::debug;
78

@@ -74,23 +75,25 @@ impl FixedSizeEncoding for u32 {
7475
/// `u32::MAX`. Whenever an index is visited, we fill in the
7576
/// appropriate spot by calling `record_position`. We should never
7677
/// visit the same index twice.
77-
pub struct Index {
78+
pub struct Index<'tcx> {
7879
positions: Vec<u8>,
80+
_marker: PhantomData<&'tcx ()>,
7981
}
8082

81-
impl Index {
82-
pub fn new(max_index: usize) -> Index {
83+
impl Index<'tcx> {
84+
pub fn new(max_index: usize) -> Self {
8385
Index {
8486
positions: vec![0xff; max_index * 4],
87+
_marker: PhantomData,
8588
}
8689
}
8790

88-
pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry<'_>>) {
91+
pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry<'tcx>>) {
8992
assert!(def_id.is_local());
9093
self.record_index(def_id.index, entry);
9194
}
9295

93-
pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'_>>) {
96+
pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'tcx>>) {
9497
assert!(entry.position < (u32::MAX as usize));
9598
let position = entry.position as u32;
9699
let array_index = item.index();
@@ -105,7 +108,7 @@ impl Index {
105108
position.write_to_bytes_at(positions, array_index)
106109
}
107110

108-
pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Index> {
111+
pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Self> {
109112
let pos = buf.position();
110113

111114
// First we write the length of the lower range ...
@@ -116,7 +119,7 @@ impl Index {
116119
}
117120
}
118121

119-
impl<'tcx> LazySeq<Index> {
122+
impl LazySeq<Index<'tcx>> {
120123
/// Given the metadata, extract out the offset of a particular
121124
/// DefIndex (if any).
122125
#[inline(never)]

Diff for: src/librustc_metadata/index_builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use std::ops::{Deref, DerefMut};
6060
/// Builder that can encode new items, adding them into the index.
6161
/// Item encoding cannot be nested.
6262
pub struct IndexBuilder<'a, 'b: 'a, 'tcx: 'b> {
63-
items: Index,
63+
items: Index<'tcx>,
6464
pub ecx: &'a mut EncodeContext<'b, 'tcx>,
6565
}
6666

@@ -123,7 +123,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
123123
})
124124
}
125125

126-
pub fn into_items(self) -> Index {
126+
pub fn into_items(self) -> Index<'tcx> {
127127
self.items
128128
}
129129
}

Diff for: src/librustc_metadata/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![feature(box_patterns)]
44
#![feature(drain_filter)]
5+
#![feature(in_band_lifetimes)]
56
#![feature(libc)]
67
#![feature(nll)]
78
#![feature(proc_macro_internals)]

Diff for: src/librustc_metadata/schema.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc::hir;
44
use rustc::hir::def::{self, CtorKind};
55
use rustc::hir::def_id::{DefIndex, DefId, CrateNum};
66
use rustc::ich::StableHashingContext;
7+
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
78
use rustc::middle::cstore::{DepKind, LinkagePreference, NativeLibrary, ForeignModule};
89
use rustc::middle::lang_items;
910
use rustc::mir;
@@ -174,7 +175,7 @@ pub enum LazyState {
174175
}
175176

176177
#[derive(RustcEncodable, RustcDecodable)]
177-
pub struct CrateRoot {
178+
pub struct CrateRoot<'tcx> {
178179
pub name: Symbol,
179180
pub triple: TargetTriple,
180181
pub extra_filename: String,
@@ -199,10 +200,10 @@ pub struct CrateRoot {
199200
pub source_map: LazySeq<syntax_pos::SourceFile>,
200201
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
201202
pub impls: LazySeq<TraitImpls>,
202-
pub exported_symbols: EncodedExportedSymbols,
203+
pub exported_symbols: LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)>,
203204
pub interpret_alloc_index: LazySeq<u32>,
204205

205-
pub index: LazySeq<index::Index>,
206+
pub index: LazySeq<index::Index<'tcx>>,
206207

207208
pub compiler_builtins: bool,
208209
pub needs_allocator: bool,
@@ -577,9 +578,3 @@ impl_stable_hash_for!(struct GeneratorData<'tcx> { layout });
577578
// Tags used for encoding Spans:
578579
pub const TAG_VALID_SPAN: u8 = 0;
579580
pub const TAG_INVALID_SPAN: u8 = 1;
580-
581-
#[derive(RustcEncodable, RustcDecodable)]
582-
pub struct EncodedExportedSymbols {
583-
pub position: usize,
584-
pub len: usize,
585-
}

0 commit comments

Comments
 (0)