Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proc-macro to derive HashStable everywhere #66279

Merged
merged 16 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::cell::RefCell;
use syntax::ast;
use syntax::source_map::SourceMap;
use syntax::symbol::Symbol;
use syntax::tokenstream::DelimSpan;
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::hygiene::{self, SyntaxContext};

Expand Down Expand Up @@ -364,13 +363,6 @@ impl<'a> syntax_pos::StableHashingContextLike for StableHashingContext<'a> {
}
}

impl<'a> HashStable<StableHashingContext<'a>> for DelimSpan {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
self.open.hash_stable(hcx, hasher);
self.close.hash_stable(hcx, hasher);
}
}

pub fn hash_stable_trait_impls<'a>(
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher,
Expand Down
15 changes: 0 additions & 15 deletions src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
impl<'ctx> syntax::StableHashingContextLike for StableHashingContext<'ctx> {}
impl<'ctx> rustc_target::StableHashingContextLike for StableHashingContext<'ctx> {}

impl_stable_hash_for!(struct ::syntax::ast::Lit {
kind,
token,
span
});

impl_stable_hash_for_spanned!(::syntax::ast::LitKind);

impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident });
Expand Down Expand Up @@ -53,15 +47,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
}
}

impl<'a> HashStable<StableHashingContext<'a>> for ast::Path {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
self.segments.len().hash_stable(hcx, hasher);
for segment in &self.segments {
segment.ident.name.hash_stable(hcx, hasher);
}
}
}

impl_stable_hash_for!(struct ::syntax::ast::AttrItem {
path,
tokens,
Expand Down
12 changes: 11 additions & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use syntax_pos::symbol::{kw, sym, Symbol};
use syntax_pos::{Span, DUMMY_SP, ExpnId};

use rustc_data_structures::fx::FxHashSet;
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;
Expand Down Expand Up @@ -112,6 +113,15 @@ impl PartialEq<Symbol> for Path {
}
}

impl<CTX> HashStable<CTX> for Path {
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
self.segments.len().hash_stable(hcx, hasher);
for segment in &self.segments {
segment.ident.name.hash_stable(hcx, hasher);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelwoerister This skips all the other fields in PathSegment and also the span field in Path. Is this intentional?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the NodeId field was added later and the whole implementation was lifted to a more general context in 759bd01. It would be good to hash the generic arguments too.

}
}
}

impl Path {
// Convert a span and an identifier to the corresponding
// one-segment path.
Expand Down Expand Up @@ -1411,7 +1421,7 @@ pub enum StrStyle {
}

/// An AST literal.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub struct Lit {
/// The original literal token as written in source code.
pub token: token::Lit,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ pub mod early_buffered_lints;
/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in librustc.
pub trait StableHashingContextLike {}
pub trait StableHashingContextLike: syntax_pos::StableHashingContextLike {}
2 changes: 1 addition & 1 deletion src/libsyntax/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl Cursor {
}
}

#[derive(Debug, Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
#[derive(Debug, Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)]
pub struct DelimSpan {
pub open: Span,
pub close: Span,
Expand Down