diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-03-21 02:16:27 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-03-21 11:29:07 +0300 |
| commit | 13dd9aff64a9730574188b373d63dadc719f73b6 (patch) | |
| tree | c4c863c4e88c1863a20ab4f6a376d947a9ee4c1a | |
| parent | 5f13820478907b09d50baf74f3ff2b78499ecd6c (diff) | |
| download | rust-13dd9aff64a9730574188b373d63dadc719f73b6.tar.gz rust-13dd9aff64a9730574188b373d63dadc719f73b6.zip | |
ast: Compress `AttrId` from `usize` to `u32`
Also stop encoding/decoding it entirely
| -rw-r--r-- | src/librustc_ast/ast.rs | 22 | ||||
| -rw-r--r-- | src/librustc_ast/attr/mod.rs | 8 |
2 files changed, 12 insertions, 18 deletions
diff --git a/src/librustc_ast/ast.rs b/src/librustc_ast/ast.rs index e3077b9897c..b7b50617eaa 100644 --- a/src/librustc_ast/ast.rs +++ b/src/librustc_ast/ast.rs @@ -31,7 +31,6 @@ use crate::tokenstream::{DelimSpan, TokenStream, TokenTree}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lrc; use rustc_data_structures::thin_vec::ThinVec; -use rustc_index::vec::Idx; use rustc_macros::HashStable_Generic; use rustc_serialize::{self, Decoder, Encoder}; use rustc_span::source_map::{respan, Spanned}; @@ -2251,27 +2250,22 @@ pub enum AttrStyle { Inner, } -#[derive(Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, Copy)] -pub struct AttrId(pub usize); - -impl Idx for AttrId { - fn new(idx: usize) -> Self { - AttrId(idx) - } - fn index(self) -> usize { - self.0 +rustc_index::newtype_index! { + pub struct AttrId { + ENCODABLE = custom + DEBUG_FORMAT = "AttrId({})" } } impl rustc_serialize::Encodable for AttrId { - fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_unit() + fn encode<S: Encoder>(&self, _: &mut S) -> Result<(), S::Error> { + Ok(()) } } impl rustc_serialize::Decodable for AttrId { - fn decode<D: Decoder>(d: &mut D) -> Result<AttrId, D::Error> { - d.read_nil().map(|_| crate::attr::mk_attr_id()) + fn decode<D: Decoder>(_: &mut D) -> Result<AttrId, D::Error> { + Ok(crate::attr::mk_attr_id()) } } diff --git a/src/librustc_ast/attr/mod.rs b/src/librustc_ast/attr/mod.rs index 249311851fb..d53d7767785 100644 --- a/src/librustc_ast/attr/mod.rs +++ b/src/librustc_ast/attr/mod.rs @@ -366,14 +366,14 @@ pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem { } crate fn mk_attr_id() -> AttrId { - use std::sync::atomic::AtomicUsize; + use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering; - static NEXT_ATTR_ID: AtomicUsize = AtomicUsize::new(0); + static NEXT_ATTR_ID: AtomicU32 = AtomicU32::new(0); let id = NEXT_ATTR_ID.fetch_add(1, Ordering::SeqCst); - assert!(id != ::std::usize::MAX); - AttrId(id) + assert!(id != u32::MAX); + AttrId::from_u32(id) } pub fn mk_attr(style: AttrStyle, path: Path, args: MacArgs, span: Span) -> Attribute { |
