Yeet PolyGenSig

This commit is contained in:
Michael Goulet 2023-12-06 19:50:35 +00:00
parent f32d29837d
commit 1ec3ef7d81
6 changed files with 65 additions and 85 deletions

View File

@ -98,9 +98,8 @@ pub use self::sty::{
CoroutineArgs, CoroutineArgsParts, EarlyParamRegion, ExistentialPredicate,
ExistentialProjection, ExistentialTraitRef, FnSig, GenSig, InlineConstArgs,
InlineConstArgsParts, LateParamRegion, ParamConst, ParamTy, PolyExistentialPredicate,
PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef,
PredicateKind, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarArgs,
VarianceDiagInfo,
PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyTraitRef, PredicateKind,
Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarArgs, VarianceDiagInfo,
};
pub use self::trait_def::TraitDef;
pub use self::typeck_results::{

View File

@ -468,16 +468,6 @@ impl<'tcx> CoroutineArgs<'tcx> {
self.split().return_ty.expect_ty()
}
/// Returns the "coroutine signature", which consists of its yield
/// and return types.
///
/// N.B., some bits of the code prefers to see this wrapped in a
/// binder, but it never contains bound regions. Probably this
/// function should be removed.
pub fn poly_sig(self) -> PolyGenSig<'tcx> {
ty::Binder::dummy(self.sig())
}
/// Returns the "coroutine signature", which consists of its resume, yield
/// and return types.
pub fn sig(self) -> GenSig<'tcx> {
@ -1352,8 +1342,6 @@ pub struct GenSig<'tcx> {
pub return_ty: Ty<'tcx>,
}
pub type PolyGenSig<'tcx> = Binder<'tcx, GenSig<'tcx>>;
/// Signature of a function type, which we have arbitrarily
/// decided to use to refer to the input/output types.
///

View File

@ -2076,7 +2076,7 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
else {
unreachable!()
};
let coroutine_sig = args.as_coroutine().poly_sig();
let coroutine_sig = args.as_coroutine().sig();
let Normalized { value: coroutine_sig, obligations } = normalize_with_depth(
selcx,
obligation.param_env,
@ -2091,13 +2091,13 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
let coroutine_def_id = tcx.require_lang_item(LangItem::Coroutine, None);
let predicate = super::util::coroutine_trait_ref_and_outputs(
let (trait_ref, yield_ty, return_ty) = super::util::coroutine_trait_ref_and_outputs(
tcx,
coroutine_def_id,
obligation.predicate.self_ty(),
coroutine_sig,
)
.map_bound(|(trait_ref, yield_ty, return_ty)| {
);
let name = tcx.associated_item(obligation.predicate.def_id).name;
let ty = if name == sym::Return {
return_ty
@ -2107,13 +2107,12 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
bug!()
};
ty::ProjectionPredicate {
let predicate = ty::ProjectionPredicate {
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
term: ty.into(),
}
});
};
confirm_param_env_candidate(selcx, obligation, predicate, false)
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
.with_addl_obligations(nested)
.with_addl_obligations(obligations)
}
@ -2128,7 +2127,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
else {
unreachable!()
};
let coroutine_sig = args.as_coroutine().poly_sig();
let coroutine_sig = args.as_coroutine().sig();
let Normalized { value: coroutine_sig, obligations } = normalize_with_depth(
selcx,
obligation.param_env,
@ -2142,22 +2141,21 @@ fn confirm_future_candidate<'cx, 'tcx>(
let tcx = selcx.tcx();
let fut_def_id = tcx.require_lang_item(LangItem::Future, None);
let predicate = super::util::future_trait_ref_and_outputs(
let (trait_ref, return_ty) = super::util::future_trait_ref_and_outputs(
tcx,
fut_def_id,
obligation.predicate.self_ty(),
coroutine_sig,
)
.map_bound(|(trait_ref, return_ty)| {
);
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
ty::ProjectionPredicate {
let predicate = ty::ProjectionPredicate {
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
term: return_ty.into(),
}
});
};
confirm_param_env_candidate(selcx, obligation, predicate, false)
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
.with_addl_obligations(nested)
.with_addl_obligations(obligations)
}
@ -2172,7 +2170,7 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
else {
unreachable!()
};
let gen_sig = args.as_coroutine().poly_sig();
let gen_sig = args.as_coroutine().sig();
let Normalized { value: gen_sig, obligations } = normalize_with_depth(
selcx,
obligation.param_env,
@ -2186,22 +2184,21 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
let tcx = selcx.tcx();
let iter_def_id = tcx.require_lang_item(LangItem::Iterator, None);
let predicate = super::util::iterator_trait_ref_and_outputs(
let (trait_ref, yield_ty) = super::util::iterator_trait_ref_and_outputs(
tcx,
iter_def_id,
obligation.predicate.self_ty(),
gen_sig,
)
.map_bound(|(trait_ref, yield_ty)| {
);
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Item);
ty::ProjectionPredicate {
let predicate = ty::ProjectionPredicate {
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
term: yield_ty.into(),
}
});
};
confirm_param_env_candidate(selcx, obligation, predicate, false)
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
.with_addl_obligations(nested)
.with_addl_obligations(obligations)
}

View File

@ -731,7 +731,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?obligation, ?coroutine_def_id, ?args, "confirm_coroutine_candidate");
let coroutine_sig = args.as_coroutine().poly_sig();
let coroutine_sig = args.as_coroutine().sig();
// NOTE: The self-type is a coroutine type and hence is
// in fact unparameterized (or at least does not reference any
@ -742,15 +742,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.no_bound_vars()
.expect("unboxed closure type should not capture bound vars from the predicate");
let trait_ref = super::util::coroutine_trait_ref_and_outputs(
let (trait_ref, _, _) = super::util::coroutine_trait_ref_and_outputs(
self.tcx(),
obligation.predicate.def_id(),
self_ty,
coroutine_sig,
)
.map_bound(|(trait_ref, ..)| trait_ref);
);
let nested = self.confirm_poly_trait_refs(obligation, trait_ref)?;
let nested = self.confirm_poly_trait_refs(obligation, ty::Binder::dummy(trait_ref))?;
debug!(?trait_ref, ?nested, "coroutine candidate obligations");
Ok(nested)
@ -770,17 +769,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?obligation, ?coroutine_def_id, ?args, "confirm_future_candidate");
let coroutine_sig = args.as_coroutine().poly_sig();
let coroutine_sig = args.as_coroutine().sig();
let trait_ref = super::util::future_trait_ref_and_outputs(
let (trait_ref, _) = super::util::future_trait_ref_and_outputs(
self.tcx(),
obligation.predicate.def_id(),
obligation.predicate.no_bound_vars().expect("future has no bound vars").self_ty(),
coroutine_sig,
)
.map_bound(|(trait_ref, ..)| trait_ref);
);
let nested = self.confirm_poly_trait_refs(obligation, trait_ref)?;
let nested = self.confirm_poly_trait_refs(obligation, ty::Binder::dummy(trait_ref))?;
debug!(?trait_ref, ?nested, "future candidate obligations");
Ok(nested)
@ -800,17 +798,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?obligation, ?coroutine_def_id, ?args, "confirm_iterator_candidate");
let gen_sig = args.as_coroutine().poly_sig();
let gen_sig = args.as_coroutine().sig();
let trait_ref = super::util::iterator_trait_ref_and_outputs(
let (trait_ref, _) = super::util::iterator_trait_ref_and_outputs(
self.tcx(),
obligation.predicate.def_id(),
obligation.predicate.no_bound_vars().expect("iterator has no bound vars").self_ty(),
gen_sig,
)
.map_bound(|(trait_ref, ..)| trait_ref);
);
let nested = self.confirm_poly_trait_refs(obligation, trait_ref)?;
let nested = self.confirm_poly_trait_refs(obligation, ty::Binder::dummy(trait_ref))?;
debug!(?trait_ref, ?nested, "iterator candidate obligations");
Ok(nested)

View File

@ -279,33 +279,33 @@ pub fn coroutine_trait_ref_and_outputs<'tcx>(
tcx: TyCtxt<'tcx>,
fn_trait_def_id: DefId,
self_ty: Ty<'tcx>,
sig: ty::PolyGenSig<'tcx>,
) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>, Ty<'tcx>)> {
sig: ty::GenSig<'tcx>,
) -> (ty::TraitRef<'tcx>, Ty<'tcx>, Ty<'tcx>) {
assert!(!self_ty.has_escaping_bound_vars());
let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [self_ty, sig.skip_binder().resume_ty]);
sig.map_bound(|sig| (trait_ref, sig.yield_ty, sig.return_ty))
let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [self_ty, sig.resume_ty]);
(trait_ref, sig.yield_ty, sig.return_ty)
}
pub fn future_trait_ref_and_outputs<'tcx>(
tcx: TyCtxt<'tcx>,
fn_trait_def_id: DefId,
self_ty: Ty<'tcx>,
sig: ty::PolyGenSig<'tcx>,
) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>)> {
sig: ty::GenSig<'tcx>,
) -> (ty::TraitRef<'tcx>, Ty<'tcx>) {
assert!(!self_ty.has_escaping_bound_vars());
let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [self_ty]);
sig.map_bound(|sig| (trait_ref, sig.return_ty))
(trait_ref, sig.return_ty)
}
pub fn iterator_trait_ref_and_outputs<'tcx>(
tcx: TyCtxt<'tcx>,
iterator_def_id: DefId,
self_ty: Ty<'tcx>,
sig: ty::PolyGenSig<'tcx>,
) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>)> {
sig: ty::GenSig<'tcx>,
) -> (ty::TraitRef<'tcx>, Ty<'tcx>) {
assert!(!self_ty.has_escaping_bound_vars());
let trait_ref = ty::TraitRef::new(tcx, iterator_def_id, [self_ty]);
sig.map_bound(|sig| (trait_ref, sig.yield_ty))
(trait_ref, sig.yield_ty)
}
pub fn impl_item_is_final(tcx: TyCtxt<'_>, assoc_item: &ty::AssocItem) -> bool {

View File

@ -99,11 +99,11 @@ fn fn_sig_for_fn_abi<'tcx>(
}
ty::Coroutine(did, args, _) => {
let coroutine_kind = tcx.coroutine_kind(did).unwrap();
let sig = args.as_coroutine().poly_sig();
let sig = args.as_coroutine().sig();
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))),
);
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(iter::once(
ty::BoundVariableKind::Region(ty::BrEnv),
));
let br = ty::BoundRegion {
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
kind: ty::BoundRegionKind::BrEnv,
@ -124,7 +124,6 @@ fn fn_sig_for_fn_abi<'tcx>(
}
};
let sig = sig.skip_binder();
// The `FnSig` and the `ret_ty` here is for a coroutines main
// `Coroutine::resume(...) -> CoroutineState` function in case we
// have an ordinary coroutine, the `Future::poll(...) -> Poll`