Skip to content

Commit 687d764

Browse files
authored
Rollup merge of #77550 - lcnr:ty-dep-path-ct-cleanup, r=ecstatic-morse
add shims for WithOptConstParam query calls r? @ecstatic-morse @eddyb
2 parents f3ab6f0 + 8160bfa commit 687d764

File tree

6 files changed

+41
-33
lines changed

6 files changed

+41
-33
lines changed

Diff for: compiler/rustc_middle/src/mir/query.rs

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! Values computed by queries that use MIR.
22
3-
use crate::mir::{Body, Promoted};
3+
use crate::mir::{abstract_const, Body, Promoted};
44
use crate::ty::{self, Ty, TyCtxt};
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::sync::Lrc;
7+
use rustc_errors::ErrorReported;
78
use rustc_hir as hir;
89
use rustc_hir::def_id::{DefId, LocalDefId};
910
use rustc_index::bit_set::BitMatrix;
@@ -407,7 +408,12 @@ pub struct CoverageInfo {
407408
pub num_expressions: u32,
408409
}
409410

411+
/// Shims which make dealing with `WithOptConstParam` easier.
412+
///
413+
/// For more information on why this is needed, consider looking
414+
/// at the docs for `WithOptConstParam` itself.
410415
impl<'tcx> TyCtxt<'tcx> {
416+
#[inline]
411417
pub fn mir_borrowck_opt_const_arg(
412418
self,
413419
def: ty::WithOptConstParam<LocalDefId>,
@@ -419,6 +425,7 @@ impl<'tcx> TyCtxt<'tcx> {
419425
}
420426
}
421427

428+
#[inline]
422429
pub fn mir_const_qualif_opt_const_arg(
423430
self,
424431
def: ty::WithOptConstParam<LocalDefId>,
@@ -430,7 +437,8 @@ impl<'tcx> TyCtxt<'tcx> {
430437
}
431438
}
432439

433-
pub fn promoted_mir_of_opt_const_arg(
440+
#[inline]
441+
pub fn promoted_mir_opt_const_arg(
434442
self,
435443
def: ty::WithOptConstParam<DefId>,
436444
) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
@@ -440,4 +448,28 @@ impl<'tcx> TyCtxt<'tcx> {
440448
self.promoted_mir(def.did)
441449
}
442450
}
451+
452+
#[inline]
453+
pub fn optimized_mir_opt_const_arg(
454+
self,
455+
def: ty::WithOptConstParam<DefId>,
456+
) -> &'tcx Body<'tcx> {
457+
if let Some((did, param_did)) = def.as_const_arg() {
458+
self.optimized_mir_of_const_arg((did, param_did))
459+
} else {
460+
self.optimized_mir(def.did)
461+
}
462+
}
463+
464+
#[inline]
465+
pub fn mir_abstract_const_opt_const_arg(
466+
self,
467+
def: ty::WithOptConstParam<DefId>,
468+
) -> Result<Option<&'tcx [abstract_const::Node<'tcx>]>, ErrorReported> {
469+
if let Some((did, param_did)) = def.as_const_arg() {
470+
self.mir_abstract_const_of_const_arg((did, param_did))
471+
} else {
472+
self.mir_abstract_const(def.did)
473+
}
474+
}
443475
}

Diff for: compiler/rustc_middle/src/ty/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2953,13 +2953,7 @@ impl<'tcx> TyCtxt<'tcx> {
29532953
/// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair.
29542954
pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> {
29552955
match instance {
2956-
ty::InstanceDef::Item(def) => {
2957-
if let Some((did, param_did)) = def.as_const_arg() {
2958-
self.optimized_mir_of_const_arg((did, param_did))
2959-
} else {
2960-
self.optimized_mir(def.did)
2961-
}
2962-
}
2956+
ty::InstanceDef::Item(def) => self.optimized_mir_opt_const_arg(def),
29632957
ty::InstanceDef::VtableShim(..)
29642958
| ty::InstanceDef::ReifyShim(..)
29652959
| ty::InstanceDef::Intrinsic(..)

Diff for: compiler/rustc_mir/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
343343
// deny-by-default lint
344344
_ => {
345345
if let Some(p) = cid.promoted {
346-
let span = tcx.promoted_mir_of_opt_const_arg(def.to_global())[p].span;
346+
let span = tcx.promoted_mir_opt_const_arg(def.to_global())[p].span;
347347
if let err_inval!(ReferencedConstant) = err.error {
348348
Err(err.report_as_error(
349349
tcx.at(span),

Diff for: compiler/rustc_mir/src/interpret/eval_context.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
477477
}
478478
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
479479
if let Some(promoted) = promoted {
480-
return Ok(&self.tcx.promoted_mir_of_opt_const_arg(def)[promoted]);
480+
return Ok(&self.tcx.promoted_mir_opt_const_arg(def)[promoted]);
481481
}
482482
match instance {
483483
ty::InstanceDef::Item(def) => {
484484
if self.tcx.is_mir_available(def.did) {
485-
if let Some((did, param_did)) = def.as_const_arg() {
486-
Ok(self.tcx.optimized_mir_of_const_arg((did, param_did)))
487-
} else {
488-
Ok(self.tcx.optimized_mir(def.did))
489-
}
485+
Ok(self.tcx.optimized_mir_opt_const_arg(def))
490486
} else {
491487
throw_unsup!(NoMirFor(def.did))
492488
}

Diff for: compiler/rustc_mir/src/transform/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,7 @@ fn mir_promoted(
287287
// this point, before we steal the mir-const result.
288288
// Also this means promotion can rely on all const checks having been done.
289289
let _ = tcx.mir_const_qualif_opt_const_arg(def);
290-
let _ = if let Some(param_did) = def.const_param_did {
291-
tcx.mir_abstract_const_of_const_arg((def.did, param_did))
292-
} else {
293-
tcx.mir_abstract_const(def.did.to_def_id())
294-
};
290+
let _ = tcx.mir_abstract_const_opt_const_arg(def.to_global());
295291
let mut body = tcx.mir_const(def).steal();
296292

297293
let mut required_consts = Vec::new();

Diff for: compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
147147
if concrete.is_ok() && substs.has_param_types_or_consts() {
148148
match infcx.tcx.def_kind(def.did) {
149149
DefKind::AnonConst => {
150-
let mir_body = if let Some(def) = def.as_const_arg() {
151-
infcx.tcx.optimized_mir_of_const_arg(def)
152-
} else {
153-
infcx.tcx.optimized_mir(def.did)
154-
};
150+
let mir_body = infcx.tcx.optimized_mir_opt_const_arg(def);
155151

156152
if mir_body.is_polymorphic {
157153
future_compat_lint();
@@ -212,13 +208,7 @@ impl AbstractConst<'tcx> {
212208
def: ty::WithOptConstParam<DefId>,
213209
substs: SubstsRef<'tcx>,
214210
) -> Result<Option<AbstractConst<'tcx>>, ErrorReported> {
215-
let inner = match (def.did.as_local(), def.const_param_did) {
216-
(Some(did), Some(param_did)) => {
217-
tcx.mir_abstract_const_of_const_arg((did, param_did))?
218-
}
219-
_ => tcx.mir_abstract_const(def.did)?,
220-
};
221-
211+
let inner = tcx.mir_abstract_const_opt_const_arg(def)?;
222212
Ok(inner.map(|inner| AbstractConst { inner, substs }))
223213
}
224214

0 commit comments

Comments
 (0)