Skip to content

Move Layout to rustc_type_ir and rustc_middle and implement (de)serialization#158576

Open
camelid wants to merge 11 commits into
rust-lang:mainfrom
camelid:move-layout
Open

Move Layout to rustc_type_ir and rustc_middle and implement (de)serialization#158576
camelid wants to merge 11 commits into
rust-lang:mainfrom
camelid:move-layout

Conversation

@camelid

@camelid camelid commented Jun 29, 2026

Copy link
Copy Markdown
Member

@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_sanitizers

cc @rcvalle

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

miri is developed in its own repository. If possible, consider making this change to rust-lang/miri instead.

cc @rust-lang/miri

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. PG-exploit-mitigations Project group: Exploit mitigations 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 Jun 29, 2026
@camelid

camelid commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

cc @workingjubilee

@workingjubilee workingjubilee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wow, I suspect this is almost completely unreviewable with GitHub's limited UI and I will have to pull this to make any sense of it at all.

View changes since this review

/// should generally only be relevant to the ABI details of
/// specific targets.
#[tracing::instrument(skip(cx), level = "debug")]
pub fn homogeneous_aggregate<C>(&self, cx: &C) -> Result<HomogeneousAggregate, Heterogeneous>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So this becomes a free function in rustc_target::callconv

Comment on lines +1344 to +1345
Copy,
Clone,

@workingjubilee workingjubilee Jun 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pure unadulterated off-topic whining that for some reason I feel needs to be said anyways why can't derive(Copy) just imply derive(Clone) sheesh, this only gets so long because of that. it makes sense why it isn't true for Ord and Eq but...

View changes since the review

@camelid

camelid commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

Wow, I suspect this is almost completely unreviewable with GitHub's limited UI and I will have to pull this to make any sense of it at all.

It can mostly be reviewed commit-by-commit. The history isn't as clean as I'd like, though it's mostly modular. Like all or most commits should compile without errors on their own.

@camelid

camelid commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

Almost all of the diff is just changing use paths or removing generic params at use sites.

@bjorn3

bjorn3 commented Jun 29, 2026

Copy link
Copy Markdown
Member

rust-analyzer supports showing type layouts. Does that still work with this PR? I don't know if it reuses the rustc layout definitions or not.

@camelid

camelid commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

rust-analyzer should be OK. x test src/tools/rust-analyzer passes with this code for me. Not sure if there's something else I should check too?

@bjorn3

bjorn3 commented Jun 29, 2026

Copy link
Copy Markdown
Member

Looks like rust-analyzer only uses rustc_abi::LayoutData and not rustc_abi::Layout.

@camelid camelid changed the title [DRAFT] Move Layout to rustc_type_ir and rustc_middle Move Layout to rustc_type_ir and rustc_middle and implement (de)serialization Jun 29, 2026
@rustbot

This comment has been minimized.

@camelid camelid added the needs-mcp This change is large enough that it needs a major change proposal before starting work. label Jun 29, 2026
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

rust-analyzer should be OK. x test src/tools/rust-analyzer passes with this code for me. Not sure if there's something else I should check too?

FYI as of now due to the fast pace development of the next solver, even in-tree r-a depends on rustc crates from crates.io instead of in-tree. So the fact that it compiles is not a proof, although yes this change isn't problematic for us.

@rust-log-analyzer

This comment has been minimized.

@workingjubilee

Copy link
Copy Markdown
Member

what

@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Jun 30, 2026
camelid added 3 commits June 30, 2026 15:33
This is in preparation for moving it from rustc_abi to rustc_target.
This is in preparation for moving Layout and TyAndLayout to
rustc_type_ir/rustc_middle. rustc_abi is a dependency of rustc_type_ir,
which is why homogeneous_aggregate (which uses TyAndLayout) needs to be
moved.

Longer-term, we should probably separate the data structures of
rustc_abi from the code that computes them. It seems a bit weird to have
rustc_type_ir depend on layout-computation code.
Since `Layout`s are interned `LayoutData` values, it makes sense for it
to be with the other interned data structures. This will allow us to
derive `TyDecodable` for `Layout`.
@rustbot

rustbot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@camelid

camelid commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

Added an experimental commit to see if caching layout_of on disk helps perf at all (not the reason for this refactoring, but want to check it out anyway).

@bors try @rust-timer queue

@rust-timer

Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 30, 2026
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
Move `Layout` to `rustc_type_ir` and `rustc_middle` and implement (de)serialization
@camelid

camelid commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

Agh the rebase needs an extra change. @bors try cancel

@rust-bors

rust-bors Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Try build cancelled. Cancelled workflows:

@rust-log-analyzer

This comment has been minimized.

@camelid

camelid commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

Copy link
Copy Markdown
Collaborator

This pull request is already queued and waiting for a try build to finish.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
Move `Layout` to `rustc_type_ir` and `rustc_middle` and implement (de)serialization
@rust-bors

rust-bors Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-gcc failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [run-make] tests/run-make-cargo/rustc-crates-on-stable stdout ----

error: rmake recipe failed to complete
status: exit status: 1
command: cd "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-cargo/rustc-crates-on-stable/rmake_out" && env -u RUSTFLAGS -u __RUSTC_DEBUG_ASSERTIONS_ENABLED -u __STD_DEBUG_ASSERTIONS_ENABLED -u __STD_REMAP_DEBUGINFO_ENABLED AR="ar" BUILD_ROOT="/checkout/obj/build/x86_64-unknown-linux-gnu" CARGO="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools-bin/cargo" CC="cc" CC_DEFAULT_FLAGS="-ffunction-sections -fdata-sections -fPIC -m64" CXX="c++" CXX_DEFAULT_FLAGS="-ffunction-sections -fdata-sections -fPIC -m64" HOST_RUSTC_DYLIB_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/bootstrap-tools/x86_64-unknown-linux-gnu/release/build/run_make_support/e3337ddc0307e9f3/out:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib" LD_LIB_PATH_ENVVAR="LD_LIBRARY_PATH" LLVM_BIN_DIR="/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin" LLVM_COMPONENTS="aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils abi aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgputargetmca amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cas cfguard cgdata codegen codegentypes core coroutines coverage csky cskyasmparser cskycodegen cskydesc cskydisassembler cskyinfo debuginfobtf debuginfocodeview debuginfodwarf debuginfodwarflowlevel debuginfogsym debuginfologicalview debuginfomsf debuginfopdb demangle dlltooldriver dtlto dwarfcfichecker dwarflinker dwarflinkerclassic dwarflinkerparallel dwp engine executionengine extensions filecheck frontendatomic frontenddirective frontenddriver frontendhlsl frontendoffloading frontendopenacc frontendopenmp fuzzercli fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo hipstdpar instcombine instrumentation interfacestub interpreter ipo irprinter irreader jitlink libdriver lineeditor linker loongarch loongarchasmparser loongarchcodegen loongarchdesc loongarchdisassembler loongarchinfo lto m68k m68kasmparser m68kcodegen m68kdesc m68kdisassembler m68kinfo mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts objcopy object objectyaml option orcdebugging orcjit orcshared orctargetprocess passes plugins powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvtargetmca runtimedyld sandboxir scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support supportlsp symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target targetparser telemetry textapi textapibinaryreader transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo webassemblyutils windowsdriver windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86targetmca xray xtensa xtensaasmparser xtensacodegen xtensadesc xtensadisassembler xtensainfo" LLVM_FILECHECK="/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" PYTHON="/usr/bin/python3" RUSTC="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" RUSTDOC="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustdoc" SOURCE_ROOT="/checkout" TARGET="x86_64-unknown-linux-gnu" TARGET_EXE_DYLIB_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" __BOOTSTRAP_JOBS="4" __RMAKE_VERBOSE_SUBPROCESS_OUTPUT="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-cargo/rustc-crates-on-stable/rmake"
stdout: none
--- stderr -------------------------------
command failed at line 41
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-cargo/rustc-crates-on-stable/rmake_out:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/bootstrap-tools/x86_64-unknown-linux-gnu/release/build/run_make_support/e3337ddc0307e9f3/out:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib" RUSTC="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" RUSTC_STAGE="0" RUSTFLAGS="-D warnings -Zallow-features=" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools-bin/cargo" "build" "--manifest-path" "/checkout/Cargo.toml" "--no-default-features" "--target-dir" "target" "-p" "rustc_type_ir" "-p" "rustc_next_trait_solver" "-p" "rustc_pattern_analysis" "-p" "rustc_lexer" "-p" "rustc_abi" "-p" "rustc_parse_format" "-p" "rustc_hashes"
output status: `exit status: 101`
=== STDOUT ===



=== STDERR ===
   Compiling unicode-ident v1.0.24

Important

For more information how to resolve CI failures of this job, visit this link.

@rust-bors

rust-bors Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 18329f9 (18329f9b2266e0477d479015299d99de16c0aad4)
Base parent: 5165714 (51657149e91586571ff1c463bc58239daa1a88d2)

@rust-timer

Copy link
Copy Markdown
Collaborator

Queued 18329f9 with parent 5165714, future comparison URL.
There are currently 0 preceding artifacts in the queue.
It will probably take at least ~1.0 hours until the benchmark run finishes.

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. A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) needs-mcp This change is large enough that it needs a major change proposal before starting work. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-perf Status: Waiting on a perf run to be completed. 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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants