Commit graph

541 commits

Author SHA1 Message Date
bjorn3
1fcae03369 Rustfmt 2025-02-08 22:12:13 +00:00
Felix S. Klock II
bcb8565f30 Contracts core intrinsics.
These are hooks to:

  1. control whether contract checks are run
  2. allow 3rd party tools to intercept and reintepret the results of running contracts.
2025-02-03 12:53:57 -08:00
Michael Goulet
fc1a9186dc Implement MIR, CTFE, and codegen for unsafe binders 2025-01-31 17:19:53 +00:00
Michael Goulet
eeecb56b73 Represent the raw pointer for a array length check as a new kind of fake borrow 2025-01-28 00:00:33 +00:00
Yotam Ofek
264fa0fc54 Run clippy --fix for unnecessary_map_or lint 2025-01-19 19:15:00 +00:00
Rémy Rakic
ca1c17c88d Revert "Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper"
This reverts commit e108481f74, reversing
changes made to 303e8bd768.
2025-01-18 22:09:34 +00:00
Rémy Rakic
a13354bea0 rename BitSet to DenseBitSet
This should make it clearer that this bitset is dense, with the
advantages and disadvantages that it entails.
2025-01-11 11:34:01 +00:00
bors
f3343420c8 Auto merge of #134625 - compiler-errors:unsafe-binders-ty, r=oli-obk
Begin to implement type system layer of unsafe binders

Mostly TODOs, but there's a lot of match arms that are basically just noops so I wanted to split these out before I put up the MIR lowering/projection part of this logic.

r? oli-obk

Tracking:

- https://github.com/rust-lang/rust/issues/130516
2024-12-24 00:51:51 +00:00
Michael Goulet
9a1c5eb5b3 Begin to implement type system layer of unsafe binders 2024-12-22 21:57:57 +00:00
Scott McMurray
5ba54c9e31 Delete Rvalue::Len
Everything's moved to `PtrMetadata` instead.
2024-12-22 06:12:39 -08:00
bors
b22856d192 Auto merge of #134326 - scottmcm:slice-drop-shim-ptrmetadata, r=saethlin
Use `PtrMetadata` instead of `Len` in slice drop shims

I tried to do a bigger change in #134297 which didn't work, so here's the part I really wanted: Removing another use of `Len`, in favour of `PtrMetadata`.

Split into two commits where the first just adds a test, so you can look at the second commit to see how the drop shim for an array changes with this PR.

Reusing the same reviewer from the last one:
r? BoxyUwU
2024-12-22 13:28:12 +00:00
bors
c434b4b4b6 Auto merge of #133328 - nnethercote:simplify-SwitchInt-handling, r=tmiasko
Simplify `SwitchInt` handling

Dataflow handling of `SwitchInt` is currently complicated. This PR simplifies it.

r? `@cjgillot`
2024-12-18 22:57:23 +00:00
许杰友 Jieyou Xu (Joe)
477f222b02
Rollup merge of #134161 - nnethercote:overhaul-token-cursors, r=spastorino
Overhaul token cursors

Some nice cleanups here.

r? `````@davidtwco`````
2024-12-18 22:56:53 +08:00
Nicholas Nethercote
8a85bdc9fb Remove a comment that shouldn't have been committed. 2024-12-18 15:54:17 +11:00
Nicholas Nethercote
2620eb42d7 Re-export more rustc_span::symbol things from rustc_span.
`rustc_span::symbol` defines some things that are re-exported from
`rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some
closely related things such as `Ident` and `kw`. So you can do `use
rustc_span::{Symbol, sym}` but you have to do `use
rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good
reason.

This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`,
and changes many `rustc_span::symbol::` qualifiers in `compiler/` to
`rustc_span::`. This is a 200+ net line of code reduction, mostly
because many files with two `use rustc_span` items can be reduced to
one.
2024-12-18 13:38:53 +11:00
Nicholas Nethercote
5f40942f9c Remove a FIXME comment.
It is possible to avoid the clone as suggested in the comment. It would
require introducing an enum with two variants
`CloneBeforeModifying(&Domain)` and `Modifiable(&mut Domain)`. But it's
not worth the effort, because this code path just isn't very hot. E.g.
when compiling a large benchmark like `cargo-0.60.0` it's only hit a few
thousand times.
2024-12-16 09:36:09 +11:00
Nicholas Nethercote
83f3d204cf Remove opt_clone_from_or_clone.
Switches to the idiom used elsewhere of calling `Analysis::bottom_value`
to initialize a `state` value outside a loop, and then using
`clone_from` to update it within the loop. This is simpler and has no
impact on performance.
2024-12-16 09:36:09 +11:00
Nicholas Nethercote
c8c50f4351 Factor out some shared code from Maybe{In,Unin}itializedPlaces. 2024-12-16 09:36:09 +11:00
Nicholas Nethercote
4d8316f4d4 Simplify dataflow SwitchInt handling.
Current `SwitchInt` handling has complicated control flow.

- The dataflow engine calls `Analysis::apply_switch_int_edge_effects`,
  passing in an "applier" that impls `SwitchIntEdgeEffects`.
- `apply_switch_int_edge_effects` possibly calls `apply` on the applier,
  passing it a closure.
- The `apply` method calls the closure on each `SwitchInt` edge.
- The closure operates on the edge.

I.e. control flow goes from the engine, to the analysis, to the applier
(which came from the engine), to the closure (which came from the
analysis). It took me a while to work this out.

This commit changes to a simpler structure that maintains the important
characteristics.

- The dataflow engine calls `Analysis::get_switch_int_data`.
- `get_switch_int_data` returns an `Option<Self::SwitchIntData>` value.
- If that returned value was `Some`, the dataflow engine calls
  `Analysis::apply_switch_int_edge_effect` on each edge, passing the
  `Self::SwitchIntData` value.
- `Analysis::apply_switch_int_edge_effect` operates on the edge.

I.e. control flow goes from the engine, to the analysis, to the
engine, to the analysis.

Added:
- The `Analysis::SwitchIntData` assoc type and the
  `Analysis::get_switch_int_data` method. Both only need to be
  defined by analyses that look at `SwitchInt` terminators.
- The `MaybePlacesSwitchIntData` struct, which has three fields.

Changes:
- `Analysis::apply_switch_int_edge_effects` becomes
  `Analysis::apply_switch_int_edge_effect`, which is a little simpler
  because it's dealing with a single edge instead of all edges.

Removed:
- The `SwitchIntEdgeEffects` trait, and its two impls:
  `BackwardSwitchIntEdgeEffectsApplier` (which has six fields) and
  `ForwardSwitchIntEdgeEffectsApplier` structs (which has four fields).
- The closure.

The new structure is more concise and simpler.
2024-12-16 09:36:07 +11:00
Nicholas Nethercote
848610fddc Add a comment to MaybeInitializedPlaces::apply_terminator_effect.
I tried reordering this method to more closely match
`MaybeUninitializedPlaces::apply_terminator_effect`, but doing so breaks
tests.
2024-12-16 09:24:46 +11:00
Scott McMurray
8acccdc355 Use PtrMetadata instead of Len in slice drop shims 2024-12-14 21:29:45 -08:00
Matthias Krüger
c6ebe6fe3b
Rollup merge of #133938 - nnethercote:rustc_mir_dataflow-renamings, r=oli-obk
`rustc_mir_dataflow` cleanups, including some renamings

Some opinionated commits in this collection, let's see how we go.

r? `@cjgillot`
2024-12-13 17:25:29 +01:00
Nicholas Nethercote
67df7cbf31 Simplify rustc_mir_dataflow::abs_domain.
`rustc_mir_dataflow` has a typedef `AbstractElem` that is equal to
`ProjectionElem<AbstractOperand, AbstractType>`. `AbstractOperand` and
`AbstractType` are both unit types. There is also has a trait `Lift` to
convert a `PlaceElem` to an `AbstractElem`.

But `rustc_mir_middle` already has a typedef `ProjectionKind` that is
equal to `ProjectionElem<(), ()>`, which is equivalent to
`AbstractElem`. So this commit reuses `ProjectionKind` in
`rustc_mir_dataflow`, removes `AbstractElem`, and simplifies the `Lift`
trait.
2024-12-11 10:45:47 +11:00
León Orell Valerian Liehr
06107a20e3
Rollup merge of #134065 - nnethercote:mv-write_graphviz_results, r=tmiasko
Move `write_graphviz_results`

r? ``@tmiasko``
2024-12-10 13:51:12 +01:00
Nicholas Nethercote
dddc09d2c3 Reorder some Analysis methods.
In most places, the `early` method is listed before the corresponding
`primary` method, like you'd expect. This commit fixes two places where
that isn't the case.
2024-12-10 12:09:25 +11:00
Nicholas Nethercote
1d56943f34 Rename some Analysis and ResultsVisitor methods.
The words "before" and "after" have an obvious temporal meaning, e.g.
`seek_before_primary_effect`,
`visit_statement_{before,after}_primary_effect`. But "before" is also
used to name the effect that occurs before the primary effect of a
statement/terminator; this is `Effect::Before`. This leads to the
confusing possibility of talking about things happening "before/after
the before event".

This commit removes this awkward overloading of "before" by renaming
`Effect::Before` as `Effect::Early`. It also renames some of the
`Analysis` and `ResultsVisitor` methods to be more consistent.

Here are the before and after names:

- `Effect::{Before,Primary}`              -> `Effect::{Early,Primary}`
- `apply_before_statement_effect`         -> `apply_early_statement_effect`
- `apply_statement_effect`                -> `apply_primary_statement_effect`
- `visit_statement_before_primary_effect` -> `visit_after_early_statement_effect`
- `visit_statement_after_primary_effect`  -> `visit_after_primary_statement_effect`

(And s/statement/terminator/ for all the terminator events.)
2024-12-10 12:07:13 +11:00
Nicholas Nethercote
b059ea857c Rename EntrySets as EntryStates.
"Set" doesn't make much sense here, we refer to domain values as "state"
everywhere else. (This name confused me for a while.)
2024-12-10 12:04:45 +11:00
Nicholas Nethercote
2298104f3f Call all Domain values state.
Currently they are called (most common) `state`, or `trans`, or (rare)
`on_entry`. I think `trans` is short for "transfer function", which
perhaps made more sense when `GenKillAnalysis` existed. Using `state`
everywhere now is more consistent.
2024-12-10 12:03:56 +11:00
Nicholas Nethercote
086233e282 Refer to a couple of domains indirectly.
Via the `Analysis::Domain` associated types, instead of the direct type
name.
2024-12-10 12:02:50 +11:00
Nicholas Nethercote
d490ea1f39 Remove lifetimes from BorrowckDomain.
They are only present because it's currently defined in terms of the
domains of `Borrows` and `MaybeUninitializedPlaces` and
`EverInitializedPlaces` via associated types. This commit introduces
typedefs for those domains, avoiding the lifetimes.
2024-12-10 12:02:48 +11:00
Nicholas Nethercote
83f67c5915 Remove unused dataflow trait impls and bounds. 2024-12-10 11:52:30 +11:00
Nicholas Nethercote
0dbb31f7e7 Fix an out-of-date comment. 2024-12-10 11:52:05 +11:00
Nicholas Nethercote
b59c4dc261 Remove an out-of-date comment.
The part about zero-sized structures is totally wrong. The rest of
it has almost no explanatory value; there are better explanations in
comments elsewhere.
2024-12-09 20:49:36 +11:00
Nicholas Nethercote
db760e27fd Move write_graphviz_results from results.rs to graphviz.rs.
It's more graphviz-y than it is results-y. This lets us reduce
visibility of several types in `graphviz.rs`.
2024-12-09 20:49:36 +11:00
Nicholas Nethercote
fa6ceba208 Remove ChunkedBitSet impls that are no longer needed.
`ChunkedBitSet` is no longer used directly by dataflow analyses, with
`MixedBitSet` replacing it in those contexts.
2024-12-09 08:53:35 +11:00
Nicholas Nethercote
34f45f0d8f Use MixedBitSet instead of ChunkedBitSet in fmt.rs.
Just minimizing uses of `ChunkedBitSet`.
2024-12-09 08:53:35 +11:00
Nicholas Nethercote
a06547508a Change ChunkedBitSet<MovePathIndex>s to MixedBitSet.
It's a performance win because `MixedBitSet` is faster and uses less
memory than `ChunkedBitSet`.

Also reflow some overlong comment lines in
`lint_tail_expr_drop_order.rs`.
2024-12-05 20:07:26 +11:00
Nicholas Nethercote
6ee1a7aaa0 Introduce MixedBitSet.
It just uses `BitSet` for small/medium sizes (<= 2048 bits) and
`ChunkedBitSet` for larger sizes. This is good because `ChunkedBitSet`
is slow and memory-hungry at smaller sizes.
2024-12-05 20:07:25 +11:00
Nicholas Nethercote
cecef131a2 Simplify ResultsHandle.
The `Borrowed` variant is no longer used. This commit removes it, along
with the `as_results_cursor` method that produces it, and renames
`as_results_cursor_mut` as `as_results_cursor`.
2024-12-02 16:19:17 +11:00
Nicholas Nethercote
d37ed10634 Fix crash with -Zdump-mir-dataflow
As of #133155 `Formatter:new` uses `as_results_cursor` to create a
non-mutable results reference, and then later that is accessed via
`deref_mut` which results in a runtime abort. Changing to
`as_results_cursor_mut` fixes it.

Fixes #133641.
2024-12-02 16:17:55 +11:00
Nicholas Nethercote
0df6a018e1 Stop using HybridBitSet in dataflow diffs.
As part of the larger goal of reducing `HybridBitSet` use in general.
This code is for debugging only and isn't performance sensitive, so
`ChunkedBitSet` should be fine.
2024-11-29 17:23:34 +11:00
Nicholas Nethercote
346929cb80 Remove unused HybridBitSet methods from BitSetExt. 2024-11-29 17:23:34 +11:00
Michael Goulet
219b2a010d
Rollup merge of #133475 - nnethercote:MaybeStorage-improvements, r=lcnr
`MaybeStorage` improvements

Minor dataflow improvements.

r? `@tmiasko`
2024-11-26 20:35:40 -05:00
Michael Goulet
3e1a089257
Rollup merge of #133326 - nnethercote:rm-DefinitelyInitializedPlaces, r=cjgillot
Remove the `DefinitelyInitializedPlaces` analysis.

Its only use is in the `tests/ui/mir-dataflow/def_inits-1.rs` where it is tested via `rustc_peek_definite_init`.

Also, it's probably buggy. It's supposed to be the inverse of `MaybeUninitializedPlaces`, and it mostly is, except that `apply_terminator_effect` is a little different, and `apply_switch_int_edge_effects` is missing. Unlike `MaybeUninitializedPlaces`, which is used extensively in borrow checking, any bugs in `DefinitelyInitializedPlaces` are easy to overlook because it is only used in one small test.

This commit removes the analysis. It also removes
`rustc_peek_definite_init`, `Dual` and `MeetSemiLattice`, all of which are no longer needed.

r? ``@cjgillot``
2024-11-26 12:03:42 -05:00
Nicholas Nethercote
a602cb666a Make some modules non-pub.
- drop_flag_effects: `pub` items within are all re-exported in `lib.rs`.
- un_derefer: doesn't contain any `pub` items.
2024-11-26 12:05:57 +11:00
Nicholas Nethercote
3d12160dfc Move always_storage_live_locals.
It's very closely related to `MaybeStorageLive` and `MaybeStorageDead`.
It's weird that it's currently in a different module.
2024-11-26 12:05:57 +11:00
Nicholas Nethercote
71789427a3 Improve MaybeStorageLive::initialize_start_block.
We can union the two sets the easy way. This removes the need for the
domain size check, because `union` does that same check itself.
2024-11-26 12:05:44 +11:00
Nicholas Nethercote
be7c6a3b43 Make it possible for ResultsCursor to borrow a Results.
`ResultsCursor` currently owns its `Results`. But sometimes the
`Results` is needed again afterwards. So there is
`ResultsCursor::into_results` for extracting the `Results`, which leads
to some awkwardness.

This commit adds `ResultsHandle`, a `Cow`-like type that can either
borrow or own a a `Results`. `ResultsCursor` now uses it. This is good
because some `ResultsCursor`s really want to own their `Results`, while
others just want to borrow it.

We end with with a few more lines of code, but get some nice cleanups.
- `ResultsCursor::into_results` and `Formatter::into_results` are
  removed.
- `write_graphviz_results` now just borrows a `Results`, instead of the
  awkward "take ownership of a `Results` and then return it unchanged"
  pattern.

This reinstates the cursor flexibility that was lost in #118230 -- which
removed the old `ResultsRefCursor` and `ResultsCloneCursor` types -- but
in a much simpler way. Hooray!
2024-11-26 11:23:40 +11:00
Nicholas Nethercote
1914dbe694 Tweak MaybeBorrowedLocals::transfer_function usage.
In `MaybeRequiresStorage::apply_before_statement_effect`, call
`transfer_function` directly, as is already done in
`MaybeRequiresStorage::apply_before_terminator_effect`. This makes it clear
that the operation doesn't rely on the `MaybeBorrowedLocals` results.
2024-11-26 11:23:40 +11:00
Nicholas Nethercote
dae019dc9d Remove self param for MaybeBorrowedLocals::transfer_function.
It is unnecessary.
2024-11-26 11:23:40 +11:00