Typeclass Codegen Ideas #153
eliaslfox
started this conversation in
Ideas and Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently typeclass codegen is not very efficient. Here are a series of ideas to improve it.
Lift Static Constructed Dictionaries to a global scope
Typeclass instances without constraints are compiled into instances of a struct while instances with constraints are compiled into functions that return a struct.
If the
Eq
dictionary forResult String Int
was lifted then the codegen could look something like thisThis would construct the dictionary once instead of constructing it every time that
g
is called.Transform calls to typeclass methods to direct function calls
Currently method calls on static dictionaries are compiled as shown below
They could be compiled instead to
This would allow sbcl to much better optimize the call site.
Hoist constructed dictionaries to a higher scope
Currently if a constructed dictionary is used multiple places in a function it will be constructed multiple times.
The above coalton code would be compiled into the following code
It could instead be compiled to the following code
Beta Was this translation helpful? Give feedback.
All reactions