Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DebugWithDb in multi-crate Salsa projects #509

Closed
wants to merge 4 commits into from

Conversation

camelid
Copy link
Contributor

@camelid camelid commented Jun 20, 2024

Previously, the auto-generated impls hard-coded the database's type to
be &dyn Db, with Db being the local crate's database. Due to
limitations of trait upcasting, this meant that Salsa structs containing
Salsa structs from multiple different crates would not be printed
properly. They would fallback to the plain std::fmt::Debug impl, which
just prints an ID -- not very useful.

Now, the impls are generic over the database type. Any database that
implements the local database trait will be accepted.

For more background, see this Zulip conversation.

r? @nikomatsakis

Previously, the auto-generated impls hard-coded the database's type to
be `&dyn Db`, with `Db` being the local crate's database. Due to
limitations of trait upcasting, this meant that Salsa structs containing
Salsa structs from multiple different crates would not be printed
properly. They would fallback to the plain `std::fmt::Debug` impl, which
just prints an ID -- not very useful.

Now, the impls are generic over the database type. Any database that
implements the local database trait will be accepted.

For more background, see this Zulip conversation [1].

[1]: https://salsa.zulipchat.com/#narrow/stream/145099-general/topic/recursive.20DebugWithDb.3F
Unfortunately, this regresses some unrelated error messages.
Copy link

netlify bot commented Jun 20, 2024

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit 75a6ca3
🔍 Latest deploy log https://app.netlify.com/sites/salsa-rs/deploys/667a35b1cbf8fc000896441d

@camelid
Copy link
Contributor Author

camelid commented Jun 20, 2024

Ideally, we'd have some tests to make sure this works cross-crate, but I thought I'd let you see what you think of the impl first :)

It's also unfortunate that this regresses some unrelated error messages, although at present I don't see a good way around it.

Copy link
Member

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this looks right to me.

@nikomatsakis
Copy link
Member

nikomatsakis commented Jun 23, 2024

I'm up to merge this -- but any idea why CI is unhappy. Seems like a netlify issue I guess.

@nikomatsakis
Copy link
Member

@camelid would you like to add some tests pre-merge?

@camelid
Copy link
Contributor Author

camelid commented Jun 25, 2024

I'm up to merge this -- but any idea why CI is unhappy. Seems like a netlify issue I guess.

Yeah, I think it's spurious.

@camelid would you like to add some tests pre-merge?

Sure 👍

The new auto-impl for `DebugWithDb` caused this error message to
regress because it expects the `__salsa_crate_Db` to be in the same
location as the `Jar`. This fixes it by using an absolute path. Note
that using custom `Jar` locations wasn't supported properly before
either.
@camelid
Copy link
Contributor Author

camelid commented Jun 25, 2024

@nikomatsakis I just pushed up a test that ensures the derived impls are generic. This seemed easier than making a multi-crate test and also tests the actual change rather than its effect. I also ran the same test on master and confirmed that it errors out, thus it is working properly. So I think this PR is ready to be merged!

error[E0277]: the trait bound `MyInputStruct: DebugWithDb<DB>` is not satisfied
  --> tests/derived-debugwithdb-is-generic.rs:34:26
   |
34 |     ensure_generic::<DB, MyInputStruct>();
   |                          ^^^^^^^^^^^^^ the trait `DebugWithDb<DB>` is not implemented for `MyInputStruct`
   |
note: required by a bound in `ensure_generic`
  --> tests/derived-debugwithdb-is-generic.rs:30:69
   |
30 | ..., S: DebugWithDb<DB>>() {}
   |         ^^^^^^^^^^^^^^^ required by this bound in `ensure_generic`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
   |
33 | fn test_all<'db, DB: ?Sized + AsSalsaDatabase + DbWithJar<Jar>>() where MyInputStruct: DebugWithDb<DB> {
   |                                                                   ++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `MyTrackedStruct<'db>: DebugWithDb<DB>` is not satisfied
  --> tests/derived-debugwithdb-is-generic.rs:35:26
   |
35 |     ensure_generic::<DB, MyTrackedStruct<'db>>();
   |                          ^^^^^^^^^^^^^^^^^^^^ the trait `DebugWithDb<DB>` is not implemented for `MyTrackedStruct<'db>`
   |
note: required by a bound in `ensure_generic`
  --> tests/derived-debugwithdb-is-generic.rs:30:69
   |
30 | ..., S: DebugWithDb<DB>>() {}
   |         ^^^^^^^^^^^^^^^ required by this bound in `ensure_generic`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
   |
33 | fn test_all<'db, DB: ?Sized + AsSalsaDatabase + DbWithJar<Jar>>() where MyTrackedStruct<'db>: DebugWithDb<DB> {
   |                                                                   +++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `MyInternedStruct<'db>: DebugWithDb<DB>` is not satisfied
  --> tests/derived-debugwithdb-is-generic.rs:36:26
   |
36 |     ensure_generic::<DB, MyInternedStruct<'db>>();
   |                          ^^^^^^^^^^^^^^^^^^^^^ the trait `DebugWithDb<DB>` is not implemented for `MyInternedStruct<'db>`
   |
note: required by a bound in `ensure_generic`
  --> tests/derived-debugwithdb-is-generic.rs:30:69
   |
30 | ..., S: DebugWithDb<DB>>() {}
   |         ^^^^^^^^^^^^^^^ required by this bound in `ensure_generic`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
   |
33 | fn test_all<'db, DB: ?Sized + AsSalsaDatabase + DbWithJar<Jar>>() where MyInternedStruct<'db>: DebugWithDb<DB> {
   |                                                                   ++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `MyDerivedStruct<'db>: DebugWithDb<DB>` is not satisfied
  --> tests/derived-debugwithdb-is-generic.rs:37:26
   |
37 |     ensure_generic::<DB, MyDerivedStruct<'db>>();
   |                          ^^^^^^^^^^^^^^^^^^^^ the trait `DebugWithDb<DB>` is not implemented for `MyDerivedStruct<'db>`
   |
note: required by a bound in `ensure_generic`
  --> tests/derived-debugwithdb-is-generic.rs:30:69
   |
30 | ..., S: DebugWithDb<DB>>() {}
   |         ^^^^^^^^^^^^^^^ required by this bound in `ensure_generic`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
   |
33 | fn test_all<'db, DB: ?Sized + AsSalsaDatabase + DbWithJar<Jar>>() where MyDerivedStruct<'db>: DebugWithDb<DB> {
   |                                                                   +++++++++++++++++++++++++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `salsa` (test "derived-debugwithdb-is-generic") due to 4 previous errors
warning: build failed, waiting for other jobs to finish...

@nikomatsakis
Copy link
Member

No longer relevant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants