Skip to content

Cleanup codegen traits #130457

New issue

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

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

Already on GitHub? # to your account

Merged
merged 11 commits into from
Sep 18, 2024
Merged

Cleanup codegen traits #130457

merged 11 commits into from
Sep 18, 2024

Conversation

nnethercote
Copy link
Contributor

The traits governing codegen are quite complicated and hard to follow. This PR cleans them up a bit.

r? @bjorn3

It only needs `Self::Value` and `Self::Type`, so it can be a subtrait of
`BackendTypes`. That is a smaller and simpler trait than `HasCodegen`
(which includes `BackendTypes` and a lot more).
It has `Backend` and `Deref` boudns, plus an associated type
`CodegenCx`, and it has a single use. This commit "inlines" it into
`BuilderMethods`, which makes the complicated backend trait situation a
little simpler.
It's a trait that aggregates five other traits. But consider the places
that use it.
- `BuilderMethods`: requires three of the five traits.
- `CodegenMethods`: requires zero(!) of the five traits.
- `BaseTypeMethods`: requires two of the five traits.
- `LayoutTypeMethods`: requires three of the five traits.
- `TypeMembershipMethods`: requires one of the five traits.

This commit just removes it, which makes everything simpler.
They both are part of `BuilderMethods`, and so should have `Builder` in
their name like all the other traits in `BuilderMethods`.
Some of these are pulled in indirectly, e.g. `MiscMethods` via
`TypeMethods`.
Specifically, put them where they are genuinely required, i.e. the
outermost place they can be.
Supertraits of `BuilderMethods` are all called `XyzBuilderMethods`.
Supertraits of `CodegenMethods` are all called `XyzMethods`. This commit
changes the latter to `XyzCodegenMethods`, for consistency.
This avoids some repetitive boilerplate code.
@rustbot
Copy link
Collaborator

rustbot commented Sep 17, 2024

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in coverage instrumentation.

cc @Zalathar

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@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 Sep 17, 2024
@nnethercote
Copy link
Contributor Author

Some opinionated changes here, let's see how it goes. Best reviewed one commit at a time.

@bjorn3
Copy link
Member

bjorn3 commented Sep 17, 2024

I'm not entirely happy with "Rename supertraits of CodegenMethods." Other than that everything looks like an improvement to me.

@nnethercote
Copy link
Contributor Author

I'm not entirely happy with "Rename supertraits of CodegenMethods." Other than that everything looks like an improvement to me.

I can remove it, though I would be interested to hear why you don't like it. The Builder/Codegen symmetry seemed obvious to me...

@bjorn3
Copy link
Member

bjorn3 commented Sep 18, 2024

I guess it is fine to keep that commit.

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 18, 2024

📌 Commit acb832d has been approved by bjorn3

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 Sep 18, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 18, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#130457 (Cleanup codegen traits)
 - rust-lang#130471 (Add zlib to musl dist image so rust-lld will support zlib compression for debug info there.)
 - rust-lang#130507 (Improve handling of raw-idents in check-cfg)
 - rust-lang#130509 (llvm-wrapper: adapt for LLVM API changes, second try)
 - rust-lang#130510 (doc: the source of `LetStmt` can also be `AssignDesugar`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 21313d7 into rust-lang:master Sep 18, 2024
6 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 18, 2024
Rollup merge of rust-lang#130457 - nnethercote:cleanup-codegen-traits, r=bjorn3

Cleanup codegen traits

The traits governing codegen are quite complicated and hard to follow. This PR cleans them up a bit.

r? `@bjorn3`
@nnethercote nnethercote deleted the cleanup-codegen-traits branch September 18, 2024 23:14
# for free to join this conversation on GitHub. Already have an account? # 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.

4 participants