Commit Graph

487 Commits

Author SHA1 Message Date
Camille GILLOT
252c64722f Parametrize gather_moves by filter. 2023-10-21 10:31:39 +00:00
Camille GILLOT
4bedd7de6e Stop computing error info in move path builder. 2023-10-21 10:30:58 +00:00
Camille GILLOT
90e6d29955 Avoid using a magic value for untracked locals. 2023-10-21 10:30:16 +00:00
Camille GILLOT
8d535070a2 Do not report errors from move path builder. 2023-10-21 10:29:40 +00:00
Camille GILLOT
a8e56d0b0b Remove is_terminal_path.
That information is redundant. Is the path is terminal, `first_child` will
already be `None`.
2023-10-21 10:26:28 +00:00
Camille GILLOT
4abea83663 Improve naming and comments. 2023-10-21 07:01:25 +00:00
Camille GILLOT
751a079413 Implement JumpThreading pass. 2023-10-21 06:58:38 +00:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Camille GILLOT
27d6a57e58 Preserve DebugInfo in DeadStoreElimination. 2023-10-06 15:46:11 +00:00
ouz-a
5d753abb30 have better explanation for relate_types 2023-10-02 23:39:45 +03:00
ouz-a
cd7f471931 Add docs, remove code, change subtyper code 2023-10-02 23:39:44 +03:00
ouz-a
3148e6a993 subtyping_projections 2023-10-02 23:37:49 +03:00
Oli Scherer
ec6f554536 Some tracing cleanups 2023-09-28 16:13:37 +00:00
bors
551c7183f8 Auto merge of #115794 - cjgillot:aggregate-no-box, r=davidtwco
Do not create a DerefLen place for `Box<[T]>`.

Fixes https://github.com/rust-lang/rust/issues/115789
2023-09-24 06:13:17 +00:00
Camille GILLOT
44ac8dcc71 Remove GeneratorWitness and rename GeneratorWitnessMIR. 2023-09-23 13:47:30 +00:00
Matthias Krüger
d4d0c840b3
Rollup merge of #115770 - ouz-a:match_elem_builder, r=lcnr
Match on elem first while building move paths

While working on https://github.com/rust-lang/rust/pull/115025 `@lcnr` and I observed "move_paths_for" function matched on the `Ty` instead of `Projection` which seems flawed as it's the `Projection`s that cause the problem not the type.

r? `@lcnr`
2023-09-22 23:12:34 +02:00
ouz-a
63df126f59 match array for constantindex and subslice 2023-09-22 16:28:45 +03:00
ouz-a
442c87a0b0 better bug message 2023-09-22 11:31:45 +03:00
ouz-a
d6efedcaf5 remove inner match 2023-09-22 11:21:55 +03:00
Ralf Jung
c94410c145 rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const 2023-09-21 08:12:30 +02:00
Camille GILLOT
e76b7f226a Do not create a DerefLen place for Box<[T]>. 2023-09-20 16:07:03 +00:00
ouz-a
0cb22a66eb very verbose error handling 2023-09-12 21:09:29 +03:00
ouz-a
22b1acb455 match on elem first 2023-09-12 10:28:37 +03:00
Camille GILLOT
6ad6b4381c Support non-scalar constants. 2023-09-11 16:29:41 +00:00
Camille GILLOT
4ad22b91fc Correct comment and assumption. 2023-09-07 15:45:25 +00:00
Camille GILLOT
fc63543792 Support array length. 2023-09-06 16:05:04 +00:00
Camille GILLOT
7ef555d84a Support non-trivial scalars in ConstProp. 2023-09-05 21:25:41 +00:00
Jason Newcomb
f686bd8949 Take &mut Results in ResultsVisitor 2023-09-02 19:35:51 -04:00
Ralf Jung
4c53783f3c when terminating during unwinding, show the reason why 2023-08-24 13:28:26 +02:00
Ralf Jung
818ec8e23a give some unwind-related terminators a more clear name 2023-08-20 15:52:38 +02:00
Camille GILLOT
f5e4eb91b7 Use Terminator::edges for backward analysis too. 2023-08-16 19:40:46 +00:00
Camille GILLOT
e9990ce89c Only evaluate yield place after resume in liveness. 2023-08-16 18:12:18 +00:00
Camille GILLOT
7ded3409b8 Specify that method only applies statement effects. 2023-08-16 18:12:18 +00:00
Camille GILLOT
aa697f599e Rename YieldResumeEffect. 2023-08-16 18:12:18 +00:00
Camille GILLOT
388f6a6413 Make TerminatorEdge plural. 2023-08-16 18:12:18 +00:00
Camille GILLOT
6cf15d4cb5 Rename MaybeUnreachable. 2023-08-16 18:12:18 +00:00
Camille GILLOT
f19cd3f2e1 Use TerminatorEdge for dataflow-const-prop. 2023-08-16 18:12:18 +00:00
Camille GILLOT
3acfa092db Only run MaybeInitializedPlaces once for drop elaboration. 2023-08-16 18:12:18 +00:00
Camille GILLOT
5173d85043 Allow apply_terminator_effect to customize edges. 2023-08-16 18:12:17 +00:00
Camille GILLOT
32711b2b4e Introduce MaybeUnreachable. 2023-08-16 18:12:17 +00:00
Camille GILLOT
934a99eb65 Move domain_size to GenKillAnalysis. 2023-08-16 18:12:17 +00:00
Camille GILLOT
8726cbc75f Move initialization dataflow impls into their own module. 2023-08-16 18:12:17 +00:00
Camille GILLOT
760881b29d Create bottom on-the-fly instead of cloning it. 2023-08-16 18:12:17 +00:00
Camille GILLOT
9c97abd54c Simplify for_each_mut_borrow. 2023-08-16 18:12:17 +00:00
Matthias Krüger
13de583583
Rollup merge of #114505 - ouz-a:cleanup_mir, r=RalfJung
Add documentation to has_deref

Documentation of `has_deref` needed some polish to be more clear about where it should be used and what's it's purpose.

cc https://github.com/rust-lang/rust/issues/114401

r? `@RalfJung`
2023-08-06 17:26:29 +02:00
ouz-a
6df546281b cleanup misinformation regarding has_deref 2023-08-06 17:29:09 +03:00
Michael Goulet
99969d282b Use upvar_tys in more places, make it a list 2023-08-01 23:19:31 +00:00
Matthias Krüger
3ce90b1649 inline format!() args up to and including rustc_codegen_llvm 2023-07-30 14:22:50 +02:00
Camille GILLOT
f5feb3e3ca Turn copy into moves during DSE. 2023-07-19 09:59:12 +00:00
Mahdi Dibaiee
e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Mark Rousskov
cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
bors
5b733e2bca Auto merge of #113316 - DrMeepster:underefer_perf, r=oli-obk
Rewrite `UnDerefer`, again

This PR is intended to improve the perf regression introduced by #112882.

`UnDerefer` has been separated out again for borrowck reasons. It was a bit overzealous to remove it in the previous PR.

r? `@oli-obk`
2023-07-11 06:52:53 +00:00
DrMeepster
b0dbd60040 optimization round 2
- moved work from `find_local` to `gather_statement`
- created custom iterator for `iter_projections`
- reverted change from `IndexVec` to `FxIndexMap`
2023-07-10 20:46:01 -07:00
Boxy
12138b8e5e Move TyCtxt::mk_x to Ty::new_x where applicable 2023-07-05 20:27:07 +01:00
DrMeepster
d1c9696b7d bring back un_derefer and rewrite it again 2023-07-04 13:45:23 -07:00
DrMeepster
4fbd6d5af4 Merge un_derefer into MovePathLookup 2023-06-29 22:14:27 -07:00
Florian Groult
3224ea4424 Export AnalysisResults trait in rustc_mir_dataflow 2023-06-27 11:35:32 +02:00
bors
b9ad9b78a2 Auto merge of #112693 - ericmarkmartin:use-more-placeref, r=spastorino
Use PlaceRef abstractions more often

Associated issue: https://github.com/rust-lang/rust/issues/80647

r? `@spastorino`
2023-06-27 00:34:49 +00:00
Eric Mark Martin
c07c10d1e4 use PlaceRef abstractions more consistently 2023-06-25 20:38:01 -04:00
Ziru Niu
8fb4c41f35 merge BorrowKind::Unique into BorrowKind::Mut 2023-06-20 20:55:31 +08:00
Michael Goulet
31d1fbf8d2
Rollup merge of #112232 - fee1-dead-contrib:match-eq-const-msg, r=b-naber
Better error for non const `PartialEq` call generated by `match`

Resolves #90237
2023-06-19 17:53:33 -07:00
bors
c911e08514 Auto merge of #112617 - lqd:dump-mir-dataflow, r=tmiasko
make mir dataflow graphviz dumps opt-in

This should save some MIR traversals and allocations that are not really needed.

Small win but noticeable locally. Let's see what LTO/PGO say.

r? `@ghost`
2023-06-19 01:17:40 +00:00
Deadbeef
89c24af133 Better error for non const PartialEq call generated by match 2023-06-18 05:24:38 +00:00
DrMeepster
a5c6cb888e remove box_free and replace with drop impl 2023-06-16 13:41:06 -07:00
Rémy Rakic
9395e2771a make mir dataflow graphviz dumps opt-in 2023-06-14 12:30:13 +00:00
bors
68c8fdaac0 Auto merge of #108293 - Jarcho:mut_analyses, r=eholk
Take MIR dataflow analyses by mutable reference

The main motivation here is any analysis requiring dynamically sized scratch memory to work. One concrete example would be pointer target tracking, where tracking the results of a dereference can result in multiple possible targets. This leads to processing multi-level dereferences requiring the ability to handle a changing number of potential targets per step. A (simplified) function for this would be `fn apply_deref(potential_targets: &mut Vec<Target>)` which would use the scratch space contained in the analysis to send arguments and receive the results.

The alternative to this would be to wrap everything in a `RefCell`, which is what `MaybeRequiresStorage` currently does. This comes with a small perf cost and loses the compiler's guarantee that we don't try to take multiple borrows at the same time.

For the implementation:
* `AnalysisResults` is an unfortunate requirement to avoid an unconstrained type parameter error.
* `CloneAnalysis` could just be `Clone` instead, but that would result in more work than is required to have multiple cursors over the same result set.
* `ResultsVisitor` now takes the results type on in each function as there's no other way to have access to the analysis without cloning it. This could use an associated type rather than a type parameter, but the current approach makes it easier to not care about the type when it's not necessary.
* `MaybeRequiresStorage` now no longer uses a `RefCell`, but the graphviz formatter now does. It could be removed, but that would require even more changes and doesn't really seem necessary.
2023-06-08 23:58:44 +00:00
lcnr
cfd0623411 unique borrows are mutating uses 2023-05-29 17:15:48 +02:00
Guillaume Gomez
ddb5424569
Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkin
Remove DesugaringKind::Replace.

A simple boolean flag is enough.
2023-05-27 13:38:31 +02:00
clubby789
f97fddab91 Ensure Fluent messages are in alphabetical order 2023-05-25 23:49:35 +00:00
Camille GILLOT
844c1cc5fe Remove DesugaringKind::Replace. 2023-05-25 17:40:46 +00:00
Jason Newcomb
eaddc37075 Take MIR dataflow analyses by mutable reference. 2023-05-18 17:46:39 -04:00
Dylan DPC
828caa80a9
Rollup merge of #110930 - b-naber:normalize-elaborate-drops, r=cjgillot
Don't expect normalization to succeed in elaborate_drops

Fixes https://github.com/rust-lang/rust/issues/110682

This was exposed through the changes in https://github.com/rust-lang/rust/pull/109247, which causes more things to be inlined. Inlining can happen before monomorphization, so we can't expect normalization to succeed. In the elaborate_drops analysis we currently have [this call](033aa092ab/compiler/rustc_mir_dataflow/src/elaborate_drops.rs (L278)) to `normalize_erasing_regions`, which ICEs when normalization fails. The types are used to infer [whether the type needs a drop](033aa092ab/compiler/rustc_mir_dataflow/src/elaborate_drops.rs (L374)), where `needs_drop` itself [uses `try_normalize_erasing_regions`](033aa092ab/compiler/rustc_middle/src/ty/util.rs (L1121)).

~[`instance_mir`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.instance_mir) isn't explicit about whether it expects the instances corresponding to the `InstanceDef`s to be monomorphized (though I think in all other contexts the function is used post-monomorphization), so the use of `instance_mir` in inlining doesn't necessarily seem wrong to me.~
2023-05-17 19:11:53 +05:30
bors
9a767b6b9e Auto merge of #110820 - cjgillot:faster-dcp, r=oli-obk
Optimize dataflow-const-prop place-tracking infra

Optimization opportunities found while investigating https://github.com/rust-lang/rust/pull/110719

Computing places breadth-first ensures that we create short projections before deep projections, since the former are more likely to be propagated.

The most relevant is the pre-computation of flooded places. Callgrind showed `flood_*` methods and especially `preorder_preinvoke` were especially hot. This PR attempts to pre-compute the set of `ValueIndex` that `preorder_invoke` would visit.

Using this information, we make some `PlaceIndex` inaccessible when they contain no `ValueIndex`, allowing to skip computations for those places.

cc `@jachris` as original author
2023-05-10 20:54:31 +00:00
b-naber
e7a2f52ba1 don't inline polymorphic adt instances whose fields contain projections
in DropGlue.
2023-05-10 16:03:52 +00:00
Camille GILLOT
38612f5ec7 Explicitly skip arguments. 2023-05-09 17:59:35 +00:00
Camille GILLOT
3490375570 Implement SSA-based reference propagation. 2023-05-09 17:59:34 +00:00
Camille GILLOT
ccc1da247b Prevent stack overflow. 2023-05-09 17:27:58 +00:00
Camille GILLOT
2aa1c23fed Add a few comments. 2023-05-09 17:27:58 +00:00
Camille GILLOT
79c073746b Do not flood on copy_nonoverlapping. 2023-05-09 17:27:58 +00:00
Camille GILLOT
add5124dce Extract handle_set_discriminant. 2023-05-09 17:27:58 +00:00
Camille GILLOT
2b0bf3cf59 Trim the places that will not be used. 2023-05-09 17:27:58 +00:00
Camille GILLOT
38fa676330 Precompute values to flood. 2023-05-09 17:27:58 +00:00
Camille GILLOT
7c3d55150d Create tracked places breadth first. 2023-05-09 17:27:58 +00:00
Camille GILLOT
71138e9933 Make HasTop and HasBottom consts. 2023-05-09 17:27:58 +00:00
Camille GILLOT
9325a254f0 Make PlaceMention a non-mutating use. 2023-04-29 16:14:33 +00:00
b-naber
930c39aa8f dont expect normalization to succeed in elaborate_drops 2023-04-28 07:17:19 +00:00
Maybe Waffle
e496fbec92 Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
DrMeepster
511e457c4b offset_of 2023-04-21 02:14:02 -07:00
bors
d7f9e81650 Auto merge of #110407 - Nilstrieb:fluent-macro, r=davidtwco
Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`

Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-04-19 08:26:47 +00:00
Nilstrieb
b5d3d970fa Add rustc_fluent_macro to decouple fluent from rustc_macros
Fluent, with all the icu4x it brings in, takes quite some time to
compile. `fluent_messages!` is only needed in further downstream rustc
crates, but is blocking more upstream crates like `rustc_index`. By
splitting it out, we allow `rustc_macros` to be compiled earlier, which
speeds up `x check compiler` by about 5 seconds (and even more after the
needless dependency on `serde_json` is removed from
`rustc_data_structures`).
2023-04-18 18:56:22 +00:00
Josh Soref
e09d0d2a29 Spelling - compiler
* account
* achieved
* advising
* always
* ambiguous
* analysis
* annotations
* appropriate
* build
* candidates
* cascading
* category
* character
* clarification
* compound
* conceptually
* constituent
* consts
* convenience
* corresponds
* debruijn
* debug
* debugable
* debuggable
* deterministic
* discriminant
* display
* documentation
* doesn't
* ellipsis
* erroneous
* evaluability
* evaluate
* evaluation
* explicitly
* fallible
* fulfill
* getting
* has
* highlighting
* illustrative
* imported
* incompatible
* infringing
* initialized
* into
* intrinsic
* introduced
* javascript
* liveness
* metadata
* monomorphization
* nonexistent
* nontrivial
* obligation
* obligations
* offset
* opaque
* opportunities
* opt-in
* outlive
* overlapping
* paragraph
* parentheses
* poisson
* precisely
* predecessors
* predicates
* preexisting
* propagated
* really
* reentrant
* referent
* responsibility
* rustonomicon
* shortcircuit
* simplifiable
* simplifications
* specify
* stabilized
* structurally
* suggestibility
* translatable
* transmuting
* two
* unclosed
* uninhabited
* visibility
* volatile
* workaround

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-17 16:09:18 -04:00
DaniPopes
677357d32b
Fix typos in compiler 2023-04-10 22:02:52 +02:00
Gary Guo
5ae3a53a44 Revert box_free unwind action 2023-04-06 09:34:16 +01:00
Gary Guo
bf6b84b10a Fix new usage of old api 2023-04-06 09:34:16 +01:00
Gary Guo
e3f2edc75b Rename Abort terminator to Terminate
Unify terminology used in unwind action and terminator, and reflect
the fact that a nounwind panic is triggered instead of an immediate
abort is triggered for this terminator.
2023-04-06 09:34:16 +01:00
Gary Guo
0a5dac3062 Add UnwindAction::Terminate 2023-04-06 09:34:16 +01:00
Gary Guo
5e6ed132fa Add UnwindAction::Unreachable
This also makes eval machine's `StackPopUnwind`
redundant so that is replaced.
2023-04-06 09:34:16 +01:00
Gary Guo
daeb844e0c Refactor unwind from Option to a new enum 2023-04-06 09:34:16 +01:00
Yuki Okushi
4e0662c8a7
Rollup merge of #109847 - clubby789:graphviz-reachable, r=oli-obk
Only create graphviz nodes for reachable MIR bb's

Fixes #109832
2023-04-05 20:47:22 +09:00
clubby789
422c33030f Disable path trimming during graphviz output 2023-04-05 03:06:37 +01:00
Scott McMurray
a2ee7592d6 Use &IndexSlice instead of &IndexVec where possible
All the same reasons as for `[T]`: more general, less pointer chasing, and `&mut IndexSlice` emphasizes that it doesn't change *length*.
2023-04-02 17:35:37 -07:00
bors
a5a690cf4b Auto merge of #109008 - clubby789:drop-elaborate-array, r=davidtwco
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-04-02 12:17:52 +00:00
clubby789
47ae42ee10 Only create graphviz nodes for reachable MIR bb's 2023-04-01 23:14:18 +01:00
bors
eb3e9c1f45 Auto merge of #109762 - scottmcm:variantdef-indexvec, r=WaffleLapkin
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-31 03:36:18 +00:00
Scott McMurray
4abb455529 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-30 09:23:40 -07:00
bors
8a7ca936e6 Auto merge of #105587 - tgross35:once-cell-min, r=m-ou-se
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-30 10:12:23 +00:00
Trevor Gross
dc4ba57566 Stabilize a portion of 'once_cell'
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-29 18:04:44 -04:00
Scott McMurray
5bbaeadc01 Move mir::Fieldabi::FieldIdx
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-28 22:22:37 -07:00
Scott McMurray
0439d13176 Refactor: VariantIdx::from_u32(0) -> FIRST_VARIANT
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-25 18:58:25 -07:00
clubby789
ce2d52841b Drop subslices of arrays 2023-03-17 12:26:04 +00:00
Tomasz Miąsko
cf0e78bd3b Use index based drop loop for slices and arrays
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-14 21:29:32 +01:00
est31
7e2ecb3cd8 Simplify message paths
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-11 22:51:57 +01:00
Camille GILLOT
4462bb54e3 Introduce a no-op PlaceMention statement for let _ =. 2023-03-09 17:45:13 +00:00
Matthias Krüger
4e84fbf8a0
Rollup merge of #108856 - Zeegomo:remove-drop-and-rep, r=tmiasko
Remove DropAndReplace terminator

#107844 made DropAndReplace unused, let's remove it completely from the codebase.
2023-03-08 21:26:51 +01:00
Giacomo Pasini
c5d4e4d907
Remove DropAndReplace terminator
PR 107844 made DropAndReplace unused, let's remove it completely
from the codebase.
2023-03-07 14:25:22 +01:00
Camille GILLOT
fc1a861558 Erase lifetimes in SROA. 2023-03-05 18:35:30 +00:00
bors
dcca6a375b Auto merge of #108250 - nnethercote:rename-interner-funcs, r=compiler-errors
Rename interner funcs

This PR cleans up some inconsistencies in interner naming.

Best reviewed one commit at a time.

r? `@compiler-errors`
2023-02-25 13:55:26 +00:00
Nicholas Nethercote
2200911616 Rename many interner functions.
(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-24 07:32:24 +11:00
Tomasz Miąsko
23e3840014 Remove dead unwinds before drop elaboration
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-23 14:05:03 +01:00
David Wood
d1fcf61117 errors: generate typed identifiers in each crate
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-22 09:15:53 +00:00
Maybe Waffle
5bf6a46032 Replace some thens with some then_somes 2023-02-16 15:26:03 +00:00
Maybe Waffle
8751fa1a9a if $c:expr { Some($r:expr) } else { None } =>> $c.then(|| $r) 2023-02-16 15:26:00 +00:00
Dylan DPC
c78e3c735a
Rollup merge of #107411 - cjgillot:dataflow-discriminant, r=oli-obk
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-15 12:24:55 +05:30
Oli Scherer
936bf29d4c s/eval_usize/eval_target_usize/ for clarity 2023-02-14 08:51:19 +00:00
Matthias Krüger
05748c66a0
Rollup merge of #107271 - Zeegomo:drop-rmw, r=oli-obk
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-08 18:32:41 +01:00
Camille GILLOT
df889c9821 Rename assign_idx methods. 2023-02-06 22:05:05 +00:00
Camille GILLOT
67a8c16fe2 Complete for_each_aliasing_place. 2023-02-06 22:01:07 +00:00
Camille GILLOT
9af191f86f Improve value_analysis API. 2023-02-06 21:58:07 +00:00
Camille GILLOT
c48756cdbf Limit creation of tracked place directly. 2023-02-06 21:55:05 +00:00
Camille GILLOT
9a6c04f5d0 Handle discriminants in dataflow-const-prop. 2023-02-06 21:51:47 +00:00
Camille GILLOT
cd3649b2a5 Only exclude locals if the place is not indirect. 2023-02-06 21:51:45 +00:00
Camille GILLOT
0d59b8c997 Remove redundant test. 2023-02-06 21:29:02 +00:00
Matthias Krüger
7be6e6d954
Rollup merge of #107724 - klensy:imports, r=Mark-Simulacrum
remove unused rustc_* imports
2023-02-06 21:16:42 +01:00
klensy
4f5f9f0a13 remove unused imports 2023-02-06 17:40:18 +03:00
Camille GILLOT
8e05ab04e5 Run SROA to fixpoint. 2023-02-05 12:08:42 +00:00
Camille GILLOT
42c9514629 Simplify construction of replacement map. 2023-02-05 11:44:18 +00:00
Giacomo Pasini
68c1e2fd48
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
  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-30 00:20:40 +01:00
Bryan Garza
360db516cc Create stable metric to measure long computation in Const Eval
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-23 23:56:22 +00:00
Maybe Waffle
6a28fb42a8 Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
nils
fd7a159710 Fix uninlined_format_args for some compiler crates
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-05 19:01:12 +01:00
Tomasz Miąsko
357c3cf72c Fix handling of dead unwinds in backward analyses
Dead unwinds set contains a head of an unreachable unwind edge.
2023-01-02 22:24:01 +01:00
Jeremy Stucki
3dde32ca97
rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
bors
eb9e5e711d Auto merge of #105880 - Nilstrieb:make-newtypes-less-not-rust, r=oli-obk
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-20 07:27:01 +00:00
Rémy Rakic
8275d115fb Revert "Auto merge of #103880 - b-naber:field-ty-mir, r=lcnr"
This reverts commit 03770f0e2b, reversing
changes made to 01ef4b21dc.
2022-12-19 15:31:20 +00:00
Nilstrieb
8bfd6450c7 A few small cleanups for newtype_index
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-18 21:47:28 +01:00
Nilstrieb
d679764fb6 Make #[debug_format] an attribute in newtype_index
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-18 21:37:38 +01:00
bors
03770f0e2b Auto merge of #103880 - b-naber:field-ty-mir, r=lcnr
Use non-ascribed type as field's type in mir

Fixes https://github.com/rust-lang/rust/issues/96514

r? `@lcnr`
2022-12-16 12:47:49 +00:00
Oli Scherer
4ffe3bdf99 Remove one more usage of mk_substs_trait 2022-12-14 15:36:39 +00:00
Jakob Degen
3522d48112 Don't require owned data in MaybeStorageLive 2022-12-13 04:22:47 -08:00
bors
71ec1457ee Auto merge of #105436 - 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-13 03:28:57 +00:00
Matthias Krüger
2daa3bcbc2
Rollup merge of #105537 - kadiwa4:remove_some_imports, r=fee1-dead
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-11 09:51:57 +01:00
KaDiWa
9bc69925cb
compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
Jakob Degen
9fb8da8f8f Remove unneeded field from SwitchTargets 2022-12-09 04:53:10 -08:00
Nicholas Nethercote
68a19209e0 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.
2022-12-08 13:59:29 +11:00
Rageking8
58110572fb fix dupe word typos 2022-12-05 16:42:36 +08:00
Oli Scherer
4f593ce5d8 Create format_args as late as possible 2022-12-01 08:49:51 +00:00
Jakob Degen
245c60749a Rewrite dest prop.
This fixes a number of correctness issues from the previous version. Additionally, we use a new
strategy which has much better performance charactersitics and also finds more opportunities to
apply the optimization.
2022-11-26 18:04:54 -08:00
b-naber
9061ffba8c use no type in ProjectionElem::Field for PlaceBuilder::UpVar 2022-11-23 21:25:27 +01:00
Oli Scherer
ec8d01fdcc Allow iterators instead of requiring slices that will get turned into iterators 2022-11-21 20:33:55 +00:00
Matthias Krüger
e3036df003 couple of clippy::perf fixes 2022-11-18 10:30:47 +01:00
Jannis Christopher Köhl
108790b8dc Remove log statement that was commented out 2022-11-12 20:32:09 +01:00
Jannis Christopher Köhl
2e034dc68c Exclude locals completely, instead of individual places 2022-11-12 14:57:14 +01:00
Jannis Christopher Köhl
3c6d1a723d Add test for repr(transparent) with scalar 2022-11-11 11:24:31 +01:00
Jannis Christopher Köhl
8ecb276735 Simplify creation of map 2022-11-10 19:12:10 +01:00
Jannis Christopher Köhl
9766ee0b20 Fix struct field tracking and add tests for it 2022-11-09 18:21:42 +01:00
Jannis Christopher Köhl
bfbca6c75c Completely remove tracking of references for now 2022-11-09 18:03:30 +01:00
Jannis Christopher Köhl
3997893ccb Fix rebase 2022-11-07 11:01:44 +01:00
Jannis Christopher Köhl
89f934917d Small corrections of documentation 2022-11-07 10:35:26 +01:00
Jannis Christopher Köhl
630e17d3e4 Limit number of tracked places, and some other perf improvements 2022-11-07 10:35:26 +01:00
Jannis Christopher Köhl
1f82a9f89e Move HasTop and HasBottom into lattice.rs 2022-11-07 10:35:25 +01:00
Jannis Christopher Köhl
de69d088a4 Explicitly match all terminators 2022-11-07 10:35:24 +01:00
Jannis Christopher Köhl
5b7b309c60 Improve documentation of assumptions 2022-11-07 10:35:24 +01:00
Jannis Christopher Köhl
274a49132b Improve documentation, plus some small changes 2022-11-07 10:35:23 +01:00
Jannis Christopher Köhl
aaa35b3e48 Add comment for the current retag situation 2022-11-07 10:35:22 +01:00
Jannis Christopher Köhl
3c0f3b04b5 Only assume Stacked Borrows if -Zunsound-mir-opts is given 2022-11-07 10:35:21 +01:00
Jannis Christopher Köhl
111324e17c Prevent registration inside references if target is !Freeze 2022-11-07 10:35:20 +01:00
Jannis Christopher Köhl
4478a87018 Fix formatting 2022-11-07 10:35:20 +01:00
Jannis Christopher Köhl
7ab1ba95de Remove Unknown state in favor of Value(Top) 2022-11-07 10:35:20 +01:00
Jannis Christopher Köhl
1765587846 Only track (trivially) freeze types 2022-11-07 10:35:20 +01:00
Jannis Christopher Köhl
b5063ab0e5 Make more assumptions explicit 2022-11-07 10:35:19 +01:00
Jannis Christopher Köhl
2f66e9417f Flood with bottom for Deinit, StorageLive and StorageDead 2022-11-07 10:35:19 +01:00
Jannis Christopher Köhl
eab77320e6 Handle NonDivergingIntrinsic and CopyNonOverlapping 2022-11-07 10:35:19 +01:00
Jannis Christopher Köhl
f99950f6ae Update test results after rebase 2022-11-07 10:35:18 +01:00
Jannis Christopher Köhl
c56e99cdba Fix typo 2022-11-07 10:35:18 +01:00
Jannis Christopher Köhl
13b70599c1 Only allow registration of scalars for now 2022-11-07 10:35:16 +01:00
Jannis Christopher Köhl
817c27744d Handle StorageLive 2022-11-07 10:35:16 +01:00
Jannis Christopher Köhl
e2ddf8a6e5 Add comment about downcast projection element 2022-11-07 10:35:15 +01:00
Jannis Christopher Köhl
1e5ca57014 Use StorageDead and Deinit to flood place 2022-11-07 10:35:15 +01:00
Jannis Christopher Köhl
904adcac0f Flood place on drop 2022-11-07 10:35:15 +01:00
Jannis Christopher Köhl
2113e45488 Remove superfluous line 2022-11-07 10:35:14 +01:00
Jannis Christopher Köhl
2e4d0820d2 Add more documentation 2022-11-07 10:35:14 +01:00
Jannis Christopher Köhl
fe84bbf844 Add tracking of unreachability 2022-11-07 10:35:13 +01:00
Jannis Christopher Köhl
16dedba1c8 Ignore terminators explicitly 2022-11-07 10:35:13 +01:00
Jannis Christopher Köhl
8a789ce009 Reject registration of downcasts for now 2022-11-07 10:35:12 +01:00
Jannis Christopher Köhl
ad99d2e15d Move handling of references and simplify flooding 2022-11-07 10:35:11 +01:00
Jannis Christopher Köhl
3f98dc7838 Clarify place expressions vs place objects 2022-11-07 10:35:11 +01:00
Jannis Christopher Köhl
e75ad93d95 Begin a semi-formal argument for correctness 2022-11-07 10:35:10 +01:00
Jannis Christopher Köhl
292869493c Add additional flooding when assigning a value and corresponding test 2022-11-07 10:35:10 +01:00