Skip to content

Commit 25b876b

Browse files
authored
Rollup merge of rust-lang#139722 - jackh726:patternkind-walk-toir, r=compiler-errors
Move some things to rustc_type_ir This moves - `PatternKind` - `FlagComputation` - `TypeWalker` into rustc_type_ir. Not strictly required for rust-analyzer next-solve integration, but helps with code duplication. r? types
2 parents 324d8d2 + accae53 commit 25b876b

File tree

16 files changed

+531
-468
lines changed

16 files changed

+531
-468
lines changed

compiler/rustc_middle/src/arena.rs

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ macro_rules! arena_types {
8989
[] name_set: rustc_data_structures::unord::UnordSet<rustc_span::Symbol>,
9090
[] autodiff_item: rustc_ast::expand::autodiff_attrs::AutoDiffItem,
9191
[] ordered_name_set: rustc_data_structures::fx::FxIndexSet<rustc_span::Symbol>,
92-
[] pats: rustc_middle::ty::PatternKind<'tcx>,
9392
[] valtree: rustc_middle::ty::ValTreeKind<'tcx>,
9493

9594
// Note that this deliberately duplicates items in the `rustc_hir::arena`,

compiler/rustc_middle/src/ty/consts.rs

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::borrow::Cow;
33
use rustc_data_structures::intern::Interned;
44
use rustc_error_messages::MultiSpan;
55
use rustc_macros::HashStable;
6+
use rustc_type_ir::walk::TypeWalker;
67
use rustc_type_ir::{self as ir, TypeFlags, WithCachedTypeInfo};
78

89
use crate::ty::{self, Ty, TyCtxt};
@@ -243,4 +244,18 @@ impl<'tcx> Const<'tcx> {
243244
pub fn is_ct_infer(self) -> bool {
244245
matches!(self.kind(), ty::ConstKind::Infer(_))
245246
}
247+
248+
/// Iterator that walks `self` and any types reachable from
249+
/// `self`, in depth-first order. Note that just walks the types
250+
/// that appear in `self`, it does not descend into the fields of
251+
/// structs or variants. For example:
252+
///
253+
/// ```text
254+
/// isize => { isize }
255+
/// Foo<Bar<isize>> => { Foo<Bar<isize>>, Bar<isize>, isize }
256+
/// [isize] => { [isize], isize }
257+
/// ```
258+
pub fn walk(self) -> TypeWalker<TyCtxt<'tcx>> {
259+
TypeWalker::new(self.into())
260+
}
246261
}

compiler/rustc_middle/src/ty/context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ impl<'tcx> CtxtInterners<'tcx> {
870870
Ty(Interned::new_unchecked(
871871
self.type_
872872
.intern(kind, |kind| {
873-
let flags = super::flags::FlagComputation::for_kind(&kind);
873+
let flags = ty::FlagComputation::<TyCtxt<'tcx>>::for_kind(&kind);
874874
let stable_hash = self.stable_hash(&flags, sess, untracked, &kind);
875875

876876
InternedInSet(self.arena.alloc(WithCachedTypeInfo {
@@ -896,7 +896,7 @@ impl<'tcx> CtxtInterners<'tcx> {
896896
Const(Interned::new_unchecked(
897897
self.const_
898898
.intern(kind, |kind: ty::ConstKind<'_>| {
899-
let flags = super::flags::FlagComputation::for_const_kind(&kind);
899+
let flags = ty::FlagComputation::<TyCtxt<'tcx>>::for_const_kind(&kind);
900900
let stable_hash = self.stable_hash(&flags, sess, untracked, &kind);
901901

902902
InternedInSet(self.arena.alloc(WithCachedTypeInfo {
@@ -912,7 +912,7 @@ impl<'tcx> CtxtInterners<'tcx> {
912912

913913
fn stable_hash<'a, T: HashStable<StableHashingContext<'a>>>(
914914
&self,
915-
flags: &ty::flags::FlagComputation,
915+
flags: &ty::FlagComputation<TyCtxt<'tcx>>,
916916
sess: &'a Session,
917917
untracked: &'a Untracked,
918918
val: &T,
@@ -940,7 +940,7 @@ impl<'tcx> CtxtInterners<'tcx> {
940940
Predicate(Interned::new_unchecked(
941941
self.predicate
942942
.intern(kind, |kind| {
943-
let flags = super::flags::FlagComputation::for_predicate(kind);
943+
let flags = ty::FlagComputation::<TyCtxt<'tcx>>::for_predicate(kind);
944944

945945
let stable_hash = self.stable_hash(&flags, sess, untracked, &kind);
946946

@@ -961,7 +961,7 @@ impl<'tcx> CtxtInterners<'tcx> {
961961
} else {
962962
self.clauses
963963
.intern_ref(clauses, || {
964-
let flags = super::flags::FlagComputation::for_clauses(clauses);
964+
let flags = ty::FlagComputation::<TyCtxt<'tcx>>::for_clauses(clauses);
965965

966966
InternedInSet(ListWithCachedTypeInfo::from_arena(
967967
&*self.arena,

0 commit comments

Comments
 (0)