Commit Graph

216925 Commits

Author SHA1 Message Date
kadmin 3e97cef7e5 Set mir-opt-level = 0 on some codegen tests
Since we're changing a bunch of stuff, necessary to remove some codegen tests
which look for specific things. Also attempting to restart a test which timed out, maybe due to
fastly failing?
2023-02-07 09:37:55 +00:00
kadmin f7cbf2eb41 Update with comments
Changing a bunch of struct constructors to `from`, no extra destructuring,
getting the type of the discriminant.
2023-02-07 09:37:55 +00:00
kadmin 33b4d20338 Clean up MIR transform 2023-02-07 09:37:55 +00:00
kadmin 96db5e9c7b Add comments
Still need to make it so that it maps discriminants to variant indexes.
Maybe instead I can map the variant indexes to discriminants?
2023-02-07 09:37:55 +00:00
kadmin 18144b66e1 Create initial version of opt 2023-02-07 09:37:55 +00:00
Arpad Borsos 7a7b2e3521
Add test for Future inflating arg size to 3x
This adds one more test that should track improvements to generator
layout, like #62958 and #62575.

In particular, this test highlights suboptimal layout, as the storage
for the argument future is not being reused across its usage as `upvar`,
`local` and `awaitee` (being polled to completion).
2023-02-07 08:52:15 +01:00
Rafael Rivera c825e08571 Specify dlltool prefix when generating import libs 2023-02-06 21:17:06 -08:00
bors dffea43fc1 Auto merge of #106180 - RalfJung:dereferenceable-generators, r=nbdd0121
make &mut !Unpin not dereferenceable, and Box<!Unpin> not noalias

See https://github.com/rust-lang/unsafe-code-guidelines/issues/381 and [this LLVM discussion](https://discourse.llvm.org/t/interaction-of-noalias-and-dereferenceable/66979). The exact semantics of how `noalias` and `dereferenceable` interact are unclear, and `@comex` found a case of LLVM actually exploiting that ambiguity for optimizations. I think for now we should treat LLVM `dereferenceable` as implying a "fake read" to happen immediately at the top of the function (standing in for the spurious reads that LLVM might introduce), and that fake read is subject to all the usual `noalias` restrictions. This means we cannot put `dereferenceable` on `&mut !Unpin` references as those references can alias with other references that are being read and written inside the function (e.g. for self-referential generators), meaning the fake read introduces aliasing conflicts with those other accesses.

For `&` this is already not a problem due to https://github.com/rust-lang/rust/pull/98017 which removed the `dereferenceable` attribute for other reasons.

Regular `&mut Unpin` references are unaffected, so I hope the impact of this is going to be tiny.

The first commit does some refactoring of the `PointerKind` enum since I found the old code very confusing each time I had to touch it. It doesn't change behavior.

Fixes https://github.com/rust-lang/miri/issues/2714

EDIT: Turns out our `Box<!Unpin>` treatment was incorrect, too, so the PR also fixes that now (in codegen and Miri): we do not put `noalias` on these boxes any more.
2023-02-07 03:35:10 +00:00
Tshepang Mbambo a002c05726 make more readable 2023-02-07 04:54:01 +02:00
Tshepang Mbambo 63dc0b86be allow quick-edit convenience 2023-02-07 04:41:13 +02:00
Nathan Fenner 4c053668d6 Split fn_ctxt/adjust_fulfillment_errors from fn_ctxt/checks 2023-02-06 17:24:25 -08:00
bors 35d6d70a64 Auto merge of #107693 - petrochenkov:metable, r=oli-obk
rustc_metadata: Encode/decode some `LazyArrays` without an `Option`

and a couple of related changes, see individual commits.

Addresses comments in https://github.com/rust-lang/rust/pull/107166#discussion_r1083417124 and https://github.com/rust-lang/rust/pull/107166#discussion_r1083768417, cc `@cjgillot` `@oli-obk.`
2023-02-07 00:03:02 +00:00
Nick Lamb 747cdc0dfd Fix problem noticed in PR106859 with char -> u8 suggestion 2023-02-06 21:48:10 +00:00
Nicholas Nethercote 1dbed69465 Optimize `TyKind::eq`. 2023-02-07 08:21:19 +11:00
Oli Scherer 0ddf249532 Avoid locking the global context across the `after_expansion` callback 2023-02-06 21:11:03 +00:00
bors e1eaa2d5d4 Auto merge of #107738 - matthiaskrgr:rollup-o18lzi8, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #106477 (Refine error spans for "The trait bound `T: Trait` is not satisfied" when passing literal structs/tuples)
 - #107596 (Add nicer output to PGO build timer)
 - #107692 (Sort Generator `print-type-sizes` according to their yield points)
 - #107714 (Clarify wording on f64::round() and f32::round())
 - #107720 (end entry paragraph with a period (.))
 - #107724 (remove unused rustc_* imports)
 - #107725 (Turn MarkdownWithToc into a struct with named fields)
 - #107731 (interpret: move discriminant reading and writing to separate file)
 - #107735 (Add mailmap for commits made by xes@meta.com)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-06 20:20:53 +00:00
Matthias Krüger 5e958293e3
Rollup merge of #107735 - edward-shen:edward-shen/mailmap, r=dtolnay
Add mailmap for commits made by xes@meta.com

Saw my contributions split at https://thanks.rust-lang.org/rust/1.69.0/

I assume it's because I committed with my work and personal email?
2023-02-06 21:16:43 +01:00
Matthias Krüger 2bb7260058
Rollup merge of #107731 - RalfJung:interpret-discriminant, r=cjgillot
interpret: move discriminant reading and writing to separate file

This is quite different from the otherwise fairly general read and write functions in place.rs and operand.rs, and also it's nice to have these two functions close together as they are basically inverses of each other.
2023-02-06 21:16:43 +01:00
Matthias Krüger 4e163af1e5
Rollup merge of #107725 - GuillaumeGomez:turn-markdownwithtoc-into-struct, r=notriddle
Turn MarkdownWithToc into a struct with named fields

Extracted the commit from https://github.com/rust-lang/rust/pull/107640.

r? `@notriddle`
2023-02-06 21:16:42 +01:00
Matthias Krüger 7be6e6d954
Rollup merge of #107724 - klensy:imports, r=Mark-Simulacrum
remove unused rustc_* imports
2023-02-06 21:16:42 +01:00
Matthias Krüger 7343f748cb
Rollup merge of #107720 - tshepang:consistency, r=Mark-Simulacrum
end entry paragraph with a period (.)
2023-02-06 21:16:42 +01:00
Matthias Krüger 7c4e6edb05
Rollup merge of #107714 - Wilfred:round_docs, r=m-ou-se
Clarify wording on f64::round() and f32::round()

"Round half-way cases" is a little confusing (it's a 'garden path sentence' as it's not immediately clear whether round is an adjective or verb).

Make this sentence longer and clearer.
2023-02-06 21:16:41 +01:00
Matthias Krüger a5288a7803
Rollup merge of #107692 - Swatinem:printsizeyield, r=compiler-errors
Sort Generator `print-type-sizes` according to their yield points

Especially when trying to diagnose runaway future sizes, it might be more intuitive to sort the variants according to the control flow (aka their yield points) rather than the size of the variants.
2023-02-06 21:16:41 +01:00
Matthias Krüger 64db7fb115
Rollup merge of #107596 - Kobzol:stage-build-timer, r=Mark-Simulacrum
Add nicer output to PGO build timer

This PR modifies the timer used in the PGO build script to contain nicer, hierarchical output of the individual build steps. It's not trivial to test locally, so I'll fire up a dist build right away.

r? ``@Mark-Simulacrum``
2023-02-06 21:16:40 +01:00
Matthias Krüger 800221b5b8
Rollup merge of #106477 - Nathan-Fenner:nathanf/refined-error-span-trait-impl, r=compiler-errors
Refine error spans for "The trait bound `T: Trait` is not satisfied" when passing literal structs/tuples

This PR adds a new heuristic which refines the error span reported for "`T: Trait` is not satisfied" errors, by "drilling down" into individual fields of structs/enums/tuples to point to the "problematic" value.

Here's a self-contained example of the difference in error span:

```rs
struct Burrito<Filling> {
    filling: Filling,
}
impl <Filling: Delicious> Delicious for Burrito<Filling> {}
fn eat_delicious_food<Food: Delicious>(food: Food) {}
fn will_type_error() {
    eat_delicious_food(Burrito { filling: Kale });
    //                 ^~~~~~~~~~~~~~~~~~~~~~~~~ (before) The trait bound `Kale: Delicious` is not satisfied
    //                                    ^~~~   (after)  The trait bound `Kale: Delicious` is not satisfied
}
```
(kale is fine, this is just a silly food-based example)

Before this PR, the error span is identified as the entire argument to the generic function `eat_delicious_food`. However, since only `Kale` is the "problematic" part, we can point at it specifically. In particular, the primary error message itself mentions the missing `Kale: Delicious` trait bound, so it's much clearer if this part is called out explicitly.

---

The _existing_ heuristic tries to label the right function argument in `point_at_arg_if_possible`. It goes something like this:
- Look at the broken base trait `Food: Delicious` and find which generics it mentions (in this case, only `Food`)
- Look at the parameter type definitions and find which of them mention `Filling` (in this case, only `food`)
- If there is exactly one relevant parameter, label the corresponding argument with the error span, instead of the entire call

This PR extends this heuristic by further refining the resulting expression span in the new `point_at_specific_expr_if_possible` function. For each `impl` in the (broken) chain, we apply the following strategy:

The strategy to determine this span involves connecting information about our generic `impl`
with information about our (struct) type and the (struct) literal expression:
- Find the `impl` (`impl <Filling: Delicious> Delicious for Burrito<Filling>`)
  that links our obligation (`Kale: Delicious`) with the parent obligation (`Burrito<Kale>: Delicious`)
- Find the "original" predicate constraint in the impl (`Filling: Delicious`) which produced our obligation.
- Find all of the generics that are mentioned in the predicate (`Filling`).
- Examine the `Self` type in the `impl`, and see which of its type argument(s) mention any of those generics.
- Examing the definition for the `Self` type, and identify (for each of its variants) if there's a unique field
  which uses those generic arguments.
- If there is a unique field mentioning the "blameable" arguments, use that field for the error span.

Before we do any of this logic, we recursively call `point_at_specific_expr_if_possible` on the parent
obligation. Hence we refine the `expr` "outwards-in" and bail at the first kind of expression/impl we don't recognize.

This function returns a `Result<&Expr, &Expr>` - either way, it returns the `Expr` whose span should be
reported as an error. If it is `Ok`, then it means it refined successfull. If it is `Err`, then it may be
only a partial success - but it cannot be refined even further.

---

I added a new test file which exercises this new behavior. A few existing tests were affected, since their error spans are now different. In one case, this leads to a different code suggestion for the autofix - although the new suggestion isn't _wrong_, it is different from what used to be.

This change doesn't create any new errors or remove any existing ones, it just adjusts the spans where they're presented.

---

Some considerations: right now, this check occurs in addition to some similar logic in `adjust_fulfillment_error_for_expr_obligation` function, which tidies up various kinds of error spans (not just trait-fulfillment error). It's possible that this new code would be better integrated into that function (or another one) - but I haven't looked into this yet.

Although this code only occurs when there's a type error, it's definitely not as efficient as possible. In particular, there are definitely some cases where it degrades to quadratic performance (e.g. for a trait `impl` with 100+ generic parameters or 100 levels deep nesting of generic types). I'm not sure if these are realistic enough to worry about optimizing yet.

There's also still a lot of repetition in some of the logic, where the behavior for different types (namely, `struct` vs `enum` variant) is _similar_ but not the same.

---

I think the biggest win here is better targeting for tuples; in particular, if you're using tuples + traits to express variadic-like functions, the compiler can't tell you which part of a tuple has the wrong type, since the span will cover the entire argument. This change allows the individual field in the tuple to be highlighted, as in this example:

```
// NEW
LL |     want(Wrapper { value: (3, q) });
   |     ----                      ^ the trait `T3` is not implemented for `Q`

// OLD
LL |     want(Wrapper { value: (3, q) });
   |     ---- ^~~~~~~~~~~~~~~~~~~~~~~~~ the trait `T3` is not implemented for `Q`
```
Especially with large tuples, the existing error spans are not very effective at quickly narrowing down the source of the problem.
2023-02-06 21:16:39 +01:00
Edward Shen af5a37e844
Modify existing bounds if they exist 2023-02-06 11:26:36 -08:00
Edward Shen 2ba0ec8adf
Add mailmap for commits made by xes@meta.com 2023-02-06 10:35:40 -08:00
bjorn3 8494882773 Rustup to rustc 1.69.0-nightly (75a0be98f 2023-02-05) 2023-02-06 18:32:25 +01:00
Camille Gillot 9c5add14e7
Comment move->copy transform. 2023-02-06 18:14:24 +01:00
bjorn3 6dfa3c9513 Sync from rust 044a28a409 2023-02-06 18:03:15 +01:00
bors 7ff69b49df Auto merge of #107727 - Dylan-DPC:rollup-b1yexcl, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #107553 (Suggest std::ptr::null if literal 0 is given to a raw pointer function argument)
 - #107580 (Recover from lifetimes with default lifetimes in generic args)
 - #107669 (rustdoc: combine duplicate rules in ayu CSS)
 - #107685 (Suggest adding a return type for async functions)
 - #107687 (Adapt SROA MIR opt for aggregated MIR)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-06 16:28:18 +00:00
Ralf Jung e1926b2110 interpret: move discriminant reading and writing to separate file 2023-02-06 17:10:26 +01:00
Kartavya Vashishtha 2fc1693cd5
split suggestions into two separate suggestions 2023-02-06 21:34:35 +05:30
Guillaume Gomez 3b494a41d9 Turn MarkdownWithToc into a struct with named fields 2023-02-06 16:31:17 +01:00
clubby789 521c5f36d6 Migrate `rustc_parse` to derive diagnostics 2023-02-06 14:40:35 +00:00
klensy 4f5f9f0a13 remove unused imports 2023-02-06 17:40:18 +03:00
CastilloDel f0830c0ade Add `run-rustfix` to tests/ui/issues/issue-92741.rs 2023-02-06 15:34:47 +01:00
CastilloDel 039f70e926 Add more test cases to tests/ui/issues/issue-92741.rs 2023-02-06 15:30:29 +01:00
Dylan DPC e385ca25be
Rollup merge of #107687 - cjgillot:sroa-2, r=oli-obk
Adapt SROA MIR opt for aggregated MIR

The pass was broken by https://github.com/rust-lang/rust/pull/107267.

This PR extends it to replace:
```
x = Struct { 0: a, 1: b }
y = move? x
```

by assignment between locals
```
x_0 = a
x_1 = b
y_0 = move? x_0
y_1 = move? x_1
```

The improved pass runs to fixpoint, so we can flatten nested field accesses.
2023-02-06 19:54:15 +05:30
Dylan DPC 675976eb21
Rollup merge of #107685 - jieyouxu:issue-90027, r=compiler-errors
Suggest adding a return type for async functions

Fixes #90027.
2023-02-06 19:54:15 +05:30
Dylan DPC fc791cb209
Rollup merge of #107669 - notriddle:notriddle/ayu-smaller, r=GuillaumeGomez
rustdoc: combine duplicate rules in ayu CSS
2023-02-06 19:54:14 +05:30
Dylan DPC 8ddbfadda0
Rollup merge of #107580 - lenko-d:default_value_for_a_lifetime_generic_parameter_produces_confusing_diagnostic, r=compiler-errors
Recover from lifetimes with default lifetimes in generic args

Fixes [#107492](https://github.com/rust-lang/rust/issues/107492)
2023-02-06 19:54:14 +05:30
Dylan DPC 496adf81de
Rollup merge of #107553 - edward-shen:edward-shen/suggest-null-ptr, r=WaffleLapkin
Suggest std::ptr::null if literal 0 is given to a raw pointer function argument

Implementation feels a little sus (we're parsing the span for a `0`) but it seems to fall in line the string-expected-found-char condition right above this check, so I think it's fine.

Feedback appreciated on help text? I think it's consistent but it does sound a little awkward maybe?

Fixes #107517
2023-02-06 19:54:13 +05:30
John Kåre Alsaker 9539737008 Make an optimal cold path for query_cache_hit 2023-02-06 15:22:12 +01:00
bors 044a28a409 Auto merge of #103761 - chenyukang:yukang/fix-103320-must-use, r=compiler-errors
Add explanatory message for [#must_use] in ops

Fixes #103320
2023-02-06 12:57:37 +00:00
John Kåre Alsaker e60ccfc6a9 Don't inline query_cache_hit to reduce code size of the query hot path. 2023-02-06 13:52:17 +01:00
Matthew Kelly 2bcd4e256a Add extended error message for E0523
Adds the extended error documentation for E0523 to indicate that the
error is no longer produced by the compiler.

Update the E0464 documentation to include example code that produces the
error.

Remove the error message E0523 from the compiler and replace it with an
internal compiler error.
2023-02-06 06:58:30 -05:00
Ralf Jung 1ef16874b5 also do not add noalias on not-Unpin Box 2023-02-06 12:17:41 +01:00
Ralf Jung ea541bc2ee make &mut !Unpin not dereferenceable
See https://github.com/rust-lang/unsafe-code-guidelines/issues/381 for discussion.
2023-02-06 11:46:37 +01:00
Ralf Jung 201ae73872 make PointerKind directly reflect pointer types
The code that consumes PointerKind (`adjust_for_rust_scalar` in rustc_ty_utils)
ended up using PointerKind variants to talk about Rust reference types (& and
&mut) anyway, making the old code structure quite confusing: one always had to
keep in mind which PointerKind corresponds to which type. So this changes
PointerKind to directly reflect the type.

This does not change behavior.
2023-02-06 11:46:32 +01:00