Skip to content

Commit

Permalink
chore: Upgrade to Scala 3.3.0-RC2, cleanup (#71)
Browse files Browse the repository at this point in the history
* chore: Upgrade to Scala 3.3.0-RC2, cleanup

* Clean-up j17.
  • Loading branch information
markehammons authored Feb 10, 2023
1 parent 3d44c88 commit 09a719b
Show file tree
Hide file tree
Showing 37 changed files with 83 additions and 112 deletions.
3 changes: 1 addition & 2 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object v {
object scoverage extends BaseModule with ScoverageReport

trait BaseModule extends ScoverageModule with ScalafmtModule {
def scalaVersion = "3.2.2"
def scalaVersion = "3.3.0-RC2"
def scoverageVersion = "2.0.7"

val munitVersion = "1.0.0-M6"
Expand All @@ -46,7 +46,6 @@ trait BaseModule extends ScoverageModule with ScalafmtModule {
"-source:future",
"-Ykind-projector",
"-Vprofile"
//"-Ycc"
)

trait BaseTest extends ScoverageTests with TestModule.Munit {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package fr.hammons.slinc

import org.openjdk.jmh.annotations.*,
Mode.{SampleTime, SingleShotTime, Throughput}
import org.openjdk.jmh.annotations.{Scope as _, *}
import java.util.concurrent.TimeUnit
import fr.hammons.slinc.Scope
import scala.util.Random
import scala.annotation.nowarn

case class div_t(quot: Int, rem: Int)

@nowarn("msg=unused explicit parameter")
trait BindingsBenchmarkShape(val s: Slinc):
import scala.language.unsafeNulls
import s.{given, *}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package fr.hammons.slinc

import org.openjdk.jmh.annotations.*,
Mode.{SampleTime, SingleShotTime, Throughput}
import java.util.concurrent.TimeUnit
import fr.hammons.slinc.Scope
import scala.annotation.experimental
import org.openjdk.jmh.annotations.{Scope as _, *}

case class A(a: Int, b: B, c: Int)
case class B(a: Int, b: Int)
Expand Down
1 change: 0 additions & 1 deletion core/src/fr/hammons/slinc/Allocator.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.hammons.slinc

import fr.hammons.slinc.ScopeI.PlatformSpecific
import java.lang.invoke.{MethodHandle, MethodType, MethodHandles}
import fr.hammons.slinc.modules.DescriptorModule

Expand Down
2 changes: 1 addition & 1 deletion core/src/fr/hammons/slinc/Bytes.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fr.hammons.slinc

import scala.quoted.{ToExpr, Expr, Quotes}
import scala.quoted.{ToExpr, Quotes}

opaque type Bytes = Long

Expand Down
3 changes: 3 additions & 0 deletions core/src/fr/hammons/slinc/DescriptorOf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fr.hammons.slinc

import fr.hammons.slinc.container.*
import scala.quoted.*
import scala.annotation.nowarn

/** Typeclass that summons TypeDescriptors
*/
Expand Down Expand Up @@ -51,6 +52,8 @@ object DescriptorOf:
given [A]: DescriptorOf[Ptr[A]] =
ptrDescriptor.asInstanceOf[DescriptorOf[Ptr[A]]]

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
def getDescriptorFor[A](using Quotes, Type[A]) =
import quotes.reflect.*
val expr = Expr
Expand Down
6 changes: 2 additions & 4 deletions core/src/fr/hammons/slinc/Fn.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package fr.hammons.slinc

import scala.annotation.targetName
import scala.quoted.*
import scala.util.TupledFunction
import scala.annotation.experimental
import scala.util.chaining.*
import fr.hammons.slinc.modules.TransitionModule
import java.lang.invoke.TypeDescriptor
import scala.annotation.nowarn

trait Fn[F, Inputs <: Tuple, Output]:
type Function = F
Expand All @@ -28,6 +25,7 @@ object Fn:
toNativeCompatibleImpl('a)
}

@nowarn
def toNativeCompatibleImpl[A](a: Expr[A])(using Quotes, Type[A]): Expr[A] =
import quotes.reflect.*
val typeArgs = TypeRepr.of[A].typeArgs
Expand Down
7 changes: 7 additions & 0 deletions core/src/fr/hammons/slinc/FunctionDescriptor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fr.hammons.slinc
import scala.quoted.*
import fr.hammons.slinc.modules.DescriptorModule
import java.lang.invoke.MethodType
import scala.annotation.nowarn

final case class FunctionDescriptor(
inputDescriptors: Seq[TypeDescriptor],
Expand Down Expand Up @@ -41,6 +42,9 @@ final case class FunctionDescriptor(

object FunctionDescriptor:
// grabs a description of a method from its definition. Ignores Seq[Variadic] arguments.
// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
@nowarn("msg=unused local definition")
def fromDefDef(using q: Quotes)(symbol: q.reflect.Symbol) =
import quotes.reflect.*
val (inputRefs, outputType) = MacroHelpers.getInputsAndOutputType(symbol)
Expand Down Expand Up @@ -70,6 +74,9 @@ object FunctionDescriptor:
fromFunctionImpl[A]
}

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
@nowarn("msg=unused local definition")
private[slinc] def fromFunctionImpl[A](using Quotes, Type[A]) =
val (inputTypes, outputType) = MacroHelpers.getInputTypesAndOutputTypes[A]

Expand Down
13 changes: 4 additions & 9 deletions core/src/fr/hammons/slinc/JitManager.scala
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
package fr.hammons.slinc

import Fn.andThen
import scala.compiletime.uninitialized
import java.util.concurrent.atomic.AtomicReference
import scala.quoted.staging.*
import java.util.concurrent.Executors
import scala.concurrent.Promise
import java.util.concurrent.atomic.AtomicBoolean
import scala.concurrent.ExecutionContext
import scala.quoted.{Quotes, Expr}
import scala.concurrent.Future
import scala.concurrent.duration.*
import scala.util.Failure.apply
import scala.util.Failure
import java.util.concurrent.atomic.AtomicMarkableReference
import java.util.concurrent.atomic.AtomicInteger
import scala.reflect.ClassTag

type JitCompiler = [A] => ((Quotes) ?=> Expr[A]) => A
object NoJitManager extends JitManager:
def jitc[F, Input <: Tuple, Output](
override def jitc[F, Input <: Tuple, Output](
lowSpeed: F,
highSpeed: JitCompiler => F,
atomicRef: F => Unit
)(using f: Fn[F, Input, Output]): Unit = atomicRef(lowSpeed)
)(using Fn[F, Input, Output]): Unit = atomicRef(lowSpeed)

def jitNow(): Unit = ()

Expand All @@ -32,11 +27,11 @@ class InstantJitManager(compiler: Compiler) extends JitManager:
override def jitNow(): Unit = ???

given Compiler = compiler
def jitc[F, Input <: Tuple, Output](
override def jitc[F, Input <: Tuple, Output](
lowSpeed: F,
highSpeed: JitCompiler => F,
atomicRef: F => Unit
)(using f: Fn[F, Input, Output]): Unit = atomicRef(
)(using Fn[F, Input, Output]): Unit = atomicRef(
highSpeed([A] => (fn: ((Quotes) ?=> Expr[A])) => run(fn))
)
trait JitManager:
Expand Down
22 changes: 17 additions & 5 deletions core/src/fr/hammons/slinc/LibraryI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package fr.hammons.slinc

import scala.quoted.*
import java.lang.invoke.MethodHandle
import scala.annotation.nowarn
import fr.hammons.slinc.modules.TransitionModule
import scala.compiletime.asMatchable
import scala.annotation.nowarn

class LibraryI(platformSpecific: LibraryI.PlatformSpecific):
trait Library[+L]:
Expand Down Expand Up @@ -35,6 +36,8 @@ object LibraryI:
def getStandardLibLookup: Lookup
def getResourceLibLookup(location: String): Lookup

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused local definition")
def checkMethodIsCompatible(using q: Quotes)(s: q.reflect.Symbol): Unit =
import quotes.reflect.*

Expand Down Expand Up @@ -84,15 +87,16 @@ object LibraryI:

}

@nowarn
def getReturnType(using q: Quotes)(s: quotes.reflect.Symbol) =
import quotes.reflect.*
if s.isDefDef then
s.typeRef.translucentSuperType match
s.typeRef.translucentSuperType.asMatchable match
case TypeLambda(_, _, ret: LambdaType) => ret.resType
case ret: LambdaType => ret.resType
else report.errorAndAbort("This symbol isn't a method!")

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused local definition")
def needsAllocator(using q: Quotes)(s: q.reflect.Symbol): Boolean =
import quotes.reflect.*

Expand All @@ -101,6 +105,10 @@ object LibraryI:
true
case _ => false

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
@nowarn("msg=unused local definition")
@nowarn("msg=unused explicit parameter")
def bindingImpl[R, L[_] <: LibraryI#Library[?]](using q: Quotes)(using
Type[R],
Type[L]
Expand Down Expand Up @@ -160,7 +168,6 @@ object LibraryI:
$transitionModule.methodArgument($desc.descriptor, $expr, alloc)
}
}

val rTransition: Expr[Object | Null => R] = Type.of[R] match
case '[Unit] =>
'{ (obj: Object | Null) => () }.asExprOf[Object | Null => R]
Expand Down Expand Up @@ -245,6 +252,8 @@ object LibraryI:
)
code

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused local definition")
def getLibrary[L[_]](using q: Quotes)(using Type[L])(
owningClass: q.reflect.Symbol
): Expr[L[Any]] =
Expand All @@ -263,10 +272,11 @@ object LibraryI:
getLookupImpl[L]('platformSpecific)
}

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
def getLookupImpl[L](
platformSpecificExpr: Expr[PlatformSpecific]
)(using Quotes, Type[L]) =
import quotes.reflect.*
val name: LibraryLocation = LibraryName.libraryName[L]
name match
case LibraryLocation.Standardard =>
Expand All @@ -282,6 +292,8 @@ object LibraryI:
getMethodAddressImpl[L]('l)
}

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
def getMethodAddressImpl[L](l: Expr[Lookup])(using Quotes, Type[L]) =
import quotes.reflect.*

Expand Down
1 change: 0 additions & 1 deletion core/src/fr/hammons/slinc/Lookup.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.hammons.slinc

import java.nio.file.Path
import java.nio.file.Paths

trait Lookup(libraryLocation: LibraryLocation):
Expand Down
18 changes: 10 additions & 8 deletions core/src/fr/hammons/slinc/MethodHandleTools.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package fr.hammons.slinc
import scala.quoted.*
import java.lang.invoke.MethodHandle
import scala.compiletime.asMatchable
import fr.hammons.slinc.modules.DescriptorModule
import fr.hammons.slinc.modules.TransitionModule
import scala.annotation.nowarn

object MethodHandleTools:
def exprNameMapping(expr: Expr[Any])(using Quotes): String =
Expand All @@ -30,6 +30,8 @@ object MethodHandleTools:
case '[Object] => "O"
case _ => "O"

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
def invokeVariadicArguments(
mhGen: Expr[Seq[TypeDescriptor] => MethodHandle],
exprs: Expr[Seq[Any]],
Expand All @@ -42,6 +44,8 @@ object MethodHandleTools:
)
}

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
def invokeArguments[R](
mh: Expr[MethodHandle],
exprs: Seq[Expr[Any]]
Expand All @@ -52,13 +56,6 @@ object MethodHandleTools:
import quotes.reflect.*

val arity = exprs.size
val callName = (exprs.map(exprNameMapping) :+ returnMapping[R]).mkString

val mod = Symbol
.requiredPackage("fr.hammons.slinc")
.declarations
.find(_.name == s"MethodHandleArity$arity")
.map(_.companionModule)

val backupMod = TypeRepr
.of[MethodHandleFacade]
Expand Down Expand Up @@ -91,6 +88,8 @@ object MethodHandleTools:
)
)

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
def calculateMethodHandleImplementation[L](
platformExpr: Expr[LibraryI.PlatformSpecific],
addresses: Expr[IArray[Object]]
Expand Down Expand Up @@ -162,6 +161,9 @@ object MethodHandleTools:
wrappedMHImpl[A]('methodHandle)
}

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
@nowarn("msg=unused local definition")
private def wrappedMHImpl[A](
methodHandleExpr: Expr[MethodHandle]
)(using Quotes, Type[A]) =
Expand Down
11 changes: 7 additions & 4 deletions core/src/fr/hammons/slinc/Receive.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package fr.hammons.slinc

import java.lang.reflect.Modifier

import scala.annotation.targetName
import scala.quoted.*
import scala.compiletime.{erasedValue, summonInline}
import scala.util.chaining.*
import scala.deriving.Mirror
import container.{ContextProof, *:::, End}
import fr.hammons.slinc.modules.DescriptorModule
import scala.annotation.nowarn

class ReceiveI(val libraryPs: LibraryI.PlatformSpecific):
@nowarn("msg=unused implicit parameter")
inline given fnReceive[A](using Fn[A, ?, ?]): Receive[A] =
new Receive[A]:
def from(mem: Mem, offset: Bytes): A =
override def from(mem: Mem, offset: Bytes): A =
val descriptor = FunctionDescriptor.fromFunction[A]

MethodHandleTools.wrappedMH[A](
Expand Down Expand Up @@ -81,6 +80,8 @@ object Receive:
}(transformsArray).asInstanceOf[Receive[A]]
end staged

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused implicit parameter")
private def stagedHelper(
layout: TypeDescriptor,
transformIndices: Map[String, Int],
Expand Down Expand Up @@ -139,6 +140,8 @@ object Receive:
.flatMap(getTransforms)
case _ => Seq.empty

// todo: get rid of this once bug https://github.com/lampepfl/dotty/issues/16863 is fixed
@nowarn("msg=unused local definition")
private def constructFromTarget(clazz: Class[?], members: List[Expr[Any]])(
using Quotes
) =
Expand Down
2 changes: 2 additions & 0 deletions core/src/fr/hammons/slinc/Scope.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.hammons.slinc

import scala.annotation.experimental

sealed trait Scope:
def apply[A](fn: Allocator ?=> A): A

Expand Down
Loading

0 comments on commit 09a719b

Please sign in to comment.