summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2023-04-16Move a const-prop-lint specific hack from mir interpret to const-prop-lint ↵Oli Scherer-1/+9
and make it fallible
2023-03-03Match unmatched backticks in comments in compiler/est31-4/+7
2023-03-03Match unmatched backticks in compiler/ that are part of rustdocest31-1/+1
2023-02-27Unify all validity check intrinsicsNilstrieb-12/+4
Also merges the inhabitedness check into the query to further unify the code paths.
2023-02-27Rollup merge of #108364 - Nilstrieb:validity-checks-refactor, r=compiler-errorsMatthias Krüger-35/+22
Unify validity checks into a single query Previously, there were two queries to check whether a type allows the 0x01 or zeroed bitpattern. I am planning on adding a further initness to check in #100423, truly uninit for MaybeUninit, which would make this three queries. This seems overkill for such a small feature, so this PR unifies them into one. I am not entirely happy with the naming and key type and open for improvements. r? oli-obk
2023-02-25Auto merge of #108250 - nnethercote:rename-interner-funcs, r=compiler-errorsbors-25/+23
Rename interner funcs This PR cleans up some inconsistencies in interner naming. Best reviewed one commit at a time. r? `@compiler-errors`
2023-02-24Rename many interner functions.Nicholas Nethercote-25/+23
(This is a large commit. The changes to `compiler/rustc_middle/src/ty/context.rs` are the most important ones.) The current naming scheme is a mess, with a mix of `_intern_`, `intern_` and `mk_` prefixes, with little consistency. In particular, in many cases it's easy to use an iterator interner when a (preferable) slice interner is available. The guiding principles of the new naming system: - No `_intern_` prefixes. - The `intern_` prefix is for internal operations. - The `mk_` prefix is for external operations. - For cases where there is a slice interner and an iterator interner, the former is `mk_foo` and the latter is `mk_foo_from_iter`. Also, `slice_interners!` and `direct_interners!` can now be `pub` or non-`pub`, which helps enforce the internal/external operations division. It's not perfect, but I think it's a clear improvement. The following lists show everything that was renamed. slice_interners - const_list - mk_const_list -> mk_const_list_from_iter - intern_const_list -> mk_const_list - substs - mk_substs -> mk_substs_from_iter - intern_substs -> mk_substs - check_substs -> check_and_mk_substs (this is a weird one) - canonical_var_infos - intern_canonical_var_infos -> mk_canonical_var_infos - poly_existential_predicates - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter - intern_poly_existential_predicates -> mk_poly_existential_predicates - _intern_poly_existential_predicates -> intern_poly_existential_predicates - predicates - mk_predicates -> mk_predicates_from_iter - intern_predicates -> mk_predicates - _intern_predicates -> intern_predicates - projs - intern_projs -> mk_projs - place_elems - mk_place_elems -> mk_place_elems_from_iter - intern_place_elems -> mk_place_elems - bound_variable_kinds - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter - intern_bound_variable_kinds -> mk_bound_variable_kinds direct_interners - region - intern_region (unchanged) - const - mk_const_internal -> intern_const - const_allocation - intern_const_alloc -> mk_const_alloc - layout - intern_layout -> mk_layout - adt_def - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid) - alloc_adt_def(!) -> mk_adt_def - external_constraints - intern_external_constraints -> mk_external_constraints Other - type_list - mk_type_list -> mk_type_list_from_iter - intern_type_list -> mk_type_list - tup - mk_tup -> mk_tup_from_iter - intern_tup -> mk_tup
2023-02-23Unify validity checks into a single queryNilstrieb-35/+22
Previously, there were two queries to check whether a type allows the 0x01 or zeroed bitpattern. I am planning on adding a further initness to check, truly uninit for MaybeUninit, which would make this three queries. This seems overkill for such a small feature, so this PR unifies them into one.
2023-02-23Remove dead unwinds before drop elaborationTomasz Miąsko-18/+39
As a part of drop elaboration, we identify dead unwinds, i.e., unwind edges on a drop terminators which are known to be unreachable, because there is no need to drop anything. Previously, the data flow framework was informed about the dead unwinds, and it assumed those edges are absent from MIR. Unfortunately, the data flow framework wasn't consistent in maintaining this assumption. In particular, if a block was reachable only through a dead unwind edge, its state was propagated to other blocks still. This became an issue in the context of change removes DropAndReplace terminator, since it introduces initialization into cleanup blocks. To avoid this issue, remove unreachable unwind edges before the drop elaboration, and elaborate only blocks that remain reachable.
2023-02-23Rollup merge of #108208 - cjgillot:flood-enum, r=oli-obkMatthias Krüger-7/+18
Correctly handle aggregates in DataflowConstProp The previous implementation from https://github.com/rust-lang/rust/pull/107411 flooded target of an aggregate assignment with `Bottom`, corresponding to the `deinit` that the interpreter does. As a consequence, when assigning `target = Enum::Variant#i(...)` all the `(target as Variant#j)` were at `Bottom` while they should have been `Top`. This PR replaces that flooding with `Top`. Aside, it corrects a second bug where the wrong place would be used to assign to enum variant fields, resulting to nothing happening. Fixes https://github.com/rust-lang/rust/issues/108166
2023-02-22Remove type-traversal trait aliasesAlan Egerton-4/+6
2023-02-22Rollup merge of #108246 - saethlin:instcombine-redundant-casts, ↵Guillaume Gomez-0/+9
r=compiler-errors Add an InstCombine for redundant casts `@rustbot` label +A-mir-opt
2023-02-20Remove use_ecx.Camille GILLOT-60/+37
2023-02-20Merge if-let and match.Camille GILLOT-67/+63
2023-02-20Move state fixup into a different method.Camille GILLOT-6/+6
2023-02-19Add an InstCombine for redundant castsBen Kimock-0/+9
2023-02-19Auto merge of #108128 - clubby789:builtin-derived-attr, r=jackh726bors-2/+2
Properly check for builtin derived code Fixes #108122
2023-02-18Replace _with_overflow instrinsics in LowerIntrinsics.Camille GILLOT-3/+23
2023-02-18Remove overflow checks from ConstProp.Camille GILLOT-102/+16
2023-02-18Use the correct place for enum variants.Camille GILLOT-6/+14
2023-02-18Flood aggregate assignments with `Top`.Camille GILLOT-1/+4
2023-02-18Auto merge of #108112 - nnethercote:clarify-iterator-interners, ↵bors-1/+1
r=oli-obk,compiler-errors Clarify iterator interners I found the iterator interners very confusing. This PR clarifies things. r? `@compiler-errors`
2023-02-17Auto merge of #105274 - saethlin:instcombine-mut-ref, r=cjgillotbors-5/+1
Enable instcombine for mutable reborrows `instcombine` used to contain this comment, which is no longer accurate because there it is fine to copy `&mut _` in MIR: ```rust // The dereferenced place must have type `&_`, so that we don't copy `&mut _`. ``` So let's try replacing that check with something much more permissive...
2023-02-17Rollup merge of #108154 - scottmcm:start-block-cleanup, r=compiler-errorsMatthias Krüger-8/+8
`BasicBlock::new(0)` -> `START_BLOCK` [no functional changes]
2023-02-17Replace `mk_foo` calls with `infer_foo` where possible.Nicholas Nethercote-1/+1
There are several `mk_foo`/`intern_foo` pairs, where the former takes an iterator and the latter takes a slice. (This naming convention is bad, but that's a fix for another PR.) This commit changes several `mk_foo` occurrences into `intern_foo`, avoiding the need for some `.iter()`/`.into_iter()` calls. Affected cases: - mk_type_list - mk_tup - mk_substs - mk_const_list
2023-02-16`BasicBlock::new(0)` -> `START_BLOCK` [no functional changes]Scott McMurray-8/+8
2023-02-17Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwUbors-11/+11
Switch to `EarlyBinder` for `type_of` query Part of the work to finish #105779 and implement https://github.com/rust-lang/types-team/issues/78. Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This adds `EarlyBinder` to the return type of the `type_of` query and removes `bound_type_of`. r? `@lcnr`
2023-02-16remove bound_type_of query; make type_of return EarlyBinder; change type_of ↵Kyle Matsuda-11/+11
in metadata
2023-02-16change usages of type_of to bound_type_ofKyle Matsuda-8/+8
2023-02-17Rollup merge of #108104 - matthiaskrgr:into, r=compiler-errorsMatthias Krüger-2/+1
don't into self don't into()-convert types to themselves
2023-02-17Rollup merge of #107489 - compiler-errors:non_lifetime_binders, r=cjgillotMatthias Krüger-1/+1
Implement partial support for non-lifetime binders This implements support for non-lifetime binders. It's pretty useless currently, but I wanted to put this up so the implementation can be discussed. Specifically, this piggybacks off of the late-bound lifetime collection code in `rustc_hir_typeck::collect::lifetimes`. This seems like a necessary step given the fact we don't resolve late-bound regions until this point, and binders are sometimes merged. Q: I'm not sure if I should go along this route, or try to modify the earlier nameres code to compute the right bound var indices for type and const binders eagerly... If so, I'll need to rename all these queries to something more appropriate (I've done this for `resolve_lifetime::Region` -> `resolve_lifetime::ResolvedArg`) cc rust-lang/types-team#81 r? `@ghost`
2023-02-16Properly check for builtin derivesclubby789-2/+2
2023-02-16Auto merge of #108127 - matthiaskrgr:rollup-kpzfc6j, r=matthiaskrgrbors-5/+3
Rollup of 7 pull requests Successful merges: - #106347 (More accurate spans for arg removal suggestion) - #108057 (Prevent some attributes from being merged with others on reexports) - #108090 (`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`) - #108092 (note issue for feature(packed_bundled_libs)) - #108099 (use chars instead of strings where applicable) - #108115 (Do not ICE on unmet trait alias bounds) - #108125 (Add new people to the compiletest review rotation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-02-16don't into selfMatthias Krüger-2/+1
don't into()-convert types to themselves
2023-02-16Auto merge of #108020 - nnethercote:opt-mk_region, r=compiler-errorsbors-5/+2
Optimize `mk_region` PR #107869 avoiding some interning under `mk_ty` by special-casing `Ty` variants with simple (integer) bodies. This PR does something similar for regions. r? `@compiler-errors`
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-5/+3
2023-02-16Enable instcombine for mutable reborrowsBen Kimock-5/+1
2023-02-16Auto merge of #107449 - saethlin:enable-copyprop, r=oli-obkbors-6/+41
Enable CopyProp r? `@tmiasko` `@rustbot` label +A-mir-opt
2023-02-16Rename some region-specific stuffMichael Goulet-1/+1
2023-02-15Auto merge of #108012 - compiler-errors:issue-107999, r=oli-obkbors-20/+24
Don't ICE in `might_permit_raw_init` if reference is polymorphic Emitting optimized MIR for a polymorphic function may require computing layout of a type that isn't (yet) known. This happens in the instcombine pass, for example. Let's fail gracefully in that condition. cc `@saethlin` fixes #107999
2023-02-15Rollup merge of #107411 - cjgillot:dataflow-discriminant, r=oli-obkDylan DPC-40/+105
Handle discriminant in DataflowConstProp cc ``@jachris`` r? ``@JakobDegen`` This PR attempts to extend the DataflowConstProp pass to handle propagation of discriminants. We handle this by adding 2 new variants to `TrackElem`: `TrackElem::Variant` for enum variants and `TrackElem::Discriminant` for the enum discriminant pseudo-place. The difficulty is that the enum discriminant and enum variants may alias each another. This is the issue of the `Option<NonZeroUsize>` test, which is the equivalent of https://github.com/rust-lang/unsafe-code-guidelines/issues/84 with a direct write. To handle that, we generalize the flood process to flood all the potentially aliasing places. In particular: - any write to `(PLACE as Variant)`, either direct or through a projection, floods `(PLACE as OtherVariant)` for all other variants and `discriminant(PLACE)`; - `SetDiscriminant(PLACE)` floods `(PLACE as Variant)` for each variant. This implies that flooding is not hierarchical any more, and that an assignment to a non-tracked place may need to flood a tracked place. This is handled by `for_each_aliasing_place` which generalizes `preorder_invoke`. As we deaggregate enums by putting `SetDiscriminant` last, this allows to propagate the value of the discriminant. This refactor will allow to make https://github.com/rust-lang/rust/pull/107009 able to handle discriminants too.
2023-02-14Make permit_uninit/zero_init fallibleMichael Goulet-20/+24
2023-02-15Replace an unnecessary `mk_ty` call with `mk_array`.Nicholas Nethercote-5/+2
2023-02-14s/eval_usize/eval_target_usize/ for clarityOli Scherer-2/+2
2023-02-13Typo.Camille GILLOT-3/+3
2023-02-12Enable CopyProp by default, tune the impl a bitBen Kimock-6/+41
2023-02-11Auto merge of #107851 - cjgillot:sroa-const, r=oli-obkbors-0/+2
Put deaggregated statements after original constant. Fixes https://github.com/rust-lang/rust/issues/107818
2023-02-10Auto merge of #85158 - JulianKnodt:array_const_val, r=cjgillotbors-0/+301
Mir-Opt for copying enums with large discrepancies I have been meaning to make this for quite a while, based off of this [hackmd](https://hackmd.io/`@ft4bxUsFT5CEUBmRKYHr7w/rJM8BBPzD).` I'm not sure where to put this opt now that I've made it, so I'd appreciate suggestions on that! It's also one long chain of statements, not sure if there's a more friendly format to make it. r? `@tmiasko` I would `r` oli but he's on leave so he suggested I `r` tmiasko or wesleywiser.
2023-02-09Put deaggregated statements after original constant.Camille GILLOT-0/+2
2023-02-08Rollup merge of #107271 - Zeegomo:drop-rmw, r=oli-obkMatthias Krüger-0/+29
Treat Drop as a rmw operation Previously, a Drop terminator was considered a move in MIR. This commit changes the behavior to only treat Drop as a mutable access to the dropped place. In order for this change to be correct, we need to guarantee that 1. A dropped value won't be used again 2. Places that appear in a drop won't be used again before a subsequent initialization. We can ensure this to be correct at MIR construction because Drop will only be emitted when a variable goes out of scope, thus having: * (1) as there is no way of reaching the old value. drop-elaboration will also remove any uninitialized drop. * (2) as the place can't be named following the end of the scope. However, the initialization status, previously tracked by moves, should also be tied to the execution of a Drop, hence the additional logic in the dataflow analyses. From discussion in [this thread](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/.60DROP.60.20to.20.60DROP_IF.60.20compiler-team.23558), originating from https://github.com/rust-lang/compiler-team/issues/558. See also https://github.com/rust-lang/rust/pull/104488#discussion_r1085556010