Skip to content

Commit 6419a55

Browse files
Put generators into the same list as opaques
1 parent 978080e commit 6419a55

File tree

10 files changed

+38
-34
lines changed

10 files changed

+38
-34
lines changed

compiler/rustc_infer/src/infer/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,10 @@ impl<'tcx> InferCtxt<'tcx> {
966966
pub fn can_define_opaque_ty(&self, id: impl Into<DefId>) -> bool {
967967
debug_assert!(!self.next_trait_solver());
968968
match self.typing_mode() {
969-
TypingMode::Analysis { defining_opaque_types, stalled_generators: _ } => {
970-
id.into().as_local().is_some_and(|def_id| defining_opaque_types.contains(&def_id))
971-
}
969+
TypingMode::Analysis { defining_opaque_types_and_generators } => id
970+
.into()
971+
.as_local()
972+
.is_some_and(|def_id| defining_opaque_types_and_generators.contains(&def_id)),
972973
// FIXME(#132279): This function is quite weird in post-analysis
973974
// and post-borrowck analysis mode. We may need to modify its uses
974975
// to support PostBorrowckAnalysis in the old solver as well.
@@ -1260,7 +1261,7 @@ impl<'tcx> InferCtxt<'tcx> {
12601261
// to handle them without proper canonicalization. This means we may cause cycle
12611262
// errors and fail to reveal opaques while inside of bodies. We should rename this
12621263
// function and require explicit comments on all use-sites in the future.
1263-
ty::TypingMode::Analysis { defining_opaque_types: _, stalled_generators: _ } => {
1264+
ty::TypingMode::Analysis { defining_opaque_types_and_generators: _ } => {
12641265
TypingMode::non_body_analysis()
12651266
}
12661267
mode @ (ty::TypingMode::Coherence

compiler/rustc_middle/src/query/plumbing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ macro_rules! define_callbacks {
366366

367367
pub type Storage<'tcx> = <$($K)* as keys::Key>::Cache<Erase<$V>>;
368368

369-
// Ensure that keys grow no larger than 96 bytes by accident.
369+
// Ensure that keys grow no larger than 88 bytes by accident.
370370
// Increase this limit if necessary, but do try to keep the size low if possible
371371
#[cfg(target_pointer_width = "64")]
372372
const _: () = {
373-
if size_of::<Key<'static>>() > 96 {
373+
if size_of::<Key<'static>>() > 88 {
374374
panic!("{}", concat!(
375375
"the query `",
376376
stringify!($name),

compiler/rustc_middle/src/ty/context.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,15 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
667667
self.opaque_types_defined_by(defining_anchor)
668668
}
669669

670-
fn stalled_generators_within(self, defining_anchor: Self::LocalDefId) -> Self::LocalDefIds {
671-
self.stalled_generators_within(defining_anchor)
670+
fn opaque_types_and_generators_defined_by(
671+
self,
672+
defining_anchor: Self::LocalDefId,
673+
) -> Self::LocalDefIds {
674+
self.mk_local_def_ids_from_iter(
675+
self.opaque_types_defined_by(defining_anchor)
676+
.iter()
677+
.chain(self.stalled_generators_within(defining_anchor)),
678+
)
672679
}
673680
}
674681

@@ -2875,11 +2882,11 @@ impl<'tcx> TyCtxt<'tcx> {
28752882
self.interners.intern_clauses(clauses)
28762883
}
28772884

2878-
pub fn mk_local_def_ids(self, clauses: &[LocalDefId]) -> &'tcx List<LocalDefId> {
2885+
pub fn mk_local_def_ids(self, def_ids: &[LocalDefId]) -> &'tcx List<LocalDefId> {
28792886
// FIXME consider asking the input slice to be sorted to avoid
28802887
// re-interning permutations, in which case that would be asserted
28812888
// here.
2882-
self.intern_local_def_ids(clauses)
2889+
self.intern_local_def_ids(def_ids)
28832890
}
28842891

28852892
pub fn mk_local_def_ids_from_iter<I, T>(self, iter: I) -> T::Output

compiler/rustc_next_trait_solver/src/solve/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,7 @@ where
329329
TypingMode::Coherence | TypingMode::PostAnalysis => false,
330330
// During analysis, opaques are rigid unless they may be defined by
331331
// the current body.
332-
TypingMode::Analysis {
333-
defining_opaque_types: non_rigid_opaques,
334-
stalled_generators: _,
335-
}
332+
TypingMode::Analysis { defining_opaque_types_and_generators: non_rigid_opaques }
336333
| TypingMode::PostBorrowckAnalysis { defined_opaque_types: non_rigid_opaques } => {
337334
!def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id))
338335
}

compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ where
3333
);
3434
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
3535
}
36-
TypingMode::Analysis { defining_opaque_types, stalled_generators: _ } => {
36+
TypingMode::Analysis { defining_opaque_types_and_generators } => {
3737
let Some(def_id) = opaque_ty
3838
.def_id
3939
.as_local()
40-
.filter(|&def_id| defining_opaque_types.contains(&def_id))
40+
.filter(|&def_id| defining_opaque_types_and_generators.contains(&def_id))
4141
else {
4242
self.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias);
4343
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ where
191191

192192
if let ty::CoroutineWitness(def_id, _) = goal.predicate.self_ty().kind() {
193193
match ecx.typing_mode() {
194-
TypingMode::Analysis { stalled_generators, defining_opaque_types: _ } => {
195-
if def_id.as_local().is_some_and(|def_id| stalled_generators.contains(&def_id))
196-
{
194+
TypingMode::Analysis { defining_opaque_types_and_generators } => {
195+
if def_id.as_local().is_some_and(|def_id| {
196+
defining_opaque_types_and_generators.contains(&def_id)
197+
}) {
197198
return ecx.forced_ambiguity(MaybeCause::Ambiguity);
198199
}
199200
}

compiler/rustc_trait_selection/src/solve/fulfill.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ where
219219
) -> PredicateObligations<'tcx> {
220220
self.obligations.drain_pending(|obl| {
221221
let stalled_generators = match infcx.typing_mode() {
222-
TypingMode::Analysis { defining_opaque_types: _, stalled_generators } => {
223-
stalled_generators
222+
TypingMode::Analysis { defining_opaque_types_and_generators } => {
223+
defining_opaque_types_and_generators
224224
}
225225
TypingMode::Coherence
226226
| TypingMode::PostBorrowckAnalysis { defined_opaque_types: _ }

compiler/rustc_trait_selection/src/traits/select/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1491,9 +1491,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14911491
// However, if we disqualify *all* goals from being cached, perf suffers.
14921492
// This is likely fixed by better caching in general in the new solver.
14931493
// See: <https://github.com/rust-lang/rust/issues/132064>.
1494-
TypingMode::Analysis { defining_opaque_types, stalled_generators } => {
1495-
debug_assert!(stalled_generators.is_empty());
1496-
defining_opaque_types.is_empty() || !pred.has_opaque_types()
1494+
TypingMode::Analysis { defining_opaque_types_and_generators } => {
1495+
defining_opaque_types_and_generators.is_empty() || !pred.has_opaque_types()
14971496
}
14981497
// The hidden types of `defined_opaque_types` is not local to the current
14991498
// inference context, so we can freely move this to the global cache.

compiler/rustc_type_ir/src/infer_ctxt.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub enum TypingMode<I: Interner> {
6565
/// let x: <() as Assoc>::Output = true;
6666
/// }
6767
/// ```
68-
Analysis { defining_opaque_types: I::LocalDefIds, stalled_generators: I::LocalDefIds },
68+
Analysis { defining_opaque_types_and_generators: I::LocalDefIds },
6969
/// Any analysis after borrowck for a given body should be able to use all the
7070
/// hidden types defined by borrowck, without being able to define any new ones.
7171
///
@@ -86,25 +86,21 @@ pub enum TypingMode<I: Interner> {
8686
impl<I: Interner> TypingMode<I> {
8787
/// Analysis outside of a body does not define any opaque types.
8888
pub fn non_body_analysis() -> TypingMode<I> {
89-
TypingMode::Analysis {
90-
defining_opaque_types: Default::default(),
91-
stalled_generators: Default::default(),
92-
}
89+
TypingMode::Analysis { defining_opaque_types_and_generators: Default::default() }
9390
}
9491

9592
pub fn typeck_for_body(cx: I, body_def_id: I::LocalDefId) -> TypingMode<I> {
9693
TypingMode::Analysis {
97-
defining_opaque_types: cx.opaque_types_defined_by(body_def_id),
98-
stalled_generators: cx.stalled_generators_within(body_def_id),
94+
defining_opaque_types_and_generators: cx
95+
.opaque_types_and_generators_defined_by(body_def_id),
9996
}
10097
}
10198

10299
/// While typechecking a body, we need to be able to define the opaque
103100
/// types defined by that body.
104101
pub fn analysis_in_body(cx: I, body_def_id: I::LocalDefId) -> TypingMode<I> {
105102
TypingMode::Analysis {
106-
defining_opaque_types: cx.opaque_types_defined_by(body_def_id),
107-
stalled_generators: Default::default(),
103+
defining_opaque_types_and_generators: cx.opaque_types_defined_by(body_def_id),
108104
}
109105
}
110106

compiler/rustc_type_ir/src/interner.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,10 @@ pub trait Interner:
318318

319319
fn opaque_types_defined_by(self, defining_anchor: Self::LocalDefId) -> Self::LocalDefIds;
320320

321-
fn stalled_generators_within(self, defining_anchor: Self::LocalDefId) -> Self::LocalDefIds;
321+
fn opaque_types_and_generators_defined_by(
322+
self,
323+
defining_anchor: Self::LocalDefId,
324+
) -> Self::LocalDefIds;
322325
}
323326

324327
/// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter`

0 commit comments

Comments
 (0)