Skip to content

Conversation

@Tetchki
Copy link

@Tetchki Tetchki commented Jul 17, 2023

Refactoring of inlined nodes to simplify the work on #17055.
This work is based on #18229.

Check if the copied inlined node's expansion exists, and if not set it to the original node's expansion
Refactoring of inlined nodes to simplify the work on scala#17055.
This work is based on scala#18229.
@Tetchki Tetchki force-pushed the inlined-refactoring branch from 1355b26 to 66ddf48 Compare July 17, 2023 15:21
case _ =>
}
(scall, stats ::: inits, args)
case inlined @ Inlined(_, _, _) => transformConstructor(Inlines.dropInlined(inlined) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this one needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newClassExtendsClassParams was finding an unexpected inlined node while transforming the constructor

@nicolasstucki
Copy link
Contributor

I have investigated the failures, and this is what I found.

Consider the following example compiled with -Ycheck:all -Xprint:all -Xprint-inline.

object Test:
  inline def foo(xs: List[Int]): Unit =
    val f = () => xs
    ()
  def test = foo(Nil)

before lambda lift we will have

    def test(): Unit =
      {{/* inlined from Test.foo(Nil) */
        {
          val f: Function0 =
            {
              def $anonfun(): scala.collection.immutable.List =
                {{/* inlined from outside */Nil()}}
              closure($anonfun:Function0)
            }
          ()
        }
      }}

but after lambda lift we get

    def test(): Unit =
      {{/* inlined from Test.foo(Nil) */
        {
          val f: Function0 =
            {
              closure(this.$anonfun$1:Function0)
            }
          ()
        }
      }}
    private final def $anonfun$1(): scala.collection.immutable.List =
      {{/* inlined from outside */Nil()}}

Note that {{/* inlined from outside */Nil()}} is not nested in inline node. This is nonsensical in this scope.

It seems we will need to redesign the contents of Inlined.call (at least in the backend phases). These nodes should be more resilient to changes of scope.

@nicolasstucki
Copy link
Contributor

Inlined trees with an empty call cannot just be dropped when lambda lifted. For example the lifted argument in the following example should be marked as inlined from bar.

object Test:
  inline def bar(): Unit = foo(Nil)
  inline def foo(xs: List[Int]): Unit =
    val f = () => xs
    ()
  def test = bar()

@nicolasstucki
Copy link
Contributor

Maybe we could change this

    def test(): Unit =
      {{/* inlined from Test.bar() */
        {{/* inlined from Test.foo(Nil) */
          {
            val f: Function0 =
              {
                def $anonfun(): scala.collection.immutable.List =
-                  {{/* inlined from outside */Nil()}}
+                  {{/*  inlined from Test.foo(Nil) */Nil()}}
                closure($anonfun:Function0)
              }
            ()
          }
        }}
      }}

But we would also need to change the way we handle nested inline contexts. We might add a new field to state if the inline node is adding a scope or poping it.

We would need to make this after the pickling phases (Pickling and PickleQuotes) to make sure that we do not change the current behavior of TASTy.

smarter added a commit that referenced this pull request Jul 19, 2023
This is the first step towards supporting `Inlined` trees after lambda
lift (see
#18230 (comment)).

We decouple the way we compute if a call was inlined from an outer scope
from the inlined call.
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 this pull request may close these issues.

3 participants