Skip to content
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

Inline methods of opaque types leave redundant proxies in byte code #21334

Open
soronpo opened this issue Aug 6, 2024 · 0 comments
Open

Inline methods of opaque types leave redundant proxies in byte code #21334

soronpo opened this issue Aug 6, 2024 · 0 comments

Comments

@soronpo
Copy link
Contributor

soronpo commented Aug 6, 2024

Compiler version

v3.4.2
v3.5.0-RC6

Minimized code

//> using scala 3.5.0-RC6
//> using option -Xprint:genBCode

opaque type MyOpaque <: Int = Int
object MyOpaque:
  inline def apply(inline value: Int): MyOpaque = value

class Foo:
  val x = MyOpaque(8)

Output

genBCode phase printing

package <empty> {
  final module class ID$package$MyOpaque extends Object {
    def <init>(): Unit =
      {
        super()
        ()
      }
    private def writeReplace(): Object =
      new scala.runtime.ModuleSerializationProxy(classOf[ID$package$MyOpaque])
  }
  @SourceFile("ID.scala") class Foo extends Object {
    def <init>(): Unit =
      {
        super()
        this.x =
          {
            val $proxy1: ID$package = ID$package:ID$package
            val ID$package$_this: ID$package = $proxy1
            8:Int
          }:Int
        ()
      }
    private val x: Int
    def x(): Int = this.x
  }
  @SourceFile("ID.scala") final module class ID$package extends Object {
    def <init>(): Unit =
      {
        super()
        ()
      }
    private def writeReplace(): Object =
      new scala.runtime.ModuleSerializationProxy(classOf[ID$package])
    final lazy module <static> val MyOpaque: ID$package$MyOpaque =
      new ID$package$MyOpaque()
  }
  final lazy module val ID$package: ID$package = new ID$package()
}

Foo.class byte code

public class Foo {
  private final int x;

  public Foo();
    Code:
       0: aload_0
       1: invokespecial #11                 // Method java/lang/Object."<init>":()V
       4: aload_0
       5: getstatic     #17                 // Field ID$package$.MODULE$:LID$package$;
       8: astore_1
       9: aload_1
      10: astore_2
      11: bipush        10
      13: putfield      #19                 // Field x:I
      16: return

  public int x();
    Code:
       0: aload_0
       1: getfield      #19                 // Field x:I
       4: ireturn
}

Expectation

The proxies should be removed, as they are completely redundant in this case. x should just get the value 8.

@soronpo soronpo added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 6, 2024
@dwijnand dwijnand added area:backend area:inline itype:enhancement and removed stat:needs triage Every issue needs to have an "area" and "itype" label itype:bug labels Aug 6, 2024
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

2 participants