about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2023-05-02Migrate `mir_transform` to translatable diagnosticsclubby789-198/+452
2023-05-02Auto merge of #111082 - saethlin:box-assertkind, r=saethlinbors-3/+3
Box AssertKind r? `@nnethercote` this feels like your kind of thing I want to add a new variant to `AssertKind` that needs 3 operands, and that ends up breaking a bunch of size assertions. So... what if we go the opposite direction first; shrinking `AssertKind` by boxing it?
2023-05-02Auto merge of #109521 - tmiasko:const-prop-validation, r=wesleywiserbors-25/+3
Don't validate constants in const propagation Validation is neither necessary nor desirable. The constant validation is already omitted at mir-opt-level >= 3, so there there are not changes in MIR test output (the propagation of invalid constants is covered by an existing test in tests/mir-opt/const_prop/invalid_constant.rs).
2023-05-01Box AssertKindBen Kimock-3/+3
2023-05-01Auto merge of #111066 - matthiaskrgr:rollup-4k6rj23, r=matthiaskrgrbors-4/+1
Rollup of 7 pull requests Successful merges: - #109540 (std docs: edit `PathBuf::set_file_name` example) - #110093 (Add 64-bit `time_t` support on 32-bit glibc Linux to `set_times`) - #110987 (update wasi_clock_time_api ref.) - #111038 (Leave promoteds untainted by errors when borrowck fails) - #111042 (Add `#[no_coverage]` to the test harness's `fn main`) - #111057 (Make sure the implementation of TcpStream::as_raw_fd is fully inlined) - #111065 (Explicitly document how Send and Sync relate to references) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-04-30Codegen fewer instructions in `mem::replace`Scott McMurray-0/+23
2023-04-30Leave promoteds untainted by errors when borrowck failsTomasz Miąsko-4/+1
Previously, when borrowck failed it would taint all promoteds within the MIR body. An attempt to evaluated the promoteds would subsequently fail with spurious "note: erroneous constant used". For example: ```console ... note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:9 | 7 | a = &0 * &1 * &2 * &3; | ^^ note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:14 | 7 | a = &0 * &1 * &2 * &3; | ^^ note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:19 | 7 | a = &0 * &1 * &2 * &3; | ^^ note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:24 | 7 | a = &0 * &1 * &2 * &3; | ^^ ``` Borrowck failure doesn't indicate that there is anything wrong with promoteds. Leave them untainted.
2023-04-30Rollup merge of #110973 - bindsdev:packed-struct-ref-diagnostic-note, ↵Matthias Krüger-2/+5
r=compiler-errors improve error notes for packed struct reference diagnostic Addresses #110199
2023-04-29Make PlaceMention a non-mutating use.Camille GILLOT-0/+1
2023-04-28improve error notes for packed struct reference diagnosticbindsdev-2/+5
2023-04-28Make drop_flags an IndexVec.Camille GILLOT-7/+8
2023-04-27Auto merge of #110882 - BoxyUwU:rename-some-ty-flags, r=compiler-errorsbors-5/+5
rename `NEEDS_SUBST` and `NEEDS_INFER` implements rust-lang/compiler-team#617
2023-04-27rename `needs_subst` to `has_param`Boxy-5/+5
2023-04-27Auto merge of #110728 - cjgillot:no-false-optes, r=oli-obkbors-38/+46
Do not bother optimizing impossible functions. This is currently checked by `ConstProp`, but I see no reason to restrict it to ConstProp only.
2023-04-27Remove workaround for CastKind::Transmute from const propTomasz Miąsko-10/+0
Since constants are no longer validated before propagation the workaround is obsolete. Remove it.
2023-04-27Don't validate constants before propagationTomasz Miąsko-15/+3
Validation is neither necessary nor desirable. The validation is already omitted at mir-opt-level >= 3, so there there are not changes in MIR test output (the propagation of invalid constants is covered by an existing test in tests/mir-opt/const_prop/invalid_constant.rs).
2023-04-26Auto merge of #110822 - scottmcm:lower-offset-to-mir, r=compiler-errorsbors-0/+17
Lower `intrinsics::offset` to `mir::BinOp::Offset` They're [semantically the same](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.Rvalue.html#variant.BinaryOp), so this means the backends don't need to handle the intrinsic and means fewer MIR basic blocks in pointer arithmetic code.
2023-04-26Auto merge of #97368 - tmandry:coverage-underflow, r=jyn514bors-1/+1
coverage: Don't underflow column number I noticed this when running coverage on a debug build of rustc. There may be other places that do this but I'm just fixing the one I hit. r? `@wesleywiser` `@richkadel`
2023-04-25Lower `intrinsics::offset` to `mir::BinOp::Offset`Scott McMurray-0/+17
They're semantically the same, so this means the backends don't need to handle the intrinsic and means fewer MIR basic blocks in pointer arithmetic code.
2023-04-25Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, ↵Matthias Krüger-1/+1
r=compiler-errors Switch to `EarlyBinder` for `explicit_item_bounds` Part of the work to finish https://github.com/rust-lang/rust/issues/105779. This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`. r? `@compiler-errors` (hope it's okay to request you, since you reviewed #110299 and #110498 :smiley:)
2023-04-25Move unstatisfaction check earlier.Camille GILLOT-50/+44
2023-04-24Fully clear the body.Camille GILLOT-11/+13
2023-04-25Rollup merge of #110685 - cjgillot:clean-dcp, r=oli-obkYuki Okushi-73/+52
Some cleanups to DataflowConstProp Mostly moving code around and short-circuiting useless cases.
2023-04-24Split `{Idx, IndexVec, IndexSlice}` into their own modulesMaybe Waffle-19/+19
2023-04-24Rollup merge of #110714 - cjgillot:reveal-consts, r=oli-obkMatthias Krüger-9/+23
Normalize types and consts in MIR opts. Some passes were using a non-RevealAll param_env, which is needlessly restrictive in mir-opts. As a drive-by, we normalize all constants, since just normalizing their types is not enough.
2023-04-24Rollup merge of #110706 - scottmcm:transmute_unchecked, r=oli-obkMatthias Krüger-1/+1
Add `intrinsics::transmute_unchecked` This takes a whole 3 lines in `compiler/` since it lowers to `CastKind::Transmute` in MIR *exactly* the same as the existing `intrinsics::transmute` does, it just doesn't have the fancy checking in `hir_typeck`. Added to enable experimenting with the request in <https://github.com/rust-lang/rust/pull/106281#issuecomment-1496648190> and because the portable-simd folks might be interested for dependently-sized array-vector conversions. It also simplifies a couple places in `core`. See also https://github.com/rust-lang/rust/pull/108442#issuecomment-1474777273, where `CastKind::Transmute` was added having exactly these semantics before the lang meeting (which I wasn't in) independently expressed interest.
2023-04-23Do not bother optimizing impossible functions.Camille GILLOT-37/+49
2023-04-23Auto merge of #110705 - saethlin:ignore-locals-cost, r=cjgillotbors-34/+0
Remove the size of locals heuristic in MIR inlining This heuristic doesn't necessarily correlate to complexity of the MIR Body. In particular, a lot of straight-line code in MIR tends to never reuse a local, even though any optimizer would effectively reuse the storage or just put everything in registers. So it doesn't even necessarily make sense that this would be a stack size heuristic. So... what happens if we just delete the heuristic? The benchmark suite improves significantly. Less heuristics better? r? `@cjgillot`
2023-04-23Auto merge of #108118 - oli-obk:lazy_typeck, r=cjgillotbors-1/+1
Run various queries from other queries instead of explicitly in phases These are just legacy leftovers from when rustc didn't have a query system. While there are more cleanups of this sort that can be done here, I want to land them in smaller steps. This phased order of query invocations was already a lie, as any query that looks at types (e.g. the wf checks run before) can invoke e.g. const eval which invokes borrowck, which invokes typeck, ...
2023-04-23Use param_env_reveal_all_normalized in MIR opts.Camille GILLOT-8/+10
2023-04-23Also reveal constants before MIR opts.Camille GILLOT-1/+13
2023-04-22Add `intrinsics::transmute_unchecked`Scott McMurray-1/+1
This takes a whole 3 lines in `compiler/` since it lowers to `CastKind::Transmute` in MIR *exactly* the same as the existing `intrinsics::transmute` does, it just doesn't have the fancy checking in `hir_typeck`. Added to enable experimenting with the request in <https://github.com/rust-lang/rust/pull/106281#issuecomment-1496648190> and because the portable-simd folks might be interested for dependently-sized array-vector conversions. It also simplifies a couple places in `core`.
2023-04-22Remove the size of locals heuristic in MIR inliningBen Kimock-34/+0
2023-04-22Turn on ConstDebugInfo pass.Wesley Wiser-1/+1
2023-04-22Reduce rightward drift.Camille GILLOT-37/+35
2023-04-22Simplify logic.Camille GILLOT-5/+3
2023-04-22Move eval_discriminant.Camille GILLOT-16/+14
2023-04-22Remove useless special case.Camille GILLOT-15/+0
2023-04-22Auto merge of #104844 - cjgillot:mention-eval-place, r=jackh726,RalfJungbors-10/+34
Evaluate place expression in `PlaceMention` https://github.com/rust-lang/rust/pull/102256 introduces a `PlaceMention(place)` MIR statement which keep trace of `let _ = place` statements from surface rust, but without semantics. This PR proposes to change the behaviour of `let _ =` patterns with respect to the borrow-checker to verify that the bound place is live. Specifically, consider this code: ```rust let _ = { let a = 5; &a }; ``` This passes borrowck without error on stable. Meanwhile, replacing `_` by `_: _` or `_p` errors with "error[E0597]: `a` does not live long enough", [see playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c448d25a7c205dc95a0967fe96bccce8). This PR *does not* change how `_` patterns behave with respect to initializedness: it remains ok to bind a moved-from place to `_`. The relevant test is `tests/ui/borrowck/let_underscore_temporary.rs`. Crater check found no regression. For consistency, this PR changes miri to evaluate the place found in `PlaceMention`, and report eventual dangling pointers found within it. r? `@RalfJung`
2023-04-22Auto merge of #110666 - JohnTitor:rollup-3pwilte, r=JohnTitorbors-8/+6
Rollup of 7 pull requests Successful merges: - #109949 (rustdoc: migrate `document_type_layout` to askama) - #110622 (Stable hash tag (discriminant) of `GenericArg`) - #110635 (More `IS_ZST` in `library`) - #110640 (compiler/rustc_target: Raise m68k-linux-gnu baseline to 68020) - #110657 (nit: consistent naming for SimplifyConstCondition) - #110659 (rustdoc: clean up JS) - #110660 (Print ty placeholders pretty) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-04-22Auto merge of #106934 - DrMeepster:offset_of, r=WaffleLapkinbors-2/+1
Add offset_of! macro (RFC 3308) Implements https://github.com/rust-lang/rfcs/pull/3308 (tracking issue #106655) by adding the built in macro `core::mem::offset_of`. Two of the future possibilities are also implemented: * Nested field accesses (without array indexing) * DST support (for `Sized` fields) I wrote this a few months ago, before the RFC merged. Now that it's merged, I decided to rebase and finish it. cc `@thomcc` (RFC author)
2023-04-21Allow `LocalDefId` as the argument to `def_path_str`Oli Scherer-1/+1
2023-04-21nit: consistent naming for SimplifyConstConditionmiguelraz-8/+6
2023-04-21Actually keep `PlaceMention` if requested.Camille GILLOT-10/+34
2023-04-21Changes from reviewKyle Matsuda-1/+1
2023-04-21Auto merge of #110569 - saethlin:mir-pass-cooperation, r=cjgillotbors-18/+17
Deduplicate unreachable blocks, for real this time In https://github.com/rust-lang/rust/pull/106428 (in particular https://github.com/rust-lang/rust/pull/106428/commits/41eda69516dd3ee217ae07c0efa369d31f630405) we noticed that inlining `unreachable_unchecked` can produce duplicate unreachable blocks. So we improved two MIR optimizations: `SimplifyCfg` was given a simplify to deduplicate unreachable blocks, then `InstCombine` was given a combiner to deduplicate switch targets that point at the same block. The problem is that change doesn't actually work. Our current pass order is ``` SimplifyCfg (does nothing relevant to this situation) Inline (produces multiple unreachable blocks) InstCombine (doesn't do anything here, oops) SimplifyCfg (produces the duplicate SwitchTargets that InstCombine is looking for) ``` So in here, I have factored out the specific function from `InstCombine` and placed it inside the simplify that produces the case it is looking for. This should ensure that it runs in the scenario it was designed for. Fixes https://github.com/rust-lang/rust/issues/110551 r? `@cjgillot`
2023-04-21offset_ofDrMeepster-2/+1
2023-04-20Run combine_duplicate_switch_targets after the simplification that produces themBen Kimock-18/+17
2023-04-20add subst_identity_iter and subst_identity_iter_copied methods on ↵Kyle Matsuda-3/+1
EarlyBinder; use this to simplify some EarlyBinder noise around explicit_item_bounds calls
2023-04-20add EarlyBinder to output of explicit_item_bounds; replace ↵Kyle Matsuda-1/+1
bound_explicit_item_bounds usages; remove bound_explicit_item_bounds query