about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2024-03-19Auto merge of #122037 - oli-obk:more_new_intrinsics, r=Nilstriebbors-9/+18
Move more intrinsics to rustc_intrinsic cc https://github.com/rust-lang/rust/issues/63585
2024-03-19Change only_local to enum type and change the macros to always require a ↵surechen-8/+2
variant of that enum.
2024-03-19Auto merge of #122021 - oli-obk:delangitemification, r=compiler-errorsbors-47/+7
Use hir::Node helper methods instead of repeating the same impl multiple times I wanted to do something entirely different and stumbled upon a bunch of cleanups
2024-03-19Ensure nested statics have a HIR node to prevent various queries from ICEingOli Scherer-0/+21
2024-03-19Remove all checks of `IntrinsicDef::must_be_overridden` except for the ↵Oli Scherer-3/+1
actual overrides in codegen
2024-03-19Make span_bug panic site useful againOli Scherer-9/+18
2024-03-19Make `const_eval_select` a rustc_intrinsicOli Scherer-1/+3
2024-03-19Auto merge of #119212 - w-utter:pretty-print-const-expr, r=compiler-errorsbors-2/+152
Fix representation when printing abstract consts Previously, when printing a const generic expr, it would only display it as `{{const expr}}`. This allows for a more legible representation when printing these out. I also zipped the types with their constants for abstract consts that contain function calls when using type annotations, eg: `foo(S: usize, true: bool) -> usize` insteaad of `foo(S, true): fn(usize, bool) -> usize` for conciseness.
2024-03-19The AssocOpaqueTy HIR node is not actually needed to differentiate from ↵Oli Scherer-2/+2
other hir nodes that were fed
2024-03-19Auto merge of #122493 - lukas-code:sized-constraint, r=lcnrbors-16/+19
clean up `Sized` checking This PR cleans up `sized_constraint` and related functions to make them simpler and faster. This should not make more or less code compile, but it can change error output in some rare cases. ## enums and unions are `Sized`, even if they are not WF The previous code has some special handling for enums, which made them sized if and only if the last field of each variant is sized. For example given this definition (which is not WF) ```rust enum E<T1: ?Sized, T2: ?Sized, U1: ?Sized, U2: ?Sized> { A(T1, T2), B(U1, U2), } ``` the enum was sized if and only if `T2` and `U2` are sized, while `T1` and `T2` were ignored for `Sized` checking. After this PR this enum will always be sized. Unsized enums are not a thing in Rust and removing this special case allows us to return an `Option<Ty>` from `sized_constraint`, rather than a `List<Ty>`. Similarly, the old code made an union defined like this ```rust union Union<T: ?Sized, U: ?Sized> { head: T, tail: U, } ``` sized if and only if `U` is sized, completely ignoring `T`. This just makes no sense at all and now this union is always sized. ## apply the "perf hack" to all (non-error) types, instead of just type parameters This "perf hack" skips evaluating `sized_constraint(adt): Sized` if `sized_constraint(adt): Sized` exactly matches a predicate defined on `adt`, for example: ```rust // `Foo<T>: Sized` iff `T: Sized`, but we know `T: Sized` from a predicate of `Foo` struct Foo<T /*: Sized */>(T); ``` Previously this was only applied to type parameters and now it is applied to every type. This means that for example this type is now always sized: ```rust // Note that this definition is WF, but the type `S<T>` not WF in the global/empty ParamEnv struct S<T>([T]) where [T]: Sized; ``` I don't anticipate this to affect compile time of any real-world program, but it makes the code a bit nicer and it also makes error messages a bit more consistent if someone does write such a cursed type. ## tuples are sized if the last type is sized The old solver already has this behavior and this PR also implements it for the new solver and `is_trivially_sized`. This makes it so that tuples work more like a struct defined like this: ```rust struct TupleN<T1, T2, /* ... */ Tn: ?Sized>(T1, T2, /* ... */ Tn); ``` This might improve the compile time of programs with large tuples a little, but is mostly also a consistency fix. ## `is_trivially_sized` for more types This function is used post-typeck code (borrowck, const eval, codegen) to skip evaluating `T: Sized` in some cases. It will now return `true` in more cases, most notably `UnsafeCell<T>` and `ManuallyDrop<T>` where `T.is_trivially_sized`. I'm anticipating that this change will improve compile time for some real world programs.
2024-03-19Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obkbors-1/+1
Stabilize associated type bounds (RFC 2289) This PR stabilizes associated type bounds, which were laid out in [RFC 2289]. This gives us a shorthand to express nested type bounds that would otherwise need to be expressed with nested `impl Trait` or broken into several `where` clauses. ### What are we stabilizing? We're stabilizing the associated item bounds syntax, which allows us to put bounds in associated type position within other bounds, i.e. `T: Trait<Assoc: Bounds...>`. See [RFC 2289] for motivation. In all position, the associated type bound syntax expands into a set of two (or more) bounds, and never anything else (see "How does this differ[...]" section for more info). Associated type bounds are stabilized in four positions: * **`where` clauses (and APIT)** - This is equivalent to breaking up the bound into two (or more) `where` clauses. For example, `where T: Trait<Assoc: Bound>` is equivalent to `where T: Trait, <T as Trait>::Assoc: Bound`. * **Supertraits** - Similar to above, `trait CopyIterator: Iterator<Item: Copy> {}`. This is almost equivalent to breaking up the bound into two (or more) `where` clauses; however, the bound on the associated item is implied whenever the trait is used. See #112573/#112629. * **Associated type item bounds** - This allows constraining the *nested* rigid projections that are associated with a trait's associated types. e.g. `trait Trait { type Assoc: Trait2<Assoc2: Copy>; }`. * **opaque item bounds (RPIT, TAIT)** - This allows constraining associated types that are associated with the opaque without having to *name* the opaque. For example, `impl Iterator<Item: Copy>` defines an iterator whose item is `Copy` without having to actually name that item bound. The latter three are not expressible in surface Rust (though for associated type item bounds, this will change in #120752, which I don't believe should block this PR), so this does represent a slight expansion of what can be expressed in trait bounds. ### How does this differ from the RFC? Compared to the RFC, the current implementation *always* desugars associated type bounds to sets of `ty::Clause`s internally. Specifically, it does *not* introduce a position-dependent desugaring as laid out in [RFC 2289], and in particular: * It does *not* desugar to anonymous associated items in associated type item bounds. * It does *not* desugar to nested RPITs in RPIT bounds, nor nested TAITs in TAIT bounds. This position-dependent desugaring laid out in the RFC existed simply to side-step limitations of the trait solver, which have mostly been fixed in #120584. The desugaring laid out in the RFC also added unnecessary complication to the design of the feature, and introduces its own limitations to, for example: * Conditionally lowering to nested `impl Trait` in certain positions such as RPIT and TAIT means that we inherit the limitations of RPIT/TAIT, namely lack of support for higher-ranked opaque inference. See this code example: https://github.com/rust-lang/rust/pull/120752#issuecomment-1979412531. * Introducing anonymous associated types makes traits no longer object safe, since anonymous associated types are not nameable, and all associated types must be named in `dyn` types. This last point motivates why this PR is *not* stabilizing support for associated type bounds in `dyn` types, e.g, `dyn Assoc<Item: Bound>`. Why? Because `dyn` types need to have *concrete* types for all associated items, this would necessitate a distinct lowering for associated type bounds, which seems both complicated and unnecessary compared to just requiring the user to write `impl Trait` themselves. See #120719. ### Implementation history: Limited to the significant behavioral changes and fixes and relevant PRs, ping me if I left something out-- * #57428 * #108063 * #110512 * #112629 * #120719 * #120584 Closes #52662 [RFC 2289]: https://rust-lang.github.io/rfcs/2289-associated-type-bounds.html
2024-03-18address nitsLukas Markeffsky-1/+1
2024-03-18Rollup merge of #122687 - lcnr:normalizes-to-emit-nested-goals, ↵Matthias Krüger-15/+25
r=compiler-errors `NormalizesTo`: return nested goals to caller Fixes the regression of `paperclip-core`. see https://hackmd.io/IsVAafiOTAaPIFcUxRJufw for more details. r? ```@compiler-errors```
2024-03-18Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkinMatthias Krüger-1/+42
Provide structured suggestion for `#![feature(foo)]` ``` error: `S2<'_>` is forbidden as the type of a const generic parameter --> $DIR/lifetime-in-const-param.rs:5:23 | LL | struct S<'a, const N: S2>(&'a ()); | ^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | LL + #![feature(adt_const_params)] | ``` Fix #55941.
2024-03-18Deduplicate `associated_body` and `body_id`Oli Scherer-47/+7
They match on almost the same patterns, which is fishy. Also turn `associated_body` into a method and do some cleanups nearby the call sites
2024-03-18cleanup + reviewlcnr-13/+4
2024-03-18update region debug formattingBoxy-2/+16
2024-03-18Provide structured suggestion for `#![feature(foo)]`Esteban Küber-1/+42
``` error: `S2<'_>` is forbidden as the type of a const generic parameter --> $DIR/lifetime-in-const-param.rs:5:23 | LL | struct S<'a, const N: S2>(&'a ()); | ^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | LL + #![feature(adt_const_params)] | ``` Fix #55941.
2024-03-18`NormalizesTo` return nested goalslcnr-2/+21
2024-03-18Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few ↵Oli Scherer-18/+18
cases that used `None`
2024-03-17Print a backtrace in const eval if interruptedBen Kimock-0/+2
2024-03-17Guard decorate on when not to skip instead许杰友 Jieyou Xu (Joe)-7/+4
2024-03-17Invoke decorate when error level is beyond warning, including error许杰友 Jieyou Xu (Joe)-7/+16
2024-03-17Only invoke `decorate` if the diag can eventually be emitted许杰友 Jieyou Xu (Joe)-2/+10
2024-03-17added pretty_print_const_exprwill-2/+152
2024-03-16Auto merge of #121926 - tgross35:f16-f128-step3-feature-gate, ↵bors-2/+64
r=compiler-errors,petrochenkov `f16` and `f128` step 3: compiler support & feature gate Continuation of https://github.com/rust-lang/rust/pull/121841, another portion of https://github.com/rust-lang/rust/pull/114607 This PR exposes the new types to the world and adds a feature gate. Marking this as a draft because I need some feedback on where I did the feature gate check. It also does not yet catch type via suffixed literals (so the feature gate test will fail, probably some others too because I haven't belssed). If there is a better place to check all types after resolution, I can do that. If not, I figure maybe I can add a second gate location in AST when it checks numeric suffixes. Unfortunately I still don't think there is much testing to be done for correctness (codegen tests or parsed value checks) until we have basic library support. I think that will be the next step. Tracking issue: https://github.com/rust-lang/rust/issues/116909 r? `@compiler-errors` cc `@Nilstrieb` `@rustbot` label +F-f16_and_f128
2024-03-15Rollup merge of #122513 - petrochenkov:somehir4, r=fmeaseGuillaume Gomez-18/+5
hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id` Also replace a few `hir_node()` calls with `hir_node_by_def_id()`. Follow up to https://github.com/rust-lang/rust/pull/120943.
2024-03-15interpret/allocation: fix aliasing issue in interpreter and refactor getters ↵Ralf Jung-11/+31
a bit - rename mutating functions to be more scary - add a new raw bytes getter
2024-03-15Rollup merge of #122526 - Zalathar:thir-expr-docs, r=oli-obkMatthias Krüger-1/+12
Docs for `thir::ExprKind::Use` and `thir::ExprKind::Let` These docs are based on my own recent investigations; hopefully they're reasonably accurate. `Use` was particularly puzzling to me at first, since the name is not very suggestive, and the old docs were quite cryptic.
2024-03-15Docs for `thir::ExprKind::Use` and `thir::ExprKind::Let`Zalathar-1/+12
2024-03-15Auto merge of #122517 - petrochenkov:bodihash, r=oli-obkbors-0/+27
Fill in HIR hash for associated opaque types Fixes https://github.com/rust-lang/rust/issues/122508
2024-03-15Auto merge of #122511 - matthiaskrgr:rollup-swzilin, r=matthiaskrgrbors-3/+83
Rollup of 10 pull requests Successful merges: - #117118 ([AIX] Remove AixLinker's debuginfo() implementation) - #121650 (change std::process to drop supplementary groups based on CAP_SETGID) - #121764 (Make incremental sessions identity no longer depend on the crate names provided by source code) - #122212 (Copy byval argument to alloca if alignment is insufficient) - #122322 (coverage: Initial support for branch coverage instrumentation) - #122373 (Fix the conflict problem between the diagnostics fixes of lint `unnecessary_qualification` and `unused_imports`) - #122479 (Implement `Duration::as_millis_{f64,f32}`) - #122487 (Rename `StmtKind::Local` variant into `StmtKind::Let`) - #122498 (Update version of cc crate) - #122503 (Make `SubdiagMessageOp` well-formed) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-14Fill in HIR hash for associated opaque typesVadim Petrochenkov-0/+27
2024-03-14remove unnecessary sized checksLukas Markeffsky-4/+7
2024-03-14clean up ADT sized constraint computationLukas Markeffsky-7/+7
2024-03-14make `Representability::Infinite` carry `ErrorGuaranteed`Lukas Markeffsky-6/+6
2024-03-14hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id`Vadim Petrochenkov-18/+5
Also replace a few `hir_node()` calls with `hir_node_by_def_id()`
2024-03-14Rollup merge of #122487 - GuillaumeGomez:rename-stmtkind-local, r=oli-obkMatthias Krüger-1/+1
Rename `StmtKind::Local` variant into `StmtKind::Let` It comes from this [discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Improve.20naming.20of.20.60ExprKind.3A.3ALet.60.3F). Starting point was: > I often end up looking at [ExprKind::Let](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/enum.ExprKind.html#variant.Let) instead of Local because of the name. I think renaming it (both the `ExprKind` variant and the Let struct) to `LetPattern` or LetPat could improve the situation as I'm not sure I'm not the only one encountering this issue. And then it evolved into: > It's already `Expr::Let` instead of `StmtKind::Local`. Counterproposal: rename `StmtKind::Local` to `StmtKind::Let`. The goal here is to clear this confusion. r? `@oli-obk`
2024-03-14Rollup merge of #122322 - Zalathar:branch, r=oli-obkMatthias Krüger-2/+82
coverage: Initial support for branch coverage instrumentation (This is a review-ready version of the changes that were drafted in #118305.) This PR adds support for branch coverage instrumentation, gated behind the unstable flag value `-Zcoverage-options=branch`. (Coverage instrumentation must also be enabled with `-Cinstrument-coverage`.) During THIR-to-MIR lowering (MIR building), if branch coverage is enabled, we collect additional information about branch conditions and their corresponding then/else blocks. We inject special marker statements into those blocks, so that the `InstrumentCoverage` MIR pass can reliably identify them even after the initially-built MIR has been simplified and renumbered. The rest of the changes are mostly just plumbing needed to gather up the information that was collected during MIR building, and include it in the coverage metadata that we embed in the final binary. Note that `llvm-cov show` doesn't print branch coverage information in its source views by default; that needs to be explicitly enabled with `--show-branches=count` or similar. --- The current implementation doesn't have any support for instrumenting `if let` or let-chains. I think it's still useful without that, and adding it would be non-trivial, so I'm happy to leave that for future work.
2024-03-14Auto merge of #119849 - lcnr:eagerly-instantiate-binders, r=compiler-errorsbors-0/+1
more eagerly instantiate binders The old solver sometimes incorrectly used `sub`, change it to explicitly instantiate binders and use `eq` instead. While doing so I also moved the instantiation before the normalize calls. This caused some observable changes, will explain these inline. This PR therefore requires a crater run and an FCP. r? types
2024-03-14Auto merge of #122497 - matthiaskrgr:rollup-pg9ux4r, r=matthiaskrgrbors-2/+3
Rollup of 10 pull requests Successful merges: - #119029 (Avoid closing invalid handles) - #122238 (Document some builtin impls in the next solver) - #122247 (rustdoc-search: depth limit `T<U>` -> `U` unboxing) - #122287 (add test ensuring simd codegen checks don't run when a static assertion failed) - #122368 (chore: remove repetitive words) - #122397 (Various cleanups around the const eval query providers) - #122406 (Fix WF for `AsyncFnKindHelper` in new trait solver) - #122477 (Change some attribute to only_local) - #122482 (Ungate the `UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES` lint) - #122490 (Update build instructions for OpenHarmony) Failed merges: - #122471 (preserve span when evaluating mir::ConstOperand) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-14eagerly instantiate binders to avoid relying on `sub`lcnr-0/+1
2024-03-14Rollup merge of #122406 - compiler-errors:next-solver-asynckind-wf, r=lcnrMatthias Krüger-2/+3
Fix WF for `AsyncFnKindHelper` in new trait solver `to_opt_closure_kind` ICEs when it sees placeholders... so don't do that no test b/c I'm too lazy to write a no-core test for this, but I could be convinced otherwise r? lcnr
2024-03-14Rename `hir::StmtKind::Local` into `hir::StmtKind::Let`Guillaume Gomez-1/+1
2024-03-14coverage: Include recorded branch info in coverage instrumentationZalathar-1/+8
2024-03-14Add compiler support for parsing `f16` and `f128`Trevor Gross-2/+64
2024-03-14coverage: Data structures for recording branch info during MIR buildingZalathar-2/+51
2024-03-13Create some minimal HIR for associated opaque typesVadim Petrochenkov-17/+21
2024-03-13coverage: Add `CoverageKind::BlockMarker`Zalathar-0/+17
2024-03-13coverage: Make `is_eligible_for_coverage` a hook methodZalathar-0/+7
This will allow MIR building to check whether a function is eligible for coverage instrumentation, and avoid collecting branch coverage info if it is not.