Skip to content

Commit ccf59a5

Browse files
committed
Auto merge of #116195 - fmease:rustdoc-investigate-perf-regression, r=<try>
[perf] rustdoc: investigate recent perf regression Investigate perf regression caused by #116084. r? `@ghost`
2 parents 56ada88 + 1f2ade0 commit ccf59a5

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

src/librustdoc/clean/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,12 @@ fn clean_fn_decl_from_did_and_sig<'tcx>(
11831183
// but shouldn't change any code meaning.
11841184
let mut output = clean_middle_ty(sig.output(), cx, None, None);
11851185

1186-
if let Some(did) = did && cx.tcx.asyncness(did).is_async() {
1186+
// If the return type is not an `impl Trait`, we can safely assume that this function isn't async
1187+
// without needing to execute the `asyncness` query which gives us a slight performance boost.
1188+
if let Some(did) = did
1189+
&& let Type::ImplTrait(_) = output
1190+
&& cx.tcx.asyncness(did).is_async()
1191+
{
11871192
output = output.sugared_async_return_type();
11881193
}
11891194

src/librustdoc/clean/types.rs

+9-26
Original file line numberDiff line numberDiff line change
@@ -1604,14 +1604,16 @@ impl Type {
16041604
///
16051605
/// This function will panic if the return type does not match the expected sugaring for async
16061606
/// functions.
1607-
pub(crate) fn sugared_async_return_type(&self) -> Type {
1608-
if let Type::ImplTrait(v) = self &&
1609-
let [GenericBound::TraitBound(PolyTrait { trait_, .. }, _ )] = &v[..]
1607+
pub(crate) fn sugared_async_return_type(self) -> Type {
1608+
if let Type::ImplTrait(mut v) = self
1609+
&& let Some(GenericBound::TraitBound(PolyTrait { mut trait_, .. }, _ )) = v.pop()
1610+
&& let Some(segment) = trait_.segments.pop()
1611+
&& let GenericArgs::AngleBracketed { mut bindings, .. } = segment.args
1612+
&& let Some(binding) = bindings.pop()
1613+
&& let TypeBindingKind::Equality { term } = binding.kind
1614+
&& let Term::Type(ty) = term
16101615
{
1611-
let bindings = trait_.bindings().unwrap();
1612-
let ret_ty = bindings[0].term();
1613-
let ty = ret_ty.ty().expect("unexpected constant in async fn return term");
1614-
ty.clone()
1616+
ty
16151617
} else {
16161618
panic!("unexpected async fn return type")
16171619
}
@@ -2189,16 +2191,6 @@ impl Path {
21892191
}
21902192
})
21912193
}
2192-
2193-
pub(crate) fn bindings(&self) -> Option<&[TypeBinding]> {
2194-
self.segments.last().and_then(|seg| {
2195-
if let GenericArgs::AngleBracketed { ref bindings, .. } = seg.args {
2196-
Some(&**bindings)
2197-
} else {
2198-
None
2199-
}
2200-
})
2201-
}
22022194
}
22032195

22042196
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
@@ -2478,15 +2470,6 @@ pub(crate) enum TypeBindingKind {
24782470
Constraint { bounds: Vec<GenericBound> },
24792471
}
24802472

2481-
impl TypeBinding {
2482-
pub(crate) fn term(&self) -> &Term {
2483-
match self.kind {
2484-
TypeBindingKind::Equality { ref term } => term,
2485-
_ => panic!("expected equality type binding for parenthesized generic args"),
2486-
}
2487-
}
2488-
}
2489-
24902473
/// The type, lifetime, or constant that a private type alias's parameter should be
24912474
/// replaced with when expanding a use of that type alias.
24922475
///

0 commit comments

Comments
 (0)