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

Add `remove_xxx` API that permits remove the value from input field #345

Open xffxff opened 2 years ago

xffxff commented 2 years ago

Old salsa has an API remove_xxx for removing the value from input, remove_input.rs is a test for that API.

Should we support it in salsa-2022? Actually, I can't think of any scenario where the input needs to be removed manually.

nikomatsakis commented 2 years ago

I don't think we should support the ability to remove a single field, because that would leave an "incomplete" struct. You can always swap a dummy value today for the input field.

It seems useful to have a way to take an entire salsa input struct and "remove" it, yielding up a tuple of its fields, though. I have mixed feelings about the last point because input structs are Copy today so it introduces the possibility of bugs, where people keep using the Id that has been removed (and we have to be sure we detect that). I'm not sure how likely such a bug is though, and I guess it can happen "de facto" today, where an input is created (e.g., to represent an input file) and then, while never explicitly removed, just stops being used.

(An obvious alternative would be to make it so that input structs are not always Copy... maybe you have to declare them to be Copy... that seems like it will be annoying to me, though.)

ryo33 commented 1 year ago

We may have a use case that requires a removal API. It's a programming environment like Smalltalk's one. That environment may not be rebooted for a long time. While the environment runs, program units (e.g., files) are continuously added and removed. If input removal is not supported, the storage continues to grow like memory leaks. I'm creating such an environment called Desk using salsa. Fortunately, in my language, each unit can be compiled independently, and I can avoid the leak problem by creating a salsa database for each unit and deleting the whole database on unit removal. But, in most programming languages, a unit cannot be compiled independently from other units, and a removal API is required.

I've created an abstract example. https://github.com/salsa-rs/salsa/pull/429/files#diff-4d97acc7609d3124bf6cd9c23e99ebac2eddec0aa7cebfae68f67d9b1922732eR33-R36