Skip to content

Conversation

@copybara-service
Copy link

Remove the trait dispatch from memoized.

This was inherited from Salsa but had no real use, and we've moved a bit away from Salsa now. In particular, there's various comments to the effect of "maybe having a trait will help us with separate compilation someday?" -- but we ended up doing separate compilation in a much more fine-grained way, with one function pointer per method. So the trait still doesn't help with that.

This does make constructing a totally fake instance in rs_snippet much more annoying. What it used to do was "crash if you use the database". It still does that, but via a local test injectiony dependency-injectiony thing, not by using traits. Overall, it's about the same, but maybe more visibly awkward. We should probably move away from this pattern, and I think I can/will for the display part at least, in a followup.

Benefits of getting rid of the trait objects:

  1. No more dyn! Yes! Hooray! This both gives us flexibility improvements (can deal in concrete types, Sized, etc), and presumably marginally improves performance or something.

  2. Overall simpler -- just one type, BindingsGenerator, instead of two types. We in the past had problems where one function accepted BindingsGenerator and the other accepted Database and then they could only talk in one direction.

  3. Now that we're committing to dealing in concrete types, we have room to e.g. produce new BindingsGenerator objects by value. We could do that from the trait, too, but only if we were committing to the trait being pointless.

This, in turn, means we can get rid of global state, and instead reuse BindingsGenerator as you'd expect: make a new BindingsGenerator object, with new state.

This was inherited from Salsa but had no real use, and we've moved a bit away from Salsa now. In particular, there's various comments to the effect of "maybe having a trait will help us with separate compilation someday?" -- but we ended up doing separate compilation in a much more fine-grained way, with one function pointer per method. So the trait _still_ doesn't help with that.

This does make constructing a totally fake instance in rs_snippet much more annoying. What it used to do was "crash if you use the database". It still does that, but via a local test injectiony dependency-injectiony thing, not by using traits. Overall, it's about the same, but maybe more visibly awkward. We should probably move away from this pattern, and I think I can/will for the display part at least, in a followup.

Benefits of getting rid of the trait objects:

1. No more `dyn`! Yes! Hooray! This both gives us flexibility improvements (can deal in concrete types, Sized, etc), and presumably marginally improves performance or something.

2. Overall simpler -- just one type, `BindingsGenerator`, instead of two types. We in the past had problems where one function accepted BindingsGenerator and the other accepted Database and then they could only talk in one direction.

3. Now that we're committing to dealing in concrete types, we have room to e.g. produce new BindingsGenerator objects by value. We could do that from the trait, too, but only if we were committing to the trait being pointless.

  This, in turn, means we can get rid of global state, and instead reuse BindingsGenerator as you'd expect: make a new BindingsGenerator object, with new state.

PiperOrigin-RevId: 860318906
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.

1 participant