Skip to content

Commit 1763388

Browse files
SparrowLiifutile
andcommitted
cleanup hashes and span in the query key
Co-authored-by: Felix Rath <[email protected]>
1 parent 3399cd0 commit 1763388

File tree

12 files changed

+30
-41
lines changed

12 files changed

+30
-41
lines changed

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2837,7 +2837,7 @@ impl UseTree {
28372837
/// Distinguishes between `Attribute`s that decorate items and Attributes that
28382838
/// are contained as statements within items. These two cases need to be
28392839
/// distinguished for pretty-printing.
2840-
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, HashStable_Generic, Hash)]
2840+
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, HashStable_Generic)]
28412841
pub enum AttrStyle {
28422842
Outer,
28432843
Inner,

compiler/rustc_ast/src/token.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub enum Delimiter {
6767
// type. This means that float literals like `1f32` are classified by this type
6868
// as `Int`. Only upon conversion to `ast::LitKind` will such a literal be
6969
// given the `Float` kind.
70-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Hash)]
70+
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
7171
pub enum LitKind {
7272
Bool, // AST only, must never appear in a `Token`
7373
Byte,
@@ -84,7 +84,7 @@ pub enum LitKind {
8484
}
8585

8686
/// A literal token.
87-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Hash)]
87+
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
8888
pub struct Lit {
8989
pub kind: LitKind,
9090
pub symbol: Symbol,
@@ -229,7 +229,7 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool {
229229
.contains(&name)
230230
}
231231

232-
#[derive(PartialEq, Encodable, Decodable, Debug, Copy, Clone, HashStable_Generic, Hash)]
232+
#[derive(PartialEq, Encodable, Decodable, Debug, Copy, Clone, HashStable_Generic)]
233233
pub enum IdentIsRaw {
234234
No,
235235
Yes,
@@ -911,7 +911,7 @@ pub enum Nonterminal {
911911
NtVis(P<ast::Visibility>),
912912
}
913913

914-
#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, Hash)]
914+
#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable)]
915915
pub enum NonterminalKind {
916916
Item,
917917
Block,

compiler/rustc_ast/src/tokenstream.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//! ownership of the original.
1515
1616
use std::borrow::Cow;
17-
use std::hash::Hash;
1817
use std::{cmp, fmt, iter};
1918

2019
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -106,15 +105,6 @@ where
106105
}
107106
}
108107
}
109-
110-
/*impl Hash for TokenStream {
111-
fn hash<H: Hasher>(&self, state: &mut H) {
112-
for sub_tt in self.trees() {
113-
sub_tt.hash(state);
114-
}
115-
}
116-
}*/
117-
118108
pub trait ToAttrTokenStream: sync::DynSend + sync::DynSync {
119109
fn to_attr_token_stream(&self) -> AttrTokenStream;
120110
}
@@ -309,7 +299,7 @@ pub struct TokenStream(pub(crate) Lrc<Vec<TokenTree>>);
309299
/// compound token. Used for conversions to `proc_macro::Spacing`. Also used to
310300
/// guide pretty-printing, which is where the `JointHidden` value (which isn't
311301
/// part of `proc_macro::Spacing`) comes in useful.
312-
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic, Hash)]
302+
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
313303
pub enum Spacing {
314304
/// The token cannot join with the following token to form a compound
315305
/// token.
@@ -737,7 +727,7 @@ impl TokenTreeCursor {
737727
}
738728
}
739729

740-
#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic, Hash)]
730+
#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
741731
pub struct DelimSpan {
742732
pub open: Span,
743733
pub close: Span,
@@ -761,7 +751,7 @@ impl DelimSpan {
761751
}
762752
}
763753

764-
#[derive(Copy, Clone, Debug, PartialEq, Encodable, Decodable, HashStable_Generic, Hash)]
754+
#[derive(Copy, Clone, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
765755
pub struct DelimSpacing {
766756
pub open: Spacing,
767757
pub close: Spacing,

compiler/rustc_expand/src/base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,6 @@ pub trait ResolverExpand {
10831083
fn expand_legacy_bang(
10841084
&self,
10851085
invoc_id: LocalExpnId,
1086-
span: Span,
10871086
current_expansion: LocalExpnId,
10881087
) -> Result<(TokenStream, usize), CanRetry>;
10891088
}

compiler/rustc_expand/src/expand.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,13 @@ pub struct MacroExpander<'a, 'b> {
400400

401401
pub fn expand_legacy_bang<'tcx>(
402402
tcx: TyCtxt<'tcx>,
403-
key: (LocalExpnId, Span, LocalExpnId),
403+
key: (LocalExpnId, LocalExpnId),
404404
) -> Result<(&'tcx TokenStream, usize), CanRetry> {
405-
let (invoc_id, span, current_expansion) = key;
405+
let (invoc_id, current_expansion) = key;
406406
let map = tcx.macro_map.borrow();
407-
let (arg, expander) = map.get(&invoc_id).as_ref().unwrap();
407+
let (arg, span, expander) = map.get(&invoc_id).as_ref().unwrap();
408408
expander
409-
.expand(&tcx.sess, span, arg.clone(), current_expansion)
409+
.expand(&tcx.sess, *span, arg.clone(), current_expansion)
410410
.map(|(tts, i)| (tcx.arena.alloc(tts) as &TokenStream, i))
411411
}
412412

@@ -709,11 +709,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
709709

710710
// Macros defined in the current crate have a real node id,
711711
// whereas macros from an external crate have a dummy id.\
712-
let tok_result: Box<dyn MacResult> = match self.cx.resolver.expand_legacy_bang(
713-
invoc.expansion_data.id,
714-
span,
715-
self.cx.current_expansion.id,
716-
) {
712+
let tok_result: Box<dyn MacResult> = match self
713+
.cx
714+
.resolver
715+
.expand_legacy_bang(invoc.expansion_data.id, self.cx.current_expansion.id)
716+
{
717717
Ok((tts, i)) => {
718718
if self.cx.trace_macros() {
719719
let msg = format!("to `{}`", pprust::tts_to_string(&tts));

compiler/rustc_expand/src/mbe/macro_rules.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ use std::borrow::Cow;
22
use std::collections::hash_map::Entry;
33
use std::{mem, slice};
44

5-
use ast::token::IdentIsRaw;
65
use rustc_ast as ast;
76
use rustc_ast::token::NtPatKind::*;
87
use rustc_ast::token::TokenKind::*;
9-
use rustc_ast::token::{self, Delimiter, NonterminalKind, Token, TokenKind};
8+
use rustc_ast::token::{self, Delimiter, IdentIsRaw, NonterminalKind, Token, TokenKind};
109
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
1110
use rustc_ast::{NodeId, DUMMY_NODE_ID};
1211
use rustc_ast_pretty::pprust;
1312
use rustc_attr::{self as attr, TransparencyError};
1413
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
14+
use rustc_data_structures::sync::Lrc;
1515
use rustc_errors::{Applicability, ErrorGuaranteed};
1616
use rustc_feature::Features;
1717
use rustc_lint_defs::builtin::{

compiler/rustc_expand/src/mbe/transcribe.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ fn maybe_use_metavar_location(
404404
})
405405
);
406406
if undelimited_seq {
407-
// Do not record metavar spans for tokens from undelimited sequences, for perf reasons. return orig_tt.clone();
407+
// Do not record metavar spans for tokens from undelimited sequences, for perf reasons.
408+
return orig_tt.clone();
408409
}
409410

410411
let insert = |mspans: &mut FxHashMap<_, _>, s, ms| match mspans.try_insert(s, ms) {

compiler/rustc_middle/src/arena.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ macro_rules! arena_types {
119119
[decode] specialization_graph: rustc_middle::traits::specialization_graph::Graph,
120120
[] crate_inherent_impls: rustc_middle::ty::CrateInherentImpls,
121121
[] hir_owner_nodes: rustc_hir::OwnerNodes<'tcx>,
122-
[] expand_lagacy_bang: rustc_ast::tokenstream::TokenStream,
122+
[] expand_legacy_bang: rustc_ast::tokenstream::TokenStream,
123123
]);
124124
)
125125
}

compiler/rustc_middle/src/query/keys.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,11 @@ impl<'tcx> Key for (ValidityRequirement, ty::ParamEnvAnd<'tcx, Ty<'tcx>>) {
592592
}
593593
}
594594

595-
impl Key for (LocalExpnId, Span, LocalExpnId) {
595+
impl Key for (LocalExpnId, LocalExpnId) {
596596
type Cache<V> = DefaultCache<Self, V>;
597597

598598
fn default_span(&self, _: TyCtxt<'_>) -> Span {
599-
self.1
599+
DUMMY_SP
600600
}
601601

602602
fn ty_def_id(&self) -> Option<DefId> {

compiler/rustc_middle/src/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ rustc_queries! {
111111
desc { "triggering a delayed bug for testing incremental" }
112112
}
113113

114-
query expand_legacy_bang(key: (LocalExpnId, Span, LocalExpnId)) -> Result<(&'tcx TokenStream, usize), CanRetry> {
114+
query expand_legacy_bang(key: (LocalExpnId, LocalExpnId)) -> Result<(&'tcx TokenStream, usize), CanRetry> {
115115
eval_always
116116
no_hash
117-
desc { "expand lagacy bang" }
117+
desc { "expand legacy bang" }
118118
}
119119

120120
/// Collects the list of all tools registered using `#![register_tool]`.

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ pub struct GlobalCtxt<'tcx> {
13101310
pub macro_map: RwLock<
13111311
FxHashMap<
13121312
LocalExpnId,
1313-
(TokenStream, Lrc<dyn TcxMacroExpander + sync::DynSync + sync::DynSend>),
1313+
(TokenStream, Span, Lrc<dyn TcxMacroExpander + sync::DynSync + sync::DynSend>),
13141314
>,
13151315
>,
13161316
}

compiler/rustc_resolve/src/macros.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
336336
self.create_stable_hashing_context(),
337337
);
338338
if let SyntaxExtensionKind::TcxLegacyBang(tcx_expander) = &ext.kind {
339-
if let InvocationKind::Bang { ref mac, .. } = invoc.kind {
339+
if let InvocationKind::Bang { ref mac, span } = invoc.kind {
340340
self.tcx
341341
.macro_map
342342
.borrow_mut()
343-
.insert(invoc_id, (mac.args.tokens.clone(), tcx_expander.clone()));
343+
.insert(invoc_id, (mac.args.tokens.clone(), span, tcx_expander.clone()));
344344
}
345345
}
346346

@@ -538,11 +538,10 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
538538
fn expand_legacy_bang(
539539
&self,
540540
invoc_id: LocalExpnId,
541-
span: Span,
542541
current_expansion: LocalExpnId,
543542
) -> Result<(TokenStream, usize), CanRetry> {
544543
self.tcx()
545-
.expand_legacy_bang((invoc_id, span, current_expansion))
544+
.expand_legacy_bang((invoc_id, current_expansion))
546545
.map(|(tts, i)| (tts.clone(), i))
547546
}
548547
}

0 commit comments

Comments
 (0)