Skip to content

Commit b615b98

Browse files
committed
continue mir pipeline
1 parent 316128c commit b615b98

File tree

11 files changed

+78
-31
lines changed

11 files changed

+78
-31
lines changed

src/librustc_interface/passes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,8 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
891891
mir::transform::check_unsafety::check_unsafety(tcx, def_id);
892892

893893
if tcx.hir().body_const_context(def_id).is_some() {
894-
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id);
894+
tcx.ensure()
895+
.mir_drops_elaborated_and_const_checked(ty::WithOptParam::dummy(def_id));
895896
}
896897
}
897898
});

src/librustc_middle/arena.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,27 @@ macro_rules! arena_types {
1414
[] layouts: rustc_target::abi::Layout, rustc_target::abi::Layout;
1515
// AdtDef are interned and compared by address
1616
[] adt_def: rustc_middle::ty::AdtDef, rustc_middle::ty::AdtDef;
17+
[] steal_mir:
18+
rustc_middle::ty::steal::Steal<rustc_middle::mir::Body<$tcx>>,
19+
rustc_middle::ty::steal::Steal<rustc_middle::mir::Body<$tcx>>;
1720
[] mir: rustc_middle::mir::Body<$tcx>, rustc_middle::mir::Body<$tcx>;
21+
[] steal_promoted:
22+
rustc_middle::ty::steal::Steal<
23+
rustc_index::vec::IndexVec<
24+
rustc_middle::mir::Promoted,
25+
rustc_middle::mir::Body<$tcx>
26+
>
27+
>,
28+
rustc_middle::ty::steal::Steal<
29+
rustc_index::vec::IndexVec<
30+
rustc_middle::mir::Promoted,
31+
rustc_middle::mir::Body<$tcx>
32+
>
33+
>;
1834
[decode] tables: rustc_middle::ty::TypeckTables<$tcx>, rustc_middle::ty::TypeckTables<'_x>;
35+
[decode] borrowck_result:
36+
rustc_middle::mir::BorrowCheckResult<$tcx>,
37+
rustc_middle::mir::BorrowCheckResult<'_x>;
1938
[] const_allocs: rustc_middle::mir::interpret::Allocation, rustc_middle::mir::interpret::Allocation;
2039
// Required for the incremental on-disk cache
2140
[few, decode] mir_keys: rustc_hir::def_id::DefIdSet, rustc_hir::def_id::DefIdSet;

src/librustc_middle/query/mod.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,33 +211,31 @@ rustc_queries! {
211211

212212
/// Fetch the MIR for a given `DefId` right after it's built - this includes
213213
/// unreachable code.
214-
query mir_built(key: LocalDefId) -> Steal<mir::Body<'tcx>> {
215-
storage(ArenaCacheSelector<'tcx>)
214+
query mir_built(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> {
216215
desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.to_def_id()) }
217216
}
218217

219218
/// Fetch the MIR for a given `DefId` up till the point where it is
220219
/// ready for const qualification.
221220
///
222221
/// See the README for the `mir` module for details.
223-
query mir_const(key: DefId) -> Steal<mir::Body<'tcx>> {
224-
desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key) }
225-
storage(ArenaCacheSelector<'tcx>)
222+
query mir_const(key: DefId) -> &'tcx Steal<mir::Body<'tcx>> {
223+
desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key) }
226224
no_hash
227225
}
228226

229-
query mir_drops_elaborated_and_const_checked(key: LocalDefId) -> Steal<mir::Body<'tcx>> {
230-
storage(ArenaCacheSelector<'tcx>)
227+
query mir_drops_elaborated_and_const_checked(
228+
key: ty::WithOptParam<LocalDefId>
229+
) -> &'tcx Steal<mir::Body<'tcx>> {
231230
no_hash
232-
desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.to_def_id()) }
231+
desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
233232
}
234233

235234
query mir_validated(key: LocalDefId) ->
236235
(
237-
Steal<mir::Body<'tcx>>,
238-
Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
236+
&'tcx Steal<mir::Body<'tcx>>,
237+
&'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
239238
) {
240-
storage(ArenaCacheSelector<'tcx>)
241239
no_hash
242240
desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
243241
}
@@ -249,7 +247,10 @@ rustc_queries! {
249247
cache_on_disk_if { key.is_local() }
250248
}
251249
query optimized_mir_of_const_arg(key: ty::WithOptParam<LocalDefId>) -> &'tcx mir::Body<'tcx> {
252-
desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
250+
desc {
251+
|tcx| "optimizing MIR for the potential const argument `{}`",
252+
tcx.def_path_str(key.did.to_def_id())
253+
}
253254
}
254255

255256
/// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
@@ -599,7 +600,7 @@ rustc_queries! {
599600
BorrowChecking {
600601
/// Borrow-checks the function body. If this is a closure, returns
601602
/// additional requirements that the closure's creator must verify.
602-
query mir_borrowck(key: LocalDefId) -> mir::BorrowCheckResult<'tcx> {
603+
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
603604
storage(ArenaCacheSelector<'tcx>)
604605
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
605606
cache_on_disk_if(tcx, opt_result) {

src/librustc_middle/ty/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,15 @@ pub struct GlobalCtxt<'tcx> {
980980
}
981981

982982
impl<'tcx> TyCtxt<'tcx> {
983-
pub fn alloc_steal_mir(self, mir: Body<'tcx>) -> Steal<Body<'tcx>> {
984-
Steal::new(mir)
983+
pub fn alloc_steal_mir(self, mir: Body<'tcx>) -> &'tcx Steal<Body<'tcx>> {
984+
self.arena.alloc(Steal::new(mir))
985985
}
986986

987987
pub fn alloc_steal_promoted(
988988
self,
989989
promoted: IndexVec<Promoted, Body<'tcx>>,
990-
) -> Steal<IndexVec<Promoted, Body<'tcx>>> {
991-
Steal::new(promoted)
990+
) -> &'tcx Steal<IndexVec<Promoted, Body<'tcx>>> {
991+
self.arena.alloc(Steal::new(promoted))
992992
}
993993

994994
pub fn alloc_adt_def(

src/librustc_mir/borrow_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn provide(providers: &mut Providers) {
9090
*providers = Providers { mir_borrowck, ..*providers };
9191
}
9292

93-
fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> BorrowCheckResult<'_> {
93+
fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx BorrowCheckResult<'tcx> {
9494
let (input_body, promoted) = tcx.mir_validated(def_id);
9595
debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id.to_def_id()));
9696

@@ -101,7 +101,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> BorrowCheckResult<'_> {
101101
});
102102
debug!("mir_borrowck done");
103103

104-
opt_closure_req
104+
tcx.arena.alloc(opt_closure_req)
105105
}
106106

107107
fn do_mir_borrowck<'a, 'tcx>(

src/librustc_mir/interpret/eval_context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
411411
match instance {
412412
ty::InstanceDef::Item(def) => {
413413
if self.tcx.is_mir_available(def.did) {
414-
Ok(self.tcx.optimized_mir(def.did))
414+
if let Some(def) = def.as_local() {
415+
Ok(self.tcx.optimized_mir_of_const_arg(def))
416+
} else {
417+
Ok(self.tcx.optimized_mir(def.did))
418+
}
415419
} else {
416420
throw_unsup!(NoMirFor(def.did))
417421
}

src/librustc_mir/transform/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
235235
}
236236

237237
/// Make MIR ready for const evaluation. This is run on all MIR, not just on consts!
238-
fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> Steal<Body<'_>> {
238+
fn mir_const<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal<Body<'tcx>> {
239239
let def_id = def_id.expect_local();
240240

241241
// 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<'_>> {
267267
fn mir_validated(
268268
tcx: TyCtxt<'tcx>,
269269
def_id: LocalDefId,
270-
) -> (Steal<Body<'tcx>>, Steal<IndexVec<Promoted, Body<'tcx>>>) {
270+
) -> (&'tcx Steal<Body<'tcx>>, &'tcx Steal<IndexVec<Promoted, Body<'tcx>>>) {
271271
// Ensure that we compute the `mir_const_qualif` for constants at
272272
// this point, before we steal the mir-const result.
273273
let _ = tcx.mir_const_qualif(def_id.to_def_id());
@@ -305,17 +305,24 @@ fn mir_validated(
305305

306306
fn mir_drops_elaborated_and_const_checked<'tcx>(
307307
tcx: TyCtxt<'tcx>,
308-
def_id: LocalDefId,
309-
) -> Steal<Body<'tcx>> {
308+
def: ty::WithOptParam<LocalDefId>,
309+
) -> &'tcx Steal<Body<'tcx>> {
310+
if def.param_did.is_none() {
311+
if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) {
312+
return tcx
313+
.mir_drops_elaborated_and_const_checked(ty::WithOptParam { param_did, ..def });
314+
}
315+
}
316+
310317
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to
311318
// execute before we can steal.
312-
tcx.ensure().mir_borrowck(def_id);
319+
tcx.ensure().mir_borrowck(def.did);
313320

314-
let (body, _) = tcx.mir_validated(def_id);
321+
let (body, _) = tcx.mir_validated(def.did);
315322
let mut body = body.steal();
316323

317-
run_post_borrowck_cleanup_passes(tcx, &mut body, def_id, None);
318-
check_consts::post_drop_elaboration::check_live_drops(tcx, def_id, &body);
324+
run_post_borrowck_cleanup_passes(tcx, &mut body, def.did, None);
325+
check_consts::post_drop_elaboration::check_live_drops(tcx, def.did, &body);
319326
tcx.alloc_steal_mir(body)
320327
}
321328

@@ -458,7 +465,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptParam<LocalDefId>) -> Bo
458465
return shim::build_adt_ctor(tcx, def.did.to_def_id());
459466
}
460467

461-
let mut body = tcx.mir_drops_elaborated_and_const_checked(def.did).steal();
468+
let mut body = tcx.mir_drops_elaborated_and_const_checked(def).steal();
462469
run_optimization_passes(tcx, &mut body, def.did, None);
463470

464471
debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR");

src/librustc_mir_build/build/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_target::spec::PanicStrategy;
2121

2222
use super::lints;
2323

24-
crate fn mir_built(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::steal::Steal<Body<'_>> {
24+
crate fn mir_built<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx ty::steal::Steal<Body<'tcx>> {
2525
tcx.alloc_steal_mir(mir_build(tcx, def_id))
2626
}
2727

src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ note: ...which requires const-evaluating `<impl at $DIR/issue-24949-assoc-const-
3030
|
3131
LL | const BAR: u32 = IMPL_REF_BAR;
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
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`...
34+
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
35+
|
36+
LL | const BAR: u32 = IMPL_REF_BAR;
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3338
note: ...which requires optimizing MIR for `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 13:2>::BAR`...
3439
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
3540
|

src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ note: ...which requires const-evaluating `FooDefault::BAR`...
3030
|
3131
LL | const BAR: u32 = DEFAULT_REF_BAR;
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
note: ...which requires optimizing MIR for the potential const argument `FooDefault::BAR`...
34+
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
35+
|
36+
LL | const BAR: u32 = DEFAULT_REF_BAR;
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3338
note: ...which requires optimizing MIR for `FooDefault::BAR`...
3439
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
3540
|

0 commit comments

Comments
 (0)