Skip to content

Commit b6c5983

Browse files
committed
Auto merge of rust-lang#107421 - cjgillot:drop-tracking-mir, r=oli-obk
Enable -Zdrop-tracking-mir by default This PR enables the `drop-tracking-mir` flag by default. This flag was initially implemented in rust-lang#101692. This flag computes auto-traits on generators based on their analysis MIR, instead of trying to compute on the HIR body. This removes the need for HIR-based drop-tracking, as we can now reuse the same code to compute generator witness types and to compute generator interior fields.
2 parents 03c199a + f0f12d7 commit b6c5983

File tree

310 files changed

+795
-8349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

310 files changed

+795
-8349
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ fn push_debuginfo_type_name<'tcx>(
426426
| ty::Placeholder(..)
427427
| ty::Alias(..)
428428
| ty::Bound(..)
429-
| ty::GeneratorWitnessMIR(..)
430429
| ty::GeneratorWitness(..) => {
431430
bug!(
432431
"debuginfo: Trying to create type name for \

compiler/rustc_const_eval/src/const_eval/valtrees.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
152152
// FIXME(oli-obk): we can probably encode closures just like structs
153153
| ty::Closure(..)
154154
| ty::Generator(..)
155-
| ty::GeneratorWitness(..) |ty::GeneratorWitnessMIR(..)=> Err(ValTreeCreationError::NonSupportedType),
155+
| ty::GeneratorWitness(..) => Err(ValTreeCreationError::NonSupportedType),
156156
}
157157
}
158158

@@ -280,7 +280,6 @@ pub fn valtree_to_const_value<'tcx>(
280280
| ty::Closure(..)
281281
| ty::Generator(..)
282282
| ty::GeneratorWitness(..)
283-
| ty::GeneratorWitnessMIR(..)
284283
| ty::FnPtr(_)
285284
| ty::RawPtr(_)
286285
| ty::Str

compiler/rustc_const_eval/src/interpret/eval_context.rs

-1
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
963963
| ty::Ref(..)
964964
| ty::Generator(..)
965965
| ty::GeneratorWitness(..)
966-
| ty::GeneratorWitnessMIR(..)
967966
| ty::Array(..)
968967
| ty::Closure(..)
969968
| ty::Never

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
100100
| ty::Dynamic(_, _, _)
101101
| ty::Closure(_, _)
102102
| ty::Generator(_, _, _)
103-
| ty::GeneratorWitness(_)
104-
| ty::GeneratorWitnessMIR(_, _)
103+
| ty::GeneratorWitness(..)
105104
| ty::Never
106105
| ty::Tuple(_)
107106
| ty::Error(_) => ConstValue::from_target_usize(0u64, &tcx),

compiler/rustc_const_eval/src/interpret/validity.rs

-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
583583
| ty::Bound(..)
584584
| ty::Param(..)
585585
| ty::Alias(..)
586-
| ty::GeneratorWitnessMIR(..)
587586
| ty::GeneratorWitness(..) => bug!("Encountered invalid type {:?}", ty),
588587
}
589588
}

compiler/rustc_const_eval/src/util/type_name.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
6464

6565
ty::Alias(ty::Weak, _) => bug!("type_name: unexpected weak projection"),
6666
ty::Alias(ty::Inherent, _) => bug!("type_name: unexpected inherent projection"),
67-
ty::GeneratorWitness(_) => bug!("type_name: unexpected `GeneratorWitness`"),
68-
ty::GeneratorWitnessMIR(..) => bug!("type_name: unexpected `GeneratorWitnessMIR`"),
67+
ty::GeneratorWitness(..) => bug!("type_name: unexpected `GeneratorWitness`"),
6968
}
7069
}
7170

compiler/rustc_error_codes/src/error_codes/E0698.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
When using generators (or async) all type variables must be bound so a
24
generator can be constructed.
35

46
Erroneous code example:
57

6-
```edition2018,compile_fail,E0698
8+
```edition2018,compile_fail,E0282
79
async fn bar<T>() -> () {}
810
911
async fn foo() {

compiler/rustc_hir_analysis/src/check/check.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1579,13 +1579,7 @@ fn opaque_type_cycle_error(
15791579
label_match(capture.place.ty(), capture.get_path_span(tcx));
15801580
}
15811581
// Label any generator locals that capture the opaque
1582-
for interior_ty in
1583-
typeck_results.generator_interior_types.as_ref().skip_binder()
1584-
{
1585-
label_match(interior_ty.ty, interior_ty.span);
1586-
}
1587-
if tcx.sess.opts.unstable_opts.drop_tracking_mir
1588-
&& let DefKind::Generator = tcx.def_kind(closure_def_id)
1582+
if let DefKind::Generator = tcx.def_kind(closure_def_id)
15891583
&& let Some(generator_layout) = tcx.mir_generator_witnesses(closure_def_id)
15901584
{
15911585
for interior_ty in &generator_layout.field_tys {
@@ -1603,7 +1597,6 @@ fn opaque_type_cycle_error(
16031597
}
16041598

16051599
pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
1606-
debug_assert!(tcx.sess.opts.unstable_opts.drop_tracking_mir);
16071600
debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Generator));
16081601

16091602
let typeck = tcx.typeck(def_id);

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ impl<'tcx> InherentCollect<'tcx> {
157157
| ty::Closure(..)
158158
| ty::Generator(..)
159159
| ty::GeneratorWitness(..)
160-
| ty::GeneratorWitnessMIR(..)
161160
| ty::Bound(..)
162161
| ty::Placeholder(_)
163162
| ty::Infer(_) => {

compiler/rustc_hir_analysis/src/coherence/orphan.rs

-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ fn do_orphan_check_impl<'tcx>(
245245
ty::Closure(..)
246246
| ty::Generator(..)
247247
| ty::GeneratorWitness(..)
248-
| ty::GeneratorWitnessMIR(..)
249248
| ty::Bound(..)
250249
| ty::Placeholder(..)
251250
| ty::Infer(..) => {

compiler/rustc_hir_analysis/src/variance/constraints.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
314314
// types, where we use Error as the Self type
315315
}
316316

317-
ty::Placeholder(..)
318-
| ty::GeneratorWitness(..)
319-
| ty::GeneratorWitnessMIR(..)
320-
| ty::Bound(..)
321-
| ty::Infer(..) => {
317+
ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Bound(..) | ty::Infer(..) => {
322318
bug!("unexpected type encountered in variance inference: {}", ty);
323319
}
324320
}

compiler/rustc_hir_typeck/src/cast.rs

-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
129129
| ty::Float(_)
130130
| ty::Array(..)
131131
| ty::GeneratorWitness(..)
132-
| ty::GeneratorWitnessMIR(..)
133132
| ty::RawPtr(_)
134133
| ty::Ref(..)
135134
| ty::FnDef(..)

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -509,21 +509,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
509509
typeck_results.rvalue_scopes = rvalue_scopes;
510510
}
511511

512-
pub(in super::super) fn resolve_generator_interiors(&self, def_id: DefId) {
513-
if self.tcx.sess.opts.unstable_opts.drop_tracking_mir {
514-
self.save_generator_interior_predicates(def_id);
515-
return;
516-
}
517-
518-
self.select_obligations_where_possible(|_| {});
519-
520-
let mut generators = self.deferred_generator_interiors.borrow_mut();
521-
for (_, body_id, interior, kind) in generators.drain(..) {
522-
crate::generator_interior::resolve_interior(self, def_id, body_id, interior, kind);
523-
self.select_obligations_where_possible(|_| {});
524-
}
525-
}
526-
527512
/// Unify the inference variables corresponding to generator witnesses, and save all the
528513
/// predicates that were stalled on those inference variables.
529514
///
@@ -533,7 +518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
533518
/// We must not attempt to select obligations after this method has run, or risk query cycle
534519
/// ICE.
535520
#[instrument(level = "debug", skip(self))]
536-
fn save_generator_interior_predicates(&self, def_id: DefId) {
521+
pub(in super::super) fn resolve_generator_interiors(&self, def_id: DefId) {
537522
// Try selecting all obligations that are not blocked on inference variables.
538523
// Once we start unifying generator witnesses, trying to select obligations on them will
539524
// trigger query cycle ICEs, as doing so requires MIR.
@@ -550,7 +535,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
550535
self.tcx,
551536
self.tcx.typeck_root_def_id(expr_def_id.to_def_id()),
552537
);
553-
let witness = Ty::new_generator_witness_mir(self.tcx, expr_def_id.to_def_id(), args);
538+
let witness = Ty::new_generator_witness(self.tcx, expr_def_id.to_def_id(), args);
554539

555540
// Unify `interior` with `witness` and collect all the resulting obligations.
556541
let span = self.tcx.hir().body(body_id).value.span;

0 commit comments

Comments
 (0)