[Truffle] Discussion: introducing first-class Array strategies #3784
+212
−105
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@chrisseaton @nirvdrum @pitr-ch I am thinking to use
ArrayStrategy
objects for our strategies on Array to reduces the number of specialization and duplication by 4.This is only a preview to get some feedback (do not merge).
What do you think?
Is it nice / too complex / not that helpful?
This is maybe slightly overlapping with ArrayMirror, although ArrayMirror is really about helpers for Java arrays, and this is really about the storage strategies for our Ruby Arrays.
In the current version, an ArrayStrategy can build an ArrayMirror easily so there is no conflict of features. There are only 5 ArrayStrategy which are singleton instances, so this also avoids potential allocation in the interpreter.
An alternative solution would be to have one node per "functionality" of Array, like "get at index", "set at index", "grow", "delete/shrink", etc. This already exists to some extent but it's underused because it's quite verbose, there would be many many features like that for Ruby Array and it's not obvious to identify them either while still keeping the performance.