Skip to content

Commit

Permalink
Use 3.3.0 lts compiler version instead of nightly (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
susliko authored Feb 26, 2024
1 parent 6955290 commit 5305259
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
os: [ubuntu-latest]
# FIXME Use stable scala version
scala: [2.13.12, 3.3.1-RC1-bin-20230318-7226ba6-NIGHTLY]
scala: [2.13.12, 3.3.0]

steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ out
gpg.sbt

modules/**/target
*/jmh-result.json
*/jmh-result.json

.metals
.bloop
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ lazy val scala213 = "2.13.12"
Return to use a stable version when 'scala.quoted.Quotes.reflectModuleSymbol.newClass'
and 'scala.quoted.Quotes.reflectModule.ClassDef.apply' are no longer experimental methods
*/
lazy val scala3 = "3.3.1-RC1-bin-20230318-7226ba6-NIGHTLY"
lazy val scala3 = "3.3.0"

ThisBuild / scalaVersion := scala3

lazy val commonSettings = Seq(
version := "0.28.1",
version := "0.28.2",
organization := "com.tethys-json",
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
homepage := Some(url("https://github.com/tethys-json/tethys")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import scala.quoted.*
import tethys.{JsonObjectWriter, JsonReader}
import tethys.commons.LowPriorityInstance
import tethys.derivation.impl.derivation.AutoDerivationMacro
import scala.annotation.experimental

trait AutoDerivation {
implicit inline def jsonWriterMaterializer[T]: LowPriorityInstance[JsonObjectWriter[T]] =
Expand All @@ -15,9 +16,11 @@ trait AutoDerivation {
}

private[this] object AutoDerivation {
@experimental
def jsonWriterMaterializer[T: Type](using Quotes): Expr[LowPriorityInstance[JsonObjectWriter[T]]] =
new AutoDerivationMacro(quotes).simpleJsonWriter[T]

@experimental
def jsonReaderMaterializer[T: Type](using Quotes): Expr[LowPriorityInstance[JsonReader[T]]] =
new AutoDerivationMacro(quotes).simpleJsonReader[T]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import tethys.derivation.impl.builder.{ReaderDescriptionMacro, WriterDescription
import tethys.derivation.impl.derivation.SemiautoDerivationMacro
import scala.quoted.*
import scala.annotation.compileTimeOnly
import scala.annotation.experimental

trait SemiautoDerivation {
inline def jsonWriter[T]: JsonObjectWriter[T] =
Expand Down Expand Up @@ -59,25 +60,31 @@ trait SemiautoDerivation {
}

private[this] object SemiautoDerivation {
@experimental
def jsonWriter[T: Type](using Quotes): Expr[JsonObjectWriter[T]] =
new SemiautoDerivationMacro(quotes).simpleJsonWriter[T]

@experimental
def jsonWriterWithConfig[T: Type](config: Expr[WriterDerivationConfig])(using Quotes): Expr[JsonObjectWriter[T]] =
new SemiautoDerivationMacro(quotes).jsonWriterWithConfig[T](config)

@experimental
def jsonWriterWithDescription[T: Type](description: Expr[WriterDescription[T]])(using
Quotes
): Expr[JsonObjectWriter[T]] =
new SemiautoDerivationMacro(quotes).jsonWriterWithWriterDescription[T](description)

@experimental
def jsonWriterWithBuilder[T <: Product: Type](builder: Expr[WriterBuilder[T]])(using
Quotes
): Expr[JsonObjectWriter[T]] =
new SemiautoDerivationMacro(quotes).jsonWriterWithBuilder[T](builder)

@experimental
def describeWriter[T <: Product: Type](builder: Expr[WriterBuilder[T]])(using Quotes): Expr[WriterDescription[T]] =
new WriterDescriptionMacro(quotes).simpleDescription[T](builder)

@experimental
def jsonReader[T: Type](using Quotes): Expr[JsonReader[T]] =
new SemiautoDerivationMacro(quotes).simpleJsonReader[T]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import scala.quoted.*
import tethys.{JsonObjectWriter, JsonReader, JsonWriter}
import tethys.commons.LowPriorityInstance
import tethys.writers.tokens.TokenWriter
import scala.annotation.experimental

class AutoDerivationMacro(val quotes: Quotes)
extends WriterDerivation
Expand All @@ -13,6 +14,7 @@ class AutoDerivationMacro(val quotes: Quotes)
import context.reflect.*

// TODO: recursive A => B => A derivation check
@experimental
def simpleJsonWriter[T: Type]: Expr[LowPriorityInstance[JsonObjectWriter[T]]] = {
val tpe: TypeRepr = TypeRepr.of[T]
val tpeSym: Symbol = tpe.typeSymbol
Expand All @@ -35,6 +37,7 @@ class AutoDerivationMacro(val quotes: Quotes)
'{ LowPriorityInstance[JsonObjectWriter[T]]($jsonObjectWriterExpr) }
}

@experimental
def simpleJsonReader[T: Type]: Expr[LowPriorityInstance[JsonReader[T]]] = {
val tpe: TypeRepr = TypeRepr.of[T]
val tpeSym: Symbol = tpe.typeSymbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import tethys.readers.{FieldName, ReaderError}
import tethys.readers.tokens.TokenIterator
import tethys.{JsonObjectWriter, JsonReader, JsonWriter}
import tethys.writers.tokens.TokenWriter
import scala.annotation.experimental

class SemiautoDerivationMacro(val quotes: Quotes) extends WriterDerivation with ReaderDerivation {
implicit val context: Quotes = quotes
import context.reflect.*

@experimental
def simpleJsonWriter[T: Type]: Expr[JsonObjectWriter[T]] =
jsonWriterWithMacroWriteDescription[T](MacroWriteDescription.empty[T])

@experimental
def jsonWriterWithConfig[T: Type](config: Expr[WriterDerivationConfig]): Expr[JsonObjectWriter[T]] = {
val tpe = TypeRepr.of[T]

Expand All @@ -28,6 +31,7 @@ class SemiautoDerivationMacro(val quotes: Quotes) extends WriterDerivation with
jsonWriterWithMacroWriteDescription[T](description)
}

@experimental
def jsonWriterWithMacroWriteDescription[T: Type](description: MacroWriteDescription): Expr[JsonObjectWriter[T]] = {
val tpe = TypeRepr.of[T]

Expand All @@ -46,11 +50,13 @@ class SemiautoDerivationMacro(val quotes: Quotes) extends WriterDerivation with
else deriveTermWriter[T]
}

@experimental
def jsonWriterWithBuilder[T <: Product: Type](builder: Expr[WriterBuilder[T]]): Expr[JsonObjectWriter[T]] = {
val description = convertWriterBuilder[T](builder)
jsonWriterWithWriterDescription[T](description)
}

@experimental
def jsonWriterWithWriterDescription[T: Type](description: Expr[WriterDescription[T]]): Expr[JsonObjectWriter[T]] = {
val tpe = TypeRepr.of[T]
val tpeSym = tpe.typeSymbol
Expand All @@ -59,6 +65,7 @@ class SemiautoDerivationMacro(val quotes: Quotes) extends WriterDerivation with
else report.errorAndAbort(s"Can't derive json writer! ${tpe.show} isn't a Case Class")
}

@experimental
def simpleJsonReader[T: Type]: Expr[JsonReader[T]] = {
val description = MacroReaderDescription(
config = emptyReaderConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import tethys.derivation.impl.builder.{WriterBuilderCommons, WriterBuilderUtils}
import tethys.derivation.impl.FieldStyle
import tethys.writers.tokens.{SimpleTokenWriter, TokenWriter}
import tethys.{JsonObjectWriter, JsonWriter}
import scala.annotation.experimental

trait WriterDerivation extends WriterBuilderCommons {
import context.reflect.*

// ---------------------------------- CASE CLASS ----------------------------------
@experimental
def deriveCaseClassWriter[T: Type](
description: MacroWriteDescription
): Expr[JsonObjectWriter[T]] = {
Expand Down Expand Up @@ -58,6 +60,7 @@ trait WriterDerivation extends WriterBuilderCommons {
}
}

@experimental
private def createDerivedWriterExpr[T: Type](
clsSym: Symbol,
clsParents: List[Tree],
Expand Down Expand Up @@ -124,6 +127,7 @@ trait WriterDerivation extends WriterBuilderCommons {
case (rest, _) => rest
}

@experimental
private def createCaseClassWriterTerms(tpes: List[TypeRepr]): List[(TypeRepr, Term)] =
tpes.map {
_.asType match {
Expand Down Expand Up @@ -305,6 +309,7 @@ trait WriterDerivation extends WriterBuilderCommons {
}

// -------------------- SEALED (TRAIT | ABSTRACT CLASS) OR ENUM -------------------
@experimental
def deriveSealedClassWriter[T: Type](
cfg: Expr[WriterDerivationConfig]
): Expr[JsonObjectWriter[T]] = {
Expand Down Expand Up @@ -477,6 +482,7 @@ trait WriterDerivation extends WriterBuilderCommons {
}

// ------------------------------------ COMMON ------------------------------------
@experimental
private def createClsSym(tpe: TypeRepr, declsFn: Symbol => List[Symbol]): Symbol =
Symbol.newClass(
parent = Symbol.spliceOwner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import scala.deriving.Mirror

import tethys.{JsonObjectWriter, JsonReader, JsonWriter}
import tethys.derivation.semiauto.{jsonReader, jsonWriter}
import scala.annotation.experimental

package object derivation {
extension (underlying: JsonReader.type) {
@experimental
inline def derived[T](using Mirror.Of[T]): JsonReader[T] = jsonReader[T]
}

extension (underlying: JsonWriter.type) {
@experimental
inline def derived[T](using Mirror.Of[T]): JsonWriter[T] = jsonWriter[T]
}

extension (underlying: JsonObjectWriter.type) {
@experimental
inline def derived[T](using Mirror.Of[T]): JsonObjectWriter[T] = jsonWriter[T]
}
}

0 comments on commit 5305259

Please sign in to comment.