Skip to content

Commit a7fe4df

Browse files
committed
update promoted_mir
1 parent ae80d7e commit a7fe4df

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

src/librustc_middle/mir/query.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Values computed by queries that use MIR.
22
3+
use crate::mir::{Body, Promoted};
34
use crate::ty::{self, Ty, TyCtxt};
45
use rustc_data_structures::fx::FxHashMap;
56
use rustc_data_structures::sync::Lrc;
@@ -343,4 +344,15 @@ impl<'tcx> TyCtxt<'tcx> {
343344
self.mir_const_qualif(def.did)
344345
}
345346
}
347+
348+
pub fn promoted_mir_of_opt_const_arg(
349+
self,
350+
def: ty::WithOptParam<DefId>,
351+
) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
352+
if let Some((did, param_did)) = def.as_const_arg() {
353+
self.promoted_mir_of_const_arg((did, param_did))
354+
} else {
355+
self.promoted_mir(def.did)
356+
}
357+
}
346358
}

src/librustc_middle/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,11 @@ rustc_queries! {
277277
cache_on_disk_if { key.is_local() }
278278
}
279279
query promoted_mir_of_const_arg(
280-
key: ty::WithOptParam<LocalDefId>
280+
key: (LocalDefId, DefId)
281281
) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
282282
desc {
283283
|tcx| "optimizing promoted MIR for the const argument `{}`",
284-
tcx.def_path_str(key.did.to_def_id()),
284+
tcx.def_path_str(key.0.to_def_id()),
285285
}
286286
}
287287
}

src/librustc_mir/const_eval/eval_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub fn const_eval_raw_provider<'tcx>(
360360
// deny-by-default lint
361361
_ => {
362362
if let Some(p) = cid.promoted {
363-
let span = tcx.promoted_mir_of_const_arg(def)[p].span;
363+
let span = tcx.promoted_mir_of_opt_const_arg(def.to_global())[p].span;
364364
if let err_inval!(ReferencedConstant) = err.error {
365365
err.report_as_error(
366366
tcx.at(span),

src/librustc_mir/interpret/eval_context.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
406406
}
407407
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
408408
if let Some(promoted) = promoted {
409-
return if let Some(def) = def.as_local() {
410-
Ok(&self.tcx.promoted_mir_of_const_arg(def)[promoted])
411-
} else {
412-
Ok(&self.tcx.promoted_mir(def.did)[promoted])
413-
};
409+
return Ok(&self.tcx.promoted_mir_of_opt_const_arg(def)[promoted]);
414410
}
415411
match instance {
416412
ty::InstanceDef::Item(def) => {

src/librustc_mir/transform/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,8 @@ pub(crate) fn provide(providers: &mut Providers) {
6262
promoted_mir: |tcx, def_id| {
6363
promoted_mir(tcx, ty::WithOptParam::dummy(def_id.expect_local()))
6464
},
65-
promoted_mir_of_const_arg: |tcx, def| {
66-
if def.param_did.is_none() {
67-
tcx.promoted_mir(def.did.to_def_id())
68-
} else {
69-
promoted_mir(tcx, def)
70-
}
65+
promoted_mir_of_const_arg: |tcx, (did, param_did)| {
66+
promoted_mir(tcx, ty::WithOptParam { did, param_did: Some(param_did) })
7167
},
7268
..*providers
7369
};
@@ -525,8 +521,8 @@ fn promoted_mir<'tcx>(
525521
def: ty::WithOptParam<LocalDefId>,
526522
) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
527523
if def.param_did.is_none() {
528-
if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) {
529-
return tcx.promoted_mir_of_const_arg(ty::WithOptParam { param_did, ..def });
524+
if let Some(param_did) = tcx.opt_const_param_of(def.did) {
525+
return tcx.promoted_mir_of_const_arg((def.did, param_did));
530526
}
531527
}
532528

0 commit comments

Comments
 (0)