about summary refs log tree commit diff
path: root/compiler/rustc_mir_dataflow/src
AgeCommit message (Collapse)AuthorLines
2023-04-02Use `&IndexSlice` instead of `&IndexVec` where possibleScott McMurray-9/+9
All the same reasons as for `[T]`: more general, less pointer chasing, and `&mut IndexSlice` emphasizes that it doesn't change *length*.
2023-04-02Auto merge of #109008 - clubby789:drop-elaborate-array, r=davidtwcobors-18/+54
Drop array patterns using subslices Fixes #109004 Drops contiguous subslices of an array when moving elements out with a pattern, which improves perf for large arrays r? `@compiler-errors`
2023-03-31Auto merge of #109762 - scottmcm:variantdef-indexvec, r=WaffleLapkinbors-3/+3
Update `ty::VariantDef` to use `IndexVec<FieldIdx, FieldDef>` And while doing the updates for that, also uses `FieldIdx` in `ProjectionKind::Field` and `TypeckResults::field_indices`. There's more places that could use it (like `rustc_const_eval` and `LayoutS`), but I tried to keep this PR from exploding to *even more* places. Part 2/? of https://github.com/rust-lang/compiler-team/issues/606
2023-03-30Update `ty::VariantDef` to use `IndexVec<FieldIdx, FieldDef>`Scott McMurray-3/+3
And while doing the updates for that, also uses `FieldIdx` in `ProjectionKind::Field` and `TypeckResults::field_indices`. There's more places that could use it (like `rustc_const_eval` and `LayoutS`), but I tried to keep this PR from exploding to *even more* places. Part 2/? of https://github.com/rust-lang/compiler-team/issues/606
2023-03-30Auto merge of #105587 - tgross35:once-cell-min, r=m-ou-sebors-1/+0
Partial stabilization of `once_cell` This PR aims to stabilize a portion of the `once_cell` feature: - `core::cell::OnceCell` - `std::cell::OnceCell` (re-export of the above) - `std::sync::OnceLock` This will leave `LazyCell` and `LazyLock` unstabilized, which have been moved to the `lazy_cell` feature flag. Tracking issue: https://github.com/rust-lang/rust/issues/74465 (does not fully close, but it may make sense to move to a new issue) Future steps for separate PRs: - ~~Add `#[inline]` to many methods~~ #105651 - Update cranelift usage of the `once_cell` crate - Update rust-analyzer usage of the `once_cell` crate - Update error messages discussing once_cell ## To be stabilized API summary ```rust // core::cell (in core/cell/once.rs) pub struct OnceCell<T> { .. } impl<T> OnceCell<T> { pub const fn new() -> OnceCell<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceCell<T>; impl<T: Debug> Debug for OnceCell<T> impl<T> Default for OnceCell<T>; impl<T> From<T> for OnceCell<T>; impl<T: PartialEq> PartialEq for OnceCell<T>; impl<T: Eq> Eq for OnceCell<T>; ``` ```rust // std::sync (in std/sync/once_lock.rs) impl<T> OnceLock<T> { pub const fn new() -> OnceLock<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceLock<T>; impl<T: Debug> Debug for OnceLock<T>; impl<T> Default for OnceLock<T>; impl<#[may_dangle] T> Drop for OnceLock<T>; impl<T> From<T> for OnceLock<T>; impl<T: PartialEq> PartialEq for OnceLock<T> impl<T: Eq> Eq for OnceLock<T>; impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T>; unsafe impl<T: Send> Send for OnceLock<T>; unsafe impl<T: Sync + Send> Sync for OnceLock<T>; impl<T: UnwindSafe> UnwindSafe for OnceLock<T>; ``` No longer planned as part of this PR, and moved to the `rust_cell_try` feature gate: ```rust impl<T> OnceCell<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } impl<T> OnceLock<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } ``` I am new to this process so would appreciate mentorship wherever needed.
2023-03-29Stabilize a portion of 'once_cell'Trevor Gross-1/+0
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-28Move `mir::Field` → `abi::FieldIdx`Scott McMurray-12/+12
The first PR for https://github.com/rust-lang/compiler-team/issues/606 This is just the move-and-rename, because it's plenty big-and-bitrotty already. Future PRs will start using `FieldIdx` more broadly, and concomitantly removing `FieldIdx::new`s.
2023-03-25Refactor: `VariantIdx::from_u32(0)` -> `FIRST_VARIANT`Scott McMurray-3/+3
Since structs are always `VariantIdx(0)`, there's a bunch of files where the only reason they had `VariantIdx` or `vec::Idx` imported at all was to get the first variant. So this uses a constant for that, and adds some doc-comments to `VariantIdx` while I'm there, since it doesn't have any today.
2023-03-17Drop subslices of arraysclubby789-18/+54
2023-03-14Use index based drop loop for slices and arraysTomasz Miąsko-101/+32
Instead of building two kinds of drop pair loops, of which only one will be eventually used at runtime in a given monomorphization, always use index based loop.
2023-03-11Simplify message pathsest31-1/+1
This makes it easier to open the messages file while developing on features. The commit was the result of automatted changes: for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
2023-03-09Introduce a no-op PlaceMention statement for `let _ =`.Camille GILLOT-0/+4
2023-03-08Rollup merge of #108856 - Zeegomo:remove-drop-and-rep, r=tmiaskoMatthias Krüger-11/+2
Remove DropAndReplace terminator #107844 made DropAndReplace unused, let's remove it completely from the codebase.
2023-03-07Remove DropAndReplace terminatorGiacomo Pasini-11/+2
PR 107844 made DropAndReplace unused, let's remove it completely from the codebase.
2023-03-05Erase lifetimes in SROA.Camille GILLOT-4/+5
2023-02-25Auto merge of #108250 - nnethercote:rename-interner-funcs, r=compiler-errorsbors-3/+3
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-3/+3
(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-23Remove dead unwinds before drop elaborationTomasz Miąsko-58/+5
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-22errors: generate typed identifiers in each crateDavid Wood-0/+4
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-16Replace some `then`s with some `then_some`sMaybe Waffle-1/+1
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-7/+1
2023-02-15Rollup merge of #107411 - cjgillot:dataflow-discriminant, r=oli-obkDylan DPC-62/+218
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-14s/eval_usize/eval_target_usize/ for clarityOli Scherer-2/+4
2023-02-08Rollup merge of #107271 - Zeegomo:drop-rmw, r=oli-obkMatthias Krüger-9/+17
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
2023-02-06Rename assign_idx methods.Camille GILLOT-23/+32
2023-02-06Complete for_each_aliasing_place.Camille GILLOT-0/+7
2023-02-06Improve value_analysis API.Camille GILLOT-7/+18
2023-02-06Limit creation of tracked place directly.Camille GILLOT-4/+18
2023-02-06Handle discriminants in dataflow-const-prop.Camille GILLOT-31/+143
2023-02-06Only exclude locals if the place is not indirect.Camille GILLOT-10/+14
2023-02-06Remove redundant test.Camille GILLOT-2/+1
2023-02-05Run SROA to fixpoint.Camille GILLOT-1/+1
2023-02-05Simplify construction of replacement map.Camille GILLOT-1/+1
2023-01-30Treat Drop as a rmw operationGiacomo Pasini-9/+17
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 a) A dropped value won't be used again b) 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: (a) as there is no way of reaching the old value. drop-elaboration will also remove any uninitialized drop. (b) 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.
2023-01-23Create stable metric to measure long computation in Const EvalBryan Garza-1/+5
This patch adds a `MirPass` that tracks the number of back-edges and function calls in the CFG, adds a new MIR instruction to increment a counter every time they are encountered during Const Eval, and emit a warning if a configured limit is breached.
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-1/+1
2023-01-05Fix `uninlined_format_args` for some compiler cratesnils-15/+15
Convert all the crates that have had their diagnostic migration completed (except save_analysis because that will be deleted soon and apfloat because of the licensing problem).
2023-01-02Fix handling of dead unwinds in backward analysesTomasz Miąsko-1/+1
Dead unwinds set contains a head of an unreachable unwind edge.
2022-12-20rustc: Remove needless lifetimesJeremy Stucki-3/+3
2022-12-20Auto merge of #105880 - Nilstrieb:make-newtypes-less-not-rust, r=oli-obkbors-9/+6
Improve syntax of `newtype_index` This makes it more like proper Rust and also makes the implementation a lot simpler. Mostly just turns weird flags in the body into proper attributes. It should probably also be converted to an attribute macro instead of function-like, but that can be done in a future PR.
2022-12-19Revert "Auto merge of #103880 - b-naber:field-ty-mir, r=lcnr"Rémy Rakic-3/+3
This reverts commit 03770f0e2b60c02db8fcf52fed5fb36aac70cedc, reversing changes made to 01ef4b21dc5251b58bd9c6fd6face2ae95d56da1.
2022-12-18A few small cleanups for `newtype_index`Nilstrieb-6/+3
Remove the `..` from the body, only a few invocations used it and it's inconsistent with rust syntax. Use `;` instead of `,` between consts. As the Rust syntax gods inteded.
2022-12-18Make `#[debug_format]` an attribute in `newtype_index`Nilstrieb-3/+3
This removes the `custom` format functionality as its only user was trivially migrated to using a normal format. If a new use case for a custom formatting impl pops up, you can add it back.
2022-12-16Auto merge of #103880 - b-naber:field-ty-mir, r=lcnrbors-3/+3
Use non-ascribed type as field's type in mir Fixes https://github.com/rust-lang/rust/issues/96514 r? `@lcnr`
2022-12-14Remove one more usage of `mk_substs_trait`Oli Scherer-2/+6
2022-12-13Don't require owned data in `MaybeStorageLive`Jakob Degen-6/+7
2022-12-13Auto merge of #105436 - ↵bors-51/+46
nnethercote:inline-place_contents_drop_state_cannot_differ, r=spastorino Inline and remove `place_contents_drop_state_cannot_differ`. It has a single call site and is hot enough to be worth inlining. And make sure `is_terminal_path` is inlined, too. r? `@ghost`
2022-12-11Rollup merge of #105537 - kadiwa4:remove_some_imports, r=fee1-deadMatthias Krüger-1/+1
compiler: remove unnecessary imports and qualified paths Some of these imports were necessary before Edition 2021, others were already in the prelude. I hope it's fine that this PR is so spread-out across files :/
2022-12-10compiler: remove unnecessary imports and qualified pathsKaDiWa-1/+1
2022-12-09Remove unneeded field from `SwitchTargets`Jakob Degen-6/+4