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

Use unused_generic_params from crate metadata #109109

Merged
merged 1 commit into from
Mar 15, 2023

Conversation

compiler-errors
Copy link
Member

Due to the way that separate_provide_extern interacted with the implementation of <ty::InstanceDef<'tcx> as Key>::query_crate_is_local, we actually never hit the foreign provider for unused_generic_params.

Additionally, since the local provider of unused_generic_params calls should_polymorphize, which always returns false if the def-id is foreign, this means that we never actually polymorphize monomorphic instances originating from foreign crates.

We don't actually encode unused_generic_params for items where all generics are used, so I had to tweak the foreign provider to fall back to ty::UnusedGenericParams::new_all_used() to avoid more ICEs when the above bugs were fixed.

@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2023

r? @Nilstrieb

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 14, 2023
@compiler-errors
Copy link
Member Author

cc @davidtwco

@@ -226,7 +226,14 @@ provide! { tcx, def_id, other, cdata,
lookup_default_body_stability => { table }
lookup_deprecation_entry => { table }
params_in_repr => { table }
unused_generic_params => { table }
unused_generic_params => {
Copy link
Member

Choose a reason for hiding this comment

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

You had a FIXME in the other PR, could you add this here as well? Would be nice to just default

Copy link
Member

Choose a reason for hiding this comment

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

Oh also, is there a reason why the type doesn't implement that trait? Could you just add the impl? Or is there something to it

Copy link
Member Author

@compiler-errors compiler-errors Mar 14, 2023

Choose a reason for hiding this comment

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

For us to have a defaulted table, the value must implement FixedSizeEncoding and IsDefault. Lazy<T> can be FixedSizeEncoding, but can't be checked for defaultness because they're just a file offset.

I could instead encode the table value as Option<LazyValue<UnusedGenericParams>>, but then ProcessQueryValue<T> for Option<T> panics if the value decoded is None -- we could use specializtion to do:

impl ProcessQueryValue<'_, UnusedGenericParams> for Option<UnusedGenericParams> {
    #[inline(always)]
    fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> UnusedGenericParams {
        self.unwrap_or_else(|| UnusedGenericParams::new_all_used())
    }
}

but I don't feel like using specialization here is compelling enough to save a few lines in the decoder rather than providing an explicit body here.

Copy link
Member

Choose a reason for hiding this comment

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

haha, yeah, it's fine

@Noratrieb
Copy link
Member

r=me

@Noratrieb
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Mar 14, 2023

📌 Commit ee2d428 has been approved by Nilstrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 14, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 15, 2023
Rollup of 7 pull requests

Successful merges:

 - rust-lang#108991 (add `enable-warnings` flag for llvm, and disable it by default.)
 - rust-lang#109109 (Use `unused_generic_params` from crate metadata)
 - rust-lang#109111 (Create dirs for build_triple)
 - rust-lang#109136 (Simplify proc macro signature validity check)
 - rust-lang#109150 (Update cargo)
 - rust-lang#109154 (Fix MappingToUnit  to support no span of arg_ty)
 - rust-lang#109157 (Remove mw from review rotation for a while)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2aa3eea into rust-lang:master Mar 15, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 15, 2023
@davidtwco
Copy link
Member

davidtwco commented Mar 16, 2023

Thanks for catching this - it seems like it could make a significant impact on the effectiveness of polymorphization in cross-crate scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants