Skip to content

Fix #4765, evaluate objects we inline from if not pure #4766

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
wants to merge 1 commit into from

Conversation

Blaisorblade
Copy link
Contributor

@Blaisorblade Blaisorblade commented Jul 5, 2018

Fix #4765: when inlining A.x, produce A and then x's body.
Missing: tests — but first let's figure out if we want to do this change.

Here's the "repl-test" from #4765 — it turns A.x into { val A$_this: A.type(A) = A; { println("x init"); 1 } } rather than { println("x init"); 1 }.

sbt:dotty> repl -Xprint:frontend
[...]
[info] Running (fork) dotty.tools.repl.Main -classpath /Users/pgiarrusso/git/dotty/library/target/scala-2.12/dotty-library_2.12-0.9.0-bin-SNAPSHOT-nonbootstrapped.jar -Xprint:frontend
scala> object A {
     |   println("object init");
     |   inline def x: 1 = { println("x init") ; 1 } //`inline val` requires a val on the rhs
     | }
result of rs$line$1 after frontend:
package <empty> {
  final lazy module val rs$line$1: rs$line$1$ = new rs$line$1$()
  final module class rs$line$1$() extends Object() { this: rs$line$1.type =>
    final lazy module val A: A$ = new A$()
    final module class A$() extends Object() { this: A.type =>
      println("object init")
      inline def x: 1.type =
        {
          println("x init")
          1
        }
    }
  }
}
// defined object A

scala> object B {
     |            val y = A.x
     |          }
result of rs$line$2 after frontend:
package <empty> {
  final lazy module val rs$line$2: rs$line$2$ = new rs$line$2$()
  final module class rs$line$2$() extends Object() { this: rs$line$2.type =>
    final lazy module val B: B$ = new B$()
    final module class B$() extends Object() { this: B.type =>
      val y: Int =
        /* inlined from A.x*/
          {
            val A$_this: A.type(A) = A
            {
              println("x init")
              1
            }
          }
    }
  }
}
// defined object B

@Blaisorblade Blaisorblade self-assigned this Jul 5, 2018
@Blaisorblade Blaisorblade changed the title WIP try fixing #4765 WIP Fix #4765, evaluate objects we inline from if not pure Jul 6, 2018
@Blaisorblade Blaisorblade changed the title WIP Fix #4765, evaluate objects we inline from if not pure Fix #4765, evaluate objects we inline from if not pure Jul 6, 2018
@Blaisorblade Blaisorblade removed their assignment Jul 6, 2018
@Blaisorblade Blaisorblade requested a review from odersky July 6, 2018 12:19
@odersky
Copy link
Contributor

odersky commented Jul 6, 2018

I think we should leave this as is for the moment. The problem is that, without a good purity analysis of objects we end up referring to way too many objects. The inliner's job is to produce fast code, and it can't do that if we fix this issue.

I believe the correct approach is to come up with a better purity analysis of objects. #4710 is a start. If we have that, we can switch to isImpure but not before.

So my suggestion:

  1. Get Some Rudimentary Tracking of Class Purity #4710 in.
  2. Think about possible ways to make the analysis more precise.
  3. Flip the switch to elide prefixes only if pure (instead of idempotent) while at the same
    time carefully evaluating how it affects performance. We should do both benchmarking
    and perform counts how many prefixes are then newly evaluated and get an idea how
    many false negatives we get in practice.

@odersky odersky assigned Blaisorblade and unassigned odersky Jul 6, 2018
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

See earlier comment

@odersky
Copy link
Contributor

odersky commented Jul 7, 2018

If it's stat:revisit (which is the right label, I agree), then we should close for now.

@odersky odersky closed this Jul 7, 2018
@Blaisorblade Blaisorblade deleted the fix-4765 branch August 11, 2018 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants