Skip to content

references to inlined method, created in tasty, are not inlined. #9687

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
rssh opened this issue Aug 31, 2020 · 2 comments · Fixed by #8870
Closed

references to inlined method, created in tasty, are not inlined. #9687

rssh opened this issue Aug 31, 2020 · 2 comments · Fixed by #8870

Comments

@rssh
Copy link
Contributor

rssh commented Aug 31, 2020

Minimized code

X.scala

package x

import scala.quoted._

object FastPath {

  inline def sum(x:Int):Int =
    x + 1

}

object SlowPath {

  def sum(x:Int):Int =
    x + 1

}

object X {

 inline def transform[A](inline x:A):A = ${
    transformImpl[A]('x)
 }

 def transformImpl[A:Type](x:Expr[A])(using qctx: QuoteContext):Expr[A] = {
    import qctx.tasty._
    val slowPath = '{ SlowPath }.unseal
    val fastPath = '{ FastPath }.unseal
    val transformer = new TreeMap() {
      override def transformTerm(term:Term)(using ctx:Context):Term = {
        term match
          case Apply(sel@Select(o,m),args) =>
                if ( o.tpe =:= slowPath.tpe && m=="sum" )
                   Apply(Select.unique(fastPath,"sum"), args)
                else
                   super.transformTerm(term)
          case _ => super.transformTerm(term)
      }
    }
    val r = transformer.transformTerm(x.unseal).seal.cast[A]
    println(s"result: ${r.show}")
    r
 }
}

and Main.scala

package x


object Main {


 def main(args:Array[String]):Unit =
   val r = X.transform{
     SlowPath.sum(1)
   }

}

Output

Latest Dotty nightly build version: 0.28.0-bin-20200828-4c99388-NIGHTLY
[info] loading settings for project root from build.sbt ...
[info] set current project to test (in build file:/Users/rssh/tests/dotty/unexpanded-inline/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] Compiling 1 Scala source to /Users/rssh/tests/dotty/unexpanded-inline/target/scala-0.28/classes ...
[info] Compiling 1 Scala source to /Users/rssh/tests/dotty/unexpanded-inline/target/scala-0.28/classes ...
result: x.FastPath.sum(1)
[error] -- Error: /Users/rssh/tests/dotty/unexpanded-inline/src/main/scala/x/Main.scala:8:22 
[error] 8 |   val r = X.transform{
[error]    |           ^
[error]    |           method sum is declared as erased, but is in fact used
[error] 9 |     SlowPath.sum(1)
[error] 10 |   }
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

Expectation

that it will compile and expand inlined FastPath.sum

btw, if this impossible => maybe give access to inlineCall from reflection interface ?

@rssh rssh added the itype:bug label Aug 31, 2020
@rssh
Copy link
Contributor Author

rssh commented Aug 31, 2020

(btw. not sure - this is a bug or not?
If not -- we should have some method to inline call from tasty).

@nicolasstucki
Copy link
Contributor

This looks like a duplicate of #8866. We have a fix for it in #8870 but it is blocked due to some bug that affects cps-async submodule. This bug is looked like a manifestation of #9518.

@nicolasstucki nicolasstucki linked a pull request Sep 1, 2020 that will close this issue
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

3 participants