Rollup merge of #137305 - nnethercote:rustc_middle-2, r=lcnr
Tweaks in and around `rustc_middle` A bunch of tiny improvements I found while working on bigger things. r? ```@lcnr```
This commit is contained in:
commit
1f6c75e682
21 changed files with 59 additions and 91 deletions
|
@ -30,7 +30,6 @@ use rustc_span::{DUMMY_SP, Span, Symbol};
|
|||
use tracing::{debug, trace};
|
||||
|
||||
pub use self::query::*;
|
||||
use self::visit::TyContext;
|
||||
use crate::mir::interpret::{AllocRange, Scalar};
|
||||
use crate::ty::codec::{TyDecoder, TyEncoder};
|
||||
use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths};
|
||||
|
@ -108,7 +107,7 @@ impl MirPhase {
|
|||
}
|
||||
}
|
||||
|
||||
/// Parses an `MirPhase` from a pair of strings. Panics if this isn't possible for any reason.
|
||||
/// Parses a `MirPhase` from a pair of strings. Panics if this isn't possible for any reason.
|
||||
pub fn parse(dialect: String, phase: Option<String>) -> Self {
|
||||
match &*dialect.to_ascii_lowercase() {
|
||||
"built" => {
|
||||
|
@ -532,17 +531,6 @@ impl<'tcx> Body<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn span_for_ty_context(&self, ty_context: TyContext) -> Span {
|
||||
match ty_context {
|
||||
TyContext::UserTy(span) => span,
|
||||
TyContext::ReturnTy(source_info)
|
||||
| TyContext::LocalDecl { source_info, .. }
|
||||
| TyContext::YieldTy(source_info)
|
||||
| TyContext::ResumeTy(source_info) => source_info.span,
|
||||
TyContext::Location(loc) => self.source_info(loc).span,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the return type; it always return first element from `local_decls` array.
|
||||
#[inline]
|
||||
pub fn return_ty(&self) -> Ty<'tcx> {
|
||||
|
@ -784,7 +772,7 @@ impl<T> ClearCrossCrate<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn assert_crate_local(self) -> T {
|
||||
pub fn unwrap_crate_local(self) -> T {
|
||||
match self {
|
||||
ClearCrossCrate::Clear => bug!("unwrapping cross-crate data"),
|
||||
ClearCrossCrate::Set(v) => v,
|
||||
|
@ -941,7 +929,7 @@ mod binding_form_impl {
|
|||
/// involved in borrow_check errors, e.g., explanations of where the
|
||||
/// temporaries come from, when their destructors are run, and/or how
|
||||
/// one might revise the code to satisfy the borrow checker's rules.
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
|
||||
pub struct BlockTailInfo {
|
||||
/// If `true`, then the value resulting from evaluating this tail
|
||||
/// expression is ignored by the block's expression context.
|
||||
|
@ -965,7 +953,6 @@ pub struct LocalDecl<'tcx> {
|
|||
/// Temporaries and the return place are always mutable.
|
||||
pub mutability: Mutability,
|
||||
|
||||
// FIXME(matthewjasper) Don't store in this in `Body`
|
||||
pub local_info: ClearCrossCrate<Box<LocalInfo<'tcx>>>,
|
||||
|
||||
/// The type of this local.
|
||||
|
@ -975,7 +962,6 @@ pub struct LocalDecl<'tcx> {
|
|||
/// e.g., via `let x: T`, then we carry that type here. The MIR
|
||||
/// borrow checker needs this information since it can affect
|
||||
/// region inference.
|
||||
// FIXME(matthewjasper) Don't store in this in `Body`
|
||||
pub user_ty: Option<Box<UserTypeProjections>>,
|
||||
|
||||
/// The *syntactic* (i.e., not visibility) source scope the local is defined
|
||||
|
@ -1083,7 +1069,6 @@ pub enum LocalInfo<'tcx> {
|
|||
AggregateTemp,
|
||||
/// A temporary created for evaluation of some subexpression of some block's tail expression
|
||||
/// (with no intervening statement context).
|
||||
// FIXME(matthewjasper) Don't store in this in `Body`
|
||||
BlockTailTemp(BlockTailInfo),
|
||||
/// A temporary created during evaluating `if` predicate, possibly for pattern matching for `let`s,
|
||||
/// and subject to Edition 2024 temporary lifetime rules
|
||||
|
@ -1098,7 +1083,7 @@ pub enum LocalInfo<'tcx> {
|
|||
|
||||
impl<'tcx> LocalDecl<'tcx> {
|
||||
pub fn local_info(&self) -> &LocalInfo<'tcx> {
|
||||
self.local_info.as_ref().assert_crate_local()
|
||||
self.local_info.as_ref().unwrap_crate_local()
|
||||
}
|
||||
|
||||
/// Returns `true` only if local is a binding that can itself be
|
||||
|
|
|
@ -22,7 +22,7 @@ pub(crate) const ALIGN: usize = 40;
|
|||
|
||||
/// An indication of where we are in the control flow graph. Used for printing
|
||||
/// extra information in `dump_mir`
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum PassWhere {
|
||||
/// We have not started dumping the control flow graph, but we are about to.
|
||||
BeforeCFG,
|
||||
|
|
|
@ -86,7 +86,7 @@ impl SwitchTargets {
|
|||
self.iter().find_map(|(v, t)| (v == value).then_some(t)).unwrap_or_else(|| self.otherwise())
|
||||
}
|
||||
|
||||
/// Adds a new target to the switch. But You cannot add an already present value.
|
||||
/// Adds a new target to the switch. Panics if you add an already present value.
|
||||
#[inline]
|
||||
pub fn add_target(&mut self, value: u128, bb: BasicBlock) {
|
||||
let value = Pu128(value);
|
||||
|
|
|
@ -51,7 +51,7 @@ pub struct ObligationCause<'tcx> {
|
|||
/// information.
|
||||
pub body_id: LocalDefId,
|
||||
|
||||
code: InternedObligationCauseCode<'tcx>,
|
||||
code: ObligationCauseCodeHandle<'tcx>,
|
||||
}
|
||||
|
||||
// This custom hash function speeds up hashing for `Obligation` deduplication
|
||||
|
@ -97,7 +97,7 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
|
||||
pub fn map_code(
|
||||
&mut self,
|
||||
f: impl FnOnce(InternedObligationCauseCode<'tcx>) -> ObligationCauseCode<'tcx>,
|
||||
f: impl FnOnce(ObligationCauseCodeHandle<'tcx>) -> ObligationCauseCode<'tcx>,
|
||||
) {
|
||||
self.code = f(std::mem::take(&mut self.code)).into();
|
||||
}
|
||||
|
@ -152,15 +152,16 @@ pub struct UnifyReceiverContext<'tcx> {
|
|||
pub args: GenericArgsRef<'tcx>,
|
||||
}
|
||||
|
||||
/// A compact form of `ObligationCauseCode`.
|
||||
#[derive(Clone, PartialEq, Eq, Default, HashStable)]
|
||||
#[derive(TypeVisitable, TypeFoldable, TyEncodable, TyDecodable)]
|
||||
pub struct InternedObligationCauseCode<'tcx> {
|
||||
pub struct ObligationCauseCodeHandle<'tcx> {
|
||||
/// `None` for `ObligationCauseCode::Misc` (a common case, occurs ~60% of
|
||||
/// the time). `Some` otherwise.
|
||||
code: Option<Arc<ObligationCauseCode<'tcx>>>,
|
||||
}
|
||||
|
||||
impl<'tcx> std::fmt::Debug for InternedObligationCauseCode<'tcx> {
|
||||
impl<'tcx> std::fmt::Debug for ObligationCauseCodeHandle<'tcx> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let cause: &ObligationCauseCode<'_> = self;
|
||||
cause.fmt(f)
|
||||
|
@ -169,14 +170,14 @@ impl<'tcx> std::fmt::Debug for InternedObligationCauseCode<'tcx> {
|
|||
|
||||
impl<'tcx> ObligationCauseCode<'tcx> {
|
||||
#[inline(always)]
|
||||
fn into(self) -> InternedObligationCauseCode<'tcx> {
|
||||
InternedObligationCauseCode {
|
||||
fn into(self) -> ObligationCauseCodeHandle<'tcx> {
|
||||
ObligationCauseCodeHandle {
|
||||
code: if let ObligationCauseCode::Misc = self { None } else { Some(Arc::new(self)) },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> {
|
||||
impl<'tcx> std::ops::Deref for ObligationCauseCodeHandle<'tcx> {
|
||||
type Target = ObligationCauseCode<'tcx>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
@ -305,7 +306,7 @@ pub enum ObligationCauseCode<'tcx> {
|
|||
/// The node of the function call.
|
||||
call_hir_id: HirId,
|
||||
/// The obligation introduced by this argument.
|
||||
parent_code: InternedObligationCauseCode<'tcx>,
|
||||
parent_code: ObligationCauseCodeHandle<'tcx>,
|
||||
},
|
||||
|
||||
/// Error derived when checking an impl item is compatible with
|
||||
|
@ -390,7 +391,8 @@ pub enum ObligationCauseCode<'tcx> {
|
|||
/// `WellFormed(None)`.
|
||||
WellFormed(Option<WellFormedLoc>),
|
||||
|
||||
/// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching against.
|
||||
/// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching
|
||||
/// against.
|
||||
MatchImpl(ObligationCause<'tcx>, DefId),
|
||||
|
||||
BinOp {
|
||||
|
@ -413,7 +415,7 @@ pub enum ObligationCauseCode<'tcx> {
|
|||
ConstParam(Ty<'tcx>),
|
||||
|
||||
/// Obligations emitted during the normalization of a weak type alias.
|
||||
TypeAlias(InternedObligationCauseCode<'tcx>, Span, DefId),
|
||||
TypeAlias(ObligationCauseCodeHandle<'tcx>, Span, DefId),
|
||||
}
|
||||
|
||||
/// Whether a value can be extracted into a const.
|
||||
|
@ -514,12 +516,6 @@ impl<'tcx> ObligationCauseCode<'tcx> {
|
|||
#[cfg(target_pointer_width = "64")]
|
||||
rustc_data_structures::static_assert_size!(ObligationCauseCode<'_>, 48);
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum StatementAsExpression {
|
||||
CorrectType,
|
||||
NeedsBoxing,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
|
||||
#[derive(TypeVisitable, TypeFoldable)]
|
||||
pub struct MatchExpressionArmCause<'tcx> {
|
||||
|
@ -584,7 +580,7 @@ pub struct DerivedCause<'tcx> {
|
|||
pub parent_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
|
||||
/// The parent trait had this cause.
|
||||
pub parent_code: InternedObligationCauseCode<'tcx>,
|
||||
pub parent_code: ObligationCauseCodeHandle<'tcx>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
|
||||
|
@ -592,9 +588,9 @@ pub struct DerivedCause<'tcx> {
|
|||
pub struct ImplDerivedCause<'tcx> {
|
||||
pub derived: DerivedCause<'tcx>,
|
||||
/// The `DefId` of the `impl` that gave rise to the `derived` obligation.
|
||||
/// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic impl,
|
||||
/// then this will be the `DefId` of that trait alias. Care should therefore be taken to handle
|
||||
/// that exceptional case where appropriate.
|
||||
/// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic
|
||||
/// impl, then this will be the `DefId` of that trait alias. Care should therefore be taken to
|
||||
/// handle that exceptional case where appropriate.
|
||||
pub impl_or_alias_def_id: DefId,
|
||||
/// The index of the derived predicate in the parent impl's predicates.
|
||||
pub impl_def_predicate_index: Option<usize>,
|
||||
|
@ -611,7 +607,7 @@ pub struct DerivedHostCause<'tcx> {
|
|||
pub parent_host_pred: ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>,
|
||||
|
||||
/// The parent trait had this cause.
|
||||
pub parent_code: InternedObligationCauseCode<'tcx>,
|
||||
pub parent_code: ObligationCauseCodeHandle<'tcx>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
|
||||
|
|
|
@ -75,12 +75,6 @@ pub type CanonicalPredicateGoal<'tcx> =
|
|||
pub type CanonicalTypeOpAscribeUserTypeGoal<'tcx> =
|
||||
CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>>;
|
||||
|
||||
pub type CanonicalTypeOpEqGoal<'tcx> =
|
||||
CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::Eq<'tcx>>>;
|
||||
|
||||
pub type CanonicalTypeOpSubtypeGoal<'tcx> =
|
||||
CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::Subtype<'tcx>>>;
|
||||
|
||||
pub type CanonicalTypeOpProvePredicateGoal<'tcx> =
|
||||
CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::ProvePredicate<'tcx>>>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue