Skip to content
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

Merged
merged 1 commit into from
Dec 20, 2016
Merged

Conversation

S11001001
Copy link
Member

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.

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.
@edmundnoble
Copy link
Contributor

@S11001001 You mention that tags with casts form an inlining barrier. Did you come across a concrete case where this version performs better?

Copy link
Member

@puffnfresh puffnfresh left a 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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@S11001001
Copy link
Member Author

@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.

@sjrd
Copy link
Contributor

sjrd commented Dec 17, 2016

Not me. So it must have been @DarkDimius.

@edmundnoble
Copy link
Contributor

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.

@xuwei-k xuwei-k merged commit 0d69226 into scalaz:series/7.3.x Dec 20, 2016
@S11001001 S11001001 mentioned this pull request Mar 27, 2017
@S11001001 S11001001 mentioned this pull request Apr 10, 2017
@S11001001 S11001001 deleted the topic/castless-tagging branch October 28, 2017 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants