-
Notifications
You must be signed in to change notification settings - Fork 706
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
Cast-free type tags #1306
Cast-free type tags #1306
Conversation
By replacing the structural type with an abstract [existential] type, the subst/unsubst code sees that a tagged type is equal to the untagged type, so it doesn't need to cast. * Now, subst cannot be used to derive unsafeCoerce in concert with singleton type patterns. * Tags/untags no longer form an optimization barrier for inlining optimizers, because there are neither internal nor external inconsistencies when tagging.
@S11001001 You mention that tags with casts form an inlining barrier. Did you come across a concrete case where this version performs better? |
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 really cool. Safer and faster. Very good job.
"k.@@" should { | ||
"be abstract" in { | ||
val r = (List[Int](42) ++ List[Int @@ Mult]()).toSet | ||
r: Set[Any] |
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.
Nice!
@edmundnoble No, it's just been bugging me since either @sjrd or @DarkDimius (or maybe both? 😕) mentioned casting as a problem at Scala Days NYC. |
Not me. So it must have been @DarkDimius. |
I remember @DarkDimius mentioning this during a dotty linker talk, saying casts can mess up the call graph analysis and end up disabling a lot of the specialization optimizations in linker. Perhaps that's it. |
By replacing the structural type with an abstract [existential] type, the
subst
/unsubst
code sees that a tagged type is equal to the untagged type, so it doesn't need to cast.subst
cannot be used to deriveunsafeCoerce
in concert with singleton type patterns.