Delegation: second attempt to improve perf
This commit is contained in:
parent
595316b400
commit
9b097b2d44
@ -2952,6 +2952,17 @@ pub struct FnDecl<'hir> {
|
|||||||
pub lifetime_elision_allowed: bool,
|
pub lifetime_elision_allowed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'hir> FnDecl<'hir> {
|
||||||
|
pub fn opt_delegation_sig_id(&self) -> Option<DefId> {
|
||||||
|
if let FnRetTy::Return(ty) = self.output
|
||||||
|
&& let TyKind::InferDelegation(sig_id, _) = ty.kind
|
||||||
|
{
|
||||||
|
return Some(sig_id);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents what type of implicit self a function has, if any.
|
/// Represents what type of implicit self a function has, if any.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
|
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
|
||||||
pub enum ImplicitSelfKind {
|
pub enum ImplicitSelfKind {
|
||||||
|
@ -54,13 +54,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// For a delegation item inherit generics from callee.
|
|
||||||
if let Some(sig_id) = tcx.hir().opt_delegation_sig_id(def_id)
|
|
||||||
&& let Some(generics) = inherit_generics_for_delegation_item(tcx, def_id, sig_id)
|
|
||||||
{
|
|
||||||
return generics;
|
|
||||||
}
|
|
||||||
|
|
||||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||||
|
|
||||||
let node = tcx.hir_node(hir_id);
|
let node = tcx.hir_node(hir_id);
|
||||||
@ -234,6 +227,16 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
|
|||||||
// inherit the generics of the item.
|
// inherit the generics of the item.
|
||||||
Some(parent.to_def_id())
|
Some(parent.to_def_id())
|
||||||
}
|
}
|
||||||
|
ItemKind::Fn(sig, _, _) => {
|
||||||
|
// For a delegation item inherit generics from callee.
|
||||||
|
if let Some(sig_id) = sig.decl.opt_delegation_sig_id()
|
||||||
|
&& let Some(generics) =
|
||||||
|
inherit_generics_for_delegation_item(tcx, def_id, sig_id)
|
||||||
|
{
|
||||||
|
return generics;
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -115,13 +115,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
|||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For a delegation item inherit predicates from callee.
|
|
||||||
if let Some(sig_id) = tcx.hir().opt_delegation_sig_id(def_id)
|
|
||||||
&& let Some(predicates) = inherit_predicates_for_delegation_item(tcx, def_id, sig_id)
|
|
||||||
{
|
|
||||||
return predicates;
|
|
||||||
}
|
|
||||||
|
|
||||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||||
let node = tcx.hir_node(hir_id);
|
let node = tcx.hir_node(hir_id);
|
||||||
|
|
||||||
@ -151,6 +144,16 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
|||||||
ItemKind::Trait(_, _, _, self_bounds, ..) | ItemKind::TraitAlias(_, self_bounds) => {
|
ItemKind::Trait(_, _, _, self_bounds, ..) | ItemKind::TraitAlias(_, self_bounds) => {
|
||||||
is_trait = Some(self_bounds);
|
is_trait = Some(self_bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemKind::Fn(sig, _, _) => {
|
||||||
|
// For a delegation item inherit predicates from callee.
|
||||||
|
if let Some(sig_id) = sig.decl.opt_delegation_sig_id()
|
||||||
|
&& let Some(predicates) =
|
||||||
|
inherit_predicates_for_delegation_item(tcx, def_id, sig_id)
|
||||||
|
{
|
||||||
|
return predicates;
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -242,7 +242,7 @@ pub(crate) fn inherit_sig_for_delegation_item<'tcx>(
|
|||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
) -> &'tcx [Ty<'tcx>] {
|
) -> &'tcx [Ty<'tcx>] {
|
||||||
let sig_id = tcx.hir().delegation_sig_id(def_id);
|
let sig_id = tcx.hir().opt_delegation_sig_id(def_id).unwrap();
|
||||||
let caller_sig = tcx.fn_sig(sig_id);
|
let caller_sig = tcx.fn_sig(sig_id);
|
||||||
if let Err(err) = check_constraints(tcx, def_id, sig_id) {
|
if let Err(err) = check_constraints(tcx, def_id, sig_id) {
|
||||||
let sig_len = caller_sig.instantiate_identity().skip_binder().inputs().len() + 1;
|
let sig_len = caller_sig.instantiate_identity().skip_binder().inputs().len() + 1;
|
||||||
|
@ -747,18 +747,7 @@ pub fn expect_expr(self, id: HirId) -> &'hir Expr<'hir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn opt_delegation_sig_id(self, def_id: LocalDefId) -> Option<DefId> {
|
pub fn opt_delegation_sig_id(self, def_id: LocalDefId) -> Option<DefId> {
|
||||||
if let Some(ret) = self.get_fn_output(def_id)
|
self.tcx.opt_hir_owner_node(def_id)?.fn_decl()?.opt_delegation_sig_id()
|
||||||
&& let FnRetTy::Return(ty) = ret
|
|
||||||
&& let TyKind::InferDelegation(sig_id, _) = ty.kind
|
|
||||||
{
|
|
||||||
return Some(sig_id);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn delegation_sig_id(self, def_id: LocalDefId) -> DefId {
|
|
||||||
self.opt_delegation_sig_id(def_id).unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
Loading…
Reference in New Issue
Block a user