summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2024-08-04Disable jump threading of float equalityNilstrieb-0/+7
Jump threading stores values as `u128` (`ScalarInt`) and does its comparisons for equality as integer comparisons. This works great for integers. Sadly, not everything is an integer. Floats famously have wonky equality semantcs, with `NaN!=NaN` and `0.0 == -0.0`. This does not match our beautiful integer bitpattern equality and therefore causes things to go horribly wrong. While jump threading could be extended to support floats by remembering that they're floats in the value state and handling them properly, it's signficantly easier to just disable it for now.
2024-07-05Don't inline drop shims with unsubstituted generic consts in MIR inlinerMichael Goulet-1/+11
(cherry picked from commit f17b27b3014adea0c40df55b31bd2fbbd72e76c4)
2024-06-07Rollup merge of #126077 - oli-obk:revert_is_mir_available, r=BoxyUwUMatthias Krüger-1/+1
Revert "Use the HIR instead of mir_keys for determining whether something will have a MIR body." This reverts commit e5cba17b84bf7bf755686e8bb36aa3775ef53f77. turns out SMIR still needs it (https://github.com/model-checking/kani/issues/3218). I'll create a full plan and MCP for what I intended this to be a part of. Maybe my plan is nonsense anyway.
2024-06-07Revert "Create const block DefIds in typeck instead of ast lowering"Oli Scherer-6/+0
This reverts commit ddc5f9b6c1f21da5d4596bf7980185a00984ac42.
2024-06-07Revert "Cache whether a body has inline consts"Oli Scherer-5/+1
This reverts commit eae5031ecbda434e92966099e0dc93917de03eff.
2024-06-06Revert "Use the HIR instead of mir_keys for determining whether something ↵Oli Scherer-1/+1
will have a MIR body." This reverts commit e5cba17b84bf7bf755686e8bb36aa3775ef53f77.
2024-06-06Auto merge of #125958 - BoxyUwU:remove_const_ty, r=lcnrbors-6/+15
Remove the `ty` field from type system `Const`s Fixes #125556 Fixes #122908 Part of the work on `adt_const_params`/`generic_const_param_types`/`min_generic_const_exprs`/generally making the compiler nicer. cc rust-lang/project-const-generics#44 Please review commit-by-commit otherwise I wasted a lot of time not just squashing this into a giant mess (and also it'll be SO much nicer because theres a lot of fluff changes mixed in with other more careful changes if looking via File Changes --- Why do this? - The `ty` field keeps causing ICEs and weird behaviour due to it either being treated as "part of the const" or it being forgotten about leading to ICEs. - As we move forward with `adt_const_params` and a potential `min_generic_const_exprs` it's going to become more complex to actually lower the correct `Ty<'tcx>` - It muddles the idea behind how we check `Const` arguments have the correct type. By having the `ty` field it may seem like we ought to be relating it when we relate two types, or that its generally important information about the `Const`. - Brings the compiler more in line with `a-mir-formality` as that also tracks the type of type system `Const`s via `ConstArgHasType` bounds in the env instead of on the `Const` itself. - A lot of stuff is a lot nicer when you dont have to pass around the type of a const lol. Everywhere we construct `Const` is now significantly nicer :sweat_smile: See #125671's description for some more information about the `ty` field --- General summary of changes in this PR: - Add `Ty` to `ConstKind::Value` as otherwise there is no way to implement `ConstArgHasType` to ensure that const arguments are correctly typed for the parameter when we stop creating anon consts for all const args. It's also just incredibly difficult/annoying to thread the correct `Ty` around to a bunch of ctfe functions otherwise. - Fully implement `ConstArgHasType` in both the old and new solver. Since it now has no reliance on the `ty` field it serves its originally intended purpose of being able to act as a double check that trait vs impls have correctly typed const parameters. It also will now be able to be responsible for checking types of const arguments to parameters under `min_generic_const_exprs`. - Add `Ty` to `mir::Const::Ty`. I dont have a great understanding of why mir constants are setup like this to be honest. Regardless they need to be able to determine the type of the const and the easiest way to make this happen was to simply store the `Ty` along side the `ty::Const`. Maybe we can do better here in the future but I'd have to spend way more time looking at everywhere we use `mir::Const`. - rustdoc has its own `Const` which also has a `ty` field. It was relatively easy to remove this. --- r? `@lcnr` `@compiler-errors`
2024-06-05Add `Ty` to `mir::Const::Ty`Boxy-6/+15
2024-06-05Auto merge of #126038 - matthiaskrgr:rollup-h4rm3x2, r=matthiaskrgrbors-30/+40
Rollup of 9 pull requests Successful merges: - #124840 (resolve: mark it undetermined if single import is not has any bindings) - #125622 (Winnow private method candidates instead of assuming any candidate of the right name will apply) - #125648 (Remove unused(?) `~/rustsrc` folder from docker script) - #125672 (Add more ABI test cases to miri (RFC 3391)) - #125800 (Fix `mut` static task queue in SGX target) - #125871 (Orphanck[old solver]: Consider opaque types to never cover type parameters) - #125893 (Handle all GVN binops in a single place.) - #126008 (Port `tests/run-make-fulldeps/issue-19371` to ui-fulldeps) - #126032 (Update description of the `IsTerminal` example) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-05Rollup merge of #125893 - cjgillot:gvn-newops, r=oli-obkMatthias Krüger-30/+40
Handle all GVN binops in a single place. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> Addresses https://github.com/rust-lang/rust/pull/125359/files#r1608185319 r? ``@oli-obk``
2024-06-04coverage: Remove hole-carving code from the main span refinerZalathar-80/+19
Now that hole spans are handled by a separate earlier pass, this code never sees hole spans, and therefore doesn't need to deal with them.
2024-06-04coverage: Use hole spans to carve up coverage spans into separate bucketsZalathar-55/+146
This performs the same task as the hole-carving code in the main span refiner, but in a separate earlier pass.
2024-06-04coverage: Build up initial spans by appending to a vectorZalathar-18/+21
This is less elegant than returning an iterator, but more flexible.
2024-06-04coverage: Return a nested vector from initial span extractionZalathar-8/+11
This will allow the span extractor to produce multiple separate buckets, instead of just one flat list of spans.
2024-06-04Auto merge of #122597 - pacak:master, r=bjorn3bors-0/+3
Show files produced by `--emit foo` in json artifact notifications Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`. Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477 Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: https://github.com/hintron/computer-enhance/issues/35 This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files. Most users won't notice this behavior, to be affected by it all of the following must hold: - user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything) - user must specify both `--emit xxx` and `--json artifacts` - user must refuse to handle unknown artifact types - user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit #88829 / #89149
2024-06-03Opt-in diagnostics reporting to avoid doing extra work in the new solverMichael Goulet-1/+1
2024-06-03Reformat `mir!` macro invocations to use braces.Nicholas Nethercote-2/+2
The `mir!` macro has multiple parts: - An optional return type annotation. - A sequence of zero or more local declarations. - A mandatory starting anonymous basic block, which is brace-delimited. - A sequence of zero of more additional named basic blocks. Some `mir!` invocations use braces with a "block" style, like so: ``` mir! { let _unit: (); { let non_copy = S(42); let ptr = std::ptr::addr_of_mut!(non_copy); // Inside `callee`, the first argument and `*ptr` are basically // aliasing places! Call(_unit = callee(Move(*ptr), ptr), ReturnTo(after_call), UnwindContinue()) } after_call = { Return() } } ``` Some invocations use parens with a "block" style, like so: ``` mir!( let x: [i32; 2]; let one: i32; { x = [42, 43]; one = 1; x = [one, 2]; RET = Move(x); Return() } ) ``` And some invocations uses parens with a "tighter" style, like so: ``` mir!({ SetDiscriminant(*b, 0); Return() }) ``` This last style is generally used for cases where just the mandatory starting basic block is present. Its braces are placed next to the parens. This commit changes all `mir!` invocations to use braces with a "block" style. Why? - Consistency is good. - The contents of the invocation is a block of code, so it's odd to use parens. They are more normally used for function-like macros. - Most importantly, the next commit will enable rustfmt for `tests/mir-opt/`. rustfmt is more aggressive about formatting macros that use parens than macros that use braces. Without this commit's changes, rustfmt would break a couple of `mir!` macro invocations that use braces within `tests/mir-opt` by inserting an extraneous comma. E.g.: ``` mir!(type RET = (i32, bool);, { // extraneous comma after ';' RET.0 = 1; RET.1 = true; Return() }) ``` Switching those `mir!` invocations to use braces avoids that problem, resulting in this, which is nicer to read as well as being valid syntax: ``` mir! { type RET = (i32, bool); { RET.0 = 1; RET.1 = true; Return() } } ```
2024-06-02Handle all GVN binops in a single place.Camille GILLOT-30/+40
2024-06-01Add some more specific checks to the MIR validatorScott McMurray-7/+94
None of the `PointerCoercion`s had any, so while there's probably more that could be done here, hopefully these are better than the previous nothing.
2024-06-01Uplift TypeRelation and RelateMichael Goulet-4/+6
2024-06-01Auto merge of #125821 - Luv-Ray:issue#121126, r=fee1-deadbors-2/+6
Check index `value <= 0xFFFF_FF00` <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> fixes #121126 check `idx <= FieldIdx::MAX_AS_U32` before calling `FieldIdx::from_u32` to avoid panic.
2024-06-01check index `value <= 0xFFFF_FF00`Luv-Ray-2/+6
2024-05-31Rollup merge of #125796 - scottmcm:more-inst-simplify, r=oli-obkMatthias Krüger-1/+1
Also InstSimplify `&raw*` We do this for `&*` and `&mut*` already; might as well do it for raw pointers too. r? mir-opt
2024-05-31Auto merge of #124662 - zetanumbers:needs_async_drop, r=oli-obkbors-6/+31
Implement `needs_async_drop` in rustc and optimize async drop glue This PR expands on #121801 and implements `Ty::needs_async_drop` which works almost exactly the same as `Ty::needs_drop`, which is needed for #123948. Also made compiler's async drop code to look more like compiler's regular drop code, which enabled me to write an optimization where types which do not use `AsyncDrop` can simply forward async drop glue to `drop_in_place`. This made size of the async block from the [async_drop test](https://github.com/zetanumbers/rust/blob/67980dd6fb11917d23d01a19c2cf4cfc3978aac8/tests/ui/async-await/async-drop.rs) to decrease by 12%.
2024-05-30Also InstSimplify `&raw*`Scott McMurray-1/+1
We do this for `&*` and `&mut*` already; might as well do it for raw pointers too.
2024-05-31Revert "Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obk"Camille GILLOT-2/+239
This reverts commit cfb730450f847bb622243eaaab15e77e58d91767, reversing changes made to 91c0823ee63e793d990bb9fed898dc95b5d6db51.
2024-05-30Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obkbors-239/+2
Enable DestinationPropagation by default. ~~Based on https://github.com/rust-lang/rust/pull/115291.~~ This PR proposes to enable the destination propagation pass by default. This pass is meant to reduce the amount of copies present in MIR. At the same time, this PR removes the `RenameReturnPlace` pass, as it is currently unsound. `DestinationPropagation` is not limited to `_0`, but does not handle borrowed locals.
2024-05-30Rollup merge of #125754 - Zalathar:conditions-num, r=lqdMatthias Krüger-6/+6
coverage: Rename MC/DC `conditions_num` to `num_conditions` Updated version of #124571, without the other changes that were split out into #125108 and #125700. This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate. Some of the code touched by this PR could perhaps use some other changes, but I would prefer to keep this PR as a simple renaming and avoid scope creep. `@rustbot` label +A-code-coverage
2024-05-30coverage: Rename MC/DC `conditions_num` to `num_conditions`Zalathar-6/+6
This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate.
2024-05-29Enable DestinationPropagation by default.Camille GILLOT-239/+2
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-1/+2
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-29Optimize async drop glue for some old typesDaria Sukhonina-6/+31
2024-05-29Rollup merge of #124251 - scottmcm:unop-ptr-metadata, r=oli-obk许杰友 Jieyou Xu (Joe)-1/+28
Add an intrinsic for `ptr::metadata` The follow-up to #123840, so we can remove `PtrComponents` and `PtrRepr` from libcore entirely (well, after a bootstrap update). As discussed in <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/.60ptr_metadata.60.20in.20MIR/near/435637808>, this introduces `UnOp::PtrMetadata` taking a raw pointer and returning the associated metadata value. By no longer going through a `union`, this should also help future PRs better optimize pointer operations. r? ``@oli-obk``
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-1/+28
2024-05-28Rollup merge of #125637 - nnethercote:rustfmt-fixes, r=GuillaumeGomezMatthias Krüger-5/+3
rustfmt fixes The `rmake.rs` entries in `rustfmt.toml` are causing major problems for `x fmt`. This PR removes them and does some minor related cleanups. r? ``@GuillaumeGomez``
2024-05-28Cache whether a body has inline constsOli Scherer-1/+4
2024-05-28Create const block DefIds in typeck instead of ast loweringOli Scherer-0/+6
2024-05-28Use the HIR instead of mir_keys for determining whether something will have ↵Oli Scherer-1/+1
a MIR body.
2024-05-28Don't format `tests/run-make/*/rmake.rs`.Nicholas Nethercote-5/+3
It's reasonable to want to, but in the current implementation this causes multiple problems. - All the `rmake.rs` files are formatted every time even when they haven't changed. This is because they get whitelisted unconditionally in the `OverrideBuilder`, before the changed files get added. - The way `OverrideBuilder` works, if any files gets whitelisted then no unmentioned files will get traversed. This is surprising, and means that the `rmake.rs` entries broke the use of explicit paths to `x fmt`, and also broke `GITHUB_ACTIONS=true git check --fmt`. The commit removes the `rmake.rs` entries, fixes the formatting of a couple of files that were misformatted (not previously caught due to the `GITHUB_ACTIONS` breakage), and bans `!`-prefixed entries in `rustfmt.toml` because they cause all these problems.
2024-05-27Rollup merge of #125616 - RalfJung:mir-validate-downcast-projection, ↵Matthias Krüger-3/+23
r=compiler-errors MIR validation: ensure that downcast projection is followed by field projection Cc https://github.com/rust-lang/rust/issues/120369
2024-05-27MIR validation: ensure that downcast projection is followed by field projectionRalf Jung-3/+23
2024-05-27Auto merge of #125602 - RalfJung:interpret-mir-lifetime, r=oli-obkbors-12/+11
interpret: get rid of 'mir lifetime I realized our MIR bodies are actually at lifetime `'tcx`, so we don't need to carry around this other lifetime everywhere. r? `@oli-obk`
2024-05-27Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercotebors-14/+8
[perf] Delay the construction of early lint diag structs Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666. See individual commits for details. The first three commits are not strictly necessary. However, the 2nd one (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement. It's also pretty sweet on its own if I may say so myself.
2024-05-27interpret: get rid of 'mir lifetime everywhereRalf Jung-12/+11
2024-05-26Avoid a `FieldIdx::from_usize` in InstSimplifyScott McMurray-5/+4
2024-05-26Rollup merge of #125508 - scottmcm:fix-125506, r=NilstriebMatthias Krüger-0/+5
Stop SRoA'ing `DynMetadata` in MIR Fixes #125506
2024-05-25Stop SRoA'ing `DynMetadata` in MIRScott McMurray-0/+5
2024-05-24compiler: unnest rustc_const_eval::check_constsJubilee Young-2/+2
2024-05-24compiler: const_eval/transform/validate.rs -> mir_transform/validate.rsJubilee Young-2/+1408
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-14/+8
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement