4 ms·
On the language side you'd need a way to tell the runtime which properties were relevant to extracting a backbone structure. Maybe a "backbone" field on the pr
by kannanvijayan 5y ago
On the language side you'd need a way to tell the runtime which properties were relevant to extracting a backbone structure. Maybe a "backbone" field on the property descriptor - e.g.:
`Object.defineProperty(obj, "prop", { writable: true, value: ..., backbone: true });`
Then you'd need to generalize the hidden type modeler in the VM to interpret the backbone field and lift "prop" (and the value associated with it) into the hidden type representation. The important thing to remember here would be to ensure that these foldings of things into the hidden type are _transitive_. If the value of `obj.prop` itself has one or more "backbone" fields defined on it, then those too would need to be lifted into the hidden type.
Assignments to these fields would need to generate a new hidden type for the underlying object, much as new shapes are created and installed for JS objects are mutated to add new properties or change the prototype.
You'd then need to implement some mechanism of collapsing the object representations down to some inline format.
Lastly, you'd need to teach the code-generator to use the hidden type to optimize accesses through "obj.prop" (or longer property access sequences).
At the end of all of that, you then get a really beautiful optimization behaviour where:
"obj.prop.anotherBackboneProp.someRegularProp", in suitably monomorphic or lightly-polymorphic locations, becomes not 3 separately-checked property accesses, but a single type-check on "obj", followed by a access into the top-level object.
That would give a rudimentary ability for library and framework developers to define common shared, stable backbone structures for their own use. And that's fun to really think about.
There's a bunch of work to be done, and it has to be motivated by real use cases, but I'm sure they are there. The idea that this powerful technique is only applicable to the _specific_ set of data structures involved in property lookup in object inheritance chains seems an unimaginative perspective.