Commit Graph

32867 Commits

Author SHA1 Message Date
Michael Goulet
3250e95305 Add a simple extension trait derive 2024-02-16 15:07:37 +00:00
bors
dfa88b328f Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkin
Implement intrinsics with fallback bodies

fixes #93145 (though we can port many more intrinsics)
cc #63585

The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for

* codegen_ssa (so llvm and gcc)
* codegen_cranelift

other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body).

cc `@scottmcm` `@WaffleLapkin`

### todo

* [ ] miri support
* [x] default intrinsic name to name of function instead of requiring it to be specified in attribute
* [x] make sure that the bodies are always available (must be collected for metadata)
2024-02-16 09:53:01 +00:00
bors
1be468815c Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnay
Use generic `NonZero` internally.

Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-16 07:46:31 +00:00
Guillaume Gomez
e84a1dd87f
Rollup merge of #121147 - tmiasko:no-debug-body, r=compiler-errors
Avoid debug logging entire MIR body

If there is a need to examine the MIR body there is -Zmir-dump.
2024-02-16 00:27:35 +01:00
Guillaume Gomez
77eaa80d5c
Rollup merge of #121146 - compiler-errors:ignore-diverging-arms, r=estebank
Only point out non-diverging arms for match suggestions

Fixes #121144

There is no reason to point at diverging arms, which will always coerce to whatever is the match block's evaluated type.

This also removes the suggestion from #106601, since as I pointed out in https://github.com/rust-lang/rust/issues/72634#issuecomment-1946210898 the added suggestion is not firing in the right cases, but instead only when one of the match arms already *actually* evaluates to `()`.

r? estebank
2024-02-16 00:27:34 +01:00
Guillaume Gomez
d6e2fc5589
Rollup merge of #121145 - adamgemmell:dev/adagem01/combined-target-features, r=Amanieu
Update aarch64 target feature docs to match LLVM

https://github.com/rust-lang/stdarch/issues/1432 https://github.com/rust-lang/stdarch/pull/1527

r? ```@Amanieu```
2024-02-16 00:27:34 +01:00
Guillaume Gomez
12a73a6bbe
Rollup merge of #121141 - compiler-errors:closure-kind-docs, r=nnethercote
Fix closure kind docs

I didn't review this close enough lol -- the old code snippet didn't use substs correctly, and had a malformed `if let`
2024-02-16 00:27:34 +01:00
Guillaume Gomez
ddad818b7a
Rollup merge of #121119 - compiler-errors:async-fn-kind-errs, r=oli-obk
Make `async Fn` trait kind errors better

1. Make it so that async closures with the wrong closurekind actually report a useful error
2. Explain why async closures can sometimes not implement `Fn`/`FnMut` (because they capture things)

r? oli-obk
2024-02-16 00:27:33 +01:00
Guillaume Gomez
c73aa787f6
Rollup merge of #121109 - nnethercote:TyKind-Err-guar-2, r=oli-obk
Add an ErrorGuaranteed to ast::TyKind::Err (attempt 2)

This makes it more like `hir::TyKind::Err`, and avoids a `has_errors` assertion in `LoweringContext::lower_ty_direct`.

r? ```@oli-obk```
2024-02-16 00:27:32 +01:00
bors
a4472498d7 Auto merge of #121133 - tmiasko:skip-coroutines, r=cjgillot
Skip coroutines in jump threading to avoid query cycles

Fixes #121094
2024-02-15 21:30:25 +00:00
bors
b656f5171b Auto merge of #119338 - compiler-errors:upcast-plus-autos, r=lcnr
Consider principal trait ref's auto-trait super-traits in dyn upcasting

Given traits like:

```rust
trait Subtrait: Supertrait + Send {}
trait Supertrait {}
```

We should be able to upcast `dyn Subtrait` to `dyn Supertrait + Send`. This is not currently possible, because when upcasting, we look at the list of auto traits in the object type (`dyn Subtrait`, which has no auto traits in its bounds) and compare them to the target's auto traits (`dyn Supertrait + Send`, which has `Send` in its bound).

Since the target has auto traits that are not present in the source, the upcasting fails. This is overly restrictive, since `dyn Subtrait` will always implement `Send` via its built-in object impl. I propose to loosen this restriction here.

r? types

---

### ~~Aside: Fix this in astconv instead?~~

### edit: This causes too many failures. See https://github.com/rust-lang/rust/pull/119825#issuecomment-1890847150

We may also fix this by by automatically elaborating all auto-trait supertraits during `AstConv::conv_object_ty_poly_trait_ref`. That is, we can make it so that `dyn Subtrait` is elaborated into the same type of `dyn Subtrait + Send`.

I'm open to considering this solution instead, but it would break coherence in the following example:

```rust
trait Foo: Send {}

trait Bar {}
impl Bar for dyn Foo {}
impl Bar for dyn Foo + Send {}
//~^ This would begin to be an overlapping impl.
```
2024-02-15 19:16:06 +00:00
Michael Goulet
954d56591c Fix closure kind docs 2024-02-15 18:44:49 +00:00
Michael Goulet
6018e21d8a Remove a suggestion that is redundant 2024-02-15 17:20:44 +00:00
bors
cbddf31863 Auto merge of #121142 - GuillaumeGomez:rollup-5qmksjw, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #120449 (Document requirements for unsized {Rc,Arc}::from_raw)
 - #120505 (Fix BTreeMap's Cursor::remove_{next,prev})
 - #120672 (std::thread update freebsd stack guard handling.)
 - #121088 (Implicitly enable evex512 if avx512 is enabled)
 - #121104 (Ignore unsized types when trying to determine the size of the original type)
 - #121107 (Fix msg for verbose suggestions with confusable capitalization)
 - #121113 (Continue compilation even if inherent impl checks fail)
 - #121120 (Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-15 17:00:55 +00:00
Michael Goulet
acb201af54 make better async fn kind errors 2024-02-15 15:59:35 +00:00
Michael Goulet
c763f833d1 Only point out non-diverging arms for match suggestions 2024-02-15 15:44:46 +00:00
Michael Goulet
ec8e898193 Consider principal trait ref's auto-trait super-traits in dyn upcasting 2024-02-15 15:38:11 +00:00
Tomasz Miąsko
5d65b1954e Avoid debug logging entire MIR body
If there is a need to examine the MIR body there is -Zmir-dump.
2024-02-15 15:54:28 +01:00
Adam Gemmell
cc7b4e02be Update aarch64 target feature docs to match LLVM 2024-02-15 14:36:29 +00:00
Guillaume Gomez
06f53dd316
Rollup merge of #121120 - nnethercote:LitKind-Err-guar, r=fmease
Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.

Similar to recent work doing the same for `ExprKind::Err` (#120586) and `TyKind::Err` (#121109).

r? `@oli-obk`
2024-02-15 14:33:03 +01:00
Guillaume Gomez
e878439d39
Rollup merge of #121113 - oli-obk:track_errors10, r=compiler-errors
Continue compilation even if inherent impl checks fail

We should not be hiding errors behind unrelated errors
2024-02-15 14:33:02 +01:00
Guillaume Gomez
3c8705402a
Rollup merge of #121107 - estebank:capitalization-suggestion, r=michaelwoerister
Fix msg for verbose suggestions with confusable capitalization

When encountering a verbose/multipart suggestion that has changes that are only caused by different capitalization of ASCII letters that have little differenciation, expand the message to highlight that fact (like we already do for inline suggestions).

The logic to do this was already present, but implemented incorrectly.
2024-02-15 14:33:02 +01:00
Guillaume Gomez
12d70af446
Rollup merge of #121104 - Urgau:bigger_layout-fix-fp, r=compiler-errors
Ignore unsized types when trying to determine the size of the original type

Fixes https://github.com/rust-lang/rust/issues/121074 a regression from https://github.com/rust-lang/rust/pull/118983
2024-02-15 14:33:01 +01:00
Guillaume Gomez
7d6c99dd06
Rollup merge of #121088 - nikic:evex512, r=Amanieu
Implicitly enable evex512 if avx512 is enabled

LLVM 18 requires the evex512 feature to allow use of zmm registers. LLVM automatically sets it when using a generic CPU, but not when `-C target-cpu` is specified. This will result either in backend legalization crashes, or code unexpectedly using ymm instead of zmm registers.

For now, make sure that `avx512*` features imply `evex512`. Long term we'll probably have to deal with the AVX10 mess somehow.

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

r? `@Amanieu`
2024-02-15 14:33:01 +01:00
bors
fa9f77ff35 Auto merge of #120931 - chenyukang:yukang-cleanup-hashmap, r=michaelwoerister
Clean up potential_query_instability with FxIndexMap and UnordMap

From https://github.com/rust-lang/rust/pull/120485#issuecomment-1916437191

r? `@michaelwoerister`
2024-02-15 12:36:37 +00:00
bors
6a4222b511 Auto merge of #116564 - oli-obk:evaluated_static_in_metadata, r=RalfJung,cjgillot
Store static initializers in metadata instead of the MIR of statics.

This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better.

The issue is that

```rust
static mut FOO: &mut u32 = &mut 42;
static mut BAR = unsafe { FOO };
```

gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo.

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

## Why is this being done?

In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](https://github.com/rust-lang/rust/issues/57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
2024-02-15 10:28:31 +00:00
Oli Scherer
73b38c661d Do not allocate a second "background" alloc id for the main allocation of a static.
Instead we re-use the static's alloc id within the interpreter for its initializer to refer to the `Allocation` that only exists within the interpreter.
2024-02-15 10:25:18 +00:00
Oli Scherer
e2386270df Return ConstAllocation from eval_static_initializer query directly 2024-02-15 10:25:18 +00:00
Oli Scherer
be6ccf13e3 Store static initializers in metadata instead of the MIR of statics. 2024-02-15 10:25:18 +00:00
Oli Scherer
95004e5ae2 Add new query just for static initializers 2024-02-15 10:25:18 +00:00
Oli Scherer
fc9d1a8133 Split a bool argument into two named functions 2024-02-15 10:25:18 +00:00
bors
4ae1e79876 Auto merge of #121131 - matthiaskrgr:rollup-mo3b8nz, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #111106 (Add known issue of let binding to format_args doc)
 - #118749 (Make contributing to windows bindings easier)
 - #120982 (Add APIs for fetching foreign items )
 - #121022 (rustdoc: cross-crate re-exports: correctly render late-bound params in source order even if early-bound params are present)
 - #121082 (Clarified docs on non-atomic oprations on owned/mut refs to atomics)
 - #121084 (Make sure `tcx.create_def` also depends on the forever red node, instead of just `tcx.at(span).create_def`)
 - #121098 (Remove unnecessary else block from `thread_local!` expanded code)
 - #121105 (Do not report overflow errors on ConstArgHasType goals)
 - #121116 (Reinstate some delayed bugs.)
 - #121122 (Enforce coroutine-closure layouts are identical)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-15 08:29:42 +00:00
Matthias Krüger
829b59a47d
Rollup merge of #121122 - compiler-errors:identical-layouts, r=oli-obk
Enforce coroutine-closure layouts are identical

Enforce that for an async closure, the by-ref and by-move coroutine layouts are identical. This is just a sanity check to make sure that optimizations aren't doing anything fishy.

r? oli-obk
2024-02-15 09:20:23 +01:00
Matthias Krüger
4899108109
Rollup merge of #121116 - nnethercote:fix-121103-121108, r=oli-obk
Reinstate some delayed bugs.

These were changed to `has_errors` assertions in #121071 because that seemed reasonable, but evidently not.

Fixes #121103.
Fixes #121108.
2024-02-15 09:20:21 +01:00
Matthias Krüger
888fe709e6
Rollup merge of #121105 - compiler-errors:no-const-ty-overflow, r=oli-obk
Do not report overflow errors on ConstArgHasType goals

This is 10% of a fix for #121090, since it at least means that we no longer mention the `ConstArgHasType` goal as the cause for the overflow. Instead, now we mention:
```
overflow evaluating the requirement `{closure@$DIR/overflow-during-mono.rs:13:41: 13:44}: Sized`
```
which is not much better, but slightly.

r? oli-obk
2024-02-15 09:20:21 +01:00
Matthias Krüger
f62d981a18
Rollup merge of #121084 - oli-obk:create_def_forever_red2, r=WaffleLapkin
Make sure `tcx.create_def` also depends on the forever red node, instead of just `tcx.at(span).create_def`

oversight from https://github.com/rust-lang/rust/pull/119136

Not actually an issue, because all uses of `tcx.create_def` were in the resolver, which is `eval_always`, but still good to harden against future uses of `create_def`

cc `@petrochenkov` `@WaffleLapkin`
2024-02-15 09:20:20 +01:00
Matthias Krüger
71466ca804
Rollup merge of #120982 - momvart:smir-61-foreign_kind, r=oli-obk
Add APIs for fetching foreign items

Closes https://github.com/rust-lang/project-stable-mir/issues/61
2024-02-15 09:20:18 +01:00
Markus Reiter
a90cc05233
Replace NonZero::<_>::new with NonZero::new. 2024-02-15 08:09:42 +01:00
Markus Reiter
746a58d435
Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
Nicholas Nethercote
ac47f6c666 Add suffixes to LitError.
To avoid some unwrapping.
2024-02-15 15:47:24 +11:00
Nicholas Nethercote
25ed6e43b0 Add ErrorGuaranteed to ast::LitKind::Err, token::LitKind::Err.
This mostly works well, and eliminates a couple of delayed bugs.

One annoying thing is that we should really also add an
`ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's
difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`,
so we have to fake it.
2024-02-15 14:46:08 +11:00
Eric Huss
217e5e484d Fix SmallCStr conversion from CStr 2024-02-14 18:40:53 -08:00
Nicholas Nethercote
332c57723a Make emit_unescape_error return Option<ErrorGuaranteed>.
And use the result in `cook_common` to decide whether to return an error
token.
2024-02-15 12:58:18 +11:00
Nicholas Nethercote
a513bb20c3 Make report_lit_error return ErrorGuaranteed.
This will be helpful for subsequent commits.
2024-02-15 12:58:18 +11:00
Nicholas Nethercote
8b35f8e41e Remove LitError::LexerError.
`cook_lexer_literal` can emit an error about an invalid int literal but
then return a non-`Err` token. And then `integer_lit` has to account for
this to avoid printing a redundant error message.

This commit changes `cook_lexer_literal` to return `Err` in that case.
Then `integer_lit` doesn't need the special case, and
`LitError::LexerError` can be removed.
2024-02-15 12:58:18 +11:00
Michael Goulet
e6a21f549e Enforce coroutine-closure layouts are identical 2024-02-15 01:18:09 +00:00
Tomasz Miąsko
5f4e4baddb Skip coroutines in jump threading to avoid query cycles 2024-02-15 00:00:00 +00:00
Nicholas Nethercote
5233bc91da Add an ErrorGuaranteed to ast::TyKind::Err.
This makes it more like `hir::TyKind::Err`, and avoids a
`span_delayed_bug` call in `LoweringContext::lower_ty_direct`.

It also requires adding `ast::TyKind::Dummy`, now that
`ast::TyKind::Err` can't be used for that purpose in the absence of an
error emission.

There are a couple of cases that aren't as neat as I would have liked,
marked with `FIXME` comments.
2024-02-15 09:35:11 +11:00
Nicholas Nethercote
64a9c9cfea Reinstate some delayed bugs.
These were changed to `has_errors` assertions in #121071 because that
seemed reasonable, but evidently not.

Fixes #121103.
Fixes #121108.
2024-02-15 09:26:45 +11:00
Oli Scherer
c1bb352c8b Continue compilation even if inherent impl checks fail 2024-02-14 21:04:51 +00:00