mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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
This commit is contained in:
@@ -413,7 +413,7 @@ fn valtree_into_mplace<'tcx>(
|
||||
Some(variant_idx),
|
||||
)
|
||||
}
|
||||
_ => (place.clone(), branches, None),
|
||||
_ => (place.clone(), branches.as_slice(), None),
|
||||
};
|
||||
debug!(?place_adjusted, ?branches);
|
||||
|
||||
|
||||
@@ -92,7 +92,6 @@ macro_rules! arena_types {
|
||||
[] name_set: rustc_data_structures::unord::UnordSet<rustc_span::Symbol>,
|
||||
[] autodiff_item: rustc_hir::attrs::AutoDiffItem,
|
||||
[] ordered_name_set: rustc_data_structures::fx::FxIndexSet<rustc_span::Symbol>,
|
||||
[] valtree: rustc_middle::ty::ValTreeKind<rustc_middle::ty::TyCtxt<'tcx>>,
|
||||
[] stable_order_of_exportable_impls:
|
||||
rustc_data_structures::fx::FxIndexMap<rustc_hir::def_id::DefId, usize>,
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
use rustc_abi::FieldIdx;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::ty::Const;
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::{Span, SpanDecoder, SpanEncoder};
|
||||
@@ -497,6 +498,7 @@ fn decode(d: &mut D) -> Self {
|
||||
&'tcx ty::List<ty::BoundVariableKind<'tcx>>,
|
||||
&'tcx ty::List<ty::Pattern<'tcx>>,
|
||||
&'tcx ty::ListWithCachedTypeInfo<ty::Clause<'tcx>>,
|
||||
&'tcx ty::List<Const<'tcx>>,
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
||||
@@ -31,12 +31,6 @@ fn try_to_scalar(&self) -> Option<Scalar> {
|
||||
// recurses through
|
||||
pub struct ValTree<'tcx>(pub(crate) Interned<'tcx, ty::ValTreeKind<TyCtxt<'tcx>>>);
|
||||
|
||||
impl<'tcx> rustc_type_ir::inherent::ValTree<TyCtxt<'tcx>> for ValTree<'tcx> {
|
||||
fn kind(&self) -> &ty::ValTreeKind<TyCtxt<'tcx>> {
|
||||
&self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ValTree<'tcx> {
|
||||
/// Returns the zero-sized valtree: `Branch([])`.
|
||||
pub fn zst(tcx: TyCtxt<'tcx>) -> Self {
|
||||
@@ -44,7 +38,7 @@ pub fn zst(tcx: TyCtxt<'tcx>) -> Self {
|
||||
}
|
||||
|
||||
pub fn is_zst(self) -> bool {
|
||||
matches!(*self, ty::ValTreeKind::Branch(box []))
|
||||
matches!(*self, ty::ValTreeKind::Branch(consts) if consts.is_empty())
|
||||
}
|
||||
|
||||
pub fn from_raw_bytes(tcx: TyCtxt<'tcx>, bytes: &[u8]) -> Self {
|
||||
@@ -58,7 +52,9 @@ pub fn from_branches(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
branches: impl IntoIterator<Item = ty::Const<'tcx>>,
|
||||
) -> Self {
|
||||
tcx.intern_valtree(ty::ValTreeKind::Branch(branches.into_iter().collect()))
|
||||
tcx.intern_valtree(ty::ValTreeKind::Branch(
|
||||
tcx.mk_const_list_from_iter(branches.into_iter()),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn from_scalar_int(tcx: TyCtxt<'tcx>, i: ScalarInt) -> Self {
|
||||
@@ -81,6 +77,14 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> rustc_type_ir::inherent::IntoKind for ty::ValTree<'tcx> {
|
||||
type Kind = ty::ValTreeKind<TyCtxt<'tcx>>;
|
||||
|
||||
fn kind(self) -> Self::Kind {
|
||||
*self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// `Ok(Err(ty))` indicates the constant was fine, but the valtree couldn't be constructed
|
||||
/// because the value contains something of type `ty` that is not valtree-compatible.
|
||||
/// The caller can then show an appropriate error; the query does not have the
|
||||
|
||||
@@ -564,7 +564,7 @@ fn new(
|
||||
))
|
||||
};
|
||||
|
||||
let valtree_zst = mk_valtree(ty::ValTreeKind::Branch(Box::default()));
|
||||
let valtree_zst = mk_valtree(ty::ValTreeKind::Branch(List::empty()));
|
||||
let valtree_true = mk_valtree(ty::ValTreeKind::Leaf(ty::ScalarInt::TRUE));
|
||||
let valtree_false = mk_valtree(ty::ValTreeKind::Leaf(ty::ScalarInt::FALSE));
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ fn with_cached_task<T>(self, task: impl FnOnce() -> T) -> (T, DepNodeIndex) {
|
||||
type Safety = hir::Safety;
|
||||
type Abi = ExternAbi;
|
||||
type Const = ty::Const<'tcx>;
|
||||
type Consts = &'tcx List<Self::Const>;
|
||||
|
||||
type ParamConst = ty::ParamConst;
|
||||
type ValueConst = ty::Value<'tcx>;
|
||||
|
||||
@@ -1930,7 +1930,7 @@ fn pretty_print_const_valtree(
|
||||
}
|
||||
// Otherwise, print the array separated by commas (or if it's a tuple)
|
||||
(ty::ValTreeKind::Branch(fields), ty::Array(..) | ty::Tuple(..)) => {
|
||||
let fields_iter = fields.iter().copied();
|
||||
let fields_iter = fields.iter();
|
||||
|
||||
match *cv.ty.kind() {
|
||||
ty::Array(..) => {
|
||||
|
||||
@@ -797,4 +797,5 @@ fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(
|
||||
&'tcx ty::List<PlaceElem<'tcx>> : mk_place_elems,
|
||||
&'tcx ty::List<ty::Pattern<'tcx>> : mk_patterns,
|
||||
&'tcx ty::List<ty::ArgOutlivesPredicate<'tcx>> : mk_outlives,
|
||||
&'tcx ty::List<ty::Const<'tcx>> : mk_const_list,
|
||||
}
|
||||
|
||||
@@ -2941,12 +2941,13 @@ fn static_pattern_match_inner(
|
||||
|
||||
match pat.ctor() {
|
||||
Constructor::Variant(variant_index) => {
|
||||
let ValTreeKind::Branch(box [actual_variant_idx]) = *valtree else {
|
||||
let ValTreeKind::Branch(branch) = *valtree else {
|
||||
bug!("malformed valtree for an enum")
|
||||
};
|
||||
|
||||
let ValTreeKind::Leaf(actual_variant_idx) = *actual_variant_idx.to_value().valtree
|
||||
else {
|
||||
if branch.len() != 1 {
|
||||
bug!("malformed valtree for an enum")
|
||||
};
|
||||
let ValTreeKind::Leaf(actual_variant_idx) = **branch[0].to_value().valtree else {
|
||||
bug!("malformed valtree for an enum")
|
||||
};
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
|
||||
///
|
||||
/// `ValTree` does not have this problem with representation, as it only contains integers or
|
||||
/// lists of (nested) `ty::Const`s (which may indirectly contain more `ValTree`s).
|
||||
#[derive_where(Clone, Debug, Hash, Eq, PartialEq; I: Interner)]
|
||||
#[derive_where(Clone, Copy, Debug, Hash, Eq, PartialEq; I: Interner)]
|
||||
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
|
||||
#[cfg_attr(
|
||||
feature = "nightly",
|
||||
@@ -159,8 +159,7 @@ pub enum ValTreeKind<I: Interner> {
|
||||
/// the fields of the variant.
|
||||
///
|
||||
/// ZST types are represented as an empty slice.
|
||||
// FIXME(mgca): Use a `List` here instead of a boxed slice
|
||||
Branch(Box<[I::Const]>),
|
||||
Branch(I::Consts),
|
||||
}
|
||||
|
||||
impl<I: Interner> ValTreeKind<I> {
|
||||
@@ -177,9 +176,9 @@ pub fn to_leaf(&self) -> I::ScalarInt {
|
||||
/// Converts to a `ValTreeKind::Branch` value, `panic`'ing
|
||||
/// if this valtree is some other kind.
|
||||
#[inline]
|
||||
pub fn to_branch(&self) -> &[I::Const] {
|
||||
pub fn to_branch(&self) -> I::Consts {
|
||||
match self {
|
||||
ValTreeKind::Branch(branch) => &**branch,
|
||||
ValTreeKind::Branch(branch) => *branch,
|
||||
ValTreeKind::Leaf(..) => panic!("expected branch, got {:?}", self),
|
||||
}
|
||||
}
|
||||
@@ -193,9 +192,9 @@ pub fn try_to_leaf(&self) -> Option<I::ScalarInt> {
|
||||
}
|
||||
|
||||
/// Attempts to convert to a `ValTreeKind::Branch` value.
|
||||
pub fn try_to_branch(&self) -> Option<&[I::Const]> {
|
||||
pub fn try_to_branch(&self) -> Option<I::Consts> {
|
||||
match self {
|
||||
ValTreeKind::Branch(branch) => Some(&**branch),
|
||||
ValTreeKind::Branch(branch) => Some(*branch),
|
||||
ValTreeKind::Leaf(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,8 +482,8 @@ fn add_const_kind(&mut self, c: &ty::ConstKind<I>) {
|
||||
match cv.valtree().kind() {
|
||||
ty::ValTreeKind::Leaf(_) => (),
|
||||
ty::ValTreeKind::Branch(cts) => {
|
||||
for ct in cts {
|
||||
self.add_const(*ct);
|
||||
for ct in cts.iter() {
|
||||
self.add_const(ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,12 +294,6 @@ pub trait ValueConst<I: Interner<ValueConst = Self>>: Copy + Debug + Hash + Eq {
|
||||
fn valtree(self) -> I::ValTree;
|
||||
}
|
||||
|
||||
// FIXME(mgca): This trait can be removed once we're not using a `Box` in `Branch`
|
||||
pub trait ValTree<I: Interner<ValTree = Self>>: Copy + Debug + Hash + Eq {
|
||||
// This isnt' `IntoKind` because then we can't return a reference
|
||||
fn kind(&self) -> &ty::ValTreeKind<I>;
|
||||
}
|
||||
|
||||
pub trait ExprConst<I: Interner<ExprConst = Self>>: Copy + Debug + Hash + Eq + Relate<I> {
|
||||
fn args(self) -> I::GenericArgs;
|
||||
}
|
||||
|
||||
@@ -150,10 +150,11 @@ fn mk_tracked<T: Debug + Clone>(
|
||||
|
||||
// Kinds of consts
|
||||
type Const: Const<Self>;
|
||||
type Consts: Copy + Debug + Hash + Eq + SliceLike<Item = Self::Const> + Default;
|
||||
type ParamConst: Copy + Debug + Hash + Eq + ParamLike;
|
||||
type ValueConst: ValueConst<Self>;
|
||||
type ExprConst: ExprConst<Self>;
|
||||
type ValTree: ValTree<Self>;
|
||||
type ValTree: Copy + Debug + Hash + Eq + IntoKind<Kind = ty::ValTreeKind<Self>>;
|
||||
type ScalarInt: Copy + Debug + Hash + Eq;
|
||||
|
||||
// Kinds of regions
|
||||
|
||||
@@ -577,9 +577,9 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>(
|
||||
if branches_a.len() == branches_b.len() =>
|
||||
{
|
||||
branches_a
|
||||
.into_iter()
|
||||
.zip(branches_b)
|
||||
.all(|(a, b)| relation.relate(*a, *b).is_ok())
|
||||
.iter()
|
||||
.zip(branches_b.iter())
|
||||
.all(|(a, b)| relation.relate(a, b).is_ok())
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
// Const generic parameter
|
||||
//@ gdb-command:info functions -q function_names::const_generic_fn.*
|
||||
//@ gdb-check:[...]static fn function_names::const_generic_fn_bool<false>();
|
||||
//@ gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#ffa3db4ca1d52dce}>();
|
||||
//@ gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#6dd80cc0c950c171}>();
|
||||
//@ gdb-check:[...]static fn function_names::const_generic_fn_signed_int<-7>();
|
||||
//@ gdb-check:[...]static fn function_names::const_generic_fn_unsigned_int<14>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user