Skip to content

Commit 6732c7b

Browse files
Allow for representing exported monomorphizations in crate metadata.
1 parent e14df76 commit 6732c7b

File tree

8 files changed

+89
-39
lines changed

8 files changed

+89
-39
lines changed

src/librustc/middle/exported_symbols.rs

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
// except according to those terms.
1010

1111
use hir::def_id::{DefId, LOCAL_CRATE};
12+
use ich::StableHashingContext;
13+
use rustc_data_structures::stable_hasher::{StableHasher, HashStable,
14+
StableHasherResult};
1215
use std::cmp;
16+
use std::mem;
1317
use ty;
18+
use ty::subst::Substs;
1419

1520
/// The SymbolExportLevel of a symbols specifies from which kinds of crates
1621
/// the symbol will be exported. `C` symbols will be exported from any
@@ -40,56 +45,89 @@ impl SymbolExportLevel {
4045
}
4146

4247
#[derive(Eq, PartialEq, Debug, Copy, Clone, RustcEncodable, RustcDecodable)]
43-
pub enum ExportedSymbol {
48+
pub enum ExportedSymbol<'tcx> {
4449
NonGeneric(DefId),
50+
Generic(DefId, &'tcx Substs<'tcx>),
4551
NoDefId(ty::SymbolName),
4652
}
4753

48-
impl ExportedSymbol {
49-
pub fn symbol_name(&self, tcx: ty::TyCtxt) -> ty::SymbolName {
54+
impl<'tcx> ExportedSymbol<'tcx> {
55+
pub fn symbol_name(&self,
56+
tcx: ty::TyCtxt<'_, 'tcx, '_>)
57+
-> ty::SymbolName {
5058
match *self {
5159
ExportedSymbol::NonGeneric(def_id) => {
5260
tcx.symbol_name(ty::Instance::mono(tcx, def_id))
5361
}
62+
ExportedSymbol::Generic(def_id, substs) => {
63+
tcx.symbol_name(ty::Instance::new(def_id, substs))
64+
}
5465
ExportedSymbol::NoDefId(symbol_name) => {
5566
symbol_name
5667
}
5768
}
5869
}
5970

60-
pub fn compare_stable(&self, tcx: ty::TyCtxt, other: &ExportedSymbol) -> cmp::Ordering {
71+
pub fn compare_stable(&self,
72+
tcx: ty::TyCtxt<'_, 'tcx, '_>,
73+
other: &ExportedSymbol<'tcx>)
74+
-> cmp::Ordering {
6175
match *self {
62-
ExportedSymbol::NonGeneric(self_def_id) => {
63-
match *other {
64-
ExportedSymbol::NonGeneric(other_def_id) => {
65-
tcx.def_path_hash(self_def_id).cmp(&tcx.def_path_hash(other_def_id))
66-
}
67-
ExportedSymbol::NoDefId(_) => {
68-
cmp::Ordering::Less
69-
}
76+
ExportedSymbol::NonGeneric(self_def_id) => match *other {
77+
ExportedSymbol::NonGeneric(other_def_id) => {
78+
tcx.def_path_hash(self_def_id).cmp(&tcx.def_path_hash(other_def_id))
79+
}
80+
ExportedSymbol::Generic(..) |
81+
ExportedSymbol::NoDefId(_) => {
82+
cmp::Ordering::Less
83+
}
84+
}
85+
ExportedSymbol::Generic(..) => match *other {
86+
ExportedSymbol::NonGeneric(_) => {
87+
cmp::Ordering::Greater
88+
}
89+
ExportedSymbol::Generic(..) => {
90+
self.symbol_name(tcx).cmp(&other.symbol_name(tcx))
91+
}
92+
ExportedSymbol::NoDefId(_) => {
93+
cmp::Ordering::Less
7094
}
7195
}
72-
ExportedSymbol::NoDefId(self_symbol_name) => {
73-
match *other {
74-
ExportedSymbol::NonGeneric(_) => {
75-
cmp::Ordering::Greater
76-
}
77-
ExportedSymbol::NoDefId(ref other_symbol_name) => {
78-
self_symbol_name.cmp(other_symbol_name)
79-
}
96+
ExportedSymbol::NoDefId(self_symbol_name) => match *other {
97+
ExportedSymbol::NonGeneric(_) |
98+
ExportedSymbol::Generic(..) => {
99+
cmp::Ordering::Greater
100+
}
101+
ExportedSymbol::NoDefId(ref other_symbol_name) => {
102+
self_symbol_name.cmp(other_symbol_name)
80103
}
81104
}
82105
}
83106
}
84107
}
85108

86-
impl_stable_hash_for!(enum self::ExportedSymbol {
87-
NonGeneric(def_id),
88-
NoDefId(symbol_name)
89-
});
90-
91109
pub fn metadata_symbol_name(tcx: ty::TyCtxt) -> String {
92110
format!("rust_metadata_{}_{}",
93111
tcx.original_crate_name(LOCAL_CRATE),
94112
tcx.crate_disambiguator(LOCAL_CRATE).to_fingerprint().to_hex())
95113
}
114+
115+
impl<'gcx> HashStable<StableHashingContext<'gcx>> for ExportedSymbol<'gcx> {
116+
fn hash_stable<W: StableHasherResult>(&self,
117+
hcx: &mut StableHashingContext<'gcx>,
118+
hasher: &mut StableHasher<W>) {
119+
mem::discriminant(self).hash_stable(hcx, hasher);
120+
match *self {
121+
ExportedSymbol::NonGeneric(def_id) => {
122+
def_id.hash_stable(hcx, hasher);
123+
}
124+
ExportedSymbol::Generic(def_id, substs) => {
125+
def_id.hash_stable(hcx, hasher);
126+
substs.hash_stable(hcx, hasher);
127+
}
128+
ExportedSymbol::NoDefId(symbol_name) => {
129+
symbol_name.hash_stable(hcx, hasher);
130+
}
131+
}
132+
}
133+
}

src/librustc/ty/maps/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ define_maps! { <'tcx>
367367
[] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
368368

369369
[] fn exported_symbols: ExportedSymbols(CrateNum)
370-
-> Arc<Vec<(ExportedSymbol, SymbolExportLevel)>>,
370+
-> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>>,
371371
[] fn collect_and_partition_translation_items:
372372
collect_and_partition_translation_items_node(CrateNum)
373373
-> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),

src/librustc_metadata/cstore_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
269269
return Arc::new(Vec::new())
270270
}
271271

272-
Arc::new(cdata.exported_symbols())
272+
Arc::new(cdata.exported_symbols(tcx))
273273
}
274274
}
275275

src/librustc_metadata/decoder.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,11 +1064,13 @@ impl<'a, 'tcx> CrateMetadata {
10641064
arg_names.decode(self).collect()
10651065
}
10661066

1067-
pub fn exported_symbols(&self) -> Vec<(ExportedSymbol, SymbolExportLevel)> {
1068-
self.root
1069-
.exported_symbols
1070-
.decode(self)
1071-
.collect()
1067+
pub fn exported_symbols(&self,
1068+
tcx: TyCtxt<'a, 'tcx, 'tcx>)
1069+
-> Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)> {
1070+
let lazy_seq: LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)> =
1071+
LazySeq::with_position_and_length(self.root.exported_symbols.position,
1072+
self.root.exported_symbols.len);
1073+
lazy_seq.decode((self, tcx)).collect()
10721074
}
10731075

10741076
pub fn get_macro(&self, id: DefIndex) -> (InternedString, MacroDef) {

src/librustc_metadata/encoder.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,13 +1429,12 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
14291429
// definition (as that's not defined in this crate).
14301430
fn encode_exported_symbols(&mut self,
14311431
exported_symbols: &[(ExportedSymbol, SymbolExportLevel)])
1432-
-> LazySeq<(ExportedSymbol, SymbolExportLevel)> {
1433-
1432+
-> EncodedExportedSymbols {
14341433
// The metadata symbol name is special. It should not show up in
14351434
// downstream crates.
14361435
let metadata_symbol_name = SymbolName::new(&metadata_symbol_name(self.tcx));
14371436

1438-
self.lazy_seq(exported_symbols
1437+
let lazy_seq = self.lazy_seq(exported_symbols
14391438
.iter()
14401439
.filter(|&&(ref exported_symbol, _)| {
14411440
match *exported_symbol {
@@ -1445,7 +1444,12 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
14451444
_ => true,
14461445
}
14471446
})
1448-
.cloned())
1447+
.cloned());
1448+
1449+
EncodedExportedSymbols {
1450+
len: lazy_seq.len,
1451+
position: lazy_seq.position,
1452+
}
14491453
}
14501454

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

src/librustc_metadata/schema.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc::hir::def::{self, CtorKind};
1616
use rustc::hir::def_id::{DefIndex, DefId, CrateNum};
1717
use rustc::ich::StableHashingContext;
1818
use rustc::middle::cstore::{DepKind, LinkagePreference, NativeLibrary};
19-
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
2019
use rustc::middle::lang_items;
2120
use rustc::mir;
2221
use rustc::session::CrateDisambiguator;
@@ -203,7 +202,7 @@ pub struct CrateRoot {
203202
pub codemap: LazySeq<syntax_pos::FileMap>,
204203
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
205204
pub impls: LazySeq<TraitImpls>,
206-
pub exported_symbols: LazySeq<(ExportedSymbol, SymbolExportLevel)>,
205+
pub exported_symbols: EncodedExportedSymbols,
207206

208207
pub index: LazySeq<index::Index>,
209208
}
@@ -525,3 +524,9 @@ impl_stable_hash_for!(struct GeneratorData<'tcx> { layout });
525524
// Tags used for encoding Spans:
526525
pub const TAG_VALID_SPAN: u8 = 0;
527526
pub const TAG_INVALID_SPAN: u8 = 1;
527+
528+
#[derive(RustcEncodable, RustcDecodable)]
529+
pub struct EncodedExportedSymbols {
530+
pub position: usize,
531+
pub len: usize,
532+
}

src/librustc_trans/back/symbol_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn is_reachable_non_generic_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
9494

9595
fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
9696
cnum: CrateNum)
97-
-> Arc<Vec<(ExportedSymbol,
97+
-> Arc<Vec<(ExportedSymbol<'tcx>,
9898
SymbolExportLevel)>>
9999
{
100100
assert_eq!(cnum, LOCAL_CRATE);

src/librustc_trans/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#![feature(conservative_impl_trait)]
3535
#![feature(optin_builtin_traits)]
3636
#![feature(inclusive_range_fields)]
37+
#![feature(underscore_lifetimes)]
3738

3839
use rustc::dep_graph::WorkProduct;
3940
use syntax_pos::symbol::Symbol;

0 commit comments

Comments
 (0)