Skip to content

Commit 521a823

Browse files
committed
rustc_pattern_analysis no longer needs to be passed an arena
1 parent 1a3edc1 commit 521a823

File tree

8 files changed

+19
-42
lines changed

8 files changed

+19
-42
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]]
@@ -5693,12 +5692,6 @@ dependencies = [
56935692
"rustc-hash",
56945693
]
56955694

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

compiler/rustc_pattern_analysis/Cargo.toml

-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ 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]
2726
default = ["rustc"]
28-
# It's not possible to only enable the `typed_arena` dependency when the `rustc` feature is off, so
29-
# we use another feature instead. The crate won't compile if one of these isn't enabled.
3027
rustc = [
3128
"dep:rustc_arena",
3229
"dep:rustc_data_structures",
@@ -41,6 +38,3 @@ rustc = [
4138
"smallvec/may_dangle",
4239
"rustc_index/nightly",
4340
]
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
@@ -240,7 +240,7 @@ impl<Cx: TypeCx> WitnessPat<Cx> {
240240
/// Construct a pattern that matches everything that starts with this constructor.
241241
/// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern
242242
/// `Some(_)`.
243-
pub(crate) fn wild_from_ctor(pcx: &PlaceCtxt<'_, '_, Cx>, ctor: Constructor<Cx>) -> Self {
243+
pub(crate) fn wild_from_ctor(pcx: &PlaceCtxt<'_, Cx>, ctor: Constructor<Cx>) -> Self {
244244
let field_tys = pcx.ctor_sub_tys(&ctor);
245245
let fields = field_tys.iter().map(|ty| Self::wildcard(*ty)).collect();
246246
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> {
@@ -1215,7 +1215,7 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
12151215
/// pats: [(false, "foo"), _, true]
12161216
/// result: [Enum::Variant { a: (false, "foo"), b: _ }, true]
12171217
/// ```
1218-
fn apply_constructor(&mut self, pcx: &PlaceCtxt<'_, '_, Cx>, ctor: &Constructor<Cx>) {
1218+
fn apply_constructor(&mut self, pcx: &PlaceCtxt<'_, Cx>, ctor: &Constructor<Cx>) {
12191219
let len = self.0.len();
12201220
let arity = ctor.arity(pcx);
12211221
let fields = self.0.drain((len - arity)..).rev().collect();
@@ -1266,7 +1266,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
12661266
/// Reverses specialization by `ctor`. See the section on `unspecialize` at the top of the file.
12671267
fn apply_constructor(
12681268
&mut self,
1269-
pcx: &PlaceCtxt<'_, '_, Cx>,
1269+
pcx: &PlaceCtxt<'_, Cx>,
12701270
missing_ctors: &[Constructor<Cx>],
12711271
ctor: &Constructor<Cx>,
12721272
report_individual_missing_ctors: bool,
@@ -1333,7 +1333,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
13331333
/// This is all explained at the top of the file.
13341334
#[instrument(level = "debug", skip(mcx, is_top_level), ret)]
13351335
fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1336-
mcx: MatchCtxt<'a, 'p, Cx>,
1336+
mcx: MatchCtxt<'a, Cx>,
13371337
matrix: &mut Matrix<'p, Cx>,
13381338
is_top_level: bool,
13391339
) -> WitnessMatrix<Cx> {
@@ -1465,7 +1465,7 @@ pub struct UsefulnessReport<'p, Cx: TypeCx> {
14651465
/// Computes whether a match is exhaustive and which of its arms are useful.
14661466
#[instrument(skip(cx, arms), level = "debug")]
14671467
pub fn compute_match_usefulness<'p, Cx: TypeCx>(
1468-
cx: MatchCtxt<'_, 'p, Cx>,
1468+
cx: MatchCtxt<'_, Cx>,
14691469
arms: &[MatchArm<'p, Cx>],
14701470
scrut_ty: Cx::Ty,
14711471
scrut_validity: ValidityConstraint,

src/tools/tidy/src/deps.rs

-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
357357
"tracing-tree",
358358
"twox-hash",
359359
"type-map",
360-
"typed-arena",
361360
"typenum",
362361
"unic-langid",
363362
"unic-langid-impl",

0 commit comments

Comments
 (0)