Commit Graph

544 Commits

Author SHA1 Message Date
Oli Scherer
84a444a1f4 Introduce opaque type to hidden type projection 2022-07-15 15:49:22 +00:00
bors
6077b7cda4 Auto merge of #99013 - RalfJung:dont-poison-my-places, r=oli-obk
interpret: get rid of MemPlaceMeta::Poison

This is achieved by refactoring the projection code (`{mplace,place,operand}_{downcast,field,index,...}`) so that we no longer need to call `assert_mem_place` in the operand handling.
2022-07-15 08:57:59 +00:00
Ralf Jung
e3ef4fdac9 rename MPlaceTy::dangling to fake_alloc_zst 2022-07-14 11:40:47 -04:00
Daniel Bevenius
ed73037661 Remove comment referring to constness.rs
This commit removes the comment in emulate_intrinsic, which is
currently referring to 'src/librustc_middle/ty/constness.rs'.
2022-07-14 16:30:48 +02:00
Joshua Nelson
3c9765cff1 Rename debugging_opts to unstable_opts
This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`).
Rename it to be more clear.
2022-07-13 17:47:06 -05:00
bors
c80dde43f9 Auto merge of #99210 - Dylan-DPC:rollup-879cp1t, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #98574 (Lower let-else in MIR)
 - #99011 (`UnsafeCell` blocks niches inside its nested type from being available outside)
 - #99030 (diagnostics: error messages when struct literals fail to parse)
 - #99155 (Keep unstable target features for asm feature checking)
 - #99199 (Refactor: remove an unnecessary `span_to_snippet`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-13 17:13:27 +00:00
bors
42bd138126 Auto merge of #98145 - ouz-a:some_branch, r=oli-obk
Pull Derefer before ElaborateDrops

_Follow up work to #97025 #96549 #96116 #95887 #95649_

This moves `Derefer` before `ElaborateDrops` and creates a new `Rvalue` called `VirtualRef` that allows us to bypass many constraints for `DerefTemp`.

r? `@oli-obk`
2022-07-13 14:32:33 +00:00
Ralf Jung
874a130ca0 get rid of MemPlaceMeta::Poison
MPlaceTy::dangling still exists, but now it is only called in places that
actually conceptually allocate something new, so that's fine.
2022-07-13 10:22:59 -04:00
Dylan DPC
1e7d04b23b
Rollup merge of #99011 - oli-obk:UnsoundCell, r=eddyb
`UnsafeCell` blocks niches inside its nested type from being available outside

fixes #87341

This implements the plan by `@eddyb` in https://github.com/rust-lang/rust/issues/87341#issuecomment-886083646

Somewhat related PR (not strictly necessary, but that cleanup made this PR simpler): #94527
2022-07-13 19:32:34 +05:30
bors
7b5715289f Auto merge of #99101 - RalfJung:interpret-projections, r=oli-obk
interpret: refactor projection handling code

Moves our projection handling code into a common file, and avoids the use of a
general mplace-based fallback function by have more specialized implementations.

mplace_index (and the other slice-related functions) could be more efficient by
copy-pasting the body of operand_index. Or we could do some trait magic to share
the code between them. But for now this is probably fine.

This is the common part of https://github.com/rust-lang/rust/pull/99013 and https://github.com/rust-lang/rust/pull/99097. I am seeing some strange perf results so this probably should be its own change so we know which diff caused which perf changes...

r? `@oli-obk`
2022-07-13 02:43:25 +00:00
ouz-a
cb0017f2f8 add new rval, pull deref early 2022-07-12 14:26:41 +03:00
Ralf Jung
04b3cd9f7c use a loop rather than try_fold 2022-07-11 22:51:33 -04:00
Ralf Jung
ab225ade1e interpret: refactor projection handling code
Moves our projection handling code into a common file, and avoids the use of a
general mplace-based fallback function by have more specialized implementations.

mplace_index (and the other slice-related functions) could be more efficient by
copy-pasting the body of operand_index. Or we could do some trait magic to share
the code between them. But for now this is probably fine.
2022-07-11 22:50:46 -04:00
Dylan DPC
9fc297a2ae
Rollup merge of #99140 - TaKO8Ki:implement-is-accessible-span, r=fee1-dead
Implement `SourceMap::is_span_accessible`

This patch adds `SourceMap::is_span_accessible` and replaces `span_to_snippet(span).is_ok()` and `span_to_snippet(span).is_err()` with it. This removes a `&str` to `String` conversion.
2022-07-11 15:19:32 +05:30
Takayuki Maeda
018155c3a2 rename a method 2022-07-11 16:51:19 +09:00
Takayuki Maeda
12d11e9a35 implement is_accessible_span 2022-07-11 11:36:15 +09:00
Michael Goulet
a1634642e0 Deny floats even when adt_const_params is enabled 2022-07-11 00:04:00 +00:00
bors
f893495e3d Auto merge of #98957 - RalfJung:zst-are-different, r=lcnr,oli-obk
don't allow ZST in ScalarInt

There are several indications that we should not ZST as a ScalarInt:
- We had two ways to have ZST valtrees, either an empty `Branch` or a `Leaf` with a ZST in it.
  `ValTree::zst()` used the former, but the latter could possibly arise as well.
- Likewise, the interpreter had `Immediate::Uninit` and `Immediate::Scalar(Scalar::ZST)`.
- LLVM codegen already had to special-case ZST ScalarInt.

So I propose we stop using ScalarInt to represent ZST (which are clearly not integers). Instead, we can add new ZST variants to those types that did not have other variants which could be used for this purpose.

Based on https://github.com/rust-lang/rust/pull/98831. Only the commits starting from "don't allow ZST in ScalarInt" are new.

r? `@oli-obk`
2022-07-09 17:16:00 +00:00
Ralf Jung
4e7aaf1f44 tweak names and output and bless 2022-07-09 07:43:56 -04:00
Ralf Jung
ac265cdc19 review feedback 2022-07-09 07:27:29 -04:00
Ralf Jung
a422b42159 don't allow ZST in ScalarInt
There are several indications that we should not ZST as a ScalarInt:
- We had two ways to have ZST valtrees, either an empty `Branch` or a `Leaf` with a ZST in it.
  `ValTree::zst()` used the former, but the latter could possibly arise as well.
- Likewise, the interpreter had `Immediate::Uninit` and `Immediate::Scalar(Scalar::ZST)`.
- LLVM codegen already had to special-case ZST ScalarInt.

So instead add new ZST variants to those types that did not have other variants
which could be used for this purpose.
2022-07-09 07:27:29 -04:00
Matthias Krüger
140250c487
Rollup merge of #99050 - JakobDegen:storage-docs, r=tmiasko
Clarify MIR semantics of storage statements

Seems worthwhile to start closing out some of the less controversial open questions about MIR semantics. Hopefully this is fairly non-controversial - it's what we implement already, and I see no reason to do anything more restrictive. cc ``@tmiasko`` who commented on this when it was discussed in the original PR that added these docs.
2022-07-09 12:52:51 +02:00
Matthias Krüger
416dc43124
Rollup merge of #99022 - pierwill:always-storage-live-locals, r=pierwill
MIR dataflow: Rename function to `always_storage_live_locals`

Related to #99021.

r?  ```@JakobDegen``` (as discussed on Zulip)
2022-07-09 12:52:50 +02:00
Dylan DPC
a6c6166d7b
Rollup merge of #98980 - RalfJung:const-prop-ice, r=oli-obk
fix ICE in ConstProp

Fixes https://github.com/rust-lang/rust/issues/96169
2022-07-09 11:28:05 +05:30
Jakob Degen
4939f6c64b Clarify MIR semantics of storage statements 2022-07-08 16:58:24 -07:00
Ralf Jung
cf9186ec69 interpret: only to track_caller in debug builds due to perf 2022-07-08 07:33:19 -04:00
Michael Goulet
f97f2a47ff Migrate MutDeref, TransientMutBorrow diagnostics 2022-07-08 03:48:10 +00:00
Michael Goulet
584e5d4c4f Migrate PanicNonStr, RawPtrComparison, RawPtrToInt diagnostics 2022-07-08 03:47:59 +00:00
Michael Goulet
c48f482813 Migrate StaticAccess diagnostic 2022-07-08 03:47:46 +00:00
Michael Goulet
1c4afbd1de Migrate NonConstOp diagnostic 2022-07-08 03:47:28 +00:00
Michael Goulet
934079fd9e Migrate unstable-in-stable diagnostic 2022-07-08 03:39:08 +00:00
pierwill
8a1c1ec8b2 MIR dataflow: Rename function to always_storage_live_locals
Related to #99021.
2022-07-07 13:49:40 -05:00
Matthias Krüger
90641470be
Rollup merge of #98979 - RalfJung:more-alloc-range, r=oli-obk
interpret: use AllocRange in UninitByteAccess

also use nice new format string syntax in `interpret/error.rs`, and use the `#` flag to add `0x` prefixes where applicable.

r? ``@oli-obk``
2022-07-07 20:33:26 +02:00
Ralf Jung
1e0f3cb566 make a name less ambiguous 2022-07-07 12:01:36 -04:00
Dylan DPC
71b3fbdb47
Rollup merge of #98930 - tmiasko:pub-basic-blocks, r=oli-obk
Make MIR basic blocks field public

This makes it possible to mutably borrow different fields of the MIR
body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`.

To preserve validity of control flow graph caches in the presence of
modifications, a new struct `BasicBlocks` wraps together basic blocks
and control flow graph caches.

The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`.
On the other hand a mutable access requires explicit `as_mut()` call.
2022-07-07 18:06:53 +05:30
Dylan DPC
f6bbe280bf
Rollup merge of #96856 - DrMeepster:fix_projection_validation, r=Icnr
Fix ProjectionElem validation

`TypeChecker::visit_projection_elem` was not actually being called.
2022-07-07 18:06:48 +05:30
Oli Scherer
2a899dc1cf UnsafeCell now has no niches, ever. 2022-07-07 10:46:22 +00:00
Tomasz Miąsko
c9dd1d9983 Make MIR basic blocks field public
This makes it possible to mutably borrow different fields of the MIR
body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`.

To preserve validity of control flow graph caches in the presence of
modifications, a new struct `BasicBlocks` wraps together basic blocks
and control flow graph caches.

The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`.
On the other hand a mutable access requires explicit `as_mut()` call.
2022-07-07 08:11:49 +02:00
bors
8824d13161 Auto merge of #98831 - RalfJung:no-more-unsized-locals, r=oli-obk
interpret: remove support for unsized_locals

I added support for unsized_locals in https://github.com/rust-lang/rust/pull/59780 but the current implementation is a crude hack and IMO definitely not the right way to have unsized locals in MIR. It also [causes problems](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Missing.20Layout.20Check.20in.20.60interpret.2Foperand.2Ers.60.3F). and what codegen does is unsound and has been for years since clearly nobody cares (so I hope nobody actually relies on that implementation and I'll be happy if Miri ensures they do not). I think if we want to have unsized locals in Miri/MIR we should add them properly, either by having a `StorageLive` that takes metadata or by having an `alloca` that returns a pointer (making the ptr indirection explicit) or something like that.

So, this PR removes the `LocalValue::Unallocated` hack. It adds `Immediate::Uninit`, for several reasons:
- This lets us still do fairly little work in `push_stack_frame`, in particular we do not actually have to create any allocations.
- If/when I remove `ScalarMaybeUninit`, we will need something like this to have an "optimized" representation of uninitialized locals. Without this we'd have to put uninitialized integers into the heap!
- const-prop needs some way to indicate "I don't know the value of this local'; it used to use `LocalValue::Unallocated` for that, now it can use `Immediate::Uninit`.

There is still a fundamental difference between `LocalValue::Unallocated` and `Immediate::Uninit`: the latter is considered a regular local that you can read from and write to, it just has a more optimized representation when compared with an actual `Allocation` that is fully uninit. In contrast, `LocalValue::Unallocated`  had this really odd behavior where you would write to it but not read from it. (This is in fact what caused the problems mentioned above.)

While at it I also did two drive-by cleanups/improvements:
- In `pop_stack_frame`, do the return value copying and local deallocation while the frame is still on the stack. This leads to better error locations being reported. The old errors were [sometimes rather confusing](https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Cron.20Job.20Failure.202022-06-24/near/287445522).
- Deduplicate `copy_op` and `copy_op_transmute`.

r? `@oli-obk`
2022-07-06 22:50:29 +00:00
Guillaume Gomez
d712f67897
Rollup merge of #98519 - TaKO8Ki:add-head-span-field-to-item-and-impl-item, r=cjgillot
Replace some `guess_head_span` with `def_span`

This patch fixes a part of #97417.
r? `@cjgillot`
2022-07-06 20:43:24 +02:00
Ralf Jung
e685530b07 deduplicate some copy_op code 2022-07-06 14:11:41 -04:00
Ralf Jung
47cb276ab8 support passing unsized fn arguments 2022-07-06 14:03:20 -04:00
Ralf Jung
8ef0caa23c interpret: remove LocalValue::Unallocated, add Operand::Uninit
Operand::Uninit is an *allocated* operand that is fully uninitialized.
This lets us lazily allocate the actual backing store of *all* locals (no matter their ABI).

I also reordered things in pop_stack_frame at the same time.
I should probably have made that a separate commit...
2022-07-06 14:03:20 -04:00
Ralf Jung
a73e2557c7 fix ICE in ConstProp 2022-07-06 13:28:42 -04:00
Ralf Jung
dfd243e27c add track_caller to some interpreter functions 2022-07-06 11:27:54 -04:00
Ralf Jung
27b7b3dcd6 interpret: use AllocRange in UninitByteAccess
also use nice new format string syntax in interpret/error.rs
2022-07-06 10:55:06 -04:00
Takayuki Maeda
83dea35384 replace guess_head_span with def_span 2022-07-06 19:09:47 +09:00
Dylan DPC
7f62a719af
Rollup merge of #98968 - RalfJung:scalar-sanity, r=oli-obk
assert Scalar sanity

With https://github.com/rust-lang/rust/pull/96814 having landed, finally our `Scalar` layouts have the invariants they deserve. :)
2022-07-06 14:49:13 +05:30
Dylan DPC
56667b5a07
Rollup merge of #98964 - RalfJung:typo, r=Dylan-DPC
fix typo in function name

I don't know what I was doing when I named that function...
follow-up to #98888
r? `@oli-obk`
2022-07-06 14:49:11 +05:30
DrMeepster
a2799b2de8 fix projectionelem validation 2022-07-06 01:59:16 -07:00