continue mir pipeline

This commit is contained in:
Bastian Kauschke 2020-07-03 22:15:27 +02:00
parent 316128c38a
commit b615b98f33
11 changed files with 78 additions and 31 deletions

View file

@ -891,7 +891,8 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
mir::transform::check_unsafety::check_unsafety(tcx, def_id);
if tcx.hir().body_const_context(def_id).is_some() {
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id);
tcx.ensure()
.mir_drops_elaborated_and_const_checked(ty::WithOptParam::dummy(def_id));
}
}
});

View file

@ -14,8 +14,27 @@ macro_rules! arena_types {
[] layouts: rustc_target::abi::Layout, rustc_target::abi::Layout;
// AdtDef are interned and compared by address
[] adt_def: rustc_middle::ty::AdtDef, rustc_middle::ty::AdtDef;
[] steal_mir:
rustc_middle::ty::steal::Steal<rustc_middle::mir::Body<$tcx>>,
rustc_middle::ty::steal::Steal<rustc_middle::mir::Body<$tcx>>;
[] mir: rustc_middle::mir::Body<$tcx>, rustc_middle::mir::Body<$tcx>;
[] steal_promoted:
rustc_middle::ty::steal::Steal<
rustc_index::vec::IndexVec<
rustc_middle::mir::Promoted,
rustc_middle::mir::Body<$tcx>
>
>,
rustc_middle::ty::steal::Steal<
rustc_index::vec::IndexVec<
rustc_middle::mir::Promoted,
rustc_middle::mir::Body<$tcx>
>
>;
[decode] tables: rustc_middle::ty::TypeckTables<$tcx>, rustc_middle::ty::TypeckTables<'_x>;
[decode] borrowck_result:
rustc_middle::mir::BorrowCheckResult<$tcx>,
rustc_middle::mir::BorrowCheckResult<'_x>;
[] const_allocs: rustc_middle::mir::interpret::Allocation, rustc_middle::mir::interpret::Allocation;
// Required for the incremental on-disk cache
[few, decode] mir_keys: rustc_hir::def_id::DefIdSet, rustc_hir::def_id::DefIdSet;

View file

@ -211,8 +211,7 @@ rustc_queries! {
/// Fetch the MIR for a given `DefId` right after it's built - this includes
/// unreachable code.
query mir_built(key: LocalDefId) -> Steal<mir::Body<'tcx>> {
storage(ArenaCacheSelector<'tcx>)
query mir_built(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> {
desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.to_def_id()) }
}
@ -220,24 +219,23 @@ rustc_queries! {
/// ready for const qualification.
///
/// See the README for the `mir` module for details.
query mir_const(key: DefId) -> Steal<mir::Body<'tcx>> {
desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key) }
storage(ArenaCacheSelector<'tcx>)
query mir_const(key: DefId) -> &'tcx Steal<mir::Body<'tcx>> {
desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key) }
no_hash
}
query mir_drops_elaborated_and_const_checked(key: LocalDefId) -> Steal<mir::Body<'tcx>> {
storage(ArenaCacheSelector<'tcx>)
query mir_drops_elaborated_and_const_checked(
key: ty::WithOptParam<LocalDefId>
) -> &'tcx Steal<mir::Body<'tcx>> {
no_hash
desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.to_def_id()) }
desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
}
query mir_validated(key: LocalDefId) ->
(
Steal<mir::Body<'tcx>>,
Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
&'tcx Steal<mir::Body<'tcx>>,
&'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
) {
storage(ArenaCacheSelector<'tcx>)
no_hash
desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
}
@ -249,7 +247,10 @@ rustc_queries! {
cache_on_disk_if { key.is_local() }
}
query optimized_mir_of_const_arg(key: ty::WithOptParam<LocalDefId>) -> &'tcx mir::Body<'tcx> {
desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
desc {
|tcx| "optimizing MIR for the potential const argument `{}`",
tcx.def_path_str(key.did.to_def_id())
}
}
/// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
@ -599,7 +600,7 @@ rustc_queries! {
BorrowChecking {
/// Borrow-checks the function body. If this is a closure, returns
/// additional requirements that the closure's creator must verify.
query mir_borrowck(key: LocalDefId) -> mir::BorrowCheckResult<'tcx> {
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
storage(ArenaCacheSelector<'tcx>)
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if(tcx, opt_result) {

View file

@ -980,15 +980,15 @@ pub struct GlobalCtxt<'tcx> {
}
impl<'tcx> TyCtxt<'tcx> {
pub fn alloc_steal_mir(self, mir: Body<'tcx>) -> Steal<Body<'tcx>> {
Steal::new(mir)
pub fn alloc_steal_mir(self, mir: Body<'tcx>) -> &'tcx Steal<Body<'tcx>> {
self.arena.alloc(Steal::new(mir))
}
pub fn alloc_steal_promoted(
self,
promoted: IndexVec<Promoted, Body<'tcx>>,
) -> Steal<IndexVec<Promoted, Body<'tcx>>> {
Steal::new(promoted)
) -> &'tcx Steal<IndexVec<Promoted, Body<'tcx>>> {
self.arena.alloc(Steal::new(promoted))
}
pub fn alloc_adt_def(

View file

@ -90,7 +90,7 @@ pub fn provide(providers: &mut Providers) {
*providers = Providers { mir_borrowck, ..*providers };
}
fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> BorrowCheckResult<'_> {
fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx BorrowCheckResult<'tcx> {
let (input_body, promoted) = tcx.mir_validated(def_id);
debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id.to_def_id()));
@ -101,7 +101,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> BorrowCheckResult<'_> {
});
debug!("mir_borrowck done");
opt_closure_req
tcx.arena.alloc(opt_closure_req)
}
fn do_mir_borrowck<'a, 'tcx>(

View file

@ -411,7 +411,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
match instance {
ty::InstanceDef::Item(def) => {
if self.tcx.is_mir_available(def.did) {
Ok(self.tcx.optimized_mir(def.did))
if let Some(def) = def.as_local() {
Ok(self.tcx.optimized_mir_of_const_arg(def))
} else {
Ok(self.tcx.optimized_mir(def.did))
}
} else {
throw_unsup!(NoMirFor(def.did))
}

View file

@ -235,7 +235,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
}
/// Make MIR ready for const evaluation. This is run on all MIR, not just on consts!
fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> Steal<Body<'_>> {
fn mir_const<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal<Body<'tcx>> {
let def_id = def_id.expect_local();
// Unsafety check uses the raw mir, so make sure it is run.
@ -267,7 +267,7 @@ fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> Steal<Body<'_>> {
fn mir_validated(
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
) -> (Steal<Body<'tcx>>, Steal<IndexVec<Promoted, Body<'tcx>>>) {
) -> (&'tcx Steal<Body<'tcx>>, &'tcx Steal<IndexVec<Promoted, Body<'tcx>>>) {
// Ensure that we compute the `mir_const_qualif` for constants at
// this point, before we steal the mir-const result.
let _ = tcx.mir_const_qualif(def_id.to_def_id());
@ -305,17 +305,24 @@ fn mir_validated(
fn mir_drops_elaborated_and_const_checked<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
) -> Steal<Body<'tcx>> {
def: ty::WithOptParam<LocalDefId>,
) -> &'tcx Steal<Body<'tcx>> {
if def.param_did.is_none() {
if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) {
return tcx
.mir_drops_elaborated_and_const_checked(ty::WithOptParam { param_did, ..def });
}
}
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to
// execute before we can steal.
tcx.ensure().mir_borrowck(def_id);
tcx.ensure().mir_borrowck(def.did);
let (body, _) = tcx.mir_validated(def_id);
let (body, _) = tcx.mir_validated(def.did);
let mut body = body.steal();
run_post_borrowck_cleanup_passes(tcx, &mut body, def_id, None);
check_consts::post_drop_elaboration::check_live_drops(tcx, def_id, &body);
run_post_borrowck_cleanup_passes(tcx, &mut body, def.did, None);
check_consts::post_drop_elaboration::check_live_drops(tcx, def.did, &body);
tcx.alloc_steal_mir(body)
}
@ -458,7 +465,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptParam<LocalDefId>) -> Bo
return shim::build_adt_ctor(tcx, def.did.to_def_id());
}
let mut body = tcx.mir_drops_elaborated_and_const_checked(def.did).steal();
let mut body = tcx.mir_drops_elaborated_and_const_checked(def).steal();
run_optimization_passes(tcx, &mut body, def.did, None);
debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR");

View file

@ -21,7 +21,7 @@ use rustc_target::spec::PanicStrategy;
use super::lints;
crate fn mir_built(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::steal::Steal<Body<'_>> {
crate fn mir_built<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx ty::steal::Steal<Body<'tcx>> {
tcx.alloc_steal_mir(mir_build(tcx, def_id))
}

View file

@ -30,6 +30,11 @@ note: ...which requires const-evaluating `<impl at $DIR/issue-24949-assoc-const-
|
LL | const BAR: u32 = IMPL_REF_BAR;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires optimizing MIR for the potential const argument `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 13:2>::BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
|
LL | const BAR: u32 = IMPL_REF_BAR;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires optimizing MIR for `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 13:2>::BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
|

View file

@ -30,6 +30,11 @@ note: ...which requires const-evaluating `FooDefault::BAR`...
|
LL | const BAR: u32 = DEFAULT_REF_BAR;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires optimizing MIR for the potential const argument `FooDefault::BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
|
LL | const BAR: u32 = DEFAULT_REF_BAR;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires optimizing MIR for `FooDefault::BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
|

View file

@ -30,6 +30,11 @@ note: ...which requires const-evaluating `<impl at $DIR/issue-24949-assoc-const-
|
LL | const BAR: u32 = TRAIT_REF_BAR;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires optimizing MIR for the potential const argument `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 13:2>::BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5
|
LL | const BAR: u32 = TRAIT_REF_BAR;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires optimizing MIR for `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 13:2>::BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5
|