about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2025-02-06coverage: Defer part of counter-creation until codegenZalathar-34/+55
2025-02-06coverage: Store BCB node IDs in mappings, and resolve them in codegenZalathar-23/+28
Even though the coverage graph itself is no longer available during codegen, its nodes can still be used as opaque IDs.
2025-02-05Rollup merge of #136563 - nnethercote:clean-up-Trivials, r=lcnrJubilee-155/+121
Clean up `Trivial*Impls` macros They're currently quite messy. Details in the individual commit logs. r? `@lcnr`
2025-02-06Fix whitespace in lift macros.Nicholas Nethercote-20/+28
This has been bugging me for some time.
2025-02-06Clean up trivial traversal/lift impl generator macro calls.Nicholas Nethercote-140/+98
We have four macros for generating trivial traversal (fold/visit) and lift impls. - `rustc_ir::TrivialTypeTraversalImpls` - `rustc_middle::TrivialTypeTraversalImpls` - `rustc_middle::TrivialLiftImpls` - `rustc_middle::TrivialTypeTraversalAndLiftImpls` The first two are very similar. The last one just combines the second and third one. The macros themselves are ok, but their use is a mess. This commit does the following. - Removes types that no longer need a lift and/or traversal impl from the macro calls. - Consolidates the macro calls into the smallest number of calls possible, with each one mentioning as many types as possible. - Orders the types within those macro calls alphabetically, and makes the module qualification more consistent. - Eliminates `rustc_middle::mir::type_foldable`, because the macro calls were merged and the manual `TypeFoldable` impls are better placed in `structural_impls.rs`, alongside all the other ones. This makes the code more concise. Moving forward, it also makes it more obvious where new types should be added.
2025-02-05Eagerly detect coroutine recursion pre-mono when possibleMichael Goulet-56/+2
2025-02-05try to suggest eliding redundant binding modifiersdianne-1/+3
2025-02-05Removed dependency on the field-offset crate.David Venhoek-3/+4
2025-02-05Pretty print pattern type values with `transmute` if they don't satisfy ↵Oli Scherer-1/+5
their pattern
2025-02-05Rollup merge of #128045 - pnkfelix:rustc-contracts, r=oli-obkLeón Orell Valerian Liehr-1/+6
#[contracts::requires(...)] + #[contracts::ensures(...)] cc https://github.com/rust-lang/rust/issues/128044 Updated contract support: attribute syntax for preconditions and postconditions, implemented via a series of desugarings that culminates in: 1. a compile-time flag (`-Z contract-checks`) that, similar to `-Z ub-checks`, attempts to ensure that the decision of enabling/disabling contract checks is delayed until the end user program is compiled, 2. invocations of lang-items that handle invoking the precondition, building a checker for the post-condition, and invoking that post-condition checker at the return sites for the function, and 3. intrinsics for the actual evaluation of pre- and post-condition predicates that third-party verification tools can intercept and reinterpret for their own purposes (e.g. creating shims of behavior that abstract away the function body and replace it solely with the pre- and post-conditions). Known issues: * My original intent, as described in the MCP (https://github.com/rust-lang/compiler-team/issues/759) was to have a rustc-prefixed attribute namespace (like rustc_contracts::requires). But I could not get things working when I tried to do rewriting via a rustc-prefixed builtin attribute-macro. So for now it is called `contracts::requires`. * Our attribute macro machinery does not provide direct support for attribute arguments that are parsed like rust expressions. I spent some time trying to add that (e.g. something that would parse the attribute arguments as an AST while treating the remainder of the items as a token-tree), but its too big a lift for me to undertake. So instead I hacked in something approximating that goal, by semi-trivially desugaring the token-tree attribute contents into internal AST constucts. This may be too fragile for the long-term. * (In particular, it *definitely* breaks when you try to add a contract to a function like this: `fn foo1(x: i32) -> S<{ 23 }> { ... }`, because its token-tree based search for where to inject the internal AST constructs cannot immediately see that the `{ 23 }` is within a generics list. I think we can live for this for the short-term, i.e. land the work, and continue working on it while in parallel adding a new attribute variant that takes a token-tree attribute alongside an AST annotation, which would completely resolve the issue here.) * the *intent* of `-Z contract-checks` is that it behaves like `-Z ub-checks`, in that we do not prematurely commit to including or excluding the contract evaluation in upstream crates (most notably, `core` and `std`). But the current test suite does not actually *check* that this is the case. Ideally the test suite would be extended with a multi-crate test that explores the matrix of enabling/disabling contracts on both the upstream lib and final ("leaf") bin crates.
2025-02-04Auto merge of #136115 - Mark-Simulacrum:shard-alloc-id, r=RalfJungbors-26/+44
Shard AllocMap Lock This improves performance on many-seed parallel (-Zthreads=32) miri executions from managing to use ~8 cores to using 27-28 cores, which is about the same as what I see with the data structure proposed in https://github.com/rust-lang/rust/pull/136105 - I haven't analyzed but I suspect the sharding might actually work out better if we commonly insert "densely" since sharding would split the cache lines and the OnceVec packs locks close together. Of course, we could do something similar with the bitset lock too. Either way, this seems like a very reasonable starting point that solves the problem ~equally well on what I can test locally. r? `@RalfJung`
2025-02-04Rollup merge of #136284 - oli-obk:push-zsxuwnzmonnl, r=lcnrMatthias Krüger-0/+2
Allow using named consts in pattern types This required a refactoring first: I had to stop using `hir::Pat`in `hir::TyKind::Pat` and instead create a separate `TyPat` that has `ConstArg` for range ends instead of `PatExpr`. Within the type system we should be using `ConstArg` for all constants, as otherwise we'd be maintaining two separate const systems that could diverge. The big advantage of this PR is that we now inherit all the rules from const generics and don't have a separate system. While this makes things harder for users (const generic rules wrt what is allowed in those consts), it also means we don't accidentally allow some things like referring to assoc consts or doing math on generic consts.
2025-02-04experimentally label the spans for default binding modesdianne-4/+2
2025-02-04Rollup merge of #136465 - nnethercote:rustc_middle-MORE, r=jieyouxuJacob Pratt-135/+45
Some `rustc_middle` cleanups Small cleanups I found while looking closely at this code. r? `@jieyouxu`
2025-02-03highlight the whole problem subpattern when pointing out the default binding ↵dianne-2/+4
mode
2025-02-04Two minor `use` fixups.Nicholas Nethercote-4/+2
I *think* this addresses what the `FIXME` comments are asking for.
2025-02-04Fix an inconsistent import.Nicholas Nethercote-3/+2
2025-02-04Update top-level `rustc_middle` comment.Nicholas Nethercote-2/+3
- Mention THIR. - Removed mentions of non-existent READMEs.
2025-02-04Simplify `thir_with_elements` macro.Nicholas Nethercote-13/+3
The `field_name`/`field_ty` don't need to be parameters, they can be hardcoded.
2025-02-04Remove `impl_for_typed_def_id` macro.Nicholas Nethercote-41/+35
It has a single call site and removing it makes the code simpler. Perhaps there were more uses at some point in the past?
2025-02-04Remove comment duplication.Nicholas Nethercote-12/+0
The same comments are on the `DepNodeExt` trait and the single impl of that trait, immediately below. This commit eliminates the duplication.
2025-02-04Remove `dep_node` comment duplication.Nicholas Nethercote-58/+0
`rustc_middle` and `rustc_query_system` both have a file called `dep_node.rs` with a big comment at the top, and the comments are very similar. The one in `rustc_query_system` looks like the original, and the one in `rustc_middle` is a copy with some improvements. This commit removes the comment from `rustc_middle` and updates the one in `rustc_query_system` to include the improvements. I did it this way because `rustc_query_system` is the crate that defines `DepNode`, and so seems like the right place for the comment.
2025-02-04Remove unused features from `rustc_middle`.Nicholas Nethercote-2/+0
2025-02-03Contracts core intrinsics.Felix S. Klock II-1/+6
These are hooks to: 1. control whether contract checks are run 2. allow 3rd party tools to intercept and reintepret the results of running contracts.
2025-02-03Rollup merge of #136484 - Zalathar:query-cache-notes, r=jieyouxuMatthias Krüger-0/+6
Notes on types/traits used for in-memory query caching When the word "cache" appears in the context of the query system, it often isn't obvious whether that is referring to the in-memory query cache or the on-disk incremental cache. For these types, we can assure the reader that they are for in-memory caching.
2025-02-03Rollup merge of #136430 - FedericoBruzzone:follow-up-136180, r=oli-obkMatthias Krüger-50/+52
Use the type-level constant value `ty::Value` where needed **Follow-up to #136180** ### Summary This PR refactors functions to accept a single type-level constant value `ty::Value` instead of separate `ty::ValTree` and `ty::Ty` parameters: - `valtree_to_const_value`: now takes `ty::Value` - `pretty_print_const_valtree`: now takes `ty::Value` - Uses `pretty_print_const_valtree` for formatting valtrees when `visit_const_operand` - Moves `try_to_raw_bytes` from `ty::Valtree` to `ty::Value` --- r? ``@lukas-code`` ``@oli-obk``
2025-02-03Move `try_to_raw_bytes` from `ty::Valtree` to `ty::Value`FedericoBruzzone-37/+34
Signed-off-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
2025-02-03Refactor using the type-level constant value `ty::Value`FedericoBruzzone-32/+37
Signed-off-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
2025-02-03Notes on types/traits used for in-memory query cachingZalathar-0/+6
When the word "cache" appears in the context of the query system, it often isn't obvious whether that is referring to the in-memory query cache or the on-disk incremental cache. For these types, we can assure the reader that they are for in-memory caching.
2025-02-03Rollup merge of #136464 - nnethercote:rm-TyCtxtAt-for-hooks, r=oli-obk许杰友 Jieyou Xu (Joe)-17/+3
Remove hook calling via `TyCtxtAt`. All hooks receive a `TyCtxtAt` argument. Currently hooks can be called through `TyCtxtAt` or `TyCtxt`. In the latter case, a `TyCtxtAt` is constructed with a dummy span and passed to the hook. However, in practice hooks are never called through `TyCtxtAt`, and always receive a dummy span. (I confirmed this via code inspection, and double-checked it by temporarily making the `TyCtxtAt` code path panic and running all the tests.) This commit removes all the `TyCtxtAt` machinery for hooks. All hooks now receive `TyCtxt` instead of `TyCtxtAt`. There are two existing hooks that use `TyCtxtAt::span`: `const_caller_location_provider` and `try_destructure_mir_constant_for_user_output`. For both hooks the span is always a dummy span, probably unintentionally. This dummy span use is now explicit. If a non-dummy span is needed for these two hooks it would be easy to add it as an extra argument because hooks are less constrained than queries. r? `@oli-obk`
2025-02-03Rollup merge of #136455 - nnethercote:less-Clone, r=compiler-errors许杰友 Jieyou Xu (Joe)-22/+22
Remove some `Clone` bounds and derives. r? `@cjgillot`
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-24/+24
2025-02-03reword pattern migration diagnostic to make sense in all editionsdianne-6/+18
This aligns the main error message a bit more with the phrasing in the Edition Guide and provides a bit more information on the labels to (hopefully!) aid in understanding.
2025-02-03Use a different hir type for patterns in pattern types than we use in match ↵Oli Scherer-0/+2
patterns
2025-02-03Auto merge of #133138 - azhogin:azhogin/target-modifiers, r=davidtwco,saethlinbors-0/+1
Target modifiers (special marked options) are recorded in metainfo Target modifiers (special marked options) are recorded in metainfo and compared to be equal in different linked crates. PR for this RFC: https://github.com/rust-lang/rfcs/pull/3716 Option may be marked as `TARGET_MODIFIER`, example: `regparm: Option<u32> = (None, parse_opt_number, [TRACKED TARGET_MODIFIER]`. If an TARGET_MODIFIER-marked option has non-default value, it will be recorded in crate metainfo as a `Vec<TargetModifier>`: ``` pub struct TargetModifier { pub opt: OptionsTargetModifiers, pub value_name: String, } ``` OptionsTargetModifiers is a macro-generated enum. Option value code (for comparison) is generated using `Debug` trait. Error example: ``` error: mixing `-Zregparm` will cause an ABI mismatch in crate `incompatible_regparm` --> $DIR/incompatible_regparm.rs:10:1 | LL | #![crate_type = "lib"] | ^ | = help: the `-Zregparm` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely = note: `-Zregparm=1` in this crate is incompatible with `-Zregparm=2` in dependency `wrong_regparm` = help: set `-Zregparm=2` in this crate or `-Zregparm=1` in `wrong_regparm` = help: if you are sure this will not cause problems, use `-Cunsafe-allow-abi-mismatch=regparm` to silence this error error: aborting due to 1 previous error ``` `-Cunsafe-allow-abi-mismatch=regparm,reg-struct-return` to disable list of flags.
2025-02-03Remove hook calling via `TyCtxtAt`.Nicholas Nethercote-17/+3
All hooks receive a `TyCtxtAt` argument. Currently hooks can be called through `TyCtxtAt` or `TyCtxt`. In the latter case, a `TyCtxtAt` is constructed with a dummy span and passed to the hook. However, in practice hooks are never called through `TyCtxtAt`, and always receive a dummy span. (I confirmed this via code inspection, and double-checked it by temporarily making the `TyCtxtAt` code path panic and running all the tests.) This commit removes all the `TyCtxtAt` machinery for hooks. All hooks now receive `TyCtxt` instead of `TyCtxtAt`. There are two existing hooks that use `TyCtxtAt::span`: `const_caller_location_provider` and `try_destructure_mir_constant_for_user_output`. For both hooks the span is always a dummy span, probably unintentionally. This dummy span use is now explicit. If a non-dummy span is needed for these two hooks it would be easy to add it as an extra argument because hooks are less constrained than queries.
2025-02-03Avoid double-boxing lists of THIR subpatternsZalathar-7/+7
2025-02-03Remove `'pat` lifetime from some match-lowering data structuresZalathar-1/+2
By storing `PatRange` in an Arc, and copying a few fields out of `Pat`, we can greatly simplify the lifetimes involved in match lowering.
2025-02-03Derive `Clone` on fewer THIR types.Nicholas Nethercote-22/+22
Some of these were never necessary, and some were facilitated by the previous commit.
2025-02-02Rollup merge of #136425 - nnethercote:mv-rustc_middle-infer, r=lcnrMatthias Krüger-175/+0
Move `rustc_middle::infer::unify_key` `rustc_infer` is a much better place for it. r? `@lcnr`
2025-02-02Rollup merge of #136422 - nnethercote:convert-lint-functions, r=NoratriebMatthias Krüger-37/+3
Convert two `rustc_middle::lint` functions to `Span` methods. `rustc_middle` is a huge crate and it's always good to move stuff out of it. There are lots of similar methods already on `Span`, so these two functions, `in_external_macro` and `is_from_async_await`, fit right in. The diff is big because `in_external_macro` is used a lot by clippy lints. r? ``@Noratrieb``
2025-02-02Rollup merge of #136394 - saethlin:clean-up-instantiation-mode, ↵Matthias Krüger-42/+79
r=compiler-errors Clean up MonoItem::instantiation_mode More progress on cleaning up and documenting instantiation mode selection. This should have no behavior changes at all, it just rearranges the code inside `MonoItem::instantiation_mode` to a more logical flow and I've tried to explain every choice the implementation is making.
2025-02-02Target modifiers (special marked options) are recorded in metainfo and ↵Andrew Zhogin-0/+1
compared to be equal in different crates
2025-02-02Rollup merge of #136368 - estebank:listify, r=fee1-deadMatthias Krüger-10/+6
Make comma separated lists of anything easier to make for errors Provide a new function `listify`, meant to be used in cases similar to `pluralize!`. When you have a slice of arbitrary elements that need to be presented to the user, `listify` allows you to turn that into a list of comma separated strings. This reduces a lot of redundant logic that happens often in diagnostics.
2025-02-02Rollup merge of #136328 - estebank:long-ty-path, r=jieyouxu,lqdMatthias Krüger-41/+93
Rework "long type names" printing logic Make it so more type-system types can be printed in a shortened version (like `Predicate`s). Centralize printing the information about the "full type name path". Make the "long type path" for the file where long types are written part of `Diag`, so that it becomes easier to keep track of it, and ensure it will always will be printed out last in the diagnostic by making its addition to the output implicit. Tweak the shortening of types in "expected/found" labels. Remove dead file `note.rs`.
2025-02-02Rollup merge of #136279 - Zalathar:ensure-ok, r=oli-obkMatthias Krüger-36/+77
Rename `tcx.ensure()` to `tcx.ensure_ok()`, and improve the associated docs This is all based on my archaeology for https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.60TyCtxtEnsure.60. The main renamings are: - `tcx.ensure()` → `tcx.ensure_ok()` - `tcx.ensure_with_value()` → `tcx.ensure_done()` - Query modifier `ensure_forwards_result_if_red` → `return_result_from_ensure_ok` Hopefully these new names are a better fit for the *actual* function and purpose of these query call modes.
2025-02-02Move `unify_key` module.Nicholas Nethercote-171/+0
From `rustc_middle::infer` to `rustc_infer::infer`. Because everything in it is only used within `rustc_infer`, and no longer needs to be `pub`. Plus it's always good to make the huge `rustc_middle` crate smaller.
2025-02-02Remove unused `ToType` trait.Nicholas Nethercote-5/+1
2025-02-02Convert two `rustc_middle::lint` functions to `Span` methods.Nicholas Nethercote-37/+3
`rustc_middle` is a huge crate and it's always good to move stuff out of it. There are lots of similar methods already on `Span`, so these two functions, `in_external_macro` and `is_from_async_await`, fit right in. The diff is big because `in_external_macro` is used a lot by clippy lints.
2025-02-01Shard AllocMap LockMark Rousskov-26/+44
This improves performance on many-seed parallel (-Zthreads=32) miri executions from managing to use ~8 cores to using 27-28 cores. That's pretty reasonable scaling for the simplicity of this solution.