[red-knot] Remove <Db: SemanticDb>
contraints in favor of dynamic dispatch
#11339
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
We used to have a mixture of functions/methods that accept
&dyn Db + HasJar
and methods that were generic overDb
.The problem with this approach is that calling a method that accepted a
Db: HasJar
wasn't possible when only holding a reference to a&dyn Db
or it required repeating theHasJar
constraint.This PR aligns our traits with Salsa by:
DbWithJar<Jar>
trait. The trait itself is empty, but it requires the type to implementHasJar<Jar>
andDatabase
DbWithJar
a base trait for all theDb
traits (SourceDb
,SemanticDb
,LintDb
etc)db: &dyn SemanticDb
as the argument. This simplifies the function signatures a lotThe last change isn't strictly related and maybe I should have done it as a separate PR. However, it removes the
query and mutation methods from the database traits because we can just call the functions directly. This aligns our API with salsa20202.
I've mixed feelings about it. It is nice, because it reduces repetition. However, it does reduce discoverability because you can no longer write
db.
to discover all queries/mutations.Test Plan
cargo build