Commit Graph

648 Commits

Author SHA1 Message Date
Dylan DPC
81f3841cfb
Rollup merge of #101101 - RalfJung:read-pointer-as-bytes, r=oli-obk
interpret: make read-pointer-as-bytes a CTFE-only error with extra information

Next step in the reaction to https://github.com/rust-lang/rust/issues/99923. Also teaches Miri to implicitly strip provenance in more situations when transmuting pointers to integers, which fixes https://github.com/rust-lang/miri/issues/2456.

Pointer-to-int transmutation during CTFE now produces a message like this:
```
   = help: this code performed an operation that depends on the underlying bytes representing a pointer
   = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
```

r? ``@oli-obk``
2022-08-30 11:26:51 +05:30
bors
9f4d5d2a28 Auto merge of #101167 - matthiaskrgr:rollup-yt3jdmp, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #100898 (Do not report too many expr field candidates)
 - #101056 (Add the syntax of references to their documentation summary.)
 - #101106 (Rustdoc-Json: Retain Stripped Modules when they are imported, not when they have items)
 - #101131 (CTFE: exposing pointers and calling extern fn is just impossible)
 - #101141 (Simplify `get_trait_ref` fn used for `virtual_function_elimination`)
 - #101146 (Various changes to logging of borrowck-related code)
 - #101156 (Remove `Sync` requirement from lint pass objects)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-29 22:49:04 +00:00
Matthias Krüger
cd53b4dba5
Rollup merge of #101131 - RalfJung:ctfe-no-needs-rfc, r=oli-obk
CTFE: exposing pointers and calling extern fn is just impossible

The remaining "needs RFC" errors are just needlessly confusing, I think -- time to get rid of that error variant. They are anyway only reachable with miri-unleashed (if at all).

r? `@oli-obk`
2022-08-29 21:12:57 +02:00
Dylan DPC
3ea5456366
Rollup merge of #100239 - RalfJung:const-prop-uninit, r=oli-obk
remove an ineffective check in const_prop

Based on https://github.com/rust-lang/rust/pull/100043, only the last two commits are new.

ConstProp has a special check when reading from a local that prevents reading uninit locals. However, if that local flows into `force_allocation`, then no check fires and evaluation proceeds. So this check is not really effective at preventing accesses to uninit locals.

With https://github.com/rust-lang/rust/pull/100043, `read_immediate` and friends always fail when reading uninit locals, so I don't see why ConstProp would need a separate check. Thus I propose we remove it. This is needed to be able to do https://github.com/rust-lang/rust/pull/100085.
2022-08-29 16:49:40 +05:30
Matthias Krüger
d814fdd3f9
Rollup merge of #100897 - RalfJung:const-not-to-mutable, r=lcnr
extra sanity check against consts pointing to mutable memory

This should be both unreachable and redundant (since we already ensure that validation only reads from read-only memory, when validating consts), but I feel like we cannot be paranoid enough here, and also if this ever fails it'll be a nicer error than the "cannot read from mutable memory" error.
2022-08-29 06:34:46 +02:00
Matthias Krüger
d182081de1
Rollup merge of #99027 - tmiasko:basic-blocks, r=oli-obk
Replace `Body::basic_blocks()` with field access

Since the refactoring in #98930, it is possible to borrow the basic blocks
independently from other parts of MIR by accessing the `basic_blocks` field
directly.

Replace unnecessary `Body::basic_blocks()` method with a direct field access,
which has an additional benefit of borrowing the basic blocks only.
2022-08-29 06:34:43 +02:00
Ralf Jung
f29c3c421b entirely get rid of NeedsRfc CTFE errors 2022-08-28 13:40:24 -04:00
Ralf Jung
a9f9145b09 CTFE: exposing pointers and calling extern fn doesn't need an RFC, it is just impossible 2022-08-28 13:32:48 -04:00
Ralf Jung
1a1220c5e4 validation should only catch UB errors 2022-08-28 11:49:32 -04:00
Matthias Krüger
5b8081490f
Rollup merge of #101038 - RalfJung:interning-alignment, r=oli-obk
no alignment check during interning

This should fix https://github.com/rust-lang/rust/issues/101034
r? `@oli-obk`

Unfortunately we don't have a self-contained testcase for this problem. I am not sure how it can be triggered...
2022-08-28 09:35:19 +02:00
Ralf Jung
2e172473da interpret: make read-pointer-as-bytes *always* work in Miri
and show some extra information when it happens in CTFE
2022-08-27 18:37:44 -04:00
Ralf Jung
e63a625711 interpret: rename relocation → provenance 2022-08-27 14:11:19 -04:00
bors
332cc8fb75 Auto merge of #100999 - nnethercote:shrink-FnAbi, r=bjorn3
Shrink `FnAbi`

Because they can take up a lot of memory in debug and release builds.

r? `@bjorn3`
2022-08-27 14:00:53 +00:00
Ralf Jung
aff9841507 remove a now-useless machine hook 2022-08-27 08:53:04 -04:00
Ralf Jung
4173e971b8 remove an ineffective check in const_prop 2022-08-27 08:53:04 -04:00
bors
bb8a08f011 Auto merge of #101064 - compiler-errors:rollup-fwm5m5f, r=compiler-errors
Rollup of 9 pull requests

Successful merges:

 - #100724 (Migrate ast lowering to session diagnostic)
 - #100735 (Migrate `rustc_ty_utils` to `SessionDiagnostic`)
 - #100738 (Diagnostics migr const eval)
 - #100744 (Migrate rustc_mir_dataflow to diagnostic structs)
 - #100776 (Migrate `rustc_lint` errors to `SessionDiagnostic`)
 - #100817 (sugg: suggest the usage of boolean value when there is a typo in the keyword)
 - #100836 (Migrate `rustc_attr` crate diagnostics)
 - #100890 (Migrate rustc_driver to SessionDiagnostic)
 - #100900 (on `region_errors.rs`)

Failed merges:

 - #100831 (Migrate `symbol_mangling` module to new diagnostics structs)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-27 00:38:06 +00:00
Michael Goulet
b54344401a
Rollup merge of #100738 - nidnogg:diagnostics_migr_const_eval, r=davidtwco
Diagnostics migr const eval

This PR should eventually contain all diagnostic migrations for the `rustc_const_eval` crate.

r? `@davidtwco`
`@rustbot` label +A-translation
2022-08-26 15:56:23 -07:00
Ralf Jung
30fa931f92 make read_immediate error immediately on uninit, so ImmTy can carry initialized Scalar 2022-08-26 13:20:57 -04:00
Ralf Jung
2e52fe01cf remove some now-unnecessary parameters from check_bytes 2022-08-26 13:20:56 -04:00
Ralf Jung
da13935ecc remove enforce_number_init machine hook that Miri no longer needs 2022-08-26 13:20:56 -04:00
Ralf Jung
9d604f301b fix an outdated machine hook name 2022-08-26 13:20:56 -04:00
Tomasz Miąsko
b48870b451 Replace Body::basic_blocks() with field access 2022-08-26 14:27:08 +02:00
Ralf Jung
b85178a5fc no alignment check during interning 2022-08-26 08:15:29 -04:00
Nicholas Nethercote
f974617bda Move ArgAbi::pad_i32 into PassMode::Cast.
Because it's only needed for that variant. This shrinks the types and
clarifies the logic.
2022-08-26 11:12:36 +10:00
Nicholas Nethercote
b853e8a619 Turn ArgAbi::pad into a bool.
Because it's only ever set to `None` or `Some(Reg::i32())`.
2022-08-26 10:53:41 +10:00
Nicholas Nethercote
e4bf113027 Box CastTarget within PassMode.
Because `PassMode::Cast` is by far the largest variant, but is
relatively rare.

This requires making `PassMode` not impl `Copy`, and `Clone` is no
longer necessary. This causes lots of sigil adjusting, but nothing very
notable.
2022-08-26 09:35:28 +10:00
bors
4d45b0745a Auto merge of #100571 - cjgillot:mir-cost-visit, r=compiler-errors
Check projection types before inlining MIR

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

I'm very unhappy with this solution, having to duplicate MIR validation code, but at least it removes the ICE.

r? `@compiler-errors`
2022-08-25 08:16:43 +00:00
Ralf Jung
cb4cd73664 extra sanity check against consts pointing to mutable memory 2022-08-23 08:12:37 -04:00
nidnogg
066796cece Addressing tidy check fail 2022-08-22 12:32:42 -03:00
nidnogg
649749c7b0 Addressing last comment on PR review 2022-08-22 12:14:49 -03:00
nidnogg
13abae2deb Switched errors to diags according to latest PRs 2022-08-22 00:02:36 -03:00
nidnogg
0a58b26e8a Hotfix ftl err name, added check for err.code in create_feature_err 2022-08-21 23:22:55 -03:00
nidnogg
4c82845b3a Fixed failing tests (missing labels), added automatic error code in create_feature_err() builder 2022-08-21 23:22:55 -03:00
nidnogg
d1f14ee1b0 Added several more migrations under ops.rs, failing some tests though 2022-08-21 23:22:54 -03:00
nidnogg
33e8aaf830 Migration on ops.rs for unstable const functions 2022-08-21 23:22:53 -03:00
nidnogg
70ea98633e Migrated Unallowed function pointer calls in interpreter/ops 2022-08-21 23:22:51 -03:00
nidnogg
6af8e46a9a Finished const_eval module migration, moving onto sibling folders 2022-08-21 23:22:50 -03:00
Ralf Jung
d7ee421870 fix ICE with extra-const-ub-checks 2022-08-21 20:00:38 -04:00
Camille GILLOT
10e71dfdb8 Also validate types before inlining. 2022-08-21 12:54:26 +02:00
Xiretza
7f3a6fd7f6 Replace #[lint/warning/error] with #[diag] 2022-08-21 09:17:43 +02:00
Matthias Krüger
c4b83ebe7c
Rollup merge of #100507 - cameron1024:suggest-lazy, r=compiler-errors
suggest `once_cell::Lazy` for non-const statics

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

Some questions:
 - removing the `if` seems to include too many cases (e.g. calls to non-const functions inside a `const fn`), but this code excludes the following case:
```rust
const FOO: Foo = non_const_fn();
```
Should we suggest `once_cell` in this case as well?
 - The original issue mentions suggesting `AtomicI32` instead of `Mutex<i32>`, should this PR address that as well?
2022-08-20 07:08:59 +02:00
Dylan DPC
c4707ff8ef
Rollup merge of #100208 - RalfJung:dyn-upcast-nop, r=petrochenkov
make NOP dyn casts not require anything about the vtable

As suggested [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/dyn-upcasting.20stabilization/near/292151439). This matches what the codegen backends already do, and what Miri did do until https://github.com/rust-lang/rust/pull/99420 when I made it super extra paranoid.
2022-08-19 12:26:41 +05:30
Matthias Krüger
bb77336c0a
Rollup merge of #99972 - RalfJung:1zst, r=lcnr
interpret: only consider 1-ZST when searching for receiver

`repr(transparent)` currently entirely rejects ZST with alignment larger than 1 (which is odd, arguably [this](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=02870f29396fa948c3123cb53d869ad1) should be accepted), so this should be safe. And if it ever isn't safe then that is very likely a bug elsewhere in the compiler.
2022-08-17 12:32:48 +02:00
Matthias Krüger
88af506e94
Rollup merge of #100600 - saethlin:rename-memory-hooks, r=RalfJung
Rename Machine memory hooks to suggest when they run

Some of the other memory hooks start with `before_` or `after_` to indicate that they run before or after a certain operation. These don't, so I was a bit confused as to when they are supposed to run.

`memory_read` can be read two ways in English, "memory was read" or "this is a memory read" so without the prefix this was especially ambiguous.
2022-08-16 06:06:00 +02:00
Ben Kimock
a5cc3a0557 Rename Machine memory hooks to suggest when they run 2022-08-15 19:54:43 -04:00
cameron
34e0d9a0bb suggest lazy-static for non-const statics 2022-08-14 23:07:47 +01:00
Michael Goulet
9ab54df8d7
Rollup merge of #100438 - compiler-errors:issue-100360, r=lcnr
Erase regions better in `promote_candidate`

Use `tcx.erase_regions` instead of manually walking through the substs.... this also makes the code slightly simpler 🙈

Fixes #100360
Fixes #89851
2022-08-13 14:10:07 -07:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Dylan DPC
392ba5f111
Rollup merge of #100229 - RalfJung:extra-const-ub-checks, r=lcnr
add -Zextra-const-ub-checks to enable more UB checking in const-eval

Cc https://github.com/rust-lang/rust/issues/99923
r? `@oli-obk`
2022-08-12 20:39:11 +05:30
Michael Goulet
f94220f68e Erase regions better in promote_candidate 2022-08-12 03:48:40 +00:00