Commit Graph

19310 Commits

Author SHA1 Message Date
Matthias Krüger
80dc91c6c3
Rollup merge of #104514 - chenyukang:yukang/fix-104513-ice, r=petrochenkov
Use node_ty_opt to avoid ICE in visit_ty

Fixes #104513
2022-11-24 21:34:51 +01:00
bors
5dfb4b0afa Auto merge of #104321 - Swatinem:async-gen, r=oli-obk
Avoid `GenFuture` shim when compiling async constructs

Previously, async constructs would be lowered to "normal" generators, with an additional `from_generator` / `GenFuture` shim in between to convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that async constructs will *directly* implement `Future` without the need to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation detail in stack traces and debuginfo, but it can in theory also help the optimizer as there is less abstractions to see through.

---

Given this demo code:

```rust
pub async fn a(arg: u32) -> Backtrace {
    let bt = b().await;
    let _arg = arg;
    bt
}

pub async fn b() -> Backtrace {
    Backtrace::force_capture()
}
```

I would get the following with the latest stable compiler (on Windows):

```
   4: async_codegen:🅱️:async_fn$0
             at .\src\lib.rs:10
   5: core::future::from_generator::impl$1::poll<enum2$<async_codegen:🅱️:async_fn_env$0> >
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\mod.rs:91
   6: async_codegen:🅰️:async_fn$0
             at .\src\lib.rs:4
   7: core::future::from_generator::impl$1::poll<enum2$<async_codegen:🅰️:async_fn_env$0> >
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\mod.rs:91
```

whereas now I get a much cleaner stack trace:

```
   3: async_codegen:🅱️:async_fn$0
             at .\src\lib.rs:10
   4: async_codegen:🅰️:async_fn$0
             at .\src\lib.rs:4
```
2022-11-24 17:14:42 +00:00
bors
1dda298ad3 Auto merge of #104809 - matthiaskrgr:rollup-8abjdwh, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #103908 (Suggest `.clone()` or `ref binding` on E0382)
 - #104517 (Throw error on failure in loading llvm-plugin)
 - #104594 (Properly handle `Pin<&mut dyn* Trait>` receiver in codegen)
 - #104742 (Make `deref_into_dyn_supertrait` lint the impl and not the usage)
 - #104753 (Pass `InferCtxt` to `DropRangeVisitor` so we can resolve vars)
 - #104771 (Add regression test for issue #99938)
 - #104772 (Small accessibility improvements)
 - #104775 (Use ObligationCtxt::normalize)
 - #104778 (⬆️ rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-24 09:44:46 +00:00
Arpad Borsos
9f36f988ad
Avoid GenFuture shim when compiling async constructs
Previously, async constructs would be lowered to "normal" generators,
with an additional `from_generator` / `GenFuture` shim in between to
convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that
async constructs will *directly* implement `Future` without the need
to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation
detail in stack traces and debuginfo, but it can in theory also help
the optimizer as there is less abstractions to see through.
2022-11-24 10:04:27 +01:00
Matthias Krüger
2190b163a3
Rollup merge of #104775 - spastorino:use-obligation-ctxt-normalize, r=lcnr
Use ObligationCtxt::normalize

r? ```@lcnr```
2022-11-24 08:42:37 +01:00
Matthias Krüger
6938717ca5
Rollup merge of #104753 - compiler-errors:drop-tracking-var-ice, r=oli-obk
Pass `InferCtxt` to `DropRangeVisitor` so we can resolve vars

The types that we encounter in the  `TypeckResults` that we pass to the `DropRangeVisitor` are not yet fully resolved, since that only happens in writeback after type checking is complete.

Instead, pass down the whole `InferCtxt` so that we can resolve any inference vars that have been constrained since they were written into the results. This is similar to how the `MemCategorizationContext` in the `ExprUseVisitor` also needs to pass down both typeck results _and_ the inference context.

Fixes an ICE mentioned in this comment: https://github.com/rust-lang/rust/issues/104382#issuecomment-1324410781
2022-11-24 08:42:35 +01:00
Matthias Krüger
c08c57e856
Rollup merge of #104742 - WaffleLapkin:forbidden-SUPER-deref, r=compiler-errors
Make `deref_into_dyn_supertrait` lint the impl and not the usage

Proposed by ``@compiler-errors`` in https://github.com/rust-lang/rust/issues/89460#issuecomment-1320806785
r? ``@crlf0710``
2022-11-24 08:42:34 +01:00
Matthias Krüger
b43c2e7cd9
Rollup merge of #104594 - compiler-errors:dyn-star-rcvr, r=eholk,estebank
Properly handle `Pin<&mut dyn* Trait>` receiver in codegen

This ensures we can actually await a `dyn* Future`, which seems important for async fn in dyn trait.

Also, disable `dyn*` trait upcasting. It's not exactly complete right now, and can cause strange ICEs for no reason -- nobody's using it either. I thought it was cute to implement when I did it, but I didn't think about how it interacts structurally with `CoerceUnsized` correctly.

Fixes #104794, presumably removing `dyn*` upcasting and its `CoerceUnsized` issues does the trick.
2022-11-24 08:42:34 +01:00
Matthias Krüger
1e0df8827b
Rollup merge of #104517 - dfordivam:patch-1, r=cuviper
Throw error on failure in loading llvm-plugin

The following code silently ignores the error as the `LLVMRustSetLastError` only tracks one error at a time. At all other places where `LLVMRustSetLastError` is used the code immediately returns.

251831ece9/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp (L801-L804)
2022-11-24 08:42:33 +01:00
Matthias Krüger
5197ef66b7
Rollup merge of #103908 - estebank:consider-cloning, r=compiler-errors
Suggest `.clone()` or `ref binding` on E0382
2022-11-24 08:42:33 +01:00
bors
341d8b8a2c Auto merge of #103808 - cjgillot:vec-cache, r=TaKO8Ki
Use an IndexVec to cache queries with index-like key

Revival of an old idea. Let's see if it has more effect.

r? `@ghost`
2022-11-24 06:32:23 +00:00
yukang
ecea94e6a4 fix #104513, Use node_ty_opt to avoid ICE in visit_ty 2022-11-24 13:02:00 +08:00
bors
fd815a5091 Auto merge of #104610 - ouz-a:revert-overflow, r=compiler-errors
Reverts check done by #100757

As my `fix` caused more issues than it resolved it's better to revert it.
( #103274 #104322 https://github.com/rust-lang/rust/issues/104606)

r? `@compiler-errors`

Reopens #95134
2022-11-24 03:29:04 +00:00
Michael Goulet
8f79fc24e3 Properly handle Pin<&mut dyn* Trait> receiver in codegen 2022-11-24 01:10:25 +00:00
Michael Goulet
c620a972f3 Disable dyn* upcasting 2022-11-24 01:10:24 +00:00
bors
872631d0f0 Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiser
Use `as_deref` in compiler (but only where it makes sense)

This simplifies some code :3

(there are some changes that are not exacly `as_deref`, but more like "clever `Option`/`Result` method use")
2022-11-24 00:17:35 +00:00
Esteban Küber
78b8d126db Fix rebase 2022-11-23 13:06:27 -08:00
Esteban Küber
0da4c44190 Account for closures 2022-11-23 12:17:48 -08:00
Esteban Küber
3a471b5fd8 Account for x @ y and suggest ref x @ ref y 2022-11-23 12:17:48 -08:00
Esteban Küber
3c905d4ccd review comments: inline bindings and fix typo 2022-11-23 12:17:48 -08:00
Esteban Küber
5993f5d0f8 Tweak output to account for alternative bindings in the same pattern 2022-11-23 12:17:47 -08:00
Esteban Küber
e6e7a6db28 Fix wording 2022-11-23 12:17:47 -08:00
Esteban Küber
d687d46f68 Tweak output in for loops
Do not suggest `.clone()` as we already suggest borrowing the iterated
value.
2022-11-23 12:17:47 -08:00
Esteban Küber
c0e481731b Remove logic duplication 2022-11-23 12:17:47 -08:00
Esteban Küber
42d7174bbc Extract suggestion logic to its own method 2022-11-23 12:17:47 -08:00
Esteban Küber
14a3d572e6 Use type_implements_trait 2022-11-23 12:17:47 -08:00
Esteban Küber
4a51f37bcb Do not suggest ref multiple times for the same binding 2022-11-23 12:17:47 -08:00
Esteban Küber
9e72e35ceb Suggest .clone() or ref binding on E0382 2022-11-23 12:17:47 -08:00
bors
70f8737b2f Auto merge of #104410 - WaffleLapkin:unregress, r=estebank
Fix perf regression by correctly matching keywords

This should (hopefully) fix regression from #99918

r? `@estebank`
2022-11-23 19:52:43 +00:00
bors
d121aa3b55 Auto merge of #104776 - Dylan-DPC:rollup-rf4c2u0, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #104269 (Fix hang in where-clause suggestion with `predicate_can_apply`)
 - #104286 (copy doc output files by format)
 - #104509 (Use obligation ctxt instead of dyn TraitEngine)
 - #104721 (Remove more `ref` patterns from the compiler)
 - #104744 (rustdoc: give struct fields CSS `display: block`)
 - #104751 (Fix an ICE parsing a malformed attribute.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-23 16:29:17 +00:00
Maybe Waffle
20f3de5ab1 Use nicer spans for deref_into_dyn_supertrait 2022-11-23 16:12:51 +00:00
Maybe Waffle
0d4a5c725a Make deref_into_dyn_supertrait lint the impl and not the usage 2022-11-23 15:40:27 +00:00
Maybe Waffle
11a5386256 Move get_associated_type from clippy to rustc_lint 2022-11-23 15:40:27 +00:00
Dylan DPC
5d7b68c82b
Rollup merge of #104751 - nnethercote:fix-104620, r=petrochenkov
Fix an ICE parsing a malformed attribute.

Fixes #104620.

r? `@petrochenkov`
2022-11-23 20:32:38 +05:30
Dylan DPC
c03026a7c6
Rollup merge of #104721 - WaffleLapkin:deref-harder, r=oli-obk
Remove more `ref` patterns from the compiler

r? `@oli-obk`
Previous PR: https://github.com/rust-lang/rust/pull/104500
2022-11-23 20:32:37 +05:30
Dylan DPC
0a791381c3
Rollup merge of #104509 - spastorino:use-obligation-ctxt, r=lcnr
Use obligation ctxt instead of dyn TraitEngine

r? `@lcnr`
2022-11-23 20:32:36 +05:30
Dylan DPC
bd91c94a5d
Rollup merge of #104269 - compiler-errors:hang-in-where-clause-sugg, r=lcnr
Fix hang in where-clause suggestion with `predicate_can_apply`

Using `predicate_may_hold` during error reporting causes an evaluation overflow, which (because we use `evaluate_obligation_no_overflow`) then causes the predicate to need to be re-evaluated locally, which results in a hang.

... but since the "add a where clause" suggestion is best-effort, just throw any overflow errors. No need for 100% accuracy.

r? `@lcnr` who has been thinking about overflows... Let me know if you want more context about this issue, and as always, feel free to reassign.

Fixes #104225
2022-11-23 20:32:35 +05:30
Santiago Pastorino
409203a315
Use ObligationCtxt::normalize 2022-11-23 11:32:49 -03:00
bors
80b3c6dbde Auto merge of #103947 - camsteffen:place-clones, r=cjgillot
Reduce `PlaceBuilder` cloning

Some API tweaks with an eye towards reducing clones.
2022-11-23 13:13:50 +00:00
Santiago Pastorino
859b147d4f
Pass ObligationCtxt from enter_canonical_trait_query and use ObligationCtxt API 2022-11-23 09:36:03 -03:00
Santiago Pastorino
5b3a06a3c2
Call fully_solve_obligations instead of repeating code 2022-11-23 09:36:00 -03:00
Santiago Pastorino
ad094cdceb
Use ObligationCtxt intead of dyn TraitEngine 2022-11-23 09:24:42 -03:00
bors
4e0d0d757e Auto merge of #102750 - the8472:opt-field-order, r=wesleywiser
optimize field ordering by grouping m*2^n-sized fields with equivalently aligned ones

```rust
use std::ptr::addr_of;
use std::mem;

struct Foo {
    word: u32,
    byte: u8,
    ary: [u8; 4]
}

fn main() {
    let foo: Foo = unsafe { mem::zeroed() };

    println!("base: {:p}\nword: {:p}\nbyte: {:p}\nary:  {:p}", &foo, addr_of!(foo.word), addr_of!(foo.byte), addr_of!(foo.ary));
}
```

prints

```
base: 0x7fffc1a8a668
word: 0x7fffc1a8a668
byte: 0x7fffc1a8a66c
ary:  0x7fffc1a8a66d
```

I.e. the `u8` in the middle causes the array to sit at an odd offset, which might prevent optimizations, especially on architectures where unaligned loads are costly.

Note that this will make field ordering niche-dependent, i.e. a `Bar<T>` with `T=char` and `T=u32` may result in different field order, this may break some code that makes invalid assumptions about `repr(Rust)` types.
2022-11-23 10:01:48 +00:00
Michael Goulet
a884a9e634 Drive-by: Don't manually call evaluate_obligation_no_overflow 2022-11-23 04:42:38 +00:00
Michael Goulet
cbe9328018 Do not need to account for overflow in predicate_can_apply 2022-11-23 04:42:38 +00:00
Manish Goregaokar
54b6292855
Rollup merge of #104621 - YC:master, r=davidtwco
Fix --extern library finding errors

- `crate_name` is not specified/passed to `metadata_crate_location_unknown_type`
c493bae0d8/compiler/rustc_error_messages/locales/en-US/metadata.ftl (L274-L275)
- `metadata_lib_filename_form` is missing `$`
- Add additional check to ensure that library is file

Testing
1. Create file `a.rs`
```rust
extern crate t;
fn main() {}
```
1. Create empty file `x`
1. Create empty directory `y`
1. Run
```sh
$ rustc -o a a.rs --extern t=x
$ rustc -o a a.rs --extern t=y
```
Both currently panic with stable.
2022-11-22 22:54:40 -05:00
Manish Goregaokar
36815c6e3b
Rollup merge of #104612 - Swatinem:async-ret-y, r=estebank
Lower return type outside async block creation

This allows feeding a different output type to async blocks with a different `ImplTraitContext`. Spotted this while working on #104321
2022-11-22 22:54:39 -05:00
Manish Goregaokar
a673364c54
Rollup merge of #104359 - Nilstrieb:plus-one, r=fee1-dead
Refactor must_use lint into two parts

Before, the lint did the checking for `must_use` and pretty printing the types in a special format in one pass, causing quite complex and untranslatable code.
Now the collection and printing is split in two. That should also make it easier to translate or extract the type pretty printing in the future.

Also fixes an integer overflow in the array length pluralization
calculation.

fixes #104352
2022-11-22 22:54:39 -05:00
Manish Goregaokar
53eab246db
Rollup merge of #103488 - oli-obk:impl_trait_for_tait, r=lcnr
Allow opaque types in trait impl headers and rely on coherence to reject unsound cases

r? ````@lcnr````

fixes #99840
2022-11-22 22:54:38 -05:00
Michael Goulet
024bb8c7fb Pass ParamEnv down instead of using ParamEnv of a module 2022-11-23 02:06:03 +00:00