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

SD-121 Remove now-unneeded J{Function,Proc}N functional interfaces #5298

Merged
merged 1 commit into from
Jul 22, 2016

Conversation

retronym
Copy link
Member

@retronym retronym commented Jul 22, 2016

Non specialized functions can directly use scala.FunctionN as the
functional interface, now that mixin generates default methods in
the new trait encoding.

Unfortunately we can't do this for specialized functions as things
stand: specialization leaves the wrong method abstract. In principle,
we could/should amend the specialization transform to fix this. But
my earlier attempts at this weren't sucessful, so for now we have
to stick with the fallback plan of keeping some hand rolled functional
interfaces around.

This commit reduces the surface area of scala.runtime.java8 to
the minimal requiremnt: one functional interface for each specialized
variant of Function{0,1,2}.

Fixes scala/scala-dev#121

@retronym
Copy link
Member Author

Review by @lrytz | @adriaanm

@retronym retronym changed the title SD-121 Pare back runtime support for indylambda to the minimal set SD-121 Remove now-uneeded J{Function,Proc}N functional interfaces Jul 22, 2016
@retronym retronym changed the title SD-121 Remove now-uneeded J{Function,Proc}N functional interfaces SD-121 Remove now-unneeded J{Function,Proc}N functional interfaces Jul 22, 2016
Non specialized functions can directly use `scala.FunctionN` as the
functional interface, now that mixin generates default methods in
the new trait encoding.

Unfortunately we can't do this for specialized functions as things
stand: specialization leaves the wrong method abstract. In principle,
we could/should amend the specialization transform to fix this. But
my earlier attempts at this weren't sucessful, so for now we have
to stick with the fallback plan of keeping some hand rolled functional
interfaces around.

This commit reduces the surface area of `scala.runtime.java8` to
the minimal requiremnt: one functional interface for each specialized
variant of `Function{0,1,2}`.
@lrytz
Copy link
Member

lrytz commented Jul 22, 2016

LGTM, cool!

@lrytz lrytz merged commit 49a4750 into scala:2.12.x Jul 22, 2016
@szeiger
Copy link
Contributor

szeiger commented Aug 29, 2016

Unfortunately this removes JFunction.proc, so now you have to manually return scala.runtime.BoxedUnit.UNIT from Java code to create a Scala function that returns Unit.

@szeiger
Copy link
Contributor

szeiger commented Aug 29, 2016

Another issue: We lose serializability of lambdas once again. JFunction* classes were Serializable, scala.Function* classes are still not.

szeiger added a commit to szeiger/scala-java8-compat that referenced this pull request Aug 29, 2016
- Add the required `override` modifiers to trait methods that now
  extend default methods of Java interfaces.

- Add casts in some of these methods because the Scala primitive types
  are not compatible at the type level with the (now inherited) Java
  boxed types.

- Use the boxed JFunction types in BoxingTest because the generic ones
  do not exist anymore.

- Tests in LambdaTest need to be commented out because usage from Java
  changed significantly after scala/scala#5298
  but we can still cross-build the actual library against 2.11 and
  2.12.0-M5. At some point we should consider branching.
@retronym
Copy link
Member Author

Maybe we should leave those concerns to Scala-java8-compat and leave things here minimal

@retronym
Copy link
Member Author

Scalac adds serializability to anon classes without the need for the functional interface itself to extend serializable.

szeiger added a commit to szeiger/scala-java8-compat that referenced this pull request Aug 31, 2016
- The various JFunction and JProcedure sources that were removed from
  Scala in scala/scala#5298 are now included
  here when building for Scala 2.12.x (except M5).

- Code that relies on specialized JFunction types being subtypes of the
  generic JFunction types will inevitably break. This is unavoidable.
  The specialized types are still part of Scala but they extend Scala
  function types directly.

- All JFunctionN types and JFunction.func methods are deprecated. They
  are provided for source compatibility between 2.11 and 2.12 only.

- The JProcedureN classes, JFunction.funcSpecialized methods and
  JFunction.proc methods are still useful in 2.12 for easy
  interoperability between Scala specialization and Java’s primitive
  types from Java code.
szeiger added a commit to scala/scala-java8-compat that referenced this pull request Sep 9, 2016
- The various JFunction and JProcedure sources that were removed from
  Scala in scala/scala#5298 are now included
  here when building for Scala 2.12.x (except M5).

- Code that relies on specialized JFunction types being subtypes of the
  generic JFunction types will inevitably break. This is unavoidable.
  The specialized types are still part of Scala but they extend Scala
  function types directly.

- All JFunctionN types and JFunction.func methods are deprecated. They
  are provided for source compatibility between 2.11 and 2.12 only.

- The JProcedureN classes, JFunction.funcSpecialized methods and
  JFunction.proc methods are still useful in 2.12 for easy
  interoperability between Scala specialization and Java’s primitive
  types from Java code.

- Generate JFunction and JProcedure sources:
  Just like for 2.11, we generate the sources again for 2.12 (after M5).
  I wrote a new code generator which is much simpler than the old one
  (because there is less and simpler code to generate). We can remove the
  old one when we drop support for Scala 2.11.

- Move code back from scala.runtime.java8 to scala.compat.java8:
  The standard library contains some specialized JFunction* classes in
  scala.runtime.java8, so we cannot use the same package here if we ever
  want this to work with Java 9 modules. Therefore everything is moved
  back to scala.compat.java8 where it was in 0.7.

  We have to drop compatibility with Scala 2.12.0-M5 which contains
  these classes as part of scala-library in scala.runtime.java8.

- Update to proper Scala 2.12.0-RC so we can build a release
@adriaanm adriaanm added the 2.12 label Oct 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants