about summary refs log tree commit diff
path: root/compiler/rustc_transmute/src/layout/dfa.rs
AgeCommit message (Collapse)AuthorLines
2025-06-09transmutability: shift abstraction boundaryJack Wrenn-20/+25
Previously, `rustc_transmute`'s layout representations were genericized over `R`, a reference. Now, it's instead genericized over representations of type and region. This allows us to move reference transmutability logic from `rustc_trait_selection` to `rustc_transmutability` (and thus unit test it independently of the compiler), and — in a follow-up PR — will make it possible to support analyzing function pointer transmutability with minimal surgery.
2025-04-30transmutability: merge contiguous runs with a common destinationTomasz Miąsko-6/+18
2025-04-29transmutability: uninit transition matches unit byte onlyTomasz Miąsko-193/+108
The previous implementation was inconsistent about transitions that apply for an init byte. For example, when answering a query, an init byte could use corresponding init transition. Init byte could also use uninit transition, but only when the corresponding init transition was absent. This behaviour was incompatible with DFA union construction. Define an uninit transition to match an uninit byte only and update implementation accordingly. To describe that `Tree::uninit` is valid for any value, build an automaton that accepts any byte value. Additionally, represent byte ranges uniformly as a pair of integers to avoid special case for uninit byte.
2025-04-23transmutability: Mark edges by ranges, not valuesJoshua Liebow-Feeser-70/+363
In the `Tree` and `Dfa` representations of a type's layout, store byte ranges rather than needing to separately store each byte value. This permits us to, for example, represent a `u8` using a single 0..=255 edge in the DFA rather than using 256 separate edges. This leads to drastic performance improvements. For example, on the author's 2024 MacBook Pro, the time to convert the `Tree` representation of a `u64` to its equivalent DFA representation drops from ~8.5ms to ~1us, a reduction of ~8,500x. See `bench_dfa_from_tree`. Similarly, the time to execute a transmutability query from `u64` to `u64` drops from ~35us to ~1.7us, a reduction of ~20x. See `bench_transmute`.
2025-04-20transmutability: remove NFA intermediate representationJack Wrenn-96/+193
Prior to this commit, the transmutability analysis used an intermediate NFA representation of type layout. We then determinized this representation into a DFA, upon which we ran the core transmutability analysis. Unfortunately, determinizing NFAs is expensive. In this commit, we avoid NFAs entirely by observing that Rust `union`s are the only source of nondeterminism and that it is comparatively cheap to compute the DFA union of DFAs. We also implement Graphviz DOT debug formatting of DFAs. Fixes rust-lang/project-safe-transmute#23 Fixes rust-lang/project-safe-transmute#24
2025-03-18Add `#[cfg(test)]` for Transition in dfamu001999-0/+3
2025-02-28Remove `allow(dead_code)` attributes.Nicholas Nethercote-10/+1
By either removing the function, or change the attribute to something more precise.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-2/+4
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-04-30Remove `extern crate tracing` from numerous crates.Nicholas Nethercote-0/+1
2024-04-08Compute transmutability from `rustc_target::abi::Layout`Jack Wrenn-0/+2
In its first step of computing transmutability, `rustc_transmutability` constructs a byte-level representation of type layout (`Tree`). Previously, this representation was computed for ADTs by inspecting the ADT definition and performing our own layout computations. This process was error-prone, verbose, and limited our ability to analyze many types (particularly default-repr types). In this PR, we instead construct `Tree`s from `rustc_target::abi::Layout`s. This helps ensure that layout optimizations are reflected our analyses, and increases the kinds of types we can now analyze, including: - default repr ADTs - transparent unions - `UnsafeCell`-containing types Overall, this PR expands the expressvity of `rustc_transmutability` to be much closer to the transmutability analysis performed by miri. Future PRs will work to close the remaining gaps (e.g., support for `Box`, raw pointers, `NonZero*`, coroutines, etc.).
2022-08-23safe transmute: use `FxIndex{Map,Set}` instead of `FxHash{Map,Set}`Jack Wrenn-1/+0
resolves query instability issues, and probably better for performance
2022-07-28safe transmute: use `AtomicU32` `State` ids to appease mipsJack Wrenn-3/+3
...instead of `AtomicU64`, which is unavailable. ref: https://github.com/rust-lang/rust/pull/92268#issuecomment-1197797990
2022-07-27safe transmute: lowercase tracing levelsJack Wrenn-1/+1
ref: https://github.com/rust-lang/rust/pull/92268#discussion_r927095154
2022-07-27safe transmute: tweak tracingJack Wrenn-1/+1
ref: https://github.com/rust-lang/rust/pull/92268#discussion_r925246903 ref: https://github.com/rust-lang/rust/pull/92268#discussion_r925250811 ref: https://github.com/rust-lang/rust/pull/92268#discussion_r925255782
2022-07-27Initial (incomplete) implementation of transmutability trait.Jack Wrenn-0/+184
This initial implementation handles transmutations between types with specified layouts, except when references are involved. Co-authored-by: Igor null <m1el.2027@gmail.com>