Commit Graph

1782 Commits

Author SHA1 Message Date
Nicholas Nethercote
cde19c016e Rename Handler as DiagCtxt. 2023-12-18 16:06:19 +11:00
Jubilee
9e872b7cd8
Rollup merge of #118933 - nnethercote:cleanup-errors-even-more, r=compiler-errors
Cleanup errors handlers even more

A sequel to #118587.

r? `@compiler-errors`
2023-12-14 16:07:48 -08:00
Nicholas Nethercote
9a78412511 Split Handler::emit_diagnostic in two.
Currently, `emit_diagnostic` takes `&mut self`.

This commit changes it so `emit_diagnostic` takes `self` and the new
`emit_diagnostic_without_consuming` function takes `&mut self`.

I find the distinction useful. The former case is much more common, and
avoids a bunch of `mut` and `&mut` occurrences. We can also restrict the
latter with `pub(crate)` which is nice.
2023-12-15 10:13:12 +11:00
Matthias Krüger
49a2fc22e9
Rollup merge of #118935 - RalfJung:interpret-downcast, r=saethlin
interpret: extend comment on the inhabitedness check in downcast

Cc https://github.com/rust-lang/rust/issues/115145
r? ``@saethlin``
2023-12-14 20:33:11 +01:00
Ralf Jung
5d87d8307f interpret: extend comment on the inhabitedness check in downcast 2023-12-14 09:50:47 +01:00
Ralf Jung
7e4c4271f4 fix computing the dynamic alignment of packed structs with dyn trait tails 2023-12-13 20:21:57 +01:00
bors
56d25ba5ea Auto merge of #118500 - ZetaNumbers:tcx_hir_refactor, r=petrochenkov
Move some methods from `tcx.hir()` to `tcx`

https://github.com/rust-lang/rust/pull/118256#issuecomment-1826442834

Renamed:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id
2023-12-13 10:31:56 +00:00
bors
2fdd9eda0c Auto merge of #118534 - RalfJung:extern-type-size-of-val, r=WaffleLapkin
codegen: panic when trying to compute size/align of extern type

The alignment is also computed when accessing a field of extern type at non-zero offset, so we also panic in that case.

Previously `size_of_val` worked because the code path there assumed that "thin pointer" means "sized". But that's not true any more with extern types. The returned size and align are just blatantly wrong, so it seems better to panic than returning wrong results. We use a non-unwinding panic since code probably does not expect size_of_val to panic.
2023-12-13 08:33:05 +00:00
Matthias Krüger
d707461a1a clippy::complexity fixes
filter_map_identity
 needless_bool
 search_is_some
 unit_arg
 map_identity
 needless_question_mark
 derivable_impls
2023-12-12 19:28:13 +01:00
zetanumbers
24f009c5e5 Move some methods from tcx.hir() to tcx
Renamings:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id

Fix rebase changes using removed methods

Use `tcx.hir_node_by_def_id()` whenever possible in compiler

Fix clippy errors

Fix compiler

Apply suggestions from code review

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

Add FIXME for `tcx.hir()` returned type about its removal

Simplify with with `tcx.hir_node_by_def_id`
2023-12-12 06:40:29 -08:00
Ralf Jung
9ef1e35166 reject projecting to fields whose offset we cannot compute 2023-12-12 08:15:17 +01:00
bors
6f40082313 Auto merge of #118661 - fee1-dead-contrib:restore-const-partialEq, r=compiler-errors
Restore `const PartialEq`

And thus fixes a number of tests. There is a bug that still needs to be fixed, so WIP for now.

r? `@compiler-errors`
2023-12-11 10:34:51 +00:00
bors
e299752868 Auto merge of #118032 - RalfJung:char-u32, r=Mark-Simulacrum
guarantee that char and u32 are ABI-compatible

In https://github.com/rust-lang/rust/pull/116894 we added a guarantee that `char` has the same alignment as `u32`, but there is still one axis where these types could differ: function call ABI. So let's nail that down as well: in a function signature, `char` and `u32` are completely equivalent.

This is a new stable guarantee, so it will need t-lang approval.
2023-12-11 04:13:19 +00:00
bors
84f6130fe3 Auto merge of #118692 - surechen:remove_unused_imports, r=petrochenkov
remove redundant imports

detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.

r? `@petrochenkov`
2023-12-10 11:55:48 +00:00
Deadbeef
d1f4bc5a19 Revert "Don't print host effect param in pretty path_generic_args"
This reverts commit f1bf874fb1.
2023-12-10 10:17:28 +00:00
surechen
40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Michael Goulet
7467c3a45c s/const_effect/host_effect 2023-12-09 17:43:08 +00:00
Michael Goulet
f1bf874fb1 Don't print host effect param in pretty path_generic_args 2023-12-09 17:42:33 +00:00
bors
ae612bedcb Auto merge of #118689 - compiler-errors:const-drop, r=fee1-dead
Fix const drop checking

Fixes confirmation of `~const Destruct` and const drops.

r? fee1-dead
2023-12-08 13:43:12 +00:00
bors
0e7f91b75e Auto merge of #118324 - RalfJung:ctfe-read-only-pointers, r=saethlin
compile-time evaluation: detect writes through immutable pointers

This has two motivations:
- it unblocks https://github.com/rust-lang/rust/pull/116745 (and therefore takes a big step towards `const_mut_refs` stabilization), because we can now detect if the memory that we find in `const` can be interned as "immutable"
- it would detect the UB that was uncovered in https://github.com/rust-lang/rust/pull/117905, which was caused by accidental stabilization of `copy` functions in `const` that can only be called with UB

When UB is detected, we emit a future-compat warn-by-default lint. This is not a breaking change, so completely in line with [the const-UB RFC](https://rust-lang.github.io/rfcs/3016-const-ub.html), meaning we don't need t-lang FCP here. I made the lint immediately show up for dependencies since it is nearly impossible to even trigger this lint without `const_mut_refs` -- the accidentally stabilized `copy` functions are the only way this can happen, so the crates that popped up in #117905 are the only causes of such UB (in the code that crater covers), and the three cases of UB that we know about have all been fixed in their respective crates already.

The way this is implemented is by making use of the fact that our interpreter is already generic over the notion of provenance. For CTFE we now use the new `CtfeProvenance` type which is conceptually an `AllocId` plus a boolean `immutable` flag (but packed for a more efficient representation). This means we can mark a pointer as immutable when it is created as a shared reference. The flag will be propagated to all pointers derived from this one. We can then check the immutable flag on each write to reject writes through immutable pointers.

I just hope perf works out.
2023-12-07 18:11:01 +00:00
Ralf Jung
8188bd4548 avoid marking as immutable what is already immutable
this has been demonstrated to help performance
2023-12-07 17:46:48 +01:00
Ralf Jung
4d93590d59 compile-time evaluation: emit a lint when a write through an immutable pointer occurs 2023-12-07 17:46:36 +01:00
Ralf Jung
cb86303342 ctfe interpreter: extend provenance so that it can track whether a pointer is immutable 2023-12-07 17:46:36 +01:00
Michael Goulet
efe8ae730f Fix const drop checking 2023-12-07 16:28:33 +00:00
Guillaume Gomez
4128809726
Rollup merge of #118565 - RalfJung:numeric_intrinsic, r=davidtwco
interpret: make numeric_intrinsic accessible from Miri

This will let us share the code of the cttz and simd_cttz intrinsics (and same for ctlz).
2023-12-04 20:46:09 +01:00
Takayuki Maeda
30a4215532
Rollup merge of #118573 - petrochenkov:pathdatakind, r=TaKO8Ki
rustc: Harmonize `DefKind` and `DefPathData`

Follow up to https://github.com/rust-lang/rust/pull/118188.

`DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`.

`DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`.
It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` instead could be a better solution, but that would be a much more invasive change.

Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values.

`DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
2023-12-04 21:19:45 +09:00
Takayuki Maeda
87625dbf2b
Rollup merge of #118540 - RalfJung:unsized-packed-offset, r=TaKO8Ki
codegen, miri: fix computing the offset of an unsized field in a packed struct

`#[repr(packed)]`  strikes again.

Fixes https://github.com/rust-lang/rust/issues/118537
Fixes https://github.com/rust-lang/miri/issues/3200

`@bjorn3` I assume cranelift needs the same fix.
2023-12-04 21:19:44 +09:00
Ralf Jung
bebba4f6e0 miri: support 'promising' alignment for symbolic alignment check 2023-12-03 21:51:14 +01:00
Vadim Petrochenkov
17e799c270 rustc: Harmonize DefKind and DefPathData
`DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`.

`DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`.
It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` could be a better solution, but that would be a much more invasive change.

Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values.

`DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
2023-12-03 16:24:56 +03:00
Ralf Jung
edabd477f8 interpret: make numeric_intrinsic accessible from Miri 2023-12-03 11:51:58 +01:00
Ralf Jung
ef15a8182b codegen, miri: fix computing the offset of an unsized field in a packed struct 2023-12-03 08:26:51 +01:00
bors
2da59b8676 Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compiler-errors
Cleanup error handlers

Mostly by making function naming more consistent. More to do after this, but this is enough for one PR.

r? compiler-errors
2023-12-02 02:48:34 +00:00
Nicholas Nethercote
a179a53565 Use Session::diagnostic in more places. 2023-12-02 09:01:35 +11:00
Nicholas Nethercote
c9008c6c8b Rename Handler::delay_good_path_bug as Handler::good_path_delayed_bug.
In line with the previous commits.
2023-12-02 09:01:34 +11:00
Nicholas Nethercote
5d1d384443 Rename HandlerInner::delay_span_bug as HandlerInner::span_delayed_bug.
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug`
follows the pattern used everywhere else: `span_err`, `span_warning`,
etc.
2023-12-02 09:01:19 +11:00
bors
a1c65db95c Auto merge of #118482 - RalfJung:interpret-local-type, r=WaffleLapkin
explain a good reason for why LocalValue does not store the type of the local

As found out by `@lcnr` in https://github.com/rust-lang/rust/pull/112307, storing the type here can lead to subtle bugs when it gets out of sync with the MIR body. That's not the reason why the interpreter does it this way I think, but good thing we dodged that bullet. :)
2023-12-01 04:08:22 +00:00
Ralf Jung
a1b03e3067 explain a good reason for why LocalValue does not store the type of the local 2023-11-30 17:01:28 +01:00
Ralf Jung
cabfe8f5dc move write_aggregate into step file, and also extract write_repeat into separate function 2023-11-28 11:40:17 +01:00
Vadim Petrochenkov
c697927f44 rustc: hir().local_def_id_to_hir_id() -> tcx.local_def_id_to_hir_id() cleanup 2023-11-26 12:41:21 +03:00
Michael Goulet
3b2f33ee28
Rollup merge of #118158 - nnethercote:reduce-fluent-boilerplate, r=compiler-errors
Reduce fluent boilerplate

Best reviewed one commit at a time.

r? `@davidtwco`
2023-11-25 17:23:33 -05:00
Nicholas Nethercote
57cd5e6551 Use rustc_fluent_macro::fluent_messages! directly.
Currently we always do this:
```
use rustc_fluent_macro::fluent_messages;
...
fluent_messages! { "./example.ftl" }
```
But there is no need, we can just do this everywhere:
```
rustc_fluent_macro::fluent_messages! { "./example.ftl" }
```
which is shorter.
2023-11-26 08:38:40 +11:00
Nicholas Nethercote
a733082be9 Avoid need for {D,Subd}iagnosticMessage imports.
The `fluent_messages!` macro produces uses of
`crate::{D,Subd}iagnosticMessage`, which means that every crate using
the macro must have this import:
```
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
```

This commit changes the macro to instead use
`rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the
imports.
2023-11-26 08:38:00 +11:00
Guillaume Gomez
9a59b059d5
Rollup merge of #117871 - klensy:unused-pub, r=cjgillot
remove unused pub fns

This removes some unused `pub fn`; also fixes few obsoleted fn names or added fixmes with reminders to update them.
2023-11-25 19:51:54 +01:00
bors
fad6bb80fa Auto merge of #118075 - tmiasko:validate-critical-call-edges, r=cjgillot
Validate there are no critical call edges in optimized MIR
2023-11-25 09:10:44 +00:00
klensy
b06d5b205c few more 2023-11-23 14:11:08 +03:00
klensy
aff6c741d4 remove unused pub fn 2023-11-23 14:11:02 +03:00
bors
38eecca62c Auto merge of #118073 - saethlin:gc-dead-allocs, r=RalfJung
Miri: GC the dead_alloc_map too

dead_alloc_map is the last piece of state in the interpreter I can find that leaks. With this PR, all of the long-term memory growth I can find in Miri with programs that do things like run a big `loop {` or run property tests is attributable to some data structure properties in borrow tracking, and is _extremely_ slow.

My only gripe with the commit in this PR is that I don't have a new test for it. I'd like to have a regression test for this, but it would have to be statistical I think because the peak memory of a process that Linux reports is not exactly the same run-to-run. Which means it would have to not be very sensitive to slow leaks (some guesswork suggests for acceptable CI time we would be checking for like 10% memory growth over a minute or two, which is still pretty fast IMO).

Unless someone has a better idea for how to detect a regression, I think on balance I'm fine with manually keeping an eye on the memory use situation.

r? RalfJung
2023-11-23 08:20:21 +00:00
Ben Kimock
f5dae8e73c Miri: GC the dead_alloc_map too 2023-11-22 22:40:55 -05:00
Michael Goulet
040151a4be
Rollup merge of #118147 - Nilstrieb:no-redundant-casts, r=WaffleLapkin
Fix some unnecessary casts

`x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix` with some manual review to ensure every fix is correct.
2023-11-22 09:28:51 -08:00
Tomasz Miąsko
cef892ebab Validate there are no critical call edges in optimized MIR 2023-11-22 01:56:31 +01:00
Nilstrieb
c089a162d8 Fix some unnecessary casts
`x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix`
with some manual review to ensure every fix is correct.
2023-11-21 22:11:08 +01:00
Nilstrieb
21a870515b Fix clippy::needless_borrow in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed
now.
2023-11-21 20:13:40 +01:00
Nilstrieb
cbadb2e1c0
Rollup merge of #118029 - saethlin:allocid-gc, r=RalfJung
Expand Miri's BorTag GC to a Provenance GC

As suggested in https://github.com/rust-lang/miri/issues/3080#issuecomment-1732505573

We previously solved memory growth issues associated with the Stacked Borrows and Tree Borrows runtimes with a GC. But of course we also have state accumulation associated with whole allocations elsewhere in the interpreter, and this PR starts tackling those.

To do this, we expand the visitor for the GC so that it can visit a BorTag or an AllocId. Instead of collecting all live AllocIds into a single HashSet, we just collect from the Machine itself then go through an accessor `InterpCx::is_alloc_live` which checks a number of allocation data structures in the core interpreter. This avoids the overhead of all the inserts that collecting their keys would require.

r? ``@RalfJung``
2023-11-21 14:36:13 +01:00
Michael Goulet
94d9b7e708
Rollup merge of #117832 - RalfJung:interpret-shift, r=cjgillot
interpret: simplify handling of shifts by no longer trying to handle signed and unsigned shift amounts in the same branch

While we're at it, also update comments in codegen and MIR building related to shifts, and fix the overflow error printed by Miri on negative shift amounts.
2023-11-19 19:14:33 -08:00
Ben Kimock
0d0a41789f Expand Miri's BorTag GC to a Provenance GC 2023-11-19 13:29:02 -05:00
bors
d0474fba92 Auto merge of #117807 - RalfJung:raw-str-slice, r=davidtwco
patterns: don't ice when encountering a raw str slice

Fixes https://github.com/rust-lang/rust/issues/117806
2023-11-19 07:44:43 +00:00
Ralf Jung
b4f3f2aeac guarantee that char and u32 are ABI-compatible 2023-11-18 08:24:02 +01:00
lcnr
41cfb20abb replace unnecessary folder impls with fold_region 2023-11-17 08:58:18 +00:00
Mark Rousskov
917f6540ed Re-format code with new rustfmt 2023-11-15 21:45:48 -05:00
Mark Rousskov
db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
cui fliter
a44a4edc0e Fix some typos
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-11-14 23:06:50 +08:00
Ralf Jung
31493c70fa interpret: simplify handling of shifts by no longer trying to handle signed and unsigned shift amounts in the same branch 2023-11-12 12:49:46 +01:00
Ralf Jung
f6a49ba416 patterns: don't ice when encountering a raw str slice 2023-11-12 09:43:08 +01:00
bors
b7583d38b7 Auto merge of #117712 - lcnr:expand-coroutine, r=jackh726
generator layout: ignore fake borrows

fixes #117059

We emit fake shallow borrows in case the scrutinee place uses a `Deref` and there is a match guard. This is necessary to prevent the match guard from mutating the scrutinee: fab1054e17/compiler/rustc_mir_build/src/build/matches/mod.rs (L1250-L1265)

These fake borrows end up impacting the generator witness computation in `mir_generator_witnesses`, which causes the issue in #117059. This PR now completely ignores fake borrows during this computation. This is sound as thse are always removed after analysis and the actual computation of the generator layout happens afterwards.

Only the second commit impacts behavior, and could be backported by itself.

r? types
2023-11-09 14:23:45 +00:00
lcnr
992d93f687 rename BorrowKind::Shallow to Fake
also adds some comments
2023-11-08 22:55:28 +01:00
bors
fdaaaf9f92 Auto merge of #116930 - RalfJung:raw-ptr-match, r=davidtwco
patterns: reject raw pointers that are not just integers

Matching against `0 as *const i32` is fine, matching against `&42 as *const i32` is not.

This extends the existing check against function pointers and wide pointers: we now uniformly reject all these pointer types during valtree construction, and then later lint because of that. See [here](https://github.com/rust-lang/rust/pull/116930#issuecomment-1784654073) for some more explanation and context.

Also fixes https://github.com/rust-lang/rust/issues/116929.

Cc `@oli-obk` `@lcnr`
2023-11-08 20:42:32 +00:00
bors
9c20ddd956 Auto merge of #117507 - nnethercote:rustc_span, r=Nilstrieb
`rustc_span` cleanups

Just some things I found while looking over this crate.

r? `@oli-obk`
2023-11-03 14:57:40 +00:00
Nicholas Nethercote
f405ce86c2 Minimize pub usage in source_map.rs.
Most notably, this commit changes the `pub use crate::*;` in that file
to `use crate::*;`. This requires a lot of `use` items in other crates
to be adjusted, because everything defined within `rustc_span::*` was
also available via `rustc_span::source_map::*`, which is bizarre.

The commit also removes `SourceMap::span_to_relative_line_string`, which
is unused.
2023-11-02 19:35:00 +11:00
Matthias Krüger
4e437be044
Rollup merge of #117441 - cjgillot:diag-noassert, r=oli-obk,RalfJung
Do not assert in op_to_const.

`op_to_const` is used in `try_destructure_mir_constant_for_diagnostics`, which may encounter invalid constants created by optimizations and debugging.

r? ``@oli-obk``

Fixes https://github.com/rust-lang/rust/issues/117368
2023-11-01 21:40:06 +01:00
Matthias Krüger
3087b63d1f
Rollup merge of #117373 - saethlin:avoid-ice-lint, r=compiler-errors
Avoid the path trimming ICE lint in error reporting

Types or really anything in MIR should never be formatted without path trimming disabled, because its formatting often tries to construct trimmed paths. In this case, the lint turns a nice error report into an irrelevant ICE.
2023-11-01 21:40:05 +01:00
Camille GILLOT
f512f91258 Comment for_diagnostics flag. 2023-11-01 19:01:55 +00:00
Camille GILLOT
224e29030a Specify diagnostic path. 2023-11-01 18:36:38 +00:00
Camille GILLOT
3a55c283d0 Rename hook. 2023-11-01 16:49:18 +00:00
Camille GILLOT
c2f49e9edf Do not assert in op_to_const. 2023-11-01 16:49:18 +00:00
Ben Kimock
88f0688530 Avoid the path trimming ICE lint in error reporting 2023-11-01 10:54:07 -04:00
bors
146dafa262 Auto merge of #114208 - GKFX:offset_of_enum, r=wesleywiser
Support enum variants in offset_of!

This MR implements support for navigating through enum variants in `offset_of!`, placing the enum variant name in the second argument to `offset_of!`. The RFC placed it in the first argument, but I think it interacts better with nested field access in the second, as you can then write things like

```rust
offset_of!(Type, field.Variant.field)
```

Alternatively, a syntactic distinction could be made between variants and fields (e.g. `field::Variant.field`) but I'm not convinced this would be helpful.

[RFC 3308 # Enum Support](https://rust-lang.github.io/rfcs/3308-offset_of.html#enum-support-offset_ofsomeenumstructvariant-field_on_variant)
Tracking Issue #106655.
2023-11-01 14:17:56 +00:00
George Bateman
d995bd61e7
Enums in offset_of: update based on est31, scottmcm & llogiq review 2023-10-31 23:26:02 +00:00
George Bateman
e936416a8d
Support enum variants in offset_of! 2023-10-31 23:25:54 +00:00
Oli Scherer
77174d3f29 Turn const_caller_location from a query to a hook 2023-10-31 16:15:18 +00:00
Guillaume Gomez
73100d8e93
Rollup merge of #117317 - RalfJung:track-caller, r=oli-obk
share some track_caller logic between interpret and codegen

Also move the code that implements the track_caller intrinsics out of the core interpreter engine -- it's just a helper creating a const-allocation, doesn't need to be part of the interpreter core.
2023-10-30 17:33:16 +01:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- 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-30 08:46:02 +11:00
bors
83c9732e0c Auto merge of #116270 - cjgillot:gvn-aggregate, r=oli-obk,RalfJung
See through aggregates in GVN

This PR is extracted from https://github.com/rust-lang/rust/pull/111344

The first 2 commit are cleanups to avoid repeated work. I propose to stop removing useless assignments as part of this pass, and let a later `SimplifyLocals` do it. This makes tests easier to read (among others).

The next 3 commits add a constant folding mechanism to the GVN pass, presented in https://github.com/rust-lang/rust/pull/116012. ~This pass is designed to only use global allocations, to avoid any risk of accidental modification of the stored state.~

The following commits implement opportunistic simplifications, in particular:
- projections of aggregates: `MyStruct { x: a }.x` gets replaced by `a`, works with enums too;
- projections of arrays: `[a, b][0]` becomes `a`;
- projections of repeat expressions: `[a; N][x]` becomes `a`;
- transform arrays of equal operands into a repeat rvalue.

Fixes https://github.com/rust-lang/miri/issues/3090

r? `@oli-obk`
2023-10-29 14:50:53 +00:00
Ralf Jung
bec88ad4aa patterns: reject raw pointers that are not just integers 2023-10-28 17:02:18 +02:00
Ralf Jung
04fa124feb share the track_caller handling within a mir::Body 2023-10-28 16:16:15 +02:00
Ralf Jung
351d532a27 interpret: call caller_location logic the same way codegen does, and share some code 2023-10-28 15:40:03 +02:00
Camille GILLOT
72f0e0e795 Rename has_provance and tweaks comments. 2023-10-25 17:59:30 +00:00
Oli Scherer
c601ade3ad Refactor away the need for some descr methods.
Instead we use `Display` impls and their `alternate` render scheme to
decide whether we want backticks or not.
2023-10-25 16:40:32 +00:00
Oli Scherer
af8a998b1e Rename AsyncCoroutineKind to CoroutineSource
similar to how we have `MatchSource`, it explains where the desugaring came from.
2023-10-25 16:14:05 +00:00
Camille GILLOT
f08dc9be17 Take an AllocId in intern_const_alloc_for_constprop. 2023-10-25 06:46:48 +00:00
Camille GILLOT
ff6812cd20 Move provenance checks out of interning method. 2023-10-25 06:46:48 +00:00
Camille GILLOT
ebc87bf567 Directly intern values instead of copying them. 2023-10-25 06:46:48 +00:00
Camille GILLOT
38c86b0798 Evaluate computed values to constants. 2023-10-25 06:46:47 +00:00
Matthias Krüger
0aade2f0de
Rollup merge of #117081 - GoodDaisy:master, r=wesleywiser
fix typos in comments
2023-10-24 17:08:59 +02:00
Matthias Krüger
8af4a3f9cd
Rollup merge of #116859 - Nilstrieb:more-more-funny-pretty-printers, r=oli-obk
Make `ty::print::Printer` take `&mut self` instead of `self`

based on #116815

This simplifies the code by removing all the `self` assignments and
makes the flow of data clearer - always into the printer.
Especially in v0 mangling, which already used  `&mut self` in some
places, it gets a lot more uniform.
2023-10-23 22:26:29 +02:00
GoodDaisy
0d780b108b fix typos in comments 2023-10-23 20:52:14 +08:00
Oli Scherer
066ec1273a Ensure that eval_to_allocation_raw isn't called on static items from miri 2023-10-23 08:35:27 +00:00
Oli Scherer
fec0b54978 Split eval_to_allocation_raw_provider 2023-10-23 08:35:26 +00:00
Oli Scherer
f85b139704 Pull out const error reporting into its own function 2023-10-23 08:35:26 +00:00
Oli Scherer
5784e9e83e Pull mplace validation logic out into an interpreter method 2023-10-23 08:35:26 +00:00
Oli Scherer
0fce74e1c0 The mutability was ignored anyway, so just check for staticness 2023-10-23 08:35:26 +00:00
Nilstrieb
5acf26b97e Make ty::print::Printer take &mut self instead of self
This simplifies the code by removing all the `self` assignments and
makes the flow of data clearer - always into the printer.
Especially in v0 mangling, which already used  `&mut self` in some
places, it gets a lot more uniform.
2023-10-21 11:33:05 +02:00
Oli Scherer
2d91c76d5d Rename CoroutineKind::Gen to ::Coroutine 2023-10-20 21:14:01 +00:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Michael Goulet
5ceda6b016 Adjust imports 2023-10-20 15:52:57 +00:00
bors
94c4e5c411 Auto merge of #115214 - Urgau:rfc-3127-trim-paths, r=compiler-errors
Implement rustc part of RFC 3127 trim-paths

This PR implements (or at least tries to) [RFC 3127 trim-paths](https://github.com/rust-lang/rust/issues/111540), the rustc part. That is `-Zremap-path-scope` with all of it's components/scopes.

`@rustbot` label: +F-trim-paths
2023-10-19 19:09:29 +00:00
Matthias Krüger
1d46614335
Rollup merge of #116650 - RalfJung:miri-intptrcast, r=oli-obk
add some comments and some cleanup around Miri intptrcast

`@saethlin` maybe this helps a bit?
2023-10-19 14:38:26 +02:00
bors
e8b8c78d84 Auto merge of #116815 - Nilstrieb:more-funny-pretty-printers, r=compiler-errors
Remove lots of generics from `ty::print`

All of these generics mostly resolve to the same thing, which means we can remove them, greatly simplifying the types involved in pretty printing and unlocking another simplification (that is not performed in this PR): Using `&mut self` instead of passing `self` through the return type.

cc `@eddyb` you probably know why it's like this, just checking in and making sure I didn't do anything bad

r? oli-obk
2023-10-18 09:57:07 +00:00
Nilstrieb
6fc6a6d783 Remove Print::Error
All printing goes through `fmt::Error` now.
2023-10-17 18:02:57 +02:00
Nilstrieb
6038888118 Remove Printer::Error
It's always a `fmt::Error` except in some cases where it was `!`, but
we're not really winning anything in that case.
2023-10-17 18:02:55 +02:00
Nilstrieb
0b5a4c1adf Remove Print::Output
Now that `Printer` doesn't have subprinters anymore, the output of a
printing operation is always the same.
2023-10-17 18:01:07 +02:00
Nilstrieb
3895f0e9af Remove "subprinter" types from Printer
These are `Self` in almost all printers except one, which can just store
the state as a field instead. This simplifies the printer and allows for
further simplifications, for example using `&mut self` instead of
passing around the printer.
2023-10-17 18:01:05 +02:00
Urgau
eccc9e6628 [RFC 3127 - Trim Paths]: Condition remapped filepath on remap scopes 2023-10-17 10:11:30 +02:00
Michael Howell
2ff2624722 docs: add Rust logo to more compiler crates
c6e6ecb1af added it to some of the
compiler's crates, but avoided adding it to all of them to reduce
bit-rot. This commit adds to more.
2023-10-16 15:38:08 -07:00
bors
98c1e3d95b Auto merge of #116550 - nnethercote:rustc-features-more, r=Nilstrieb
Cleanup `rustc_features` some more

The sequel to #116437.

r? `@Nilstrieb`
2023-10-16 14:34:53 +00:00
bors
e7bdc5f9f8 Auto merge of #114330 - RalfJung:dagling-ptr-deref, r=oli-obk
don't UB on dangling ptr deref, instead check inbounds on projections

This implements https://github.com/rust-lang/reference/pull/1387 in Miri. See that PR for what the change is about.

Detecting dangling references in `let x = &...;` is now done by validity checking only, so some tests need to have validity checking enabled. There is no longer inherently a "nodangle" check in evaluating the expression `&*ptr` (aside from the aliasing model).

r? `@oli-obk`

Based on:
- https://github.com/rust-lang/reference/pull/1387
- https://github.com/rust-lang/rust/pull/115524
2023-10-16 12:40:16 +00:00
bors
a00c09e9d8 Auto merge of #116724 - RalfJung:alloc-bytes, r=oli-obk
interpret: clean up AllocBytes

Fixes https://github.com/rust-lang/miri/issues/2836
Nothing has moved here in half a year, so let's just remove these unused stubs -- they need a proper re-design anyway.

r? `@oli-obk`
2023-10-16 10:45:00 +00:00
Nicholas Nethercote
d284c8a2d7 Rename ACTIVE_FEATURES as UNSTABLE_FEATURES.
It's a better name, and lets "active features" refer to the features
that are active in a particular program, due to being declared or
enabled by the edition.

The commit also renames `Features::enabled` as `Features::active` to
match this; I changed my mind and have decided that "active" is a little
better thatn "enabled" for this, particularly because a number of
pre-existing comments use "active" in this way.

Finally, the commit renames `Status::Stable` as `Status::Accepted`, to
match `ACCEPTED_FEATURES`.
2023-10-16 08:17:23 +11:00
Ralf Jung
b131fc10ae separate bounds-check from alignment check 2023-10-15 18:13:33 +02:00
Ralf Jung
e24835c6e0 more precise error for 'based on misaligned pointer' case 2023-10-15 18:13:33 +02:00
Ralf Jung
cbf47a17d2 avoid computing misalignment if we won't act on it 2023-10-15 18:13:33 +02:00
Ralf Jung
f3f9b795bd place evaluation: require the original pointer to be aligned if an access happens 2023-10-15 18:13:31 +02:00
Ralf Jung
ea9a24e32e avoid re-checking the offset while iterating an array/slice 2023-10-15 18:12:46 +02:00
Ralf Jung
b1ebf002c3 don't UB on dangling ptr deref, instead check inbounds on projections 2023-10-15 18:12:46 +02:00
bors
a48396984a Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb
Format all the let-chains in compiler crates

Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped).

This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else.

I will also add this commit to the ignore list after it has landed.

The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree.
```
~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates
~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif
```

cc `@rust-lang/rustfmt`
r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :>

cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
2023-10-15 13:23:55 +00:00
Guillaume Gomez
03cbf50c34
Rollup merge of #116576 - eduardosm:const-eval-wasm-target-features, r=RalfJung
const-eval: allow calling functions with targat features disabled at compile time in WASM

This is not unsafe on WASM, see https://github.com/rust-lang/rust/pull/84988

r? `@RalfJung`

Fixes https://github.com/rust-lang/rust/issues/116516
2023-10-14 22:35:05 +02:00
Eduardo Sánchez Muñoz
f9b1af6587 const-eval: allow calling functions with targat features disabled at compile time in WASM
This is not unsafe on WASM, see https://github.com/rust-lang/rust/pull/84988
2023-10-14 20:15:05 +02:00
Ralf Jung
9c417a4ad4 interpret: clean up AllocBytes 2023-10-14 12:29:16 +02:00
bors
139f63a6eb Auto merge of #116015 - EvanMerlock:master, r=oli-obk
const_eval: allow function pointer signatures containing &mut T in const contexts

potentially fixes #114994

We utilize a `TypeVisitor` here in order to more easily handle control flow.
- In the event the typekind the Visitor sees is a function pointer, we skip over it
- However, otherwise we do one of two things:
   - If we find a mutable reference, check it, then continue visiting types
   - If we find any other type, continue visiting types

This means we will check if the function pointer _itself_ is mutable, but not if any of the types _within_ are.
2023-10-14 09:18:28 +00:00
bors
75a5dd05bc Auto merge of #115524 - RalfJung:misalign, r=wesleywiser
const-eval: make misalignment a hard error

It's been a future-incompat error (showing up in cargo's reports) since https://github.com/rust-lang/rust/pull/104616, Rust 1.68, released in March.  That should be long enough.

The question for the lang team is simply -- should we move ahead with this, making const-eval alignment failures a hard error? (It turns out some of them accidentally already were hard errors since #104616. But not all so this is still a breaking change. Crater found no regression.)
2023-10-14 00:57:09 +00:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Ralf Jung
1ee055f0ec add some comments and some cleanup around Miri intptrcast 2023-10-13 07:42:07 +02:00
bors
061c33051a Auto merge of #116551 - RalfJung:nondet-nan, r=oli-obk
miri: make NaN generation non-deterministic

This implements the [LLVM semantics for NaN generation](https://llvm.org/docs/LangRef.html#behavior-of-floating-point-nan-values). I will soon submit an RFC to make this also officially the Rust semantics, but it has been our de-facto semantics for a long time so there's no reason Miri has to wait for that RFC. This PR just better aligns Miri with codegen.

This PR does that just for the operations that have MIR primitives; a future PR will adjust the intrinsics.
2023-10-10 11:42:27 +00:00
Ralf Jung
08deb0daed float-to-float casts also have non-deterministic NaN results 2023-10-09 08:30:34 +02:00
Ralf Jung
615d738abe ensure unary minus propagates NaN payloads exactly 2023-10-09 07:37:24 +02:00
Ralf Jung
6796c5765d miri: make NaN generation non-deterministic 2023-10-08 20:35:46 +02:00
bors
48e24629e9 Auto merge of #115583 - RalfJung:packed-unsized, r=lcnr
fix detecting references to packed unsized fields

Fixes https://github.com/rust-lang/rust/issues/115396

This is a breaking change, but permitted as a soundness fix.
2023-10-07 10:57:18 +00:00
Jubilee
6d1c3a40cb
Rollup merge of #116277 - RalfJung:post-mono, r=oli-obk
dont call mir.post_mono_checks in codegen

It seems like all tests are still passing when I remove this... let's see what CI says.
2023-10-06 16:37:46 -07:00
bors
94bc9c737e Auto merge of #114811 - estebank:impl-ambiguity, r=wesleywiser
Show more information when multiple `impl`s apply

- When there are `impl`s without type params, show only those (to avoid showing overly generic `impl`s).
```
error[E0283]: type annotations needed
  --> $DIR/multiple-impl-apply.rs:34:9
   |
LL |     let y = x.into();
   |         ^     ---- type must be known at this point
   |
note: multiple `impl`s satisfying `_: From<Baz>` found
  --> $DIR/multiple-impl-apply.rs:14:1
   |
LL | impl From<Baz> for Bar {
   | ^^^^^^^^^^^^^^^^^^^^^^
...
LL | impl From<Baz> for Foo {
   | ^^^^^^^^^^^^^^^^^^^^^^
   = note: required for `Baz` to implement `Into<_>`
help: consider giving `y` an explicit type
   |
LL |     let y: /* Type */ = x.into();
   |          ++++++++++++
```

- Lower the importance of `T: Sized`, `T: WellFormed` and coercion errors, to prioritize more relevant errors. The pre-existing deduplication logic deals with hiding redundant errors better that way, and we show errors with more metadata that is useful to the user.

- Show `<SelfTy as Trait>::assoc_fn` suggestion in more cases.
```
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> $DIR/cross-return-site-inference.rs:38:16
   |
LL |     return Err(From::from("foo"));
   |                ^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to a specific available implementation
   |
LL |     return Err(</* self type */ as From>::from("foo"));
   |                +++++++++++++++++++     +
```

Fix #88284.
2023-10-06 18:44:32 +00:00
Camille GILLOT
e63d19c4dd Remove mir::LocalDecl::internal. 2023-10-04 17:55:15 +00:00
Esteban Küber
91b9ffeab0 Reorder fullfillment errors to keep more interesting ones first
In `report_fullfillment_errors` push back `T: Sized`, `T: WellFormed`
and coercion errors to the end of the list. The pre-existing
deduplication logic eliminates redundant errors better that way, keeping
the resulting output with fewer errors than before, while also having
more detail.
2023-10-04 02:04:14 +00:00
bors
e3c631b3de Auto merge of #116376 - matthiaskrgr:rollup-b3d14gq, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #115863 (Add check_unused_messages in tidy)
 - #116210 (Ensure that `~const` trait bounds on associated functions are in const traits or impls)
 - #116358 (Rename both of the `Match` relations)
 - #116371 (Remove unused features from `rustc_llvm`.)
 - #116374 (Print normalized ty)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-03 11:49:06 +00:00
bors
eb0f3ed59c Auto merge of #115025 - ouz-a:ouz_testing, r=lcnr
Make subtyping explicit in MIR

This adds new mir-opt that pushes new `ProjectionElem` called `ProjectionElem::Subtype(T)` to `Rvalue` of a subtyped assignment so we can unsoundness issues like https://github.com/rust-lang/rust/issues/107205

Addresses https://github.com/rust-lang/rust/issues/112651

r? `@lcnr`
2023-10-03 10:02:52 +00:00
ouz-a
42c39b343d print normalized ty 2023-10-03 12:17:27 +03:00
ouz-a
5d753abb30 have better explanation for relate_types 2023-10-02 23:39:45 +03:00
ouz-a
6f0c5ee2d4 change is_subtype to relate_types 2023-10-02 23:39:45 +03:00
ouz-a
cd7f471931 Add docs, remove code, change subtyper code 2023-10-02 23:39:44 +03:00
ouz-a
3148e6a993 subtyping_projections 2023-10-02 23:37:49 +03:00
bors
8fa7bdf191 Auto merge of #115670 - Zoxc:outline-panic-macro-1, r=Mark-Simulacrum
Partially outline code inside the panic! macro

This outlines code inside the panic! macro in some cases. This is split out from https://github.com/rust-lang/rust/pull/115562 to exclude changes to rustc.
2023-10-01 05:56:47 +00:00
Ralf Jung
acb7c21507 dont call mir.post_mono_checks in codegen 2023-09-30 07:38:08 +02:00
Oli Scherer
0031cf7c7e Add a mir validation check to prevent OpaqueCast after analysis passes finish 2023-09-28 16:13:38 +00:00
Oli Scherer
2d4201f7c6 Skip reinterning if nothing changed 2023-09-28 16:13:38 +00:00
Oli Scherer
6ea2db7c2d Strip OpaqueCast during RevealAll. 2023-09-28 16:13:38 +00:00
Ralf Jung
a993a8bf3f const-eval: make misalignment a hard error 2023-09-26 15:32:55 +02:00
lcnr
3c52a3e280 subst -> instantiate 2023-09-26 09:37:55 +02:00
Camille GILLOT
44ac8dcc71 Remove GeneratorWitness and rename GeneratorWitnessMIR. 2023-09-23 13:47:30 +00:00
Evan Merlock
fd1ccbc68d fix(const_eval): correctly check const type for function pointers
- uses TypeReader for resolving local/return ty to support case where function pointer is before another type in a compound type
2023-09-22 19:43:02 -05:00
Oli Scherer
2ba911c832 Have a single struct for queries and hook 2023-09-22 16:26:20 +00:00
Oli Scherer
2157f31731 Add a way to decouple the implementation and the declaration of a TyCtxt method. 2023-09-22 09:23:15 +00:00
bors
0fd7ce99b0 Auto merge of #116010 - RalfJung:more-typed-immediates, r=oli-obk
interpret: more consistently use ImmTy in operators and casts

The diff in src/tools/miri/src/shims/x86/sse2.rs should hopefully suffice to explain why this is nicer. :)
2023-09-21 14:02:55 +00:00
Guillaume Gomez
208f6ed95c
Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obk
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const

Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`.

Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all.

However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish...

``@oli-obk`` any ideas?
2023-09-21 13:25:39 +02:00
Oli Scherer
9c762b58ba Prevent promotion of const fn calls in inline consts 2023-09-21 09:00:22 +00:00
Ralf Jung
c94410c145 rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const 2023-09-21 08:12:30 +02:00
Ralf Jung
0eff07b748 try to avoid some layout_of calls 2023-09-21 07:26:16 +02:00
Ralf Jung
23fd2860fa stronger consistency check in ImmTy::from_immediate 2023-09-20 22:28:46 +02:00
Ralf Jung
bdbf545f42 interpret: less debug-printing of types 2023-09-20 22:25:42 +02:00
Ralf Jung
da08a3f40c interpret: more consistently use ImmTy in operators and casts 2023-09-20 21:57:54 +02:00
Ralf Jung
a2374e65aa the Const::eval_bits methods don't need to be given the Ty 2023-09-20 07:27:21 +02:00
Ralf Jung
ea22adbabd adjust constValue::Slice to work for arbitrary slice types 2023-09-19 20:17:43 +02:00
Ralf Jung
5a0a1ff0cd move ConstValue into mir
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-19 11:11:02 +02:00
bors
cebb9cfd4f Auto merge of #115748 - RalfJung:post-mono, r=oli-obk
move required_consts check to general post-mono-check function

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) https://github.com/rust-lang/rust/issues/115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? `@oli-obk`
2023-09-18 19:41:21 +00:00
Ralf Jung
06a76ab415 make interpreter type Debug impl independent of Ty debug impl 2023-09-15 09:54:06 +02:00
Ralf Jung
9ac8b363e3 don't point at const usage site for resolution-time errors
also share the code that emits the actual error
2023-09-14 22:34:05 +02:00
Ralf Jung
89ac57db4d move required_consts check to general post-mono-check function 2023-09-14 22:30:42 +02:00
bors
e437e57954 Auto merge of #115804 - RalfJung:valtree-to-const-val, r=oli-obk
consistently pass ty::Const through valtrees

Some drive-by things extracted from https://github.com/rust-lang/rust/pull/115748.
2023-09-14 15:34:31 +00:00
Ralf Jung
7aa44eee99 don't force all slice-typed ConstValue to be ConstValue::Slice 2023-09-14 11:56:55 +02:00
Ralf Jung
06947be196 valtree_to_const_value: add fast-path for Scalar tuples/structs 2023-09-14 07:40:05 +02:00
Ralf Jung
430c386821 make it more clear which functions create fresh AllocId 2023-09-14 07:27:31 +02:00
Ralf Jung
0f8908da27 cleanup op_to_const a bit; rename ConstValue::ByRef → Indirect 2023-09-14 07:27:30 +02:00
Ralf Jung
551f481ffb use AllocId instead of Allocation in ConstValue::ByRef 2023-09-14 07:26:24 +02:00
Ralf Jung
3aedb85a27 a bit of cleanup in valtree_to_const_value 2023-09-14 07:22:44 +02:00
bors
eb2446a57e Auto merge of #115820 - matthiaskrgr:rollup-kyglvpu, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #115736 (Remove `verbose_generic_activity_with_arg`)
 - #115771 (cleanup leftovers of const_err lint)
 - #115798 (add helper method for finding the one non-1-ZST field)
 - #115812 (Merge settings.css into rustdoc.css)
 - #115815 (fix: return early when has tainted in mir pass)
 - #115816 (Disabled socketpair for Vita)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-13 18:19:15 +00:00
Matthias Krüger
565b9c2264
Rollup merge of #115798 - RalfJung:non_1zst_field, r=wesleywiser
add helper method for finding the one non-1-ZST field
2023-09-13 18:37:42 +02:00
Matthias Krüger
1ec29fb24f
Rollup merge of #115771 - RalfJung:no-more-const-err-lint, r=oli-obk
cleanup leftovers of const_err lint

Some code / comments seem to not have been updated when const_err was turned into a hard error, so we can do a bit of cleanup here.

r? `@oli-obk`
2023-09-13 18:37:42 +02:00
Camille GILLOT
054ed8e7eb Introduce Machine::POST_MONO_CHECKS. 2023-09-12 20:17:52 +00:00
Ralf Jung
60091fe924 add helper method for finding the one non-1-ZST field 2023-09-12 20:52:05 +02:00
Ralf Jung
fd91dfb494 cleanup leftovers of const_err lint 2023-09-12 13:41:42 +02:00
bors
cc7a9d6972 Auto merge of #115705 - cjgillot:const-prop-aggregate, r=oli-obk
Read from non-scalar constants and statics in dataflow const-prop

DataflowConstProp is designed to handle scalar values. When MIR features an assignment from a non-scalar constant, we need to manually decompose it into the custom state space.

This PR tweaks interpreter callbacks to allow reusing `eval_mir_constant` without having a stack frame to get a span from.

r? `@oli-obk`
cc `@jachris`
2023-09-12 09:02:27 +00:00
Camille GILLOT
6984030f80 Use write_immediate. 2023-09-11 16:29:42 +00:00
Camille GILLOT
bcfe1a4bf2 Remove cur_span hook. 2023-09-11 16:29:42 +00:00
Camille GILLOT
4901893721 Inline callback. 2023-09-11 16:29:41 +00:00
Camille GILLOT
d278ce126c Return ImmTy in discriminant_for_variant. 2023-09-11 16:29:41 +00:00
Camille GILLOT
6ad6b4381c Support non-scalar constants. 2023-09-11 16:29:41 +00:00
Ralf Jung
e00120906e handle/hack for arbitrary-self dyn receivers 2023-09-09 15:38:23 +02:00
Ralf Jung
a38a3bfc6d implement and test ABI compatibility for transparent wrappers around NPO types 2023-09-09 15:36:44 +02:00
Ralf Jung
b5bab2b1cc implement and test fn ptr ABI compatibility rules 2023-09-09 15:36:44 +02:00
Ralf Jung
f993ddc079 give extra context to ABI mismatch errors 2023-09-09 15:36:44 +02:00
Ralf Jung
897a65804d interpret: change ABI-compat test to be type-based, so the test is consistent across targets 2023-09-09 15:36:44 +02:00
John Kåre Alsaker
6a02baaa3d Partially outline code inside the panic! macro 2023-09-08 14:05:57 +02:00
bors
cd71a37f32 Auto merge of #115372 - RalfJung:abi-assert-eq, r=davidtwco
add rustc_abi(assert_eq) to test some guaranteed or at least highly expected ABI compatibility guarantees

This new repr(transparent) test is super useful, it would have found https://github.com/rust-lang/rust/issues/115336 and found https://github.com/rust-lang/rust/issues/115404, https://github.com/rust-lang/rust/issues/115481, https://github.com/rust-lang/rust/issues/115509.
2023-09-08 11:56:08 +00:00
Ralf Jung
b0cf4c28ea turns out Layout has some more things to worry about -- move ABI comparison into helper function
like is_bool, and some special magic extra fields
2023-09-08 09:14:07 +02:00
Ralf Jung
c3e14edd8b accept some differences for rustc_abi(assert_eq), so that we can test more things to be compatible 2023-09-08 08:59:55 +02:00
bors
3d249706aa Auto merge of #115608 - RalfJung:fn-arg-validity, r=oli-obk
miri: catch function calls where the argument is caller-invalid / the return value callee-invalid

When doing a type-changing copy, we must validate the data both at the old and new type.

Fixes https://github.com/rust-lang/miri/issues/3017
2023-09-08 04:10:14 +00:00
Ralf Jung
73d8dcb803 miri: catch function calls where the argument is caller-invalid / the return value callee-invalid 2023-09-06 16:36:00 +02:00
Ralf Jung
ad7045e160 still accept references to u8 slices and str in packed fields 2023-09-06 08:32:30 +02:00
Ralf Jung
8b3435c10f fix detecting references to packed unsized fields 2023-09-05 22:29:51 +02:00
Camille GILLOT
26c48e6f95 Refactor how MIR represents composite debuginfo. 2023-09-05 17:20:07 +00:00
Ralf Jung
fa5f13775a interpret: make MemPlace, Place, Operand types private to the interpreter 2023-09-04 17:53:38 +02:00
Ralf Jung
efc759238d miri ABI check: fix handling of 1-ZST; don't accept sign differences 2023-08-31 17:27:23 +02:00
Ralf Jung
c37bd09d88 miri function ABI check: specifically look for repr(transparent) 2023-08-30 17:07:25 +02:00
Ralf Jung
1e95aa0c49 interpret: make sure we accept transparent newtypes as ABI-compatible
also we were missing the case for Vector arguments, so handle those as well
2023-08-30 17:04:54 +02:00
Ralf Jung
6d1ce9bd13 storage_live: avoid computing the layout unless necessary 2023-08-30 13:46:55 +02:00
Ralf Jung
f87e91de7d unify passing of sized and unsized function arguments :-) 2023-08-30 13:46:55 +02:00
Ralf Jung
7cdeff266c a bit of meta-related cleanup on Projectable 2023-08-30 13:46:55 +02:00
Ralf Jung
a09df43d9f move marking-locals-live out of push_stack_frame, so it happens with argument passing
this entirely avoids even creating unsized locals in Immediate::Uninitialized state
2023-08-30 13:46:54 +02:00
Ralf Jung
bdd5855b8e interpret: fix projecting into an unsized field of a local
new invariant: Place::Local never refers to something unsized
2023-08-30 13:43:34 +02:00
Matthias Krüger
23f86255ef
Rollup merge of #115272 - RalfJung:miri-error-print, r=saethlin
miri/diagnostics: don't forget to print_backtrace when ICEing on unexpected errors

This should fix the missing output encountered [here](https://github.com/rust-lang/rust/issues/115145#issuecomment-1694334410).

r? `@saethlin`
2023-08-30 07:18:11 +02:00
Ralf Jung
b2ebf1c23f const_eval and codegen: audit uses of is_zst 2023-08-29 09:03:46 +02:00
bors
191dc54dbf Auto merge of #115182 - RalfJung:abi-compat-sign, r=b-naber
miri ABI compatibility check: accept u32 and i32

If only the sign differs, then surely these types are compatible. (We do still check that `arg_ext` is the same, just in case.)

Also I made it so that the ABI check must *imply* that size and alignment are the same, but it doesn't actively check that itself. With how crazy ABI constraints get, having equal size and align really shouldn't be used as a signal for anything I think...
2023-08-28 22:56:10 +00:00
Matthias Krüger
88b476c388
Rollup merge of #115164 - RalfJung:no-in-place-packed, r=b-naber
MIR validation: reject in-place argument/return for packed fields

As discussed [here](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Packed.20fields.20and.20in-place.20function.20argument.2Freturn.20passing).
2023-08-28 19:53:54 +02:00
Ralf Jung
beeb2b13cc miri/diagnostics: don't forget to print_backtrace when ICEing on unexpected errors
then also use the new helper in a few other places
2023-08-27 15:42:25 +02:00
bors
296c7a683c Auto merge of #115184 - saethlin:local-allocated-spans, r=RalfJung
Record allocation spans inside force_allocation

This expands https://github.com/rust-lang/miri/pull/2940 to cover locals

r? `@RalfJung`
2023-08-25 17:03:33 +00:00
Ben Kimock
8ecdefb3db
Add a doc comment for the new hook
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-25 11:58:31 -04:00
Ben Kimock
ec21d584ee Record allocation spans inside force_allocation 2023-08-25 11:16:52 -04:00
bors
25ed43ddf3 Auto merge of #115138 - cjgillot:dse-move-packed, r=compiler-errors
Do not convert copies of packed projections to moves.

This code path was introduced in https://github.com/rust-lang/rust/pull/113758

After seeing https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Packed.20fields.20and.20in-place.20function.20argument.2Freturn.20passing, this may be UB, so should be disallowed.

This should not appear in normally-built MIR, which introduces temporary copies for packed projections.
2023-08-25 13:27:21 +00:00
Ralf Jung
5194060ded miri ABI compatibility check: accept u32 and i32 2023-08-24 21:02:21 +02:00
Camille GILLOT
15a68610dd Only check packed ADT. 2023-08-24 15:42:55 +00:00
Ralf Jung
4c53783f3c when terminating during unwinding, show the reason why 2023-08-24 13:28:26 +02:00
Ralf Jung
739144fc5b MIR validation: reject in-place argument/return for packed fields 2023-08-24 11:38:19 +02:00
Ralf Jung
807e5b8022 avoid return in tail position
Co-authored-by: fee1-dead <ent3rm4n@gmail.com>
2023-08-20 15:52:40 +02:00
Ralf Jung
ac3bca24b7 interpret: have assert_* intrinsics call the panic machinery instead of a direct abort 2023-08-20 15:52:40 +02:00
Ralf Jung
788fd44a3b interpret/miri: call panic_cannot_unwind lang item instead of hard-coding the same message 2023-08-20 15:52:40 +02:00
Ralf Jung
818ec8e23a give some unwind-related terminators a more clear name 2023-08-20 15:52:38 +02:00
bors
ff55fa3026 Auto merge of #113124 - nbdd0121:eh_frame, r=cjgillot
Add MIR validation for unwind out from nounwind functions + fixes to make validation pass

`@Nilstrieb`  This is the MIR validation you asked in https://github.com/rust-lang/rust/pull/112403#discussion_r1222739722.

Two passes need to be fixed to get the validation to pass:
* `RemoveNoopLandingPads` currently unconditionally introduce a resume block (even there is none to begin with!), changed to not do that
* Generator state transform introduces a `assert` which may unwind, and its drop elaboration also introduces many new `UnwindAction`s, so in this case run the AbortUnwindingCalls after the transformation.

I believe this PR should also fix Rust-for-Linux/linux#1016, cc `@ojeda`

r? `@Nilstrieb`
2023-08-20 09:58:52 +00:00
Ralf Jung
410bd45ff2 const-eval: ensure we never const-execute a function marked rustc_do_not_const_check 2023-08-19 14:33:31 +02:00
Gary Guo
eb4d6d9ff7 Add missing instantiation of generator ty in validator 2023-08-18 16:40:10 +01:00
Gary Guo
56b933763e Add MIR validation for unwind out from nounwind functions 2023-08-18 13:51:42 +01:00
Camille GILLOT
933b618360 Revert "Implement references VarDebugInfo."
This reverts commit 2ec0071913.
2023-08-17 17:02:04 +00:00
Camille GILLOT
388f6a6413 Make TerminatorEdge plural. 2023-08-16 18:12:18 +00:00
Camille GILLOT
5173d85043 Allow apply_terminator_effect to customize edges. 2023-08-16 18:12:17 +00:00
Deadbeef
f441fa08da Remove constness from ImplSource::Param 2023-08-14 02:17:30 +00:00
bors
e3590fccfb Auto merge of #114637 - matthiaskrgr:rollup-544y8p5, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #106425 (Make ExitStatus implement Default)
 - #113480 (add aarch64-unknown-teeos target)
 - #113586 (Mention style for new syntax in tracking issue template)
 - #113593 (CFI: Fix error compiling core with LLVM CFI enabled)
 - #114612 (update llvm-wrapper include to silence deprecation warning)
 - #114613 (Prevent constant rebuilds of `rustc-main` (and thus everything else))
 - #114615 (interpret: remove incomplete protection against invalid where clauses)
 - #114628 (Allowing re-implementation of mir_drops_elaborated query)
 - #114629 (tests: Uncomment now valid GAT code behind FIXME)
 - #114630 (Migrate GUI colors test to original CSS color format)
 - #114631 (add provisional cache test for new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-08 22:00:40 +00:00
Matthias Krüger
5c5ae6c5f3
Rollup merge of #114615 - RalfJung:interpret-invalid-where, r=lcnr
interpret: remove incomplete protection against invalid where clauses

Cc https://github.com/rust-lang/rust/issues/97477, https://github.com/rust-lang/project-const-generics/issues/37

r? ``@lcnr``
2023-08-08 21:44:45 +02:00
bors
f88a8b71ce Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obk
correctly lower `impl const` to bind to host effect param

r? `@oli-obk`
2023-08-08 19:23:41 +00:00
Ralf Jung
a7132bf387 interpret: remove incomplete protection against invalid where clauses 2023-08-08 10:35:22 +02:00
bors
6d55184d05 Auto merge of #114520 - RalfJung:unsized-valtrees, r=oli-obk
simplify handling of valtrees for unsized types
2023-08-08 07:48:01 +00:00
Matthias Krüger
cbe2522652
Rollup merge of #114382 - scottmcm:compare-bytes-intrinsic, r=cjgillot
Add a new `compare_bytes` intrinsic instead of calling `memcmp` directly

As discussed in #113435, this lets the backends be the place that can have the "don't call the function if n == 0" logic, if it's needed for the target.  (I didn't actually *add* those checks, though, since as I understood it we didn't actually need them on known targets?)

Doing this also let me make it `const` (unstable), which I don't think `extern "C" fn memcmp` can be.

cc `@RalfJung` `@Amanieu`
2023-08-07 05:29:12 +02:00
Scott McMurray
502af03445 Add a new compare_bytes intrinsic instead of calling memcmp directly 2023-08-06 15:47:40 -07:00
Matthias Krüger
74dce18639
Rollup merge of #114542 - RalfJung:const-prop-nonsense, r=compiler-errors
interpret: use ConstPropNonsense for more const-prop induced issues
2023-08-07 00:06:06 +02:00
Ralf Jung
997ec63fb1 simplify handling of valtrees for unsized types 2023-08-06 21:25:49 +02:00
Ralf Jung
b6e3bc23ef remove an unnecessary special case in valtree_into_mplace 2023-08-06 21:25:49 +02:00
Matthias Krüger
13de583583
Rollup merge of #114505 - ouz-a:cleanup_mir, r=RalfJung
Add documentation to has_deref

Documentation of `has_deref` needed some polish to be more clear about where it should be used and what's it's purpose.

cc https://github.com/rust-lang/rust/issues/114401

r? `@RalfJung`
2023-08-06 17:26:29 +02:00
ouz-a
6df546281b cleanup misinformation regarding has_deref 2023-08-06 17:29:09 +03:00
Deadbeef
92f4c59e48 lower impl const to bind to host effect param 2023-08-06 13:34:53 +00:00
Ralf Jung
efd54ccf5a interpret: use ConstPropNonsense for more const-prop induced issues 2023-08-06 15:20:03 +02:00
Ralf Jung
3345077b42 interpret: add mplace_to_ref helper method 2023-08-04 15:00:57 +02:00
Matthias Krüger
00dcc7b97c
Rollup merge of #114372 - RalfJung:const-pointer-as-int, r=oli-obk
const validation: point at where we found a pointer but expected an integer

Instead of validation just printing "unable to turn pointer into bytes", make this a regular validation error that says where in the value the bad pointer was found. Also distinguish "expected integer, got pointer" from "expected pointer, got partial pointer or mix of pointers".

To avoid duplicating things too much I refactored the diagnostics for validity a bit, so that "got uninit, expected X" and "got pointer, expected X" can share the "X" part. Also all the errors emitted for validation are now grouped under `const_eval_validation` so that they are in a single group in the ftl file.

r? `@oli-obk`
2023-08-03 17:29:08 +02:00
Matthias Krüger
01fdb9d148
Rollup merge of #114363 - RalfJung:interpret-not-miri, r=jackh726
avoid 'miri' when refering to the shared interpreter

This is basically the rustc source code version of https://github.com/rust-lang/rustc-dev-guide/pull/1471.
2023-08-03 08:12:39 +02:00
Ralf Jung
7767cbb3b0 const validation: point at where we found a pointer but expected an integer 2023-08-02 18:51:50 +02:00
Deadbeef
4fec845c3f Remove constness from TraitPredicate 2023-08-02 15:38:00 +00:00
Ralf Jung
2984670cea avoid 'miri' when refering to the shared interpreter 2023-08-02 16:52:03 +02:00
Nilstrieb
46f6b05eb7
Rollup merge of #114079 - compiler-errors:closure-upvars, r=oli-obk
Use `upvar_tys` in more places, make it return a list

Just a cleanup that fell out of a PR that I was gonna write, but that PR kinda got stuck.
2023-08-02 13:46:54 +02:00
bors
64ad036307 Auto merge of #114333 - RalfJung:dangling-ptr-offset, r=oli-obk
Miri: fix error on dangling pointer inbounds offset

We used to claim that the pointer was "dereferenced", but that is just not true.

Can be reviewed commit-by-commit. The first commit is an unrelated rename that didn't seem worth splitting into its own PR.

r? `@oli-obk`
2023-08-02 09:12:32 +00:00
Michael Goulet
99969d282b Use upvar_tys in more places, make it a list 2023-08-01 23:19:31 +00:00
Ralf Jung
8496292dda properly track why we checked whether a pointer is in-bounds
also simplify the in-bounds checking in Miri's borrow trackers
2023-08-01 17:57:13 +02:00
Ralf Jung
7d5886504c rename deref_operand → deref_pointer and some Miri helper functions 2023-08-01 13:40:29 +02:00
Ralf Jung
b169ee7c1a fix alignment handling for Repeat expressions 2023-07-31 19:22:14 +02:00
Matthias Krüger
5dee519386
Rollup merge of #113773 - compiler-errors:err-layout-bail, r=cjgillot
Don't attempt to compute layout of type referencing error

Leads to more ICEs and strange diagnostics than are worth it.

Fixes #113760
2023-07-29 06:13:05 +02:00
bors
aafd75a9c5 Auto merge of #114134 - fee1-dead-contrib:rm-constness-from-param-env, r=oli-obk
Remove `constness` from `ParamEnv`

This should be replaced by keyword generics/effects. cc #110395

r? `@oli-obk`
2023-07-28 08:53:12 +00:00
Michael Goulet
d45eb41c50 Dont report CTFE errors that are due to references-error layouts 2023-07-27 18:51:44 +00:00
Deadbeef
b0fa2201d3 bless clippy 2023-07-27 17:56:25 +00:00
Deadbeef
e6b423aebb Remove constness from ParamEnv 2023-07-27 15:50:42 +00:00
Guillaume Gomez
218e88e5d8
Rollup merge of #114123 - oli-obk:tait_wtf, r=WaffleLapkin
Turns out opaque types can have hidden types registered during mir validation

See the newly added test's documentation for an explanation.

fixes #114121
2023-07-27 16:05:15 +02:00
Oli Scherer
99a9a63ca6 Turns out opaque types can have hidden types registered during mir validation 2023-07-27 08:23:06 +00:00
Matthias Krüger
fa21a8c6f8
Rollup merge of #114075 - matthiaskrgr:fmt_args_rustc_3, r=wesleywiser
inline format!() args from rustc_codegen_llvm to the end (4)

r? `@WaffleLapkin`
2023-07-27 06:04:13 +02:00
bors
0d95f91329 Auto merge of #113843 - wesleywiser:replace_rustc_apfloat, r=pnkfelix
Replace in-tree `rustc_apfloat` with the new version of the crate

Replace the in-tree version of `rustc_apfloat` with the new version of the crate which has been correctly licensed. The new crate incorporates upstream changes from LLVM since the original port was done including many correctness fixes and has been extensively fuzz tested to validate correctness.

Fixes #100233
Fixes #102403
Fixes #113407
Fixes #113409
Fixes #55993
Fixes #93224
Closes #93225
Closes #109573
2023-07-26 21:21:19 +00:00
Wesley Wiser
15e9f56088 Replace in-tree rustc_apfloat with the new version of the crate 2023-07-26 10:20:15 -04:00
bors
bd9785cce8 Auto merge of #114071 - RalfJung:interpret-generic-read-write, r=oli-obk
interpret: make read/write methods generic

Instead of always having to call `into()` to convert things to `PlaceTy`/`OpTy`, make the relevant methods generic. This also means that when we read from an `MPlaceTy`, we avoid creating an intermediate `PlaceTy`.

This makes it feasible to remove the `Copy` from `MPlaceTy`. All the other `*Ty` interpreter types already had their `Copy` removed a while ago so this is only consistent. (And in fact we had one function that accidentally took `MPlaceTy` instead of `&MPlaceTy`.)
2023-07-26 13:06:25 +00:00
Ralf Jung
571e8ce777 valtree: a bit of cleanup 2023-07-26 11:45:35 +02:00
Matthias Krüger
0b13deb548
Rollup merge of #113661 - oli-obk:tait_wtf, r=lcnr
Double check that hidden types match the expected hidden type

Fixes https://github.com/rust-lang/rust/issues/113278 specifically, but I left a TODO for where we should also add some hardening.

It feels a bit like papering over the issue, but at least this way we don't get unsoundness, but just surprising errors. Errors will be improved and given spans before this PR lands.

r? `@compiler-errors` `@lcnr`
2023-07-25 23:34:07 +02:00
Matthias Krüger
c64ef5e070 inline format!() args from rustc_codegen_llvm to the end (4)
r? @WaffleLapkin
2023-07-25 23:20:28 +02:00
Ralf Jung
da3f0d0eb7 make MPlaceTy non-Copy 2023-07-25 22:35:07 +02:00
Ralf Jung
77ff1b83cd interpret: make read functions generic over operand type 2023-07-25 22:33:59 +02:00
Ralf Jung
00fb45dccd interpret: make write functions generic over the place type 2023-07-25 22:33:58 +02:00
bors
8327047b23 Auto merge of #113393 - compiler-errors:next-solver-unsize-rhs, r=lcnr
Normalize the RHS of an `Unsize` goal in the new solver

`Unsize` goals are... tricky. Not only do they structurally match on their self type, but they're also structural on their other type parameter. I'm pretty certain that it is both incomplete and also just plain undesirable to not consider normalizing the RHS of an unsize goal. More practically, I'd like for this code to work:

```rust
trait A {}
trait B: A {}

impl A for usize {}
impl B for usize {}

trait Mirror {
    type Assoc: ?Sized;
}

impl<T: ?Sized> Mirror for T {
    type Assoc = T;
}

fn main() {
    // usize: Unsize<dyn B>
    let x = Box::new(1usize) as Box<<dyn B as Mirror>::Assoc>;
    // dyn A: Unsize<dyn B>
    let y = x as Box<<dyn A as Mirror>::Assoc>;
}
```

---

In order to achieve this, we add `EvalCtxt::normalize_non_self_ty` (naming modulo bikeshedding), which *must* be used for all non-self type arguments that are structurally matched in candidate assembly. Currently this is only necessary for `Unsize`'s argument, but I could see future traits requiring this (hopefully rarely) in the future. It uses `repeat_while_none` to limit infinite looping, and normalizes the self type until it is no longer an alias.

Also, we need to fix feature gate detection for `trait_upcasting` and `unsized_tuple_coercion` when HIR typeck has unnormalized types. We can do that by checking the `ImplSource` returned by selection, which necessitates adding a new impl source for tuple upcasting.
2023-07-25 17:10:31 +00:00
Michael Goulet
a7ed9c1da7 Make everything builtin! 2023-07-25 16:08:58 +00:00
bors
4fc6b33474 Auto merge of #114011 - RalfJung:place-projection, r=oli-obk
interpret: Unify projections for MPlaceTy, PlaceTy, OpTy

For ~forever, we didn't really have proper shared code for handling projections into those three types. This is mostly because `PlaceTy` projections require `&mut self`: they might have to `force_allocate` to be able to represent a project part-way into a local.

This PR finally fixes that, by enhancing `Place::Local` with an `offset` so that such an optimized place can point into a part of a place without having requiring an in-memory representation. If we later write to that place, we will still do `force_allocate` -- for now we don't have an optimized path in `write_immediate` that would avoid allocation for partial overwrites of immediately stored locals. But in `write_immediate` we have `&mut self` so at least this no longer pollutes all our type signatures.

(Ironically, I seem to distantly remember that many years ago, `Place::Local` *did* have an `offset`, and I removed it to simplify things. I guess I didn't realize why it was so useful... I am also not sure if this was actually used to achieve place projection on `&self` back then.)

The `offset` had type `Option<Size>`, where `None` represent "no projection was applied". This is needed because locals *can* be unsized (when they are arguments) but `Place::Local` cannot store metadata: if the offset is `None`, this refers to the entire local, so we can use the metadata of the local itself (which must be indirect); if a projection gets applied, since the local is indirect, it will turn into a `Place::Ptr`. (Note that even for indirect locals we can have `Place::Local`: when the local appears in MIR, we always start with `Place::Local`, and only check `frame.locals` later. We could eagerly normalize to `Place::Ptr` but I don't think that would actually simplify things much.)

Having done all that, we can finally properly abstract projections: we have a new `Projectable` trait that has the basic methods required for projecting, and then all projection methods are implemented for anything that implements that trait. We can even implement it for `ImmTy`! (Not that we need that, but it seems neat.) The visitor can be greatly simplified; it doesn't need its own trait any more but it can use the `Projectable` trait. We also don't need the separate `Mut` visitor any more; that was required only to reflect that projections on `PlaceTy` needed `&mut self`.

It is possible that there are some more `&mut self` that can now become `&self`... I guess we'll notice that over time.

r? `@oli-obk`
2023-07-25 14:18:08 +00:00
Ralf Jung
d127600511 add some sanity checks in write_immediate_no_validate 2023-07-25 14:30:58 +02:00
Ralf Jung
14a674c88c interpret: read_discriminant: only return VariantIdx 2023-07-25 14:30:58 +02:00
Ralf Jung
a2bcafa500 interpret: refactor projection code to work on a common trait, and use that for visitors 2023-07-25 14:30:58 +02:00
Ralf Jung
a593de4fab interpret: support projecting into Place::Local without force_allocation 2023-07-24 15:35:47 +02:00
bors
c39995485f Auto merge of #113853 - cjgillot:split-validator, r=compiler-errors
Reuse the MIR validator for MIR inlining

Instead of having the inliner home-cook its own validation, we just check that the substituted MIR body passes the regular validation.

The MIR validation is first split in two: control flow validation (MIR syntax and CFG invariants) and type validation (subtyping relationship in assignments and projections). Only the latter can be affected by instantiating type parameters.
2023-07-22 16:59:23 +00:00
David Tolnay
5bbf0a8306
Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"
This reverts commit 557359f925, reversing
changes made to 1e6c09a803.
2023-07-21 22:35:57 -07:00
bors
d908a5b08e Auto merge of #113892 - RalfJung:uninit-undef-poison, r=wesleywiser
clarify MIR uninit vs LLVM undef/poison

In [this LLVM discussion](https://discourse.llvm.org/t/rfc-load-instruction-uninitialized-memory-semantics/67481) I learned that mapping our uninitialized memory in MIR to poison in LLVM would be quite problematic due to the lack of a byte type. I am not sure where to write down this insight but this seems like a reasonable start.
2023-07-21 19:32:17 +00:00
Camille GILLOT
b6cd7006e0 Reuse MIR validator for inliner. 2023-07-21 13:58:33 +00:00
Camille GILLOT
2ef2ac0b51 Make type validation buffer errors. 2023-07-21 13:54:34 +00:00
Camille GILLOT
030589d488 Separate CFG validation from type validation. 2023-07-21 13:54:34 +00:00
Oli Scherer
44e21503a8 Double check that hidden types match the expected hidden type 2023-07-21 13:19:36 +00:00
Moulins
39cfe70e4f CTFE: move target_{i, u}size_{min, max) to rustc_abi::TargetDataLayout 2023-07-21 03:31:47 +02:00
Moulins
76c49aead6 support non-null pointer niches in CTFE 2023-07-21 03:31:45 +02:00
Ralf Jung
41a73d8251 clarify MIR uninit vs LLVM undef/poison 2023-07-20 18:43:54 +02:00
Eduardo Sánchez Muñoz
ae2a72deaa Refactor checking function target features during const-eval
* Split into its own function
* Do not build a `Vec` of unavailable features
2023-07-16 16:07:55 +02:00
Eduardo Sánchez Muñoz
b5fde0dae0 miri: fail when calling a function that requires an unavailable target feature
miri will report an UB when calling a function that has a `#[target_feature(enable = ...)]` attribute is called and the required feature is not available.

"Available features" are the same that `is_x86_feature_detected!` (or equivalent) reports to be available during miri execution (which can be enabled or disabled with the `-C target-feature` flag).
2023-07-16 00:23:17 +02:00
Mahdi Dibaiee
e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Mark Rousskov
cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
Ralf Jung
e7c6db7d44 fix handling of alignment for dyn-sized places 2023-07-11 21:59:01 +02:00
Ralf Jung
dd453a6a99 miri: protect Move() function arguments during the call 2023-07-11 21:59:01 +02:00
bors
9bb6fbe261 Auto merge of #113376 - Nilstrieb:pointer-coercions-are-not-casts-because-that-sounds-way-to-general-aaaa, r=oli-obk
Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`

It makes it sounds like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a little enum variants. Make it clear there these are only coercions and that people who see this and think "why are so many pointer related casts not in these variants" aren't insane.

This enum was added in #59987. I'm not sure whether the variant sharing is actually worth it, but this at least makes it less confusing.

r? oli-obk
2023-07-08 13:48:30 +00:00
Nilstrieb
2beabbbf6f Rename adjustment::PointerCast and variants using it to PointerCoercion
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related
casts, when in reality their just used to share a some enum variants. Make it clear there these
are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-07 18:17:16 +02:00
Ralf Jung
7a83ef82da miri: check that assignments do not self-overlap 2023-07-07 16:54:44 +02:00
bors
1a449dcfd2 Auto merge of #113308 - compiler-errors:poly-select, r=lcnr
Split `SelectionContext::select` into fns that take a binder and don't

*most* usages of `SelectionContext::select` don't need to use a binder, but wrap them in a dummy because of the signature. Let's split this out into `SelectionContext::{select,poly_select}` and limit the usages of the latter.

Right now, we only have 3 places where we're calling `poly_select` -- fulfillment, internally within the old solver, and the auto-trait finder.

r? `@lcnr`
2023-07-07 10:32:42 +00:00
Michael Goulet
3aa4561923
Rollup merge of #111917 - WaffleLapkin:validate_unalloc, r=oli-obk
Simplify duplicate checks for mir validator

This removes unnecessary allocations & is less code.
2023-07-06 20:11:38 -07:00
Michael Goulet
52f7384995 Separate select calls that don't need a binder 2023-07-06 16:50:12 +00:00
bors
4dd1719b34 Auto merge of #113377 - BoxyUwU:move_ty_ctors_to_ty, r=compiler-errors
Move `TyCtxt::mk_x` to `Ty::new_x` where applicable

Part of rust-lang/compiler-team#616

turns out there's a lot of places we construct `Ty` this is a ridiculously huge PR :S

r? `@oli-obk`
2023-07-06 08:10:42 +00:00
Boxy
12138b8e5e Move TyCtxt::mk_x to Ty::new_x where applicable 2023-07-05 20:27:07 +01:00
Oli Scherer
8ac1a67d11 Name the destructure_mir_constant query appropriately 2023-07-05 15:54:43 +00:00
Oli Scherer
46cce98134 Use options instead of errors if the errors are never needed 2023-07-05 15:54:43 +00:00
Oli Scherer
09b89efa70 Remove a function argument that is always passed with the same value. 2023-07-05 15:54:43 +00:00
Oli Scherer
a0eb348d38 Specialize DestructuredConstant to its one user (pretty printing) 2023-07-05 15:54:43 +00:00
Oli Scherer
4dcf988360 Specialize try_destructure_mir_constant for its sole user 2023-07-05 15:54:43 +00:00
bors
72b2101434 Auto merge of #112718 - oli-obk:SIMD-destructure_mir_const, r=cjgillot
Make simd_shuffle_indices use valtrees

This removes the second-to-last user of the `destructure_mir_constant` query. So in a follow-up we can remove the query and just move the query provider function directly into pretty printing (which is the last user).

cc `@rust-lang/clippy` there's a small functional change, but I think it is correct?
2023-07-02 07:43:36 +00: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
James Dietz
71362c733f remove FIXME and add test 2023-06-28 07:59:36 -04:00
James Dietz
ce5ed5b6cc add check for ConstKind::Value(_) 2023-06-28 07:49:50 -04:00
bors
b9ad9b78a2 Auto merge of #112693 - ericmarkmartin:use-more-placeref, r=spastorino
Use PlaceRef abstractions more often

Associated issue: https://github.com/rust-lang/rust/issues/80647

r? `@spastorino`
2023-06-27 00:34:49 +00:00
Oli Scherer
168de14ac9 Make simd_shuffle_indices use valtrees 2023-06-26 09:34:52 +00:00
Eric Mark Martin
c07c10d1e4 use PlaceRef abstractions more consistently 2023-06-25 20:38:01 -04:00
Nilstrieb
70b6a74c3c Add enum for can_access_statics boolean
`/*can_access_statics:*/ false` is one of the ways to do this, but not
the one I like.
2023-06-24 20:40:40 +00:00
Ziru Niu
a52cc0a8c9 address most easy comments 2023-06-20 20:55:31 +08:00
Ziru Niu
8fb4c41f35 merge BorrowKind::Unique into BorrowKind::Mut 2023-06-20 20:55:31 +08:00
Michael Goulet
31d1fbf8d2
Rollup merge of #112232 - fee1-dead-contrib:match-eq-const-msg, r=b-naber
Better error for non const `PartialEq` call generated by `match`

Resolves #90237
2023-06-19 17:53:33 -07:00
Scott McMurray
c780e55995 Dedup some type checks in the MIR validator 2023-06-19 01:47:03 -07:00
Scott McMurray
3fd8501823 Remove unchecked_add/sub/mul/shl/shr from CTFE/cg_ssa/cg_clif 2023-06-19 01:47:03 -07:00
Scott McMurray
39788e07ba Promote unchecked_add/sub/mul/shl/shr to mir::BinOp 2023-06-19 01:47:03 -07:00
bors
677710eaf0 Auto merge of #112638 - lqd:rpo, r=cjgillot
Switch the BB CFG cache from postorder to RPO

The `BasicBlocks` CFG cache is interesting:
- it stores a postorder, but `traversal::postorder` doesn't use it
- `traversal::reverse_postorder` does traverse the postorder cache backwards
- we do more RPO traversals than postorder traversals (around 20x on the perf.rlo benchmarks IIRC) but it's not cached
- a couple places here and there were manually reversing the non-cached postorder traversal

This PR switches the order of the cache, and makes a bit more use of it. This is a tiny win locally, but it's also for consistency and aesthetics.

r? `@ghost`
2023-06-18 12:45:41 +00:00
Deadbeef
89c24af133 Better error for non const PartialEq call generated by match 2023-06-18 05:24:38 +00:00
Michael Goulet
d97d4ebecc Remove even more redundant builtin candidates 2023-06-17 03:32:46 +00:00
Michael Goulet
2835d9d1d3 Simplify even more candidates 2023-06-17 03:32:46 +00:00
Michael Goulet
9e68b6f505 Simplify some impl source candidates 2023-06-17 03:32:45 +00:00
Oli Scherer
f3b7dd6388 Add AliasKind::Weak for type aliases.
Only use it when the type alias contains an opaque type.

Also does wf-checking on such type aliases.
2023-06-16 19:39:48 +00:00
Rémy Rakic
e596579066 inline explicit rpo access in promote consts 2023-06-14 20:08:04 +00:00
bors
68c8fdaac0 Auto merge of #108293 - Jarcho:mut_analyses, r=eholk
Take MIR dataflow analyses by mutable reference

The main motivation here is any analysis requiring dynamically sized scratch memory to work. One concrete example would be pointer target tracking, where tracking the results of a dereference can result in multiple possible targets. This leads to processing multi-level dereferences requiring the ability to handle a changing number of potential targets per step. A (simplified) function for this would be `fn apply_deref(potential_targets: &mut Vec<Target>)` which would use the scratch space contained in the analysis to send arguments and receive the results.

The alternative to this would be to wrap everything in a `RefCell`, which is what `MaybeRequiresStorage` currently does. This comes with a small perf cost and loses the compiler's guarantee that we don't try to take multiple borrows at the same time.

For the implementation:
* `AnalysisResults` is an unfortunate requirement to avoid an unconstrained type parameter error.
* `CloneAnalysis` could just be `Clone` instead, but that would result in more work than is required to have multiple cursors over the same result set.
* `ResultsVisitor` now takes the results type on in each function as there's no other way to have access to the analysis without cloning it. This could use an associated type rather than a type parameter, but the current approach makes it easier to not care about the type when it's not necessary.
* `MaybeRequiresStorage` now no longer uses a `RefCell`, but the graphviz formatter now does. It could be removed, but that would require even more changes and doesn't really seem necessary.
2023-06-08 23:58:44 +00:00
Thom Chiovoloni
9e5573a0d2
Use 128 bits for TypeId hash
- Switch TypeId to 128 bits
- Hack around the fact that tracing-subscriber dislikes how TypeId is hashed
- Remove lowering of type_id128 from rustc_codegen_llvm
- Remove unnecessary `type_id128` intrinsic (just change return type of `type_id`)
- Only hash the lower 64 bits of the TypeId
- Reword comment
2023-06-04 08:34:48 -07:00
Michael Goulet
5460f92a0f
Rollup merge of #112168 - scottmcm:lower-div-rem-unchecked-to-mir, r=oli-obk
Lower `unchecked_div`/`_rem` to MIR's `BinOp::Div`/`Rem`

As described in <https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.BinOp.html#variant.Div>, the ordinary `BinOp`s for these are already UB for division by zero ([or overflow](https://llvm.org/docs/LangRef.html#sdiv-instruction), [demo](https://rust.godbolt.org/z/71e7P7Exh)), as MIR building is responsible for inserting code to panic for those cases regardless of whether the overflow checks are enabled.

So we can lower these in the same arm that lowers `wrapping_add` to MIR `BinOp::Add` and such, as all these cases turn into ordinary `Rvalue::BinaryOp`s.
2023-06-02 16:02:06 -07:00
Deadbeef
f6c2bc5c24 fix diagnostic message 2023-06-01 14:45:19 +00:00
Deadbeef
f964b46451 improve debug message by eagerly translating 2023-06-01 14:45:19 +00:00
Deadbeef
4f83717cf7 Use translatable diagnostics in rustc_const_eval 2023-06-01 14:45:18 +00:00
Scott McMurray
73f104b6d6 remove unchecked_div/_rem from ctfe 2023-06-01 00:05:55 -07:00
bors
23f93a1266 Auto merge of #103877 - oli-obk:const_eval_step_limit, r=fee1-dead
Replace const eval limit by a lint and add an exponential backoff warning

The lint triggers at the first power of 2 that comes after 1 million function calls or traversed back-edges (takes less than a second on usual programs). After the first emission, an unsilenceable warning is repeated at every following power of 2 terminators, causing it to get reported less and less the longer the evaluation runs.

cc `@rust-lang/wg-const-eval`

fixes #93481
closes #67217
2023-06-01 05:32:00 +00:00
bors
871b595202 Auto merge of #111913 - oli-obk:valtrees2, r=lcnr
Only rewrite valtree-constants to patterns and keep other constants opaque

Now that we can reliably fall back to comparing constants with `PartialEq::eq` to the match scrutinee, we can

1. eagerly try to convert constants to valtrees
2. then deeply convert the valtree to a pattern
3. if the to-valtree conversion failed, create an "opaque constant" pattern.

This PR specifically avoids any behavioral changes or major cleanups. What we can now do as follow ups is

* move the two remaining call sites to `destructure_mir_constant` off that query
* make valtree to pattern conversion infallible
    * this needs to be done after careful analysis of the effects. There may be user visible changes from that.

based on https://github.com/rust-lang/rust/pull/111768
2023-05-31 16:36:51 +00:00