Skip to content

Commit 503745e

Browse files
committed
Auto merge of #151210 - matthiaskrgr:rollup-JwDAUuv, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #145354 (Cache derive proc macro expansion with incremental query) - #151123 (Support primitives in type info reflection) - #151178 (simplify words initialization using Rc::new_zeroed) - #151187 (Use `default_field_values` more in `Resolver`) - #151197 (remove lcnr from compiler review rotation) - #151203 (Revert `QueryStackFrame` split) r? @ghost
2 parents b08c11d + 57e950b commit 503745e

54 files changed

Lines changed: 1160 additions & 573 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,11 +3887,13 @@ dependencies = [
38873887
"rustc_lexer",
38883888
"rustc_lint_defs",
38893889
"rustc_macros",
3890+
"rustc_middle",
38903891
"rustc_parse",
38913892
"rustc_proc_macro",
38923893
"rustc_serialize",
38933894
"rustc_session",
38943895
"rustc_span",
3896+
"scoped-tls",
38953897
"smallvec",
38963898
"thin-vec",
38973899
"tracing",

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3348,7 +3348,8 @@ impl UseTree {
33483348
/// Distinguishes between `Attribute`s that decorate items and Attributes that
33493349
/// are contained as statements within items. These two cases need to be
33503350
/// distinguished for pretty-printing.
3351-
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, HashStable_Generic, Walkable)]
3351+
#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)]
3352+
#[derive(Encodable, Decodable, HashStable_Generic, Walkable)]
33523353
pub enum AttrStyle {
33533354
Outer,
33543355
Inner,

compiler/rustc_ast/src/token.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ impl DocFragmentKind {
4040
}
4141
}
4242

43-
#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
43+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
4444
pub enum CommentKind {
4545
Line,
4646
Block,
4747
}
4848

49-
#[derive(Copy, Clone, PartialEq, Debug, Encodable, Decodable, HashStable_Generic)]
49+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable, HashStable_Generic)]
5050
pub enum InvisibleOrigin {
5151
// From the expansion of a metavariable in a declarative macro.
5252
MetaVar(MetaVarKind),
@@ -123,7 +123,7 @@ impl fmt::Display for MetaVarKind {
123123
/// Describes how a sequence of token trees is delimited.
124124
/// Cannot use `proc_macro::Delimiter` directly because this
125125
/// structure should implement some additional traits.
126-
#[derive(Copy, Clone, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
126+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
127127
pub enum Delimiter {
128128
/// `( ... )`
129129
Parenthesis,
@@ -186,7 +186,7 @@ impl Delimiter {
186186
// type. This means that float literals like `1f32` are classified by this type
187187
// as `Int`. Only upon conversion to `ast::LitKind` will such a literal be
188188
// given the `Float` kind.
189-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
189+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
190190
pub enum LitKind {
191191
Bool, // AST only, must never appear in a `Token`
192192
Byte,
@@ -203,7 +203,7 @@ pub enum LitKind {
203203
}
204204

205205
/// A literal token.
206-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
206+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
207207
pub struct Lit {
208208
pub kind: LitKind,
209209
pub symbol: Symbol,
@@ -349,7 +349,7 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool {
349349
.contains(&name)
350350
}
351351

352-
#[derive(PartialEq, Encodable, Decodable, Debug, Copy, Clone, HashStable_Generic)]
352+
#[derive(PartialEq, Eq, Encodable, Decodable, Hash, Debug, Copy, Clone, HashStable_Generic)]
353353
pub enum IdentIsRaw {
354354
No,
355355
Yes,
@@ -376,7 +376,7 @@ impl From<bool> for IdentIsRaw {
376376
}
377377
}
378378

379-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
379+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
380380
pub enum TokenKind {
381381
/* Expression-operator symbols. */
382382
/// `=`
@@ -526,7 +526,7 @@ pub enum TokenKind {
526526
Eof,
527527
}
528528

529-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
529+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Debug, HashStable_Generic)]
530530
pub struct Token {
531531
pub kind: TokenKind,
532532
pub span: Span,

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! which are themselves a single [`Token`] or a `Delimited` subsequence of tokens.
66
77
use std::borrow::Cow;
8+
use std::hash::Hash;
89
use std::ops::Range;
910
use std::sync::Arc;
1011
use std::{cmp, fmt, iter, mem};
@@ -22,7 +23,7 @@ use crate::token::{self, Delimiter, Token, TokenKind};
2223
use crate::{AttrVec, Attribute};
2324

2425
/// Part of a `TokenStream`.
25-
#[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
26+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
2627
pub enum TokenTree {
2728
/// A single token. Should never be `OpenDelim` or `CloseDelim`, because
2829
/// delimiters are implicitly represented by `Delimited`.
@@ -538,7 +539,7 @@ pub struct AttrsTarget {
538539
/// compound token. Used for conversions to `proc_macro::Spacing`. Also used to
539540
/// guide pretty-printing, which is where the `JointHidden` value (which isn't
540541
/// part of `proc_macro::Spacing`) comes in useful.
541-
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
542+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
542543
pub enum Spacing {
543544
/// The token cannot join with the following token to form a compound
544545
/// token.
@@ -595,7 +596,7 @@ pub enum Spacing {
595596
}
596597

597598
/// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s.
598-
#[derive(Clone, Debug, Default, Encodable, Decodable)]
599+
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Encodable, Decodable)]
599600
pub struct TokenStream(pub(crate) Arc<Vec<TokenTree>>);
600601

601602
impl TokenStream {
@@ -811,14 +812,6 @@ impl TokenStream {
811812
}
812813
}
813814

814-
impl PartialEq<TokenStream> for TokenStream {
815-
fn eq(&self, other: &TokenStream) -> bool {
816-
self.iter().eq(other.iter())
817-
}
818-
}
819-
820-
impl Eq for TokenStream {}
821-
822815
impl FromIterator<TokenTree> for TokenStream {
823816
fn from_iter<I: IntoIterator<Item = TokenTree>>(iter: I) -> Self {
824817
TokenStream::new(iter.into_iter().collect::<Vec<TokenTree>>())
@@ -970,7 +963,8 @@ impl TokenCursor {
970963
}
971964
}
972965

973-
#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic, Walkable)]
966+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
967+
#[derive(Encodable, Decodable, HashStable_Generic, Walkable)]
974968
pub struct DelimSpan {
975969
pub open: Span,
976970
pub close: Span,
@@ -994,7 +988,7 @@ impl DelimSpan {
994988
}
995989
}
996990

997-
#[derive(Copy, Clone, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
991+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
998992
pub struct DelimSpacing {
999993
pub open: Spacing,
1000994
pub close: Spacing,

compiler/rustc_const_eval/src/const_eval/type_info.rs

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_abi::FieldIdx;
22
use rustc_hir::LangItem;
3-
use rustc_middle::mir::interpret::CtfeProvenance;
3+
use rustc_middle::mir::interpret::{CtfeProvenance, Scalar};
44
use rustc_middle::span_bug;
55
use rustc_middle::ty::layout::TyAndLayout;
66
use rustc_middle::ty::{self, Const, ScalarInt, Ty};
@@ -35,6 +35,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
3535

3636
interp_ok((variant_id, self.project_downcast(&field_dest, variant_id)?))
3737
};
38+
let ptr_bit_width = || self.tcx.data_layout.pointer_size().bits();
3839
match field.name {
3940
sym::kind => {
4041
let variant_index = match ty.kind() {
@@ -64,13 +65,46 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
6465

6566
variant
6667
}
67-
// For now just merge all primitives into one `Leaf` variant with no data
68-
ty::Uint(_) | ty::Int(_) | ty::Float(_) | ty::Char | ty::Bool => {
69-
downcast(sym::Leaf)?.0
68+
ty::Bool => {
69+
let (variant, _variant_place) = downcast(sym::Bool)?;
70+
variant
71+
}
72+
ty::Char => {
73+
let (variant, _variant_place) = downcast(sym::Char)?;
74+
variant
75+
}
76+
ty::Int(int_ty) => {
77+
let (variant, variant_place) = downcast(sym::Int)?;
78+
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
79+
self.write_int_type_info(
80+
place,
81+
int_ty.bit_width().unwrap_or_else(/* isize */ ptr_bit_width),
82+
true,
83+
)?;
84+
variant
85+
}
86+
ty::Uint(uint_ty) => {
87+
let (variant, variant_place) = downcast(sym::Int)?;
88+
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
89+
self.write_int_type_info(
90+
place,
91+
uint_ty.bit_width().unwrap_or_else(/* usize */ ptr_bit_width),
92+
false,
93+
)?;
94+
variant
95+
}
96+
ty::Float(float_ty) => {
97+
let (variant, variant_place) = downcast(sym::Float)?;
98+
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
99+
self.write_float_type_info(place, float_ty.bit_width())?;
100+
variant
101+
}
102+
ty::Str => {
103+
let (variant, _variant_place) = downcast(sym::Str)?;
104+
variant
70105
}
71106
ty::Adt(_, _)
72107
| ty::Foreign(_)
73-
| ty::Str
74108
| ty::Pat(_, _)
75109
| ty::Slice(_)
76110
| ty::RawPtr(..)
@@ -203,4 +237,46 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
203237

204238
interp_ok(())
205239
}
240+
241+
fn write_int_type_info(
242+
&mut self,
243+
place: impl Writeable<'tcx, CtfeProvenance>,
244+
bit_width: u64,
245+
signed: bool,
246+
) -> InterpResult<'tcx> {
247+
for (field_idx, field) in
248+
place.layout().ty.ty_adt_def().unwrap().non_enum_variant().fields.iter_enumerated()
249+
{
250+
let field_place = self.project_field(&place, field_idx)?;
251+
match field.name {
252+
sym::bit_width => self.write_scalar(
253+
ScalarInt::try_from_target_usize(bit_width, self.tcx.tcx).unwrap(),
254+
&field_place,
255+
)?,
256+
sym::signed => self.write_scalar(Scalar::from_bool(signed), &field_place)?,
257+
other => span_bug!(self.tcx.def_span(field.did), "unimplemented field {other}"),
258+
}
259+
}
260+
interp_ok(())
261+
}
262+
263+
fn write_float_type_info(
264+
&mut self,
265+
place: impl Writeable<'tcx, CtfeProvenance>,
266+
bit_width: u64,
267+
) -> InterpResult<'tcx> {
268+
for (field_idx, field) in
269+
place.layout().ty.ty_adt_def().unwrap().non_enum_variant().fields.iter_enumerated()
270+
{
271+
let field_place = self.project_field(&place, field_idx)?;
272+
match field.name {
273+
sym::bit_width => self.write_scalar(
274+
ScalarInt::try_from_target_usize(bit_width, self.tcx.tcx).unwrap(),
275+
&field_place,
276+
)?,
277+
other => span_bug!(self.tcx.def_span(field.did), "unimplemented field {other}"),
278+
}
279+
}
280+
interp_ok(())
281+
}
206282
}

compiler/rustc_data_structures/src/fx.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,18 @@ macro_rules! define_stable_id_collections {
2828
pub type $entry_name<'a, T> = $crate::fx::IndexEntry<'a, $key, T>;
2929
};
3030
}
31+
32+
pub mod default {
33+
use super::{FxBuildHasher, FxHashMap, FxHashSet};
34+
35+
// FIXME: These two functions will become unnecessary after
36+
// <https://github.com/rust-lang/rustc-hash/pull/63> lands and we start using the corresponding
37+
// `rustc-hash` version. After that we can use `Default::default()` instead.
38+
pub const fn fx_hash_map<K, V>() -> FxHashMap<K, V> {
39+
FxHashMap::with_hasher(FxBuildHasher)
40+
}
41+
42+
pub const fn fx_hash_set<V>() -> FxHashSet<V> {
43+
FxHashSet::with_hasher(FxBuildHasher)
44+
}
45+
}

compiler/rustc_data_structures/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#![feature(assert_matches)]
1919
#![feature(auto_traits)]
2020
#![feature(cfg_select)]
21+
#![feature(const_default)]
22+
#![feature(const_trait_impl)]
2123
#![feature(core_intrinsics)]
2224
#![feature(dropck_eyepatch)]
2325
#![feature(extend_one)]

compiler/rustc_data_structures/src/unord.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::hash::Hash;
88
use std::iter::{Product, Sum};
99
use std::ops::Index;
1010

11-
use rustc_hash::{FxHashMap, FxHashSet};
11+
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
1212
use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
1313

1414
use crate::fingerprint::Fingerprint;
@@ -241,10 +241,10 @@ pub struct UnordSet<V: Eq + Hash> {
241241

242242
impl<V: Eq + Hash> UnordCollection for UnordSet<V> {}
243243

244-
impl<V: Eq + Hash> Default for UnordSet<V> {
244+
impl<V: Eq + Hash> const Default for UnordSet<V> {
245245
#[inline]
246246
fn default() -> Self {
247-
Self { inner: FxHashSet::default() }
247+
Self { inner: FxHashSet::with_hasher(FxBuildHasher) }
248248
}
249249
}
250250

@@ -438,10 +438,10 @@ pub struct UnordMap<K: Eq + Hash, V> {
438438

439439
impl<K: Eq + Hash, V> UnordCollection for UnordMap<K, V> {}
440440

441-
impl<K: Eq + Hash, V> Default for UnordMap<K, V> {
441+
impl<K: Eq + Hash, V> const Default for UnordMap<K, V> {
442442
#[inline]
443443
fn default() -> Self {
444-
Self { inner: FxHashMap::default() }
444+
Self { inner: FxHashMap::with_hasher(FxBuildHasher) }
445445
}
446446
}
447447

compiler/rustc_expand/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ rustc_hir = { path = "../rustc_hir" }
2121
rustc_lexer = { path = "../rustc_lexer" }
2222
rustc_lint_defs = { path = "../rustc_lint_defs" }
2323
rustc_macros = { path = "../rustc_macros" }
24+
rustc_middle = { path = "../rustc_middle" }
2425
rustc_parse = { path = "../rustc_parse" }
2526
# We must use the proc_macro version that we will compile proc-macros against,
2627
# not the one from our own sysroot.
2728
rustc_proc_macro = { path = "../rustc_proc_macro" }
2829
rustc_serialize = { path = "../rustc_serialize" }
2930
rustc_session = { path = "../rustc_session" }
3031
rustc_span = { path = "../rustc_span" }
32+
scoped-tls = "1.0"
3133
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
3234
thin-vec = "0.2.12"
3335
tracing = "0.1"

compiler/rustc_expand/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ pub mod module;
2929
#[allow(rustc::untranslatable_diagnostic)]
3030
pub mod proc_macro;
3131

32+
pub fn provide(providers: &mut rustc_middle::query::Providers) {
33+
providers.derive_macro_expansion = proc_macro::provide_derive_macro_expansion;
34+
}
35+
3236
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

0 commit comments

Comments
 (0)