layout: Store inverse memory index in FieldsShape::Arbitrary#150116
Conversation
|
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
…=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
Adapt kani-compiler to the rustc/rustc_public API changes in this window: - rust-lang/rust#148766 (mir-const-runtime-checks): `Rvalue::NullaryOp` and `NullOp` were removed; `SizeOf`/`AlignOf`/`OffsetOf` become `mir::ConstValue` and the `ub_checks`/`contract_checks`/`overflow_checks` flags move to a new `Operand::RuntimeChecks(RuntimeChecks)`. Drop the `NullaryOp` match arms and handle `Operand::RuntimeChecks` everywhere `Operand` is matched (codegen it to `false`, as the old `NullOp::RuntimeChecks` was; treat it as a no-op in the points-to / uninit / MIR-internalization visitors). - rust-lang/rust#150116: `FieldsShape::Arbitrary::memory_index` renamed to `in_memory_order` (Kani only uses its length). - New `ValueAbi::ScalableVector` variant handled in the valid-value analysis. - rust-lang/rust#6d6068f6c5b (stabilize annotate-snippet): `HumanReadableErrorType` became a struct `{ short, unicode }` instead of an enum with a `Default` variant. Main suites pass on 12-31: expected (458), ui (144), kani (589), 0 failures. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Upgrade the toolchain to `nightly-2025-12-31` and adapt Kani to the corresponding `rustc`/`rustc_public` changes: - **Crate-qualified names** (rust-lang/rust#149401): `name()` now qualifies local items with the crate name. Add a `strip_local_crate_prefix` helper and keep harness/function/static pretty names, the recursion-tracker `--nondet-static-exclude`, stubbing diagnostics, and the autoharness/`list` output crate-relative; fix the automatic contract-harness lookup accordingly. - **MIR runtime checks** (rust-lang/rust#148766): `Rvalue::NullaryOp`/`NullOp` were removed and the `ub`/`contract`/`overflow` checks moved to `Operand::RuntimeChecks`; update the CPROVER and LLBC codegen and the related analyses. - **`unsized_fn_params`**: the updated std passes unsized values by value (e.g. `impl … for [&str]`). Represent unsized-by-value arguments as fat pointers so they codegen instead of triggering an ICE (test under `tests/kani/UnsizedFnParams`). - Smaller adaptations: `FieldsShape::…::in_memory_order` (rust-lang/rust#150116), the new `ValueAbi::ScalableVector` variant, the `HumanReadableErrorType` struct form, coercion/safety cleanups (rust-lang/rust#148602), a refreshed `pointer_generator_error` expected file, and a `clippy::result_large_err` allow. Resolves: model-checking#4623 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
All usages of
memory_indexstart by callinginvert_bijective_mapping, so storing the inverted mapping directly saves some work and simplifies the code.