Skip to content

Commit

Permalink
continue mir pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Jul 15, 2020
1 parent 316128c commit b615b98
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
});
Expand Down
19 changes: 19 additions & 0 deletions src/librustc_middle/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 14 additions & 13 deletions src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,33 +211,31 @@ 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()) }
}

/// Fetch the MIR for a given `DefId` up till the point where it is
/// 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()) }
}
Expand All @@ -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`
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand All @@ -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>(
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
25 changes: 16 additions & 9 deletions src/librustc_mir/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down

0 comments on commit b615b98

Please sign in to comment.