question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inliner can remove side effects from objects

See original GitHub issue

Noticed while discussing #4763, haven’t found in the tracker. Might be a known bug (related to what @allanrenucci noticed recently with constant folding accepting idempotent rather than pure methods), but we should have an issue for this.

EDIT: the issue is that println("object init"); is dropped.

sbt:dotty> repl -Xprint:frontend
object A {
  println("object init");
  inline def x: 1 = { println("x init") ; 1 } //`inline val` requires a val on the rhs
}
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>

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*/
          {
            {
              println("x init")
              1
            }
          }
    }
  }
}
// defined object B

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sjrdcommented, Jul 12, 2018

The inliner’s job is to produce fast code, and it can’t do that if we fix this issue.

I’m sorry but no. The inliner’s primary job is to produce correct code. Under that constraint, it should make it as fast as possible. But disregarding correctness because it’s annoying to produce fast code is a terrible mistake.

If you want to do that, you need to change the language specification to relax the rules of object initialization.

0reactions
oderskycommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GCC Inline Assembly side effects
I think you can use the same trick to eliminate the volatile . But I think it is not actually necessary here because...
Read more >
Lambda side effect change when `inline` is used
I trying to add support for Scala 3 to the cfor project (Scala cfor macro, like a java for-loop). In Scala 3, the...
Read more >
React, Inline Functions, and Performance | by Ryan Florence
So, if you inline an object in your JSX, it will fail the PureComponent prop ... (unless they are used in lifecycle hooks...
Read more >
Work with anchored objects in InDesign
To anchor an existing object, select it and choose Edit > Cut. Then, using the Type tool, position the insertion point where you...
Read more >
Inline Frames and Anchored Objects in Adobe InDesign CS3
You know what we we're talking about—illustrations that should appear immediately after a paragraph (think of the screen shots in a manual), or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found