Skip to content

Commit 935f41f

Browse files
committed
Auto merge of rust-lang#116195 - fmease:rustdoc-investigate-perf-regression, r=<try>
[perf] rustdoc: investigate recent perf regression Investigate perf regression caused by rust-lang#116084. r? `@ghost`
2 parents 085acd0 + 2b7f06f commit 935f41f

File tree

6 files changed

+44
-72
lines changed

6 files changed

+44
-72
lines changed

src/librustdoc/clean/mod.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,10 @@ fn clean_function<'tcx>(
11081108
clean_args_from_types_and_names(cx, sig.decl.inputs, names)
11091109
}
11101110
};
1111-
let decl = clean_fn_decl_with_args(cx, sig.decl, Some(&sig.header), args);
1111+
let mut decl = clean_fn_decl_with_args(cx, sig.decl, args);
1112+
if sig.header.is_async() {
1113+
decl.output = decl.sugared_async_return_type();
1114+
}
11121115
(generics, decl)
11131116
});
11141117
Box::new(Function { decl, generics })
@@ -1159,16 +1162,12 @@ fn clean_args_from_types_and_body_id<'tcx>(
11591162
fn clean_fn_decl_with_args<'tcx>(
11601163
cx: &mut DocContext<'tcx>,
11611164
decl: &hir::FnDecl<'tcx>,
1162-
header: Option<&hir::FnHeader>,
11631165
args: Arguments,
11641166
) -> FnDecl {
1165-
let mut output = match decl.output {
1167+
let output = match decl.output {
11661168
hir::FnRetTy::Return(typ) => clean_ty(typ, cx),
11671169
hir::FnRetTy::DefaultReturn(..) => Type::Tuple(Vec::new()),
11681170
};
1169-
if let Some(header) = header && header.is_async() {
1170-
output = output.sugared_async_return_type();
1171-
}
11721171
FnDecl { inputs: args, output, c_variadic: decl.c_variadic }
11731172
}
11741173

@@ -1181,11 +1180,7 @@ fn clean_fn_decl_from_did_and_sig<'tcx>(
11811180

11821181
// We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
11831182
// but shouldn't change any code meaning.
1184-
let mut output = clean_middle_ty(sig.output(), cx, None, None);
1185-
1186-
if let Some(did) = did && cx.tcx.asyncness(did).is_async() {
1187-
output = output.sugared_async_return_type();
1188-
}
1183+
let output = clean_middle_ty(sig.output(), cx, None, None);
11891184

11901185
FnDecl {
11911186
output,
@@ -2571,7 +2566,7 @@ fn clean_bare_fn_ty<'tcx>(
25712566
.map(|x| clean_generic_param(cx, None, x))
25722567
.collect();
25732568
let args = clean_args_from_types_and_names(cx, bare_fn.decl.inputs, bare_fn.param_names);
2574-
let decl = clean_fn_decl_with_args(cx, bare_fn.decl, None, args);
2569+
let decl = clean_fn_decl_with_args(cx, bare_fn.decl, args);
25752570
(generic_params, decl)
25762571
});
25772572
BareFunctionDecl { unsafety: bare_fn.unsafety, abi: bare_fn.abi, decl, generic_params }
@@ -3082,7 +3077,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
30823077
// NOTE: generics must be cleaned before args
30833078
let generics = clean_generics(generics, cx);
30843079
let args = clean_args_from_types_and_names(cx, decl.inputs, names);
3085-
let decl = clean_fn_decl_with_args(cx, decl, None, args);
3080+
let decl = clean_fn_decl_with_args(cx, decl, args);
30863081
(generics, decl)
30873082
});
30883083
ForeignFunctionItem(Box::new(Function { decl, generics }))

src/librustdoc/clean/types.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,28 @@ impl FnDecl {
13841384
pub(crate) fn self_type(&self) -> Option<SelfTy> {
13851385
self.inputs.values.get(0).and_then(|v| v.to_self())
13861386
}
1387+
1388+
/// Returns the sugared return type for an async function.
1389+
///
1390+
/// For example, if the return type is `impl std::future::Future<Output = i32>`, this function
1391+
/// will return `i32`.
1392+
///
1393+
/// # Panics
1394+
///
1395+
/// This function will panic if the return type does not match the expected sugaring for async
1396+
/// functions.
1397+
pub(crate) fn sugared_async_return_type(&self) -> Type {
1398+
if let Type::ImplTrait(v) = &self.output &&
1399+
let [GenericBound::TraitBound(PolyTrait { trait_, .. }, _ )] = &v[..]
1400+
{
1401+
let bindings = trait_.bindings().unwrap();
1402+
let ret_ty = bindings[0].term();
1403+
let ty = ret_ty.ty().expect("Unexpected constant return term");
1404+
ty.clone()
1405+
} else {
1406+
panic!("unexpected desugaring of async function")
1407+
}
1408+
}
13871409
}
13881410

13891411
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
@@ -1595,28 +1617,6 @@ impl Type {
15951617
}
15961618
}
15971619

1598-
/// Returns the sugared return type for an async function.
1599-
///
1600-
/// For example, if the return type is `impl std::future::Future<Output = i32>`, this function
1601-
/// will return `i32`.
1602-
///
1603-
/// # Panics
1604-
///
1605-
/// This function will panic if the return type does not match the expected sugaring for async
1606-
/// 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[..]
1610-
{
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()
1615-
} else {
1616-
panic!("unexpected async fn return type")
1617-
}
1618-
}
1619-
16201620
/// Checks if this is a `T::Name` path for an associated type.
16211621
pub(crate) fn is_assoc_ty(&self) -> bool {
16221622
match self {

tests/rustdoc/inline_cross/async-fn.rs

-19
This file was deleted.

tests/rustdoc/inline_cross/auxiliary/async-fn.rs

-18
This file was deleted.

tests/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs

+6
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ pub struct Foo;
3333
impl Foo {
3434
pub fn method<'a>(_x: impl Clone + Into<Vec<u8>> + 'a) {}
3535
}
36+
37+
pub struct Bar;
38+
39+
impl Bar {
40+
pub async fn async_foo(&self) {}
41+
}

tests/rustdoc/inline_cross/impl_trait.rs

+8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ pub use impl_trait_aux::func4;
3333
// @!has - '//pre[@class="rust item-decl"]' 'where'
3434
pub use impl_trait_aux::func5;
3535

36+
// @has impl_trait/fn.async_fn.html
37+
// @has - '//pre[@class="rust item-decl"]' "pub async fn async_fn()"
38+
pub use impl_trait_aux::async_fn;
39+
3640
// @has impl_trait/struct.Foo.html
3741
// @has - '//*[@id="method.method"]//h4[@class="code-header"]' "pub fn method<'a>(_x: impl Clone + Into<Vec<u8, Global>> + 'a)"
3842
// @!has - '//*[@id="method.method"]//h4[@class="code-header"]' 'where'
3943
pub use impl_trait_aux::Foo;
44+
45+
// @has impl_trait/struct.Bar.html
46+
// @has - '//*[@id="method.async_foo"]' "pub async fn async_foo("
47+
pub use impl_trait_aux::Bar;

0 commit comments

Comments
 (0)