Skip to content

Commit 4a2d390

Browse files
authored
Unrolled build for #152593
Rollup merge of #152593 - spirali:valtreekind-list, r=lcnr Box in `ValTreeKind::Branch(Box<[I::Const]>)` changed to `List` This is related to trait system refactoring. It fixes the FIXME in `ValTreeKind` ``` // FIXME(mgca): Use a `List` here instead of a boxed slice Branch(Box<[I::Const]>), ``` It introduces `Interner::Consts`, changes `Branch(Box<[I::Const]>)` to `Branch(I::Consts)`, and updates all relevant places. r? lcnr
2 parents a3ac2f2 + f8998e9 commit 4a2d390

15 files changed

Lines changed: 38 additions & 36 deletions

File tree

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ fn valtree_into_mplace<'tcx>(
413413
Some(variant_idx),
414414
)
415415
}
416-
_ => (place.clone(), branches, None),
416+
_ => (place.clone(), branches.as_slice(), None),
417417
};
418418
debug!(?place_adjusted, ?branches);
419419

compiler/rustc_middle/src/arena.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ macro_rules! arena_types {
9292
[] name_set: rustc_data_structures::unord::UnordSet<rustc_span::Symbol>,
9393
[] autodiff_item: rustc_hir::attrs::AutoDiffItem,
9494
[] ordered_name_set: rustc_data_structures::fx::FxIndexSet<rustc_span::Symbol>,
95-
[] valtree: rustc_middle::ty::ValTreeKind<rustc_middle::ty::TyCtxt<'tcx>>,
9695
[] stable_order_of_exportable_impls:
9796
rustc_data_structures::fx::FxIndexMap<rustc_hir::def_id::DefId, usize>,
9897

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::marker::{DiscriminantKind, PointeeSized};
1313
use rustc_abi::FieldIdx;
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_hir::def_id::LocalDefId;
16+
use rustc_middle::ty::Const;
1617
use rustc_serialize::{Decodable, Encodable};
1718
use rustc_span::source_map::Spanned;
1819
use rustc_span::{Span, SpanDecoder, SpanEncoder};
@@ -497,6 +498,7 @@ impl_decodable_via_ref! {
497498
&'tcx ty::List<ty::BoundVariableKind<'tcx>>,
498499
&'tcx ty::List<ty::Pattern<'tcx>>,
499500
&'tcx ty::ListWithCachedTypeInfo<ty::Clause<'tcx>>,
501+
&'tcx ty::List<Const<'tcx>>,
500502
}
501503

502504
#[macro_export]

compiler/rustc_middle/src/ty/consts/valtree.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,14 @@ impl<'tcx> ty::ValTreeKind<TyCtxt<'tcx>> {
3131
// recurses through
3232
pub struct ValTree<'tcx>(pub(crate) Interned<'tcx, ty::ValTreeKind<TyCtxt<'tcx>>>);
3333

34-
impl<'tcx> rustc_type_ir::inherent::ValTree<TyCtxt<'tcx>> for ValTree<'tcx> {
35-
fn kind(&self) -> &ty::ValTreeKind<TyCtxt<'tcx>> {
36-
&self
37-
}
38-
}
39-
4034
impl<'tcx> ValTree<'tcx> {
4135
/// Returns the zero-sized valtree: `Branch([])`.
4236
pub fn zst(tcx: TyCtxt<'tcx>) -> Self {
4337
tcx.consts.valtree_zst
4438
}
4539

4640
pub fn is_zst(self) -> bool {
47-
matches!(*self, ty::ValTreeKind::Branch(box []))
41+
matches!(*self, ty::ValTreeKind::Branch(consts) if consts.is_empty())
4842
}
4943

5044
pub fn from_raw_bytes(tcx: TyCtxt<'tcx>, bytes: &[u8]) -> Self {
@@ -58,7 +52,9 @@ impl<'tcx> ValTree<'tcx> {
5852
tcx: TyCtxt<'tcx>,
5953
branches: impl IntoIterator<Item = ty::Const<'tcx>>,
6054
) -> Self {
61-
tcx.intern_valtree(ty::ValTreeKind::Branch(branches.into_iter().collect()))
55+
tcx.intern_valtree(ty::ValTreeKind::Branch(
56+
tcx.mk_const_list_from_iter(branches.into_iter()),
57+
))
6258
}
6359

6460
pub fn from_scalar_int(tcx: TyCtxt<'tcx>, i: ScalarInt) -> Self {
@@ -81,6 +77,14 @@ impl fmt::Debug for ValTree<'_> {
8177
}
8278
}
8379

80+
impl<'tcx> rustc_type_ir::inherent::IntoKind for ty::ValTree<'tcx> {
81+
type Kind = ty::ValTreeKind<TyCtxt<'tcx>>;
82+
83+
fn kind(self) -> Self::Kind {
84+
*self.0
85+
}
86+
}
87+
8488
/// `Ok(Err(ty))` indicates the constant was fine, but the valtree couldn't be constructed
8589
/// because the value contains something of type `ty` that is not valtree-compatible.
8690
/// The caller can then show an appropriate error; the query does not have the

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ impl<'tcx> CommonConsts<'tcx> {
564564
))
565565
};
566566

567-
let valtree_zst = mk_valtree(ty::ValTreeKind::Branch(Box::default()));
567+
let valtree_zst = mk_valtree(ty::ValTreeKind::Branch(List::empty()));
568568
let valtree_true = mk_valtree(ty::ValTreeKind::Leaf(ty::ScalarInt::TRUE));
569569
let valtree_false = mk_valtree(ty::ValTreeKind::Leaf(ty::ScalarInt::FALSE));
570570

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
9595
type Safety = hir::Safety;
9696
type Abi = ExternAbi;
9797
type Const = ty::Const<'tcx>;
98+
type Consts = &'tcx List<Self::Const>;
9899

99100
type ParamConst = ty::ParamConst;
100101
type ValueConst = ty::Value<'tcx>;

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
19301930
}
19311931
// Otherwise, print the array separated by commas (or if it's a tuple)
19321932
(ty::ValTreeKind::Branch(fields), ty::Array(..) | ty::Tuple(..)) => {
1933-
let fields_iter = fields.iter().copied();
1933+
let fields_iter = fields.iter();
19341934

19351935
match *cv.ty.kind() {
19361936
ty::Array(..) => {

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,4 +797,5 @@ list_fold! {
797797
&'tcx ty::List<PlaceElem<'tcx>> : mk_place_elems,
798798
&'tcx ty::List<ty::Pattern<'tcx>> : mk_patterns,
799799
&'tcx ty::List<ty::ArgOutlivesPredicate<'tcx>> : mk_outlives,
800+
&'tcx ty::List<ty::Const<'tcx>> : mk_const_list,
800801
}

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,12 +2941,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
29412941

29422942
match pat.ctor() {
29432943
Constructor::Variant(variant_index) => {
2944-
let ValTreeKind::Branch(box [actual_variant_idx]) = *valtree else {
2944+
let ValTreeKind::Branch(branch) = *valtree else {
29452945
bug!("malformed valtree for an enum")
29462946
};
2947-
2948-
let ValTreeKind::Leaf(actual_variant_idx) = *actual_variant_idx.to_value().valtree
2949-
else {
2947+
if branch.len() != 1 {
2948+
bug!("malformed valtree for an enum")
2949+
};
2950+
let ValTreeKind::Leaf(actual_variant_idx) = **branch[0].to_value().valtree else {
29502951
bug!("malformed valtree for an enum")
29512952
};
29522953

compiler/rustc_type_ir/src/const_kind.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<CTX> HashStable<CTX> for InferConst {
140140
///
141141
/// `ValTree` does not have this problem with representation, as it only contains integers or
142142
/// lists of (nested) `ty::Const`s (which may indirectly contain more `ValTree`s).
143-
#[derive_where(Clone, Debug, Hash, Eq, PartialEq; I: Interner)]
143+
#[derive_where(Clone, Copy, Debug, Hash, Eq, PartialEq; I: Interner)]
144144
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
145145
#[cfg_attr(
146146
feature = "nightly",
@@ -159,8 +159,7 @@ pub enum ValTreeKind<I: Interner> {
159159
/// the fields of the variant.
160160
///
161161
/// ZST types are represented as an empty slice.
162-
// FIXME(mgca): Use a `List` here instead of a boxed slice
163-
Branch(Box<[I::Const]>),
162+
Branch(I::Consts),
164163
}
165164

166165
impl<I: Interner> ValTreeKind<I> {
@@ -177,9 +176,9 @@ impl<I: Interner> ValTreeKind<I> {
177176
/// Converts to a `ValTreeKind::Branch` value, `panic`'ing
178177
/// if this valtree is some other kind.
179178
#[inline]
180-
pub fn to_branch(&self) -> &[I::Const] {
179+
pub fn to_branch(&self) -> I::Consts {
181180
match self {
182-
ValTreeKind::Branch(branch) => &**branch,
181+
ValTreeKind::Branch(branch) => *branch,
183182
ValTreeKind::Leaf(..) => panic!("expected branch, got {:?}", self),
184183
}
185184
}
@@ -193,9 +192,9 @@ impl<I: Interner> ValTreeKind<I> {
193192
}
194193

195194
/// Attempts to convert to a `ValTreeKind::Branch` value.
196-
pub fn try_to_branch(&self) -> Option<&[I::Const]> {
195+
pub fn try_to_branch(&self) -> Option<I::Consts> {
197196
match self {
198-
ValTreeKind::Branch(branch) => Some(&**branch),
197+
ValTreeKind::Branch(branch) => Some(*branch),
199198
ValTreeKind::Leaf(_) => None,
200199
}
201200
}

0 commit comments

Comments
 (0)