Commit Graph

377 Commits

Author SHA1 Message Date
bors
acfd327fd4 Auto merge of #97177 - oli-obk:const-stability, r=davidtwco
Implement proper stability check for const impl Trait, fall back to unstable const when undeclared

Continuation of #93960

`@jhpratt` it looks to me like the test was simply not testing for the failure you were looking for? Your checks actually do the right thing for const traits?
2022-05-22 06:47:36 +00:00
Jacob Pratt
49c82f31a8
Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
Guillaume Gomez
9098f05b26
Rollup merge of #97188 - carbotaniuman:remove-null-assert, r=RalfJung
Remove unneeded null pointer asserts in ptr2int casts

This removes an assert that a pointer with address 0 has no provenance. This change is needed to support permissive provenance work in Miri, and seems justified by `ptr.with_addr(0)` working and a discussion on Zulip regarding LLVM semantics.

r? `@RalfJung`
2022-05-20 14:03:04 +02:00
Guillaume Gomez
706aa59efa
Rollup merge of #97185 - RalfJung:number-validity, r=oli-obk
interpret/validity: separately control checking numbers for being init and non-ptr

This lets Miri control this in a more fine-grained way.

r? `@oli-obk`
2022-05-20 14:03:03 +02:00
carbotaniuman
e24673502f Remove unneeded asserts 2022-05-19 13:51:53 -05:00
Ralf Jung
4bb152c4bc fmt 2022-05-19 20:34:37 +02:00
Ralf Jung
5514b1176f interpret/validity: separately control checking numbers for being init and non-ptr 2022-05-19 20:16:25 +02:00
Jacob Pratt
f0620c9503 Proper const stability check, default to unstable
Rather than deferring to const eval for checking if a trait is const, we
now check up-front. This allows the error to be emitted earlier, notably
at the same time as other stability checks.

Also included in this commit is a change of the default const stability
level to UNstable. Previously, an item that was `const` but did not
explicitly state it was unstable was implicitly stable.
2022-05-19 12:21:45 +00:00
Jacob Pratt
a9dd4cfa6b Add and use stability helper methods
This avoids an ambiguity (when reading) where `.level.is_stable()` is
not immediately clear whether it is general stability or const
stability.
2022-05-19 12:21:45 +00:00
Jacob Pratt
f53fc41cfc Fall back to being const-unstable when undeclared 2022-05-19 12:21:45 +00:00
bors
cd282d7f75 Auto merge of #97019 - b-naber:transition-to-valtrees-pt1, r=oli-obk
Transition to valtrees pt1

Compartmentalising https://github.com/rust-lang/rust/pull/96591 as much as possible.

r? `@oli-obk`
2022-05-18 20:12:07 +00:00
Yuki Okushi
248890c32e
Rollup merge of #97116 - RalfJung:ref-validity, r=oli-obk
interpret/validity: reject references to uninhabited types

According to https://doc.rust-lang.org/reference/behavior-considered-undefined.html, this is definitely UB. And we can check this without actually looking up anything in memory, we just need the reference value and its type, making this a great candidate for a validity invariant IMO and my favorite resolution of https://github.com/rust-lang/unsafe-code-guidelines/issues/77.

With this PR, Miri with `-Zmiri-check-number-validity` implements all my preferred options for what the validity invariants of our types could be. :)

CTFE has been doing recursive checking anyway, so this is backwards compatible but might change the error output. I will submit a PR with the new Miri tests soon.

r? `@oli-obk`
2022-05-18 07:41:01 +09:00
Ralf Jung
501f5d09a0 interpret/validity: reject references to uninhabited types 2022-05-17 17:32:36 +02:00
bors
3655175a75 Auto merge of #97111 - JohnTitor:rollup-x3vjf6u, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #96329 (Add a couple tests for #90887 fixes)
 - #97009 (Allow `unused_macro_rules` in path tests)
 - #97075 (Add regression test for #81804)
 - #97079 (Change `Successors` to `impl Iterator<Item = BasicBlock>`)
 - #97080 (remove the `RelateResultCompare` trait)
 - #97093 (Migrate `maybe_recover_from_bad_type_plus` diagnostic)
 - #97102 (Update function pointer call error message)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-17 12:01:12 +00:00
bors
735efc0c70 Auto merge of #97012 - oli-obk:🦀_intrinsics, r=davidtwco
Add a query for checking whether a function is an intrinsic.

work towards #93145

This will reduce churn when we add more ways to declare intrinsics

r? `@scottmcm`
2022-05-17 09:39:26 +00:00
mbartlett21
56649bb844 Update function pointer call error message
It now uses the type of context. (issue 97082)
2022-05-17 04:13:20 +00:00
b-naber
96b36d6eb2 use GlobalId in eval_to_valtree query and introduce query for valtree_to_const_val 2022-05-16 15:58:15 +02:00
Oli Scherer
0a6b69106e Add a query for checking whether a function is an intrinsic. 2022-05-16 07:07:44 +00:00
bors
2a8a0fc423 Auto merge of #96883 - jackh726:early-binder-2, r=oli-obk
Add EarlyBinder

Chalk has no concept of `Param` (e0ade19d13/chalk-ir/src/lib.rs (L579)) or `ReEarlyBound` (e0ade19d13/chalk-ir/src/lib.rs (L1308)). Everything  is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk.

Either way, tracking when we have or haven't already substituted out these in rustc can be helpful.

As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted.

r? `@nikomatsakis`
2022-05-14 23:53:11 +00:00
bors
8019fa0dc0 Auto merge of #95826 - carbotaniuman:miri-permissive-provenance, r=RalfJung
Initial work on Miri permissive-exposed-provenance

Rustc portion of the changes for portions of a permissive ptr-to-int model for Miri. The main changes here are changing `ptr_get_alloc` and `get_alloc_id` to return an Option, and also making ptr-to-int casts have an expose side effect.
2022-05-14 10:36:47 +00:00
Jack Huey
c92248ab9f Add bound_type_of 2022-05-13 18:27:18 -04:00
carbotaniuman
bd5fce65c6 Rustc changes for permissive provenance 2022-05-13 12:30:25 -05:00
klensy
7f318256c9 fix clippy expect_fun_call 2022-05-12 19:26:52 +03:00
bors
481db40311 Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwco
don't encode only locally used attrs

Part of https://github.com/rust-lang/compiler-team/issues/505.

We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR.

After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates.

cc https://github.com/rust-lang/rust/pull/94963#issuecomment-1082924289
2022-05-12 12:48:30 +00:00
bors
3a08bd7873 Auto merge of #96889 - Aaron1011:place-ref-remove, r=compiler-errors
Remove `PartialOrd`/`Ord` impl for `PlaceRef`

This is a new attempt at #93315. It removes one usage
of the `Ord` impl for `DefId`, which should make it easier
to eventually remove that impl.
2022-05-12 05:03:48 +00:00
Scott McMurray
003b954a43 Apply CR suggestions; add real tracking issue 2022-05-11 17:16:25 -07:00
Scott McMurray
4bb15b3797 Add a debug check for ordering, and check for isize overflow in CTFE 2022-05-11 17:16:25 -07:00
Scott McMurray
89a18cb600 Add unsigned_offset_from on pointers
Like we have `add`/`sub` which are the `usize` version of `offset`, this adds the `usize` equivalent of `offset_from`.  Like how `.add(d)` replaced a whole bunch of `.offset(d as isize)`, you can see from the changes here that it's fairly common that code actually knows the order between the pointers and *wants* a `usize`, not an `isize`.

As a bonus, this can do `sub nuw`+`udiv exact`, rather than `sub`+`sdiv exact`, which can be optimized slightly better because it doesn't have to worry about negatives.  That's why the slice iterators weren't using `offset_from`, though I haven't updated that code in this PR because slices are so perf-critical that I'll do it as its own change.

This is an intrinsic, like `offset_from`, so that it can eventually be allowed in CTFE.  It also allows checking the extra safety condition -- see the test confirming that CTFE catches it if you pass the pointers in the wrong order.
2022-05-11 17:16:25 -07:00
Aaron Hill
6b747aa397
Remove PartialOrd/Ord impl for PlaceRef
This is a new attempt at #93315. It removes one usage
of the `Ord` impl for `DefId`, which should make it easier
to eventually remove that impl.
2022-05-11 16:22:23 -04:00
bors
6dd68402c5 Auto merge of #96220 - RalfJung:scalar-no-padding, r=oli-obk
tighten sanity checks around Scalar and ScalarPair

While investigating https://github.com/rust-lang/rust/issues/96185 I noticed codegen has tighter sanity checks here than Miri does, so I added some more assertions. Strangely, some of them fail, so I also needed to add a HACK... that is probably worth looking into.

This does not fix that issue, but it changes the ICE messages, making it quite clear that we have a scalar whose size is not the same as that of the surrounding layout.

r? `@oli-obk`
2022-05-11 18:34:14 +00:00
Dylan DPC
0c2cee2e9d
Rollup merge of #95281 - pierwill:fix-85513, r=Dylan-DPC
Fix inaccurate function name in `rustc_const_eval` docs

Looks to me like this fixes #85513. I had trouble making a intra-docs link to `eval_place_to_op` work, though...
2022-05-11 13:49:28 +02:00
Ralf Jung
14f6daf935 avoid computing Scalar size/align in debug builds 2022-05-11 13:32:19 +02:00
Jack Huey
319575ae8c Introduce EarlyBinder 2022-05-10 22:47:18 -04:00
Ralf Jung
761077e19e fmt 2022-05-10 14:38:00 +02:00
Ralf Jung
aef8a9306d update/remove some old comments 2022-05-10 14:23:32 +02:00
Ralf Jung
600d960261 even tighter checks for layouts on immediate field projections 2022-05-10 14:23:32 +02:00
Ralf Jung
79c169d5cf disable one check for now until #96185 is fixed 2022-05-10 14:23:32 +02:00
Ralf Jung
719655658a tighten sanity checks around Scalar and ScalarPair 2022-05-10 13:32:20 +02:00
lcnr
6c8265dc56 only_local: always check for misuse 2022-05-10 12:07:35 +02:00
bors
e013f9e0ca Auto merge of #96815 - SparrowLii:promote_const, r=oli-obk
optimize `promote_consts` by caching the results of `validate_local`

From the FIXME in the impl of `promote_consts`. Early return the `validate_local` should save some compile time.

`qualif_local` is similar to this, but requires futher changing because there are different types of qualif checks. If this PR is effective, I will do it as well.
2022-05-09 11:49:09 +00:00
SparrowLii
b890037af3 use Result<(),()> instead of Validity enum 2022-05-09 17:13:30 +08:00
SparrowLii
cb7f116c04 optimize promote_consts by cache the validate check 2022-05-07 21:02:25 +08:00
Jakob Degen
c4168fdb50 Check that field projections have the correct type 2022-05-06 16:43:09 -04:00
pierwill
f1f0734718 Fix inaccurate function name in rustc_const_eval docs 2022-05-06 14:52:42 -05:00
Jakob Degen
5289bbece3 Expand validator to be more precise on checked binary ops 2022-05-06 15:40:32 -04:00
Matthias Krüger
68048199c9
Rollup merge of #96714 - RalfJung:scalar-pair-debug, r=oli-obk
interpret/validity: debug-check ScalarPair layout information

This would have caught https://github.com/rust-lang/rust/issues/96158.
I ran the Miri test suite and it still passes.

r? `@oli-obk`
2022-05-05 15:43:07 +02:00
Ralf Jung
e47d6c7a6b give it a scary name 2022-05-05 09:55:38 +02:00
Ralf Jung
5b20da8180 interpret: debug-check ScalarPair layout information 2022-05-04 22:52:02 +02:00
Josh Triplett
0fc5c524f5 Stabilize bool::then_some 2022-05-04 13:22:08 +02:00
Vadim Petrochenkov
5b5964f569 rustc: Panic by default in DefIdTree::parent
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.
2022-05-02 01:56:50 +03:00