Skip to content

Commit 99dccc5

Browse files
committed
rustc_metadata: parametrize schema::CrateRoot by 'tcx.
1 parent f1079b2 commit 99dccc5

File tree

9 files changed

+37
-47
lines changed

9 files changed

+37
-47
lines changed

src/librustc_metadata/creader.rs

Lines changed: 3 additions & 3 deletions
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 {
@@ -467,7 +467,7 @@ impl<'a> CrateLoader<'a> {
467467
// Go through the crate metadata and load any crates that it references
468468
fn resolve_crate_deps(&mut self,
469469
root: &Option<CratePaths>,
470-
crate_root: &CrateRoot,
470+
crate_root: &CrateRoot<'_>,
471471
metadata: &MetadataBlob,
472472
krate: CrateNum,
473473
span: Span,
@@ -573,7 +573,7 @@ impl<'a> CrateLoader<'a> {
573573
/// implemented as dynamic libraries, but we have a possible future where
574574
/// custom derive (and other macro-1.1 style features) are implemented via
575575
/// executables and custom IPC.
576-
fn load_derive_macros(&mut self, root: &CrateRoot, dylib: Option<PathBuf>, span: Span)
576+
fn load_derive_macros(&mut self, root: &CrateRoot<'_>, dylib: Option<PathBuf>, span: Span)
577577
-> Vec<(ast::Name, Lrc<SyntaxExtension>)> {
578578
use std::{env, mem};
579579
use crate::dynamic_lib::DynamicLibrary;

src/librustc_metadata/cstore.rs

Lines changed: 5 additions & 1 deletion
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

src/librustc_metadata/cstore_impl.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
244244

245245
used_crate_source => { Lrc::new(cdata.source.clone()) }
246246

247-
exported_symbols => {
248-
let cnum = cdata.cnum;
249-
assert!(cnum != LOCAL_CRATE);
250-
251-
Arc::new(cdata.exported_symbols(tcx))
252-
}
247+
exported_symbols => { Arc::new(cdata.exported_symbols(tcx)) }
253248
}
254249

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

src/librustc_metadata/decoder.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ for DecodeContext<'a, 'tcx> {
366366

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

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

378-
pub fn get_root(&self) -> CrateRoot {
378+
pub fn get_root(&self) -> CrateRoot<'tcx> {
379379
let slice = self.raw_bytes();
380380
let offset = METADATA_HEADER.len();
381381
let pos = (((slice[offset + 0] as u32) << 24) | ((slice[offset + 1] as u32) << 16) |
@@ -445,7 +445,7 @@ impl<'tcx> EntryKind<'tcx> {
445445
/// |- proc macro #0 (DefIndex 1:N)
446446
/// |- proc macro #1 (DefIndex 1:N+1)
447447
/// \- ...
448-
crate fn proc_macro_def_path_table(crate_root: &CrateRoot,
448+
crate fn proc_macro_def_path_table(crate_root: &CrateRoot<'_>,
449449
proc_macros: &[(ast::Name, Lrc<SyntaxExtension>)])
450450
-> DefPathTable
451451
{
@@ -1111,10 +1111,7 @@ impl<'a, 'tcx> CrateMetadata {
11111111
// link those in so we skip those crates.
11121112
vec![]
11131113
} else {
1114-
let lazy_seq: LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)> =
1115-
LazySeq::with_position_and_length(self.root.exported_symbols.position,
1116-
self.root.exported_symbols.len);
1117-
lazy_seq.decode((self, tcx)).collect()
1114+
self.root.exported_symbols.decode((self, tcx)).collect()
11181115
}
11191116
}
11201117

src/librustc_metadata/encoder.rs

Lines changed: 6 additions & 11 deletions
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, ());
@@ -1590,13 +1590,13 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
15901590
// symbol associated with them (they weren't translated) or if they're an FFI
15911591
// definition (as that's not defined in this crate).
15921592
fn encode_exported_symbols(&mut self,
1593-
exported_symbols: &[(ExportedSymbol<'_>, SymbolExportLevel)])
1594-
-> EncodedExportedSymbols {
1593+
exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportLevel)])
1594+
-> LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)> {
15951595
// The metadata symbol name is special. It should not show up in
15961596
// downstream crates.
15971597
let metadata_symbol_name = SymbolName::new(&metadata_symbol_name(self.tcx));
15981598

1599-
let lazy_seq = self.lazy_seq(exported_symbols
1599+
self.lazy_seq(exported_symbols
16001600
.iter()
16011601
.filter(|&&(ref exported_symbol, _)| {
16021602
match *exported_symbol {
@@ -1606,12 +1606,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
16061606
_ => true,
16071607
}
16081608
})
1609-
.cloned());
1610-
1611-
EncodedExportedSymbols {
1612-
len: lazy_seq.len,
1613-
position: lazy_seq.position,
1614-
}
1609+
.cloned())
16151610
}
16161611

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

src/librustc_metadata/index.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::schema::*;
22

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

@@ -12,24 +13,26 @@ use log::debug;
1213
/// `u32::MAX`. Whenever an index is visited, we fill in the
1314
/// appropriate spot by calling `record_position`. We should never
1415
/// visit the same index twice.
15-
pub struct Index {
16-
positions: [Vec<u8>; 2]
16+
pub struct Index<'tcx> {
17+
positions: [Vec<u8>; 2],
18+
_marker: PhantomData<&'tcx ()>,
1719
}
1820

19-
impl Index {
20-
pub fn new((max_index_lo, max_index_hi): (usize, usize)) -> Index {
21+
impl Index<'tcx> {
22+
pub fn new((max_index_lo, max_index_hi): (usize, usize)) -> Self {
2123
Index {
2224
positions: [vec![0xff; max_index_lo * 4],
2325
vec![0xff; max_index_hi * 4]],
26+
_marker: PhantomData,
2427
}
2528
}
2629

27-
pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry<'_>>) {
30+
pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry<'tcx>>) {
2831
assert!(def_id.is_local());
2932
self.record_index(def_id.index, entry);
3033
}
3134

32-
pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'_>>) {
35+
pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'tcx>>) {
3336
assert!(entry.position < (u32::MAX as usize));
3437
let position = entry.position as u32;
3538
let space_index = item.address_space().index();
@@ -45,7 +48,7 @@ impl Index {
4548
write_le_u32(destination, position);
4649
}
4750

48-
pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Index> {
51+
pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Self> {
4952
let pos = buf.position();
5053

5154
// First we write the length of the lower range ...
@@ -59,7 +62,7 @@ impl Index {
5962
}
6063
}
6164

62-
impl<'tcx> LazySeq<Index> {
65+
impl LazySeq<Index<'tcx>> {
6366
/// Given the metadata, extract out the offset of a particular
6467
/// DefIndex (if any).
6568
#[inline(never)]

src/librustc_metadata/index_builder.rs

Lines changed: 2 additions & 2 deletions
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
}

src/librustc_metadata/lib.rs

Lines changed: 1 addition & 0 deletions
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)]

src/librustc_metadata/schema.rs

Lines changed: 4 additions & 9 deletions
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)