about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2025-04-07Enable contracts for const functionsCelina G. Val-12/+15
Use `const_eval_select!()` macro to enable contract checking only at runtime. The existing contract logic relies on closures, which are not supported in constant functions. This commit also removes one level of indirection for ensures clauses, however, it currently has a spurious warning message when the bottom of the function is unreachable.
2025-04-07Restrict some queries by def-kind moreMichael Goulet-26/+43
2025-04-07Rollup merge of #139466 - compiler-errors:trivial-incr-tainting, r=oli-obkStuart Cook-16/+20
Trivial tweaks to stop tracking source span directly Firstly, remove some unnecessary work from `sccs_info`. This included debug printing which ends up giving all mir borrowck queries a dependency edge from the query to `source_span` (I think?). Secondly, turn some calls from `hir_span` (which does some span adjustment, and thus incurs span tracking, which causes a dependency edge from the query to `source_span`) to `def_span`, which should cache better. r? oli-obk
2025-04-07Rollup merge of #139465 - EnzymeAD:autodiff-sret, r=oli-obkStuart Cook-2/+28
add sret handling for scalar autodiff r? `@oli-obk` Fixing one of the todo's which I left in my previous batching PR. This one handles sret for scalar autodiff. `sret` mostly shows up when we try to return a lot of scalar floats. People often start testing autodiff which toy functions which just use a few scalars as inputs and outputs, and those were the most likely to be affected by this issue. So this fix should make learning/teaching hopefully a bit easier. Tracking: - https://github.com/rust-lang/rust/issues/124509
2025-04-07Rollup merge of #139461 - compiler-errors:significant-drop-span, r=oli-obkStuart Cook-18/+4
Stop calling `source_span` query in significant drop order code `source_span` is only meant for incremental tracking. I don't really think we need to highlight the whole drop impl span anyways; it can be quite large. r? oli-obk
2025-04-07Rollup merge of #139455 - Skgland:remove_rust-intrinsic_ABI, r=oli-obkStuart Cook-152/+86
Remove support for `extern "rust-intrinsic"` blocks Part of rust-lang/rust#132735 Looked manageable and there didn't appear to have been progress in the last two weeks, so decided to give it a try.
2025-04-07Rollup merge of #139397 - Zalathar:virtual, r=jieyouxuStuart Cook-88/+110
coverage: Build the CGU's global file table as late as possible Embedding coverage metadata in the output binary is a delicate dance, because per-function records need to embed references to the per-CGU filename table, but we only want to include files in that table if they are successfully used by at least one function. The way that we build the file tables has changed a few times over the last few years. This particular change is motivated by experimental work on properly supporting macro-expansion regions, which adds some additional constraints that our previous implementation wasn't equipped to deal with. LLVM is very strict about not allowing unused entries in local file tables. Currently that's not much of an issue, because we assume one source file per function, but to support expansion regions we need the flexibility to avoid committing to the use of a file until we're completely sure that we are able and willing to produce at least one coverage mapping region for it. In particular, when preparing a function's covfun record, we need the flexibility to decide at a late stage that a particular file isn't needed/usable after all. (It's OK for the *global* file table to contain unused entries, but we would still prefer to avoid that if possible, and this implementation also achieves that.)
2025-04-07Rollup merge of #139365 - Bryanskiy:leak-perf, r=lcnrStuart Cook-35/+51
Default auto traits: fix perf Skip computing `requires_default_supertraits` if `experimental-default-bounds` option is not enabled. Possible perf fix for https://github.com/rust-lang/rust/pull/120706 r? lcnr
2025-04-07Rollup merge of #139112 - m-ou-se:super-let, r=lcnrStuart Cook-31/+119
Implement `super let` Tracking issue: https://github.com/rust-lang/rust/issues/139076 This implements `super let` as proposed in #139080, based on the following two equivalence rules. 1. For all expressions `$expr` in any context, these are equivalent: - `& $expr` - `{ super let a = & $expr; a }` 2. And, additionally, these are equivalent in any context when `$expr` is a temporary (aka rvalue): - `& $expr` - `{ super let a = $expr; & a }` So far, this experiment has a few interesting results: ## Interesting result 1 In this snippet: ```rust super let a = f(&temp()); ``` I originally expected temporary `temp()` would be dropped at the end of the statement (`;`), just like in a regular `let`, because `temp()` is not subject to temporary lifetime extension. However, it turns out that that would break the fundamental equivalence rules. For example, in ```rust g(&f(&temp())); ``` the temporary `temp()` will be dropped at the `;`. The first equivalence rule tells us this must be equivalent: ```rust g({ super let a = &f(&temp()); a }); ``` But that means that `temp()` must live until the last `;` (after `g()`), not just the first `;` (after `f()`). While this was somewhat surprising to me at first, it does match the exact behavior we need for `pin!()`: The following _should work_. (See also https://github.com/rust-lang/rust/issues/138718) ```rust g(pin!(f(&mut temp()))); ``` Here, `temp()` lives until the end of the statement. This makes sense from the perspective of the user, as no other `;` or `{}` are visible. Whether `pin!()` uses a `{}` block internally or not should be irrelevant. This means that _nothing_ in a `super let` statement will be dropped at the end of that super let statement. It does not even need its own scope. This raises questions that are useful for later on: - Will this make temporaries live _too long_ in cases where `super let` is used not in a hidden block in a macro, but as a visible statement in code like the following? ```rust let writer = { super let file = File::create(&format!("/home/{user}/test")); Writer::new(&file) }; ``` - Is a `let` statement in a block still the right syntax for this? Considering it has _no_ scope of its own, maybe neither a block nor a statement should be involved This leads me to think that instead of `{ super let $pat = $init; $expr }`, we might want to consider something like `let $pat = $init in $expr` or `$expr where $pat = $init`. Although there are also issues with these, as it isn't obvious anymore if `$init` should be subject to temporary lifetime extension. (Do we want both `let _ = _ in ..` and `super let _ = _ in ..`?) ## Interesting result 2 What about `super let x;` without initializer? ```rust let a = { super let x; x = temp(); &x }; ``` This works fine with the implementation in this PR: `x` is extended to live as long as `a`. While it matches my expectations, a somewhat interesting thing to realize is that these are _not_ equivalent: - `super let x = $expr;` - `super let x; x = $expr;` In the first case, all temporaries in $expr will live at least as long as (the result of) the surrounding block. In the second case, temporaries will be dropped at the end of the assignment statement. (Because the assignment statement itself "is not `super`".) This difference in behavior might be confusing, but it _might_ be useful. One might want to extend the lifetime of a variable without extending all the temporaries in the initializer expression. On the other hand, that can also be expressed as: - `let x = $expr; super let x = x;` (w/o temporary lifetime extension), or - `super let x = { $expr };` (w/ temporary lifetime extension) So, this raises these questions: - Do we want to accept `super let x;` without initializer at all? - Does it make sense for statements other than let statements to be "super"? An expression statement also drops temporaries at its `;`, so now that we discovered that `super let` basically disables that `;` (see interesting result 1), is there a use to having other statements without their own scope? (I don't think that's ever useful?) ## Interesting result 3 This works now: ```rust super let Some(x) = a.get(i) else { return }; ``` I didn't put in any special cases for `super let else`. This is just the behavior that 'naturally' falls out when implementing `super let` without thinking of the `let else` case. - Should `super let else` work? ## Interesting result 4 This 'works': ```rust fn main() { super let a = 123; } ``` I didn't put in any special cases for `super let` at function scope. I had expected the code to cause an ICE or other weird failure when used at function body scope, because there's no way to let the variable live as long as the result of the function. This raises the question: - Does this mean that this behavior is the natural/expected behavior when `super let` is used at function scope? Or is this just a quirk and should we explicitly disallow `super let` in a function body? (Probably the latter.) --- The questions above do not need an answer to land this PR. These questions should be considered when redesigning/rfc'ing/stabilizing the feature.
2025-04-07Rollup merge of #139108 - Nadrieril:simplify-expandedconstant, r=oli-obkStuart Cook-124/+95
Simplify `thir::PatKind::ExpandedConstant` I made it a bit less ad-hoc. In particular, I removed `is_inline: bool` that was just caching the output of `tcx.def_kind(def_id)`. This makes inline consts a tiny bit less special in patterns. r? `@oli-obk` cc `@Zalathar`
2025-04-07Rollup merge of #139035 - nnethercote:PatKind-Missing, r=oli-obkStuart Cook-61/+70
Add new `PatKind::Missing` variants To avoid some ugly uses of `kw::Empty` when handling "missing" patterns, e.g. in bare fn tys. Helps with #137978. Details in the individual commits. r? ``@oli-obk``
2025-04-07handle sret for scalar autodiffManuel Drehwald-2/+28
2025-04-07rm `RegionInferenceContext::var_infos`lcnr-14/+8
we already track this info in the `definitions` field
2025-04-07coverage: Build the CGU's global file table as late as possibleZalathar-88/+110
2025-04-07Auto merge of #139473 - Kobzol:rollup-ycksn9b, r=Kobzolbors-72/+88
Rollup of 5 pull requests Successful merges: - #138314 (fix usage of `autodiff` macro with inner functions) - #139426 (Make the UnifyKey and UnifyValue imports non-nightly) - #139431 (Remove LLVM 18 inline ASM span fallback) - #139456 (style guide: add let-chain rules) - #139467 (More trivial tweaks) r? `@ghost` `@rustbot` modify labels: rollup
2025-04-07Rollup merge of #139467 - compiler-errors:more-trivial-tweaks, r=oli-obkJakub Beránek-12/+6
More trivial tweaks Found some really tiny nits when trying to find places that span tracking caused queries to be recomputed in incremental; these probably don't need a perf run b/c they're so simple. r? oli-obk
2025-04-07Rollup merge of #139431 - beetrees:no-llvm-18, r=jieyouxuJakub Beránek-5/+2
Remove LLVM 18 inline ASM span fallback The minimum supported LLVM version is now 19, so this fallback is no longer required.
2025-04-07Rollup merge of #139426 - jackh726:rust-analyzer-next-solver-new, r=lcnrJakub Beránek-7/+3
Make the UnifyKey and UnifyValue imports non-nightly Explicitly depend on ena in rustc_type_ir and import types from there. This is required for rust-analyzer to use the new solver. r? types
2025-04-07Rollup merge of #138314 - haenoe:autodiff-inner-function, r=ZuseZ4Jakub Beránek-48/+77
fix usage of `autodiff` macro with inner functions This PR adds additional handling into the expansion step of the `std::autodiff` macro (in `compiler/rustc_builtin_macros/src/autodiff.rs`), which allows the macro to be applied to inner functions. ```rust #![feature(autodiff)] use std::autodiff::autodiff; fn main() { #[autodiff(d_inner, Forward, Dual, DualOnly)] fn inner(x: f32) -> f32 { x * x } } ``` Previously, the compiler didn't allow this due to only handling `Annotatable::Item` and `Annotatable::AssocItem` and missing the handling of `Annotatable::Stmt`. This resulted in the rather generic error ``` error: autodiff must be applied to function --> src/main.rs:6:5 | 6 | / fn inner(x: f32) -> f32 { 7 | | x * x 8 | | } | |_____^ error: could not compile `enzyme-test` (bin "enzyme-test") due to 1 previous error ``` This issue was originally reported [here](https://github.com/EnzymeAD/rust/issues/184). Quick question: would it make sense to add a ui test to ensure there is no regression on this? This is my first contribution, so I'm extra grateful for any piece of feedback!! :D r? `@oli-obk` Tracking issue for autodiff: #124509
2025-04-07Don't call Span.with_parent on the good path in has_stashed_diagnosticMichael Goulet-26/+44
2025-04-07More trivial tweaksMichael Goulet-12/+6
2025-04-07Trivial tweaks to stop tracking source span directlyMichael Goulet-16/+20
2025-04-07Auto merge of #138766 - Zalathar:unused-fn, r=SparrowLiibors-161/+180
coverage: Deal with unused functions and their names in one place When coverage codegen creates dummy instances and covfun records for unused functions, we already know that they are unused, so we might as well set up the special array of unused function names at the same time. --- The first commit only moves code around; all significant changes are in the second commit. There should be no change in compiler output.
2025-04-06Stop calling source_span query in significant drop order codeMichael Goulet-18/+4
2025-04-06refactor: simplify function-info gatheringHaeNoe-41/+26
2025-04-06update/bless testsBennet Bleßmann-5/+5
2025-04-06update docsBennet Bleßmann-3/+2
- src\doc\nomicon\src\ffi.md should also have its ABI list updated
2025-04-06remove compiler support for `extern "rust-intrinsic"` blocksSkgland-144/+79
2025-04-06fix usage of `autodiff` macro with inner functionsHaeNoe-32/+76
- fix errors caused by the move of `ast::Item::ident` (see #138740) - move the logic of getting `sig`, `vis`, and `ident` from two seperate `match` statements into one (less repetition especially with the nested `match`)
2025-04-06Explicitly depend on ena in rustc_type_ir and make the UnifyKey and ↵jackh726-7/+3
UnifyValue imports non-nightly
2025-04-06Rollup merge of #139414 - Adamkob12:fix_typo_raw_list, r=NadrierilGuillaume Gomez-3/+3
Fix typo in `RawList`'s documentation
2025-04-06Rollup merge of #139391 - TaKO8Ki:check-if-merged-attrs-list-is-empty, ↵Guillaume Gomez-7/+9
r=jdonszelmann Check if merged attributes list is empty in expr Fixes #139373 In the example code, an [`UnrecognizedReprHint`](https://github.com/rust-lang/rust/blob/6b5ccfc87f59ab017032e430d4d358b4989735da/compiler/rustc_attr_parsing/src/attributes/repr.rs#L155) error is output, and the list of merged attributes becomes empty. This causes a [panic](https://github.com/rust-lang/rust/blob/6b5ccfc87f59ab017032e430d4d358b4989735da/compiler/rustc_ast_lowering/src/lib.rs#L618) to occur. So, it's necessary to check if merged attributes list is empty as other functions do. ref: https://github.com/rust-lang/rust/blob/6b5ccfc87f59ab017032e430d4d358b4989735da/compiler/rustc_ast_lowering/src/lib.rs#L896
2025-04-06Rollup merge of #139367 - GuillaumeGomez:proc-macro-values, r=UrgauGuillaume Gomez-742/+13
Add `*_value` methods to proc_macro lib This is the (re-)implementation of https://github.com/rust-lang/libs-team/issues/459. It allows to get the actual value (unescaped) of the different string literals. It was originally done in https://github.com/rust-lang/rust/pull/136355 but it broke the artifacts build so we decided to move the crate to crates.io to go around this limitation. Part of https://github.com/rust-lang/rust/issues/136652. Considering this is a copy-paste of the originally approved PR, no need to go through the whole process again. \o/ r? `@Urgau`
2025-04-06Reuse `parent_args`Nadrieril-12/+3
2025-04-06Add the inline const type annotation in pattern loweringNadrieril-31/+35
2025-04-06Tweak `lower_pat_expr`Nadrieril-35/+33
2025-04-06Remove the `is_inline` field from `PatKind::ExpandedConstant`Nadrieril-51/+32
2025-04-06Let `const_to_pat` handle the `ExpandedConstant` wrappingNadrieril-15/+12
2025-04-06Auto merge of #138947 - madsmtm:refactor-apple-versions, r=Noratriebbors-166/+190
Refactor Apple version handling in the compiler Move various Apple version handling code in the compiler out `rustc_codegen_ssa` and into a place where it can be accessed by `rustc_attr_parsing`, which I found to be necessary when doing https://github.com/rust-lang/rust/pull/136867. Thought I'd split it out to make it easier to land, and to make further changes like https://github.com/rust-lang/rust/pull/131477 have fewer conflicts / PR dependencies. There should be no functional changes in this PR. `@rustbot` label O-apple r? rust-lang/compiler
2025-04-06coverage: Deal with unused functions and their names in one placeZalathar-39/+51
2025-04-06coverage: Extract module `mapgen::unused` for handling unused functionsZalathar-125/+132
2025-04-05Tell LLVM about impossible niche tagsScott McMurray-0/+28
2025-04-06Auto merge of #139411 - yotamofek:pr/mir_transform/instsimplify, ↵bors-3/+3
r=compiler-errors In `simplify_repeated_aggregate`, don't test first element against itself r? `@saethlin` Noticed that in `InstSimplifyContext::simplify_repeated_aggregate`, we're accidentally evaluating the first element's value twice, and then comparing it with itself, instead of just checking whether the rest of the elements are equal to the first one. This will probably save very few cycles, but since `InstSimplify` is always enabled, this might improve perf by a bit.
2025-04-06Remove LLVM 18 inline ASM span fallbackbeetrees-5/+2
2025-04-05Auto merge of #139275 - cuviper:min-llvm-19, r=nikicbors-233/+47
Update the minimum external LLVM to 19 With this change, we'll have stable support for LLVM 19 and 20. For reference, the previous increase to LLVM 18 was #130487. cc `@rust-lang/wg-llvm` r? nikic
2025-04-05Suppress missing field error when autoderef bottoms out in inferMichael Goulet-2/+7
2025-04-05Fix trait upcasting to dyn type with no principal when there are projectionsMichael Goulet-14/+24
2025-04-05Update the minimum external LLVM to 19Josh Stone-233/+47
2025-04-05Rollup merge of #139404 - yotamofek:pr/smir/cleanup, r=compiler-errorsMatthias Krüger-26/+12
Small smir cleanup First commit might have small positive perf effect, second one is just to make code a bit shorter
2025-04-05Rollup merge of #139319 - makai410:refactor, r=celinvalMatthias Krüger-302/+344
StableMIR: Prepare for refactoring Temporarily make `stable_mir` "parasitic" on the `rustc_smir` crate. It aims to resolve the circular dependency that would arise if we directly invert the dependency order between `rustc_smir` and `stable_mir`. Once the refactoring is complete (`rustc_smir` does not depend on `stable_mir`), we will migrate it back to the `stable_mir` crate. See more details: [here](https://hackmd.io/jBRkZLqAQL2EVgwIIeNMHg).