Commit Graph

5220 Commits

Author SHA1 Message Date
bors
46514218f6 Auto merge of #112835 - lcnr:proof-tree-nits, r=BoxyUwU
proof tree nits

r? `@BoxyUwU`
2023-06-20 19:58:46 +00:00
Guillaume Gomez
73496fc5d5
Rollup merge of #112786 - lcnr:early-binder, r=Nilstrieb
change binders from tuple structs to named fields
2023-06-20 14:23:40 +02:00
lcnr
f7472aa69e cleanup imports 2023-06-20 12:41:00 +02:00
bors
6fc0273b5a Auto merge of #112320 - compiler-errors:do-not-impl-via-obj, r=lcnr
Add `implement_via_object` to `rustc_deny_explicit_impl` to control object candidate assembly

Some built-in traits are special, since they are used to prove facts about the program that are important for later phases of compilation such as codegen and CTFE. For example, the `Unsize` trait is used to assert to the compiler that we are able to unsize a type into another type. It doesn't have any methods because it doesn't actually *instruct* the compiler how to do this unsizing, but this is later used (alongside an exhaustive match of combinations of unsizeable types) during codegen to generate unsize coercion code.

Due to this, these built-in traits are incompatible with the type erasure provided by object types. For example, the existence of `dyn Unsize<T>` does not mean that the compiler is able to unsize `Box<dyn Unsize<T>>` into `Box<T>`, since `Unsize` is a *witness* to the fact that a type can be unsized, and it doesn't actually encode that unsizing operation in its vtable as mentioned above.

The old trait solver gets around this fact by having complex control flow that never considers object bounds for certain built-in traits:
2f896da247/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs (L61-L132)

However, candidate assembly in the new solver is much more lovely, and I'd hate to add this list of opt-out cases into the new solver. Instead of maintaining this complex and hard-coded control flow, instead we can make this a property of the trait via a built-in attribute. We already have such a build attribute that's applied to every single trait that we care about: `rustc_deny_explicit_impl`. This PR adds `implement_via_object` as a meta-item to that attribute that allows us to opt a trait out of object-bound candidate assembly as well.

r? `@lcnr`
2023-06-20 08:42:37 +00:00
Michael Goulet
ca68cf0d46 Merge attrs, better validation 2023-06-20 04:38:55 +00:00
Michael Goulet
91e5c3f2e5 Make rustc_deny_explicit_impl only local as well 2023-06-20 04:38:46 +00:00
Michael Goulet
657d3f43a9 Add rustc_do_not_implement_via_object 2023-06-20 04:38:46 +00: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
bors
4051305389 Auto merge of #112238 - scottmcm:mir-add-unchecked, r=cjgillot
Promote unchecked integer math to MIR `BinOp`s

So slice indexing by a range gets down to one basic block, for example.

r? cjgillot
2023-06-19 17:14:21 +00:00
lcnr
f2975810a5 change binders from tuple structs to named fields 2023-06-19 11:38:07 +02:00
Scott McMurray
39788e07ba Promote unchecked_add/sub/mul/shl/shr to mir::BinOp 2023-06-19 01:47:03 -07:00
Boxy
3a6ce74c07 move to nested module 2023-06-19 09:08:03 +01:00
Boxy
51090b962f show normalizes-to hack and response instantiation goals 2023-06-19 09:06:16 +01:00
Boxy
e367c04dc6 introduce a separate set of types for finalized proof trees 2023-06-19 09:06:16 +01:00
Boxy
3587d4ced8 say what kind of cache hit 2023-06-19 09:01:37 +01:00
Boxy
3009b2c647 initial info dump 2023-06-19 09:01:37 +01:00
Deadbeef
446db517af fix doc 2023-06-19 03:47:27 +00: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
Rémy Rakic
08a9f25245 remove redundant combinators between PO and RPO 2023-06-18 09:16:40 +00:00
Matthias Krüger
3436069c34
Rollup merge of #112734 - dswij:bounds-predicates-clause, r=compiler-errors
Make `Bound::predicates`  use `Clause`

Part of #107250

`Bound::predicates` returns an iterator over `Binder<_, Clause>` instead of `Predicate`.

I tried updating `explicit_predicates_of` as well, but it seems that it needs a lot more change than I thought. Will do it in a separate PR instead.
2023-06-18 08:06:43 +02:00
Matthias Krüger
8d3d3cc0ba
Rollup merge of #112667 - compiler-errors:wf-goal-is-clause, r=lcnr
Move WF/ConstEvaluatable goal to clause

It can show up in a param-env, so I think it needs to be a clause kind.

r? ```@lcnr``` or ```@oli-obk```
2023-06-18 08:06:41 +02:00
Deadbeef
89c24af133 Better error for non const PartialEq call generated by match 2023-06-18 05:24:38 +00:00
Michael Goulet
6594c75449 Move ConstEvaluatable to Clause 2023-06-17 21:27:13 +00:00
Michael Goulet
52d3fc93f2 Move WF goal to clause 2023-06-17 21:20:20 +00:00
Matthias Krüger
5518eb863f
Rollup merge of #112738 - matthiaskrgr:ice_msg, r=oli-obk
make ice msg "Unknown runtime phase" a bit nicer
2023-06-17 18:27:31 +02:00
Matthias Krüger
32aee06448 make ice msg "Unknown runtime phase" a bit nicer 2023-06-17 13:55:11 +02:00
Matthias Krüger
981a2a2c00
Rollup merge of #112728 - Zalathar:spanview-charset, r=Nilstrieb
Add `<meta charset="utf-8">` to `-Zdump-mir-spanview` output

Without an explicit `<meta charset>` declaration, some browsers (e.g. Safari) won't detect the page encoding as UTF-8, causing unicode characters in the dump output to display incorrectly.
2023-06-17 12:43:32 +02:00
dswij
f874345784 Bound::predicates to return Clause 2023-06-17 17:16:30 +08:00
Zalathar
3eddb29555 Add <meta charset="utf-8"> to -Zdump-mir-spanview output 2023-06-17 18:31:35 +10: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
1311bb56f3 Simplify an ObjectData field 2023-06-17 03:32:45 +00:00
Michael Goulet
9e68b6f505 Simplify some impl source candidates 2023-06-17 03:32:45 +00:00
Michael Goulet
1704481bfa Remove some ImplSource candidates 2023-06-17 03:32:45 +00:00
bors
0cc541e4b2 Auto merge of #108860 - oli-obk:tait_alias, r=compiler-errors
Add `AliasKind::Weak` for type aliases.

`type Foo<T: Debug> = Bar<T>;` does not check `T: Debug` at use sites of `Foo<NotDebug>`, because in contrast to a

```rust
trait Identity {
    type Identity;
}
impl<T: Debug> Identity for T {
    type Identity = T;
}
<NotDebug as Identity>::Identity
```

type aliases do not exist in the type system, but are expanded to their aliased type immediately when going from HIR to the type layer.

Similarly:

* a private type alias for a public type is a completely fine thing, even though it makes it a bit hard to write out complex times sometimes
* rustdoc expands the type alias, even though often times users use them for documentation purposes
* diagnostics show the expanded type, which is confusing if the user wrote a type alias and the diagnostic talks about another type that they don't know about.

For type alias impl trait, these issues do not actually apply in most cases, but sometimes you have a type alias impl trait like `type Foo<T: Debug> = (impl Debug, Bar<T>);`, which only really checks it for `impl Debug`, but by accident prevents `Bar<T>` from only being instantiated after proving `T: Debug`. This PR makes sure that we always check these bounds explicitly and don't rely on an implementation accident.

To not break all the type aliases out there, we only use it when the type alias contains an opaque type. We can decide to do this for all type aliases over an edition.

Or we can later extend this to more types if we figure out the back-compat concerns with suddenly checking such bounds.

As a side effect, easily allows fixing https://github.com/rust-lang/rust/issues/108617, which I did.

fixes https://github.com/rust-lang/rust/issues/108617
2023-06-17 00:33:29 +00:00
Michael Goulet
56c96d7552
Rollup merge of #112706 - WaffleLapkin:syntax_context_is_root, r=petrochenkov
Add `SyntaxContext::is_root`

Makes the code a tad nicer.
2023-06-16 12:53:24 -07:00
Michael Goulet
cef94ecedf
Rollup merge of #112665 - compiler-errors:assumption-takes-clause, r=lcnr
Make assumption functions in new solver take `Binder<'tcx, Clause<'tcx>>`

We just use an if-let to match on an optional clause at all the places where we transition from `Predicate` -> `Clause`, but I assume that when things like item-bounds and param-env start to only store `Clause`s then those can just be trivially dropped.

r? ``@lcnr``
2023-06-16 12:53:23 -07: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
Maybe Waffle
73c5c97de7 Add SyntaxContext::is_root 2023-06-16 13:47:42 +00:00
Dylan DPC
64f6c00772
Rollup merge of #112443 - compiler-errors:next-solver-opportunistically-resolve-regions, r=lcnr
Opportunistically resolve regions in new solver

Use `opportunistic_resolve_var` during canonicalization to collapse some regions.

We have to start using `CanonicalVarValues::is_identity_modulo_regions`. We also have to modify that function to consider responses like `['static, ^0, '^1, ^2]` to be an "identity" response, since because we opportunistically resolve regions, there's no longer a 1:1 mapping between canonical var values and bound var indices in the response...

There's one nasty side-effect -- one test (`tests/ui/dyn-star/param-env-infer.rs`) starts to ICE because the certainty goes from `Yes` to `Maybe(Overflow)`... Not exactly sure why, though? Putting this up for discussion/investigation.

r? ```@lcnr```
2023-06-16 14:46:15 +05:30
bors
c84d5e7078 Auto merge of #112346 - saethlin:no-comment, r=oli-obk
Remove comments from mir-opt MIR dumps

See https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Line.20numbers.20in.20mir-opt.20tests/near/363849874

In https://github.com/rust-lang/rust/pull/99780 there is mention that "there has been a zulip conversation about disabling line numbers with mixed opinions" which to me means that some people opposed this. I can't find the referenced conversation so... here we go.

The current situation is quite chaotic. It's not hard to find MIR diffs which contain

* Absolute line numbers
* Relative line numbers
* Substituted line numbers (LL)
For example: 408bbd0406/tests/mir-opt/inline/inline_shims.drop.Inline.diff (L10-L17)

And sometimes adding a comment at the top of a mir-opt test generates a diff in the test because a line number changed: https://github.com/rust-lang/rust/pull/98112/files#diff-b8cf4bcce95078e6a3faf075e9abf6864872fb28a64d95c04f04513b9e3bbd81

And irrelevant changes to the standard library can generate diffs in mir-opt tests: https://github.com/rust-lang/rust/pull/110694/files#diff-bf96b0e7c67b8b272814536888fd9428c314991e155beae1f0a2a67f0ac47b2c
769886cc35

I think we should, specifically in mir-opt tests, completely remove the comments, or insert placeholders for all line and column numbers.
2023-06-16 01:55:34 +00:00
Guillaume Gomez
af955a647e
Rollup merge of #112614 - lukas-code:apit-unsized-suggestion, r=compiler-errors
tweak suggestion for argument-position `impl ?Sized`

fixes this invalid suggestion:
```text
help: consider removing the `?Sized` bound to make the type parameter `Sized`
  |
1 - fn foo(_: impl ?Sized) {}
1 + fn foo(_: impl ) {}
  |
```
2023-06-15 22:04:56 +02:00
Ben Kimock
0a1fa411ed Remove comments from mir-opt MIR dumps 2023-06-15 15:19:11 -04:00
Michael Goulet
b4ba7c4f93 Make assumption functions in new solver take clause 2023-06-15 16:18:38 +00:00
Matthias Krüger
c0a089e118
Rollup merge of #112634 - mj10021:issue-112438-fix, r=compiler-errors
add InlineConst check

add check to close #112438
2023-06-15 17:52:38 +02:00
Lukas Markeffsky
b6a3f126c0 change std::marker::Sized to just Sized 2023-06-15 12:01:38 +02:00
Lukas Markeffsky
ee7e717322 tweak suggestion for argument-position impl ?Sized 2023-06-15 12:00:57 +02:00
Rémy Rakic
f134101e69 remove unused postorder CFG cache 2023-06-14 23:01:36 +00:00
Rémy Rakic
0b4b0869a7 make traversal::postorder traverse RPO cache backwards 2023-06-14 23:01:36 +00:00
James Dietz
20499b9669 add InlineConst check 2023-06-14 18:01:05 -04:00