salsa-rs / salsa

A generic framework for on-demand, incrementalized computation. Inspired by adapton, glimmer, and rustc's query system.
https://salsa-rs.netlify.app/
Apache License 2.0
2.14k stars 152 forks source link

Ingredient debug name are uninformative for tracked trait impl #587

Open arialpew opened 1 month ago

arialpew commented 1 month ago

A tracked trait impl give inner_fn_name_ as ingredient debug name. We should pick the name of the original trait impl, not the InnerTrait trait impl generated by salsa::tracked macro.

#[salsa::db]
struct Database;

#[salsa::db]
impl salsa::Database for Database {
    fn salsa_event(&self, event: &dyn Fn() -> salsa::Event) {
        let event = event();

        if let salsa::EventKind::WillExecute { database_key } = event.kind {
            dbg!(self.ingredient_debug_name(database_key.ingredient_index()));
        }
    }
}

/// Given a tracked trait impl (which is implemented for some tracked input or tracked struct).
#[salsa::tracked]
impl MyTrait for MyStruct {
    #[salsa::tracked]
    fn parse(self, db: &dyn salsa::Database) -> Something<'_> {
      // impl
    }
}

/// EXPANDED
///
/// The macro generate this InnerTrait code, which take over `parse`,
/// when resolving the ingredient_debug_name.
/// All tracked trait impl result in this uninformative `inner_fn_name_`.
/// `<MyStruct as MyTrait>::parse` would be the best possible debug name output,
/// or `parse` or `MyTrait::parse`, but that would make it harder to distinguish multiple trait implementors.
trait InnerTrait_ {
    fn inner_fn_name_(self, db: &dyn salsa::Database) -> Something<'_>;
}

impl InnerTrait_ for SourceFile {
    fn inner_fn_name_(self, db: &dyn salsa::Database) -> Something<'_> {
      // impl
    }
}
puuuuh commented 1 month ago

I can implement this, but its a little bit hacky due to absent of ToString on syn::Type. Only way i could see is to take impl.ty.span().source_text() and normalize it somehow and the same for impl.self_ty. Idk if its ok