Represent class dictionaries as newtypes#4125
Conversation
d8e67ea to
cd869eb
Compare
|
I wanted to use data constructors as their implementation is more optimisable by JS runtimes*, and it makes the representation less record-dependent for backends that have to implement records by means that may be less efficient than static data types. I was also thinking that perhaps it'd be easier to use annotations on the data constructor form of this to use for later optimisations, but you've already made good progress on a major part of that without needing it (#3915)! * In light of some benchmarks Nate tried recently, there probably isn't much of a distinction between object and "class" performance anymore, so the JS concern isn't really there anymore. Property access used to be significantly faster on "classes" than on standard objects. I'm in favour of this PR - even if later it seems that the data approach is better again for some reason, for we still get to eliminate the |
cd869eb to
a0d482e
Compare
|
@garyb So, would you be willing to approve this PR? Or are there other things you think need to be addressed? |
|
I haven't reviewed it thoroughly yet, but it looks good from a glance! Will try to remember to come back to it this weekend for a proper 👍 |
Class dictionaries are now represented as newtype wrappers of records. This drops the awkward TypeClassDictionaryConstructorApp and TypeClassDictionaryAccessor expressions in favor of regular newtype constructors and record accessors.
a0d482e to
880b6b0
Compare
garyb
left a comment
There was a problem hiding this comment.
👍 Sorry it took ages to get to!
Class dictionaries are now represented as newtype wrappers of records.
This drops the awkward TypeClassDictionaryConstructorApp and
TypeClassDictionaryAccessor expressions in favor of regular newtype
constructors and record accessors.
Description of the change
This is mostly motivated by an attempt-in-progress at #4086, but I think it stands on its own merits.
Previously: #3567 and #781. I'm tempted to say that this PR closes those, but maybe there are reasons to prefer the data representation over the newtype one I've implemented? I quite like how simple the generated code for the newtype representation is, and how it means that the newtype constructors can be completely erased (with other newtypes, the constructors still have to be exported in case some code references them in a way that isn't an erased application, but with typeclass newtypes that's not possible). But adapting this PR to use data instead of newtype would be easy and would also suffice for my #4086 purposes.
This newly-updated comment describes the details:
purescript/src/Language/PureScript/Sugar/TypeClasses.hs
Lines 109 to 198 in cd869eb
Checklist: