Skip to content

Inlined inline val reference does not get constant folded #8843

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
nicolasstucki opened this issue Apr 30, 2020 · 1 comment · Fixed by #8852
Closed

Inlined inline val reference does not get constant folded #8843

nicolasstucki opened this issue Apr 30, 2020 · 1 comment · Fixed by #8852

Comments

@nicolasstucki
Copy link
Contributor

Minimized code

class C:
  type X <: Tuple

inline def f(c: C): Unit = {
  inline val size = compiletime.constValue[Tuple.Size[c.X]]
  val n = size
  val m: Int = n
  ???
}

def test: Unit = f(??? : C { type X = Tuple1[Any] })

Output

result after typer:
...
def test: Unit = 
      {
        val c: C{X = Tuple1[Any]} = 
          ??? :
            C 
              {
                type X = Tuple1[Any]
              }
        {
          inline val size: (1 : Int) = 1
          val n: (1 : Int) = size
          val m: Int = n
          ???
        }:Unit
      }
...
result after genBCode:
...
    def test(): Unit = 
      {
        val c: C = ???():C
        {
          {
            inline val size: Int = 1
            val n: Int = size
            val m: Int = n
            ???()
          }:scala.runtime.BoxedUnit
          ()
        }
      }
...

Expectation

The reference to size should be replaced by the literal constant 1. This is needed to ensure that all local inline vals can be erased.

@nicolasstucki
Copy link
Contributor Author

Related to #8836

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 1, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 1, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 1, 2020
@nicolasstucki nicolasstucki linked a pull request May 1, 2020 that will close this issue
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 1, 2020
nicolasstucki added a commit that referenced this issue May 2, 2020
Fix #8843: Normalize type when constant folding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant