Commit Graph

48 Commits

Author SHA1 Message Date
Michael Goulet
37076c9b4e Don't attempt to compute layout of type referencing error 2023-07-27 18:24:08 +00:00
bors
c44324a4fe Auto merge of #113677 - bryangarza:unevaluated-const-ice_issue-110892, 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-18 09:07:32 +00:00
Bryan Garza
ef50e204f3 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-17 09:43:35 -07:00
Mahdi Dibaiee
e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Nilstrieb
3019c1cb2a Put LayoutError behind reference to shrink result
`LayoutError` is 24 bytes, which is bigger than the `Ok` types, so let's
shrink that.
2023-07-01 21:16:25 +02:00
Bryan Garza
f4cf8f65a5 Safe Transmute: Refactor error handling and Answer type
- 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-06-12 16:56:21 -07:00
Bryan Garza
d2164d5c9a Safe Transmute: Update definition of Condition type
- Change `Condition` to not contain `Answer`s but instead just contain other
  `Condition`s directly.
- Also improve error reporting for `DstHasStricterAlignment`
2023-05-24 17:49:56 -07:00
Bryan Garza
6266358237 Safe Transmute: Check mutability before creating dst -> src obligation
- 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-24 15:00:06 -07:00
Bryan Garza
94ad084ac6 Safe Transmute: Fix propagation of errors
- 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-24 14:52:19 -07:00
Bryan Garza
263a4f2cb6 Safe Transmute: Change Answer type to Result
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-24 14:52:19 -07:00
Bryan Garza
8f1cec8d84 Safe Transmute: Enable handling references, including recursive types
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-05-24 14:52:18 -07:00
Nicholas Nethercote
671de6d62a Remove unused TypeFoldable/TypeVisitable impls. 2023-04-26 15:19:50 +10:00
Michael Goulet
f6bfb4bf8e Erase regions when confirming transmutability candidate 2023-04-16 19:12:34 +00:00
Matthias Krüger
6ef8648a48 more clippy fixes: clippy::{iter_cloned_collect, unwarp_or_else_default, option_map_or_none} 2023-04-16 12:45:51 +02:00
Bryan Garza
36febe1f4d Improve safe transmute error reporting
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-13 21:57:08 +00:00
Nilstrieb
f058d05fc2 Some simple clippy::perf fixes 2023-04-09 21:59:28 +02:00
Vadim Petrochenkov
c83553da31 rustc_middle: Remove trait DefIdTree
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-03-02 23:46:44 +04:00
Alan Egerton
695072daa6
Remove type-traversal trait aliases 2023-02-22 17:04:58 +00:00
Oli Scherer
936bf29d4c s/eval_usize/eval_target_usize/ for clarity 2023-02-14 08:51:19 +00:00
Scott McMurray
7d57685682 Also remove #![feature(control_flow_enum)] where possible 2023-01-18 10:22:21 -08:00
nils
fd7a159710 Fix uninlined_format_args for some compiler crates
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).
2023-01-05 19:01:12 +01:00
Dylan DPC
a9005b6cc0
Rollup merge of #105864 - matthiaskrgr:compl, r=Nilstrieb
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-19 14:41:35 +05:30
Matthias Krüger
1da4a49912 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
2022-12-19 00:04:28 +01:00
Matthias Krüger
fec9e9ecf1 don't clone Copy types 2022-12-18 14:25:55 +01:00
bors
6b8d9dd0a0 Auto merge of #103831 - chenyukang:yukang/fix-103751-ice, r=nagisa
Fix capacity overflow issue during transmutability check

Fixes #103751
2022-11-05 13:48:30 +00:00
Matthias Krüger
61c6cdb5f4
Rollup merge of #103915 - chenyukang:yukang/fix-103874, r=lcnr
Improve use of ErrorGuaranteed and code cleanup

Part of #103874
2022-11-04 06:40:32 +01:00
yukang
ab22f5521b change error_reported to use Result instead of an option 2022-11-03 04:57:44 +08:00
yukang
749afe57c3 fix #103751: Fix capacity overflow issue during transmutability check 2022-11-01 15:46:58 +08:00
yukang
55568419ac fix #103783, fix ICE checking transmutability of NaughtyLenArray 2022-10-30 06:21:27 +08:00
Cameron Steffen
349415d1c6 Remove TypeckResults from InferCtxt 2022-10-07 07:06:19 -05:00
Takayuki Maeda
0e615caa8d check if const is ADT or not 2022-10-03 17:51:18 +09:00
Josh Stone
a72666ed56 rustc_transmute: fix big-endian discriminants 2022-09-20 13:03:43 -07:00
bors
8521a8c92d Auto merge of #100726 - jswrenn:transmute, r=oli-obk
safe transmute: use `Assume` struct to provide analysis options

This task was left as a TODO in #92268; resolving it brings [`BikeshedIntrinsicFrom`](https://doc.rust-lang.org/nightly/core/mem/trait.BikeshedIntrinsicFrom.html) more in line with the API defined in [MCP411](https://github.com/rust-lang/compiler-team/issues/411).

**Before:**
```rust
pub unsafe trait BikeshedIntrinsicFrom<
    Src,
    Context,
    const ASSUME_ALIGNMENT: bool,
    const ASSUME_LIFETIMES: bool,
    const ASSUME_VALIDITY: bool,
    const ASSUME_VISIBILITY: bool,
> where
    Src: ?Sized,
{}
```
**After:**
```rust
pub unsafe trait BikeshedIntrinsicFrom<Src, Context, const ASSUME: Assume = { Assume::NOTHING }>
where
    Src: ?Sized,
{}
```

`Assume::visibility` has also been renamed to `Assume::safety`, as library safety invariants are what's actually being assumed; visibility is just the mechanism by which it is currently checked (and that may change).

r? `@oli-obk`

---

Related:
- https://github.com/rust-lang/compiler-team/issues/411
- https://github.com/rust-lang/rust/issues/99571
2022-09-04 07:55:44 +00:00
Oli Scherer
ee3c835018 Always import all tracing macros for the entire crate instead of piecemeal by module 2022-09-01 14:54:27 +00:00
Jack Wrenn
fbcc038a22 safe transmute: use to_valtree to destructure const Assume
ref: https://github.com/rust-lang/rust/pull/100726#discussion_r954813220
2022-08-31 18:17:32 +00:00
Dezhi Wu
b1430fb7ca Fix a bunch of typo
This PR will fix some typos detected by [typos].

I only picked the ones I was sure were spelling errors to fix, mostly in
the comments.

[typos]: https://github.com/crate-ci/typos
2022-08-31 18:24:55 +08:00
Yuki Okushi
ba31a9b505
Rollup merge of #100604 - dtolnay:okorerr, r=m-ou-se
Remove unstable Result::into_ok_or_err

Pending FCP: https://github.com/rust-lang/rust/issues/82223#issuecomment-1214920203

```@rustbot``` label +waiting-on-fcp
2022-08-26 09:51:44 +09:00
Jack Wrenn
1d844fe629 safe transmute: use FxIndex{Map,Set} instead of FxHash{Map,Set}
resolves query instability issues, and probably better for performance
2022-08-23 15:52:49 +00:00
Jack Wrenn
f46fffc276 safe transmute: use Assume struct to provide analysis options
This was left as a TODO in #92268, and brings the trait more in
line with what was defined in MCP411.

`Assume::visibility` has been renamed to `Assume::safety`, as
library safety is what's actually being assumed; visibility is
just the mechanism by which it is currently checked (this may
change).

ref: https://github.com/rust-lang/compiler-team/issues/411
ref: https://github.com/rust-lang/rust/issues/99571
2022-08-22 18:37:54 +00:00
Jhonny Bill Mena
c835d9c0d2 ADD - diagnostic lints to rustc_transmute
Module is complete because it has zero diagnostics.
2022-08-21 09:17:09 -04:00
David Tolnay
39809c5f68
Replace a try_fold in rustc_transmute to use ControlFlow instead of Result 2022-08-17 17:20:42 -07:00
David Tolnay
83f081fc01
Remove unstable Result::into_ok_or_err 2022-08-17 17:20:42 -07:00
Jack Wrenn
965ffb0b5c safe transmute: fix broken intradoc link 2022-08-02 14:44:23 +00:00
Jack Wrenn
e8a1925b64 safe transmute: use AtomicU32 State ids to appease mips
...instead of `AtomicU64`, which is unavailable.

ref: https://github.com/rust-lang/rust/pull/92268#issuecomment-1197797990
2022-07-28 13:47:11 +00:00
Jack Wrenn
aee5f31c68 safe transmute: lowercase tracing levels
ref: https://github.com/rust-lang/rust/pull/92268#discussion_r927095154
2022-07-27 17:33:57 +00:00
Jack Wrenn
2268603046 safe transmute: tweak Nfa::union to consume params by value
ref: https://github.com/rust-lang/rust/pull/92268#discussion_r925274516
2022-07-27 17:33:57 +00:00
Jack Wrenn
c0d0ce95eb safe transmute: tweak tracing
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-27 17:33:56 +00:00
Jack Wrenn
bc4a1dea41 Initial (incomplete) implementation of transmutability trait.
This initial implementation handles transmutations between types with specified layouts, except when references are involved.

Co-authored-by: Igor null <m1el.2027@gmail.com>
2022-07-27 17:33:56 +00:00