| Age | Commit message (Collapse) | Author | Lines |
|
NLL should identify and respect the lifetime annotations that the user wrote
Part of #47184.
r? @nikomatsakis
|
|
|
|
|
|
Previously, "_1" was not marked as "definitely uninitialized" after a "switchInt(move _1)" terminator.
Related discussion: https://internals.rust-lang.org/t/why-is-2-definitely-initialized-after-switchint-move-2/6760
|
|
Sometimes a simple goto misses the cleanup/unwind edges. Specifically, in the
case of infinite loops such as those introduced by a loop statement without any
other out edges. Analogous to TerminatorKind::FalseEdges; this new terminator
kind is used when we want borrowck to consider an unwind path, but real control
flow should never actually take it.
|
|
|
|
[MIR Borrowck] Moveck inline asm statements
Closes #45695
New behavior:
* Input operands to `asm!` are moved, direct output operands are initialized.
* Direct, non-read-write outputs match the assignment changes in #46752 (Shallow writes, end borrows).
|
|
|
|
The Abort Terminatorkind will cause an llvm.trap function call to be
emitted.
Signed-off-by: David Henningsson <diwic@ubuntu.com>
|
|
High-level picture: The old `Borrows` analysis is now called
`Reservations` (implemented as a newtype wrapper around `Borrows`);
this continues to compute whether a `Rvalue::Ref` can reach a
statement without an intervening `EndRegion`. In addition, we also
track what `Place` each such `Rvalue::Ref` was immediately assigned
to in a given borrow (yay for MIR-structural properties!).
The new `ActiveBorrows` analysis then tracks the initial use of any of
those assigned `Places` for a given borrow. I.e. a borrow becomes
"active" immediately after it starts being "used" in some way. (This
is conservative in the sense that we will treat a copy `x = y;` as a
use of `y`; in principle one might further delay activation in such
cases.)
The new `ActiveBorrows` analysis needs to take the `Reservations`
results as an initial input, because the reservation state influences
the gen/kill sets for `ActiveBorrows`. In particular, a use of `a`
activates a borrow `a = &b` if and only if there exists a path (in the
control flow graph) from the borrow to that use. So we need to know if
the borrow reaches a given use to know if it really gets a gen-bit or
not.
* Incorporating the output from one dataflow analysis into the input
of another required more changes to the infrastructure than I had
expected, and even after those changes, the resulting code is still
a bit subtle.
* In particular, Since we need to know the intrablock reservation
state, we need to dynamically update a bitvector for the
reservations as we are also trying to compute the gen/kills
bitvector for the active borrows.
* The way I ended up deciding to do this (after also toying with at
least two other designs) is to put both the reservation state and
the active borrow state into a single bitvector. That is why we now
have separate (but related) `BorrowIndex` and
`ReserveOrActivateIndex`: each borrow index maps to a pair of
neighboring reservation and activation indexes.
As noted above, these changes are solely adding the active borrows
dataflow analysis (and updating the existing code to cope with the
switch from `Borrows` to `Reservations`). The code to process the
bitvector in the borrow checker currently just skips over all of the
active borrow bits.
But atop this commit, one *can* observe the analysis results by
looking at the graphviz output, e.g. via
```rust
#[rustc_mir(borrowck_graphviz_preflow="pre_two_phase.dot",
borrowck_graphviz_postflow="post_two_phase.dot")]
```
Includes doc for `FindPlaceUses`, as well as `Reservations` and
`ActiveBorrows` structs, which are wrappers are the `Borrows` struct
that dictate which flow analysis should be performed.
|
|
In particular, if we see a variable is DROP-LIVE, but it is not
MAYBE-INIT, then we can ignore the drop. This leavess attempt to use
more complex refinements of the idea (e.g., for subpaths or subfields)
to future work.
|
|
|
|
|
|
|
|
* Used for new dataflow to track if a variable has every been initialized
* Used for other dataflows that need to be updated for initializations
|
|
|
|
|
|
|
|
Also, factor out `do_mir_borrowck`, which is the code that actually
performs the MIR borrowck from within the scope of an inference context.
This change should be a pure refactoring.
|
|
This will be important in next commit, since the input types will be
tagged not with `'gcx` but rather `'tcx`. Also, using the region-erased,
lifted types enables better caching.
|
|
Implicitly threaded `Location` through MoveData construction via a
`Gatherer` struct (so that we could look up the span corresponding to
the location when we need to signal an error).
|
|
Currently is using DUMMY_SP as the associated span; a follow-up commit
will pass in appropriate spans when constructing the errors.
|
|
|
|
|
|
|
|
One can either use `-Z borrowck-mir` or add the `#[rustc_mir_borrowck]` attribute
to opt into MIR based borrow checking.
Note that regardless of whether one opts in or not, AST-based borrow
check will still run as well. The errors emitted from AST-based
borrow check will include a "(Ast)" suffix in their error message,
while the errors emitted from MIR-based borrow check will include a
"(Mir)" suffix.
post-rebase: removed check for intra-statement mutual conflict;
replaced with assertion checking that at most one borrow is generated
per statement.
post-rebase: removed dead code: `IdxSet::pairs` and supporting stuff.
|
|
|
|
post-rebase: addressed review comment: rename `loc_map`/`location_map` and `rgn_map`/`region_map`.
post-rebase: remove now unnecessary `mut` decl.
post-rebase: address comments: bind iterator expr, and alpha-rename `loc`/`location` and `idx`/`index`.
|
|
Like #43008 (f668999), but _much more aggressive_.
|
|
# Conflicts:
# src/librustc_mir/build/scope.rs
|
|
This falls naturally out of making drop elaboration work with `box`
expressions, which is probably required for sane MIR borrow-checking.
This is a pure refactoring with no intentional functional effects.
|
|
|
|
when we can rely on them being locked in memory
|
|
|
|
|
|
|
|
Leaving types unerased would lead to 2 types with a different "name"
getting different move-paths, which would cause major brokenness (see
e.g. #42903).
This does not fix any *known* issue, but is required if we want to use
abs_domain with non-erased regions (because the same can easily
have different names). cc @RalfJung.
|
|
Make the "main" constructors of NonZero/Shared/Unique return Option
Per discussion in https://github.com/rust-lang/rust/issues/27730#issuecomment-303939441.
This is a breaking change to unstable APIs.
The old behavior is still available under the name `new_unchecked`. Note that only that one can be `const fn`, since `if` is currently not allowed in constant contexts.
In the case of `NonZero` this requires adding a new `is_zero` method to the `Zeroable` trait. I mildly dislike this, but it’s not much worse than having a `Zeroable` trait in the first place. `Zeroable` and `NonZero` are both unstable, this can be reworked later.
|
|
|
|
… to protect against UB in the unlikely case that `idx + 1` overflows.
|
|
|
|
Turn `elaborate_drops` and `rustc_peek` implementations into MIR
passes that also live in `rustc_mir` crate.
Rewire things so `rustc_driver` uses the `ElaborateDrops` from
`rustc_mir` crate.
|