Skip to content

Commit 71c9dd5

Browse files
committed
Refactor generator interior types calculation
1 parent 8f58a71 commit 71c9dd5

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/librustc/query/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ rustc_queries! {
108108
/// unreachable code.
109109
query mir_built(_: DefId) -> &'tcx Steal<mir::BodyCache<'tcx>> {}
110110

111+
/// Compute the generator interior types for a given `DefId`
112+
/// (if it corresponds to a generator), for use in determining
113+
/// generator auto trait implementation
114+
query mir_generator_interior(_: DefId) -> &'tcx Steal<mir::BodyCache<'tcx>> {}
115+
111116
/// Fetch the MIR for a given `DefId` up till the point where it is
112117
/// ready for const evaluation.
113118
///

src/librustc/traits/select.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -2807,10 +2807,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
28072807

28082808
let mut used_types = Vec::new();
28092809

2810-
// Note - while we use `optimized_mir`, the .generator_interior_tys
2811-
// field is only set during construction of the original MIR,
2812-
// and is unaffected by optimizations
2813-
let interior_tys = self.tcx().optimized_mir(did).generator_interior_tys
2810+
// We use `mir_validated` since earlier queries (e.g. `mir_const`)
2811+
// may be been stolen by the time this code runs. However, `generator_interior_tys`
2812+
// is computed early on and never modified, so it's fine to use
2813+
// a later query.
2814+
let mir = self.tcx().mir_validated(did).0.borrow();
2815+
let interior_tys = mir.generator_interior_tys
28142816
.as_ref().expect("Missing generator interior types!");
28152817

28162818
for ty in interior_tys {

src/librustc_mir/transform/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub(crate) fn provide(providers: &mut Providers<'_>) {
4646
mir_const,
4747
mir_const_qualif,
4848
mir_validated,
49+
mir_generator_interior,
4950
optimized_mir,
5051
is_mir_available,
5152
promoted_mir,
@@ -98,7 +99,12 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet {
9899
}
99100

100101
fn mir_built(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal<BodyCache<'_>> {
101-
let mut mir = build::mir_build(tcx, def_id);
102+
let mir = build::mir_build(tcx, def_id);
103+
tcx.alloc_steal_mir(mir)
104+
}
105+
106+
fn mir_generator_interior(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal<BodyCache<'_>> {
107+
let mut mir = tcx.mir_const(def_id).steal();
102108
if let ty::Generator(..) = tcx.type_of(def_id).kind {
103109
let interior_types = generator::generator_interior_tys(tcx, def_id, &mir);
104110
mir.generator_interior_tys = Some(interior_types);
@@ -248,7 +254,7 @@ fn mir_validated(
248254
// this point, before we steal the mir-const result.
249255
let _ = tcx.mir_const_qualif(def_id);
250256

251-
let mut body = tcx.mir_const(def_id).steal();
257+
let mut body = tcx.mir_generator_interior(def_id).steal();
252258
let promote_pass = promote_consts::PromoteTemps::default();
253259
run_passes(tcx, &mut body, InstanceDef::Item(def_id), None, MirPhase::Validated, &[
254260
// What we need to run borrowck etc.

0 commit comments

Comments
 (0)