layout: Store inverse memory index in FieldsShape::Arbitrary#150116
layout: Store inverse memory index in FieldsShape::Arbitrary#150116bors merged 1 commit intorust-lang:mainfrom
FieldsShape::Arbitrary#150116Conversation
|
r? @nnethercote rustbot has assigned @nnethercote. Use |
This comment has been minimized.
This comment has been minimized.
c3ca7dc to
8db435e
Compare
|
huh. I wonder what it's inverted relative to? |
This comment has been minimized.
This comment has been minimized.
|
@moulins I have no objection to the substance of the change but "inverse" suggests a relativeness this doesn't capture... IMO this is still just a "memory index" until you do something like specify the other half of the pair, whether it's the key or value, at which point they might adopt a logical ordering.
|
|
kinda curious if this has any effect on perf or if it's just logical cleanup @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
layout: Store inverse memory index in `FieldsShape::Arbitrary`
Hm, good point... what about |
|
something like that sounds good to me! |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (ed52dc8): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 481.694s -> 485.432s (0.78%) |
| FieldsShape::Arbitrary { memory_index, .. } => { | ||
| for idx in Self::aggregate_field_iter(memory_index) { | ||
| FieldsShape::Arbitrary { inverse_memory_index, .. } => { | ||
| for idx in Self::aggregate_field_iter(inverse_memory_index) { |
There was a problem hiding this comment.
If iterating in memory order is now cheap, maybe we should just always do that... in fact that could unlock a bunch of follow-up cleanup here. Probably best to make all that a follow-up PR, but a good indication that this PR moves us in the right direction. :)
There was a problem hiding this comment.
So you'd propose removing aggregate_field_iter entirely and and simply iterate the fields directly?
There was a problem hiding this comment.
Yes. But I would suggest doing it in a separate PR so we can separately benchmark that change.
8db435e to
e0bc269
Compare
This comment has been minimized.
This comment has been minimized.
|
Renamed EDIT: I just noticed that rust-analyzer has its own version of |
|
@moulins I don't think this type is related in a meaningful way? https://github.com/rust-lang/rust/blob/main/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs#L519 Do you mean something else? |
|
To be clear, I am 100% certain that rust-analyzer uses |
|
You're totally right; from what I can see, the uses are here in |
All usages of `memory_index` start by calling `invert_bijective_mapping`, so storing the inverted mapping directly saves some work and simplifies the code.
e0bc269 to
b31ee3a
Compare
|
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
|
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. |
|
Cool! r? workingjubilee ( I don't believe this is truly performance sensitive by itself, I only asked the bot because it was truly just idle curiosity and I'm trying to get a sense of where the hotter spots in |
…=workingjubilee layout: Store inverse memory index in `FieldsShape::Arbitrary` All usages of `memory_index` start by calling `invert_bijective_mapping`, so storing the inverted mapping directly saves some work and simplifies the code.
…=workingjubilee layout: Store inverse memory index in `FieldsShape::Arbitrary` All usages of `memory_index` start by calling `invert_bijective_mapping`, so storing the inverted mapping directly saves some work and simplifies the code.
…=workingjubilee layout: Store inverse memory index in `FieldsShape::Arbitrary` All usages of `memory_index` start by calling `invert_bijective_mapping`, so storing the inverted mapping directly saves some work and simplifies the code.
Rollup of 7 pull requests Successful merges: - #149633 (Enable `outline-atomics` by default on AArch64 FreeBSD) - #149788 (Move shared offload globals and define per-kernel globals once) - #149989 (Improve filenames encoding and misc) - #150012 (rustc_target: Add `efiapi` ABI support for LoongArch) - #150116 (layout: Store inverse memory index in `FieldsShape::Arbitrary`) - #150151 (Destabilise `target-spec-json`) - #150159 (Split eii macro expansion code) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 6 pull requests Successful merges: - #149633 (Enable `outline-atomics` by default on AArch64 FreeBSD) - #149788 (Move shared offload globals and define per-kernel globals once) - #149989 (Improve filenames encoding and misc) - #150012 (rustc_target: Add `efiapi` ABI support for LoongArch) - #150116 (layout: Store inverse memory index in `FieldsShape::Arbitrary`) - #150159 (Split eii macro expansion code) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #150116 - moulins:layout-inv-memory-index, r=workingjubilee layout: Store inverse memory index in `FieldsShape::Arbitrary` All usages of `memory_index` start by calling `invert_bijective_mapping`, so storing the inverted mapping directly saves some work and simplifies the code.
…utine layout This commit fixes a critical bug introduced in PR rust-lang#150116 that caused "offset is not a multiple of 16" errors when compiling for x86_64-unknown-uefi. Problem: -------- PR rust-lang#150116 optimized memory layout by inverting the storage representation from `memory_index` (source→memory) to `in_memory_order` (memory→source). However, in compiler/rustc_abi/src/layout/coroutine.rs (lines 244-276), the code was building `combined_in_memory_order` directly instead of: 1. Building `combined_memory_index` (source→memory) first 2. Inverting it to get `in_memory_order` (memory→source) This caused fields to be placed at incorrect offsets, violating PE/COFF alignment requirements (16-byte multiples), triggering linker errors. Solution: --------- Changed the coroutine layout code to: - Build `combined_memory_index` as an intermediate representation - Use correct indexing: `combined_memory_index[i] = memory_index` - Invert at the end: `combined_in_memory_order = combined_memory_index.invert_bijective_mapping()` Impact: ------- - Fixes UEFI target compilation (x86_64-unknown-uefi) - May affect other PE/COFF targets - Enables SOBEX OS development to continue Files changed: -------------- - compiler/rustc_abi/src/layout/coroutine.rs: Applied fix - BUG_FIX_REPORT.md: Detailed investigation report - fix_pr150116_coroutine_layout.patch: Patch for upstream submission - .gitignore: Added Claude Code settings Upstream: --------- This fix should be submitted to rust-lang/rust as it affects the latest nightly (2025-12-19) and potentially other PE/COFF targets. 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Rollup of 6 pull requests Successful merges: - rust-lang/rust#149633 (Enable `outline-atomics` by default on AArch64 FreeBSD) - rust-lang/rust#149788 (Move shared offload globals and define per-kernel globals once) - rust-lang/rust#149989 (Improve filenames encoding and misc) - rust-lang/rust#150012 (rustc_target: Add `efiapi` ABI support for LoongArch) - rust-lang/rust#150116 (layout: Store inverse memory index in `FieldsShape::Arbitrary`) - rust-lang/rust#150159 (Split eii macro expansion code) r? `@ghost` `@rustbot` modify labels: rollup
PR rust-lang#150116 introduced a bug in coroutine variant layout by incorrectly building the `in_memory_order` mapping directly instead of building an intermediate `memory_index` and inverting it. The bug caused fields to be placed at incorrect memory offsets, violating alignment requirements. This manifested as linker errors on PE/COFF targets (e.g., x86_64-unknown-uefi): error: offset is not a multiple of 16 Fix by correctly building `combined_memory_index` (source→memory) as an intermediate representation, then inverting it to get `combined_in_memory_order` (memory→source).
PR rust-lang#150116 introduced a bug in coroutine variant layout by incorrectly keeping the direct construction of `in_memory_order` without adapting it to the new representation. Before PR rust-lang#150116, the code correctly built an inverse mapping indexed by memory position, then inverted it to get the memory_index. After PR rust-lang#150116, the code still built the mapping indexed by memory position (as if it were an inverse mapping), but treated it directly as `in_memory_order` without inversion. This caused incorrect field ordering. The bug manifested as linker errors on PE/COFF targets (e.g., x86_64-unknown-uefi): error: offset is not a multiple of 16 And as ICEs with non-bijective mapping assertions in other cases. Fix by correctly keeping the inverse memory index construction (indexed by memory position), then using it directly as `in_memory_order` since that's what the new representation expects.
Rollup of 6 pull requests Successful merges: - rust-lang/rust#149633 (Enable `outline-atomics` by default on AArch64 FreeBSD) - rust-lang/rust#149788 (Move shared offload globals and define per-kernel globals once) - rust-lang/rust#149989 (Improve filenames encoding and misc) - rust-lang/rust#150012 (rustc_target: Add `efiapi` ABI support for LoongArch) - rust-lang/rust#150116 (layout: Store inverse memory index in `FieldsShape::Arbitrary`) - rust-lang/rust#150159 (Split eii macro expansion code) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 6 pull requests Successful merges: - rust-lang/rust#149633 (Enable `outline-atomics` by default on AArch64 FreeBSD) - rust-lang/rust#149788 (Move shared offload globals and define per-kernel globals once) - rust-lang/rust#149989 (Improve filenames encoding and misc) - rust-lang/rust#150012 (rustc_target: Add `efiapi` ABI support for LoongArch) - rust-lang/rust#150116 (layout: Store inverse memory index in `FieldsShape::Arbitrary`) - rust-lang/rust#150159 (Split eii macro expansion code) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 6 pull requests Successful merges: - rust-lang/rust#149633 (Enable `outline-atomics` by default on AArch64 FreeBSD) - rust-lang/rust#149788 (Move shared offload globals and define per-kernel globals once) - rust-lang/rust#149989 (Improve filenames encoding and misc) - rust-lang/rust#150012 (rustc_target: Add `efiapi` ABI support for LoongArch) - rust-lang/rust#150116 (layout: Store inverse memory index in `FieldsShape::Arbitrary`) - rust-lang/rust#150159 (Split eii macro expansion code) r? `@ghost` `@rustbot` modify labels: rollup
All usages of
memory_indexstart by callinginvert_bijective_mapping, so storing the inverted mapping directly saves some work and simplifies the code.