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

polymorphization: shims and predicates #89514

Merged
merged 5 commits into from
Oct 17, 2021

Conversation

davidtwco
Copy link
Member

Supersedes #75737 and #75414. This pull request includes up some changes to polymorphization which hadn't landed previously and gets stage2 bootstrapping and the test suite passing when polymorphization is enabled. There are still issues with type_id and polymorphization to investigate but this should get polymorphization in a reasonable state to work on.

  • polymorphize: remove predicate logic #75737 and instance: polymorphize shims #75414 both worked but were blocked on having the rest of the test suite pass (with polymorphization enabled) with and without the PRs. It makes more sense to just land these so that the changes are in.
  • polymorphize: remove predicate logic #75737's changes remove the restriction of InstanceDef::Item on polymorphization, so that shims can now be polymorphized. This won't have much of an effect until polymorphization's analysis is more advanced, but it doesn't hurt.
  • instance: polymorphize shims #75414's changes remove all logic which marks parameters as used based on their presence in predicates - given mangling: mangle impl params w/ v0 scheme #75675, this will enable more polymorphization and avoid the symbol clashes that predicate logic previously sidestepped.
  • Polymorphization now explicitly checks (and skips) foreign items, this is necessary for stage2 bootstrapping to work when polymorphization is enabled.
  • The conditional determining the emission of a note adding context to a post-monomorphization error has been modified. Polymorphization results in optimized_mir running for shims during collection where that wouldn't happen previously, some errors are emitted during optimized_mir and these were considered post-monomorphization errors with the existing logic (more errors and shims have a DefId coming from the std crate, not the local crate), adding a note that resulted in tests failing. It isn't particularly feasible to change where polymorphization runs or prevent it from using optimized_mir, so it seemed more reasonable to not change the conditional.
  • characteristic_def_id_of_type was being invoked during partitioning for self types of impl blocks which had projections that depended on the value of unused generic parameters of a function - this caused a ICE in a debuginfo test. If partitioning is enabled and the instance needs substitution then this is skipped. That test still fails for me locally, but not with an ICE, but it fails in a fresh checkout too, so 🤷‍♂️.

r? @lcnr

davidtwco and others added 5 commits October 1, 2021 16:34
Foreign items do not have bodies and so cannot be polymorphized.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit removes all logic which marks parameters as used based on
their presence in predicates - given rust-lang#75675, this will
enable more polymorphization and avoid the symbol clashes that predicate
logic previously sidestepped.

Signed-off-by: David Wood <david@davidtw.co>
rustc adds notes to errors which happen post-monomorphization to
provide the user with helpful context (as these errors may rely on the
specific instantiations). To prevent this note being added where it is
not appropriate, the node is checked to originate outwith the current
crate. However, when polymorphization is enabled, this can result in
some errors (produced by `optimized_mir`) to occur earlier in
compilation than they normally would, during the collection of shims.
Some shims have ids that originate in the standard library, but these
should not receive the PME note, so instances for compiler-generated
functions no longer receive this note.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit removes the restriction of `InstanceDef::Item` on
polymorphization, so that shims can now be polymorphized.

Signed-off-by: David Wood <david.wood@huawei.com>
`characteristic_def_id_of_type` was being invoked during partitioning
for self types of impl blocks which had projections that depended on the
value of unused generic parameters of a function, resulting in an ICE in
the 'generic-names' debuginfo test. If partitioning is enabled and the
instance needs substitution then this is now skipped.

Signed-off-by: David Wood <david.wood@huawei.com>
@rust-highfive
Copy link
Collaborator

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 4, 2021
@lcnr
Copy link
Contributor

lcnr commented Oct 13, 2021

❤️ @bors r+

@bors
Copy link
Contributor

bors commented Oct 13, 2021

📌 Commit b39e915 has been approved by lcnr

@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 Oct 13, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 14, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 16, 2021
…edicates, r=lcnr

polymorphization: shims and predicates

Supersedes rust-lang#75737 and rust-lang#75414. This pull request includes up some changes to polymorphization which hadn't landed previously and gets stage2 bootstrapping and the test suite passing when polymorphization is enabled. There are still issues with `type_id` and polymorphization to investigate but this should get polymorphization in a reasonable state to work on.

- rust-lang#75737 and rust-lang#75414 both worked but were blocked on having the rest of the test suite pass (with polymorphization enabled) with and without the PRs. It makes more sense to just land these so that the changes are in.
- rust-lang#75737's changes remove the restriction of `InstanceDef::Item` on polymorphization, so that shims can now be polymorphized. This won't have much of an effect until polymorphization's analysis is more advanced, but it doesn't hurt.
- rust-lang#75414's changes remove all logic which marks parameters as used based on their presence in predicates - given rust-lang#75675, this will enable more polymorphization and avoid the symbol clashes that predicate logic previously sidestepped.
- Polymorphization now explicitly checks (and skips) foreign items, this is necessary for stage2 bootstrapping to work when polymorphization is enabled.
- The conditional determining the emission of a note adding context to a post-monomorphization error has been modified. Polymorphization results in `optimized_mir` running for shims during collection where that wouldn't happen previously, some errors are emitted during `optimized_mir` and these were considered post-monomorphization errors with the existing logic (more errors and shims have a `DefId` coming from the std crate, not the local crate), adding a note that resulted in tests failing. It isn't particularly feasible to change where polymorphization runs or prevent it from using `optimized_mir`, so it seemed more reasonable to not change the conditional.
- `characteristic_def_id_of_type` was being invoked during partitioning for self types of impl blocks which had projections that depended on the value of unused generic parameters of a function - this caused a ICE in a debuginfo test. If partitioning is enabled and the instance needs substitution then this is skipped. That test still fails for me locally, but not with an ICE, but it fails in a fresh checkout too, so 🤷‍♂️.

r? `@lcnr`
@bors
Copy link
Contributor

bors commented Oct 17, 2021

⌛ Testing commit b39e915 with merge 6f53ddf...

@bors
Copy link
Contributor

bors commented Oct 17, 2021

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing 6f53ddf to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 17, 2021
@bors bors merged commit 6f53ddf into rust-lang:master Oct 17, 2021
@rustbot rustbot added this to the 1.57.0 milestone Oct 17, 2021
@davidtwco davidtwco deleted the polymorphize-shims-and-predicates branch October 17, 2021 17:38
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6f53ddf): comparison url.

Summary: This change led to moderate relevant improvements 🎉 in compiler performance.

  • Moderate improvement in instruction counts (up to -0.8% on full builds of deeply-nested)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

None yet

7 participants