Skip to content

Commit ad74788

Browse files
Use bound_coroutine_witnesses in old solver
1 parent 8282181 commit ad74788

File tree

5 files changed

+27
-81
lines changed

5 files changed

+27
-81
lines changed

Diff for: compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
324324
self.features()
325325
}
326326

327-
fn bound_coroutine_hidden_types(
327+
fn coroutine_hidden_types(
328328
self,
329329
def_id: DefId,
330330
) -> ty::EarlyBinder<'tcx, ty::Binder<'tcx, &'tcx ty::List<Ty<'tcx>>>> {
331-
self.bound_coroutine_hidden_types(def_id)
331+
self.coroutine_hidden_types(def_id)
332332
}
333333

334334
fn fn_sig(self, def_id: DefId) -> ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>> {

Diff for: compiler/rustc_middle/src/ty/util.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -725,27 +725,10 @@ impl<'tcx> TyCtxt<'tcx> {
725725
}
726726
}
727727

728-
/// Return the set of types that should be taken into account when checking
729-
/// trait bounds on a coroutine's internal state.
730-
// FIXME(compiler-errors): We should remove this when the old solver goes away;
731-
// and all other usages of this function should go through `bound_coroutine_hidden_types`
732-
// instead.
733-
pub fn coroutine_hidden_types(
734-
self,
735-
def_id: DefId,
736-
) -> impl Iterator<Item = ty::EarlyBinder<'tcx, Ty<'tcx>>> {
737-
let coroutine_layout = self.mir_coroutine_witnesses(def_id);
738-
coroutine_layout
739-
.as_ref()
740-
.map_or_else(|| [].iter(), |l| l.field_tys.iter())
741-
.filter(|decl| !decl.ignore_for_traits)
742-
.map(|decl| ty::EarlyBinder::bind(decl.ty))
743-
}
744-
745728
/// Return the set of types that should be taken into account when checking
746729
/// trait bounds on a coroutine's internal state. This properly replaces
747730
/// `ReErased` with new existential bound lifetimes.
748-
pub fn bound_coroutine_hidden_types(
731+
pub fn coroutine_hidden_types(
749732
self,
750733
def_id: DefId,
751734
) -> ty::EarlyBinder<'tcx, ty::Binder<'tcx, &'tcx ty::List<Ty<'tcx>>>> {

Diff for: compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ where
7474

7575
ty::CoroutineWitness(def_id, args) => Ok(ecx
7676
.cx()
77-
.bound_coroutine_hidden_types(def_id)
77+
.coroutine_hidden_types(def_id)
7878
.instantiate(cx, args)
7979
.map_bound(|tys| tys.to_vec())),
8080

@@ -240,7 +240,7 @@ where
240240
// impl Copy/Clone for CoroutineWitness where T: Copy/Clone forall T in coroutine_hidden_types
241241
ty::CoroutineWitness(def_id, args) => Ok(ecx
242242
.cx()
243-
.bound_coroutine_hidden_types(def_id)
243+
.coroutine_hidden_types(def_id)
244244
.instantiate(ecx.cx(), args)
245245
.map_bound(|tys| tys.to_vec())),
246246
}

Diff for: compiler/rustc_trait_selection/src/traits/select/mod.rs

+21-58
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::ops::ControlFlow;
99
use std::{cmp, iter};
1010

1111
use hir::def::DefKind;
12-
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
12+
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
1313
use rustc_data_structures::stack::ensure_sufficient_stack;
1414
use rustc_errors::{Diag, EmissionGuarantee};
1515
use rustc_hir as hir;
@@ -25,7 +25,6 @@ use rustc_middle::dep_graph::{DepNodeIndex, dep_kinds};
2525
pub use rustc_middle::traits::select::*;
2626
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
2727
use rustc_middle::ty::error::TypeErrorToStringExt;
28-
use rustc_middle::ty::fold::fold_regions;
2928
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
3029
use rustc_middle::ty::{
3130
self, GenericArgsRef, PolyProjectionPredicate, Ty, TyCtxt, TypeFoldable, TypeVisitableExt,
@@ -2199,8 +2198,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
21992198
}
22002199

22012200
ty::CoroutineWitness(def_id, args) => {
2202-
let hidden_types = bind_coroutine_hidden_types_above(
2203-
self.infcx,
2201+
let hidden_types = rebind_coroutine_witness_types(
2202+
self.infcx.tcx,
22042203
def_id,
22052204
args,
22062205
obligation.predicate.bound_vars(),
@@ -2348,7 +2347,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
23482347
}
23492348

23502349
ty::CoroutineWitness(def_id, args) => {
2351-
bind_coroutine_hidden_types_above(self.infcx, def_id, args, t.bound_vars())
2350+
rebind_coroutine_witness_types(self.infcx.tcx, def_id, args, t.bound_vars())
23522351
}
23532352

23542353
// For `PhantomData<T>`, we pass `T`.
@@ -2843,6 +2842,23 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
28432842
}
28442843
}
28452844

2845+
fn rebind_coroutine_witness_types<'tcx>(
2846+
tcx: TyCtxt<'tcx>,
2847+
def_id: DefId,
2848+
args: ty::GenericArgsRef<'tcx>,
2849+
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
2850+
) -> ty::Binder<'tcx, Vec<Ty<'tcx>>> {
2851+
let bound_coroutine_types = tcx.coroutine_hidden_types(def_id).skip_binder();
2852+
let shifted_coroutine_types =
2853+
tcx.shift_bound_var_indices(bound_vars.len(), bound_coroutine_types.skip_binder());
2854+
ty::Binder::bind_with_vars(
2855+
ty::EarlyBinder::bind(shifted_coroutine_types.to_vec()).instantiate(tcx, args),
2856+
tcx.mk_bound_variable_kinds_from_iter(
2857+
bound_vars.iter().chain(bound_coroutine_types.bound_vars()),
2858+
),
2859+
)
2860+
}
2861+
28462862
impl<'o, 'tcx> TraitObligationStack<'o, 'tcx> {
28472863
fn list(&'o self) -> TraitObligationStackList<'o, 'tcx> {
28482864
TraitObligationStackList::with(self)
@@ -3151,56 +3167,3 @@ pub(crate) enum ProjectionMatchesProjection {
31513167
Ambiguous,
31523168
No,
31533169
}
3154-
3155-
/// Replace all regions inside the coroutine interior with late bound regions.
3156-
/// Note that each region slot in the types gets a new fresh late bound region, which means that
3157-
/// none of the regions inside relate to any other, even if typeck had previously found constraints
3158-
/// that would cause them to be related.
3159-
#[instrument(level = "trace", skip(infcx), ret)]
3160-
fn bind_coroutine_hidden_types_above<'tcx>(
3161-
infcx: &InferCtxt<'tcx>,
3162-
def_id: DefId,
3163-
args: ty::GenericArgsRef<'tcx>,
3164-
bound_vars: &ty::List<ty::BoundVariableKind>,
3165-
) -> ty::Binder<'tcx, Vec<Ty<'tcx>>> {
3166-
let tcx = infcx.tcx;
3167-
let mut seen_tys = FxHashSet::default();
3168-
3169-
let considering_regions = infcx.considering_regions;
3170-
3171-
let num_bound_variables = bound_vars.len() as u32;
3172-
let mut counter = num_bound_variables;
3173-
3174-
let hidden_types: Vec<_> = tcx
3175-
.coroutine_hidden_types(def_id)
3176-
// Deduplicate tys to avoid repeated work.
3177-
.filter(|bty| seen_tys.insert(*bty))
3178-
.map(|mut bty| {
3179-
// Only remap erased regions if we use them.
3180-
if considering_regions {
3181-
bty = bty.map_bound(|ty| {
3182-
fold_regions(tcx, ty, |r, current_depth| match r.kind() {
3183-
ty::ReErased => {
3184-
let br = ty::BoundRegion {
3185-
var: ty::BoundVar::from_u32(counter),
3186-
kind: ty::BoundRegionKind::Anon,
3187-
};
3188-
counter += 1;
3189-
ty::Region::new_bound(tcx, current_depth, br)
3190-
}
3191-
r => bug!("unexpected region: {r:?}"),
3192-
})
3193-
})
3194-
}
3195-
3196-
bty.instantiate(tcx, args)
3197-
})
3198-
.collect();
3199-
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
3200-
bound_vars.iter().chain(
3201-
(num_bound_variables..counter)
3202-
.map(|_| ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon)),
3203-
),
3204-
);
3205-
ty::Binder::bind_with_vars(hidden_types, bound_vars)
3206-
}

Diff for: compiler/rustc_type_ir/src/interner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub trait Interner:
189189
type Features: Features<Self>;
190190
fn features(self) -> Self::Features;
191191

192-
fn bound_coroutine_hidden_types(
192+
fn coroutine_hidden_types(
193193
self,
194194
def_id: Self::DefId,
195195
) -> ty::EarlyBinder<Self, ty::Binder<Self, Self::Tys>>;

0 commit comments

Comments
 (0)