Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove clean::Function::header and calculate it on-demand #91217

Closed

Conversation

yuvaldolev
Copy link
Contributor

Addresses #89673

Remove clean::Function::header and calculate it on-demand based on the DefId.

r? @jyn514

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 25, 2021
@jyn514 jyn514 added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 25, 2021
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome ❤️ Thank you for working on this!

src/librustdoc/json/conversions.rs Outdated Show resolved Hide resolved
@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 25, 2021
@jyn514
Copy link
Member

jyn514 commented Nov 25, 2021

 error: internal compiler error: compiler/rustc_ty_utils/src/ty.rs:493:9: asyncness: expected fn-like node but got `DefId(0:36 ~ foo[cf51]::PubTrait::function)`

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Hmm, can you run this locally with RUST_BACKTRACE set to see how it's happening? I wonder if we need to avoid calling asyncness for associated functions?

@jyn514
Copy link
Member

jyn514 commented Nov 25, 2021

Maybe also look at fn_kind to see why it returns None: https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_hir/hir.rs.html#3267-3291

@rust-log-analyzer

This comment has been minimized.

@yuvaldolev
Copy link
Contributor Author

@rustbot label -S-waiting-on-author +S-waiting-on-review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 26, 2021
@rust-log-analyzer

This comment has been minimized.

@yuvaldolev
Copy link
Contributor Author

@rustbot label +S-waiting-on-author -S-waiting-on-review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 26, 2021
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks mostly good from me, but I'd like to have someone from the compiler team review - @petrochenkov would you be willing to look over the HIR changes?

Comment on lines +111 to +112
/// `extern "C" { pub fn foo(); }`
ForeignFn(Ident),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new variant shouldn't be necessary - if you look at ItemFn above it allows for an ABI field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it requires a FnHeader, which is not available for ForeignItem functions.
Should I just create a header with all items such as asyncness and constness set to false?

Copy link
Member

@jyn514 jyn514 Nov 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question for petrochenkov, I'm not sure. https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.ForeignItemKind.html has a FnDecl but not FnHeader. Maybe try implementing that for now and we can change it later if necessary.

@jyn514 jyn514 assigned petrochenkov and unassigned jyn514 Nov 26, 2021
@jyn514 jyn514 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 26, 2021
@petrochenkov
Copy link
Contributor

The HIR changes do not look right, the new variant is not integrated into the HIR visitor (intravisit.rs), so it's not constructed by the compiler, only by rustdoc.

As you can see FnKind is currently used only for functions with bodies (it's not used for trait functions without bodies TraitItemKind::Fn(_, TraitFn::Required(_)), for example) and is a part of fn visit_fn logic which includes visiting of function bodies.
You can try migrating HIR visitor to visit_fn/FnKind for functions without bodies as well (I can't predict whether it will be an improvement or not), but I suggest doing it in a PR separate from the rustdoc changes.

r? @jyn514

@rust-highfive rust-highfive assigned jyn514 and unassigned petrochenkov Nov 27, 2021
@jyn514
Copy link
Member

jyn514 commented Nov 27, 2021

@petrochenkov how can we find this information for functions without bodies without using fn_sig? In particular, asyncness, constness, and abi - I guess we can just hard-code that trait and foreign functions aren't async for now, but I'm not sure how to get the constness or abi.

@petrochenkov
Copy link
Contributor

The constness is always non-const for foreign functions, and the ABI can be taken from their parent item - the extern block (at least locally). It's better to look for examples of their use in the compiler and do the same thing, I'm pretty sure codegen takes the ABI of foreign functions from somewhere.

@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 30, 2021
@bors
Copy link
Contributor

bors commented Dec 2, 2021

☔ The latest upstream changes (presumably #91291) made this pull request unmergeable. Please resolve the merge conflicts.

@camelid camelid added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 17, 2021
@camelid
Copy link
Member

camelid commented Dec 17, 2021

how can we find this information for functions without bodies without using fn_sig? In particular, asyncness, constness, and abi - I guess we can just hard-code that trait and foreign functions aren't async for now, but I'm not sure how to get the constness or abi.

I'm probably missing some context, but what's wrong with using tcx.fn_sig()? It looks like you can get unsafety and ABI from it.

@jyn514
Copy link
Member

jyn514 commented Dec 18, 2021

@camelid it panics on trait functions without a default implementation

@camelid
Copy link
Member

camelid commented Dec 18, 2021

But don't those still have signatures?

@JohnCSimon
Copy link
Member

Ping from triage:
@yuvaldolev can you post your status on this PR?
If it's ready for review send a message containing
@rustbot ready

@JohnCSimon
Copy link
Member

@yuvaldolev
Ping from triage:
Closing this due to inactivity because the author hasn't posted in several months.
Please reopen when you are ready to continue with this. Thank you.

@rustbot label: +S-inactive

@JohnCSimon JohnCSimon closed this Feb 12, 2022
@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Feb 12, 2022
@GuillaumeGomez
Copy link
Member

Just gave a try to this issue and I think this is the wrong approach. I'll open a PR shortly once I'm done with the cleanup.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 29, 2022
…camelid

Remove header field from clean::Function

Fixes rust-lang#89673.

This is another take on rust-lang#89673 (compared to rust-lang#91217) but very different on the approach: I moved the header call in one place but still require to have the `clean::Item` so I can use the `DefId` to get what is missing.

cc `@jyn514` (you reviewed the original so maybe you want to take a look?)
r? `@camelid`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants