Commit Graph

4959 Commits

Author SHA1 Message Date
Yuki Okushi
31e2f4d800
Rollup merge of #111173 - nnethercote:still-more-Encoder-cleanups, r=cjgillot
Still more encoder cleanups

r? ``@cjgillot``
2023-05-05 12:46:27 +09:00
Matthias Krüger
c0ca84b006
Rollup merge of #111100 - BoxyUwU:array_repeat_expr_wf, r=compiler-errors
check array type of repeat exprs is wf

Fixes #111091

Also makes sure that we actually renumber regions in the length of repeat exprs which we previously weren't doing and would cause ICEs in `adt_const_params` + `generic_const_exprs` from attempting to prove the wf goals when the length was an unevaluated constant with `'erased` in the `ty` field of `Const`

The duplicate errors are caused by the fact that `const_arg_to_const`/`array_len_to_const` in `FnCtxt` adds a `WellFormed` goal for the created `Const` which is also checked by the added `WellFormed(array_ty)`. I don't want to change this to just emit a `T: Sized` goal for the element type since that would ignore `ConstArgHasType` wf requirements and generally uncomfortable with the idea of trying to sync up `wf::obligations` for arrays and the code in hir typeck for repeat exprs.

r? `@compiler-errors`
2023-05-04 19:18:21 +02:00
Matthias Krüger
0ac8ebdf11
Rollup merge of #110826 - cjgillot:place-mention-use, r=JakobDegen,lcnr
Make PlaceMention a non-mutating use.

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

r? `@JakobDegen`

I don't agree with your statement in https://github.com/rust-lang/rust/issues/110781#issuecomment-1520841434. I suggest that we start fixing `PlaceContext` to be accurate enough for optimizations to use it. This structure is very convenient to use in visitors, and we perhaps have an opportunity to make it less of a footgun.
2023-05-04 19:18:19 +02:00
bors
eac35583d2 Auto merge of #111174 - matthiaskrgr:rollup-ncnqivh, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #110859 (Explicitly reject negative and reservation drop impls)
 - #111020 (Validate resolution for SelfCtor too.)
 - #111024 (Use the full Fingerprint when stringifying Svh)
 - #111027 (Remove `allow(rustc::potential_query_instability)` for `builtin_macros`)
 - #111039 (Encode def span for foreign return-position `impl Trait` in trait)
 - #111070 (Don't suffix `RibKind` variants)
 - #111094 (Add needs-unwind annotations to tests that need stack unwinding)
 - #111103 (correctly recurse when expanding anon consts)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-04 13:44:38 +00:00
Boxy
7d9130f3b9 do not allow rustc::pass_by_value lint 2023-05-04 11:22:40 +01:00
Boxy
c04106f9f1 check array type of repeat exprs is wf 2023-05-04 11:22:40 +01:00
Matthias Krüger
b4d992fec7
Rollup merge of #111103 - BoxyUwU:normal_fold_with_gce_norm, r=compiler-errors
correctly recurse when expanding anon consts

recursing with `super_fold_with` is wrong in case `bac` is itself normalizable, the test that was supposed to test for this being wrong did not actually test for this in reality because of the usage of `{ (N) }` instead of `{{ N }}`. The former resulting in a simple `ConstKind::Param` instead of `ConstKind::Unevaluated`. Tbh generally this test seems very brittle and it will be a lot easier to test once we have normalization of assoc consts since then we can just test that `T::ASSOC` normalizes to some `U::OTHER` which normalizes to some third thing.

r? `@compiler-errors`
2023-05-04 08:09:07 +02:00
Matthias Krüger
6fca1a9259
Rollup merge of #110859 - compiler-errors:no-negative-drop-impls, r=oli-obk
Explicitly reject negative and reservation drop impls

Fixes #110858

It doesn't really make sense for a type to have a `!Drop` impl. Or at least, I don't want us to implicitly assign a meaning to it by the way the compiler *currently* handles it (incompletely), and rather I would like to see a PR (or an RFC...) assign a meaning to `!Drop` if we actually wanted one for it.
2023-05-04 08:09:03 +02:00
bors
6f8c0557e0 Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnr
Replace `tcx.mk_trait_ref` with `TraitRef::new`

First step in implementing https://github.com/rust-lang/compiler-team/issues/616
r? `@lcnr`
2023-05-04 05:54:09 +00:00
Nicholas Nethercote
6b70be2a34 Remove unneeded encode/decode methods.
In #110927 the encode/decode methods for `i8`, `char`, `bool`, and `str`
were made inherent. This commit removes some unnecessary implementations
of these methods that were missed in that PR.
2023-05-04 13:11:52 +10:00
Nicholas Nethercote
58002faca0 Reorder some MemDecoder methods.
So they match the order in the `Decoder` trait.
2023-05-04 13:11:51 +10:00
Manish Goregaokar
48c78248a3
Rollup merge of #111146 - petrochenkov:decident, r=compiler-errors
rustc_middle: Fix `opt_item_ident` for non-local def ids

Noticed while working on https://github.com/rust-lang/rust/pull/110855.
2023-05-03 16:42:51 -07:00
Manish Goregaokar
38bbc39895
Rollup merge of #105452 - rcvalle:rust-cfi-3, r=bjorn3
Add cross-language LLVM CFI support to the Rust compiler

This PR adds cross-language LLVM Control Flow Integrity (CFI) support to the Rust compiler by adding the `-Zsanitizer-cfi-normalize-integers` option to be used with Clang `-fsanitize-cfi-icall-normalize-integers` for normalizing integer types (see https://reviews.llvm.org/D139395).

It provides forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space). For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler, see design document in the tracking issue #89653.

Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and -Zsanitizer-cfi-normalize-integers, and requires proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto).

Thank you again, ``@bjorn3,`` ``@nikic,`` ``@samitolvanen,`` and the Rust community for all the help!
2023-05-03 16:42:48 -07:00
Ramon de C Valle
004aa15b47 Add cross-language LLVM CFI support to the Rust compiler
This commit adds cross-language LLVM Control Flow Integrity (CFI)
support to the Rust compiler by adding the
`-Zsanitizer-cfi-normalize-integers` option to be used with Clang
`-fsanitize-cfi-icall-normalize-integers` for normalizing integer types
(see https://reviews.llvm.org/D139395).

It provides forward-edge control flow protection for C or C++ and Rust
-compiled code "mixed binaries" (i.e., for when C or C++ and Rust
-compiled code share the same virtual address space). For more
information about LLVM CFI and cross-language LLVM CFI support for the
Rust compiler, see design document in the tracking issue #89653.

Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and
-Zsanitizer-cfi-normalize-integers, and requires proper (i.e.,
non-rustc) LTO (i.e., -Clinker-plugin-lto).
2023-05-03 22:41:29 +00:00
Dylan DPC
e87fcf979f
Rollup merge of #111097 - oli-obk:🚲_layout, r=compiler-errors
Avoid ICEing miri on layout query cycles

Miri has special logic for catching panics during interpretation. Raising a fatal error in rustc uses unwinding to abort compilation. Thus miri ends up catching that fatal error and thinks it saw an ICE. While we should probably change that to ignore `Fatal` payloads, I think it's also neat to continue compilation after a layout query cycle 😆

Query cycles now (in addition to reporting an error just like before), return `Err(Cycle)` instead of raising a fatal error. This allows the interpreter to wind down via the regular error paths.

r? `@RalfJung` for a first round, feel free to reroll for the compiler team once the miri side looks good
2023-05-04 00:17:27 +05:30
Dylan DPC
8b7080b15b
Rollup merge of #110943 - RalfJung:interpret-unsized-arg-ice, r=oli-obk
interpret: fail more gracefully on uninit unsized locals

r? `@oli-obk`

Fixes https://github.com/rust-lang/rust/issues/68538
2023-05-04 00:17:25 +05:30
Dylan DPC
0228994cdf
Rollup merge of #110908 - petrochenkov:notagain4, r=compiler-errors
resolve: One more attempt to simplify `module_children`

If the next step is performed and `fn module_children_local` is merged with the `module_children` query, then it causes perf regressions, regardless of whether query result feeding is [used](https://perf.rust-lang.org/compare.html?start=43a78029b4f4d92978b8fde0a677ea300b113c41&end=2eb5bcc5068b9d92f74bcb1797da664865d6981d&stat=instructions:u) or [not](https://perf.rust-lang.org/compare.html?start=2fce2290865f012391b8f3e581c3852a248031fa&end=2a33d6cd99481d1712037a79e7d66a8aefadbf72&stat=instructions:u).
2023-05-04 00:17:24 +05:30
Dylan DPC
80df4ab403
Rollup merge of #110791 - compiler-errors:negative-bounds, r=oli-obk
Implement negative bounds for internal testing purposes

Implements partial support the `!` negative polarity on trait bounds. This is incomplete, but should allow us to at least be able to play with the feature.

Not even gonna consider them as a public-facing feature, but I'm implementing them because would've been nice to have in UI tests, for example in #110671.
2023-05-04 00:17:23 +05:30
Vadim Petrochenkov
6f6c379ee0 rustc_middle: Fix opt_item_ident for non-local def ids 2023-05-03 20:09:10 +03:00
Nicholas Nethercote
6b62f37402 Restrict From<S> for {D,Subd}iagnosticMessage.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.

This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.

As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.
2023-05-03 08:44:39 +10:00
Michael Goulet
6e01e910cb Implement negative bounds 2023-05-02 22:36:24 +00:00
bors
a368898de7 Auto merge of #111028 - compiler-errors:attr-query-no-caching, r=cjgillot
Make some simple queries no longer cache on disk

I don't think we need to cache queries with really simple local providers, like loading hir and accessing an attr

r? `@ghost`
2023-05-02 17:49:39 +00:00
Boxy
4d0887e1a2 correctly recurse when expanding anon consts 2023-05-02 18:42:55 +01:00
Oli Scherer
7bc6d598f9 Avoid ICEing miri on layout query cycles 2023-05-02 16:14:20 +00:00
Vadim Petrochenkov
ef77dd232d resolve: One more attempt to simplify module_children 2023-05-02 17:21:08 +03:00
Ben Kimock
f08f903fa9 Box AssertKind 2023-05-01 23:12:41 -04:00
bors
4b87ed9d0f Auto merge of #111026 - compiler-errors:only-typeck-root, r=cjgillot
Only cache typeck results if it's the typeck root

context: https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/incr_comp_query_cache_promotion.20taking.20forever

Basically, typeck children just copy the typeck results of their typeck root item, so caching their results means copying the same typeck results for each child item.

r? `@ghost`
2023-05-01 06:58:49 +00:00
Michael Goulet
37f7db87b0 Make some simple queries no longer cache on disk 2023-05-01 05:08:28 +00:00
Matthias Krüger
1b262b8b56
Rollup merge of #110823 - compiler-errors:tweak-await-span, r=b-naber
Tweak await span to not contain dot

Fixes a discrepancy between method calls and await expressions where the latter are desugared to have a span that *contains* the dot (i.e. `.await`) but method call identifiers don't contain the dot. This leads to weird suggestions suggestions in borrowck -- see linked issue.

Fixes #110761

This mostly touches a bunch of tests to tighten their `await` span.
2023-05-01 01:09:47 +02:00
Michael Goulet
938e807816 Only cache typeck results if it's the typeck root 2023-04-30 19:36:59 +00:00
bors
f5adff6bd8 Auto merge of #109611 - Zoxc:query-engine-rem, r=cjgillot
Remove `QueryEngine` trait

This removes the `QueryEngine` trait and `Queries` from `rustc_query_impl` and replaced them with function pointers and fields in `QuerySystem`. As a side effect `OnDiskCache` is moved back into `rustc_middle` and the `OnDiskCache` trait is also removed.

This has a couple of benefits.
- `TyCtxt` is used in the query system instead of the removed `QueryCtxt` which is larger.
- Function pointers are more flexible to work with. A variant of https://github.com/rust-lang/rust/pull/107802 is included which avoids the double indirection. For https://github.com/rust-lang/rust/pull/108938 we can name entry point `__rust_end_short_backtrace` to avoid some overhead. For https://github.com/rust-lang/rust/pull/108062 it avoids the duplicate `QueryEngine` structs.
- `QueryContext` now implements `DepContext` which avoids many `dep_context()` calls in `rustc_query_system`.
- The `rustc_driver` size is reduced by 0.33%, hopefully that means some bootstrap improvements.
- This avoids the unsafe code around the `QueryEngine` trait.

r? `@cjgillot`
2023-04-29 21:58:13 +00:00
Camille GILLOT
4ec76df4a9 Expand comment on NonMutatingUseContext. 2023-04-29 16:16:41 +00:00
Camille GILLOT
9325a254f0 Make PlaceMention a non-mutating use. 2023-04-29 16:14:33 +00:00
Matthias Krüger
37076ebbe5
Rollup merge of #110927 - nnethercote:Encoder-Decoder-cleanups, r=scottmcm
Encoder/decoder cleanups

Best reviewed one commit at a time.

r? ``@scottmcm``
2023-04-28 22:56:45 +02:00
Ralf Jung
25e9b79060 interpret: fail more gracefully on uninit unsized locals 2023-04-28 14:42:03 +02:00
Nicholas Nethercote
23e91d4d73 Remove some unnecessary derives.
I was curious about how many `Encodable`/`Decodable` derives we have.
Some grepping revealed that it's over 500 of each, but the number of
`Encodable` ones was higher, which was weird. Most of the
`Encodable`-only ones were in `hir.rs`. This commit removes them all,
plus some other unnecessary derives in that file and others that I found
via trial and error.
2023-04-28 18:34:55 +10:00
Matthias Krüger
57e9a4be48
Rollup merge of #110838 - nnethercote:more-Folder-Visitable-cleanups, r=lcnr
More `Typefoldable`/`TypeVisitable` cleanups

r? ``@lcnr``
2023-04-27 21:34:14 +02:00
Michael Goulet
6c9249f689 Don't call await a method 2023-04-27 17:18:12 +00:00
Michael Goulet
bd146c72ac Explicitly reject negative and reservation drop impls 2023-04-27 17:02:17 +00:00
Boxy
842419712a rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
Boxy
f04b8fe0af rename needs_infer to has_infer 2023-04-27 08:35:19 +01:00
Matthias Krüger
e47562c674
Rollup merge of #110835 - nnethercote:strict-region-folders-2, r=compiler-errors
Make some region folders a little stricter.

Because certain regions cannot occur in them.

r? ``@compiler-errors``
2023-04-26 18:51:44 +02:00
Maybe Waffle
39b95c965a Don't return a Binder from TraitRef::identity 2023-04-26 11:59:51 +00:00
Maybe Waffle
1b8c7784e5 Add new ToPredicate impls and TraitRef methods to remove some ty::Binber::dummy calls 2023-04-26 11:48:17 +00:00
Maybe Waffle
4f2532fb53 Switch ty::TraitRef::from_lang_item from using TyCtxtAt to TyCtxt and a Span 2023-04-26 10:55:11 +00:00
John Kåre Alsaker
b6943736bd Inline tweaks 2023-04-26 07:47:37 +02:00
John Kåre Alsaker
4440e8196a Add query accessor functions 2023-04-26 07:46:14 +02:00
John Kåre Alsaker
66d85438ca Remove QueryEngine trait 2023-04-26 07:46:13 +02:00
John Kåre Alsaker
897a146006 Move on_disk_cache.rs 2023-04-26 07:46:13 +02:00
Nicholas Nethercote
a82ad2fed4 Derive Type{Foldable,Visitable} for UserTypeProjection.
Because the derived versions are good enough.
2023-04-26 15:19:51 +10:00