Skip to content

Functions declared in miniboxed scopes still box #114

@VladUreche

Description

@VladUreche

Technical limitation, will fix it:

$ cat gh-bug-X.scala 
package miniboxing.tests.correctness.bugX

class C[@miniboxed T](t: T) {
  def method = {
    // the body of foo is _not_ specialized since T => T is not an
    // optimized stack initiator, at least not in specialization's view:
    val foo = (x: T) => x
    foo(t)
  }
}

$ ../mb-scalac gh-bug-X.scala -Xprint:minibox-commit
[[syntax trees at end of            minibox-commit]] // gh-bug-X.scala
package miniboxing.tests.correctness.bugX {
  abstract trait C[@miniboxed T] extends Object {
    def method(): T;
    def method_D(T_TypeTag: Byte): Double;
    def method_J(T_TypeTag: Byte): Long
  };
  class C_D[Tsp] extends Object with miniboxing.tests.correctness.bugX.C[Tsp] {
    def <init>(miniboxing|tests|correctness|bugX|C_D|T_TypeTag: Byte, t: Double): miniboxing.tests.correctness.bugX.C_D[Tsp] = {
      C_D.super.<init>();
      ()
    };
    def method(): Tsp = MiniboxConversionsDouble.this.minibox2box[Tsp](C_D.this.method_D(C_D.this.miniboxing|tests|correctness|bugX|C_D|T_TypeTag), C_D.this.miniboxing|tests|correctness|bugX|C_D|T_TypeTag);
    def method_D(T_TypeTag: Byte): Double = {
      val foo: miniboxing.runtime.MiniboxedFunction1[Tsp,Tsp] = {
        final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Tsp,Tsp] with Serializable {
          def <init>(): <$anon: Tsp => Tsp> = {
            $anonfun.super.<init>();
            ()
          };
          final def apply(x: Tsp): Tsp = x
        };
        MiniboxedFunctionBridge.this.function1_opt_bridge_double_double[Tsp, Tsp](T_TypeTag, T_TypeTag, (new <$anon: Tsp => Tsp>(): Tsp => Tsp))
      };
      foo.apply_DD(T_TypeTag, T_TypeTag, C_D.this.t)
    };
    def method_J(T_TypeTag: Byte): Long = MiniboxConversions.this.unreachableConversion[Nothing]("Double", "Long");
    <paramaccessor> private[this] val miniboxing|tests|correctness|bugX|C_D|T_TypeTag: Byte = _;
    <paramaccessor> private[this] val t: Double = _
  };
  class C_J[Tsp] extends Object with miniboxing.tests.correctness.bugX.C[Tsp] {
    def <init>(miniboxing|tests|correctness|bugX|C_J|T_TypeTag: Byte, t: Long): miniboxing.tests.correctness.bugX.C_J[Tsp] = {
      C_J.super.<init>();
      ()
    };
    def method(): Tsp = MiniboxConversionsLong.this.minibox2box[Tsp](C_J.this.method_J(C_J.this.miniboxing|tests|correctness|bugX|C_J|T_TypeTag), C_J.this.miniboxing|tests|correctness|bugX|C_J|T_TypeTag);
    def method_D(T_TypeTag: Byte): Double = MiniboxConversions.this.unreachableConversion[Nothing]("Long", "Double");
    def method_J(T_TypeTag: Byte): Long = {
      val foo: miniboxing.runtime.MiniboxedFunction1[Tsp,Tsp] = {
        final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Tsp,Tsp] with Serializable {
          def <init>(): <$anon: Tsp => Tsp> = {
            $anonfun.super.<init>();
            ()
          };
          final def apply(x: Tsp): Tsp = x
        };
        MiniboxedFunctionBridge.this.function1_opt_bridge_long_long[Tsp, Tsp](T_TypeTag, T_TypeTag, (new <$anon: Tsp => Tsp>(): Tsp => Tsp))
      };
      foo.apply_JJ(T_TypeTag, T_TypeTag, C_J.this.t)
    };
    <paramaccessor> private[this] val miniboxing|tests|correctness|bugX|C_J|T_TypeTag: Byte = _;
    <paramaccessor> private[this] val t: Long = _
  };
  class C_L[Tsp] extends Object with miniboxing.tests.correctness.bugX.C[Tsp] {
    def <init>(t: Tsp): miniboxing.tests.correctness.bugX.C_L[Tsp] = {
      C_L.super.<init>();
      ()
    };
    def method(): Tsp = {
      val foo: miniboxing.runtime.MiniboxedFunction1[Tsp,Tsp] = {
        final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Tsp,Tsp] with Serializable {
          def <init>(): <$anon: Tsp => Tsp> = {
            $anonfun.super.<init>();
            ()
          };
          final def apply(x: Tsp): Tsp = x
        };
        MiniboxedFunctionBridge.this.function1_bridge[Tsp, Tsp]((new <$anon: Tsp => Tsp>(): Tsp => Tsp))
      };
      foo.apply(C_L.this.t)
    };
    def method_D(T_TypeTag: Byte): Double = MiniboxConversionsDouble.this.box2minibox_tt[Tsp](C_L.this.method(), T_TypeTag);
    def method_J(T_TypeTag: Byte): Long = MiniboxConversionsLong.this.box2minibox_tt[Tsp](C_L.this.method(), T_TypeTag);
    <paramaccessor> private[this] val t: Tsp = _
  }
}

The problem is that, in all definitions, the

  final def apply(x: Tsp): Tsp = x

is not specialized. This means function definitions need to be hijacked completely, before the head for interop-coerce...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions