-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User guided specialisation stage #252
base: hkmc2
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,87 @@ | |||
|
|||
|
|||
:spt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to also show the JS code, which is much easier to read.
84db949
to
2a42dd2
Compare
Co-authored-by: Anson Yeung <[email protected]>
Ported specialisation keyword from previous commits to new HEAD, as it was easier than rebasing, as other components had significantly changed.
As part of moving specialiser code to the new head rewrote logic to pass the specialisation flags through the compiler - now has a much smaller footprint.
2a42dd2
to
b91aa15
Compare
case Primitive(name: Str) | ||
case Function(lhs: SimpleType, rhs: SimpleType) | ||
case Record(fields: Ls[(Str, SimpleType)]) | ||
case ClassType(sym: ClassSymbol, supers: Ls[SimpleType], members: Map[Str, SimpleType]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more like ClassInfo
(which is not a SimpleType
). The types of actual class instances should be a different constructor (which points back to the ClassInfo
).
TODO: Write specification/architecture of algorithm first. You need to attach the flows of normal parameters to the flows of specialized ones. Example:
Another way of thinking about this: specialized functions are polymorphic, but the polymorphic instances are indexed not by the individual call sites but by the list of concrete shapes flowing into their specialized parameters.
In this approach, we remember whatever flows into Note: Similarly, |
Another interesting thing: the calls to specialized functions happening in non-specialized contexts may have to be turned into pattern matches. Reusing the previous example: fun foo(spec x, p1, p2) = ...
fun bar(x, arg) =
foo(x, arg, 123)
bar(Int, 0)
bar(Str, true) This should basically specialize into: fun foo_Int(x, p1, p2) = ...
fun foo_Str(x, p1, p2) = ...
fun bar(x, arg) =
if x is
Int then foo_Int(x, arg, 123)
Str then foo_Str(x, arg, 123)
bar(Int, 0)
bar(Str, true) In fact, at least conceptually, we should probably always generate pattern matching by default and possibly optimize it later. So even a direct call like foo(42, true, 0) should be turned into let $arg = 42
if $arg is
Int then foo_Int($arg, true, 0) which will be optimized the the expected let $arg = 42
foo_Int($arg, true, 0) So this looks pretty similar to the earlier defunctionalization/demethodization project! |
Draft PR for implementing a user-guided specialisation pass in the mlscript compiler, very much still WIP