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.12k stars 150 forks source link

Use sharded-slab to store tracked struct instance data #491

Open nikomatsakis opened 3 months ago

nikomatsakis commented 3 months ago

The existing implementation uses a direct pointer for tracked struct data. This is maximally efficient but not safe. To make it safe, we would need to have a cheap way to ensure that the tracked struct has not been deleted -- this could only happen if user's "leak" data to bypass salsa's dependency tracking, but unfortunately that is possible without triggering UB (though it does require safe code). One way to do this would be to use arenas to allocate tracked struct storage. But another option is to first try using the sharded slab create -- while not maximally efficient, it presents us a safe interface to build on and may be "fast enough". We can explore future refinements later.