|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 | 11 | use hir::def_id::{DefId, LOCAL_CRATE};
|
| 12 | +use ich::StableHashingContext; |
| 13 | +use rustc_data_structures::stable_hasher::{StableHasher, HashStable, |
| 14 | + StableHasherResult}; |
12 | 15 | use std::cmp;
|
| 16 | +use std::mem; |
13 | 17 | use ty;
|
| 18 | +use ty::subst::Substs; |
14 | 19 |
|
15 | 20 | /// The SymbolExportLevel of a symbols specifies from which kinds of crates
|
16 | 21 | /// the symbol will be exported. `C` symbols will be exported from any
|
@@ -40,56 +45,89 @@ impl SymbolExportLevel {
|
40 | 45 | }
|
41 | 46 |
|
42 | 47 | #[derive(Eq, PartialEq, Debug, Copy, Clone, RustcEncodable, RustcDecodable)]
|
43 |
| -pub enum ExportedSymbol { |
| 48 | +pub enum ExportedSymbol<'tcx> { |
44 | 49 | NonGeneric(DefId),
|
| 50 | + Generic(DefId, &'tcx Substs<'tcx>), |
45 | 51 | NoDefId(ty::SymbolName),
|
46 | 52 | }
|
47 | 53 |
|
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 { |
50 | 58 | match *self {
|
51 | 59 | ExportedSymbol::NonGeneric(def_id) => {
|
52 | 60 | tcx.symbol_name(ty::Instance::mono(tcx, def_id))
|
53 | 61 | }
|
| 62 | + ExportedSymbol::Generic(def_id, substs) => { |
| 63 | + tcx.symbol_name(ty::Instance::new(def_id, substs)) |
| 64 | + } |
54 | 65 | ExportedSymbol::NoDefId(symbol_name) => {
|
55 | 66 | symbol_name
|
56 | 67 | }
|
57 | 68 | }
|
58 | 69 | }
|
59 | 70 |
|
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 { |
61 | 75 | 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 |
70 | 94 | }
|
71 | 95 | }
|
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) |
80 | 103 | }
|
81 | 104 | }
|
82 | 105 | }
|
83 | 106 | }
|
84 | 107 | }
|
85 | 108 |
|
86 |
| -impl_stable_hash_for!(enum self::ExportedSymbol { |
87 |
| - NonGeneric(def_id), |
88 |
| - NoDefId(symbol_name) |
89 |
| -}); |
90 |
| - |
91 | 109 | pub fn metadata_symbol_name(tcx: ty::TyCtxt) -> String {
|
92 | 110 | format!("rust_metadata_{}_{}",
|
93 | 111 | tcx.original_crate_name(LOCAL_CRATE),
|
94 | 112 | tcx.crate_disambiguator(LOCAL_CRATE).to_fingerprint().to_hex())
|
95 | 113 | }
|
| 114 | + |
| 115 | +impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ExportedSymbol<'gcx> { |
| 116 | + fn hash_stable<W: StableHasherResult>(&self, |
| 117 | + hcx: &mut StableHashingContext<'a>, |
| 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 | +} |
0 commit comments