update promoted_mir
This commit is contained in:
parent
ae80d7e012
commit
a7fe4df04a
5 changed files with 20 additions and 16 deletions
|
|
@ -1,5 +1,6 @@
|
|||
//! Values computed by queries that use MIR.
|
||||
|
||||
use crate::mir::{Body, Promoted};
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
|
|
@ -343,4 +344,15 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self.mir_const_qualif(def.did)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn promoted_mir_of_opt_const_arg(
|
||||
self,
|
||||
def: ty::WithOptParam<DefId>,
|
||||
) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
|
||||
if let Some((did, param_did)) = def.as_const_arg() {
|
||||
self.promoted_mir_of_const_arg((did, param_did))
|
||||
} else {
|
||||
self.promoted_mir(def.did)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -277,11 +277,11 @@ rustc_queries! {
|
|||
cache_on_disk_if { key.is_local() }
|
||||
}
|
||||
query promoted_mir_of_const_arg(
|
||||
key: ty::WithOptParam<LocalDefId>
|
||||
key: (LocalDefId, DefId)
|
||||
) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
|
||||
desc {
|
||||
|tcx| "optimizing promoted MIR for the const argument `{}`",
|
||||
tcx.def_path_str(key.did.to_def_id()),
|
||||
tcx.def_path_str(key.0.to_def_id()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -360,7 +360,7 @@ pub fn const_eval_raw_provider<'tcx>(
|
|||
// deny-by-default lint
|
||||
_ => {
|
||||
if let Some(p) = cid.promoted {
|
||||
let span = tcx.promoted_mir_of_const_arg(def)[p].span;
|
||||
let span = tcx.promoted_mir_of_opt_const_arg(def.to_global())[p].span;
|
||||
if let err_inval!(ReferencedConstant) = err.error {
|
||||
err.report_as_error(
|
||||
tcx.at(span),
|
||||
|
|
|
|||
|
|
@ -406,11 +406,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
}
|
||||
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
|
||||
if let Some(promoted) = promoted {
|
||||
return if let Some(def) = def.as_local() {
|
||||
Ok(&self.tcx.promoted_mir_of_const_arg(def)[promoted])
|
||||
} else {
|
||||
Ok(&self.tcx.promoted_mir(def.did)[promoted])
|
||||
};
|
||||
return Ok(&self.tcx.promoted_mir_of_opt_const_arg(def)[promoted]);
|
||||
}
|
||||
match instance {
|
||||
ty::InstanceDef::Item(def) => {
|
||||
|
|
|
|||
|
|
@ -62,12 +62,8 @@ pub(crate) fn provide(providers: &mut Providers) {
|
|||
promoted_mir: |tcx, def_id| {
|
||||
promoted_mir(tcx, ty::WithOptParam::dummy(def_id.expect_local()))
|
||||
},
|
||||
promoted_mir_of_const_arg: |tcx, def| {
|
||||
if def.param_did.is_none() {
|
||||
tcx.promoted_mir(def.did.to_def_id())
|
||||
} else {
|
||||
promoted_mir(tcx, def)
|
||||
}
|
||||
promoted_mir_of_const_arg: |tcx, (did, param_did)| {
|
||||
promoted_mir(tcx, ty::WithOptParam { did, param_did: Some(param_did) })
|
||||
},
|
||||
..*providers
|
||||
};
|
||||
|
|
@ -525,8 +521,8 @@ fn promoted_mir<'tcx>(
|
|||
def: ty::WithOptParam<LocalDefId>,
|
||||
) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
|
||||
if def.param_did.is_none() {
|
||||
if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) {
|
||||
return tcx.promoted_mir_of_const_arg(ty::WithOptParam { param_did, ..def });
|
||||
if let Some(param_did) = tcx.opt_const_param_of(def.did) {
|
||||
return tcx.promoted_mir_of_const_arg((def.did, param_did));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue