about summary refs log tree commit diff
path: root/compiler/rustc_transmute
AgeCommit message (Collapse)AuthorLines
2024-04-19ScalarInt: add methods to assert being a (u)int of given sizeRalf Jung-1/+1
2024-04-08Rollup merge of #123367 - jswrenn:layoutify, r=compiler-errorsMatthias Krüger-247/+230
Safe Transmute: Compute transmutability from `rustc_target::abi::Layout` 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.). r? `@compiler-errors`
2024-04-08Compute transmutability from `rustc_target::abi::Layout`Jack Wrenn-247/+230
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.).
2024-03-27Remove unnecessary `Partial/Ord` deriveOli Scherer-1/+1
2024-03-22Rollup merge of #122784 - jswrenn:tag_for_variant, r=compiler-errorsMatthias Krüger-25/+19
Add `tag_for_variant` query This query allows for sharing code between `rustc_const_eval` and `rustc_transmutability`. It's a precursor to a PR I'm working on to entirely replace the bespoke layout computations in `rustc_transmutability`. r? `@compiler-errors`
2024-03-22Add `tag_for_variant` queryJack Wrenn-25/+19
This query allows for sharing code between `rustc_const_eval` and `rustc_transmutability`. Also moves `DummyMachine` to `rustc_const_eval`.
2024-03-18Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few ↵Oli Scherer-1/+2
cases that used `None`
2024-03-15Safe Transmute: Use 'not yet supported', not 'unspecified' in errorsJack Wrenn-13/+13
We can (and will) support analyzing the transmutability of types whose layouts aren't completely specified by its repr. This change ensures that the error messages remain sensible after this support lands.
2024-03-13safe transmute: require that src referent is smaller than dstJack Wrenn-3/+39
The source referent absolutely must be smaller than the destination referent of a ref-to-ref transmute; the excess bytes referenced cannot arise from thin air, even if those bytes are uninitialized.
2024-03-08bump itertools to 0.12klensy-1/+1
still depend on 0.11: * clippy * rustfmt, sigh
2024-03-05Convert `TypeVisitor` and `DefIdVisitor` to use `VisitorResult`Jason Newcomb-7/+9
2024-02-27safe transmute: revise safety analysisJack Wrenn-109/+168
Migrate to a simplified safety analysis that does not use visibility. Closes https://github.com/rust-lang/project-safe-transmute/issues/15
2024-02-06Invert diagnostic lints.Nicholas Nethercote-2/+0
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-01-25Remove unused featuresclubby789-1/+2
2024-01-09Fix an ICE that occurs after an error has already been reportedOli Scherer-0/+1
2023-11-22Update itertools to 0.11.Nicholas Nethercote-1/+1
Because the API for `with_position` improved in 0.11 and I want to use it.
2023-10-30Clean up `rustc_*/Cargo.toml`.Nicholas Nethercote-5/+7
- Sort dependencies and features sections. - Add `tidy` markers to the sorted sections so they stay sorted. - Remove empty `[lib`] sections. - Remove "See more keys..." comments. Excluded files: - rustc_codegen_{cranelift,gcc}, because they're external. - rustc_lexer, because it has external use. - stable_mir, because it has external use.
2023-10-18Use v0.0.0 in compiler cratesMichael Goulet-1/+1
2023-10-06Remove the `MaybeTransmutableQuery<&'l Dfa<...>, C>` impl.Nicholas Nethercote-16/+0
Because there is also a `MaybeTransmutableQuery<Dfa<...>, C>` impl, and we don't need both.
2023-10-06Fix a comment.Nicholas Nethercote-3/+1
It was duplicated from the method above.
2023-10-06Remove `map_layouts`.Nicholas Nethercote-57/+33
As per the `FIXME` comment, it's an abstraction that makes the code harder to read.
2023-10-06Make the comment order match variant declaration order.Nicholas Nethercote-1/+1
2023-10-06Remove an unnecessary `pub(crate)`.Nicholas Nethercote-1/+1
2023-09-13make the eval() functions on our const types return the resulting valueRalf Jung-7/+4
2023-09-06Fix error report for size overflow from transmuteyukang-0/+9
2023-07-27Don't attempt to compute layout of type referencing errorMichael Goulet-1/+1
2023-07-18Auto merge of #113677 - bryangarza:unevaluated-const-ice_issue-110892, ↵bors-1/+12
r=davidtwco Safe Transmute: Fix ICE (due to UnevaluatedConst) This patch updates the code that looks at the `Assume` type when evaluating if transmutation is possible. An ICE was being triggered in the case that the `Assume` parameter contained an unevaluated const (in this test case, due to a function with missing parameter names). Fixes #110892
2023-07-17Safe Transmute: Fix ICE (due to UnevaluatedConst)Bryan Garza-1/+12
This patch updates the code that looks at the `Assume` type when evaluating if transmutation is possible. An ICE was being triggered in the case that the `Assume` parameter contained an unevaluated const (in this test case, due to a function with missing parameter names). Fixes #110892
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-7/+7
2023-07-01Put `LayoutError` behind reference to shrink resultNilstrieb-4/+4
`LayoutError` is 24 bytes, which is bigger than the `Ok` types, so let's shrink that.
2023-06-12Safe Transmute: Refactor error handling and Answer typeBryan Garza-89/+99
- Create `Answer` type that is not just a type alias of `Result` - Remove a usage of `map_layouts` to make the code easier to read - Don't hide errors related to Unknown Layout when computing transmutability
2023-05-24Safe Transmute: Update definition of Condition typeBryan Garza-14/+17
- Change `Condition` to not contain `Answer`s but instead just contain other `Condition`s directly. - Also improve error reporting for `DstHasStricterAlignment`
2023-05-24Safe Transmute: Check mutability before creating dst -> src obligationBryan Garza-7/+32
- Only create dst -> src obligation if Dst is mutable - Add some long comments to explain parts of the transmutability code that were unclear to me when reading - Update/add tests
2023-05-24Safe Transmute: Fix propagation of errorsBryan Garza-15/+30
- Make sure that the most specific Reason is the one that bubbles up when we are folding over the `Answer` tree. `Reason::DstIsBitIncompatible` is the least specific, so that should be used only when there isn't anything else available. - Small fixes where we used the wrong Reason variant. - Tiny cleanups
2023-05-24Safe Transmute: Change Answer type to ResultBryan Garza-117/+90
This patch updates the `Answer` type from `rustc_transmute` so that it just a type alias to `Result`. This makes it so that the standard methods for `Result` can be used to process the `Answer` tree, including being able to make use of the `?` operator on `Answer`s. Also, remove some unused functions
2023-05-24Safe Transmute: Enable handling references, including recursive typesBryan Garza-51/+178
This patch enables support for references in Safe Transmute, by generating nested obligations during trait selection. Specifically, when we call `confirm_transmutability_candidate(...)`, we now recursively traverse the `rustc_transmute::Answer` tree and create obligations for all the `Answer` variants, some of which include multiple nested `Answer`s. Also, to handle recursive types, enable support for coinduction for the Safe Transmute trait (`BikeshedIntrinsicFrom`) by adding the `#[rustc_coinduction]` annotation. Also fix some small logic issues when reducing the `or` and `and` combinations in `rustc_transmute`, so that we don't end up with additional redundant `Answer`s in the tree. Co-authored-by: Jack Wrenn <jack@wrenn.fyi>
2023-04-26Remove unused `TypeFoldable`/`TypeVisitable` impls.Nicholas Nethercote-2/+2
2023-04-16Erase regions when confirming transmutability candidateMichael Goulet-6/+3
2023-04-16more clippy fixes: clippy::{iter_cloned_collect, unwarp_or_else_default, ↵Matthias Krüger-1/+1
option_map_or_none}
2023-04-13Improve safe transmute error reportingBryan Garza-28/+33
This patch updates the error reporting when Safe Transmute is not possible between 2 types by including the reason. Also, fix some small bugs that occur when computing the `Answer` for transmutability.
2023-04-09Some simple `clippy::perf` fixesNilstrieb-1/+1
2023-03-02rustc_middle: Remove trait `DefIdTree`Vadim Petrochenkov-3/+1
This trait was a way to generalize over both `TyCtxt` and `Resolver`, but now `Resolver` has access to `TyCtxt`, so this trait is no longer necessary.
2023-02-22Remove type-traversal trait aliasesAlan Egerton-1/+1
2023-02-14s/eval_usize/eval_target_usize/ for clarityOli Scherer-2/+3
2023-01-18Also remove `#![feature(control_flow_enum)]` where possibleScott McMurray-1/+1
2023-01-05Fix `uninlined_format_args` for some compiler cratesnils-1/+1
Convert all the crates that have had their diagnostic migration completed (except save_analysis because that will be deleted soon and apfloat because of the licensing problem).
2022-12-19Rollup merge of #105864 - matthiaskrgr:compl, r=NilstriebDylan DPC-5/+1
clippy::complexity fixes filter_next needless_question_mark bind_instead_of_map manual_find derivable_impls map_identity redundant_slicing skip_while_next unnecessary_unwrap needless_bool r? `@compiler-errors`
2022-12-19clippy::complexity fixesMatthias Krüger-5/+1
filter_next needless_question_mark bind_instead_of_map manual_find derivable_impls map_identity redundant_slicing skip_while_next unnecessary_unwrap needless_bool
2022-12-18don't clone Copy typesMatthias Krüger-2/+2
2022-11-05Auto merge of #103831 - chenyukang:yukang/fix-103751-ice, r=nagisabors-2/+2
Fix capacity overflow issue during transmutability check Fixes #103751