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

Support Function1 and Function2 methods #153

Open
VladUreche opened this issue Nov 28, 2014 · 1 comment
Open

Support Function1 and Function2 methods #153

VladUreche opened this issue Nov 28, 2014 · 1 comment

Comments

@VladUreche
Copy link
Member

Function1 provides andThen and composewhile Function2 provides curried and tupled. These should be supported by the function transformation procedure directly, without transforming from MiniboxedFunctionX to FunctionX and then back. Right now, we're safe because anonymous functions are not transformed, but we'll have to do that as part of #114:

$ cat gh-bug-xxx.scala 
package miniboxing.tests.compile.bugxxx

object Test extends App {

  val f = ((x: Int) => x + 1) andThen (x => x * 2)

  println(f(1)) // 4
  println(f(2)) // 6
}

$ mb-scalac gh-bug-xxx.scala -Xprint:interop-commit
[[syntax trees at end of            interop-commit]] // gh-bug-xxx.scala
package miniboxing.tests.compile.bugxxx {
  object Test extends Object with App {
    def <init>(): miniboxing.tests.compile.bugxxx.Test.type = {
      Test.super.<init>();
      ()
    };
    private[this] val f: miniboxing.runtime.MiniboxedFunction1[Int,Int] = MiniboxedFunctionBridge.this.function1_bridge[Int, Int]({
  @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Int,Int] with Serializable {
    def <init>(): <$anon: Int => Int> = {
      $anonfun.super.<init>();
      ()
    };
    final def apply(x: Int): Int = x.+(1)
  };
  (new <$anon: Int => Int>(): Int => Int)
}.andThen[Int]({
      @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Int,Int] with Serializable {
        def <init>(): <$anon: Int => Int> = {
          $anonfun.super.<init>();
          ()
        };
        final def apply(x: Int): Int = x.*(2)
      };
      (new <$anon: Int => Int>(): Int => Int)
    }));
    <stable> <accessor> def f(): miniboxing.runtime.MiniboxedFunction1[Int,Int] = Test.this.f;
    scala.this.Predef.println(Test.this.f().apply(1));
    scala.this.Predef.println(Test.this.f().apply(2))
  }
}
@VladUreche
Copy link
Member Author

Kicking this down the track, I can't handle it yet.

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

1 participant