Skip to content

Commit

Permalink
Merge branch 'comprof'
Browse files Browse the repository at this point in the history
  • Loading branch information
ghik committed Oct 11, 2018
2 parents 2caae61 + d32c023 commit c9a3b44
Show file tree
Hide file tree
Showing 29 changed files with 423 additions and 298 deletions.
49 changes: 44 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ val commonSettings = Seq(
"-Xfatal-warnings",
s"-Xlint:-missing-interpolator,-adapted-args,${if (scalaBinaryVersion.value == "2.12") "-unused," else ""}_",
),
scalacOptions ++= {
if (scalaBinaryVersion.value == "2.12") Seq(
"-Ycache-plugin-class-loader:last-modified",
"-Ycache-macro-class-loader:last-modified",
) else Seq.empty
},
// some Java 8 related tests use Java interface static methods, Scala 2.11.12 requires JDK8 target for that
scalacOptions in Test ++= (if (scalaBinaryVersion.value == "2.11") Seq("-target:jvm-1.8") else Seq()),
scalacOptions in Test ++= (if (scalaBinaryVersion.value == "2.11") Seq("-target:jvm-1.8") else Nil),
apiURL := Some(url("http://avsystem.github.io/scala-commons/api")),
autoAPIMappings := true,

Expand Down Expand Up @@ -131,19 +137,20 @@ val CompileAndTest = "compile->compile;test->test"
lazy val commons = project.in(file("."))
.enablePlugins(ScalaUnidocPlugin)
.aggregate(
`commons-analyzer`,
`commons-macros`,
`commons-annotations`,
`commons-annotations-js`,
`commons-macros`,
`commons-core`,
`commons-core-js`,
`commons-analyzer`,
`commons-jetty`,
`commons-benchmark`,
`commons-mongo`,
`commons-spring`,
`commons-redis`,
`commons-akka`,
`commons-kafka`,
`commons-benchmark`,
`commons-benchmark-js`,
)
.settings(
commonSettings,
Expand All @@ -159,6 +166,7 @@ lazy val commons = project.in(file("."))
`commons-core-js`,
`commons-benchmark`,
`commons-benchmark-js`,
`commons-comprof`,
),
)

Expand Down Expand Up @@ -285,7 +293,10 @@ lazy val `commons-benchmark-js` = project.in(`commons-benchmark`.base / "js")
"com.lihaoyi" %%% "upickle" % upickleVersion,
"com.github.japgolly.scalajs-benchmark" %%% "benchmark" % scalajsBenchmarkVersion,
),
scalaJSUseMainModuleInitializer := true
scalaJSUseMainModuleInitializer := true,
test := {},
testOnly := {},
testQuick := {},
)

lazy val `commons-mongo` = project
Expand Down Expand Up @@ -344,3 +355,31 @@ lazy val `commons-akka` = project
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test,
),
)

lazy val `commons-comprof` = project
.dependsOn(`commons-core`)
.settings(
jvmCommonSettings,
noPublishSettings,
ideSkipProject := true,
addCompilerPlugin("ch.epfl.scala" %% "scalac-profiling" % "1.0.0"),
scalacOptions ++= Seq(
s"-P:scalac-profiling:sourceroot:${baseDirectory.value}",
"-P:scalac-profiling:generate-macro-flamegraph",
"-P:scalac-profiling:no-profiledb",
"-Xmacro-settings:statsEnabled",
"-Ystatistics:typer",
),
sourceGenerators in Compile += Def.task {
val originalSrc = (sourceDirectory in `commons-core`).value /
"test/scala/com/avsystem/commons/rest/RestTestApi.scala"
val originalContent = IO.read(originalSrc)
(0 until 100).map { i =>
val pkg = f"oa$i%02d"
val newContent = originalContent.replaceAllLiterally("package rest", s"package rest\npackage $pkg")
val newFile = (sourceManaged in Compile).value / pkg / "RestTestApi.scala"
IO.write(newFile, newContent)
newFile
}
}.taskValue
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,26 @@ case class AnnotationsOf[A, T](annots: List[A]) extends AnyVal
object AnnotationsOf {
implicit def materialize[A, T]: AnnotationsOf[A, T] = macro macros.misc.MiscMacros.annotationsOf[A, T]
}

final class HasAnnotation[A, T]
object HasAnnotation {
private[this] val reusable = new HasAnnotation
def create[A, T]: HasAnnotation[A, T] = reusable.asInstanceOf

implicit def materialize[A, T]: AnnotationsOf[A, T] = macro macros.misc.MiscMacros.hasAnnotation[A, T]
}

case class SelfAnnotation[A](annot: A) extends AnyVal
object SelfAnnotation {
implicit def materialize[A]: SelfAnnotation[A] = macro macros.misc.MiscMacros.selfAnnotation[A]
}

case class SelfOptAnnotation[A](annotOpt: Opt[A])
object SelfOptAnnotationOf {
implicit def materialize[A]: SelfOptAnnotation[A] = macro macros.misc.MiscMacros.selfOptAnnotation[A]
}

case class SelfAnnotations[A](annots: List[A]) extends AnyVal
object SelfAnnotations {
implicit def materialize[A]: SelfAnnotations[A] = macro macros.misc.MiscMacros.selfAnnotations[A]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ trait RPCFramework {
type RawRPC
val RawRPC: BaseRawRpcCompanion

trait BaseRawRpcCompanion extends RawRpcCompanion[RawRPC] {
override val implicits: RPCFramework.this.type = RPCFramework.this
}
trait BaseRawRpcCompanion extends RawRpcCompanion[RawRPC]

def read[T: Reader](raw: RawValue): T
def write[T: Writer](value: T): RawValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.avsystem.commons.macros.rpc.RpcMacros
/**
* Base trait for companion objects of raw RPC traits.
*/
trait RawRpcCompanion[Raw] extends RpcImplicitsProvider {
trait RawRpcCompanion[Raw] {
type AsRawRpc[Real] = AsRaw[Raw, Real]
type AsRealRpc[Real] = AsReal[Raw, Real]
type AsRawRealRpc[Real] = AsRawReal[Raw, Real]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ package rpc
import com.avsystem.commons.macros.rpc.RpcMacros
import com.avsystem.commons.meta.MetadataCompanion

trait RpcMetadataCompanion[M[_]] extends MetadataCompanion[M] with RpcImplicitsProvider {
trait RpcMetadataCompanion[M[_]] extends MetadataCompanion[M] {
def materialize[Real]: M[Real] = macro RpcMacros.rpcMetadata[Real]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ import org.scalatest.FunSuite

import scala.annotation.StaticAnnotation

class genann[T](val value: T) extends StaticAnnotation
class genagg[T](value: T) extends AnnotationAggregate {
case class genann[T](value: T) extends StaticAnnotation
case class genagg[T](value: T) extends AnnotationAggregate {
@genann(value) type Implied
}

@genagg(42)
class Subject

abstract class SelfAnnots(implicit val annots: SelfAnnotations[genann[_]])
@genagg(42) @genann("fuu") class Klass extends SelfAnnots
@genagg(42) @genann("fuu") object Objekt extends SelfAnnots

class AnnotationOfTest extends FunSuite {
test("aggregate with generic") {
assert(AnnotationOf.materialize[genann[Int], Subject].annot.value == 42)
}

test("self annotations") {
assert(new Klass().annots.annots == List(genann(42), genann("fuu")))
assert(Objekt.annots.annots == List(genann(42), genann("fuu")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object FlatBaseEntity extends RestDataCompanion[FlatBaseEntity]
@description("REST entity")
case class RestEntity(
@description("entity id") id: String,
@whenAbsent("anonymous") name: String = whenAbsent.debugMacro.value,
@whenAbsent("anonymous") name: String = whenAbsent.value,
@description("recursive optional subentity") subentity: OptArg[RestEntity] = OptArg.Empty
) extends FlatBaseEntity
object RestEntity extends RestDataCompanion[RestEntity]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ trait NewRawRpc {
@multi def prefix(@methodName name: String): NewRawRpc
}
object NewRawRpc extends RawRpcCompanion[NewRawRpc] {
override val implicits: this.type = this

implicit def asRawRealFromGenCodec[T: GenCodec]: AsRawReal[String, T] = ???
implicit def futureAsRawRealFromGenCodec[T: GenCodec]: AsRawReal[Future[String], Future[T]] = ???
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ trait TestApi extends SomeBase {
def postit(arg: String, bar: String, int: Int, @suchMeta(3, "c") foo: String): String
}
object TestApi {
import NewRawRpc._
implicit val asRawReal: NewRawRpc.AsRawRealRpc[TestApi] = NewRawRpc.materializeAsRawReal[TestApi]
implicit val metadata: NewRpcMetadata[TestApi] = NewRpcMetadata.materialize[TestApi]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class mongoId extends AnnotationAggregate {

@flatten sealed trait FlatSealedBase {
@mongoId def id: String
@generated
@name("upper_id") def upperId: String = id.toUpperCase
@generated @name("upper_id") def upperId: String = id.toUpperCase
}
object FlatSealedBase extends HasGenCodec[FlatSealedBase] {
case class FirstCase(id: String, int: Int = 42) extends FlatSealedBase
Expand Down
Loading

0 comments on commit c9a3b44

Please sign in to comment.