Open nikomatsakis opened 1 month ago
CC: @ibraheemdev
Ok, I realized this is a bit more complicated than I thought. There are two parts required
#[id]
fields -- we don't currently distinguish them, but we should.The decision about which fields are "id" fields is driven by this input to the macro-rules macro:
which is provided here
it should be fairly straightforward to modify the latter file to flip the defaults. (Note that the next section will also likely change this interface slightly.)
I'd probably also rename these from "id" fields to "untracked" fields.
#[id]
fieldsThis is the trickier bit. Currently we create a field ingredient for every field, regardless of whether it's part of the #[id]
hash:
the field accessor for every field is the same:
in particular it invokes the field
method from the tracked struct on line 205. That function is defined here:
It does a fair bit of work and in particular adds a read.
All of that work is unnecessary for id-fields. Just as with an interned struct, the idea is that if the id fields have changed, then you will have a new tracked struct instance from salsa's perspective, so they can be regarded as immutable. As a result, we just have to read from them. Compare to the fields
method from interned structs.
I think what I would do is to modify the setup_tracked_struct
macro so that when we generate the field getters, we generate the getters for id fields differently (they invoke a untracked_fields
method on the ingredient or something like that, and we rename the existing getter to tracked_fields
).
This will require changing the macro inputs. There are a few few ways to go about this. Perhaps the easiest is to add some kind of field_getter_method
argument that is either untracked_fields
or tracked_fields
depending and then modify this line
to read let fields = $Configuration::ingredient(db).$field_getter_method(db, self, $field_index);
.
Thanks for the writeup! I can work on this after https://github.com/salsa-rs/salsa/issues/597 (if no one else has gotten to it first).
Picking this up if you haven't @ibraheemdev
@OLUWAMUYIWA Feel free!
As described in this hackmd, we want to change how tracked struct dependencies work. The basic idea is to switch the default: instead of labeling some fields as
#[id]
and having the rest be independently tracked, we will have fields be#[id]
by default unless they are annotated with#[salsa::tracked]
. This is a fairly straightforward change that can be done in the proc-macro.Example
Before:
After: