Skip to content

cg_llvm: Move all code out of the crate root - #163003

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
Zalathar:llvm-backend
Sep 19, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
Zalathar:llvm-backend

Conversation

@Zalathar

Copy link
Copy Markdown
Member

Having non-trivial code in the crate root causes a few problems, most of which stem from every item being effectively pub(crate):

  • Fields/methods can't be private, so enforcing abstractions is impossible
  • Every use becomes a de-facto re-export, leading to messy imports
  • Moving items out of the root requires visibility adjustment

This PR therefore moves all non-trivial code out of the crate root, and into rustc_codegen_llvm::back::llvm_backend.


Deciding where to move the code to was a bit tricky. But the code being moved delegates a lot of its methods to other submodules in back, so creating another submodule in back seemed reasonable. I certainly like it more than the status-quo.

The main commit doesn't modify any of the code being moved, other than updating imports, as verified manually by:

git diff --color-moved --color-moved-ws=allow-indentation-change head^ head

There should be no change to compiler behaviour.

This makes it easier to confirm that the move itself doesn't modify any code.
Having non-trivial code in the crate root causes a few problems, most
of which stem from every item being effectively `pub(crate)`:

- Fields/methods can't be private, so enforcing abstractions is impossible
- Every `use` becomes a de-facto re-export, leading to messy imports
- Moving items out of the root requires visibility adjustment
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 19, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 19, 2026
@rustbot

rustbot commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

r? @Walnut356

rustbot has assigned @Walnut356.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 20 candidates

@Walnut356

Copy link
Copy Markdown
Contributor

Looks good 👍

@bors r+

@rust-bors

rust-bors Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

📌 Commit eb921ee has been approved by Walnut356

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 19, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 19, 2026
…uwer

Rollup of 2 pull requests

Successful merges:

 - #163003 (cg_llvm: Move all code out of the crate root )
 - #163008 (Add safety section for transmute_neo)
@rust-bors
rust-bors Bot merged commit a21a490 into rust-lang:main Sep 19, 2026
13 checks passed
rust-bors Bot pushed a commit that referenced this pull request Sep 19, 2026
Rollup merge of #163003 - Zalathar:llvm-backend, r=Walnut356

cg_llvm: Move all code out of the crate root

Having non-trivial code in the crate root causes a few problems, most of which stem from every item being effectively `pub(crate)`:

- Fields/methods can't be private, so enforcing abstractions is impossible
- Every `use` becomes a de-facto re-export, leading to messy imports
- Moving items out of the root requires visibility adjustment

This PR therefore moves all non-trivial code out of the crate root, and into `rustc_codegen_llvm::back::llvm_backend`.

---

Deciding where to move the code *to* was a bit tricky. But the code being moved delegates a lot of its methods to other submodules in `back`, so creating another submodule in `back` seemed reasonable. I certainly like it more than the status-quo.

The main commit doesn't modify any of the code being moved, other than updating imports, as verified manually by:

```shell
git diff --color-moved --color-moved-ws=allow-indentation-change head^ head
```

There should be no change to compiler behaviour.
@rustbot rustbot added this to the 1.100.0 milestone Sep 19, 2026
@Zalathar
Zalathar deleted the llvm-backend branch September 20, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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.

3 participants