Skip to content

Can we store the original call before inline? #5503

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
Duhemm opened this issue Nov 23, 2018 · 1 comment
Closed

Can we store the original call before inline? #5503

Duhemm opened this issue Nov 23, 2018 · 1 comment

Comments

@Duhemm
Copy link
Contributor

Duhemm commented Nov 23, 2018

When the IDE works with trees coming from TASTy, it cannot see the trees before inlining. That means that find all references and rename can return wrong results. All of that happens because we cannot see the original call in the trees that have been unpickled.

Example:

  @Test def referencesInlineArg: Unit = {
    withSources(
      tasty"""package foo
             |object Bar {
             |  val fizz = Foo.foo(Foo.${m1}myValue${m2})
             |}""",
      code"""package foo
            |object Foo {
            |  inline def foo(x: Int): Int = 0
            |  val ${m3}myValue${m4} = 3
            |}"""
    ).references(m3 to m4, List(m1 to m2, m3 to m4), withDecl = true)
     .references(m3 to m4, List(m1 to m2), withDecl = false)
  }

The references inside object Bar will not be seen by the IDE. Note that object Bar is not opened , but its trees will be unpickled. If we use the code interpolator instead of tasty, then the test passes.

This used to be fine after @nicolasstucki moved inlining out of typer in #5216, but this was reverted by @odersky in #5382 and #5383.

My understanding is that the original call is removed because its size may explode. Would it be possible to improve on that by only storing pre-expansion trees in the original call?

Considering the following source:

object Foo {
  inline def foo(x: Int): Int = /* something huge */
  inline def bar: Int = /* something huge */
  inline def baz: Int = /* something huge */
  inline def fizz(a: Int, b: Int) = /* ... */
}
object Bar {
  import Foo._
  val buzz = fizz(foo(baz), bar)
}

What I'm suggesting is that the RHS of val buzz could be

Inlined(
  call = Apply(fizz, List(Apply(foo, List(baz)), bar)),
  expansion = /* ... */)

instead of

Inlined(
  call = Apply(fizz,
               List(
                 Inlined(
                   call = Apply(foo, List(/* something huge */)),
                   expansion = /* something huge */),
                 Inlined(
                   call = Apply(bar, List(/* something huge */)),
                   expansion = /* something huge */))),
  expansion = /* ... */)

which would be more helpful than the current

Inlined(
  call = Foo,
  expansion = /* ... */)

Would it be possible to create this original call and store it? Would that solve the bytecode size issues?

None of this is a concern for incremental compilation, because the original call is removed after ExtractDependencies.

@odersky
Copy link
Contributor

odersky commented Nov 26, 2018

We decided we can keep outermost inline calls. That would avoid the combinatorial explosion.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 27, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 18, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 18, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 18, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 18, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 19, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 19, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 19, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 19, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 19, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 19, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 24, 2019
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 24, 2019
@nicolasstucki nicolasstucki removed their assignment Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants