Skip to content

2.13 regression in @tailrec + singleton types #467

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

Closed
SethTisue opened this issue Jan 29, 2018 · 4 comments · Fixed by scala/scala#6420
Closed

2.13 regression in @tailrec + singleton types #467

SethTisue opened this issue Jan 29, 2018 · 4 comments · Fixed by scala/scala#6420
Assignees
Milestone

Comments

@SethTisue
Copy link
Member

at e.g. https://scala-ci.typesafe.com/view/scala-2.13.x/job/scala-2.13.x-integrate-community-build/919/consoleFull we see:

[akka-actor] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.9/project-builds/akka-actor-75f78e641cd66395240926f2b01f241f7dee1dce/akka-actor/src/main/scala/akka/util/ByteIterator.scala:277:33: could not optimize @tailrec annotated method dropWhile: it has a singleton result type which cannot be erased correctly
[akka-actor] [error]     @tailrec final override def dropWhile(p: Byte ⇒ Boolean): this.type =
[akka-actor] [error]                                 ^
[akka-actor] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.9/project-builds/akka-actor-75f78e641cd66395240926f2b01f241f7dee1dce/akka-actor/src/main/scala/akka/util/ByteIterator.scala:312:34: could not optimize @tailrec annotated method getToArray: it has a singleton result type which cannot be erased correctly
[akka-actor] [error]     @tailrec protected final def getToArray[A](xs: Array[A], offset: Int, n: Int, elemSize: Int)(getSingle: ⇒ A)(getMult: (Array[A], Int, Int) ⇒ Unit): this.type =
[akka-actor] [error]                                  ^
[akka-actor] [warn] 109 warnings found
[akka-actor] [error] two errors found

@milessabin since it involves singleton types, I'm tentatively assigning this to you for investigation.

@jrudolph
Copy link

jrudolph commented Mar 5, 2018

The change here is not just a nuisance but a regression since, as the error message says, tail call optimization isn't done any more.

@milessabin
Copy link

Agreed. I'm on it.

@jrudolph
Copy link

jrudolph commented Mar 5, 2018

Cool, thanks Miles.

@SethTisue SethTisue added this to the 2.13.0-M4 milestone Mar 5, 2018
2m added a commit to akka/akka that referenced this issue Mar 7, 2018
jrudolph added a commit to jrudolph/akka-http that referenced this issue Mar 8, 2018
This is due to scala/scala-dev#467.

This might lead to stack overflows, so don't merge but wait for a
fix in the next version.
jrudolph added a commit to jrudolph/akka-http that referenced this issue Mar 8, 2018
This is due to scala/scala-dev#467.

This might lead to stack overflows, so don't merge but wait for a
fix in the next version.
milessabin added a commit to milessabin/scala that referenced this issue Mar 13, 2018
At one point the literal types PR modified the semantics of asInstanceOf
to check for equality of the target value with the value embedded in the
singleton type. This interacted badly with mkAttributedCastHack in
Tailcalls,

  dotta@c2534bf

because the inserted casts could end up referring to a non-existent
Symbol which would be needed to implement the equality check during
Erasure.

The fix at the time was to make the use of a singleton type as a method
argument or result type disqualify the method from having the tailcall
optimization applied. A later decision by the SIP committee decided for
unrelated reasons that an asInstanceOf test should not perform an
equality check, so this disqualification became unnecessary. It was not
removed, however.

This came to light because singleton types are used as method argument
and result types in methods which are expected to have the tail call
optimizatino applied, resulting in,

  scala/scala-dev#467

We fix that here by doing what should have been done earlier: removing
the disqualification.
@milessabin
Copy link

Fixed in scala/scala#6420.

adriaanm pushed a commit to scala/scala that referenced this issue Apr 11, 2018
Singleton typed args/results don't interfere with tailcalls

At one point the literal types PR modified the semantics of asInstanceOf
to check for equality of the target value with the value embedded in the
singleton type. This interacted badly with mkAttributedCastHack in
Tailcalls,

  dotta@c2534bf

because the inserted casts could end up referring to a non-existent
Symbol which would be needed to implement the equality check during
Erasure.

The fix at the time was to make the use of a singleton type as a method
argument or result type disqualify the method from having the tailcall
optimization applied. A later decision by the SIP committee decided for
unrelated reasons that an asInstanceOf test should not perform an
equality check, so this disqualification became unnecessary. It was not
removed, however.

This came to light because singleton types are used as method argument
and result types in methods which are expected to have the tail call
optimizatino applied, resulting in,

  scala/scala-dev#467

We fix that here by doing what should have been done earlier: removing
the disqualification.
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 a pull request may close this issue.

3 participants