about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
AgeCommit message (Collapse)AuthorLines
2025-01-17Rollup merge of #134980 - lqd:polonius-next-episode-7, r=jackh726Matthias Krüger-171/+386
Location-sensitive polonius prototype: endgame This PR sets up the naive location-sensitive analysis end-to-end, and replaces the location-insensitive analysis. It's roughly all the in-progress work I wanted to land for the prototype, modulo cleanups I still want to do after the holidays, or the polonius debugger, and so on. Here, we traverse the localized constraint graph, have to deal with kills and time-traveling (👌), and record that as loan liveness for the existing scope and active loans computations. Then the near future looks like this, especially if the 2025h1 project goal is accepted: - gradually bringing it up to completion - analyzing and fixing the few remaining test failures - going over the *numerous* fixmes in this prototype (one of which is similar to a hang on one test's millions and millions of constraints) - trying to see how to lower the impact of the lack of NLL liveness optimization on diagnostics, and their categorization of local variables and temporaries (the vast majority of blessed expectations differences), as well as the couple ICEs trying to find an NLL constraint to blame for errors. - dealing with the theoretical weakness around kills, conflating reachability for the two TCS, etc that is described ad nauseam in the code. - switching the compare mode to the in-tree implementation, and blessing the diagnostics - apart from the hang, it's not catastrophically slower on our test suite, so then we can try to enable it on CI - checking crater, maybe trying to make it faster :3, etc. I've tried to gradually introduce this PR's work over 4 commits, because it's kind of subtle/annoying, and Niko/I are not completely convinced yet. That one comment explaining the situation is maybe 30% of the PR 😓. Who knew that spacetime reachability and time-traveling could be mind bending. I kinda found this late and the impact on this part of the computation was a bit unexpected to us. A bit more care/thought will be needed here. I've described my plan in the comments though. In any case, I believe we have the current implementation is a conservative approximation that shouldn't result in unsoundness but false positives at worst. So it feels fine for now. r? ``@jackh726`` --- Fixes #127628 -- which was a assertion triggered for a difference in loan computation between NLLs and the location-insensitive analysis. That doesn't exist anymore so I've removed this crash test.
2025-01-16Coerce safe-to-call target_feature functions to fn pointers.Luca Versari-1/+14
2025-01-14Rollup merge of #134940 - compiler-errors:scrape, r=lcnrJubilee-19/+48
Make sure to scrape region constraints from deeply normalizing type outlives assumptions in borrowck Otherwise we're just randomly registering these region relations into the infcx which isn't good r? lcnr
2025-01-14Make sure to scrape region constraints from deeply normalizing type outlives ↵Michael Goulet-19/+48
assumptions in borrowck
2025-01-14mir borrowck: cleanup late-bound region handlinglcnr-40/+26
2025-01-14Auto merge of #135465 - jhpratt:rollup-7p93bct, r=jhprattbors-2/+2
Rollup of 10 pull requests Successful merges: - #134498 (Fix cycle error only occurring with -Zdump-mir) - #134977 (Detect `mut arg: &Ty` meant to be `arg: &mut Ty` and provide structured suggestion) - #135390 (Re-added regression test for #122638) - #135393 (uefi: helpers: Introduce OwnedDevicePath) - #135440 (rm unnecessary `OpaqueTypeDecl` wrapper) - #135441 (Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024) - #135444 (Update books) - #135450 (Fix emscripten-wasm-eh with unwind=abort) - #135452 (bootstrap: fix outdated feature name in comment) - #135454 (llvm: Allow sized-word rather than ymmword in tests) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-13rm unnecessary `OpaqueTypeDecl` wrapperlcnr-2/+2
2025-01-13Assert that Instance::try_resolve is only used on body-like thingsMichael Goulet-38/+29
2025-01-12Auto merge of #135402 - matthiaskrgr:rollup-cz7hs13, r=matthiaskrgrbors-1/+0
Rollup of 6 pull requests Successful merges: - #129259 (Add inherent versions of MaybeUninit methods for slices) - #135374 (Suggest typo fix when trait path expression is typo'ed) - #135377 (Make MIR cleanup for functions with impossible predicates into a real MIR pass) - #135378 (Remove a bunch of diagnostic stashing that doesn't do anything) - #135397 (compiletest: add erroneous variant to `string_enum`s conversions error) - #135398 (add more crash tests) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-12Rollup merge of #135378 - compiler-errors:unnecessary-stashing, r=chenyukangMatthias Krüger-1/+0
Remove a bunch of diagnostic stashing that doesn't do anything #121669 removed a bunch of conditional diagnostic stashing/canceling, but left around the `steal` calls which just emitted the error eagerly instead of canceling the diagnostic. I think that these no-op `steal` calls don't do much and are confusing to encounter, so let's remove them. The net effect is: 1. We emit more duplicated errors, since stashing has the side effect of duplicating diagnostics. This is not a big deal, since outside of `-Zdeduplicate-diagnostics=no`, the errors are already being deduplicated by the compiler. 2. It changes the order of diagnostics, since we're no longer stashing and then later stealing the errors. I don't think this matters much for the changes that the UI test suite manifests, and it makes these errors less order dependent.
2025-01-12Rollup merge of #135364 - yotamofek:borrowck-diag-fix, r=compiler-errorsMatthias Krüger-13/+10
Cleanup `suggest_binding_for_closure_capture_self` diag in borrowck Mostly grammar fix/improvement, but also a small cleanup to use iterators instead of for loops for collecting into a vector.
2025-01-12move out of scope precomputer codeRémy Rakic-34/+32
this addresses review comments while: - keeping the symmetry between the NLL and Polonius out of scope precomputers - keeping the unstable `calculate_borrows_out_of_scope_at_location` function to avoid churn for consumers
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-140/+59
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-10/+112
2025-01-12disable NLL liveness optimization when using poloniusRémy Rakic-5/+13
in NLLs some locals are marked live at all points if one of their regions escapes the function but that doesn't work in a flow-sensitive setting like polonius
2025-01-11Remove a bunch of diagnostic stashing that doesn't do anythingMichael Goulet-1/+0
2025-01-11collect diag suggestions instead of pushing into vector repeatedlyYotam Ofek-12/+9
2025-01-11improve clunky grammar in borrowck diagnosticYotam Ofek-1/+1
2025-01-11rename `BitSet` to `DenseBitSet`Rémy Rakic-17/+18
This should make it clearer that this bitset is dense, with the advantages and disadvantages that it entails.
2025-01-08Remove special-casing for argument patterns in MIR typeckdianne-13/+0
2025-01-08Auto merge of #135260 - matthiaskrgr:rollup-8irqs72, r=matthiaskrgrbors-146/+153
Rollup of 6 pull requests Successful merges: - #134228 (Exhaustively handle expressions in patterns) - #135194 (triagebot: mark tidy changes with a more specific `A-tidy` label) - #135222 (Ensure that we don't try to access fields on a non-struct pattern type) - #135250 (A couple simple borrowck cleanups) - #135252 (Fix release notes link) - #135253 (Revert #131365) Failed merges: - #135195 (Make `lit_to_mir_constant` and `lit_to_const` infallible) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-08Rollup merge of #135250 - lqd:simple-cleanups, r=matthewjasperMatthias Krüger-146/+153
A couple simple borrowck cleanups This PR has a couple simple renamings: - it's been a long time since the mapping from `Location`s to `PointIndex`es was extracted from `RegionElements` into the `DenseLocationMap`, but only the types were renamed at the time. borrowck still refers to this map as `elements`. That's confusing, especially since sometimes we also use the mapping via `LivenessValues`, and makes more sense as `location_map` instead. - to clarify `LocationTable` is not as general as it sounds, and is only for datalog polonius. In this branch I didn't rename the handful of `location_table` fields and params to `polonius_table`, but can do that to differentiate it even more from `location_map`. I did try it locally and it looks worthwhile, so if you'd prefer I can also push it here. (Or we could even switch these datalog types and fields to even more explicit names) - to clarify the incomprehensible `AllFacts`, it is renamed to `PoloniusFacts`. These can be referred to as `facts` within the legacy polonius module, but as `polonius_facts` outside of it to make it clear that they're not about NLLs (nor are they about in-tree polonius but that'll be magically fixed when they're removed in the future) r? `@matthewjasper`
2025-01-08Try to explain borrow for tail expr temporary drop order change in 2024Michael Goulet-21/+31
2025-01-08Don't do AccessDepth::Drop for types with no drop implMichael Goulet-4/+12
2025-01-08remove an extraneous commentwieDasDing-1/+0
Co-authored-by: Rémy Rakic <remy.rakic+github@gmail.com>
2025-01-08apply suggestions on fn nameDing Xiang Fei-4/+4
2025-01-08run borrowck tests on BIDs and emit tail-expr-drop-order lints forDing Xiang Fei-14/+72
potential violations
2025-01-08rename `AllFacts` to `PoloniusFacts`Rémy Rakic-45/+47
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-46/+47
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-08Auto merge of #133858 - dianne:better-blame-constraints-for-static, r=lcnrbors-239/+218
`best_blame_constraint`: Blame better constraints when the region graph has cycles from invariance or `'static` This fixes #132749 by changing which constraint is blamed for region errors in several cases. `best_blame_constraint` had a heuristic that tried to pinpoint the constraint causing an error by filtering out any constraints where the outliving region is unified with the ultimate target region being outlived. However, it used the SCCs of the region graph to do this, which is unreliable; in particular, if the target region is `'static`, or if there are cycles from the presence of invariant types, it was skipping over the constraints it should be blaming. As is the case in that issue, this could lead to confusing diagnostics. The simplest fix seems to work decently, judging by test stderr: this makes `best_blame_constraint` no longer filter constraints by their outliving region's SCC. There are admittedly some quirks in the test output. In many cases, subdiagnostics that depend on the particular constraint being blamed have either started or stopped being emitted. After starting at this for quite a while, I think anything too fickle about whether it outputs based on the particular constraint being blamed should instead be looking at the constraint path as a whole, similar to what's done for [the placeholder-from-predicate note](https://github.com/rust-lang/rust/compare/master...dianne:rust:better-blame-constraints-for-static#diff-3c0de6462469af483c9ecdf2c4b00cb26192218ef2d5c62a0fde75107a74caaeR506). Very many tests involving invariant types gained a note pointing out the types' invariance, but in a few cases it was lost. A particularly illustrative example is [tests/ui/lifetimes/copy_modulo_regions.stderr](https://github.com/rust-lang/rust/compare/master...dianne:rust:better-blame-constraints-for-static?expand=1#diff-96e1f8b29789b3c4ce2f77a5e0fba248829b97ef9d1ce39e7d2b4aa57b2cf4f0); I'd argue the new constraint is a better one to blame, but it lacks the variance diagnostic information that's elsewhere in the constraint path. If desired, I can try making that note check the whole path rather than just the blamed constraint. The subdiagnostic [`BorrowExplanation::add_object_lifetime_default_note`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_borrowck/diagnostics/explain_borrow/enum.BorrowExplanation.html#method.add_object_lifetime_default_note) depends on a `Cast` being blamed, so [a special case](https://github.com/rust-lang/rust/pull/133858/commits/364ca7f99c12fb5220e6b568ac391979317ce878) was necessary to keep it from disappearing from tests specifically testing for it. However, see the FIXME comment in that commit; I think the special case should be removed once that subdiagnostic works properly, but it's nontrivial enough to warrant a separate PR. Incidentally, this removes the note from a test where it was being added erroneously: in [tests/ui/borrowck/two-phase-surprise-no-conflict.stderr](https://github.com/rust-lang/rust/compare/master...dianne:rust:better-blame-constraints-for-static?expand=1#diff-8cf085af8203677de6575a45458c9e6b03412a927df879412adec7e4f7ff5e14), the object lifetime is explicitly provided and it's not `'static`.
2025-01-08stop calling `DenseLocationMap` "elements"Rémy Rakic-61/+65
"Elements" are `RegionElement`s. The dense location mapping was removed from the element containers a while ago but didn't rename its use-sites. Most of the old naming only used the mapping, and are better named `location_map`.
2025-01-08Rollup merge of #134920 - lqd:polonius-next-episode-6, r=jackh726Jacob Pratt-117/+307
Convert typeck constraints in location-sensitive polonius In this PR, we do a big chunk of the work of localizing regular outlives constraints. The slightly annoying thing is handling effectful statements: usually the subset graph propagates loans at a single point between regions, and liveness propagates loans between points within a single region, but some statements have effects applied on exit. This was also a problem before, in datalog polonius terms and Niko's solution at the time, this is about: the mid-point. The idea was to duplicate all MIR locations into two physical points, and orchestrate the effects with that. Somewhat easier to do, but double the CFG. We've always believed we didn't _need_ midpoints in principle, as we can represent changes on exit as on happening entry to the successor, but there's some difficulty in tracking the position information at sufficient granularity through outlives relation (especially since we also have bidirectional edges and time-traveling now). Now, that is surely what we should be doing in the future. In the mean time, I infer this from the kind of statement/terminator where an outlives constraint arose. It's not particularly complicated but some explanation will help clarify the code. Assignments (in their various forms) are the quintessential example of these crossover cases: loans that would flow into the LHS would not be visible on entry to the point but on exit -- so we'll localize these edges to the successor. Let's look at a real-world example, involving invariance for bidirectional edges: ```rust let mut _1: HashMap<i32, &'7 i32>; let mut _3: &'9 mut HashMap<i32, &'10 i32>; ... /* at bb1[3]: */ _3 = &'3 mut _1; ``` Here, typeck expectedly produces 3 outlives constraints today: 1. `'3 -> '9` 2. `'7 -> '10` 3. `'10 -> '7` And we localize them like so, 1. `'3 -> '9` flows into the LHS and becomes: `3_bb1_3 -> 9_bb1_4` 2. `'7 -> '10` flows into the LHS and becomes: `7_bb1_3 -> 10_bb1_4` 3. `'10 -> '7` flows from the LHS and becomes: `10_bb1_4 -> 7_bb1_3` (time traveling 👌) --- r? ``@jackh726`` To keep you entertained during the holidays I also threw in a couple of small changes removing cruft in the borrow checker. We're actually getting there. The next PR will be the last one needed to get end-to-end tests working.
2025-01-07Rollup merge of #133810 - lcnr:remove-verify_bound, r=compiler-errorsMatthias Krüger-18/+8
remove unnecessary `eval_verify_bound` This does not impact any tests. I feel like any cases where this could useful should instead be fixed by a general improvement to `eval_verify_bound` to avoid having to promote this `TypeTest` in the first place :thinking: r? types cc ``@nikomatsakis``
2025-01-07Avoid naming variables `str`Josh Triplett-3/+3
This renames variables named `str` to other names, to make sure `str` always refers to a type. It's confusing to read code where `str` (or another standard type name) is used as an identifier. It also produces misleading syntax highlighting.
2025-01-06only avoid blaming assignments from argument patternsdianne-27/+26
2025-01-06point out unblamed constraints from `Copy`/`Sized` bounds in region errorsdianne-0/+24
2025-01-06make outlives constraints from pointer comparisons less boringdianne-2/+2
2025-01-06make outlives constraints from generic arguments less boringdianne-17/+24
2025-01-06`best_blame_constraint`: prioritize blaming interesting-seeming constraintsdianne-72/+87
2025-01-06remove the unused `ConstraintCategory::ClosureBounds`dianne-1/+0
2025-01-06`best_blame_constraint`: avoid blaming assignments without user-provided typesdianne-6/+19
2025-01-06`best_blame_constraint`: avoid blaming constraints from MIR generated by ↵dianne-1/+8
desugaring
2025-01-06`best_blame_constraint`: add a special case to recover object lifetime ↵dianne-1/+21
default notes
2025-01-06`best_blame_constraint`: don't filter constraints by sup SCCdianne-49/+11
The SCCs of the region graph are not a reliable heuristic to use for blaming an interesting constraint for diagnostics. For region errors, if the outlived region is `'static`, or the involved types are invariant in their lifetiems, there will be cycles in the constraint graph containing both the target region and the most interesting constraints to blame. To get better diagnostics in these cases, this commit removes that heuristic.
2025-01-06further clean up `best_blame_constraint`dianne-50/+46
This gets rid of `categorized_path`, as it was redundant given the `OutlivesConstraint`s in `path` already have a category field.
2025-01-06cleanup: remove `ExtraConstraintInfo`dianne-131/+68
`ExtraConstraintInfo` was used only for a single subdiagnostic, so this moves the logic for that to its own function and eliminates the indirection. In order to do so cleanly, this also changes the arguments to `BorrowExplanation::add_explanation_to_diagnostic`, which happens to simplify its call sites.
2025-01-06address review commentsRémy Rakic-21/+31
push constraint creation to where the statement/terminator info is gathered
2025-01-06Remove CallKind::Deref hack from UseSpansMichael Goulet-9/+0
It's not really necessary