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

Assign memo ingredients per salsa-struct-ingredient #614

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ShoyuVanilla
Copy link
Contributor

Closes #600

Copy link

netlify bot commented Nov 13, 2024

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit 738d5f9
🔍 Latest deploy log https://app.netlify.com/sites/salsa-rs/deploys/67362956bcce110008e6366b

Copy link

codspeed-hq bot commented Nov 13, 2024

CodSpeed Performance Report

Merging #614 will not alter performance

Comparing ShoyuVanilla:issue-600 (738d5f9) with master (e4d36da)

Summary

✅ 8 untouched benchmarks

src/zalsa.rs Outdated
@@ -130,6 +132,9 @@ pub struct Zalsa {
/// adding new kinds of ingredients.
jar_map: Mutex<FxHashMap<TypeId, IngredientIndex>>,

/// Map from the type-id of a salsa struct to the index of its first ingredient.
salsa_struct_map: Mutex<FxHashMap<TypeId, IngredientIndex>>,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like this new table for SalsaStruct -> IngredientIndex but I couldn't find any other way to pass the salsa-struct-ingredient to its tracked function when creating the function's ingredient, as salsa-struct-ingredient is accessible only with its Configuration, that is private inside the macro-expanded code of that salsa struct.
Would there be some good alternatives?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would be inclined to add a method ingredient_index to SalsaStructInDb but best to hear what @nikomatsakis thinks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to get the IngredientIndex for salsa struct here;

impl $zalsa::Jar for $Configuration {
fn create_ingredients(
&self,
aux: &dyn $zalsa::JarAux,
first_index: $zalsa::IngredientIndex,
) -> Vec<Box<dyn $zalsa::Ingredient>> {
let fn_ingredient = <$zalsa::function::IngredientImpl<$Configuration>>::new(
first_index,
aux,
);

and we can't get the actual instance of salsa struct here. All we have is JarAux - actually, this is Zalsa -, so that function should be a static method, I guess. (I'm afraid that this makes SalsaStructInDb dyn-incompatible but we are not using it as a trait object anywhere in salsa)

Thus, the function would be implemented inside our setup_* macros like;

fn ingredient_index(aux: &dyn JarAux) -> IngredientIndex {
    aux.lookup_jar_by_type(JarImpl::<$Configuration>::default())
}

and we need to expose some method like lookup_jar_by_type in JarAux, I think.

Copy link
Contributor

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

I don't think we currently have a test for a tracked fn that has more than one argument (other than db) and thus uses the interner. Could you double check if that's indeed the case and, if so, add a test for it?

src/zalsa.rs Outdated
Comment on lines 123 to 125
/// [ingredient-indices](`IngredientIndex`)for tracked functions that have this salsa struct
/// as input.
memo_ingredients: RwLock<FxHashMap<IngredientIndex, Vec<IngredientIndex>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
/// [ingredient-indices](`IngredientIndex`)for tracked functions that have this salsa struct
/// as input.
memo_ingredients: RwLock<FxHashMap<IngredientIndex, Vec<IngredientIndex>>>,
/// [ingredient-indices](`IngredientIndex`) for tracked functions that have this salsa struct
/// as input.
memo_ingredient_indices: RwLock<FxHashMap<IngredientIndex, Vec<IngredientIndex>>>,

I also have a slight preference to the name @nikomatsakis suggest in the mentoring instructions (memo_ingredient_indices)

src/zalsa.rs Outdated
Comment on lines 123 to 125
/// [ingredient-indices](`IngredientIndex`)for tracked functions that have this salsa struct
/// as input.
memo_ingredients: RwLock<FxHashMap<IngredientIndex, Vec<IngredientIndex>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

We could consider using a Vec<Vec<IngredientIndex>> here and directly index into the Vec using the IngredientIndex as an offset. This would result in wasting some memory because not every IngredientIndex is an index for a tracked struct but it would avoid one additional hashing step

@ShoyuVanilla
Copy link
Contributor Author

I don't think we currently have a test for a tracked fn that has more than one argument (other than db) and thus uses the internet. Could you double check if that's indeed the case and, if so, add a test for it?

Sure! I'll add tests and edit things you commented when I get home. Thanks for the review

impl JarAux for Zalsa {
fn next_memo_ingredient_index(&self, ingredient_index: IngredientIndex) -> MemoIngredientIndex {
let mut memo_ingredients = self.memo_ingredients.lock();
struct JarAuxImpl<'a>(&'a Zalsa, &'a FxHashMap<TypeId, IngredientIndex>);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed salsa struct ingredient lookup as I said here but I had to change this to avoid deadlocks 😢

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.

Assign memo ingredients per salsa-struct-ingredient, not globally
2 participants