Conversation
| #[salsa::tracked] | ||
| pub fn check_types(db: &dyn Db, file: File) { |
There was a problem hiding this comment.
This has to be a salsa query so that the mdtest framework can get the diagnostics (accumulator require a query)
There was a problem hiding this comment.
All the code here is copied over from ruff_server.
3dd3ee3 to
24d6e87
Compare
CodSpeed Performance ReportMerging #14116 will degrade performances by 32.2%Comparing Summary
Benchmarks breakdown
|
d9ec46b to
ec9a12b
Compare
|
ec9a12b to
522f3d4
Compare
AlexWaygood
left a comment
There was a problem hiding this comment.
Just a few comments from skimming. I'll try to look at this more in-depth tomorrow!
carljm
left a comment
There was a problem hiding this comment.
Looks great to me, thank you! I think this is definitely an improvement in terms of reliable handling of diagnostics (to avoid duplicating or accidentally missing them); hopefully parallel-db brings back most of the regression.
| @@ -0,0 +1,175 @@ | |||
| use ruff_text_size::TextRange; | |||
| use salsa::Accumulator as _; | |||
There was a problem hiding this comment.
What is the benefit of the as _ here? It seems to be just as happy for me locally without it.
| use salsa::Accumulator as _; | |
| use salsa::Accumulator; |
There was a problem hiding this comment.
Both work, for as long as there's no other type named Accumulator. Using as _ imports that type "unnamed". You can't reference the type itself. That's often sufficient for traits because all that is needed is to bring the trait into the scope to call that trait's functions.
|
I just noticed that we can now support invalid-syntax in mdtests. I ported the exception handler with invalid syntax test case to demonstrate it |
522f3d4 to
27d2a8e
Compare
27d2a8e to
c9e4d72
Compare
c9e4d72 to
371e5fc
Compare
|
I don't think this is the way to go. The problem is that salsa's accumulator are I have a fix specific for unpacking and I'll look into extracting some of the improvements I made in this PR but I'm more convinced now that accumulators, as they are today, are not a good fit with our very deeply nested queries. |
Summary
Use a Salsa accumulator for diagnostics to avoid double-emitting diagnostics for unpack assignments.
We now use a single
CompileDiagnosticaccumulator that stores all diagnostics. That includes IO errors, parse errors, and type check errors. I decided that we're beyond whereStringannotations are fun. That's why I introduced aDiagnostictrait with 5 implementations:ParseDiagnosticfor parse errorsSourceTextDiagnosticfor IO errorsTypeCheckDiagnosticfor type inference errorsRevealedTypeDiagnosticforreveal_type(info severity)CompileDiagnosticwhich is a cheap cloneable any diagnostic wrapper that implements salsa accumulator.Using a structured diagnostic has the advantage of no longer needing manual parsing in the LSP.
A nice side effect of this is that mdtests now support tests with syntax errors because parse-errors are just another diagnostic :)
Performance regression
I expect this to hit performance pretty bad, especially the incremental benchmark. The problem is that there's currently no way to run an accumulator concurrently. That's why I had to resort to a hack where we run type checking in parallel, and then collect the diagnostics. This has the downside that Salsa first runs all queries (in parallel) but then has to iterate over all of them again to collect the diagnostics (even if there are none!). The queries are all cached, but it is still expensive because the query dependency tree is somewhat large.
This overhead is especially noticeable in the cache case. We'll need salsa-rs/salsa#568 to do the accumulation and checking in one go.
Test Plan
cargo test