Skip to content

Unfinalize the class DefaultPromise #4690

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

Merged
merged 1 commit into from
Aug 18, 2015

Conversation

retronym
Copy link
Member

It was non-final in Scala 2.11.x, and made final as part
of fa0743c.

Removing the final modifier seems like the cleanest way to enable
conversions like javaFuture.toScala.toJava to return the original
javaFuture in scala-java8-compat.

I have made the methods defined in this class final as an
alternative lockdown.

Discussion, Motivation:

scala/scala-java8-compat#46
scala/scala-java8-compat#50

Review by @viktorklang

@scala-jenkins scala-jenkins added this to the 2.12.0-M3 milestone Aug 13, 2015
It was non-final in Scala 2.11.x, and made final as part
of fa0743c.

Removing the final modifier seems like the cleanest way to enable
conversions like `javaFuture.toScala.toJava` to return the original
`javaFuture` in scala-java8-compat.

I have made the methods defined in this class final as an
alternative lockdown.

Discussion, Motivation:

  scala/scala-java8-compat#46
  scala/scala-java8-compat#50
@retronym retronym force-pushed the topic/defaultpromise branch from 87f95ec to 898ee2a Compare August 13, 2015 05:25
final class DefaultPromise[T] extends AtomicReference[AnyRef](Nil) with Promise[T] {
// Left non-final to enable addition of extra fields by Java/Scala converters
// in scala-java8-compat.
class DefaultPromise[T] extends AtomicReference[AnyRef](Nil) with Promise[T] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to keep in mind is that this class extends AtomicReference (for performance reasons, since VarHandles are not available and AtomicReferenceUpdaters are slow) so subclasses could technically override the methods on AtomicReference (or worse, mess around with them).

I think we ought to put a big WARNING sign that says "don't mess around with the innards"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@retronym Could you verify that the transitively inherited methods from Promise are final too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it is enough that this is private[concurrent]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more worried about Java users here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but AtomicReferenceUpdater will save memory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise/Future helps a lot,change the way of asynchronous programming with scala,thanks @viktorklang .opt of Promise should be a part of slip,I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd be great :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more worried about Java users here.

We don't compile qualified private into JVM private.

$ 2.12.0-M2  javap scala/concurrent/impl/Promise\$DefaultPromise.class
Compiled from "Promise.scala"
public final class scala.concurrent.impl.Promise$DefaultPromise<T> extends java.util.concurrent.atomic.AtomicReference<java.lang.Object> implements scala.concurrent.impl.Promise<T> {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more worried about Java users here.

Are you suggesting that I add final overriding methods that delegate to the super method for each of (or some of) these:

image

That seems quite heavyweight to me. What are we seeking to prevent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably overthinking this. I think we'll be fine.

@retronym
Copy link
Member Author

@viktorklang Are you happy to give this one a LGTM?

retronym added a commit to retronym/scala-java8-compat that referenced this pull request Aug 17, 2015
Makes `toJava.toScala` and `toScala.toJava` a wrap-and-unwrap
operation, rather than a wrap-and-rewrap.

Once 2.12.0-M3 is released, we can reduce the overhead by extending
`DefaultPromise` rather than `Promise`.

See:
  4faeac5
  scala/scala#4690
retronym added a commit to retronym/scala-java8-compat that referenced this pull request Aug 17, 2015
Makes `toJava.toScala` and `toScala.toJava` a wrap-and-unwrap
operation, rather than a wrap-and-rewrap.

Once 2.12.0-M3 is released, we can reduce the overhead by extending
`DefaultPromise` rather than `Promise`.

See:
  4faeac5
  scala/scala#4690
@viktorklang
Copy link
Contributor

@retronym Apologies, of course, LGTM!

@retronym
Copy link
Member Author

LGTM echo, for the purposes of the bot.

retronym added a commit that referenced this pull request Aug 18, 2015
Unfinalize the class DefaultPromise
@retronym retronym merged commit cd77e23 into scala:2.12.x Aug 18, 2015
retronym added a commit to retronym/scala-java8-compat that referenced this pull request Aug 18, 2015
Makes `toJava.toScala` and `toScala.toJava` a wrap-and-unwrap
operation, rather than a wrap-and-rewrap.

Removes the cross build on 2.12, we should wait until 2.12.0-M3
in which DefaultPromise is once again extendable.

See:
  4faeac5
  scala/scala#4690
retronym added a commit to retronym/scala-java8-compat that referenced this pull request Aug 28, 2015
Makes `toJava.toScala` and `toScala.toJava` a wrap-and-unwrap
operation, rather than a wrap-and-rewrap.

Removes the cross build on 2.12, we should wait until 2.12.0-M3
in which DefaultPromise is once again extendable.

See:
  4faeac5
  scala/scala#4690
Ichoran pushed a commit to Ichoran/scala-java8-compat that referenced this pull request Sep 27, 2015
Makes `toJava.toScala` and `toScala.toJava` a wrap-and-unwrap
operation, rather than a wrap-and-rewrap.

Removes the cross build on 2.12, we should wait until 2.12.0-M3
in which DefaultPromise is once again extendable.

See:
  retronym@4faeac5
  scala/scala#4690
@adriaanm adriaanm added 2.12 and removed 2.12 labels 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