Skip to content

Invert special case in inliner for static super accessors in traits #241

Closed
@lrytz

Description

@lrytz

When static super accessors for trait methods were introduced, the static methods contained the actual implementation and the default method would forward to the static one. This was later inversed.

The initial commit introduced a special case to the inliner to follow through default methdos into the static methods (scala/scala@7d51b3f#diff-804ddd7dd6341c64ee5a5c79db540e59L96). Now that the static method is the forwarder, this is no longer required. However, we could add a similar special case for static calls to the super accessor to make sure the actual body gets inlined.

Related, if a trait method is inlined, it is also inlined into the static super accessor, the body is duplicated. It would be better to avoid this duplication and inline through static accessors, like we initially inlined through default methods.

$ cat Test.scala
trait T {
  final def m(f: Int => Int) = f(100)
}

class C extends T {
  def n = m(x => x + 1)
}

$ qsc -opt:l:classpath Test.scala

$ cfr-decompiler T.class
public interface T {
    default public static /* synthetic */ int m$(T $this, Function1 f) {
        return f.apply$mcII$sp(100);
    }

    default public int m(Function1<Object, Object> f) {
        return f.apply$mcII$sp(100);
    }

    default public static void $init$(T $this) {
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions