bors [Thu, 24 Nov 2022 17:14:42 +0000 (17:14 +0000)]
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
}
I would get the following with the latest stable compiler (on Windows):
```
4: async_codegen::b::async_fn$0
at .\src\lib.rs:10
5: core::future::from_generator::impl$1::poll<enum2$<async_codegen::b::async_fn_env$0> >
at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\mod.rs:91
6: async_codegen::a::async_fn$0
at .\src\lib.rs:4
7: core::future::from_generator::impl$1::poll<enum2$<async_codegen::a::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::b::async_fn$0
at .\src\lib.rs:10
4: async_codegen::a::async_fn$0
at .\src\lib.rs:4
```
bors [Thu, 24 Nov 2022 09:44:46 +0000 (09:44 +0000)]
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 (:arrow_up: rust-analyzer)
Arpad Borsos [Fri, 18 Nov 2022 21:56:22 +0000 (22:56 +0100)]
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.
Matthias Krüger [Thu, 24 Nov 2022 07:42:36 +0000 (08:42 +0100)]
Rollup merge of #104772 - GuillaumeGomez:small-accessibility-improvement, r=notriddle
Small accessibility improvements
From this [reddit post](https://www.reddit.com/r/rust/comments/z1gyz7/accessible_documentation/), I started to check a bit how to improve accessibility and how we could add test for it.
So these two fixes come from the use of the [pa11y tool](https://github.com/pa11y/pa11y). To make it work, I had to update its puppeteer version to the last one but otherwise it seems to be quite nice. I didn't fix all the errors it reported because they were about colors. To get the same result as mine, you can use this config:
I think trying to improve accessibility is something we should definitely aim for. I'll try to integrate a tool to enforce this check (very likely `pa11y`) directly into the CI.
Matthias Krüger [Thu, 24 Nov 2022 07:42:35 +0000 (08:42 +0100)]
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
Matthias Krüger [Thu, 24 Nov 2022 07:42:34 +0000 (08:42 +0100)]
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.
Matthias Krüger [Thu, 24 Nov 2022 07:42:33 +0000 (08:42 +0100)]
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.
bors [Wed, 23 Nov 2022 16:29:17 +0000 (16:29 +0000)]
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.)
Dylan DPC [Wed, 23 Nov 2022 15:02:35 +0000 (20:32 +0530)]
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.
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.
Rollup merge of #104750 - mati865:bump-fd-lock-again, r=jyn514
Bump `fd-lock` in `bootstrap` again
Followup to https://github.com/rust-lang/rust/pull/103778
Sorry for the quick succession but this fixes one more building issue for Tier 3 `windows-gnullvm` that I have previously missed, and it would be nice to have it in the release.
- `crate_name` is not specified/passed to `metadata_crate_location_unknown_type`
https://github.com/rust-lang/rust/blob/c493bae0d8efd75723460ce5c371f726efa93f15/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.
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.
- Fix failure to parse rustc's JSON output if it is too nested (rust-lang/cargo#11368)
- Add suggestions when `cargo add` multiple packages (rust-lang/cargo#11186)
- Update mod.rs (rust-lang/cargo#11395)
- Fix typo `try use` -> `try to use` (rust-lang/cargo#11394)
- Add warning when `cargo tree -i <spec>` can not find packages (rust-lang/cargo#11377)
- Clean profile, patch, and replace in cargo remove (rust-lang/cargo#11194)
- chore: Upgrade miow (rust-lang/cargo#11391)
- Fix failure to parse rustc's JSON output if it is too nested (rust-lang/cargo#11368)
- Add suggestions when `cargo add` multiple packages (rust-lang/cargo#11186)
- Update mod.rs (rust-lang/cargo#11395)
- Fix typo `try use` -> `try to use` (rust-lang/cargo#11394)
- Add warning when `cargo tree -i <spec>` can not find packages (rust-lang/cargo#11377)
- Clean profile, patch, and replace in cargo remove (rust-lang/cargo#11194)
- chore: Upgrade miow (rust-lang/cargo#11391)
Mateusz Mikuła [Tue, 22 Nov 2022 23:12:57 +0000 (00:12 +0100)]
Bump `fd-lock` in `bootstrap` again
Followup to https://github.com/rust-lang/rust/pull/103778
Sorry for the quick succession but this fixes one more building issue for Tier 3 `windows-gnullvm` that I have previously missed, and it would be nice to have it in the release.
Yuki Okushi [Tue, 22 Nov 2022 21:40:24 +0000 (06:40 +0900)]
Rollup merge of #104728 - WaffleLapkin:require-lang-items-politely, r=compiler-errors
Use `tcx.require_lang_item` instead of unwrapping lang items
I clearly remember esteban telling me that there is `require_lang_item` but he was from a phone atm and I couldn't find it, so I didn't use it. Stumbled on it today, so here we are :)
Yuki Okushi [Tue, 22 Nov 2022 21:40:22 +0000 (06:40 +0900)]
Rollup merge of #104717 - GuillaumeGomez:test-projection-used-as-const-generic, r=oli-obk
Add failing test for projections used as const generic
Based on the experiment done in https://github.com/rust-lang/rust/pull/104443, we realized it's currently not possible to support projections in const generics. More information about it in https://github.com/rust-lang/rust/pull/104443#discussion_r1029375633.
This PR adds the UI test in any case so we can gather data in order to work towards adding `TyAlias` into the ABI in the future.
Yuki Okushi [Tue, 22 Nov 2022 21:40:22 +0000 (06:40 +0900)]
Rollup merge of #102293 - ecnelises:aix.initial, r=davidtwco
Add powerpc64-ibm-aix as Tier-3 target
This is part of the effort mentioned in https://github.com/rust-lang/compiler-team/issues/553.
A reference to these options are definitions from [clang](https://github.com/llvm/llvm-project/blob/ad6fe32032a6229e0c40510e9bed419a01c695b3/clang/lib/Basic/Targets/PPC.h#L414-L448) and [llvm](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp).
AIX has a system `ld` but [its options and behaviors](https://www.ibm.com/docs/en/aix/7.3?topic=l-ld-command) are different from GNU ld. Thanks to ``@bzEq`` for contributing the linking args.
Yuki Okushi [Tue, 22 Nov 2022 21:40:21 +0000 (06:40 +0900)]
Rollup merge of #101368 - thomcc:wintls-noinline, r=ChrisDenton
Forbid inlining `thread_local!`'s `__getit` function on Windows
Sadly, this will make things slower to avoid UB in an edge case, but it seems hard to avoid... and really whenever I look at this code I can't help but think we're asking for trouble.
It's pretty dodgy for us to leave this as a normal function rather than `#[inline(never)]`, given that if it *does* get inlined into a dynamically linked component, it's extremely unsafe (you get some other thread local, or if you're lucky, crash). Given that it's pretty rare for people to use dylibs on Windows, the fact that we haven't gotten bug reports about it isn't really that convincing. Ideally we'd come up with some kind of compiler solution (that avoids paying for this cost when static linking, or *at least* for use within the same crate...), but it's not clear what that looks like.
Oh, and because all this is only needed when we're implementing `thread_local!` with `#[thread_local]`, this patch adjusts the `cfg_attr` to be `all(windows, target_thread_local)` as well.
r? ``@ChrisDenton``
See also #84933, which is about improving the situation.
bors [Tue, 22 Nov 2022 20:47:17 +0000 (20:47 +0000)]
Auto merge of #104735 - the8472:simd-contains-fix, r=thomcc
Simd contains fix
Fixes #104726
The bug was introduced by an improvement late in the original PR (#103779) which added the backtracking when the last and first byte of the needle were the same. That changed the meaning of the variable for the last probe offset, which I should have split into the last byte offset and last probe offset. Not doing so lead to incorrect loop conditions.