Skip to content

Nested inline calls - unrelated code affects compilation #18010

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
ncreep opened this issue Jun 19, 2023 · 9 comments
Closed

Nested inline calls - unrelated code affects compilation #18010

ncreep opened this issue Jun 19, 2023 · 9 comments
Labels
area:typer itype:bug Spree Suitable for a future Spree

Comments

@ncreep
Copy link

ncreep commented Jun 19, 2023

Compiler version

3.3.0

Minimized code

While trying to work around #8739 (nested transparent calls) I stumbled upon some spooky compilation side-effects:

//> using scala "3.3.0"
import scala.compiletime.*

class Typed[A]

transparent inline def computeType[T <: Tuple]: Typed[_ <: Tuple] =
  inline erasedValue[T] match
    case _: EmptyTuple => Typed[EmptyTuple]
    case _: (h *: t) =>
      inline computeType[t] match
        case _: Typed[ts] =>
          Typed[h *: ts]

val x: Typed[("a", "b", "c")] =
  computeType[("a", "b", "c")]

This fails to compile with the following message:

Found:    Typed[?1.CAP]
Required: Typed[(("a" : String), ("b" : String), ("c" : String))]

where:    ?1 is an unknown value of type scala.runtime.TypeBox[("a" : String) *: Nothing, ("a" : String) *: Tuple]

But if I add any other code in the second branch everything compiles just fine.
So this compiles:

case _: Typed[ts] =>
  println("")
  Typed[h *: ts]

And this:

case _: Typed[ts] =>
  123
  Typed[h *: ts]

And even this:

case _: Typed[ts] =>
  val x = Typed[h *: ts]
  x

Expectation

The code should have a consistent type irrespective of code that is unrelated to the final result type.

Thanks

@ncreep ncreep added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 19, 2023
@odersky
Copy link
Contributor

odersky commented Jun 24, 2023

That's indeed a mystery. Maybe for experienced people in the Spree to find out?

@odersky odersky added area:typer Spree Suitable for a future Spree and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 24, 2023
@SethTisue
Copy link
Member

SethTisue commented Jul 6, 2023

minimized somewhat:

//> using scala 3.3.1-RC3

import scala.compiletime.erasedValue

class Typed[A]

transparent inline def computeType: Any =
  inline erasedValue[Tuple1["a"]] match
    case _ =>
      inline (Typed[EmptyTuple]: Typed[_ <: Tuple]) match
        case _: Typed[ts] =>
//          println("")   // compiles if uncommented
          Typed["a" *: ts]

val x: Typed[Tuple1["a"]] = computeType

not sure if actually-helpful minimization, or just minimization golf

also not positive it can't be reduced further

@ncreep
Copy link
Author

ncreep commented Jul 8, 2023

@SethTisue, thanks for the minimization. It does seem actually helpful as it shows that the nested transparent call is not part of the issue (as my title implied).

@SethTisue SethTisue changed the title Nested transparent calls - unrelated code affects compilation Nested inline calls - unrelated code affects compilation Jul 8, 2023
@scala-center-bot
Copy link

scala-center-bot commented Nov 29, 2023

This issue was picked for the Issue Spree No. 40 of December 5th, 2023 which takes place in 6 days. @mbovel, @EugeneFlesselle and @entangled90 will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

@entangled90
Copy link
Contributor

I tested both snippets on last commit on master (7a56da7) and both snippets provided compile with or without a println statement.

Version 3.3.1 manifest the same issue as 3.3.0.

@som-snytt
Copy link
Contributor

I did not do a bisect, but a quick probe says it progressed in August, which makes sense. Either someone had a restful Aug 1 holiday, then came back and saw the problem immediately, or someone was restless during their extended summer break, uninterested in further conversations with family, and decided to tackle some bugs in their spare time.

@entangled90
Copy link
Contributor

Run a bisect: commit that fixed the issue was 2b9a62b

@mbovel
Copy link
Member

mbovel commented Dec 5, 2023

Excellent, thanks @entangled90! Let's close this issue then 🥳

@mbovel mbovel closed this as completed Dec 5, 2023
@ncreep
Copy link
Author

ncreep commented Dec 5, 2023

Thanks for resolving this.

Can anyone please briefly explain what was the root cause of the issue?
Seeing how strange the failure was, I'm very curious to know what triggered it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

No branches or pull requests

7 participants