cleanup WithOptConstParam queries
This commit is contained in:
parent
a835b483fe
commit
536674fb69
5 changed files with 38 additions and 30 deletions
|
@ -1,9 +1,10 @@
|
||||||
//! Values computed by queries that use MIR.
|
//! Values computed by queries that use MIR.
|
||||||
|
|
||||||
use crate::mir::{Body, Promoted};
|
use crate::mir::{abstract_const, Body, Promoted};
|
||||||
use crate::ty::{self, Ty, TyCtxt};
|
use crate::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
|
use rustc_errors::ErrorReported;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_index::bit_set::BitMatrix;
|
use rustc_index::bit_set::BitMatrix;
|
||||||
|
@ -407,7 +408,12 @@ pub struct CoverageInfo {
|
||||||
pub num_expressions: u32,
|
pub num_expressions: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shims which make dealing with `WithOptConstParam` easier.
|
||||||
|
///
|
||||||
|
/// For more information on why this is needed, consider looking
|
||||||
|
/// at the docs for `WithOptConstParam` itself.
|
||||||
impl<'tcx> TyCtxt<'tcx> {
|
impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
#[inline]
|
||||||
pub fn mir_borrowck_opt_const_arg(
|
pub fn mir_borrowck_opt_const_arg(
|
||||||
self,
|
self,
|
||||||
def: ty::WithOptConstParam<LocalDefId>,
|
def: ty::WithOptConstParam<LocalDefId>,
|
||||||
|
@ -419,6 +425,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn mir_const_qualif_opt_const_arg(
|
pub fn mir_const_qualif_opt_const_arg(
|
||||||
self,
|
self,
|
||||||
def: ty::WithOptConstParam<LocalDefId>,
|
def: ty::WithOptConstParam<LocalDefId>,
|
||||||
|
@ -430,6 +437,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn promoted_mir_of_opt_const_arg(
|
pub fn promoted_mir_of_opt_const_arg(
|
||||||
self,
|
self,
|
||||||
def: ty::WithOptConstParam<DefId>,
|
def: ty::WithOptConstParam<DefId>,
|
||||||
|
@ -440,4 +448,28 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.promoted_mir(def.did)
|
self.promoted_mir(def.did)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn optimized_mir_of_opt_const_arg(
|
||||||
|
self,
|
||||||
|
def: ty::WithOptConstParam<DefId>,
|
||||||
|
) -> &'tcx Body<'tcx> {
|
||||||
|
if let Some((did, param_did)) = def.as_const_arg() {
|
||||||
|
self.optimized_mir_of_const_arg((did, param_did))
|
||||||
|
} else {
|
||||||
|
self.optimized_mir(def.did)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn mir_abstract_const_of_opt_const_arg(
|
||||||
|
self,
|
||||||
|
def: ty::WithOptConstParam<DefId>,
|
||||||
|
) -> Result<Option<&'tcx [abstract_const::Node<'tcx>]>, ErrorReported> {
|
||||||
|
if let Some((did, param_did)) = def.as_const_arg() {
|
||||||
|
self.mir_abstract_const_of_const_arg((did, param_did))
|
||||||
|
} else {
|
||||||
|
self.mir_abstract_const(def.did)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2953,13 +2953,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair.
|
/// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair.
|
||||||
pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> {
|
pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> {
|
||||||
match instance {
|
match instance {
|
||||||
ty::InstanceDef::Item(def) => {
|
ty::InstanceDef::Item(def) => self.optimized_mir_of_opt_const_arg(def),
|
||||||
if let Some((did, param_did)) = def.as_const_arg() {
|
|
||||||
self.optimized_mir_of_const_arg((did, param_did))
|
|
||||||
} else {
|
|
||||||
self.optimized_mir(def.did)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ty::InstanceDef::VtableShim(..)
|
ty::InstanceDef::VtableShim(..)
|
||||||
| ty::InstanceDef::ReifyShim(..)
|
| ty::InstanceDef::ReifyShim(..)
|
||||||
| ty::InstanceDef::Intrinsic(..)
|
| ty::InstanceDef::Intrinsic(..)
|
||||||
|
|
|
@ -482,11 +482,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
match instance {
|
match instance {
|
||||||
ty::InstanceDef::Item(def) => {
|
ty::InstanceDef::Item(def) => {
|
||||||
if self.tcx.is_mir_available(def.did) {
|
if self.tcx.is_mir_available(def.did) {
|
||||||
if let Some((did, param_did)) = def.as_const_arg() {
|
Ok(self.tcx.optimized_mir_of_opt_const_arg(def))
|
||||||
Ok(self.tcx.optimized_mir_of_const_arg((did, param_did)))
|
|
||||||
} else {
|
|
||||||
Ok(self.tcx.optimized_mir(def.did))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw_unsup!(NoMirFor(def.did))
|
throw_unsup!(NoMirFor(def.did))
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,11 +332,7 @@ fn mir_promoted(
|
||||||
// this point, before we steal the mir-const result.
|
// this point, before we steal the mir-const result.
|
||||||
// Also this means promotion can rely on all const checks having been done.
|
// Also this means promotion can rely on all const checks having been done.
|
||||||
let _ = tcx.mir_const_qualif_opt_const_arg(def);
|
let _ = tcx.mir_const_qualif_opt_const_arg(def);
|
||||||
let _ = if let Some(param_did) = def.const_param_did {
|
let _ = tcx.mir_abstract_const_of_opt_const_arg(def.to_global());
|
||||||
tcx.mir_abstract_const_of_const_arg((def.did, param_did))
|
|
||||||
} else {
|
|
||||||
tcx.mir_abstract_const(def.did.to_def_id())
|
|
||||||
};
|
|
||||||
let mut body = tcx.mir_const(def).steal();
|
let mut body = tcx.mir_const(def).steal();
|
||||||
|
|
||||||
let mut required_consts = Vec::new();
|
let mut required_consts = Vec::new();
|
||||||
|
|
|
@ -147,11 +147,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
|
||||||
if concrete.is_ok() && substs.has_param_types_or_consts() {
|
if concrete.is_ok() && substs.has_param_types_or_consts() {
|
||||||
match infcx.tcx.def_kind(def.did) {
|
match infcx.tcx.def_kind(def.did) {
|
||||||
DefKind::AnonConst => {
|
DefKind::AnonConst => {
|
||||||
let mir_body = if let Some(def) = def.as_const_arg() {
|
let mir_body = infcx.tcx.optimized_mir_of_opt_const_arg(def);
|
||||||
infcx.tcx.optimized_mir_of_const_arg(def)
|
|
||||||
} else {
|
|
||||||
infcx.tcx.optimized_mir(def.did)
|
|
||||||
};
|
|
||||||
|
|
||||||
if mir_body.is_polymorphic {
|
if mir_body.is_polymorphic {
|
||||||
future_compat_lint();
|
future_compat_lint();
|
||||||
|
@ -212,13 +208,7 @@ impl AbstractConst<'tcx> {
|
||||||
def: ty::WithOptConstParam<DefId>,
|
def: ty::WithOptConstParam<DefId>,
|
||||||
substs: SubstsRef<'tcx>,
|
substs: SubstsRef<'tcx>,
|
||||||
) -> Result<Option<AbstractConst<'tcx>>, ErrorReported> {
|
) -> Result<Option<AbstractConst<'tcx>>, ErrorReported> {
|
||||||
let inner = match (def.did.as_local(), def.const_param_did) {
|
let inner = tcx.mir_abstract_const_of_opt_const_arg(def)?;
|
||||||
(Some(did), Some(param_did)) => {
|
|
||||||
tcx.mir_abstract_const_of_const_arg((did, param_did))?
|
|
||||||
}
|
|
||||||
_ => tcx.mir_abstract_const(def.did)?,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(inner.map(|inner| AbstractConst { inner, substs }))
|
Ok(inner.map(|inner| AbstractConst { inner, substs }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue