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

Can't use miette::Report in accumulator due to Clone requirement #456

Open DCNick3 opened 1 year ago

DCNick3 commented 1 year ago

It's quite convenient to use miette to provide diagnostic type.

Unfortunately, it's not possible to use the type-erased error type of miette::Report due to it not implementing clone =(

// ERROR: the trait bound `miette::Report: std::clone::Clone` is not satisfied [E0277]
// Note: required by a bound in `salsa_2022::accumulator::AccumulatorIngredient`
#[salsa::accumulator]
pub struct Diagnostics(miette::Report);

Would it be possible to use something like #[return_ref] as in #[salsa::tracked] to not require it?

(Possible workarounds: using a concrete type like miette::MietteDiagnostic or wrapping the miette::Report in Arc)

DropDemBits commented 1 year ago

I believe the main reason why Clone is required is because of this function: https://github.com/salsa-rs/salsa/blob/d4a94fbf07bb837f3d9d0a4caa5db4d5db29243f/components/salsa-2022/src/accumulator.rs#L76-L98

Wonder if would be possible to add some indirection to the accumulator data?