| Age | Commit message (Collapse) | Author | Lines |
|
|
|
MIR dumping is a mess. There are lots of functions and entry points,
e.g. `dump_mir`, `dump_mir_with_options`, `dump_polonius_mir`,
`dump_mir_to_writer`. Also, it's crucial that `create_dump_file` is
never called without `dump_enabled` first being checked, but there is no
mechanism for ensuring this and it's hard to tell if it is satisfied on
all paths. (`dump_enabled` is checked twice on some paths, however!)
This commit introduces `MirWriter`, which controls the MIR writing, and
encapsulates the `extra_data` closure and `options`. Two existing
functions are now methods of this type. It sets reasonable defaults,
allowing the removal of many `|_, _| Ok(())` closures.
The commit also introduces `MirDumper`, which is layered on top of
`MirWriter`, and which manages the creation of the dump files,
encapsulating pass names, disambiguators, etc. Four existing functions
are now methods of this type.
- `MirDumper::new` will only succeed if dumps are enabled, and will
return `None` otherwise, which makes it impossible to dump when you
shouldn't.
- It also sets reasonable defaults for various things like
disambiguators, which means you no longer need to specify them in many
cases. When they do need to be specified, it's now done via setter
methods.
- It avoids some repetition. E.g. `dump_nll_mir` previously specifed the
pass name `"nll"` four times and the disambiguator `&0` three times;
now it specifies them just once, to put them in the `MirDumper`.
- For Polonius, the `extra_data` closure can now be specified earlier,
which avoids having to pass some arguments through some functions.
|
|
The dynamic dispatch cost doesn't matter for MIR dumping, which is
perf-insensitive. And it's necessary for the next commit, which will
store some `extra_data` closures in a struct.
|
|
remove some unused private trait impls
they're neither required for completeness nor used
|
|
|
|
|
|
Remove incomplete handling of kills during traversal for loan liveness
to get to a simpler and actionable prototype.
This handles the cases, on sufficiently simple examples, that were
deferred from NLLs (NLL problem case 3, lending iterators), and is still
a good step to put in people's hands without needing to wait for another
full implementation. This is a practical cut in scope, but it also
shows where are the areas of improvement, that we will explore in the
future.
|
|
use `is_multiple_of` and `div_ceil`
In tricky logic, these functions are much more informative than the manual implementations. They also catch subtle bugs:
- the manual `is_multiple_of` often does not handle division by zero
- manual `div_ceil` often does not consider overflow
The transformation is free for `is_multiple_of` if the divisor is compile-time known to be non-zero. For `div_ceil` there is a small cost to considering overflow. Here is some assembly https://godbolt.org/z/5zP8KaE1d.
|
|
|
|
|
|
Co-authored-by: lcnr <rust@lcnr.de>
|
|
This commit breaks out the logic of placheolder rewriting
into its own preprocessing step.
The only functional change from this is that the preprocessing
step (where extra `r: 'static` constraints are added) is
performed upstream of Polonius legacy, finally affecting
Polonius. That is mostly a by-product, though.
|
|
async_drop_in_place::{closure}, scoped async drop added.
|
|
|
|
Rollup of 7 pull requests
Successful merges:
- #139476 (rm `RegionInferenceContext::var_infos`)
- #139485 (compiletest: Stricter parsing for diagnostic kinds)
- #139491 (Update books)
- #139500 (document panic behavior of Vec::resize and Vec::resize_with)
- #139501 (Fix stack overflow in exhaustiveness due to recursive HIR opaque hidden types)
- #139504 (add missing word in doc comment)
- #139509 (clean: remove Deref<Target=RegionKind> impl for Region and use `.kind()`)
r? `@ghost`
`@rustbot` modify labels: rollup
|
|
|
|
we already track this info in the `definitions` field
|
|
|
|
It's a very small and simple type.
|
|
Ignore NLL boring locals in polonius diagnostics
Another easy one ``@jackh726`` (the diff is inflated by blessed test expectations don't worry :)
NLLs don't compute liveness for boring locals, and therefore cannot find them in causes explaining borrows. In polonius, we don't have this liveness optimization (we may be able to do something partially similar in the future, e.g. for function parameters and the like), so we do encounter these in diagnostics even though we don't want to. This PR:
- restructures the polonius context into per-phase data, in spirit as you requested in an earlier review
- stores the locals NLLs would consider boring into the errors/diagnostics data
- ignores these if a boring local is found when trying to explain borrows
This PR fixes around 80 cases of diagnostics differences between `-Zpolonius=next` and NLLs. I've also added explicit revisions to a few polonius tests (both for the in-tree implementation as well as the datalog implementation -- even if we'll eventually remove them). I didn't do this for all the "dead" expectations that were removed from #136112 for that same reason, it's fine. I'll soon/eventually add explicit revisions where they're needed: there's only a handful of tests left to fix.
r? ``@jackh726``
|
|
|
|
this is used in diagnostics to focus on relevant live locals to match
NLL diagnostics
|
|
|
|
- describe how that data flows during borrowck
- prepares for recording some liveness data for diagnostics, not just
for the main analysis
|
|
|
|
Add mermaid graphs of NLL regions and SCCs to polonius MIR dump
This PR expands the polonius MIR dump again with a couple of mermaid charts ported from the graphviz version:
- the NLL region graph
- and the NLL SCCs
I still have done zero visual design on this until now, but [here's](https://gistpreview.github.io/?fbbf900fed2ad21108c7ca0353456398) how it looks (i.e. still bad) just to give an idea of the result.
r? `````@matthewjasper````` (feel free to reassign) or anyone
|
|
|
|
- invert pre/code which was an invalid combination, that works fine in
practice
- remove unneeded code wrapper for graphs
|
|
|
|
|
|
|
|
escape the regular raw MIR into its own section
|
|
|
|
Temporarily bring back `Rvalue::Len`
r? `@compiler-errors` as requested in https://github.com/rust-lang/rust/issues/135671#issuecomment-2599580364
> However, in the mean time, I'd rather we not crunch trying to find and more importantly validate the soundness of a solution 🤔
Agreed. To fix the IMO P-critical #135671 for which we somehow didn't have test coverage, this PR temporarily reverts:
- https://github.com/rust-lang/rust/pull/133734
- its bugfix https://github.com/rust-lang/rust/pull/134371
- https://github.com/rust-lang/rust/pull/134330
cc `@scottmcm`
I added the few samples from that issue as a test, but we can add more in the future, in particular it seems `@steffahn` [will work on that](https://github.com/rust-lang/rust/issues/135671#issuecomment-2599714354).
Fixes #135671. And if we want to land this, it should also be nominated for beta backport.
|
|
This reverts commit e108481f74ff123ad98a63bd107a18d13035b275, reversing
changes made to 303e8bd768526a5812bb1776e798e829ddb7d3ca.
|
|
Instead of materializing `Locations::All` constraints as physical edges
at all the points in the CFG, we record them as logical edges and only
materialize them during traversal as successors for a given node.
This fixes the slowness/hang in the `saturating-float-casts.rs` test.
|
|
this prepares the code structure for adding logical edges to the graph next
|
|
it's a bit mind-bending
|
|
|
|
we're in in the endgame now
set up the location-sensitive analysis end to end:
- stop recording inflowing loans and loan liveness in liveness
- replace location-insensitive liveness data with live loans computed by
reachability
- remove equivalence between polonius scopes and NLL scopes, and only
run one scope computation
|
|
|
|
This is another strangely named struct (and associated fields) that is
hard to see was related to datalog polonius.
|
|
Its original naming hides the fact that it's related to datalog
polonius, and bound to be deleted in the near future.
It also conflicts with the expected name for the actual NLL location
map, and prefixing it with its use will make the differentiation
possible.
|
|
push constraint creation to where the statement/terminator info is gathered
|
|
|
|
it's been simplified over the years, but now it's no longer useful.
- document its replacement in `BorrowKind`
- use that everywhere instead
|
|
it's still partially a skeleton, but works well enough for almost all tests to pass
|
|
|
|
this is specific to the old datalog implementation and wasn't noticed in
the previous module move
|
|
this is mostly to remove imports of the polonius legacy module
also what is going on in this function, what the...
|