Commit Graph

239314 Commits

Author SHA1 Message Date
Michael Goulet
4ec68576d3 Cache flags for ty::Const 2023-11-22 23:28:28 +00:00
bors
06d1afe518 Auto merge of #118178 - compiler-errors:rollup-0i11w85, r=compiler-errors
Rollup of 6 pull requests

Successful merges:

 - #118012 (Add support for global allocation in smir)
 - #118013 (Enable Rust to use the EHCont security feature of Windows)
 - #118100 (Enable profiler in dist-powerpc64-linux)
 - #118142 (Tighten up link attributes for llvm-wrapper bindings)
 - #118147 (Fix some unnecessary casts)
 - #118161 (Allow defining opaques in `check_coroutine_obligations`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-11-22 18:49:51 +00:00
Michael Goulet
4ec548afbe
Rollup merge of #118161 - compiler-errors:coroutine-obligation-opaques, r=lcnr
Allow defining opaques in `check_coroutine_obligations`

In the new trait solver, when an obligation stalls on an unresolved coroutine witness, we will stash away the *root* obligation, even if the stalled obligation is only a distant descendent of the root obligation, since the new solver is purely recursive.

This means that we may need to reprocess alias-relate obligations (and others) which may define opaque types in the new solver. Currently, we use the coroutine's def id as the defining anchor in `check_coroutine_obligations`, which will allow defining no opaque types, resulting in errors like:

```
error[E0271]: type mismatch resolving `{coroutine@<source>:6:5: 6:17} <: impl Clone`
 --> <source>:6:5
  |
6 | /     move |_: ()| {
7 | |         let () = yield ();
8 | |     }
  | |_____^ types differ
```

So this PR fixes the defining anchor and does the same trick as `check_opaque_well_formed`, where we manually compare opaques that were defined against their hidden types to make sure they weren't defined differently when processing these stalled coroutine obligations.

r? `@lcnr` cc `@cjgillot`
2023-11-22 09:28:52 -08:00
Michael Goulet
040151a4be
Rollup merge of #118147 - Nilstrieb:no-redundant-casts, r=WaffleLapkin
Fix some unnecessary casts

`x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix` with some manual review to ensure every fix is correct.
2023-11-22 09:28:51 -08:00
Michael Goulet
dd9f3ad806
Rollup merge of #118142 - saethlin:llvm-linkage, r=tmiasko
Tighten up link attributes for llvm-wrapper bindings

Fixes https://github.com/rust-lang/rust/issues/118084 by moving all of the declarations of symbols from `llvm_rust` into a separate extern block with `#[link(name = "llvm-wrapper", kind = "static")]`.

This also renames `LLVMTimeTraceProfiler*` to `LLVMRustTimeTraceProfiler*` because those are functions from `llvm_rust`.

r? tmiasko
2023-11-22 09:28:51 -08:00
Michael Goulet
90f04e1b4d
Rollup merge of #118100 - ecnelises:ppc64_profiler, r=Kobzol
Enable profiler in dist-powerpc64-linux
2023-11-22 09:28:50 -08:00
Michael Goulet
1fb2624205
Rollup merge of #118013 - sivadeilra:user/ardavis/ehcont, r=wesleywiser
Enable Rust to use the EHCont security feature of Windows

In the future Windows will enable Control-flow Enforcement Technology (CET aka Shadow Stacks). To protect the path where the context is updated during exception handling, the binary is required to enumerate valid unwind entrypoints in a dedicated section which is validated when the context is being set during exception handling.

The required support for EHCONT Guard has already been merged into LLVM, long ago. This change simply adds the Rust codegen option to enable it.

Relevant LLVM change: https://reviews.llvm.org/D40223

This also adds a new `ehcont-guard` option to the bootstrap config which enables EHCont Guard when building std.

We at Microsoft have been using this feature for a significant period of time; we are confident that the LLVM feature, when enabled, generates well-formed code.

We currently enable EHCONT using a codegen feature, but I'm certainly open to refactoring this to be a target feature instead, or to use any appropriate mechanism to enable it.
2023-11-22 09:28:50 -08:00
Michael Goulet
d58ded9058
Rollup merge of #118012 - celinval:smir-alloc, r=ouz-a
Add support for global allocation in smir

Add APIs to StableMir to support global allocation. Before this change, StableMir users had no API available to retrieve Allocation provenance information. They had to resource to internal APIs instead.

One example is retrieving the Allocation of an `&str`. See test for an example on how the API can be used.
2023-11-22 09:28:49 -08:00
bors
6d2b84b3ed Auto merge of #118133 - Urgau:stabilize_trait_upcasting, r=WaffleLapkin
Stabilize RFC3324 dyn upcasting coercion

This PR stabilize the `trait_upcasting` feature, aka https://github.com/rust-lang/rfcs/pull/3324.

The FCP was completed here: https://github.com/rust-lang/rust/issues/65991#issuecomment-1817552398.

~~And also remove the `deref_into_dyn_supertrait` lint which is now handled by dyn upcasting coercion.~~

Heavily inspired by https://github.com/rust-lang/rust/pull/101718
Fixes https://github.com/rust-lang/rust/issues/65991
2023-11-22 16:15:34 +00:00
bors
73bc12199e Auto merge of #112380 - jieyouxu:useless-bindings-lint, r=WaffleLapkin
Add allow-by-default lint for unit bindings

### Example

```rust
#![warn(unit_bindings)]

macro_rules! owo {
    () => {
        let whats_this = ();
    }
}

fn main() {
    // No warning if user explicitly wrote `()` on either side.
    let expr = ();
    let () = expr;
    let _ = ();

    let _ = expr; //~ WARN binding has unit type
    let pat = expr; //~ WARN binding has unit type
    let _pat = expr; //~ WARN binding has unit type

    // No warning for let bindings with unit type in macro expansions.
    owo!();

    // No warning if user explicitly annotates the unit type on the binding.
    let pat: () = expr;
}
```

outputs

```
warning: binding has unit type `()`
  --> $DIR/unit-bindings.rs:17:5
   |
LL |     let _ = expr;
   |     ^^^^-^^^^^^^^
   |         |
   |         this pattern is inferred to be the unit type `()`
   |
note: the lint level is defined here
  --> $DIR/unit-bindings.rs:3:9
   |
LL | #![warn(unit_bindings)]
   |         ^^^^^^^^^^^^^

warning: binding has unit type `()`
  --> $DIR/unit-bindings.rs:18:5
   |
LL |     let pat = expr;
   |     ^^^^---^^^^^^^^
   |         |
   |         this pattern is inferred to be the unit type `()`

warning: binding has unit type `()`
  --> $DIR/unit-bindings.rs:19:5
   |
LL |     let _pat = expr;
   |     ^^^^----^^^^^^^^
   |         |
   |         this pattern is inferred to be the unit type `()`

warning: 3 warnings emitted
```

This lint is not triggered if any of the following conditions are met:

- The user explicitly annotates the binding with the `()` type.
- The binding is from a macro expansion.
- The user explicitly wrote `let () = init;`
- The user explicitly wrote `let pat = ();`. This is allowed for local lifetimes.

### Known Issue

It is known that this lint can trigger on some proc-macro generated code whose span returns false for `Span::from_expansion` because e.g. the proc-macro simply forwards user code spans, and otherwise don't have distinguishing syntax context compared to non-macro-generated code. For those kind of proc-macros, I believe the correct way to fix them is to instead emit identifers with span like `Span::mixed_site().located_at(user_span)`.

Closes #71432.
2023-11-22 14:03:16 +00:00
Urgau
4c2d6de70e Stabilize RFC3324 dyn upcasting coercion
Aka trait_upcasting feature.

And also adjust the `deref_into_dyn_supertrait` lint.
2023-11-22 13:56:36 +01:00
bors
a6b8ae582a Auto merge of #118086 - nnethercote:queries-cleanups, r=bjorn3
Queries cleanups

r? `@bjorn3`
2023-11-22 11:44:56 +00:00
bors
5a9e0e8787 Auto merge of #118125 - nnethercote:custom_encodable, r=compiler-errors
Make some `newtype_index!` derived impls opt-in instead of opt-out

Opt-in is the standard Rust way of doing things, and avoids some unnecessary dependencies on the `rustc_serialize` crate.

r? `@lcnr`
2023-11-22 09:29:49 +00:00
Nicholas Nethercote
0991374bd1 Document newtype_index attributes. 2023-11-22 18:38:20 +11:00
Nicholas Nethercote
7060fc8327 Replace no_ord_impl with orderable.
Similar to the previous commit, this replaces `newtype_index`'s opt-out
`no_ord_impl` attribute with the opt-in `orderable` attribute.
2023-11-22 18:38:17 +11:00
Nicholas Nethercote
3ef9d4d0ed Replace custom_encodable with encodable.
By default, `newtype_index!` types get a default `Encodable`/`Decodable`
impl. You can opt out of this with `custom_encodable`. Opting out is the
opposite to how Rust normally works with autogenerated (derived) impls.

This commit inverts the behaviour, replacing `custom_encodable` with
`encodable` which opts into the default `Encodable`/`Decodable` impl.
Only 23 of the 59 `newtype_index!` occurrences need `encodable`.

Even better, there were eight crates with a dependency on
`rustc_serialize` just from unused default `Encodable`/`Decodable`
impls. This commit removes that dependency from those eight crates.
2023-11-22 18:37:14 +11:00
bors
855c6836b7 Auto merge of #118071 - Urgau:check-cfg-cargo-feature, r=petrochenkov
Remove `feature` from the list of well known check-cfg name

This PR removes `feature` from the list of well known check-cfg.

This is done for multiple reasons:
 - Cargo is the source of truth, rustc shouldn't have any knowledge of it
 - It creates a conflict between Cargo and rustc when there are no features defined.
   In this case Cargo won't pass any `--check-cfg` for `feature` since no feature will ever be passed, but rustc by having in it's list adds a implicit `cfg(feature, values(any()))` which is completely wrong. Having any cfg `feature` is unexpected not allow any `feature` value.

While doing this, I took the opportunity to specialise the diagnostic a bit for the case above.

r? `@petrochenkov`
2023-11-22 07:31:13 +00:00
bors
cc4bb0de20 Auto merge of #117928 - nnethercote:rustc_ast_pretty, r=fee1-dead
`rustc_ast_pretty` cleanups

Some improvements I found while looking at this code.

r? `@fee1-dead`
2023-11-22 05:09:33 +00:00
Michael Goulet
4f958a4802 Allow defining opaques in check_coroutine_obligations 2023-11-22 03:44:13 +00:00
Celina G. Val
c07a6d5c9a Add allocation test and a bit more documentation 2023-11-21 19:16:58 -08:00
Celina G. Val
5b3cf6610b Add support to get virtual table allocation 2023-11-21 19:16:58 -08:00
Celina G. Val
fa5ff859e6 Add support to global allocation to stable-mir 2023-11-21 19:16:53 -08:00
bors
739d556826 Auto merge of #117582 - compiler-errors:uplift-canonical-var, r=jackh726
Uplift `CanonicalVarInfo` and friends into `rustc_type_ir`

Depends on #117580 and #117578

Uplift `CanonicalVarInfo` and friends into `rustc_type_ir` so they can be consumed by an interner-agnostic `Canonicalizer` implementation for the new trait solver ❤️

r? `@ghost`
2023-11-22 02:43:23 +00:00
Nicholas Nethercote
971010ea5a Merge Queries::{ongoing_codegen,linker}.
There is no real need for them to be separate.
2023-11-22 13:22:49 +11:00
Nicholas Nethercote
3a4798c92d Make Compiler::{sess,codegen_backend} public.
And remove the relevant getters on `Compiler` and `Queries`.
2023-11-22 13:22:41 +11:00
Nicholas Nethercote
09c807ed82 Add two useful comments. 2023-11-22 13:20:56 +11:00
Nicholas Nethercote
cf561904db Add comments about a timer. 2023-11-22 13:20:56 +11:00
bors
ed10a53025 Auto merge of #118152 - matthiaskrgr:rollup-bqcck4w, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #117972 (Add VarDebugInfo to Stable MIR)
 - #118109 (rustdoc-search: simplify `checkPath` and `sortResults`)
 - #118110 (Document `DefiningAnchor` a bit more)
 - #118112 (Don't ICE when ambiguity is found when selecting `Index` implementation in typeck)
 - #118135 (Remove quotation from filename in stable_mir)

Failed merges:

 - #118012 (Add support for global allocation in smir)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-11-22 00:30:56 +00:00
Nicholas Nethercote
6686221d29 Remove outdated reference to compiler plugins. 2023-11-22 11:06:24 +11:00
Nicholas Nethercote
9fe6bb4a10 Add some comments. 2023-11-22 11:06:16 +11:00
Matthias Krüger
914891fc58
Rollup merge of #118135 - ouz-a:fix_stable_span, r=celinval
Remove quotation from filename in stable_mir

Previously we had quotation marks in filenames which is obviously wrong this fixes that.

r? ```@celinval```
2023-11-21 23:46:20 +01:00
Matthias Krüger
802f71b294
Rollup merge of #118112 - compiler-errors:index-ambiguity-ice, r=aliemjay
Don't ICE when ambiguity is found when selecting `Index` implementation in typeck

Fixes #118111

The problem here is when we're manually "selecting" an impl for `base_ty: Index<?0>`, we don't consider placeholder region errors (leak check) or ambiguous predicates. Those can lead to us not actually emitting any fulfillment errors on line 3131.
2023-11-21 23:46:20 +01:00
Matthias Krüger
a11be28e13
Rollup merge of #118110 - compiler-errors:defining-anchor, r=aliemjay
Document `DefiningAnchor` a bit more

r? types
2023-11-21 23:46:19 +01:00
Matthias Krüger
bdb929e788
Rollup merge of #118109 - notriddle:notriddle/search-cleanup-2, r=GuillaumeGomez
rustdoc-search: simplify `checkPath` and `sortResults`

These two commits reduce the amount of code in search.js with no noticeable change in performance.

https://notriddle.com/rustdoc-html-demo-5/profile-5/index.html
2023-11-21 23:46:19 +01:00
Matthias Krüger
a98698e9c4
Rollup merge of #117972 - ouz-a:stable_debuginfo, r=celinval
Add VarDebugInfo to Stable MIR

Previously we omitted `VarDebugInfo` because we didn't have `Projection` now that https://github.com/rust-lang/rust/pull/117517 is merged it's possible to add `VarDebugInfo` information in `Body`. This PR adds stable version of the `VarDebugInfo` to `Body`

r? ```@celinval```
2023-11-21 23:46:18 +01:00
Arlie Davis
80896cbe35 update -Cehcont-guard and comment 2023-11-21 14:35:02 -08:00
bors
fec80b4475 Auto merge of #118143 - Nilstrieb:only-borrow-what-you-need, r=compiler-errors
Fix `clippy::needless_borrow` in the compiler

`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed now.

r? `@compiler-errors` you told me you want to review this

I will do a self review first (which, for this, is easiest on GitHub once the PR is open) - did it
2023-11-21 22:34:19 +00:00
Arlie Davis
9429d68842 convert ehcont-guard to an unstable option 2023-11-21 14:24:23 -08:00
Arlie Davis
d582f1092b x.py fmt 2023-11-21 13:41:24 -08:00
Arlie Davis
e11d8d147b Add support for generating the EHCont section
In the future Windows will enable Control-flow Enforcement Technology
(CET aka Shadow Stacks). To protect the path where the context is
updated during exception handling, the binary is required to enumerate
valid unwind entrypoints in a dedicated section which is validated when
the context is being set during exception handling.

The required support for EHCONT has already been merged into LLVM,
long ago. This change adds the Rust codegen option to enable it.

Reference:

* https://reviews.llvm.org/D40223

This also adds a new `ehcont-guard` option to the bootstrap config which
enables EHCont Guard when building std.
2023-11-21 13:41:23 -08:00
Nicholas Nethercote
10c8b56af1 Factor out common code in PrintState.
The AST and HIR versions of `State::print_ident` are textually
identical, but the types differ slightly. This commit factors out the
common code they both have by replacing `print_ident` with `ann_post`,
which is a smaller function that still captures the type difference.
2023-11-22 08:13:21 +11:00
Nicholas Nethercote
e16b52d4f0 Streamline PrintState.
`PrintState` is a trait containing code that can be used by both AST and
HIR pretty-printing. But several of its methods are only used by AST
printing.

This commit moves those methods out of the trait and into the AST
`State` impl, so they are not exposed unnecessarily. This commit also
removes four unused methods: `param_to_string`,
`foreign_item_to_string`, `assoc_item_to_string`, and
`print_inner_attributes_inline`.
2023-11-22 08:13:21 +11:00
Nicholas Nethercote
c6a9027102 Remove unused PrintState::generic_params_to_string method. 2023-11-22 08:13:21 +11:00
Nicholas Nethercote
d9443f71c7 Remove or downgrade unnecessary pub visibility markers. 2023-11-22 08:13:21 +11:00
Nicholas Nethercote
33cee0b22c Remove NO_ANN.
This makes `rustc_hir_pretty` more like `rustc_ast_pretty`.
2023-11-22 08:13:21 +11:00
Nicholas Nethercote
ce363bb6e6 Remove IterDelimited.
itertools has `with_position` which does the same thing.
2023-11-22 08:13:21 +11:00
Nicholas Nethercote
3eadc6844b Update itertools to 0.11.
Because the API for `with_position` improved in 0.11 and I want to use
it.
2023-11-22 08:13:21 +11:00
Nicholas Nethercote
1d320ed387 Remove unnecessary derives. 2023-11-22 08:13:21 +11:00
Nicholas Nethercote
2f51f0b290 Remove unneeded features. 2023-11-22 08:13:21 +11:00
Nilstrieb
c089a162d8 Fix some unnecessary casts
`x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix`
with some manual review to ensure every fix is correct.
2023-11-21 22:11:08 +01:00