Skip to content

Commit 47936b4

Browse files
committed
Avoid specialization for AttrId deserialization
1 parent 8d598b0 commit 47936b4

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

compiler/rustc_ast/src/ast.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
pub use crate::format::*;
2222
pub use crate::util::parser::ExprPrecedence;
23+
pub use rustc_span::AttrId;
2324
pub use GenericArgs::*;
2425
pub use UnsafeSource::*;
2526

@@ -30,7 +31,6 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3031
use rustc_data_structures::stack::ensure_sufficient_stack;
3132
use rustc_data_structures::sync::Lrc;
3233
use rustc_macros::HashStable_Generic;
33-
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
3434
use rustc_span::source_map::{respan, Spanned};
3535
use rustc_span::symbol::{kw, sym, Ident, Symbol};
3636
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
@@ -2682,22 +2682,6 @@ pub enum AttrStyle {
26822682
Inner,
26832683
}
26842684

2685-
rustc_index::newtype_index! {
2686-
#[orderable]
2687-
#[debug_format = "AttrId({})"]
2688-
pub struct AttrId {}
2689-
}
2690-
2691-
impl<S: Encoder> Encodable<S> for AttrId {
2692-
fn encode(&self, _s: &mut S) {}
2693-
}
2694-
2695-
impl<D: Decoder> Decodable<D> for AttrId {
2696-
default fn decode(_: &mut D) -> AttrId {
2697-
panic!("cannot decode `AttrId` with `{}`", std::any::type_name::<D>());
2698-
}
2699-
}
2700-
27012685
/// A list of attributes.
27022686
pub type AttrVec = ThinVec<Attribute>;
27032687

compiler/rustc_metadata/src/rmeta/decoder.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,12 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnIndex {
416416
}
417417
}
418418

419-
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ast::AttrId {
420-
#[inline]
421-
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> ast::AttrId {
422-
let sess = d.sess.expect("can't decode AttrId without Session");
419+
impl<'a, 'tcx> SpanDecoder for DecodeContext<'a, 'tcx> {
420+
fn decode_attr_id(&mut self) -> rustc_span::AttrId {
421+
let sess = self.sess.expect("can't decode AttrId without Session");
423422
sess.parse_sess.attr_id_generator.mk_attr_id()
424423
}
425-
}
426424

427-
impl<'a, 'tcx> SpanDecoder for DecodeContext<'a, 'tcx> {
428425
fn decode_crate_num(&mut self) -> CrateNum {
429426
let cnum = CrateNum::from_u32(self.read_u32());
430427
self.map_encoded_cnum_to_current(cnum)

compiler/rustc_middle/src/query/on_disk_cache.rs

+4
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,10 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> {
741741
panic!("Failed to convert DefPathHash {def_path_hash:?}")
742742
})
743743
}
744+
745+
fn decode_attr_id(&mut self) -> rustc_span::AttrId {
746+
panic!("cannot decode `AttrId` with `CacheDecoder`");
747+
}
744748
}
745749

746750
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx UnordSet<LocalDefId> {

compiler/rustc_span/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,12 @@ impl Default for Span {
10191019
}
10201020
}
10211021

1022+
rustc_index::newtype_index! {
1023+
#[orderable]
1024+
#[debug_format = "AttrId({})"]
1025+
pub struct AttrId {}
1026+
}
1027+
10221028
pub trait SpanEncoder: Encoder {
10231029
fn encode_span(&mut self, span: Span);
10241030
fn encode_symbol(&mut self, symbol: Symbol);
@@ -1106,6 +1112,11 @@ impl<E: SpanEncoder> Encodable<E> for DefId {
11061112
}
11071113
}
11081114

1115+
impl<E: SpanEncoder> Encodable<E> for AttrId {
1116+
fn encode(&self, _s: &mut E) {
1117+
// A fresh id will be generated when decoding
1118+
}
1119+
}
11091120
pub trait SpanDecoder: Decoder {
11101121
fn decode_span(&mut self) -> Span;
11111122
fn decode_symbol(&mut self) -> Symbol;
@@ -1114,6 +1125,7 @@ pub trait SpanDecoder: Decoder {
11141125
fn decode_crate_num(&mut self) -> CrateNum;
11151126
fn decode_def_index(&mut self) -> DefIndex;
11161127
fn decode_def_id(&mut self) -> DefId;
1128+
fn decode_attr_id(&mut self) -> AttrId;
11171129
}
11181130

11191131
impl SpanDecoder for MemDecoder<'_> {
@@ -1147,6 +1159,10 @@ impl SpanDecoder for MemDecoder<'_> {
11471159
fn decode_def_id(&mut self) -> DefId {
11481160
DefId { krate: Decodable::decode(self), index: Decodable::decode(self) }
11491161
}
1162+
1163+
fn decode_attr_id(&mut self) -> AttrId {
1164+
panic!("cannot decode `AttrId` with `MemDecoder`");
1165+
}
11501166
}
11511167

11521168
impl<D: SpanDecoder> Decodable<D> for Span {
@@ -1191,6 +1207,12 @@ impl<D: SpanDecoder> Decodable<D> for DefId {
11911207
}
11921208
}
11931209

1210+
impl<D: SpanDecoder> Decodable<D> for AttrId {
1211+
fn decode(s: &mut D) -> AttrId {
1212+
s.decode_attr_id()
1213+
}
1214+
}
1215+
11941216
/// Insert `source_map` into the session globals for the duration of the
11951217
/// closure's execution.
11961218
pub fn set_source_map<T, F: FnOnce() -> T>(source_map: Lrc<SourceMap>, f: F) -> T {

0 commit comments

Comments
 (0)