Skip to content

Commit 044ff22

Browse files
committed
rustc_pattern_analysis no longer needs to be passed an arena
1 parent 5e66a03 commit 044ff22

File tree

7 files changed

+19
-39
lines changed

7 files changed

+19
-39
lines changed

Cargo.lock

-7
Original file line numberDiff line numberDiff line change
@@ -4355,7 +4355,6 @@ dependencies = [
43554355
"rustc_target",
43564356
"smallvec",
43574357
"tracing",
4358-
"typed-arena",
43594358
]
43604359

43614360
[[package]]
@@ -5692,12 +5691,6 @@ dependencies = [
56925691
"rustc-hash",
56935692
]
56945693

5695-
[[package]]
5696-
name = "typed-arena"
5697-
version = "2.0.2"
5698-
source = "registry+https://github.com/rust-lang/crates.io-index"
5699-
checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a"
5700-
57015694
[[package]]
57025695
name = "typenum"
57035696
version = "1.16.0"

compiler/rustc_pattern_analysis/Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ rustc_span = { path = "../rustc_span", optional = true }
2020
rustc_target = { path = "../rustc_target", optional = true }
2121
smallvec = { version = "1.8.1", features = ["union"] }
2222
tracing = "0.1"
23-
typed-arena = { version = "2.0.2", optional = true }
2423
# tidy-alphabetical-end
2524

2625
[features]
@@ -41,6 +40,3 @@ rustc = [
4140
"smallvec/may_dangle",
4241
"rustc_index/nightly",
4342
]
44-
stable = [
45-
"dep:typed-arena",
46-
]

compiler/rustc_pattern_analysis/src/constructor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ impl<Cx: TypeCx> Constructor<Cx> {
718718

719719
/// The number of fields for this constructor. This must be kept in sync with
720720
/// `Fields::wildcards`.
721-
pub(crate) fn arity(&self, pcx: &PlaceCtxt<'_, '_, Cx>) -> usize {
721+
pub(crate) fn arity(&self, pcx: &PlaceCtxt<'_, Cx>) -> usize {
722722
pcx.ctor_arity(self)
723723
}
724724

@@ -727,7 +727,7 @@ impl<Cx: TypeCx> Constructor<Cx> {
727727
/// this checks for inclusion.
728728
// We inline because this has a single call site in `Matrix::specialize_constructor`.
729729
#[inline]
730-
pub(crate) fn is_covered_by<'p>(&self, pcx: &PlaceCtxt<'_, 'p, Cx>, other: &Self) -> bool {
730+
pub(crate) fn is_covered_by(&self, pcx: &PlaceCtxt<'_, Cx>, other: &Self) -> bool {
731731
match (self, other) {
732732
(Wildcard, _) => pcx
733733
.mcx
@@ -861,7 +861,7 @@ impl<Cx: TypeCx> ConstructorSet<Cx> {
861861
#[instrument(level = "debug", skip(self, pcx, ctors), ret)]
862862
pub(crate) fn split<'a>(
863863
&self,
864-
pcx: &PlaceCtxt<'a, '_, Cx>,
864+
pcx: &PlaceCtxt<'a, Cx>,
865865
ctors: impl Iterator<Item = &'a Constructor<Cx>> + Clone,
866866
) -> SplitConstructorSet<Cx> {
867867
let mut present: SmallVec<[_; 1]> = SmallVec::new();

compiler/rustc_pattern_analysis/src/lib.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ use crate::rustc::RustcMatchCheckCtxt;
3636
#[cfg(feature = "rustc")]
3737
use crate::usefulness::{compute_match_usefulness, ValidityConstraint};
3838

39-
// It's not possible to only enable the `typed_arena` dependency when the `rustc` feature is off, so
40-
// we use another feature instead. The crate won't compile if one of these isn't enabled.
41-
#[cfg(feature = "rustc")]
42-
pub(crate) use rustc_arena::TypedArena;
43-
#[cfg(feature = "stable")]
44-
pub(crate) use typed_arena::Arena as TypedArena;
45-
4639
pub trait Captures<'a> {}
4740
impl<'a, T: ?Sized> Captures<'a> for T {}
4841

@@ -85,11 +78,9 @@ pub trait TypeCx: Sized + fmt::Debug {
8578
/// Context that provides information global to a match.
8679
#[derive(derivative::Derivative)]
8780
#[derivative(Clone(bound = ""), Copy(bound = ""))]
88-
pub struct MatchCtxt<'a, 'p, Cx: TypeCx> {
81+
pub struct MatchCtxt<'a, Cx: TypeCx> {
8982
/// The context for type information.
9083
pub tycx: &'a Cx,
91-
/// An arena to store the wildcards we produce during analysis.
92-
pub wildcard_arena: &'p TypedArena<DeconstructedPat<'p, Cx>>,
9384
}
9485

9586
/// The arm of a match expression.
@@ -110,11 +101,9 @@ pub fn analyze_match<'p, 'tcx>(
110101
arms: &[rustc::MatchArm<'p, 'tcx>],
111102
scrut_ty: Ty<'tcx>,
112103
) -> rustc::UsefulnessReport<'p, 'tcx> {
113-
// Arena to store the extra wildcards we construct during analysis.
114-
let wildcard_arena = tycx.pattern_arena;
115104
let scrut_ty = tycx.reveal_opaque_ty(scrut_ty);
116105
let scrut_validity = ValidityConstraint::from_bool(tycx.known_valid_scrutinee);
117-
let cx = MatchCtxt { tycx, wildcard_arena };
106+
let cx = MatchCtxt { tycx };
118107

119108
let report = compute_match_usefulness(cx, arms, scrut_ty, scrut_validity);
120109

compiler/rustc_pattern_analysis/src/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<Cx: TypeCx> WitnessPat<Cx> {
235235
/// Construct a pattern that matches everything that starts with this constructor.
236236
/// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern
237237
/// `Some(_)`.
238-
pub(crate) fn wild_from_ctor(pcx: &PlaceCtxt<'_, '_, Cx>, ctor: Constructor<Cx>) -> Self {
238+
pub(crate) fn wild_from_ctor(pcx: &PlaceCtxt<'_, Cx>, ctor: Constructor<Cx>) -> Self {
239239
let field_tys = pcx.ctor_sub_tys(&ctor);
240240
let fields = field_tys.iter().map(|ty| Self::wildcard(*ty)).collect();
241241
Self::new(ctor, fields, pcx.ty)

compiler/rustc_pattern_analysis/src/rustc.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ pub type ConstructorSet<'p, 'tcx> =
3131
pub type DeconstructedPat<'p, 'tcx> =
3232
crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
3333
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
34-
pub type MatchCtxt<'a, 'p, 'tcx> = crate::MatchCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>;
34+
pub type MatchCtxt<'a, 'p, 'tcx> = crate::MatchCtxt<'a, RustcMatchCheckCtxt<'p, 'tcx>>;
3535
pub(crate) type PlaceCtxt<'a, 'p, 'tcx> =
36-
crate::usefulness::PlaceCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>;
36+
crate::usefulness::PlaceCtxt<'a, RustcMatchCheckCtxt<'p, 'tcx>>;
3737
pub(crate) type SplitConstructorSet<'p, 'tcx> =
3838
crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
3939
pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
@@ -76,7 +76,9 @@ pub struct RustcMatchCheckCtxt<'p, 'tcx> {
7676
/// outside its module and should not be matchable with an empty match statement.
7777
pub module: DefId,
7878
pub param_env: ty::ParamEnv<'tcx>,
79+
/// To allocate lowered patterns
7980
pub pattern_arena: &'p TypedArena<DeconstructedPat<'p, 'tcx>>,
81+
/// To allocate the result of `self.ctor_sub_tys()`
8082
pub dropless_arena: &'p DroplessArena,
8183
/// Lint level at the match.
8284
pub match_lint_level: HirId,

compiler/rustc_pattern_analysis/src/usefulness.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -731,19 +731,19 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
731731
/// Context that provides information local to a place under investigation.
732732
#[derive(derivative::Derivative)]
733733
#[derivative(Debug(bound = ""), Clone(bound = ""), Copy(bound = ""))]
734-
pub(crate) struct PlaceCtxt<'a, 'p, Cx: TypeCx> {
734+
pub(crate) struct PlaceCtxt<'a, Cx: TypeCx> {
735735
#[derivative(Debug = "ignore")]
736-
pub(crate) mcx: MatchCtxt<'a, 'p, Cx>,
736+
pub(crate) mcx: MatchCtxt<'a, Cx>,
737737
/// Type of the place under investigation.
738738
pub(crate) ty: Cx::Ty,
739739
/// Whether the place is the original scrutinee place, as opposed to a subplace of it.
740740
pub(crate) is_scrutinee: bool,
741741
}
742742

743-
impl<'a, 'p, Cx: TypeCx> PlaceCtxt<'a, 'p, Cx> {
743+
impl<'a, Cx: TypeCx> PlaceCtxt<'a, Cx> {
744744
/// A `PlaceCtxt` when code other than `is_useful` needs one.
745745
#[cfg_attr(not(feature = "rustc"), allow(dead_code))]
746-
pub(crate) fn new_dummy(mcx: MatchCtxt<'a, 'p, Cx>, ty: Cx::Ty) -> Self {
746+
pub(crate) fn new_dummy(mcx: MatchCtxt<'a, Cx>, ty: Cx::Ty) -> Self {
747747
PlaceCtxt { mcx, ty, is_scrutinee: false }
748748
}
749749

@@ -1056,7 +1056,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10561056
/// This computes `specialize(ctor, self)`. See top of the file for explanations.
10571057
fn specialize_constructor(
10581058
&self,
1059-
pcx: &PlaceCtxt<'_, 'p, Cx>,
1059+
pcx: &PlaceCtxt<'_, Cx>,
10601060
ctor: &Constructor<Cx>,
10611061
ctor_is_relevant: bool,
10621062
) -> Matrix<'p, Cx> {
@@ -1214,7 +1214,7 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
12141214
/// pats: [(false, "foo"), _, true]
12151215
/// result: [Enum::Variant { a: (false, "foo"), b: _ }, true]
12161216
/// ```
1217-
fn apply_constructor(&mut self, pcx: &PlaceCtxt<'_, '_, Cx>, ctor: &Constructor<Cx>) {
1217+
fn apply_constructor(&mut self, pcx: &PlaceCtxt<'_, Cx>, ctor: &Constructor<Cx>) {
12181218
let len = self.0.len();
12191219
let arity = ctor.arity(pcx);
12201220
let fields = self.0.drain((len - arity)..).rev().collect();
@@ -1265,7 +1265,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
12651265
/// Reverses specialization by `ctor`. See the section on `unspecialize` at the top of the file.
12661266
fn apply_constructor(
12671267
&mut self,
1268-
pcx: &PlaceCtxt<'_, '_, Cx>,
1268+
pcx: &PlaceCtxt<'_, Cx>,
12691269
missing_ctors: &[Constructor<Cx>],
12701270
ctor: &Constructor<Cx>,
12711271
report_individual_missing_ctors: bool,
@@ -1332,7 +1332,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
13321332
/// This is all explained at the top of the file.
13331333
#[instrument(level = "debug", skip(mcx, is_top_level), ret)]
13341334
fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1335-
mcx: MatchCtxt<'a, 'p, Cx>,
1335+
mcx: MatchCtxt<'a, Cx>,
13361336
matrix: &mut Matrix<'p, Cx>,
13371337
is_top_level: bool,
13381338
) -> WitnessMatrix<Cx> {
@@ -1464,7 +1464,7 @@ pub struct UsefulnessReport<'p, Cx: TypeCx> {
14641464
/// Computes whether a match is exhaustive and which of its arms are useful.
14651465
#[instrument(skip(cx, arms), level = "debug")]
14661466
pub fn compute_match_usefulness<'p, Cx: TypeCx>(
1467-
cx: MatchCtxt<'_, 'p, Cx>,
1467+
cx: MatchCtxt<'_, Cx>,
14681468
arms: &[MatchArm<'p, Cx>],
14691469
scrut_ty: Cx::Ty,
14701470
scrut_validity: ValidityConstraint,

0 commit comments

Comments
 (0)