Skip to content

Commit 35d2f64

Browse files
committed
rustc_metadata: parametrize schema::CrateRoot by 'tcx.
1 parent f51e6c7 commit 35d2f64

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 {
@@ -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;

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
@@ -245,12 +245,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
245245

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

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

256251
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
{
@@ -1122,10 +1122,7 @@ impl<'a, 'tcx> CrateMetadata {
11221122
// link those in so we skip those crates.
11231123
vec![]
11241124
} else {
1125-
let lazy_seq: LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)> =
1126-
LazySeq::with_position_and_length(self.root.exported_symbols.position,
1127-
self.root.exported_symbols.len);
1128-
lazy_seq.decode((self, tcx)).collect()
1125+
self.root.exported_symbols.decode((self, tcx)).collect()
11291126
}
11301127
}
11311128

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

@@ -74,24 +75,26 @@ 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-
positions: [Vec<u8>; 2]
78+
pub struct Index<'tcx> {
79+
positions: [Vec<u8>; 2],
80+
_marker: PhantomData<&'tcx ()>,
7981
}
8082

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

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

94-
pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'_>>) {
97+
pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'tcx>>) {
9598
assert!(entry.position < (u32::MAX as usize));
9699
let position = entry.position as u32;
97100
let space_index = item.address_space().index();
@@ -107,7 +110,7 @@ impl Index {
107110
position.write_to_bytes_at(positions, array_index)
108111
}
109112

110-
pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Index> {
113+
pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Self> {
111114
let pos = buf.position();
112115

113116
// First we write the length of the lower range ...
@@ -121,7 +124,7 @@ impl Index {
121124
}
122125
}
123126

124-
impl<'tcx> LazySeq<Index> {
127+
impl LazySeq<Index<'tcx>> {
125128
/// Given the metadata, extract out the offset of a particular
126129
/// DefIndex (if any).
127130
#[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)