Skip to content

Commit

Permalink
Merge pull request #554 from AVSystem/xsource3
Browse files Browse the repository at this point in the history
Use -xsource:3
  • Loading branch information
ddworak authored Mar 19, 2024
2 parents 03fa117 + 098d9fb commit 6af67c8
Show file tree
Hide file tree
Showing 21 changed files with 81 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ final class AnalyzerPlugin(val global: Global) extends Plugin { plugin =>

import global._

def newPhase(prev: Phase) = new StdPhase(prev) {
def newPhase(prev: Phase): StdPhase = new StdPhase(prev) {
def apply(unit: CompilationUnit): Unit =
rules.foreach(rule => if (rule.level != Level.Off) rule.analyze(unit.asInstanceOf[rule.global.CompilationUnit]))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.avsystem.commons
package mongo

import java.nio.ByteBuffer
import com.avsystem.commons.ser.{Nested, Toplevel}

import com.avsystem.commons.rpc.akka.serialization.{Nested, Something}
import java.nio.ByteBuffer
import org.bson.codecs.{BsonDocumentCodec, DecoderContext, EncoderContext}
import org.bson.io.BasicOutputBuffer
import org.bson.{BsonArray, BsonBinaryReader, BsonBinaryWriter, BsonDocument, BsonInt32, BsonString}
Expand All @@ -18,11 +18,11 @@ class BsonCodecBenchmark {

import BsonCodecBenchmark._

private val something = Something(42, Nested(List(4, 8, 15, 16, 23, 42, 0), 131), "lol")
private val something = Toplevel(42, Nested(List(4, 8, 15, 16, 23, 42, 0), 131), "lol")
private val doc = somethingCodec.toDocument(something)
private val bytes = binaryEncode(something)

def binaryEncode(something: Something): Array[Byte] = {
def binaryEncode(something: Toplevel): Array[Byte] = {
val output = new BasicOutputBuffer()
val writer = new BsonBinaryWriter(output)
val doc = somethingCodec.toDocument(something)
Expand All @@ -36,7 +36,7 @@ class BsonCodecBenchmark {
}

@Benchmark
def binaryDecoding(): Something = {
def binaryDecoding(): Toplevel = {
val reader = new BsonBinaryReader(ByteBuffer.wrap(bytes))
val doc = bsonDocumentCodec.decode(reader, DecoderContext.builder().build())
somethingCodec.fromDocument(new Doc(doc))
Expand All @@ -48,7 +48,7 @@ class BsonCodecBenchmark {
}

@Benchmark
def decoding(): Something = {
def decoding(): Toplevel = {
somethingCodec.fromDocument(doc)
}
}
Expand Down Expand Up @@ -76,13 +76,13 @@ object BsonCodecBenchmark {

val nestedKey: DocKey[Nested, BsonDocument] = nestedCodec.bsonCodec.key("nested")

val somethingCodec = new DocumentCodec[Something] {
override def toDocument(t: Something): Doc = Doc()
val somethingCodec = new DocumentCodec[Toplevel] {
override def toDocument(t: Toplevel): Doc = Doc()
.put(intKey, t.int)
.put(nestedKey, t.nested)
.put(strKey, t.str)

override def fromDocument(doc: Doc): Something = Something(
override def fromDocument(doc: Doc): Toplevel = Toplevel(
int = doc.require(intKey),
nested = doc.require(nestedKey),
str = doc.require(strKey)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.avsystem.commons
package mongo

import com.avsystem.commons.ser.{Nested, Toplevel}

import java.io.StringWriter
import java.nio.ByteBuffer

import com.avsystem.commons.rpc.akka.serialization.{Nested, Something}
import org.bson.io.BasicOutputBuffer
import org.bson.json.{JsonReader, JsonWriter}
import org.bson.{BsonBinaryReader, BsonBinaryWriter, BsonDocument, BsonDocumentReader, BsonDocumentWriter, BsonReader, BsonValue, BsonWriter}
Expand All @@ -16,29 +16,29 @@ import org.openjdk.jmh.annotations.{Benchmark, BenchmarkMode, Fork, Measurement,
@BenchmarkMode(Array(Mode.Throughput))
@State(Scope.Thread)
class BsonInputOutputBenchmark {
private val something = Something(42, Nested(List(4, 8, 15, 16, 23, 42, 0), 131), "lol")
private val something = Toplevel(42, Nested(List(4, 8, 15, 16, 23, 42, 0), 131), "lol")
private val bytes = binaryEncode(something)
private val doc = documentEncode(something)
private val json = jsonEncode(something)

def write(something: Something, bsonWriter: BsonWriter): Unit = {
def write(something: Toplevel, bsonWriter: BsonWriter): Unit = {
val output = new BsonWriterOutput(bsonWriter)
Something.codec.write(output, something)
Toplevel.codec.write(output, something)
}

def binaryEncode(something: Something): Array[Byte] = {
def binaryEncode(something: Toplevel): Array[Byte] = {
val bsonOutput = new BasicOutputBuffer()
write(something, new BsonBinaryWriter(bsonOutput))
bsonOutput.toByteArray
}

def documentEncode(something: Something): BsonDocument = {
def documentEncode(something: Toplevel): BsonDocument = {
val doc = new BsonDocument()
write(something, new BsonDocumentWriter(doc))
doc
}

def jsonEncode(something: Something): String = {
def jsonEncode(something: Toplevel): String = {
val stringWriter = new StringWriter()
write(something, new JsonWriter(stringWriter))
stringWriter.toString
Expand All @@ -64,23 +64,23 @@ class BsonInputOutputBenchmark {
BsonValueOutput.write(something)
}

def read(bsonReader: BsonReader): Something = {
def read(bsonReader: BsonReader): Toplevel = {
val input = new BsonReaderInput(bsonReader)
Something.codec.read(input)
Toplevel.codec.read(input)
}

@Benchmark
def binaryDecoding(): Something = {
def binaryDecoding(): Toplevel = {
read(new BsonBinaryReader(ByteBuffer.wrap(bytes)))
}

@Benchmark
def documentDecoding(): Something = {
def documentDecoding(): Toplevel = {
read(new BsonDocumentReader(doc))
}

@Benchmark
def jsonDecoding(): Something = {
def jsonDecoding(): Toplevel = {
read(new JsonReader(json))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,28 @@ class SimpleValueOutput(
def this(consumer: Any => Unit) =
this(consumer, new MHashMap[String, Any], new ListBuffer[Any])

def writeNull(): Unit = consumer(null)
def writeBoolean(boolean: Boolean): Unit = consumer(boolean)
def writeString(str: String): Unit = consumer(str)
def writeInt(int: Int): Unit = consumer(int)
def writeLong(long: Long): Unit = consumer(long)
def writeDouble(double: Double): Unit = consumer(double)
def writeBigInt(bigInt: BigInt): Unit = consumer(bigInt)
def writeBigDecimal(bigDecimal: BigDecimal): Unit = consumer(bigDecimal)
def writeBinary(binary: Array[Byte]): Unit = consumer(binary)
override def writeNull(): Unit = consumer(null)
override def writeBoolean(boolean: Boolean): Unit = consumer(boolean)
override def writeString(str: String): Unit = consumer(str)
override def writeInt(int: Int): Unit = consumer(int)
override def writeLong(long: Long): Unit = consumer(long)
override def writeDouble(double: Double): Unit = consumer(double)
override def writeBigInt(bigInt: BigInt): Unit = consumer(bigInt)
override def writeBigDecimal(bigDecimal: BigDecimal): Unit = consumer(bigDecimal)
override def writeBinary(binary: Array[Byte]): Unit = consumer(binary)

def writeList(): ListOutput = new ListOutput {
private val buffer = newListRepr
override def declareSize(size: Int): Unit = buffer.sizeHint(size)
def writeElement() = new SimpleValueOutput(buffer += _, newObjectRepr, newListRepr)
def finish(): Unit = consumer(buffer.result())
override def writeElement(): SimpleValueOutput = new SimpleValueOutput(buffer += _, newObjectRepr, newListRepr)
override def finish(): Unit = consumer(buffer.result())
}

def writeObject(): ObjectOutput = new ObjectOutput {
private val result = newObjectRepr
override def declareSize(size: Int): Unit = result.sizeHint(size)
def writeField(key: String) = new SimpleValueOutput(v => result += ((key, v)), newObjectRepr, newListRepr)
def finish(): Unit = consumer(result)
override def writeField(key: String): SimpleValueOutput = new SimpleValueOutput(v => result += ((key, v)), newObjectRepr, newListRepr)
override def finish(): Unit = consumer(result)
}
}

Expand All @@ -95,15 +95,15 @@ class SimpleValueInput(value: Any) extends InputAndSimpleInput {
case _ => throw new ReadFailure(s"Expected ${classTag[B].runtimeClass} but got ${value.getClass}")
}

def readNull(): Boolean = value == null
def readBoolean(): Boolean = doReadUnboxed[Boolean, JBoolean]
def readString(): String = doRead[String]
def readInt(): Int = doReadUnboxed[Int, JInteger]
def readLong(): Long = doReadUnboxed[Long, JLong]
def readDouble(): Double = doReadUnboxed[Double, JDouble]
def readBigInt(): BigInt = doRead[JBigInteger]
def readBigDecimal(): BigDecimal = doRead[JBigDecimal]
def readBinary(): Array[Byte] = doRead[Array[Byte]]
override def readNull(): Boolean = value == null
override def readBoolean(): Boolean = doReadUnboxed[Boolean, JBoolean]
override def readString(): String = doRead[String]
override def readInt(): Int = doReadUnboxed[Int, JInteger]
override def readLong(): Long = doReadUnboxed[Long, JLong]
override def readDouble(): Double = doReadUnboxed[Double, JDouble]
override def readBigInt(): BigInt = doRead[JBigInteger]
override def readBigDecimal(): BigDecimal = doRead[JBigDecimal]
override def readBinary(): Array[Byte] = doRead[Array[Byte]]

def readObject(): ObjectInput =
new ObjectInput {
Expand All @@ -112,22 +112,22 @@ class SimpleValueInput(value: Any) extends InputAndSimpleInput {
case (k, v) => new SimpleValueFieldInput(k, v)
}
override def knownSize: Int = if(map.isEmpty) 0 else map.knownSize
def nextField(): SimpleValueFieldInput = it.next()
override def nextField(): SimpleValueFieldInput = it.next()
override def peekField(name: String): Opt[SimpleValueFieldInput] =
map.get(name).map(new SimpleValueFieldInput(name, _)).toOpt // values may be null!
def hasNext: Boolean = it.hasNext
override def hasNext: Boolean = it.hasNext
}

def readList(): ListInput =
new ListInput {
private val inputSeq: BSeq[Any] = doRead[BSeq[Any]]
private val it = inputSeq.iterator.map(new SimpleValueInput(_))
override def knownSize: Int = if(inputSeq.isEmpty) 0 else inputSeq.knownSize
def nextElement(): SimpleValueInput = it.next()
def hasNext: Boolean = it.hasNext
override def nextElement(): SimpleValueInput = it.next()
override def hasNext: Boolean = it.hasNext
}

def skip(): Unit = ()
override def skip(): Unit = ()
}

class SimpleValueFieldInput(val fieldName: String, value: Any)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ObservableExtensionsTest extends AnyFunSuite with Matchers
private implicit val scheduler: Scheduler = Scheduler(RunNowEC)

test("headOptL") {
forAll { ints: List[Int] =>
forAll { (ints: List[Int]) =>
Observable.fromIterable(ints).headOptL.runToFuture.futureValue shouldBe ints.headOpt
}
}
Expand All @@ -26,7 +26,7 @@ class ObservableExtensionsTest extends AnyFunSuite with Matchers
}

test("findOptL") {
forAll { ints: List[Int] =>
forAll { (ints: List[Int]) =>
Observable.fromIterable(ints).findOptL(_ > 1).runToFuture.futureValue shouldBe ints.findOpt(_ > 1)
}
}
Expand All @@ -38,13 +38,13 @@ class ObservableExtensionsTest extends AnyFunSuite with Matchers
}

test("distinct") {
forAll { ints: List[Int] =>
forAll { (ints: List[Int]) =>
Observable.fromIterable(ints).distinct.toListL.runToFuture.futureValue shouldBe ints.distinct
}
}

test("distinctBy") {
forAll { ints: List[Int] =>
forAll { (ints: List[Int]) =>
val f: Int => Int = _ % 256

Observable.fromIterable(ints).distinctBy(f).toListL.runToFuture.futureValue shouldBe
Expand All @@ -53,20 +53,20 @@ class ObservableExtensionsTest extends AnyFunSuite with Matchers
}

test("sortedL") {
forAll { ints: List[Int] =>
forAll { (ints: List[Int]) =>
Observable.fromIterable(ints).sortedL.runToFuture.futureValue shouldBe ints.sorted
}
}

test("sortedByL") {
forAll { ints: List[Int] =>
forAll { (ints: List[Int]) =>
val f: Int => Int = _ % 256
Observable.fromIterable(ints).sortedByL(f).runToFuture.futureValue shouldBe ints.sortBy(f)
}
}

test("toL") {
forAll { ints: List[(Int, Int)] =>
forAll { (ints: List[(Int, Int)]) =>
def testFactory[T](factory: Factory[(Int, Int), T])(implicit position: Position) =
Observable.fromIterable(ints).toL(factory).runToFuture.futureValue shouldBe factory.fromSpecific(ints)

Expand Down Expand Up @@ -100,7 +100,7 @@ class ObservableExtensionsTest extends AnyFunSuite with Matchers
}

test("mkMapL") {
forAll { ints: List[Int] =>
forAll { (ints: List[Int]) =>
Observable.fromIterable(ints).mkMapL(_ % 3, _ + 2).runToFuture.futureValue shouldBe ints.mkMap(_ % 3, _ + 2)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TaskExtensionsTest extends AnyFunSuite with Matchers with ScalaCheckDriven
}

test("traverseMap") {
forAll { data: List[(String, Int)] =>
forAll { (data: List[(String, Int)]) =>
val map = data.toMap
val expected = map.view.map({ case (key, value) => (key + key, value + 2) }).toMap
val result = Task.traverseMap(map)({ case (key, value) => Task((key + key, value + 2)) }).runToFuture.futureValue
Expand All @@ -33,7 +33,7 @@ class TaskExtensionsTest extends AnyFunSuite with Matchers with ScalaCheckDriven
}

test("traverseMapValues") {
forAll { data: List[(String, Int)] =>
forAll { (data: List[(String, Int)]) =>
val map = data.toMap
val expected = map.view.mapValues(value => value + 2).toMap
val result = Task.traverseMapValues(map)({ case (key, value) => Task(value + 2) }).runToFuture.futureValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IsoInstantTest extends AnyFunSuite with ScalaCheckPropertyChecks {

test("roundtrip") {
val genTstamp = Gen.choose[Long](-(1L << 50), 1L << 50)
forAll(genTstamp) { l: Long =>
forAll(genTstamp) { (l: Long) =>
assert(IsoInstant.parse(IsoInstant.format(l)) == l)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class JsonStringInputOutputTest extends AnyFunSuite with SerializationTestUtils
}

test("serialize all types") {
forAll { item: CompleteItem =>
forAll { (item: CompleteItem) =>
val serialized = write(item)
val deserialized = read[CompleteItem](serialized)

Expand Down Expand Up @@ -363,7 +363,7 @@ class JsonStringInputOutputTest extends AnyFunSuite with SerializationTestUtils
Gen.sized(sz => sized(math.min(sz, 1)))
}

forAll { dncc: DeepNestedTestCC =>
forAll { (dncc: DeepNestedTestCC) =>
val serialized = write(dncc)
val deserialized = read[DeepNestedTestCC](serialized)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class JettyRPCFrameworkTest extends AnyFunSuite with ScalaFutures with Matchers
val impl: SomeApi = new SomeApi {
override def keks: Future[Long] = Future.successful(keksResult)
override def isTop(keks: Long): Future[Boolean] = Future.successful(keks == Int.MaxValue)
override val topper = new TopperImpl("%s", topKeksResult)
override val topper: TopperImpl = new TopperImpl("%s", topKeksResult)
override def differentTopper(helloPattern: String): Topper = new TopperImpl(helloPattern, topKeksResult)
override def erroneousKeks: Future[Int] = Future.failed(new RuntimeException("cannot into"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ case class CustomWrappy(value: String)

object CustomImplicits {
implicit val customWrappyCodec: GenCodec[CustomWrappy] =
GenCodec.transformed[CustomWrappy, String](_.value, CustomWrappy)
GenCodec.transformed[CustomWrappy, String](_.value, CustomWrappy.apply)
}

abstract class CustomPolyDataCompanion[D[_]](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

class BigDecimalEncodingTest extends AnyFunSuite with ScalaCheckPropertyChecks {
test("BigDecimal BSON encoding") {
forAll { value: BigDecimal =>
forAll { (value: BigDecimal) =>
assert(value == BsonInput.bigDecimalFromBytes(BsonOutput.bigDecimalBytes(value)))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

class Decimal128UtilsTest extends AnyFunSuite with ScalaCheckPropertyChecks {
test("Decimal128Utils.fromBigDecimal is equivalent to new Decimal128") {
forAll(Arbitrary.arbitrary[BigDecimal]) { bd: BigDecimal =>
forAll(Arbitrary.arbitrary[BigDecimal]) { (bd: BigDecimal) =>
val usingUtils = Decimal128Utils.fromBigDecimal(bd)
val usingConstructor = try new Decimal128(bd.bigDecimal).opt catch {
case _: NumberFormatException => Opt.Empty
Expand Down
1 change: 1 addition & 0 deletions project/Commons.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ object Commons extends ProjectGroup("commons") {
"-language:experimental.macros",
"-language:higherKinds",
"-Xfatal-warnings",
"-Xsource:3",
"-Xlint:-missing-interpolator,-adapted-args,-unused,_",
"-Ycache-plugin-class-loader:last-modified",
"-Ycache-macro-class-loader:last-modified",
Expand Down
Loading

0 comments on commit 6af67c8

Please sign in to comment.