Skip to content

Commit

Permalink
Remove @inline annotations and enable Scala 2 inliner
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Dec 30, 2023
1 parent d829637 commit 8cb7d25
Show file tree
Hide file tree
Showing 34 changed files with 254 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object ActorTestKit {
* using default configuration from the reference.conf resources that ship with the Akka libraries.
* The application.conf of your project is not used in this case.
*/
def create(): ActorTestKit =
@noinline def create(): ActorTestKit =
new ActorTestKit(scaladsl.ActorTestKit(TestKitUtils.testNameFromCallStack(classOf[ActorTestKit])))

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ object ActorTestKit {
* When the test has completed you should terminate the `ActorSystem` and
* the testkit with [[ActorTestKit#shutdownTestKit]].
*/
def create(customConfig: Config): ActorTestKit =
@noinline def create(customConfig: Config): ActorTestKit =
new ActorTestKit(scaladsl.ActorTestKit(TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]), customConfig))

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class TestKitJunitResource(_kit: ActorTestKit) extends ExternalResource {
* using default configuration from the reference.conf resources that ship with the Akka libraries.
* The application.conf of your project is not used in this case.
*/
def this() = this(ActorTestKit.create(TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource])))
@noinline def this() = this(ActorTestKit.create(TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource])))

/**
* Use a custom [[pekko.actor.typed.ActorSystem]] for the actor system.
Expand All @@ -76,7 +76,7 @@ final class TestKitJunitResource(_kit: ActorTestKit) extends ExternalResource {
/**
* Use a custom config for the actor system.
*/
def this(customConfig: String) =
@noinline def this(customConfig: String) =
this(
ActorTestKit.create(
TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource]),
Expand All @@ -85,13 +85,13 @@ final class TestKitJunitResource(_kit: ActorTestKit) extends ExternalResource {
/**
* Use a custom config for the actor system.
*/
def this(customConfig: Config) =
@noinline def this(customConfig: Config) =
this(ActorTestKit.create(TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource]), customConfig))

/**
* Use a custom config for the actor system, and a custom [[pekko.actor.testkit.typed.TestKitSettings]].
*/
def this(customConfig: Config, settings: TestKitSettings) =
@noinline def this(customConfig: Config, settings: TestKitSettings) =
this(ActorTestKit.create(TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource]), customConfig, settings))

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object ActorTestKit {
* using default configuration from the reference.conf resources that ship with the Akka libraries.
* The application.conf of your project is not used in this case.
*/
def apply(): ActorTestKit = {
@noinline def apply(): ActorTestKit = {
val system = ActorSystem(
ActorTestKitGuardian.testKitGuardian,
TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]),
Expand Down Expand Up @@ -111,7 +111,7 @@ object ActorTestKit {
* When the test has completed you should terminate the `ActorSystem` and
* the testkit with [[ActorTestKit#shutdownTestKit]].
*/
def apply(customConfig: Config): ActorTestKit = {
@noinline def apply(customConfig: Config): ActorTestKit = {
val system = ActorSystem(
ActorTestKitGuardian.testKitGuardian,
TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import pekko.actor.typed.Props
import pekko.util.Timeout

object ActorTestKitBase {
def testNameFromCallStack(): String = TestKitUtils.testNameFromCallStack(classOf[ActorTestKitBase])
@noinline def testNameFromCallStack(): String = TestKitUtils.testNameFromCallStack(classOf[ActorTestKitBase])
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.FutureConverters#CompletionStageOps.asScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.FutureConverters#CompletionStageOps.asScala")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.FutureConverters#CompletionStageOps.asScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.FutureConverters#FutureOps.asJava$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.FutureConverters#FutureOps.asJava")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.FutureConverters#FutureOps.asJava$extension")
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOption.toJava$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOption.toJavaPrimitive$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOption.toJava")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOption.toJavaPrimitive")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOption.toJava$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOption.toJavaPrimitive$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptional.toJavaPrimitive$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptional.toScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptional.toScala")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptional.toJavaPrimitive")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptional.toScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptional.toJavaPrimitive$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalDouble.toJavaGeneric$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalDouble.toScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalDouble.toScala")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalDouble.toJavaGeneric")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalDouble.toScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalDouble.toJavaGeneric$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalInt.toJavaGeneric$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalInt.toScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalInt.toScala")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalInt.toJavaGeneric")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalInt.toScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalInt.toJavaGeneric$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalLong.toJavaGeneric$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalLong.toScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalLong.toScala")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalLong.toJavaGeneric")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalLong.toScala$extension")
ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.util.OptionConverters#RichOptionalLong.toJavaGeneric$extension")
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ object ByteIterator {
extends ByteIterator {
iterator =>

@inline final def len: Int = until - from
final def len: Int = until - from

@inline final def hasNext: Boolean = from < until
final def hasNext: Boolean = from < until

@inline final def head: Byte = array(from)
final def head: Byte = array(from)

final def next(): Byte = {
if (!hasNext) EmptyImmutableSeq.iterator.next()
Expand Down Expand Up @@ -206,13 +206,13 @@ object ByteIterator {
}
normalize()

@inline private def current: ByteArrayIterator = iterators.head
@inline private def dropCurrent(): Unit = { iterators = iterators.tail }
@inline final def clear(): Unit = { iterators = MultiByteArrayIterator.empty.iterators }
private def current: ByteArrayIterator = iterators.head
private def dropCurrent(): Unit = { iterators = iterators.tail }
final def clear(): Unit = { iterators = MultiByteArrayIterator.empty.iterators }

@inline final def hasNext: Boolean = current.hasNext
final def hasNext: Boolean = current.hasNext

@inline final def head: Byte = current.head
final def head: Byte = current.head

final def next(): Byte = {
val result = current.next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] {
this
}

@inline protected final def fillByteBuffer(len: Int, byteOrder: ByteOrder)(fill: ByteBuffer => Unit): this.type = {
protected final def fillByteBuffer(len: Int, byteOrder: ByteOrder)(fill: ByteBuffer => Unit): this.type = {
fillArray(len) {
case (array, start) =>
val buffer = ByteBuffer.wrap(array, start, len)
Expand Down Expand Up @@ -1078,7 +1078,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] {
_tempCapacity = _temp.length
}

@inline private def shouldResizeTempFor(size: Int): Boolean = _tempCapacity < size || _tempCapacity == 0
private def shouldResizeTempFor(size: Int): Boolean = _tempCapacity < size || _tempCapacity == 0

private def ensureTempSize(size: Int): Unit = {
if (shouldResizeTempFor(size)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ object ByteIterator {
extends ByteIterator {
iterator =>

@inline final def len: Int = until - from
final def len: Int = until - from

@inline final def hasNext: Boolean = from < until
final def hasNext: Boolean = from < until

@inline final def head: Byte = array(from)
final def head: Byte = array(from)

final def next(): Byte = {
if (!hasNext) EmptyImmutableSeq.iterator.next()
Expand Down Expand Up @@ -218,13 +218,13 @@ object ByteIterator {
}
normalize()

@inline private def current: ByteArrayIterator = iterators.head
@inline private def dropCurrent(): Unit = { iterators = iterators.tail }
@inline final def clear(): Unit = { iterators = MultiByteArrayIterator.empty.iterators }
private def current: ByteArrayIterator = iterators.head
private def dropCurrent(): Unit = { iterators = iterators.tail }
final def clear(): Unit = { iterators = MultiByteArrayIterator.empty.iterators }

@inline final def hasNext: Boolean = current.hasNext
final def hasNext: Boolean = current.hasNext

@inline final def head: Byte = current.head
final def head: Byte = current.head

final def next(): Byte = {
val result = current.next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] {
this
}

@inline protected final def fillByteBuffer(len: Int, byteOrder: ByteOrder)(fill: ByteBuffer => Unit): this.type = {
protected final def fillByteBuffer(len: Int, byteOrder: ByteOrder)(fill: ByteBuffer => Unit): this.type = {
fillArray(len) {
case (array, start) =>
val buffer = ByteBuffer.wrap(array, start, len)
Expand Down Expand Up @@ -1128,7 +1128,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] {
_tempCapacity = _temp.length
}

@inline private def shouldResizeTempFor(size: Int): Boolean = _tempCapacity < size || _tempCapacity == 0
private def shouldResizeTempFor(size: Int): Boolean = _tempCapacity < size || _tempCapacity == 0

private def ensureTempSize(size: Int): Unit = {
if (shouldResizeTempFor(size)) {
Expand Down
16 changes: 8 additions & 8 deletions actor/src/main/scala-3/org/apache/pekko/util/ByteIterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ object ByteIterator {
extends ByteIterator {
iterator =>

@inline final def len: Int = until - from
final def len: Int = until - from

@inline final def hasNext: Boolean = from < until
final def hasNext: Boolean = from < until

@inline final def head: Byte = array(from)
final def head: Byte = array(from)

final def next(): Byte = {
if (!hasNext) EmptyImmutableSeq.iterator.next()
Expand Down Expand Up @@ -215,13 +215,13 @@ object ByteIterator {
}
normalize()

@inline private def current: ByteArrayIterator = iterators.head
@inline private def dropCurrent(): Unit = { iterators = iterators.tail }
@inline def clear(): Unit = { iterators = MultiByteArrayIterator.empty.iterators }
private def current: ByteArrayIterator = iterators.head
private def dropCurrent(): Unit = { iterators = iterators.tail }
def clear(): Unit = { iterators = MultiByteArrayIterator.empty.iterators }

@inline final def hasNext: Boolean = current.hasNext
final def hasNext: Boolean = current.hasNext

@inline final def head: Byte = current.head
final def head: Byte = current.head

final def next(): Byte = {
val result = current.next()
Expand Down
4 changes: 2 additions & 2 deletions actor/src/main/scala-3/org/apache/pekko/util/ByteString.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] {
this
}

@inline protected final def fillByteBuffer(len: Int, byteOrder: ByteOrder)(fill: ByteBuffer => Unit): this.type = {
protected final def fillByteBuffer(len: Int, byteOrder: ByteOrder)(fill: ByteBuffer => Unit): this.type = {
fillArray(len) {
case (array, start) =>
val buffer = ByteBuffer.wrap(array, start, len)
Expand Down Expand Up @@ -1128,7 +1128,7 @@ final class ByteStringBuilder extends Builder[Byte, ByteString] {
_tempCapacity = _temp.length
}

@inline private def shouldResizeTempFor(size: Int): Boolean = _tempCapacity < size || _tempCapacity == 0
private def shouldResizeTempFor(size: Int): Boolean = _tempCapacity < size || _tempCapacity == 0

private def ensureTempSize(size: Int): Unit = {
if (shouldResizeTempFor(size)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, derived from Akka.
*/

package org.apache.pekko.util

import org.apache.pekko.annotation.InternalStableApi

import java.util.concurrent.CompletionStage
import scala.concurrent.Future

/**
* INTERNAL API
*
* Remove this once Scala 2.12 support is dropped since all methods are in Scala 2.13+ stdlib
*/
@InternalStableApi
private[pekko] object FutureConverters {
import scala.jdk.javaapi

def asJava[T](f: Future[T]): CompletionStage[T] = javaapi.FutureConverters.asJava(f)

implicit final class FutureOps[T](private val f: Future[T]) extends AnyVal {
inline def asJava: CompletionStage[T] = FutureConverters.asJava(f)
}

def asScala[T](cs: CompletionStage[T]): Future[T] = javaapi.FutureConverters.asScala(cs)

implicit final class CompletionStageOps[T](private val cs: CompletionStage[T]) extends AnyVal {
inline def asScala: Future[T] = FutureConverters.asScala(cs)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* license agreements; and to You under the Apache License, version 2.0:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* This file is part of the Apache Pekko project, derived from Akka.
*/

package org.apache.pekko.util

import org.apache.pekko.annotation.InternalStableApi

import java.util._
import scala.jdk.OptionShape

/**
* INTERNAL API
*
* Remove this once Scala 2.12 support is dropped since all methods are in Scala 2.13+ stdlib
*/
@InternalStableApi
private[pekko] object OptionConverters {

inline final def toScala[A](o: Optional[A]): Option[A] = scala.jdk.javaapi.OptionConverters.toScala(o)

inline def toScala(o: OptionalDouble): Option[java.lang.Double] = scala.jdk.javaapi.OptionConverters.toScala(o)

inline def toScala(o: OptionalInt): Option[java.lang.Integer] = scala.jdk.javaapi.OptionConverters.toScala(o)

inline def toScala(o: OptionalLong): Option[java.lang.Long] = scala.jdk.javaapi.OptionConverters.toScala(o)

inline final def toJava[A](o: Option[A]): Optional[A] = scala.jdk.javaapi.OptionConverters.toJava(o)

implicit final class RichOptional[A](private val o: java.util.Optional[A]) extends AnyVal {
inline def toScala: Option[A] = scala.jdk.OptionConverters.RichOptional(o).toScala

inline def toJavaPrimitive[O](implicit shape: OptionShape[A, O]): O =
scala.jdk.OptionConverters.RichOptional(o).toJavaPrimitive
}

implicit final class RichOption[A](private val o: Option[A]) extends AnyVal {
inline def toJava: Optional[A] = scala.jdk.OptionConverters.RichOption(o).toJava

inline def toJavaPrimitive[O](implicit shape: OptionShape[A, O]): O =
scala.jdk.OptionConverters.RichOption(o).toJavaPrimitive
}

implicit class RichOptionalDouble(private val o: OptionalDouble) extends AnyVal {

/** Convert a Java `OptionalDouble` to a Scala `Option` */
inline def toScala: Option[Double] = scala.jdk.OptionConverters.RichOptionalDouble(o).toScala

/** Convert a Java `OptionalDouble` to a generic Java `Optional` */
inline def toJavaGeneric: Optional[Double] = scala.jdk.OptionConverters.RichOptionalDouble(o).toJavaGeneric
}

/** Provides conversions from `OptionalInt` to Scala `Option` and the generic `Optional` */
implicit class RichOptionalInt(private val o: OptionalInt) extends AnyVal {

/** Convert a Java `OptionalInt` to a Scala `Option` */
inline def toScala: Option[Int] = scala.jdk.OptionConverters.RichOptionalInt(o).toScala

/** Convert a Java `OptionalInt` to a generic Java `Optional` */
inline def toJavaGeneric: Optional[Int] = scala.jdk.OptionConverters.RichOptionalInt(o).toJavaGeneric
}

/** Provides conversions from `OptionalLong` to Scala `Option` and the generic `Optional` */
implicit class RichOptionalLong(private val o: OptionalLong) extends AnyVal {

/** Convert a Java `OptionalLong` to a Scala `Option` */
inline def toScala: Option[Long] = scala.jdk.OptionConverters.RichOptionalLong(o).toScala

/** Convert a Java `OptionalLong` to a generic Java `Optional` */
inline def toJavaGeneric: Optional[Long] = scala.jdk.OptionConverters.RichOptionalLong(o).toJavaGeneric
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,6 @@ private[pekko] class ActorSystemImpl(
}
}

@inline
private def logFatalError(message: String, cause: Throwable, thread: Thread): Unit = {
// First log to stderr as this has the best chance to get through in an 'emergency panic' situation:
import System.err
Expand Down
Loading

0 comments on commit 8cb7d25

Please sign in to comment.