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

Assign memo ingredients per salsa-struct-ingredient, not globally #600

Open nikomatsakis opened 4 days ago

nikomatsakis commented 4 days ago

Today every tracked function gets assigned a distinct MemoIngredientIndex. These are used to index into the memo table attached to a salsa struct. But every function can be attached to salsa structs of exactly one kind, so indices only have to be distinct per salsa struct, not globally. This would save a lot of space in larger projects.

nikomatsakis commented 3 days ago

Mentoring instructions

Currently 'memo ingredient indices' are a vector; the values in the vector are the fn ingredient indices that would be storing the memo (this should be documented!).

https://github.com/salsa-rs/salsa/blob/710691d6070cf7cf3638f50ac74f0ac8bce9c48c/src/zalsa.rs#L122-L123

This should be changed into a map of vectors, indexed by the "salsa struct ingredient index" (the ingredient index on which the memo is stored):

/// Map from the [`IngredientIndex`][] of a salsa struct to a list of
/// [ingredient-indices](`IngredientIndex`)for tracked functions that have this salsa struct as input.
memo_ingredient_indices: RwLock<Map<IngredientIndex, Vec<IngredientIndex>>>

then we modify next_memo_ingredient_index to take the tracked struct ingredient index as an argument

https://github.com/salsa-rs/salsa/blob/710691d6070cf7cf3638f50ac74f0ac8bce9c48c/src/zalsa.rs#L300-L305

This is called my the various code in salsa-macro-rules, so that will have to be modified to pass in the ingredient index for the salsa struct on which the function is invoked.

We also modify ingredient_index_for_memo similarly

https://github.com/salsa-rs/salsa/blob/710691d6070cf7cf3638f50ac74f0ac8bce9c48c/src/zalsa.rs#L291-L296

and change the one caller of that last method:

https://github.com/salsa-rs/salsa/blob/master/src/tracked_struct.rs#L504

to pass in the self.ingredient_index.