Skip to content

Commit db36304

Browse files
committed
rustc_pattern_analysis no longer needs to be passed an arena
1 parent 174e73a commit db36304

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
@@ -4366,7 +4366,6 @@ dependencies = [
43664366
"rustc_target",
43674367
"smallvec",
43684368
"tracing",
4369-
"typed-arena",
43704369
]
43714370

43724371
[[package]]
@@ -5705,12 +5704,6 @@ dependencies = [
57055704
"rustc-hash",
57065705
]
57075706

5708-
[[package]]
5709-
name = "typed-arena"
5710-
version = "2.0.2"
5711-
source = "registry+https://github.com/rust-lang/crates.io-index"
5712-
checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a"
5713-
57145707
[[package]]
57155708
name = "typenum"
57165709
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
@@ -38,13 +38,6 @@ use crate::rustc::RustcMatchCheckCtxt;
3838
#[cfg(feature = "rustc")]
3939
use crate::usefulness::{compute_match_usefulness, ValidityConstraint};
4040

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

@@ -89,11 +82,9 @@ pub trait TypeCx: Sized + fmt::Debug {
8982
/// Context that provides information global to a match.
9083
#[derive(derivative::Derivative)]
9184
#[derivative(Clone(bound = ""), Copy(bound = ""))]
92-
pub struct MatchCtxt<'a, 'p, Cx: TypeCx> {
85+
pub struct MatchCtxt<'a, Cx: TypeCx> {
9386
/// The context for type information.
9487
pub tycx: &'a Cx,
95-
/// An arena to store the wildcards we produce during analysis.
96-
pub wildcard_arena: &'p TypedArena<DeconstructedPat<'p, Cx>>,
9788
}
9889

9990
/// The arm of a match expression.
@@ -114,11 +105,9 @@ pub fn analyze_match<'p, 'tcx>(
114105
arms: &[rustc::MatchArm<'p, 'tcx>],
115106
scrut_ty: Ty<'tcx>,
116107
) -> Result<rustc::UsefulnessReport<'p, 'tcx>, ErrorGuaranteed> {
117-
// Arena to store the extra wildcards we construct during analysis.
118-
let wildcard_arena = tycx.pattern_arena;
119108
let scrut_ty = tycx.reveal_opaque_ty(scrut_ty);
120109
let scrut_validity = ValidityConstraint::from_bool(tycx.known_valid_scrutinee);
121-
let cx = MatchCtxt { tycx, wildcard_arena };
110+
let cx = MatchCtxt { tycx };
122111

123112
let report = compute_match_usefulness(cx, arms, scrut_ty, scrut_validity)?;
124113

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
@@ -33,11 +33,11 @@ pub type ConstructorSet<'p, 'tcx> =
3333
pub type DeconstructedPat<'p, 'tcx> =
3434
crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
3535
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
36-
pub type MatchCtxt<'a, 'p, 'tcx> = crate::MatchCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>;
36+
pub type MatchCtxt<'a, 'p, 'tcx> = crate::MatchCtxt<'a, RustcMatchCheckCtxt<'p, 'tcx>>;
3737
pub type OverlappingRanges<'p, 'tcx> =
3838
crate::usefulness::OverlappingRanges<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
3939
pub(crate) type PlaceCtxt<'a, 'p, 'tcx> =
40-
crate::usefulness::PlaceCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>;
40+
crate::usefulness::PlaceCtxt<'a, RustcMatchCheckCtxt<'p, 'tcx>>;
4141
pub(crate) type SplitConstructorSet<'p, 'tcx> =
4242
crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
4343
pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
@@ -80,7 +80,9 @@ pub struct RustcMatchCheckCtxt<'p, 'tcx> {
8080
/// outside its module and should not be matchable with an empty match statement.
8181
pub module: DefId,
8282
pub param_env: ty::ParamEnv<'tcx>,
83+
/// To allocate lowered patterns
8384
pub pattern_arena: &'p TypedArena<DeconstructedPat<'p, 'tcx>>,
85+
/// To allocate the result of `self.ctor_sub_tys()`
8486
pub dropless_arena: &'p DroplessArena,
8587
/// Lint level at the match.
8688
pub match_lint_level: HirId,

compiler/rustc_pattern_analysis/src/usefulness.rs

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

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

@@ -1067,7 +1067,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10671067
/// This computes `specialize(ctor, self)`. See top of the file for explanations.
10681068
fn specialize_constructor(
10691069
&self,
1070-
pcx: &PlaceCtxt<'_, 'p, Cx>,
1070+
pcx: &PlaceCtxt<'_, Cx>,
10711071
ctor: &Constructor<Cx>,
10721072
ctor_is_relevant: bool,
10731073
) -> Matrix<'p, Cx> {
@@ -1226,7 +1226,7 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
12261226
/// pats: [(false, "foo"), _, true]
12271227
/// result: [Enum::Variant { a: (false, "foo"), b: _ }, true]
12281228
/// ```
1229-
fn apply_constructor(&mut self, pcx: &PlaceCtxt<'_, '_, Cx>, ctor: &Constructor<Cx>) {
1229+
fn apply_constructor(&mut self, pcx: &PlaceCtxt<'_, Cx>, ctor: &Constructor<Cx>) {
12301230
let len = self.0.len();
12311231
let arity = ctor.arity(pcx);
12321232
let fields = self.0.drain((len - arity)..).rev().collect();
@@ -1277,7 +1277,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
12771277
/// Reverses specialization by `ctor`. See the section on `unspecialize` at the top of the file.
12781278
fn apply_constructor(
12791279
&mut self,
1280-
pcx: &PlaceCtxt<'_, '_, Cx>,
1280+
pcx: &PlaceCtxt<'_, Cx>,
12811281
missing_ctors: &[Constructor<Cx>],
12821282
ctor: &Constructor<Cx>,
12831283
report_individual_missing_ctors: bool,
@@ -1421,7 +1421,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
14211421
/// This is all explained at the top of the file.
14221422
#[instrument(level = "debug", skip(mcx, is_top_level), ret)]
14231423
fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1424-
mcx: MatchCtxt<'a, 'p, Cx>,
1424+
mcx: MatchCtxt<'a, Cx>,
14251425
matrix: &mut Matrix<'p, Cx>,
14261426
overlapping_range_endpoints: &mut Vec<OverlappingRanges<'p, Cx>>,
14271427
is_top_level: bool,
@@ -1591,7 +1591,7 @@ pub struct UsefulnessReport<'p, Cx: TypeCx> {
15911591
/// Computes whether a match is exhaustive and which of its arms are useful.
15921592
#[instrument(skip(cx, arms), level = "debug")]
15931593
pub fn compute_match_usefulness<'p, Cx: TypeCx>(
1594-
cx: MatchCtxt<'_, 'p, Cx>,
1594+
cx: MatchCtxt<'_, Cx>,
15951595
arms: &[MatchArm<'p, Cx>],
15961596
scrut_ty: Cx::Ty,
15971597
scrut_validity: ValidityConstraint,

src/tools/tidy/src/deps.rs

-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
359359
"tracing-tree",
360360
"twox-hash",
361361
"type-map",
362-
"typed-arena",
363362
"typenum",
364363
"unic-langid",
365364
"unic-langid-impl",

0 commit comments

Comments
 (0)