about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-02 00:04:04 +0000
committerbors <bors@rust-lang.org>2023-12-02 00:04:04 +0000
commitbd3a22115fa3b7c572333783cd315c134b48e967 (patch)
tree3daf396ccda79d24988dbf8dc7ec332cd8dc1417 /tests
parent8c2b57721728233e074db69d93517614de338055 (diff)
parentde2b8b13d4f4fe71b6915b5de6dee6ed1f6d3cb8 (diff)
downloadrust-bd3a22115fa3b7c572333783cd315c134b48e967.tar.gz
rust-bd3a22115fa3b7c572333783cd315c134b48e967.zip
Auto merge of #118175 - lqd:unify-live-loans, r=matthewjasper
Centralize live loans maintenance to fix scope differences due to liveness

As found in the recent [polonius crater run](https://github.com/rust-lang/rust/pull/117593#issuecomment-1801398892), NLLs and the location-insensitive polonius computed different scopes on some specific CFG shapes, e.g. the following.

![image](https://github.com/rust-lang/rust/assets/247183/c3649f5e-3058-454e-854e-1a6b336bdd5e)

I had missed that liveness data was pushed from different sources than just the liveness computation: there are a few places that do this -- and some of them may be unneeded or at the very least untested, as no tests changed when I tried removing some of them.

Here, `_6` is e.g. dead on entry to `bb2[0]` during `liveness::trace`, but its regions will be marked as live later during "constraint generation" (which I plan to refactor away and put in the liveness module soon). This should cause the inflowing loans to be marked live, but they were only computed in `liveness::trace`.

Therefore, this PR moves live loan maintenance to `LivenessValues`, so that the various places pushing liveness data will all also update live loans at the same time -- except for promoteds which I don't believe need them, and their liveness handling is already interesting/peculiar.

All the regressions I saw in the initial crater run were related to this kind of shapes, and this change did fix all of them on the [next run](https://github.com/rust-lang/rust/pull/117593#issuecomment-1826132145).

r? `@matthewjasper`

(This will conflict with #117880 but whichever lands first is fine by me, the end goal is the same for both)
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/nll/polonius/location-insensitive-scopes-liveness.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/ui/nll/polonius/location-insensitive-scopes-liveness.rs b/tests/ui/nll/polonius/location-insensitive-scopes-liveness.rs
new file mode 100644
index 00000000000..5fabf31cecd
--- /dev/null
+++ b/tests/ui/nll/polonius/location-insensitive-scopes-liveness.rs
@@ -0,0 +1,46 @@
+// This is a non-regression test about differences in scopes computed by NLLs and `-Zpolonius=next`
+// found during the crater run for PR #117593.
+//
+// Live loans were computed too early compared to some of the liveness data coming from later passes
+// than `liveness::trace`, on some specific CFGs shapes: a variable was dead during tracing but its
+// regions were marked live later, and live loans were not recomputed at this point.
+
+// check-pass
+// revisions: nll polonius
+// [polonius] compile-flags: -Zpolonius=next
+
+// minimized from wavefc-cli-3.0.0
+fn repro1() {
+    let a = 0;
+    let closure = || {
+        let _b = a;
+    };
+
+    let callback = if true { Some(closure) } else { None };
+    do_it(callback);
+}
+fn do_it<F>(_: Option<F>)
+where
+    F: Fn(),
+{
+}
+
+// minimized from simple-server-0.4.0
+fn repro2() {
+    let mut a = &();
+    let s = S(&mut a);
+    let _ = if true { Some(s) } else { None };
+}
+struct S<'a>(&'a mut &'a ());
+
+// minimized from https://github.com/SHaaD94/AICup2022
+fn repro3() {
+    let runner = ();
+    let writer = debug_interface(&runner);
+    let _ = if true { Some(writer) } else { None };
+}
+fn debug_interface(_: &()) -> &mut dyn std::io::Write {
+    unimplemented!()
+}
+
+fn main() {}