Skip to content

Commit 16f39c5

Browse files
committed
Revert "Auto merge of rust-lang#101692 - cjgillot:generator-lazy-witness, r=oli-obk"
This reverts commit 6cd6bad, reversing changes made to 7d4df2d.
1 parent 869baa3 commit 16f39c5

File tree

270 files changed

+601
-6273
lines changed

Some content is hidden

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

270 files changed

+601
-6273
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ fn push_debuginfo_type_name<'tcx>(
414414
| ty::Placeholder(..)
415415
| ty::Alias(..)
416416
| ty::Bound(..)
417-
| ty::GeneratorWitnessMIR(..)
418417
| ty::GeneratorWitness(..) => {
419418
bug!(
420419
"debuginfo: Trying to create type name for \

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
151151
// FIXME(oli-obk): we can probably encode closures just like structs
152152
| ty::Closure(..)
153153
| ty::Generator(..)
154-
| ty::GeneratorWitness(..) |ty::GeneratorWitnessMIR(..)=> Err(ValTreeCreationError::NonSupportedType),
154+
| ty::GeneratorWitness(..) => Err(ValTreeCreationError::NonSupportedType),
155155
}
156156
}
157157

@@ -314,7 +314,6 @@ pub fn valtree_to_const_value<'tcx>(
314314
| ty::Closure(..)
315315
| ty::Generator(..)
316316
| ty::GeneratorWitness(..)
317-
| ty::GeneratorWitnessMIR(..)
318317
| ty::FnPtr(_)
319318
| ty::RawPtr(_)
320319
| ty::Str

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
101101
| ty::Closure(_, _)
102102
| ty::Generator(_, _, _)
103103
| ty::GeneratorWitness(_)
104-
| ty::GeneratorWitnessMIR(_, _)
105104
| ty::Never
106105
| ty::Tuple(_)
107106
| ty::Error(_) => ConstValue::from_machine_usize(0u64, &tcx),

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
602602
| ty::Bound(..)
603603
| ty::Param(..)
604604
| ty::Alias(..)
605-
| ty::GeneratorWitnessMIR(..)
606605
| ty::GeneratorWitness(..) => bug!("Encountered invalid type {:?}", ty),
607606
}
608607
}

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,12 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
372372
return;
373373
};
374374

375-
let Some(f_ty) = layout.field_tys.get(local) else {
375+
let Some(&f_ty) = layout.field_tys.get(local) else {
376376
self.fail(location, format!("Out of bounds local {:?} for {:?}", local, parent_ty));
377377
return;
378378
};
379379

380-
f_ty.ty
380+
f_ty
381381
} else {
382382
let Some(f_ty) = substs.as_generator().prefix_tys().nth(f.index()) else {
383383
fail_out_of_bounds(self, location);

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
6464
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),
6565

6666
ty::GeneratorWitness(_) => bug!("type_name: unexpected `GeneratorWitness`"),
67-
ty::GeneratorWitnessMIR(..) => bug!("type_name: unexpected `GeneratorWitnessMIR`"),
6867
}
6968
}
7069

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,8 +2103,8 @@ pub enum LocalSource {
21032103
}
21042104

21052105
/// Hints at the original code for a `match _ { .. }`.
2106-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
2107-
#[derive(HashStable_Generic, Encodable, Decodable)]
2106+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)]
2107+
#[derive(HashStable_Generic)]
21082108
pub enum MatchSource {
21092109
/// A `match _ { .. }`.
21102110
Normal,

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir::{ItemKind, Node, PathSegment};
1414
use rustc_infer::infer::opaque_types::ConstrainOpaqueTypeRegionVisitor;
1515
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
1616
use rustc_infer::infer::{DefiningAnchor, RegionVariableOrigin, TyCtxtInferExt};
17-
use rustc_infer::traits::{Obligation, TraitEngineExt as _};
17+
use rustc_infer::traits::Obligation;
1818
use rustc_lint::builtin::REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS;
1919
use rustc_middle::hir::nested_filter;
2020
use rustc_middle::middle::stability::EvalResult;
@@ -28,7 +28,7 @@ use rustc_span::{self, Span};
2828
use rustc_target::spec::abi::Abi;
2929
use rustc_trait_selection::traits::error_reporting::on_unimplemented::OnUnimplementedDirective;
3030
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
31-
use rustc_trait_selection::traits::{self, ObligationCtxt, TraitEngine, TraitEngineExt as _};
31+
use rustc_trait_selection::traits::{self, ObligationCtxt};
3232

3333
use std::ops::ControlFlow;
3434

@@ -1460,8 +1460,7 @@ fn opaque_type_cycle_error(
14601460
for def_id in visitor.opaques {
14611461
let ty_span = tcx.def_span(def_id);
14621462
if !seen.contains(&ty_span) {
1463-
let descr = if ty.is_impl_trait() { "opaque " } else { "" };
1464-
err.span_label(ty_span, &format!("returning this {descr}type `{ty}`"));
1463+
err.span_label(ty_span, &format!("returning this opaque type `{ty}`"));
14651464
seen.insert(ty_span);
14661465
}
14671466
err.span_label(sp, &format!("returning here with type `{ty}`"));
@@ -1508,34 +1507,3 @@ fn opaque_type_cycle_error(
15081507
}
15091508
err.emit()
15101509
}
1511-
1512-
pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
1513-
debug_assert!(tcx.sess.opts.unstable_opts.drop_tracking_mir);
1514-
debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Generator));
1515-
1516-
let typeck = tcx.typeck(def_id);
1517-
let param_env = tcx.param_env(def_id);
1518-
1519-
let generator_interior_predicates = &typeck.generator_interior_predicates[&def_id];
1520-
debug!(?generator_interior_predicates);
1521-
1522-
let infcx = tcx
1523-
.infer_ctxt()
1524-
// typeck writeback gives us predicates with their regions erased.
1525-
// As borrowck already has checked lifetimes, we do not need to do it again.
1526-
.ignoring_regions()
1527-
// Bind opaque types to `def_id` as they should have been checked by borrowck.
1528-
.with_opaque_type_inference(DefiningAnchor::Bind(def_id))
1529-
.build();
1530-
1531-
let mut fulfillment_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
1532-
for (predicate, cause) in generator_interior_predicates {
1533-
let obligation = Obligation::new(tcx, cause.clone(), param_env, *predicate);
1534-
fulfillment_cx.register_predicate_obligation(&infcx, obligation);
1535-
}
1536-
let errors = fulfillment_cx.select_all_or_error(&infcx);
1537-
debug!(?errors);
1538-
if !errors.is_empty() {
1539-
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
1540-
}
1541-
}

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ pub fn provide(providers: &mut Providers) {
105105
region_scope_tree,
106106
collect_return_position_impl_trait_in_trait_tys,
107107
compare_impl_const: compare_impl_item::compare_impl_const_raw,
108-
check_generator_obligations: check::check_generator_obligations,
109108
..*providers
110109
};
111110
}

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ impl<'tcx> InherentCollect<'tcx> {
240240
| ty::Closure(..)
241241
| ty::Generator(..)
242242
| ty::GeneratorWitness(..)
243-
| ty::GeneratorWitnessMIR(..)
244243
| ty::Bound(..)
245244
| ty::Placeholder(_)
246245
| ty::Infer(_) => {

compiler/rustc_hir_analysis/src/variance/constraints.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
293293
// types, where we use Error as the Self type
294294
}
295295

296-
ty::Placeholder(..)
297-
| ty::GeneratorWitness(..)
298-
| ty::GeneratorWitnessMIR(..)
299-
| ty::Bound(..)
300-
| ty::Infer(..) => {
301-
bug!("unexpected type encountered in variance inference: {}", ty);
296+
ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Bound(..) | ty::Infer(..) => {
297+
bug!(
298+
"unexpected type encountered in \
299+
variance inference: {}",
300+
ty
301+
);
302302
}
303303
}
304304
}

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
130130
| ty::Float(_)
131131
| ty::Array(..)
132132
| ty::GeneratorWitness(..)
133-
| ty::GeneratorWitnessMIR(..)
134133
| ty::RawPtr(_)
135134
| ty::Ref(..)
136135
| ty::FnDef(..)

compiler/rustc_hir_typeck/src/check.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,7 @@ pub(super) fn check_fn<'a, 'tcx>(
130130
let gen_ty = if let (Some(_), Some(gen_kind)) = (can_be_generator, body.generator_kind) {
131131
let interior = fcx
132132
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span });
133-
fcx.deferred_generator_interiors.borrow_mut().push((
134-
fn_def_id,
135-
body.id(),
136-
interior,
137-
gen_kind,
138-
));
133+
fcx.deferred_generator_interiors.borrow_mut().push((body.id(), interior, gen_kind));
139134

140135
let (resume_ty, yield_ty) = fcx.resume_yield_tys.unwrap();
141136
Some(GeneratorTypes {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -517,72 +517,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
517517
}
518518

519519
pub(in super::super) fn resolve_generator_interiors(&self, def_id: DefId) {
520-
if self.tcx.sess.opts.unstable_opts.drop_tracking_mir {
521-
self.save_generator_interior_predicates(def_id);
522-
return;
523-
}
524-
525-
self.select_obligations_where_possible(|_| {});
526-
527520
let mut generators = self.deferred_generator_interiors.borrow_mut();
528-
for (_, body_id, interior, kind) in generators.drain(..) {
529-
crate::generator_interior::resolve_interior(self, def_id, body_id, interior, kind);
521+
for (body_id, interior, kind) in generators.drain(..) {
530522
self.select_obligations_where_possible(|_| {});
531-
}
532-
}
533-
534-
/// Unify the inference variables corresponding to generator witnesses, and save all the
535-
/// predicates that were stalled on those inference variables.
536-
///
537-
/// This process allows to conservatively save all predicates that do depend on the generator
538-
/// interior types, for later processing by `check_generator_obligations`.
539-
///
540-
/// We must not attempt to select obligations after this method has run, or risk query cycle
541-
/// ICE.
542-
#[instrument(level = "debug", skip(self))]
543-
fn save_generator_interior_predicates(&self, def_id: DefId) {
544-
// Try selecting all obligations that are not blocked on inference variables.
545-
// Once we start unifying generator witnesses, trying to select obligations on them will
546-
// trigger query cycle ICEs, as doing so requires MIR.
547-
self.select_obligations_where_possible(|_| {});
548-
549-
let generators = std::mem::take(&mut *self.deferred_generator_interiors.borrow_mut());
550-
debug!(?generators);
551-
552-
for &(expr_def_id, body_id, interior, _) in generators.iter() {
553-
debug!(?expr_def_id);
554-
555-
// Create the `GeneratorWitness` type that we will unify with `interior`.
556-
let substs = ty::InternalSubsts::identity_for_item(
557-
self.tcx,
558-
self.tcx.typeck_root_def_id(expr_def_id.to_def_id()),
559-
);
560-
let witness = self.tcx.mk_generator_witness_mir(expr_def_id.to_def_id(), substs);
561-
562-
// Unify `interior` with `witness` and collect all the resulting obligations.
563-
let span = self.tcx.hir().body(body_id).value.span;
564-
let ok = self
565-
.at(&self.misc(span), self.param_env)
566-
.eq(interior, witness)
567-
.expect("Failed to unify generator interior type");
568-
let mut obligations = ok.obligations;
569-
570-
// Also collect the obligations that were unstalled by this unification.
571-
obligations
572-
.extend(self.fulfillment_cx.borrow_mut().drain_unstalled_obligations(&self.infcx));
573-
574-
let obligations = obligations.into_iter().map(|o| (o.predicate, o.cause)).collect();
575-
debug!(?obligations);
576-
self.typeck_results
577-
.borrow_mut()
578-
.generator_interior_predicates
579-
.insert(expr_def_id, obligations);
523+
crate::generator_interior::resolve_interior(self, def_id, body_id, interior, kind);
580524
}
581525
}
582526

583527
#[instrument(skip(self), level = "debug")]
584-
pub(in super::super) fn report_ambiguity_errors(&self) {
585-
let mut errors = self.fulfillment_cx.borrow_mut().collect_remaining_errors();
528+
pub(in super::super) fn select_all_obligations_or_error(&self) {
529+
let mut errors = self.fulfillment_cx.borrow_mut().select_all_or_error(&self);
586530

587531
if !errors.is_empty() {
588532
self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);

compiler/rustc_hir_typeck/src/inherited.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct Inherited<'tcx> {
5656
pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, hir::HirId)>>,
5757

5858
pub(super) deferred_generator_interiors:
59-
RefCell<Vec<(LocalDefId, hir::BodyId, Ty<'tcx>, hir::GeneratorKind)>>,
59+
RefCell<Vec<(hir::BodyId, Ty<'tcx>, hir::GeneratorKind)>>,
6060

6161
pub(super) body_id: Option<hir::BodyId>,
6262

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,24 +294,14 @@ fn typeck_with_fallback<'tcx>(
294294
// Before the generator analysis, temporary scopes shall be marked to provide more
295295
// precise information on types to be captured.
296296
fcx.resolve_rvalue_scopes(def_id.to_def_id());
297+
fcx.resolve_generator_interiors(def_id.to_def_id());
297298

298299
for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) {
299300
let ty = fcx.normalize(span, ty);
300301
fcx.require_type_is_sized(ty, span, code);
301302
}
302303

303-
fcx.select_obligations_where_possible(|_| {});
304-
305-
debug!(pending_obligations = ?fcx.fulfillment_cx.borrow().pending_obligations());
306-
307-
// This must be the last thing before `report_ambiguity_errors`.
308-
fcx.resolve_generator_interiors(def_id.to_def_id());
309-
310-
debug!(pending_obligations = ?fcx.fulfillment_cx.borrow().pending_obligations());
311-
312-
if let None = fcx.infcx.tainted_by_errors() {
313-
fcx.report_ambiguity_errors();
314-
}
304+
fcx.select_all_obligations_or_error();
315305

316306
if let None = fcx.infcx.tainted_by_errors() {
317307
fcx.check_transmutes();

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
545545
assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
546546
self.typeck_results.generator_interior_types =
547547
fcx_typeck_results.generator_interior_types.clone();
548-
for (&expr_def_id, predicates) in fcx_typeck_results.generator_interior_predicates.iter() {
549-
let predicates = self.resolve(predicates.clone(), &self.fcx.tcx.def_span(expr_def_id));
550-
self.typeck_results.generator_interior_predicates.insert(expr_def_id, predicates);
551-
}
552548
}
553549

554550
#[instrument(skip(self), level = "debug")]

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
435435
ty::Closure(..)
436436
| ty::Generator(..)
437437
| ty::GeneratorWitness(..)
438-
| ty::GeneratorWitnessMIR(..)
439438
| ty::Bool
440439
| ty::Char
441440
| ty::Int(..)

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::infer::region_constraints::{Constraint, RegionConstraintData};
1717
use crate::infer::{InferCtxt, InferOk, InferResult, NllRegionVariableOrigin};
1818
use crate::traits::query::{Fallible, NoSolution};
1919
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
20-
use crate::traits::{PredicateObligations, TraitEngine, TraitEngineExt};
20+
use crate::traits::{PredicateObligations, TraitEngine};
2121
use rustc_data_structures::captures::Captures;
2222
use rustc_index::vec::Idx;
2323
use rustc_index::vec::IndexVec;

compiler/rustc_infer/src/infer/freshen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
209209
| ty::Foreign(..)
210210
| ty::Param(..)
211211
| ty::Closure(..)
212-
| ty::GeneratorWitnessMIR(..)
213212
| ty::GeneratorWitness(..) => t.super_fold_with(self),
214213

215214
ty::Placeholder(..) | ty::Bound(..) => bug!("unexpected type {:?}", t),

compiler/rustc_infer/src/infer/outlives/components.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn compute_components<'tcx>(
112112
}
113113

114114
// All regions are bound inside a witness
115-
ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) => (),
115+
ty::GeneratorWitness(..) => (),
116116

117117
// OutlivesTypeParameterEnv -- the actual checking that `X:'a`
118118
// is implied by the environment is done in regionck.

compiler/rustc_infer/src/traits/engine.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,11 @@ pub trait TraitEngine<'tcx>: 'tcx {
3636
obligation: PredicateObligation<'tcx>,
3737
);
3838

39-
fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
39+
fn select_all_or_error(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
4040

41-
fn collect_remaining_errors(&mut self) -> Vec<FulfillmentError<'tcx>>;
41+
fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
4242

4343
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
44-
45-
/// Among all pending obligations, collect those are stalled on a inference variable which has
46-
/// changed since the last call to `select_where_possible`. Those obligations are marked as
47-
/// successful and returned.
48-
fn drain_unstalled_obligations(
49-
&mut self,
50-
infcx: &InferCtxt<'tcx>,
51-
) -> Vec<PredicateObligation<'tcx>>;
5244
}
5345

5446
pub trait TraitEngineExt<'tcx> {
@@ -57,8 +49,6 @@ pub trait TraitEngineExt<'tcx> {
5749
infcx: &InferCtxt<'tcx>,
5850
obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
5951
);
60-
61-
fn select_all_or_error(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
6252
}
6353

6454
impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
@@ -71,13 +61,4 @@ impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
7161
self.register_predicate_obligation(infcx, obligation);
7262
}
7363
}
74-
75-
fn select_all_or_error(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>> {
76-
let errors = self.select_where_possible(infcx);
77-
if !errors.is_empty() {
78-
return errors;
79-
}
80-
81-
self.collect_remaining_errors()
82-
}
8364
}

0 commit comments

Comments
 (0)