Commit d8a0f0a
authored
[ty] Fix Salsa panic propagation (#24141)
## Summary
This PR fixes probably the most likely case why users saw
astral-sh/ty#1565 in their IDE.
I added handling to convert panics to diagnostics in
#17631 to `check_file_impl`.
However, this was before `check_file_impl` became a Salsa query. We have
to be a bit more careful, now that `check_file_impl` is a Salsa query.
1. We have to add an untracked read whenever we suppress a panic because
Salsa only carries over dependencies of queries that run to completion
and not of queries that panic (the assumption is that all queries
unwind). Adding an `untracked_read` ensures that the `check_file_impl`
reruns after every change. This is more often than necessary, but it is
the best we can do here without knowing the exact dependencies that were
collected up to when `check_file_impl`'s dependency panicked.
2. Suppressing all Salsa panics in `check_files_impl` is unlikely to be
what we want because it means the function still runs to completion even
when the query was cancelled. Instead, we want to propagate a
cancellation so that its `db` handle gets released as quickly as
possible to unblock any pending mutation. However, we do need some
special handling for Salsa's propagating panic to avoid regressing
#17631. For a query `A` running on
thread `a` that depends on query `B` running on thread `b`. If `B`
panics, Salsa throws the original panic on thread `b` but throws a
`Cancelled::PropagatingPanic` panic on thread `a`. Thread `b`'s panic is
the more useful one because it contains the actual panic information. We
already convert `b`'s panic to a `Diagnostic`, but we silently ignore
any `Cancelled::PropagatingPanic`. This PR also creates a propagating
panic to a diagnostic. While these panics don't contain any useful
information, they at least indicate to a user that `A` was only
partially checked. They should have a second diagnostic for `B` that
contains the full panic information (unless `B` is a query that didn't
run as part of `project.check`, e.g. `hover`).
## Test plan
I used @AlexWaygood's panda-stubs reproducer and I was no longer able to
reproduce the Salsa panic.
I plan on doing some CLI `--watch` testing tomorrow morning but this
should block code review.1 parent 84ff94b commit d8a0f0a
2 files changed
Lines changed: 39 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
319 | 318 | | |
320 | 319 | | |
321 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
322 | 324 | | |
323 | 325 | | |
324 | 326 | | |
| |||
646 | 648 | | |
647 | 649 | | |
648 | 650 | | |
649 | | - | |
| 651 | + | |
650 | 652 | | |
651 | 653 | | |
652 | | - | |
653 | 654 | | |
654 | 655 | | |
655 | 656 | | |
| |||
749 | 750 | | |
750 | 751 | | |
751 | 752 | | |
752 | | - | |
| 753 | + | |
753 | 754 | | |
754 | 755 | | |
755 | 756 | | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
| 757 | + | |
760 | 758 | | |
761 | 759 | | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
762 | 784 | | |
763 | 785 | | |
764 | 786 | | |
| |||
790 | 812 | | |
791 | 813 | | |
792 | 814 | | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
793 | 819 | | |
794 | 820 | | |
795 | 821 | | |
| |||
0 commit comments