s/PatCtxt/PlaceCtxt/

This commit is contained in:
Nadrieril 2023-12-15 16:32:44 +01:00
parent 1e89a38423
commit 60ea14bfaa
5 changed files with 33 additions and 33 deletions

View File

@ -162,7 +162,7 @@ use self::Constructor::*;
use self::MaybeInfiniteInt::*; use self::MaybeInfiniteInt::*;
use self::SliceKind::*; use self::SliceKind::*;
use crate::usefulness::PatCtxt; use crate::usefulness::PlaceCtxt;
use crate::MatchCx; use crate::MatchCx;
/// Whether we have seen a constructor in the column or not. /// Whether we have seen a constructor in the column or not.
@ -717,7 +717,7 @@ impl<Cx: MatchCx> Constructor<Cx> {
/// The number of fields for this constructor. This must be kept in sync with /// The number of fields for this constructor. This must be kept in sync with
/// `Fields::wildcards`. /// `Fields::wildcards`.
pub(crate) fn arity(&self, pcx: &PatCtxt<'_, '_, Cx>) -> usize { pub(crate) fn arity(&self, pcx: &PlaceCtxt<'_, '_, Cx>) -> usize {
pcx.cx.ctor_arity(self, pcx.ty) pcx.cx.ctor_arity(self, pcx.ty)
} }
@ -726,7 +726,7 @@ impl<Cx: MatchCx> Constructor<Cx> {
/// this checks for inclusion. /// this checks for inclusion.
// We inline because this has a single call site in `Matrix::specialize_constructor`. // We inline because this has a single call site in `Matrix::specialize_constructor`.
#[inline] #[inline]
pub(crate) fn is_covered_by<'p>(&self, pcx: &PatCtxt<'_, 'p, Cx>, other: &Self) -> bool { pub(crate) fn is_covered_by<'p>(&self, pcx: &PlaceCtxt<'_, 'p, Cx>, other: &Self) -> bool {
match (self, other) { match (self, other) {
(Wildcard, _) => pcx (Wildcard, _) => pcx
.cx .cx
@ -859,7 +859,7 @@ impl<Cx: MatchCx> ConstructorSet<Cx> {
#[instrument(level = "debug", skip(self, pcx, ctors), ret)] #[instrument(level = "debug", skip(self, pcx, ctors), ret)]
pub(crate) fn split<'a>( pub(crate) fn split<'a>(
&self, &self,
pcx: &PatCtxt<'_, '_, Cx>, pcx: &PlaceCtxt<'_, '_, Cx>,
ctors: impl Iterator<Item = &'a Constructor<Cx>> + Clone, ctors: impl Iterator<Item = &'a Constructor<Cx>> + Clone,
) -> SplitConstructorSet<Cx> ) -> SplitConstructorSet<Cx>
where where
@ -1008,7 +1008,7 @@ impl<Cx: MatchCx> ConstructorSet<Cx> {
// In the absence of the `exhaustive_patterns` feature however, we don't count nested empty // In the absence of the `exhaustive_patterns` feature however, we don't count nested empty
// types as empty. Only non-nested `!` or `enum Foo {}` are considered empty. // types as empty. Only non-nested `!` or `enum Foo {}` are considered empty.
if !pcx.cx.is_exhaustive_patterns_feature_on() if !pcx.cx.is_exhaustive_patterns_feature_on()
&& !(pcx.is_top_level && matches!(self, Self::NoConstructors)) && !(pcx.is_scrutinee && matches!(self, Self::NoConstructors))
{ {
// Treat all missing constructors as nonempty. // Treat all missing constructors as nonempty.
// This clears `missing_empty`. // This clears `missing_empty`.

View File

@ -13,7 +13,7 @@ use crate::errors::{
OverlappingRangeEndpoints, Uncovered, OverlappingRangeEndpoints, Uncovered,
}; };
use crate::rustc::{ use crate::rustc::{
Constructor, DeconstructedPat, MatchArm, PatCtxt, RustcMatchCheckCtxt, SplitConstructorSet, Constructor, DeconstructedPat, MatchArm, PlaceCtxt, RustcMatchCheckCtxt, SplitConstructorSet,
WitnessPat, WitnessPat,
}; };
use crate::MatchCx; use crate::MatchCx;
@ -68,7 +68,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
} }
/// Do constructor splitting on the constructors of the column. /// Do constructor splitting on the constructors of the column.
fn analyze_ctors(&self, pcx: &PatCtxt<'_, 'p, 'tcx>) -> SplitConstructorSet<'p, 'tcx> { fn analyze_ctors(&self, pcx: &PlaceCtxt<'_, 'p, 'tcx>) -> SplitConstructorSet<'p, 'tcx> {
let column_ctors = self.patterns.iter().map(|p| p.ctor()); let column_ctors = self.patterns.iter().map(|p| p.ctor());
pcx.cx.ctors_for_ty(pcx.ty).split(pcx, column_ctors) pcx.cx.ctors_for_ty(pcx.ty).split(pcx, column_ctors)
} }
@ -84,7 +84,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
/// which may change the lengths. /// which may change the lengths.
fn specialize( fn specialize(
&self, &self,
pcx: &PatCtxt<'a, 'p, 'tcx>, pcx: &PlaceCtxt<'a, 'p, 'tcx>,
ctor: &Constructor<'p, 'tcx>, ctor: &Constructor<'p, 'tcx>,
) -> Vec<PatternColumn<'a, 'p, 'tcx>> { ) -> Vec<PatternColumn<'a, 'p, 'tcx>> {
let arity = ctor.arity(pcx); let arity = ctor.arity(pcx);
@ -130,7 +130,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
let Some(ty) = column.head_ty() else { let Some(ty) = column.head_ty() else {
return Vec::new(); return Vec::new();
}; };
let pcx = &PatCtxt::new_dummy(cx, ty, wildcard_arena); let pcx = &PlaceCtxt::new_dummy(cx, ty, wildcard_arena);
let set = column.analyze_ctors(pcx); let set = column.analyze_ctors(pcx);
if set.present.is_empty() { if set.present.is_empty() {
@ -232,7 +232,7 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
let Some(ty) = column.head_ty() else { let Some(ty) = column.head_ty() else {
return; return;
}; };
let pcx = &PatCtxt::new_dummy(cx, ty, wildcard_arena); let pcx = &PlaceCtxt::new_dummy(cx, ty, wildcard_arena);
let set = column.analyze_ctors(pcx); let set = column.analyze_ctors(pcx);

View File

@ -6,7 +6,7 @@ use std::fmt;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use crate::constructor::{Constructor, Slice, SliceKind}; use crate::constructor::{Constructor, Slice, SliceKind};
use crate::usefulness::PatCtxt; use crate::usefulness::PlaceCtxt;
use crate::{Captures, MatchCx}; use crate::{Captures, MatchCx};
use self::Constructor::*; use self::Constructor::*;
@ -77,7 +77,7 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> {
/// `other_ctor` can be different from `self.ctor`, but must be covered by it. /// `other_ctor` can be different from `self.ctor`, but must be covered by it.
pub(crate) fn specialize<'a>( pub(crate) fn specialize<'a>(
&self, &self,
pcx: &PatCtxt<'a, 'p, Cx>, pcx: &PlaceCtxt<'a, 'p, Cx>,
other_ctor: &Constructor<Cx>, other_ctor: &Constructor<Cx>,
) -> SmallVec<[&'a DeconstructedPat<'p, Cx>; 2]> { ) -> SmallVec<[&'a DeconstructedPat<'p, Cx>; 2]> {
let wildcard_sub_tys = || { let wildcard_sub_tys = || {
@ -178,7 +178,7 @@ impl<Cx: MatchCx> WitnessPat<Cx> {
/// Construct a pattern that matches everything that starts with this constructor. /// Construct a pattern that matches everything that starts with this constructor.
/// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern /// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern
/// `Some(_)`. /// `Some(_)`.
pub(crate) fn wild_from_ctor(pcx: &PatCtxt<'_, '_, Cx>, ctor: Constructor<Cx>) -> Self { pub(crate) fn wild_from_ctor(pcx: &PlaceCtxt<'_, '_, Cx>, ctor: Constructor<Cx>) -> Self {
let field_tys = pcx.cx.ctor_sub_tys(&ctor, pcx.ty); let field_tys = pcx.cx.ctor_sub_tys(&ctor, pcx.ty);
let fields = field_tys.iter().map(|ty| Self::wildcard(*ty)).collect(); let fields = field_tys.iter().map(|ty| Self::wildcard(*ty)).collect();
Self::new(ctor, fields, pcx.ty) Self::new(ctor, fields, pcx.ty)

View File

@ -31,8 +31,8 @@ pub type ConstructorSet<'p, 'tcx> =
pub type DeconstructedPat<'p, 'tcx> = pub type DeconstructedPat<'p, 'tcx> =
crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>; crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>; pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
pub(crate) type PatCtxt<'a, 'p, 'tcx> = pub(crate) type PlaceCtxt<'a, 'p, 'tcx> =
crate::usefulness::PatCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>; crate::usefulness::PlaceCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>;
pub(crate) type SplitConstructorSet<'p, 'tcx> = pub(crate) type SplitConstructorSet<'p, 'tcx> =
crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>; crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'tcx>>; pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'tcx>>;

View File

@ -575,35 +575,35 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
f() f()
} }
/// Context that provides information local to a place under investigation.
#[derive(Clone)] #[derive(Clone)]
pub(crate) struct PatCtxt<'a, 'p, Cx: MatchCx> { pub(crate) struct PlaceCtxt<'a, 'p, Cx: MatchCx> {
pub(crate) cx: &'a Cx, pub(crate) cx: &'a Cx,
/// Type of the current column under investigation.
pub(crate) ty: Cx::Ty,
/// Whether the current pattern is the whole pattern as found in a match arm, or if it's a
/// subpattern.
pub(crate) is_top_level: bool,
/// An arena to store the wildcards we produce during analysis. /// An arena to store the wildcards we produce during analysis.
pub(crate) wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>, pub(crate) wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>,
/// Type of the place under investigation.
pub(crate) ty: Cx::Ty,
/// Whether the place is the original scrutinee place, as opposed to a subplace of it.
pub(crate) is_scrutinee: bool,
} }
impl<'a, 'p, Cx: MatchCx> PatCtxt<'a, 'p, Cx> { impl<'a, 'p, Cx: MatchCx> PlaceCtxt<'a, 'p, Cx> {
/// A `PatCtxt` when code other than `is_useful` needs one. /// A `PlaceCtxt` when code other than `is_useful` needs one.
#[cfg_attr(not(feature = "rustc"), allow(dead_code))] #[cfg_attr(not(feature = "rustc"), allow(dead_code))]
pub(crate) fn new_dummy( pub(crate) fn new_dummy(
cx: &'a Cx, cx: &'a Cx,
ty: Cx::Ty, ty: Cx::Ty,
wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>, wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>,
) -> Self { ) -> Self {
PatCtxt { cx, ty, is_top_level: false, wildcard_arena } PlaceCtxt { cx, ty, is_scrutinee: false, wildcard_arena }
} }
} }
impl<'a, 'p, Cx: MatchCx> Copy for PatCtxt<'a, 'p, Cx> {} impl<'a, 'p, Cx: MatchCx> Copy for PlaceCtxt<'a, 'p, Cx> {}
impl<'a, 'p, Cx: MatchCx> fmt::Debug for PatCtxt<'a, 'p, Cx> { impl<'a, 'p, Cx: MatchCx> fmt::Debug for PlaceCtxt<'a, 'p, Cx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PatCtxt").field("ty", &self.ty).finish() f.debug_struct("PlaceCtxt").field("ty", &self.ty).finish()
} }
} }
@ -714,7 +714,7 @@ impl<'a, 'p, Cx: MatchCx> PatStack<'a, 'p, Cx> {
/// Only call if `ctor.is_covered_by(self.head().ctor())` is true. /// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
fn pop_head_constructor( fn pop_head_constructor(
&self, &self,
pcx: &PatCtxt<'a, 'p, Cx>, pcx: &PlaceCtxt<'a, 'p, Cx>,
ctor: &Constructor<Cx>, ctor: &Constructor<Cx>,
) -> PatStack<'a, 'p, Cx> { ) -> PatStack<'a, 'p, Cx> {
// We pop the head pattern and push the new fields extracted from the arguments of // We pop the head pattern and push the new fields extracted from the arguments of
@ -785,7 +785,7 @@ impl<'a, 'p, Cx: MatchCx> MatrixRow<'a, 'p, Cx> {
/// Only call if `ctor.is_covered_by(self.head().ctor())` is true. /// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
fn pop_head_constructor( fn pop_head_constructor(
&self, &self,
pcx: &PatCtxt<'a, 'p, Cx>, pcx: &PlaceCtxt<'a, 'p, Cx>,
ctor: &Constructor<Cx>, ctor: &Constructor<Cx>,
parent_row: usize, parent_row: usize,
) -> MatrixRow<'a, 'p, Cx> { ) -> MatrixRow<'a, 'p, Cx> {
@ -914,7 +914,7 @@ impl<'a, 'p, Cx: MatchCx> Matrix<'a, 'p, Cx> {
/// This computes `specialize(ctor, self)`. See top of the file for explanations. /// This computes `specialize(ctor, self)`. See top of the file for explanations.
fn specialize_constructor( fn specialize_constructor(
&self, &self,
pcx: &PatCtxt<'a, 'p, Cx>, pcx: &PlaceCtxt<'a, 'p, Cx>,
ctor: &Constructor<Cx>, ctor: &Constructor<Cx>,
) -> Matrix<'a, 'p, Cx> { ) -> Matrix<'a, 'p, Cx> {
let wildcard_row = self.wildcard_row.pop_head_constructor(pcx, ctor); let wildcard_row = self.wildcard_row.pop_head_constructor(pcx, ctor);
@ -1064,7 +1064,7 @@ impl<Cx: MatchCx> WitnessStack<Cx> {
/// pats: [(false, "foo"), _, true] /// pats: [(false, "foo"), _, true]
/// result: [Enum::Variant { a: (false, "foo"), b: _ }, true] /// result: [Enum::Variant { a: (false, "foo"), b: _ }, true]
/// ``` /// ```
fn apply_constructor(&mut self, pcx: &PatCtxt<'_, '_, Cx>, ctor: &Constructor<Cx>) { fn apply_constructor(&mut self, pcx: &PlaceCtxt<'_, '_, Cx>, ctor: &Constructor<Cx>) {
let len = self.0.len(); let len = self.0.len();
let arity = ctor.arity(pcx); let arity = ctor.arity(pcx);
let fields = self.0.drain((len - arity)..).rev().collect(); let fields = self.0.drain((len - arity)..).rev().collect();
@ -1114,7 +1114,7 @@ impl<Cx: MatchCx> WitnessMatrix<Cx> {
/// Reverses specialization by `ctor`. See the section on `unspecialize` at the top of the file. /// Reverses specialization by `ctor`. See the section on `unspecialize` at the top of the file.
fn apply_constructor( fn apply_constructor(
&mut self, &mut self,
pcx: &PatCtxt<'_, '_, Cx>, pcx: &PlaceCtxt<'_, '_, Cx>,
missing_ctors: &[Constructor<Cx>], missing_ctors: &[Constructor<Cx>],
ctor: &Constructor<Cx>, ctor: &Constructor<Cx>,
report_individual_missing_ctors: bool, report_individual_missing_ctors: bool,
@ -1202,7 +1202,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: MatchCx>(
}; };
debug!("ty: {ty:?}"); debug!("ty: {ty:?}");
let pcx = &PatCtxt { cx, ty, is_top_level, wildcard_arena }; let pcx = &PlaceCtxt { cx, ty, is_scrutinee: is_top_level, wildcard_arena };
// Whether the place/column we are inspecting is known to contain valid data. // Whether the place/column we are inspecting is known to contain valid data.
let place_validity = matrix.place_validity[0]; let place_validity = matrix.place_validity[0];