about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src/polonius
AgeCommit message (Collapse)AuthorLines
2025-09-16Remove Rvalue::Len.Camille Gillot-7/+2
2025-09-01Introduce `MirDumper` and `MirWriter`.Nicholas Nethercote-55/+32
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.
2025-09-01Use trait object references for closures.Nicholas Nethercote-1/+1
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.
2025-08-11Rollup merge of #145111 - fee1-dead-contrib:push-rlvnyrztlkpq, r=jieyouxuGuillaume Gomez-16/+0
remove some unused private trait impls they're neither required for completeness nor used
2025-08-09remove some unused private trait implsDeadbeef-16/+0
2025-08-08turn expensive assert into debug assertionRémy Rakic-2/+3
2025-08-08simplify polonius=nextRémy Rakic-199/+28
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.
2025-07-06Rollup merge of #143477 - folkertdev:use-is-multiple-of, r=joshtriplettMatthias Krüger-1/+1
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.
2025-07-05use `is_multiple_of` instead of manual moduloFolkert de Vries-1/+1
2025-07-04Remove Symbol for Named LateParam/Bound variantsMichael Goulet-7/+10
2025-06-04Use an enum for SCC representatives, plus other code reviewAmanda Stjerna-1/+1
Co-authored-by: lcnr <rust@lcnr.de>
2025-06-03Move placeholder handling to a proper preprocessing stepAmanda Stjerna-3/+3
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.
2025-04-28AsyncDrop implementation using shim codegen of ↵Andrew Zhogin-1/+8
async_drop_in_place::{closure}, scoped async drop added.
2025-04-11move `dump_polonius_mir`lcnr-1/+1
2025-04-08Auto merge of #139536 - matthiaskrgr:rollup-j6goald, r=matthiaskrgrbors-2/+2
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
2025-04-08move `ClosureRegionRequirements` to `rustc_borrowck`lcnr-2/+2
2025-04-07rm `RegionInferenceContext::var_infos`lcnr-2/+2
we already track this info in the `definitions` field
2025-02-22Greatly simplify lifetime captures in edition 2024Michael Goulet-1/+1
2025-02-21Make `PassWhere` impl `Copy`.Nicholas Nethercote-1/+1
It's a very small and simple type.
2025-02-03Rollup merge of #136299 - lqd:polonius-next-episode-9, r=jackh726Matthias Krüger-44/+81
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``
2025-01-31Implement MIR, CTFE, and codegen for unsafe bindersMichael Goulet-0/+4
2025-01-31record boring locals in polonius contextRémy Rakic-16/+26
this is used in diagnostics to focus on relevant live locals to match NLL diagnostics
2025-01-31create context for errors and diagnostics for last borrowck phaseRémy Rakic-10/+20
2025-01-31split polonius context into per-phase dataRémy Rakic-30/+47
- describe how that data flows during borrowck - prepares for recording some liveness data for diagnostics, not just for the main analysis
2025-01-30add constraint graph to polonius MIR dumpRémy Rakic-9/+101
2025-01-29Rollup merge of #136104 - lqd:polonius-debugger-episode-2, r=matthewjasperLeón Orell Valerian Liehr-5/+136
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
2025-01-28Represent the raw pointer for a array length check as a new kind of fake borrowMichael Goulet-11/+10
2025-01-26tidy up html structureRémy Rakic-4/+4
- invert pre/code which was an invalid combination, that works fine in practice - remove unneeded code wrapper for graphs
2025-01-26add NLL SCCs to polonius MIR dumpRémy Rakic-0/+49
2025-01-26add NLL region graph to the polonius MIR dumpRémy Rakic-1/+83
2025-01-25add CFG to polonius MIR dumpRémy Rakic-2/+71
2025-01-25switch polonius MIR dump to HTMLRémy Rakic-9/+67
escape the regular raw MIR into its own section
2025-01-25use more explicit MIR dumping processRémy Rakic-4/+36
2025-01-19Auto merge of #135709 - lqd:bring-back-len, r=compiler-errorsbors-2/+7
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.
2025-01-18Revert "Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper"Rémy Rakic-2/+7
This reverts commit e108481f74ff123ad98a63bd107a18d13035b275, reversing changes made to 303e8bd768526a5812bb1776e798e829ddb7d3ca.
2025-01-17encode `Locations::All` typeck constraints as logical edgesRémy Rakic-25/+49
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.
2025-01-17make `LocalizedConstraintGraph` a struct and not an aliasRémy Rakic-21/+23
this prepares the code structure for adding logical edges to the graph next
2025-01-12deal with naive reachability weaknessRémy Rakic-13/+82
it's a bit mind-bending
2025-01-12handle kills in reachabilityRémy Rakic-7/+126
2025-01-12replace location-insensitive analysis with location-sensitive analysisRémy Rakic-4/+3
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
2025-01-12introduce reachability to the constraint graphRémy Rakic-5/+107
2025-01-08rename `AllFacts` to `PoloniusFacts`Rémy Rakic-21/+21
This is another strangely named struct (and associated fields) that is hard to see was related to datalog polonius.
2025-01-08rename `LocationTable` to `PoloniusLocationTable`Rémy Rakic-32/+32
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.
2025-01-06address review commentsRémy Rakic-21/+31
push constraint creation to where the statement/terminator info is gathered
2025-01-01remove borrowck duplicate of `std::ops::ControlFlow`Rémy Rakic-2/+4
2025-01-01remove `allow_two_phase_borrow`Rémy Rakic-2/+2
it's been simplified over the years, but now it's no longer useful. - document its replacement in `BorrowKind` - use that everywhere instead
2025-01-01localize typeck constraintsRémy Rakic-3/+196
it's still partially a skeleton, but works well enough for almost all tests to pass
2025-01-01move typeck constraints conversion to its own moduleRémy Rakic-39/+44
2024-12-30move `facts` module to polonius legacy moduleRémy Rakic-7/+258
this is specific to the old datalog implementation and wasn't noticed in the previous module move
2024-12-30simplify `add_extra_drop_facts`Rémy Rakic-1/+8
this is mostly to remove imports of the polonius legacy module also what is going on in this function, what the...