Auto merge of #96883 - jackh726:early-binder-2, r=oli-obk

Add EarlyBinder

Chalk has no concept of `Param` (e0ade19d13/chalk-ir/src/lib.rs (L579)) or `ReEarlyBound` (e0ade19d13/chalk-ir/src/lib.rs (L1308)). Everything  is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk.

Either way, tracking when we have or haven't already substituted out these in rustc can be helpful.

As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted.

r? `@nikomatsakis`
This commit is contained in:
bors
2022-05-14 23:53:11 +00:00
67 changed files with 400 additions and 217 deletions

View File

@@ -6,7 +6,8 @@ use crate::ty::layout::IntegerExt;
use crate::ty::query::TyCtxtAt;
use crate::ty::subst::{GenericArgKind, Subst, SubstsRef};
use crate::ty::{
self, Const, DebruijnIndex, DefIdTree, List, ReEarlyBound, Ty, TyCtxt, TyKind::*, TypeFoldable,
self, Const, DebruijnIndex, DefIdTree, EarlyBinder, List, ReEarlyBound, Ty, TyCtxt, TyKind::*,
TypeFoldable,
};
use rustc_apfloat::Float as _;
use rustc_ast as ast;
@@ -591,6 +592,32 @@ impl<'tcx> TyCtxt<'tcx> {
trace!(?expanded_type);
if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) }
}
pub fn bound_type_of(self, def_id: DefId) -> EarlyBinder<Ty<'tcx>> {
EarlyBinder(self.type_of(def_id))
}
pub fn bound_fn_sig(self, def_id: DefId) -> EarlyBinder<ty::PolyFnSig<'tcx>> {
EarlyBinder(self.fn_sig(def_id))
}
pub fn bound_impl_trait_ref(self, def_id: DefId) -> Option<EarlyBinder<ty::TraitRef<'tcx>>> {
self.impl_trait_ref(def_id).map(|i| EarlyBinder(i))
}
pub fn bound_explicit_item_bounds(
self,
def_id: DefId,
) -> EarlyBinder<&'tcx [(ty::Predicate<'tcx>, rustc_span::Span)]> {
EarlyBinder(self.explicit_item_bounds(def_id))
}
pub fn bound_item_bounds(
self,
def_id: DefId,
) -> EarlyBinder<&'tcx ty::List<ty::Predicate<'tcx>>> {
EarlyBinder(self.item_bounds(def_id))
}
}
struct OpaqueTypeExpander<'tcx> {
@@ -622,7 +649,7 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) {
Some(expanded_ty) => *expanded_ty,
None => {
let generic_ty = self.tcx.type_of(def_id);
let generic_ty = self.tcx.bound_type_of(def_id);
let concrete_ty = generic_ty.subst(self.tcx, substs);
let expanded_ty = self.fold_ty(concrete_ty);
self.expanded_cache.insert((def_id, substs), expanded_ty);