From 120a7d2769ba507dc7bc1f383234a4ed6331a122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 19:57:25 +0200 Subject: [PATCH 01/14] =?UTF-8?q?refactor(scala-3,mongo):=20BsonGenCodecs?= =?UTF-8?q?=20implicit=20val/def=20=E2=86=92=20anonymous=20given=20+=20@de?= =?UTF-8?q?precated=20shims?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Translated from origin/master@8f70be80. - Trait `BsonGenCodecs` uses `export BsonGenCodecs.given` instead of named `implicit def` forwarders. - Object holds anonymous `given GenCodec[X] = …` declarations as canonical instances. - `@deprecated def name: T = summon` shims preserve source-compat for named-import callers. - Internal callers (EntityIdMode, ObjectIdWrapperCompanion) switched from `BsonGenCodecs.objectIdCodec` to `summon[GenCodec[ObjectId]]` (with `import BsonGenCodecs.given` to bring instances into scope). --- .../commons/mongo/BsonGenCodecs.scala | 94 +++++++++++-------- .../commons/mongo/typed/EntityIdMode.scala | 3 +- .../typed/ObjectIdWrapperCompanion.scala | 3 +- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala index 57291ea71..464809825 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala @@ -10,46 +10,28 @@ import org.bson.types.{Decimal128, ObjectId} import java.nio.ByteBuffer trait BsonGenCodecs { - implicit def objectIdIdentityWrapping: TransparentWrapping[ObjectId, ObjectId] = - BsonGenCodecs.objectIdIdentityWrapping - implicit def objectIdCodec: GenCodec[ObjectId] = BsonGenCodecs.objectIdCodec - implicit def objectIdKeyCodec: GenKeyCodec[ObjectId] = BsonGenCodecs.objectIdKeyCodec - implicit def decimal128Codec: GenCodec[Decimal128] = BsonGenCodecs.decimal128Codec - - implicit def bsonArrayCodec: GenCodec[BsonArray] = BsonGenCodecs.bsonArrayCodec - implicit def bsonBinaryCodec: GenCodec[BsonBinary] = BsonGenCodecs.bsonBinaryCodec - implicit def bsonBooleanCodec: GenCodec[BsonBoolean] = BsonGenCodecs.bsonBooleanCodec - implicit def bsonDateTimeCodec: GenCodec[BsonDateTime] = BsonGenCodecs.bsonDateTimeCodec - implicit def bsonDocumentCodec: GenCodec[BsonDocument] = BsonGenCodecs.bsonDocumentCodec - implicit def bsonDecimal128Codec: GenCodec[BsonDecimal128] = BsonGenCodecs.bsonDecimal128Codec - implicit def bsonDoubleCodec: GenCodec[BsonDouble] = BsonGenCodecs.bsonDoubleCodec - implicit def bsonInt32Codec: GenCodec[BsonInt32] = BsonGenCodecs.bsonInt32Codec - implicit def bsonInt64Codec: GenCodec[BsonInt64] = BsonGenCodecs.bsonInt64Codec - implicit def bsonNullCodec: GenCodec[BsonNull] = BsonGenCodecs.bsonNullCodec - implicit def bsonObjectIdCodec: GenCodec[BsonObjectId] = BsonGenCodecs.bsonObjectIdCodec - implicit def bsonStringCodec: GenCodec[BsonString] = BsonGenCodecs.bsonStringCodec - implicit def bsonValueCodec: GenCodec[BsonValue] = BsonGenCodecs.bsonValueCodec + export BsonGenCodecs.given } object BsonGenCodecs { // needed so that ObjectId can be used as ID type in AutoIdMongoEntity // (TransparentWrapping is used in EntityIdMode) - implicit val objectIdIdentityWrapping: TransparentWrapping[ObjectId, ObjectId] = TransparentWrapping.identity + given TransparentWrapping[ObjectId, ObjectId] = TransparentWrapping.identity - implicit val objectIdCodec: GenCodec[ObjectId] = GenCodec.nullable( + given GenCodec[ObjectId] = GenCodec.nullable( i => i.readCustom(ObjectIdMarker).getOrElse(new ObjectId(i.readSimple().readString())), (o, v) => if (!o.writeCustom(ObjectIdMarker, v)) o.writeSimple().writeString(v.toHexString), ) - implicit val objectIdKeyCodec: GenKeyCodec[ObjectId] = + given GenKeyCodec[ObjectId] = GenKeyCodec.create(new ObjectId(_), _.toHexString) - implicit val decimal128Codec: GenCodec[Decimal128] = GenCodec.nullable( + given GenCodec[Decimal128] = GenCodec.nullable( i => i.readCustom(Decimal128Marker).getOrElse(new Decimal128(i.readSimple().readBigDecimal().bigDecimal)), (o, v) => if (!o.writeCustom(Decimal128Marker, v)) o.writeSimple().writeBigDecimal(v.bigDecimalValue()), ) - implicit val bsonValueCodec: GenCodec[BsonValue] = GenCodec.create( + given GenCodec[BsonValue] = GenCodec.create( i => i.readCustom(BsonValueMarker).getOrElse { val reader = new BsonBinaryReader(ByteBuffer.wrap(i.readSimple().readBinary())) @@ -67,27 +49,63 @@ object BsonGenCodecs { ) private def bsonValueSubCodec[T <: BsonValue](fromBsonValue: BsonValue => T): GenCodec[T] = - bsonValueCodec.transform(identity, fromBsonValue) + summon[GenCodec[BsonValue]].transform(identity, fromBsonValue) - implicit val bsonArrayCodec: GenCodec[BsonArray] = bsonValueSubCodec(_.asArray()) - implicit val bsonBinaryCodec: GenCodec[BsonBinary] = bsonValueSubCodec(_.asBinary()) - implicit val bsonBooleanCodec: GenCodec[BsonBoolean] = bsonValueSubCodec(_.asBoolean()) - implicit val bsonDateTimeCodec: GenCodec[BsonDateTime] = bsonValueSubCodec(_.asDateTime()) - implicit val bsonDocumentCodec: GenCodec[BsonDocument] = bsonValueSubCodec(_.asDocument()) - implicit val bsonDecimal128Codec: GenCodec[BsonDecimal128] = bsonValueSubCodec(_.asDecimal128()) - implicit val bsonDoubleCodec: GenCodec[BsonDouble] = bsonValueSubCodec(_.asDouble()) - implicit val bsonInt32Codec: GenCodec[BsonInt32] = bsonValueSubCodec(_.asInt32()) - implicit val bsonInt64Codec: GenCodec[BsonInt64] = bsonValueSubCodec(_.asInt64()) + given GenCodec[BsonArray] = bsonValueSubCodec(_.asArray()) + given GenCodec[BsonBinary] = bsonValueSubCodec(_.asBinary()) + given GenCodec[BsonBoolean] = bsonValueSubCodec(_.asBoolean()) + given GenCodec[BsonDateTime] = bsonValueSubCodec(_.asDateTime()) + given GenCodec[BsonDocument] = bsonValueSubCodec(_.asDocument()) + given GenCodec[BsonDecimal128] = bsonValueSubCodec(_.asDecimal128()) + given GenCodec[BsonDouble] = bsonValueSubCodec(_.asDouble()) + given GenCodec[BsonInt32] = bsonValueSubCodec(_.asInt32()) + given GenCodec[BsonInt64] = bsonValueSubCodec(_.asInt64()) - implicit val bsonNullCodec: GenCodec[BsonNull] = + given GenCodec[BsonNull] = bsonValueSubCodec { bv => if (bv.isNull) BsonNull.VALUE else throw new ReadFailure("Input did not contain expected null value") } - implicit val bsonObjectIdCodec: GenCodec[BsonObjectId] = - objectIdCodec.transform(_.getValue, new BsonObjectId(_)) + given GenCodec[BsonObjectId] = + summon[GenCodec[ObjectId]].transform(_.getValue, new BsonObjectId(_)) - implicit val bsonStringCodec: GenCodec[BsonString] = + given GenCodec[BsonString] = GenCodec.StringCodec.transform(_.getValue, new BsonString(_)) + + // Source-compat aliases for callers that previously referenced these by name. + @deprecated("Use summon[TransparentWrapping[ObjectId, ObjectId]]", since = "scala-3") + def objectIdIdentityWrapping: TransparentWrapping[ObjectId, ObjectId] = summon + @deprecated("Use summon[GenCodec[ObjectId]]", since = "scala-3") + def objectIdCodec: GenCodec[ObjectId] = summon + @deprecated("Use summon[GenKeyCodec[ObjectId]]", since = "scala-3") + def objectIdKeyCodec: GenKeyCodec[ObjectId] = summon + @deprecated("Use summon[GenCodec[Decimal128]]", since = "scala-3") + def decimal128Codec: GenCodec[Decimal128] = summon + @deprecated("Use summon[GenCodec[BsonValue]]", since = "scala-3") + def bsonValueCodec: GenCodec[BsonValue] = summon + @deprecated("Use summon[GenCodec[BsonArray]]", since = "scala-3") + def bsonArrayCodec: GenCodec[BsonArray] = summon + @deprecated("Use summon[GenCodec[BsonBinary]]", since = "scala-3") + def bsonBinaryCodec: GenCodec[BsonBinary] = summon + @deprecated("Use summon[GenCodec[BsonBoolean]]", since = "scala-3") + def bsonBooleanCodec: GenCodec[BsonBoolean] = summon + @deprecated("Use summon[GenCodec[BsonDateTime]]", since = "scala-3") + def bsonDateTimeCodec: GenCodec[BsonDateTime] = summon + @deprecated("Use summon[GenCodec[BsonDocument]]", since = "scala-3") + def bsonDocumentCodec: GenCodec[BsonDocument] = summon + @deprecated("Use summon[GenCodec[BsonDecimal128]]", since = "scala-3") + def bsonDecimal128Codec: GenCodec[BsonDecimal128] = summon + @deprecated("Use summon[GenCodec[BsonDouble]]", since = "scala-3") + def bsonDoubleCodec: GenCodec[BsonDouble] = summon + @deprecated("Use summon[GenCodec[BsonInt32]]", since = "scala-3") + def bsonInt32Codec: GenCodec[BsonInt32] = summon + @deprecated("Use summon[GenCodec[BsonInt64]]", since = "scala-3") + def bsonInt64Codec: GenCodec[BsonInt64] = summon + @deprecated("Use summon[GenCodec[BsonNull]]", since = "scala-3") + def bsonNullCodec: GenCodec[BsonNull] = summon + @deprecated("Use summon[GenCodec[BsonObjectId]]", since = "scala-3") + def bsonObjectIdCodec: GenCodec[BsonObjectId] = summon + @deprecated("Use summon[GenCodec[BsonString]]", since = "scala-3") + def bsonStringCodec: GenCodec[BsonString] = summon } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala index e104a5424..8c5aece21 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala @@ -2,6 +2,7 @@ package com.avsystem.commons package mongo.typed import com.avsystem.commons.mongo.{mongoId, BsonGenCodecs} +import com.avsystem.commons.mongo.BsonGenCodecs.given import com.avsystem.commons.serialization.{GenCodec, TransparentWrapping} import org.bson.types.ObjectId @@ -20,7 +21,7 @@ sealed trait EntityIdMode[E, ID] { case EntityIdMode.Explicit() => format.fieldRefFor(MongoRef.RootRef(format), MongoEntity.Id) case EntityIdMode.Auto(idWrapping) => - val idCodec = GenCodec.fromTransparentWrapping(idWrapping, BsonGenCodecs.objectIdCodec) + val idCodec = GenCodec.fromTransparentWrapping(idWrapping, summon[GenCodec[ObjectId]]) MongoRef.FieldRef(MongoRef.RootRef(format), mongoId.Id, MongoFormat.Opaque(idCodec), Opt.Empty) } } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala index 2638cecff..38dc35ed3 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala @@ -2,6 +2,7 @@ package com.avsystem.commons package mongo.typed import com.avsystem.commons.mongo.BsonGenCodecs +import com.avsystem.commons.mongo.BsonGenCodecs.given import com.avsystem.commons.serialization.{GenCodec, TransparentWrapperCompanion} import org.bson.types.ObjectId @@ -23,5 +24,5 @@ abstract class ObjectIdWrapperCompanion[ID] extends TransparentWrapperCompanion[ */ def get(): ID = wrap(ObjectId.get()) - implicit val codec: GenCodec[ID] = GenCodec.fromTransparentWrapping(this, BsonGenCodecs.objectIdCodec) + implicit val codec: GenCodec[ID] = GenCodec.fromTransparentWrapping(this, summon[GenCodec[ObjectId]]) } From 5e1a83c796be009fafa58391901258a70e883d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 19:58:52 +0200 Subject: [PATCH 02/14] =?UTF-8?q?refactor(scala-3,mongo):=20(implicit=20X:?= =?UTF-8?q?=20T)=20=E2=86=92=20(using=20X:=20T)=20parameter=20list=20sweep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Translated from origin/master@eef0edce + 848b8e9e. Mechanical sweep across 19 mongo files. Bridge `this(rawCollection)(meta)` call sites in TypedMongoCollection updated to explicit `(using …)` syntax now that the receiver param list is `using`. Source-compat: positional implicit-arg call sites unchanged (Scala 3 accepts both syntaxes); named-argument call sites must update from `foo(x = …)` to `foo(using x = …)`. --- .../scala/com/avsystem/commons/mongo/BsonCodec.scala | 2 +- .../scala/com/avsystem/commons/mongo/BsonRef.scala | 4 ++-- .../main/scala/com/avsystem/commons/mongo/DocKey.scala | 2 +- .../main/scala/com/avsystem/commons/mongo/Filter.scala | 2 +- .../avsystem/commons/mongo/core/GenCodecProvider.scala | 2 +- .../mongo/core/ops/BsonRefIterableFiltering.scala | 2 +- .../mongo/core/ops/BsonRefIterableUpdating.scala | 2 +- .../com/avsystem/commons/mongo/core/ops/Sorting.scala | 4 ++-- .../com/avsystem/commons/mongo/sync/MongoOps.scala | 2 +- .../commons/mongo/text/TextSearchLanguage.scala | 2 +- .../com/avsystem/commons/mongo/typed/DataTypeDsl.scala | 2 +- .../commons/mongo/typed/MongoEntityCompanion.scala | 4 ++-- .../com/avsystem/commons/mongo/typed/MongoIndex.scala | 2 +- .../commons/mongo/typed/MongoPolyDataCompanion.scala | 2 +- .../com/avsystem/commons/mongo/typed/MongoRef.scala | 4 ++-- .../commons/mongo/typed/MongoUpdateOperator.scala | 2 +- .../commons/mongo/typed/ProjectionZippers.scala | 2 +- .../commons/mongo/typed/QueryOperatorsDsl.scala | 4 ++-- .../commons/mongo/typed/TypedMongoCollection.scala | 10 +++++----- 19 files changed, 28 insertions(+), 28 deletions(-) diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonCodec.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonCodec.scala index 85e0b0ea4..978e00934 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonCodec.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonCodec.scala @@ -22,7 +22,7 @@ trait BsonCodec[A, BSON <: BsonValue] { self => def key(key: String): DocKey[A, BSON] = new DocKey[A, BSON](key, this) - def collection[C[X] <: IterableOnce[X]](implicit fac: Factory[A, C[A]]): BsonCodec[C[A], BsonArray] = + def collection[C[X] <: IterableOnce[X]](using fac: Factory[A, C[A]]): BsonCodec[C[A], BsonArray] = BsonCodec.create[C[A], BsonArray]( ba => ba.iterator().asScala.map(bv => self.fromBson(bv.asInstanceOf[BSON])).to(fac), col => new BsonArray(col.iterator.map(self.toBson).to(JList)), diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonRef.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonRef.scala index 1b7df8873..185164c29 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonRef.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonRef.scala @@ -19,7 +19,7 @@ case class BsonRef[S, T](path: String, codec: GenCodec[T], getter: S => T) { object BsonRef { val BsonKeySeparator = "." - def identity[S](implicit codec: GenCodec[S]): BsonRef[S, S] = BsonRef("", codec, s => s) + def identity[S](using codec: GenCodec[S]): BsonRef[S, S] = BsonRef("", codec, s => s) def create[S]: Creator[S] = new Creator[S] {} trait Creator[S] { @@ -29,7 +29,7 @@ object BsonRef { def ref[T](fun: S => T): BsonRef[S, T] = ??? } - def apply[S, T](genRef: GenRef[S, T])(implicit codec: GenCodec[T]): BsonRef[S, T] = { + def apply[S, T](genRef: GenRef[S, T])(using codec: GenCodec[T]): BsonRef[S, T] = { val path = genRef.rawRef.normalize .map { case Field(name) => KeyEscaper.escape(name) diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/DocKey.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/DocKey.scala index 5b60bab9d..6019521ec 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/DocKey.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/DocKey.scala @@ -8,7 +8,7 @@ import org.bson.{BsonDocument, BsonValue} * MKej */ case class DocKey[A, BSON <: BsonValue](key: String, codec: BsonCodec[A, BSON]) { - def ++[B, BBSON <: BsonValue](other: DocKey[B, BBSON])(implicit ev: BSON <:< BsonDocument): DocKey[B, BBSON] = + def ++[B, BBSON <: BsonValue](other: DocKey[B, BBSON])(using ev: BSON <:< BsonDocument): DocKey[B, BBSON] = new DocKey(key + "." + other.key, other.codec) } object DocKey { diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala index 06e898383..628405511 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala @@ -48,7 +48,7 @@ object Filter { def elemMatch(key: DocKey[_, _ <: BsonArray], filter: Bson): Bson = F.elemMatch(key.key, filter) - def contains[A, COL <: Iterable[A]](key: DocKey[COL, _ <: BsonArray], value: A)(implicit fac: Factory[A, COL]): Bson = + def contains[A, COL <: Iterable[A]](key: DocKey[COL, _ <: BsonArray], value: A)(using fac: Factory[A, COL]): Bson = F.eq(key.key, key.codec.toBson((fac.newBuilder += value).result()).asScala.head) object Limitations { diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/GenCodecProvider.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/GenCodecProvider.scala index 825a886eb..26c45c8bd 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/GenCodecProvider.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/GenCodecProvider.scala @@ -6,7 +6,7 @@ import com.avsystem.commons.serialization.GenCodec import org.bson.codecs.Codec import org.bson.codecs.configuration.{CodecProvider, CodecRegistry} -class GenCodecProvider[T: GenCodec](legacyOptionEncoding: Boolean)(implicit ct: ClassTag[T]) extends CodecProvider { +class GenCodecProvider[T: GenCodec](legacyOptionEncoding: Boolean)(using ct: ClassTag[T]) extends CodecProvider { private val mongoCodec = new GenCodecBasedBsonCodec[T](legacyOptionEncoding) private val runtimeClass = ct.runtimeClass diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableFiltering.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableFiltering.scala index cebf0bc24..b322205cd 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableFiltering.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableFiltering.scala @@ -6,7 +6,7 @@ import com.avsystem.commons.serialization.GenCodec final class BsonRefIterableFiltering[E, C[T] <: Iterable[T]]( protected val bsonRef: BsonRef[_, C[E]] -)(implicit protected val elementCodec: GenCodec[E] +)(using protected val elementCodec: GenCodec[E] ) extends BaseIterableFiltering[E, C] with BsonRefKeyValueHandling[C[E]] with BsonRefKeyElementHandling[E, C] diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableUpdating.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableUpdating.scala index 3ba04cbab..6a7312bd9 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableUpdating.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefIterableUpdating.scala @@ -6,7 +6,7 @@ import com.avsystem.commons.serialization.GenCodec final class BsonRefIterableUpdating[E, C[T] <: Iterable[T]]( protected val bsonRef: BsonRef[_, C[E]] -)(implicit protected val elementCodec: GenCodec[E] +)(using protected val elementCodec: GenCodec[E] ) extends BaseIterableUpdating[E, C] with BsonRefKeyValueHandling[C[E]] with BsonRefKeyElementHandling[E, C] diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/Sorting.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/Sorting.scala index 799ffb678..c5588c021 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/Sorting.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/Sorting.scala @@ -5,8 +5,8 @@ import com.mongodb.client.model.Sorts import org.bson.conversions.Bson object Sorting { - def ascending[K](keys: K*)(implicit kg: KeyGetter[K]): Bson = Sorts.ascending(keys.map(kg.keyOf).asJava) - def descending[K](keys: K*)(implicit kg: KeyGetter[K]): Bson = Sorts.descending(keys.map(kg.keyOf).asJava) + def ascending[K](keys: K*)(using kg: KeyGetter[K]): Bson = Sorts.ascending(keys.map(kg.keyOf).asJava) + def descending[K](keys: K*)(using kg: KeyGetter[K]): Bson = Sorts.descending(keys.map(kg.keyOf).asJava) def orderBy(sorts: Bson*): Bson = Sorts.orderBy(sorts.asJava) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala index 67e101429..d1f39b134 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala @@ -20,7 +20,7 @@ trait MongoOps { object MongoOps { final class DBOps(private val db: MongoDatabase) extends AnyVal { - def getCollection[A](name: String, codec: BsonCodec[A, BsonDocument])(implicit ct: ClassTag[A]) + def getCollection[A](name: String, codec: BsonCodec[A, BsonDocument])(using ct: ClassTag[A]) : MongoCollection[A] = { val mongoCodec = new MongoCodec[A, BsonDocument](codec, db.getCodecRegistry) val registry = CodecRegistries.fromRegistries( diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/text/TextSearchLanguage.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/text/TextSearchLanguage.scala index 8b7f5f2ac..b8d0ecf15 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/text/TextSearchLanguage.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/text/TextSearchLanguage.scala @@ -10,7 +10,7 @@ import com.avsystem.commons.misc.{AbstractValueEnum, AbstractValueEnumCompanion, * @see * [[https://docs.mongodb.com/manual/reference/text-search-languages/#text-search-languages]] */ -final class TextSearchLanguage(val code: String)(implicit enumCtx: EnumCtx) extends AbstractValueEnum +final class TextSearchLanguage(val code: String)(using enumCtx: EnumCtx) extends AbstractValueEnum object TextSearchLanguage extends AbstractValueEnumCompanion[TextSearchLanguage] { /** Uses simple tokenization with no list of stop words and no stemming. diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/DataTypeDsl.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/DataTypeDsl.scala index e9ca5ce0c..48f00f4ba 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/DataTypeDsl.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/DataTypeDsl.scala @@ -14,7 +14,7 @@ trait DataRefDsl[E, T] { def SelfRef: ThisRef[E, T] // called by .ref macro to ensure that the source type is not opaque and inner references are possible - @macroPrivate def asAdtRef(implicit ev: IsMongoAdtOrSubtype[T]): ThisRef[E, T] = SelfRef + @macroPrivate def asAdtRef(using ev: IsMongoAdtOrSubtype[T]): ThisRef[E, T] = SelfRef /** A macro that interprets an anonymous function as a [[MongoPropertyRef]]. * diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala index f59d9f430..c3e059b14 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala @@ -40,7 +40,7 @@ sealed abstract class BaseMongoCompanion[T] extends DataTypeDsl[T] { abstract class AbstractMongoDataCompanion[Implicits, E]( implicits: Implicits -)(implicit instances: MacroInstances[Implicits, MongoAdtInstances[E]] +)(using instances: MacroInstances[Implicits, MongoAdtInstances[E]] ) extends BaseMongoCompanion[E] { implicit val codec: GenObjectCodec[E] = instances(implicits, this).codec implicit val format: MongoAdtFormat[E] = instances(implicits, this).format @@ -48,7 +48,7 @@ abstract class AbstractMongoDataCompanion[Implicits, E]( abstract class AbstractMongoEntityCompanion[Implicits, E <: BaseMongoEntity]( implicits: Implicits -)(implicit instances: MacroInstances[Implicits, MongoEntityInstances[E]] +)(using instances: MacroInstances[Implicits, MongoEntityInstances[E]] ) extends BaseMongoCompanion[E] { implicit val codec: GenObjectCodec[E] = instances(implicits, this).codec implicit val format: MongoAdtFormat[E] = instances(implicits, this).format diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoIndex.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoIndex.scala index d2dc8cff3..b405c7616 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoIndex.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoIndex.scala @@ -67,7 +67,7 @@ object MongoIndex { MongoIndex(fields.iterator.map(f => f -> MongoIndexType.Descending).toVector) } -final class MongoIndexType(implicit enumCtx: EnumCtx) extends AbstractValueEnum { +final class MongoIndexType(using enumCtx: EnumCtx) extends AbstractValueEnum { import MongoIndexType._ diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala index 594ec7835..52dd3e572 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala @@ -21,7 +21,7 @@ trait MongoPolyAdtInstances[D[_]] { abstract class AbstractMongoPolyDataCompanion[Implicits, D[_]]( implicits: Implicits -)(implicit instances: MacroInstances[Implicits, MongoPolyAdtInstances[D]] +)(using instances: MacroInstances[Implicits, MongoPolyAdtInstances[D]] ) { implicit def codec[T: GenCodec]: GenObjectCodec[D[T]] = instances(implicits, this).codec[T] diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoRef.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoRef.scala index 59926bf5d..cf7cbb693 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoRef.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoRef.scala @@ -279,7 +279,7 @@ object MongoPropertyRef { } } - implicit def optionalRefOps[E, O, T](ref: MongoPropertyRef[E, O])(implicit optionLike: OptionLike.Aux[O, T]) + implicit def optionalRefOps[E, O, T](ref: MongoPropertyRef[E, O])(using optionLike: OptionLike.Aux[O, T]) : OptionalRefOps[E, O, T] = new OptionalRefOps[E, O, T](ref) @@ -290,7 +290,7 @@ object MongoPropertyRef { } } - implicit def transparentRefOps[E, T, R](ref: MongoPropertyRef[E, T])(implicit wrapping: TransparentWrapping[R, T]) + implicit def transparentRefOps[E, T, R](ref: MongoPropertyRef[E, T])(using wrapping: TransparentWrapping[R, T]) : TransparentRefOps[E, T, R] = new TransparentRefOps[E, T, R](ref) diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoUpdateOperator.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoUpdateOperator.scala index 0817d58cf..4d3a41b90 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoUpdateOperator.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoUpdateOperator.scala @@ -44,7 +44,7 @@ sealed trait MongoUpdateOperator[T] extends Product { } } object MongoUpdateOperator { - final class CurrentDateType(implicit enumCtx: EnumCtx) extends AbstractValueEnum + final class CurrentDateType(using enumCtx: EnumCtx) extends AbstractValueEnum object CurrentDateType extends AbstractValueEnumCompanion[CurrentDateType] { final val Timestamp, Date: Value = new CurrentDateType } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ProjectionZippers.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ProjectionZippers.scala index 379e50296..8cca8c727 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ProjectionZippers.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ProjectionZippers.scala @@ -357,7 +357,7 @@ trait ProjectionZippers { this: MongoProjection.type => ) } -final class ProductProjection[E, T](componentProjections: Seq[MongoProjection[E, _]])(implicit applier: Applier[T]) +final class ProductProjection[E, T](componentProjections: Seq[MongoProjection[E, _]])(using applier: Applier[T]) extends MongoProjection[E, T] { def projectionRefs: Set[MongoRef[E, _]] = diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/QueryOperatorsDsl.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/QueryOperatorsDsl.scala index ef7f2ae15..b70814157 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/QueryOperatorsDsl.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/QueryOperatorsDsl.scala @@ -101,7 +101,7 @@ object QueryOperatorsDsl { def containsAll(values: Iterable[T]): R = dsl.all(values) } - implicit def forOptional[O, T, R](dsl: QueryOperatorsDsl[O, R])(implicit optionLike: OptionLike.Aux[O, T]) + implicit def forOptional[O, T, R](dsl: QueryOperatorsDsl[O, R])(using optionLike: OptionLike.Aux[O, T]) : ForOptional[O, T, R] = new ForOptional(dsl) @@ -113,7 +113,7 @@ object QueryOperatorsDsl { } } -final class RegexFlag(val javaFlag: Int, val char: Char)(implicit enumCtx: EnumCtx) extends AbstractValueEnum +final class RegexFlag(val javaFlag: Int, val char: Char)(using enumCtx: EnumCtx) extends AbstractValueEnum object RegexFlag extends AbstractValueEnumCompanion[RegexFlag] { // code based on org.bson.codecs.PatternCodec diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala index df5e6c24a..ae67f2ae4 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala @@ -19,14 +19,14 @@ class TypedMongoCollection[E <: BaseMongoEntity] private ( val nativeCollection: MongoCollection[E], docCollection: MongoCollection[BsonDocument], val clientSession: Opt[TypedClientSession], -)(implicit meta: MongoEntityMeta[E] +)(using meta: MongoEntityMeta[E] ) extends DataTypeDsl[E] with TypedMongoUtils { def this( rawCollection: MongoCollection[_], clientSession: OptArg[TypedClientSession] = OptArg.Empty, - )(implicit meta: MongoEntityMeta[E] + )(using meta: MongoEntityMeta[E] ) = this( TypedMongoCollection.mkNativeCollection[E](rawCollection), rawCollection.withDocumentClass(classOf[BsonDocument]), @@ -385,16 +385,16 @@ class TypedMongoCollection[E <: BaseMongoEntity] private ( } @bincompat private[typed] def this(rawCollection: MongoCollection[_], format: MongoAdtFormat[E]) = - this(rawCollection)(MongoEntityMeta.bincompatMeta(format)) + this(rawCollection)(using MongoEntityMeta.bincompatMeta(format)) @bincompat private[typed] def this(rawCollection: MongoCollection[_], meta: MongoEntityMeta[E]) = - this(rawCollection)(meta) + this(rawCollection)(using meta) } object TypedMongoCollection { private def mkNativeCollection[E <: BaseMongoEntity: MongoEntityMeta]( rawCollection: MongoCollection[_] - )(implicit meta: MongoEntityMeta[E] + )(using meta: MongoEntityMeta[E] ): MongoCollection[E] = { import meta.format._ val codecRegistry: CodecRegistry = GenCodecRegistry.create[E](rawCollection.getCodecRegistry) From e0d42cbd8a5ceff909d8130a6496f387ae07b79c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 19:59:21 +0200 Subject: [PATCH 03/14] fix(scala-3): preserve OptArg.argToOptArg implicit (erasure-bridge collision) Translated from origin/master@39c047eb. Polymorphic `Conversion[A, OptArg[A]]` would generate a clashing JVM erasure bridge: both `A` and the `OptArg` value class erase to `Object`. Kept verbatim as `implicit def` with fork's explanatory comment. --- core/src/main/scala/com/avsystem/commons/misc/OptArg.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala b/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala index 78d0e5d7c..994f6d991 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala @@ -2,7 +2,9 @@ package com.avsystem.commons.misc object OptArg { - /** This implicit conversion allows you to pass unwrapped values where `OptArg` is required. + /** This conversion allows you to pass unwrapped values where `OptArg` is required. Kept as `implicit def` (not a + * `given Conversion`) because a polymorphic `Conversion[A, OptArg[A]]` generates a clashing bridge: both `A` and the + * `OptArg` value class erase to `Object`. */ implicit def argToOptArg[A](value: A): OptArg[A] = OptArg(value) From 87df9ee3469ff787dd07ee6b0436c619e87f1ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 20:03:58 +0200 Subject: [PATCH 04/14] =?UTF-8?q?refactor(scala-3,mongo):=20residual=20imp?= =?UTF-8?q?licit=20val/def=20=E2=86=92=20given=20for=20typeclass=20instanc?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Translated from origin/master@848b8e9e + eef0edce. Converts typeclass-instance implicits to `given` across mongo: - Filter.CanCompare instances - KeyGetter.bsonRefKeyGetter / docKeyKeyGetter (implicit object → given X: T with { … }) - EntityIdMode.explicitIdMode / autoIdMode - BaseMongoCompanion.codec / format / isMongoAdtOrSubtype - AbstractMongoDataCompanion.codec / format - AbstractMongoEntityCompanion.codec / format / meta - MongoFormat.codec, collectionFormat, dictionaryFormat, typedMapFormat, optionalFormat, transparentFormat, leafFormat - MongoAdtFormat.codec / dataClassTag - MongoPolyDataCompanion.codec / format / tCodec / isMongoAdtOrSubtype - MongoTypedKey.mongoFormatMapping - ObjectIdWrapperCompanion.codec TypedMongoCollection.mkNativeCollection updated to `import meta.format.{given, _}` and `summon[ClassTag[E]]` for ClassTag resolution now that `dataClassTag` is a `given`. Extension-shim `implicit def` patterns (`bsonRefUpdating`, `bsonFiltering`, `bsonUpdating`, `dbOps`, `findIterableOps`, `optionalRefOps`, `transparentRefOps`, `forOptional`, etc.) preserved as-is — they belong to slice 3.1 (`implicit class → extension`) and will be converted there. Same for `implicit class macroDslExtensions` companions. --- .../com/avsystem/commons/mongo/Filter.scala | 8 +++--- .../commons/mongo/core/ops/KeyGetter.scala | 4 +-- .../commons/mongo/typed/EntityIdMode.scala | 6 ++-- .../mongo/typed/MongoEntityCompanion.scala | 16 +++++------ .../commons/mongo/typed/MongoFormat.scala | 28 +++++++++---------- .../mongo/typed/MongoPolyDataCompanion.scala | 8 +++--- .../commons/mongo/typed/MongoTypedKey.scala | 2 +- .../typed/ObjectIdWrapperCompanion.scala | 2 +- .../mongo/typed/TypedMongoCollection.scala | 4 +-- 9 files changed, 39 insertions(+), 39 deletions(-) diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala index 628405511..830478650 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/Filter.scala @@ -55,10 +55,10 @@ object Filter { trait CanCompare[BSON <: BsonValue] object CanCompare { def create[BSON <: BsonValue]: CanCompare[BSON] = new CanCompare[BSON] {} - implicit val date: CanCompare[BsonDateTime] = create[BsonDateTime] - implicit val int32: CanCompare[BsonInt32] = create[BsonInt32] - implicit val int64: CanCompare[BsonInt64] = create[BsonInt64] - implicit val double: CanCompare[BsonDouble] = create[BsonDouble] + given CanCompare[BsonDateTime] = create[BsonDateTime] + given CanCompare[BsonInt32] = create[BsonInt32] + given CanCompare[BsonInt64] = create[BsonInt64] + given CanCompare[BsonDouble] = create[BsonDouble] } } } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/KeyGetter.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/KeyGetter.scala index 41c7dd72e..ad4116d44 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/KeyGetter.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/KeyGetter.scala @@ -8,11 +8,11 @@ trait KeyGetter[-T] { } object KeyGetter { - implicit object bsonRefKeyGetter extends KeyGetter[BsonRef[_, _]] { + given bsonRefKeyGetter: KeyGetter[BsonRef[_, _]] with { override def keyOf(t: BsonRef[_, _]): String = t.path } - implicit object docKeyKeyGetter extends KeyGetter[DocKey[_, _]] { + given docKeyKeyGetter: KeyGetter[DocKey[_, _]] with { override def keyOf(t: DocKey[_, _]): String = t.key } } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala index 8c5aece21..8df8eb4a6 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala @@ -29,9 +29,9 @@ object EntityIdMode { case class Explicit[E, ID]() extends EntityIdMode[E, ID] case class Auto[E, ID](idWrapping: TransparentWrapping[ObjectId, ID]) extends EntityIdMode[E, ID] - implicit def explicitIdMode[E <: MongoEntity[ID], ID]: EntityIdMode[E, ID] = Explicit() + given explicitIdMode[E <: MongoEntity[ID], ID]: EntityIdMode[E, ID] = Explicit() - implicit def autoIdMode[E <: AutoIdMongoEntity[ID], ID]( - implicit idWrapping: TransparentWrapping[ObjectId, ID] + given autoIdMode[E <: AutoIdMongoEntity[ID], ID](using + idWrapping: TransparentWrapping[ObjectId, ID] ): EntityIdMode[E, ID] = Auto(idWrapping) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala index c3e059b14..e481721cb 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoEntityCompanion.scala @@ -24,10 +24,10 @@ trait MongoEntityInstances[E <: BaseMongoEntity] extends MongoAdtInstances[E] { sealed trait IsMongoAdtOrSubtype[T] sealed abstract class BaseMongoCompanion[T] extends DataTypeDsl[T] { - implicit def codec: GenObjectCodec[T] - implicit def format: MongoAdtFormat[T] + given codec: GenObjectCodec[T] + given format: MongoAdtFormat[T] - implicit def isMongoAdtOrSubtype[C <: T]: IsMongoAdtOrSubtype[C] = null + given isMongoAdtOrSubtype[C <: T]: IsMongoAdtOrSubtype[C] = null implicit class macroDslExtensions(value: T) { @explicitGenerics @@ -42,17 +42,17 @@ abstract class AbstractMongoDataCompanion[Implicits, E]( implicits: Implicits )(using instances: MacroInstances[Implicits, MongoAdtInstances[E]] ) extends BaseMongoCompanion[E] { - implicit val codec: GenObjectCodec[E] = instances(implicits, this).codec - implicit val format: MongoAdtFormat[E] = instances(implicits, this).format + given codec: GenObjectCodec[E] = instances(implicits, this).codec + given format: MongoAdtFormat[E] = instances(implicits, this).format } abstract class AbstractMongoEntityCompanion[Implicits, E <: BaseMongoEntity]( implicits: Implicits )(using instances: MacroInstances[Implicits, MongoEntityInstances[E]] ) extends BaseMongoCompanion[E] { - implicit val codec: GenObjectCodec[E] = instances(implicits, this).codec - implicit val format: MongoAdtFormat[E] = instances(implicits, this).format - implicit val meta: MongoEntityMeta[E] = instances(implicits, this).meta + given codec: GenObjectCodec[E] = instances(implicits, this).codec + given format: MongoAdtFormat[E] = instances(implicits, this).format + given meta: MongoEntityMeta[E] = instances(implicits, this).meta // TODO[scala3-port]: `E#IDType` type projection forbidden on abstract types; widen to Any to keep signatures (M) type ID = Any diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala index 97b9c499f..58fc4c441 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala @@ -14,7 +14,7 @@ import scala.annotation.tailrec * indirectly as an embedded value). */ sealed trait MongoFormat[T] { - implicit def codec: GenCodec[T] + given codec: GenCodec[T] def writeBson(value: T): BsonValue = BsonValueOutput.write(value) @@ -93,32 +93,32 @@ object MongoFormat extends MetadataCompanion[MongoFormat] with MongoFormatLowPri wrappedFormat: MongoFormat[R], ) extends MongoFormat[T] - implicit def collectionFormat[C[X] <: Iterable[X], T]( - implicit collectionCodec: GenCodec[C[T]], + given collectionFormat[C[X] <: Iterable[X], T](using + collectionCodec: GenCodec[C[T]], elementFormat: MongoFormat[T], ): MongoFormat[C[T]] = CollectionFormat(collectionCodec, elementFormat) - implicit def dictionaryFormat[M[X, Y] <: BMap[X, Y], K, V]( - implicit mapCodec: GenCodec[M[K, V]], + given dictionaryFormat[M[X, Y] <: BMap[X, Y], K, V](using + mapCodec: GenCodec[M[K, V]], keyCodec: GenKeyCodec[K], valueFormat: MongoFormat[V], ): MongoFormat[M[K, V]] = DictionaryFormat(mapCodec, keyCodec, valueFormat) // TODO[scala3-port]: K[_] → K[Any] workaround for Scala 3 wildcard-as-type-arg restriction (S) - implicit def typedMapFormat[K[_]]( - implicit keyCodec: GenKeyCodec[K[Any]], + given typedMapFormat[K[_]](using + keyCodec: GenKeyCodec[K[Any]], valueFormats: MongoFormatMapping[K], ): MongoFormat[TypedMap[K]] = TypedMapFormat[K](TypedMap.typedMapCodec, keyCodec, valueFormats) - implicit def optionalFormat[O, T]( - implicit optionLike: OptionLike.Aux[O, T], + given optionalFormat[O, T](using + optionLike: OptionLike.Aux[O, T], optionCodec: GenCodec[O], wrappedFormat: MongoFormat[T], ): MongoFormat[O] = OptionalFormat(optionCodec, optionLike, wrappedFormat) - implicit def transparentFormat[R, T]( - implicit codec: GenCodec[T], + given transparentFormat[R, T](using + codec: GenCodec[T], wrapping: TransparentWrapping[R, T], wrappedFormat: MongoFormat[R], ): MongoFormat[T] = TransparentFormat(codec, wrapping, wrappedFormat) @@ -158,13 +158,13 @@ object MongoFormat extends MetadataCompanion[MongoFormat] with MongoFormatLowPri } } trait MongoFormatLowPriority { this: MongoFormat.type => - implicit def leafFormat[T: GenCodec]: MongoFormat[T] = Opaque(GenCodec[T]) + given leafFormat[T: GenCodec]: MongoFormat[T] = Opaque(GenCodec[T]) } sealed trait MongoAdtFormat[T] extends MongoFormat[T] with TypedMetadata[T] { - implicit def codec: GenObjectCodec[T] + given codec: GenObjectCodec[T] // this is not named `classTag` in order to avoid naming conflict with `com.avsystem.commons.classTag` - implicit def dataClassTag: ClassTag[T] + given dataClassTag: ClassTag[T] def fieldRefFor[E, T0](prefix: MongoRef[E, T], scalaFieldName: String): MongoPropertyRef[E, T0] } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala index 52dd3e572..0b02ee904 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoPolyDataCompanion.scala @@ -23,15 +23,15 @@ abstract class AbstractMongoPolyDataCompanion[Implicits, D[_]]( implicits: Implicits )(using instances: MacroInstances[Implicits, MongoPolyAdtInstances[D]] ) { - implicit def codec[T: GenCodec]: GenObjectCodec[D[T]] = instances(implicits, this).codec[T] + given codec[T: GenCodec]: GenObjectCodec[D[T]] = instances(implicits, this).codec[T] - implicit def format[T: MongoFormat]: MongoAdtFormat[D[T]] = { - implicit def tCodec: GenCodec[T] = MongoFormat[T].codec + given format[T: MongoFormat]: MongoAdtFormat[D[T]] = { + given tCodec: GenCodec[T] = MongoFormat[T].codec instances(implicits, this).format[T] } // TODO[scala3-port]: D[_] → D[Any] workaround for Scala 3 wildcard-as-type-arg restriction (S) - implicit def isMongoAdtOrSubtype[C <: D[Any]]: IsMongoAdtOrSubtype[C] = null + given isMongoAdtOrSubtype[C <: D[Any]]: IsMongoAdtOrSubtype[C] = null implicit class macroDslExtensions[T](value: D[T]) { @explicitGenerics diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoTypedKey.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoTypedKey.scala index 339a01ffa..924a92af2 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoTypedKey.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoTypedKey.scala @@ -15,7 +15,7 @@ trait MongoTypedKey[T] extends TypedKey[T] { override def valueCodec: GenCodec[T] = valueFormat.codec } object MongoTypedKey { - implicit def mongoFormatMapping[K[X] <: MongoTypedKey[X]]: MongoFormatMapping[K] = + given mongoFormatMapping[K[X] <: MongoTypedKey[X]]: MongoFormatMapping[K] = new MongoFormatMapping[K] { override def valueFormat[T](key: K[T]): MongoFormat[T] = key.valueFormat } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala index 38dc35ed3..ddd69634b 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala @@ -24,5 +24,5 @@ abstract class ObjectIdWrapperCompanion[ID] extends TransparentWrapperCompanion[ */ def get(): ID = wrap(ObjectId.get()) - implicit val codec: GenCodec[ID] = GenCodec.fromTransparentWrapping(this, summon[GenCodec[ObjectId]]) + given codec: GenCodec[ID] = GenCodec.fromTransparentWrapping(this, summon[GenCodec[ObjectId]]) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala index ae67f2ae4..cec156f45 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/TypedMongoCollection.scala @@ -396,9 +396,9 @@ object TypedMongoCollection { rawCollection: MongoCollection[_] )(using meta: MongoEntityMeta[E] ): MongoCollection[E] = { - import meta.format._ + import meta.format.{given, _} val codecRegistry: CodecRegistry = GenCodecRegistry.create[E](rawCollection.getCodecRegistry) - val documentClass = classTag.runtimeClass.asInstanceOf[Class[E]] + val documentClass = summon[ClassTag[E]].runtimeClass.asInstanceOf[Class[E]] rawCollection.withCodecRegistry(codecRegistry).withDocumentClass(documentClass) } } From 38b0c7628cc07c3e12d5bcd9f9d6cc6151534756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 20:13:20 +0200 Subject: [PATCH 05/14] =?UTF-8?q?refactor(scala-3,core):=20implicit=20val/?= =?UTF-8?q?def=20=E2=86=92=20given=20for=20typeclass=20instances=20+=20mat?= =?UTF-8?q?erialize=20stubs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Translated from origin/master@39c047eb + ebffde26 + 848b8e9e. Converts typeclass instances and materialize-macro stubs to `given`: - serialization: GenCodec collection/option/either/enum/transparent/fallback codecs; GenKeyCodec primitive/enum/transparent codecs (named → anonymous given); GenObjectCodec.fromTransparentWrapping; HasGenCodec.codec family; TupleGenCodecs; TransparentWrapperCompanion.self/ordering; SerializationName.fromNameAnnot/fromSimpleClassName - cbor/json: CborOptimizedCodecs.cborMapCodec/cborJMapCodec, OptGenKeyCodec.fromKeyCodec/noKeyCodec, CborAdtMetadata.codec, RawCbor.codec, WrappedJson.codec - misc: BoxingUnboxing instances, TypeString/JavaClassName instances + materialize, SealedUtils.evidence + OrderedEnum.ordering, Timestamp.ordering, ValueOf.fromScala, AnnotationOf/ApplierUnapplier/Delegation/SamCompanion/SimpleClassName/SourceInfo/SelfInstance materialize stubs - meta: MacroInstances.materialize, MetadataCompanion.fromFallback/lazyMetadata/notFound (+ BoundedMetadataCompanion), OptionLike.optionOptionLike etc., AutoOptionalParams.allAutoOptionalParams - mongo: EntityIdMode/ObjectIdWrapperCompanion call sites updated for given-method-application syntax (`GenCodec.fromTransparentWrapping(using …)`) - tuples: TupleDerivation.tupleNInstances Extension-shim `implicit def Xops(...)` patterns left in place — they belong to slice 3.1 (`implicit class → extension`) which is staged off `upstream/scala-3` independently. `OptArg.argToOptArg`, `GenRef.fun2GenRef`, and `Implicits.scala` deliberately untouched. --- .../commons/meta/MacroInstances.scala | 2 +- .../commons/meta/MetadataCompanion.scala | 16 ++-- .../avsystem/commons/meta/OptionLike.scala | 14 ++-- .../avsystem/commons/misc/AnnotationOf.scala | 14 ++-- .../commons/misc/ApplierUnapplier.scala | 6 +- .../commons/misc/BoxingUnboxing.scala | 36 ++++---- .../avsystem/commons/misc/Delegation.scala | 2 +- .../avsystem/commons/misc/SamCompanion.scala | 2 +- .../avsystem/commons/misc/SealedUtils.scala | 6 +- .../avsystem/commons/misc/SelfInstance.scala | 2 +- .../commons/misc/SimpleClassName.scala | 2 +- .../avsystem/commons/misc/SourceInfo.scala | 2 +- .../com/avsystem/commons/misc/Timestamp.scala | 2 +- .../avsystem/commons/misc/TypeString.scala | 40 ++++----- .../com/avsystem/commons/misc/ValueOf.scala | 4 +- .../commons/serialization/GenCodec.scala | 74 ++++++++--------- .../commons/serialization/GenKeyCodec.scala | 50 +++++------ .../serialization/GenObjectCodec.scala | 2 +- .../commons/serialization/HasGenCodec.scala | 32 +++---- .../serialization/SerializationName.scala | 6 +- .../TransparentWrapperCompanion.scala | 4 +- .../serialization/TupleGenCodecs.scala | 82 +++++++++--------- .../serialization/cbor/CborAdtMetadata.scala | 2 +- .../cbor/CborOptimizedCodecs.scala | 28 ++++--- .../commons/serialization/cbor/RawCbor.scala | 2 +- .../serialization/json/WrappedJson.scala | 2 +- .../commons/tuples/TupleDerivation.scala | 83 +++++++++---------- .../commons/mongo/typed/EntityIdMode.scala | 2 +- .../typed/ObjectIdWrapperCompanion.scala | 2 +- 29 files changed, 261 insertions(+), 260 deletions(-) diff --git a/core/src/main/scala/com/avsystem/commons/meta/MacroInstances.scala b/core/src/main/scala/com/avsystem/commons/meta/MacroInstances.scala index b8a221e11..b90e7042b 100644 --- a/core/src/main/scala/com/avsystem/commons/meta/MacroInstances.scala +++ b/core/src/main/scala/com/avsystem/commons/meta/MacroInstances.scala @@ -45,5 +45,5 @@ object MacroInstances { final class materializeWith(prefix: Any, materializer: String = "materialize") extends StaticAnnotation // TODO[scala3-port]: materialize (Scala 2 macro def) (L) - implicit def materialize[Implicits, Instances]: MacroInstances[Implicits, Instances] = ??? + given materialize[Implicits, Instances]: MacroInstances[Implicits, Instances] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/meta/MetadataCompanion.scala b/core/src/main/scala/com/avsystem/commons/meta/MetadataCompanion.scala index 9c59d6268..61518c97c 100644 --- a/core/src/main/scala/com/avsystem/commons/meta/MetadataCompanion.scala +++ b/core/src/main/scala/com/avsystem/commons/meta/MetadataCompanion.scala @@ -13,9 +13,9 @@ import scala.annotation.implicitNotFound * metadata class constructor */ trait MetadataCompanion[M[_]] { - final def apply[Real](implicit metadata: M[Real]): M[Real] = metadata + final def apply[Real](using metadata: M[Real]): M[Real] = metadata - implicit final def fromFallback[Real](implicit fallback: Fallback[M[Real]]): M[Real] = fallback.value + given fromFallback[Real](using fallback: Fallback[M[Real]]): M[Real] = fallback.value final class Lazy[Real](metadata: => M[Real]) { lazy val value: M[Real] = metadata @@ -25,10 +25,10 @@ trait MetadataCompanion[M[_]] { // macro effectively turns `metadata` param into by-name param (implicit params by themselves cannot be by-name) // TODO[scala3-port]: lazyMetadata (Scala 2 macro def) (L) - implicit def lazyMetadata[Real](implicit metadata: M[Real]): Lazy[Real] = ??? + given lazyMetadata[Real](using metadata: M[Real]): Lazy[Real] = ??? @implicitNotFound("#{forNotLazy}") - implicit def notFound[T](implicit forNotLazy: ImplicitNotFound[M[T]]): ImplicitNotFound[Lazy[T]] = + given notFound[T](using forNotLazy: ImplicitNotFound[M[T]]): ImplicitNotFound[Lazy[T]] = ImplicitNotFound() } } @@ -44,9 +44,9 @@ trait MetadataCompanion[M[_]] { */ // cannot share code with MetadataCompanion because of binary compatibility problems, must copy trait BoundedMetadataCompanion[Hi, Lo <: Hi, M[_ >: Lo <: Hi]] { - final def apply[Real >: Lo <: Hi](implicit metadata: M[Real]): M[Real] = metadata + final def apply[Real >: Lo <: Hi](using metadata: M[Real]): M[Real] = metadata - implicit final def fromFallback[Real >: Lo <: Hi](implicit fallback: Fallback[M[Real]]): M[Real] = fallback.value + given fromFallback[Real >: Lo <: Hi](using fallback: Fallback[M[Real]]): M[Real] = fallback.value final class Lazy[Real >: Lo <: Hi](metadata: => M[Real]) { lazy val value: M[Real] = metadata @@ -56,10 +56,10 @@ trait BoundedMetadataCompanion[Hi, Lo <: Hi, M[_ >: Lo <: Hi]] { // macro effectively turns `metadata` param into by-name param (implicit params by themselves cannot be by-name) // TODO[scala3-port]: lazyMetadata (bounded) (Scala 2 macro def) (L) - implicit def lazyMetadata[Real >: Lo <: Hi](implicit metadata: M[Real]): Lazy[Real] = ??? + given lazyMetadata[Real >: Lo <: Hi](using metadata: M[Real]): Lazy[Real] = ??? @implicitNotFound("#{forNotLazy}") - implicit def notFound[T >: Lo <: Hi](implicit forNotLazy: ImplicitNotFound[M[T]]): ImplicitNotFound[Lazy[T]] = + given notFound[T >: Lo <: Hi](using forNotLazy: ImplicitNotFound[M[T]]): ImplicitNotFound[Lazy[T]] = ImplicitNotFound() } } diff --git a/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala b/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala index 6632da8cf..43c0114c9 100644 --- a/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala +++ b/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala @@ -53,19 +53,19 @@ final class OptionLikeImpl[O, A]( object OptionLike { type Aux[O, V] = OptionLike[O] { type Value = V } - implicit def optionOptionLike[A]: BaseOptionLike[Option[A], A] = + given optionOptionLike[A]: BaseOptionLike[Option[A], A] = new OptionLikeImpl(None, Some(_), _.isDefined, _.get, ignoreNulls = true) - implicit def optOptionLike[A]: BaseOptionLike[Opt[A], A] = + given optOptionLike[A]: BaseOptionLike[Opt[A], A] = new OptionLikeImpl(Opt.Empty, Opt.some, _.isDefined, _.get, ignoreNulls = true) - implicit def optRefOptionLike[A >: Null]: BaseOptionLike[OptRef[A], A] = + given optRefOptionLike[A >: Null]: BaseOptionLike[OptRef[A], A] = new OptionLikeImpl(OptRef.Empty, OptRef.some, _.isDefined, _.get, ignoreNulls = true) - implicit def optArgOptionLike[A]: BaseOptionLike[OptArg[A], A] = + given optArgOptionLike[A]: BaseOptionLike[OptArg[A], A] = new OptionLikeImpl(OptArg.Empty, OptArg.some, _.isDefined, _.get, ignoreNulls = true) - implicit def nOptOptionLike[A]: BaseOptionLike[NOpt[A], A] = + given nOptOptionLike[A]: BaseOptionLike[NOpt[A], A] = new OptionLikeImpl(NOpt.Empty, NOpt.some, _.isDefined, _.get, ignoreNulls = false) } @@ -82,8 +82,8 @@ object AutoOptionalParam { } trait AutoOptionalParams { - implicit def allAutoOptionalParams[T]( - implicit optionLike: OptionLike[T] + given allAutoOptionalParams[T](using + optionLike: OptionLike[T] ): AutoOptionalParam[T] = AutoOptionalParam[T] } object AutoOptionalParams extends AutoOptionalParams diff --git a/core/src/main/scala/com/avsystem/commons/misc/AnnotationOf.scala b/core/src/main/scala/com/avsystem/commons/misc/AnnotationOf.scala index 217e35604..0cc5c9ab5 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/AnnotationOf.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/AnnotationOf.scala @@ -10,7 +10,7 @@ import scala.annotation.implicitNotFound case class AnnotationOf[A, T](annot: A) extends AnyVal object AnnotationOf { // TODO[scala3-port]: AnnotationOf.materialize (Scala 2 macro def) (L) - implicit def materialize[A, T]: AnnotationOf[A, T] = ??? + given materialize[A, T]: AnnotationOf[A, T] = ??? } /** A typeclass which captures a possible annotation of type `A` applied on a class/trait/object associated with type @@ -20,7 +20,7 @@ object AnnotationOf { case class OptAnnotationOf[A, T](annotOpt: Opt[A]) object OptAnnotationOf { // TODO[scala3-port]: OptAnnotationOf.materialize (Scala 2 macro def) (L) - implicit def materialize[A, T]: OptAnnotationOf[A, T] = ??? + given materialize[A, T]: OptAnnotationOf[A, T] = ??? } /** A typeclass which captures all annotations of type `A` applied on a class/trait/object associated with type `T`. @@ -29,7 +29,7 @@ object OptAnnotationOf { case class AnnotationsOf[A, T](annots: List[A]) extends AnyVal object AnnotationsOf { // TODO[scala3-port]: AnnotationsOf.materialize (Scala 2 macro def) (L) - implicit def materialize[A, T]: AnnotationsOf[A, T] = ??? + given materialize[A, T]: AnnotationsOf[A, T] = ??? } /** A typeclass which serves as an evidence that an annotation of type `A` is applied on a class/trait/object associated @@ -44,7 +44,7 @@ object HasAnnotation { def create[A, T]: HasAnnotation[A, T] = reusable.asInstanceOf[HasAnnotation[A, T]] // TODO[scala3-port]: HasAnnotation.materialize (Scala 2 macro def) (L) - implicit def materialize[A, T]: HasAnnotation[A, T] = ??? + given materialize[A, T]: HasAnnotation[A, T] = ??? } /** A typeclass which may be used in an implicit constructor parameter of an abstract class. Captures an annotation of @@ -67,7 +67,7 @@ object HasAnnotation { case class SelfAnnotation[A](annot: A) extends AnyVal object SelfAnnotation { // TODO[scala3-port]: SelfAnnotation.materialize (Scala 2 macro def) (L) - implicit def materialize[A]: SelfAnnotation[A] = ??? + given materialize[A]: SelfAnnotation[A] = ??? } /** A typeclass which may be used in an implicit constructor parameter of an abstract class. Captures a possible @@ -90,7 +90,7 @@ object SelfAnnotation { case class SelfOptAnnotation[A](annotOpt: Opt[A]) object SelfOptAnnotation { // TODO[scala3-port]: SelfOptAnnotation.materialize (Scala 2 macro def) (L) - implicit def materialize[A]: SelfOptAnnotation[A] = ??? + given materialize[A]: SelfOptAnnotation[A] = ??? } /** A typeclass which may be used in an implicit constructor parameter of an abstract class. Captures all annotations of @@ -112,5 +112,5 @@ object SelfOptAnnotation { case class SelfAnnotations[A](annots: List[A]) extends AnyVal object SelfAnnotations { // TODO[scala3-port]: SelfAnnotations.materialize (Scala 2 macro def) (L) - implicit def materialize[A]: SelfAnnotations[A] = ??? + given materialize[A]: SelfAnnotations[A] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/ApplierUnapplier.scala b/core/src/main/scala/com/avsystem/commons/misc/ApplierUnapplier.scala index bce4dd2dc..3f0e5734a 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/ApplierUnapplier.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/ApplierUnapplier.scala @@ -11,7 +11,7 @@ trait Applier[T] { } object Applier { // TODO[scala3-port]: Applier.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: Applier[T] = ??? + given materialize[T]: Applier[T] = ??? } /** Typeclass which captures case class `unapply`/`unapplySeq` method in a raw form that returns untyped sequence of @@ -23,7 +23,7 @@ trait Unapplier[T] { } object Unapplier { // TODO[scala3-port]: Unapplier.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: Unapplier[T] = ??? + given materialize[T]: Unapplier[T] = ??? } class ProductUnapplier[T <: Product] extends Unapplier[T] { @@ -35,5 +35,5 @@ abstract class ProductApplierUnapplier[T <: Product] extends ProductUnapplier[T] trait ApplierUnapplier[T] extends Applier[T] with Unapplier[T] object ApplierUnapplier { // TODO[scala3-port]: ApplierUnapplier.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: ApplierUnapplier[T] = ??? + given materialize[T]: ApplierUnapplier[T] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala b/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala index 7550a6150..2a92ba25e 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala @@ -3,32 +3,32 @@ package misc case class Boxing[-A, +B](fun: A => B) extends AnyVal object Boxing extends LowPrioBoxing { - def fromImplicitConv[A, B](implicit conv: A => B): Boxing[A, B] = Boxing(conv) + def fromImplicitConv[A, B](using conv: A => B): Boxing[A, B] = Boxing(conv) - implicit val BooleanBoxing: Boxing[Boolean, JBoolean] = fromImplicitConv - implicit val ByteBoxing: Boxing[Byte, JByte] = fromImplicitConv - implicit val ShortBoxing: Boxing[Short, JShort] = fromImplicitConv - implicit val IntBoxing: Boxing[Int, JInteger] = fromImplicitConv - implicit val LongBoxing: Boxing[Long, JLong] = fromImplicitConv - implicit val FloatBoxing: Boxing[Float, JFloat] = fromImplicitConv - implicit val DoubleBoxing: Boxing[Double, JDouble] = fromImplicitConv + given Boxing[Boolean, JBoolean] = fromImplicitConv + given Boxing[Byte, JByte] = fromImplicitConv + given Boxing[Short, JShort] = fromImplicitConv + given Boxing[Int, JInteger] = fromImplicitConv + given Boxing[Long, JLong] = fromImplicitConv + given Boxing[Float, JFloat] = fromImplicitConv + given Boxing[Double, JDouble] = fromImplicitConv } trait LowPrioBoxing { this: Boxing.type => - implicit def nullableBoxing[A >: Null]: Boxing[A, A] = Boxing(identity) + given nullableBoxing[A >: Null]: Boxing[A, A] = Boxing(identity) } case class Unboxing[+A, -B](fun: B => A) extends AnyVal object Unboxing extends LowPrioUnboxing { - def fromImplicitConv[A, B](implicit conv: B => A): Unboxing[A, B] = Unboxing(conv) + def fromImplicitConv[A, B](using conv: B => A): Unboxing[A, B] = Unboxing(conv) - implicit val BooleanUnboxing: Unboxing[Boolean, JBoolean] = fromImplicitConv - implicit val ByteUnboxing: Unboxing[Byte, JByte] = fromImplicitConv - implicit val ShortUnboxing: Unboxing[Short, JShort] = fromImplicitConv - implicit val IntUnboxing: Unboxing[Int, JInteger] = fromImplicitConv - implicit val LongUnboxing: Unboxing[Long, JLong] = fromImplicitConv - implicit val FloatUnboxing: Unboxing[Float, JFloat] = fromImplicitConv - implicit val DoubleUnboxing: Unboxing[Double, JDouble] = fromImplicitConv + given Unboxing[Boolean, JBoolean] = fromImplicitConv + given Unboxing[Byte, JByte] = fromImplicitConv + given Unboxing[Short, JShort] = fromImplicitConv + given Unboxing[Int, JInteger] = fromImplicitConv + given Unboxing[Long, JLong] = fromImplicitConv + given Unboxing[Float, JFloat] = fromImplicitConv + given Unboxing[Double, JDouble] = fromImplicitConv } trait LowPrioUnboxing { this: Unboxing.type => - implicit def nullableUnboxing[A >: Null]: Unboxing[A, A] = Unboxing(identity) + given nullableUnboxing[A >: Null]: Unboxing[A, A] = Unboxing(identity) } diff --git a/core/src/main/scala/com/avsystem/commons/misc/Delegation.scala b/core/src/main/scala/com/avsystem/commons/misc/Delegation.scala index dcd8f8e24..7e35b2300 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/Delegation.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/Delegation.scala @@ -9,7 +9,7 @@ trait Delegation[A, B] { object Delegation { // TODO[scala3-port]: materializeDelegation (Scala 2 macro def) (L) - implicit def materializeDelegation[A, B]: Delegation[A, B] = ??? + given materializeDelegation[A, B]: Delegation[A, B] = ??? /** Provides following syntax: * diff --git a/core/src/main/scala/com/avsystem/commons/misc/SamCompanion.scala b/core/src/main/scala/com/avsystem/commons/misc/SamCompanion.scala index 5af10fb82..27dec936f 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SamCompanion.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SamCompanion.scala @@ -17,6 +17,6 @@ object SamCompanion { object ValidSam { // TODO[scala3-port]: isValidSam (Scala 2 macro def) (L) - implicit def isValidSam[T, F]: ValidSam[T, F] = ??? + given isValidSam[T, F]: ValidSam[T, F] = ??? } } diff --git a/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala b/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala index 917b4be4a..7a2e282d2 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala @@ -31,9 +31,9 @@ object SealedUtils { */ trait SealedEnumCompanion[T] { - /** Thanks to this implicit, [[SealedEnumCompanion]] and its subtraits can be used as typeclasses. + /** Thanks to this given, [[SealedEnumCompanion]] and its subtraits can be used as typeclasses. */ - implicit def evidence: this.type = this + given evidence: this.type = this /** Holds a list of all case objects of a sealed trait or class `T`. This must be implemented separately for every * sealed enum, but can be implemented simply by using the [[caseObjects]] macro. It's important to *always* state @@ -153,7 +153,7 @@ object OrderedEnum { private object reusableOrdering extends Ordering[OrderedEnum] { def compare(x: OrderedEnum, y: OrderedEnum) = Integer.compare(x.sourceInfo.offset, y.sourceInfo.offset) } - implicit def ordering[T <: OrderedEnum]: Ordering[T] = + given ordering[T <: OrderedEnum]: Ordering[T] = reusableOrdering.asInstanceOf[Ordering[T]] } diff --git a/core/src/main/scala/com/avsystem/commons/misc/SelfInstance.scala b/core/src/main/scala/com/avsystem/commons/misc/SelfInstance.scala index 829b9fef4..3d0562992 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SelfInstance.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SelfInstance.scala @@ -5,5 +5,5 @@ package misc case class SelfInstance[C[_]](instance: C[Any]) object SelfInstance { // TODO[scala3-port]: SelfInstance.materialize (Scala 2 macro def) (L) - implicit def materialize[C[_]]: SelfInstance[C] = ??? + given materialize[C[_]]: SelfInstance[C] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/SimpleClassName.scala b/core/src/main/scala/com/avsystem/commons/misc/SimpleClassName.scala index 8d1a5fa17..a3a5cffea 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SimpleClassName.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SimpleClassName.scala @@ -6,5 +6,5 @@ object SimpleClassName { def of[T](implicit scn: SimpleClassName[T]): String = scn.name // TODO[scala3-port]: SimpleClassName.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: SimpleClassName[T] = ??? + given materialize[T]: SimpleClassName[T] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/SourceInfo.scala b/core/src/main/scala/com/avsystem/commons/misc/SourceInfo.scala index bf418c3a2..dbf69059d 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SourceInfo.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SourceInfo.scala @@ -26,5 +26,5 @@ object SourceInfo { def apply()(implicit si: SourceInfo): SourceInfo = si // TODO[scala3-port]: SourceInfo.here (Scala 2 macro def) (L) - implicit def here: SourceInfo = ??? + given here: SourceInfo = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/Timestamp.scala b/core/src/main/scala/com/avsystem/commons/misc/Timestamp.scala index 5b7be55c1..46c44b2ed 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/Timestamp.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/Timestamp.scala @@ -54,6 +54,6 @@ object Timestamp { implicit def conversions(tstamp: Timestamp): TimestampConversions = new TimestampConversions(tstamp.millis) - implicit val ordering: Ordering[Timestamp] = + given ordering: Ordering[Timestamp] = Ordering.by(_.millis) } diff --git a/core/src/main/scala/com/avsystem/commons/misc/TypeString.scala b/core/src/main/scala/com/avsystem/commons/misc/TypeString.scala index a4de4ac93..f9511f919 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/TypeString.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/TypeString.scala @@ -25,16 +25,16 @@ class TypeString[T](val value: String) extends AnyVal { override def toString: String = value } object TypeString { - def apply[T](implicit ts: TypeString[T]): TypeString[T] = ts + def apply[T](using ts: TypeString[T]): TypeString[T] = ts def of[T: TypeString]: String = TypeString[T].value // TODO[scala3-port]: TypeString.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: TypeString[T] = ??? + given materialize[T]: TypeString[T] = ??? - implicit val keyCodec: GenKeyCodec[TypeString[_]] = + given keyCodec: GenKeyCodec[TypeString[_]] = GenKeyCodec.create[TypeString[_]](new TypeString(_), _.value) - implicit val codec: GenCodec[TypeString[_]] = + given codec: GenCodec[TypeString[_]] = GenCodec.nonNullSimple[TypeString[_]](i => new TypeString(i.readString()), (o, ts) => o.writeString(ts.value)) } @@ -48,22 +48,22 @@ class JavaClassName[T](val value: String) extends AnyVal { override def toString: String = value } object JavaClassName extends JavaClassNameLowPrio { - def apply[T](implicit ts: JavaClassName[T]): JavaClassName[T] = ts + def apply[T](using ts: JavaClassName[T]): JavaClassName[T] = ts def of[T: JavaClassName]: String = JavaClassName[T].value - implicit val NothingClassName: JavaClassName[Nothing] = new JavaClassName("scala.runtime.Nothing$") - implicit val NothingArrayClassName: JavaClassName[Array[Nothing]] = new JavaClassName("[Lscala.runtime.Nothing$;") - implicit val UnitClassName: JavaClassName[Unit] = new JavaClassName("void") - implicit val BooleanClassName: JavaClassName[Boolean] = new JavaClassName("boolean") - implicit val ByteClassName: JavaClassName[Byte] = new JavaClassName("byte") - implicit val ShortClassName: JavaClassName[Short] = new JavaClassName("short") - implicit val IntClassName: JavaClassName[Int] = new JavaClassName("int") - implicit val LongClassName: JavaClassName[Long] = new JavaClassName("long") - implicit val FloatClassName: JavaClassName[Float] = new JavaClassName("float") - implicit val DoubleClassName: JavaClassName[Double] = new JavaClassName("double") - implicit val CharClassName: JavaClassName[Char] = new JavaClassName("char") + given NothingClassName: JavaClassName[Nothing] = new JavaClassName("scala.runtime.Nothing$") + given NothingArrayClassName: JavaClassName[Array[Nothing]] = new JavaClassName("[Lscala.runtime.Nothing$;") + given UnitClassName: JavaClassName[Unit] = new JavaClassName("void") + given BooleanClassName: JavaClassName[Boolean] = new JavaClassName("boolean") + given ByteClassName: JavaClassName[Byte] = new JavaClassName("byte") + given ShortClassName: JavaClassName[Short] = new JavaClassName("short") + given IntClassName: JavaClassName[Int] = new JavaClassName("int") + given LongClassName: JavaClassName[Long] = new JavaClassName("long") + given FloatClassName: JavaClassName[Float] = new JavaClassName("float") + given DoubleClassName: JavaClassName[Double] = new JavaClassName("double") + given CharClassName: JavaClassName[Char] = new JavaClassName("char") - implicit def arrayClassName[T: JavaClassName]: JavaClassName[Array[T]] = { + given arrayClassName[T: JavaClassName]: JavaClassName[Array[T]] = { val elementName = JavaClassName.of[T] match { case "void" => "Lscala.runtime.BoxedUnit;" case "boolean" => "Z" @@ -80,13 +80,13 @@ object JavaClassName extends JavaClassNameLowPrio { new JavaClassName("[" + elementName) } - implicit val keyCodec: GenKeyCodec[JavaClassName[_]] = + given keyCodec: GenKeyCodec[JavaClassName[_]] = GenKeyCodec.create[JavaClassName[_]](new JavaClassName(_), _.value) - implicit val codec: GenCodec[JavaClassName[_]] = + given codec: GenCodec[JavaClassName[_]] = GenCodec.nonNullSimple[JavaClassName[_]](i => new JavaClassName(i.readString()), (o, ts) => o.writeString(ts.value)) } trait JavaClassNameLowPrio { this: JavaClassName.type => // TODO[scala3-port]: JavaClassName.materialize (Scala 2 macro def) (L) - implicit def materialize[T]: JavaClassName[T] = ??? + given materialize[T]: JavaClassName[T] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/misc/ValueOf.scala b/core/src/main/scala/com/avsystem/commons/misc/ValueOf.scala index c07b04fff..aabf5dae3 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/ValueOf.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/ValueOf.scala @@ -17,8 +17,8 @@ class ValueOf[T](val value: T) extends AnyVal { @nowarn("msg=deprecated") object ValueOf { @deprecated("Use scala.valueOf[T] from the standard library (available since Scala 2.13)", "2.28.0") - def apply[T](implicit vof: ValueOf[T]): T = vof.value + def apply[T](using vof: ValueOf[T]): T = vof.value @deprecated("Use scala.ValueOf[T] from the standard library (available since Scala 2.13)", "2.28.0") - implicit def fromScala[T](implicit vof: scala.ValueOf[T]): ValueOf[T] = new ValueOf[T](vof.value) + given fromScala[T](using vof: scala.ValueOf[T]): ValueOf[T] = new ValueOf[T](vof.value) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala index 97c3eef3b..1fc3434a3 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala @@ -307,7 +307,7 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { def nullable: Boolean = wrapped.nullable } - implicit def fromTransparentWrapping[R, T](implicit tw: TransparentWrapping[R, T], wrapped: OOOFieldsObjectCodec[R]) + given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrapped: OOOFieldsObjectCodec[R]) : OOOFieldsObjectCodec[T] = new Transformed(wrapped, tw.unwrap, tw.wrap) } @@ -467,7 +467,7 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { } } - implicit def arrayCodec[T: ClassTag: GenCodec]: GenCodec[Array[T]] = + given arrayCodec[T: ClassTag: GenCodec]: GenCodec[Array[T]] = nullableList[Array[T]]( _.iterator(read[T]).toArray[T], (lo, arr) => { @@ -483,58 +483,58 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { // these are covered by the generic `seqCodec` and `setCodec` but making them explicit may be easier // for the compiler and also make IntelliJ less confused - implicit def bseqCodec[T: GenCodec]: GenCodec[BSeq[T]] = - seqCodec[BSeq, T](using GenCodec[T], implicitly[Factory[T, List[T]]]) - implicit def iseqCodec[T: GenCodec]: GenCodec[ISeq[T]] = - seqCodec[ISeq, T](using GenCodec[T], implicitly[Factory[T, List[T]]]) - implicit def mseqCodec[T: GenCodec]: GenCodec[MSeq[T]] = seqCodec[MSeq, T] - implicit def bindexedSeqCodec[T: GenCodec]: GenCodec[BIndexedSeq[T]] = seqCodec[BIndexedSeq, T] - implicit def iindexedSeqCodec[T: GenCodec]: GenCodec[IIndexedSeq[T]] = seqCodec[IIndexedSeq, T] - implicit def mindexedSeqCodec[T: GenCodec]: GenCodec[MIndexedSeq[T]] = seqCodec[MIndexedSeq, T] - implicit def listCodec[T: GenCodec]: GenCodec[List[T]] = seqCodec[List, T] - implicit def vectorCodec[T: GenCodec]: GenCodec[Vector[T]] = seqCodec[Vector, T] - implicit def bsetCodec[T: GenCodec]: GenCodec[BSet[T]] = setCodec[BSet, T] - implicit def isetCodec[T: GenCodec]: GenCodec[ISet[T]] = setCodec[ISet, T] - implicit def msetCodec[T: GenCodec]: GenCodec[MSet[T]] = setCodec[MSet, T] - implicit def ihashSetCodec[T: GenCodec]: GenCodec[IHashSet[T]] = setCodec[IHashSet, T] - implicit def mhashSetCodec[T: GenCodec]: GenCodec[MHashSet[T]] = setCodec[MHashSet, T] + given bseqCodec[T: GenCodec]: GenCodec[BSeq[T]] = + seqCodec[BSeq, T](using GenCodec[T], summon[Factory[T, List[T]]]) + given iseqCodec[T: GenCodec]: GenCodec[ISeq[T]] = + seqCodec[ISeq, T](using GenCodec[T], summon[Factory[T, List[T]]]) + given mseqCodec[T: GenCodec]: GenCodec[MSeq[T]] = seqCodec[MSeq, T] + given bindexedSeqCodec[T: GenCodec]: GenCodec[BIndexedSeq[T]] = seqCodec[BIndexedSeq, T] + given iindexedSeqCodec[T: GenCodec]: GenCodec[IIndexedSeq[T]] = seqCodec[IIndexedSeq, T] + given mindexedSeqCodec[T: GenCodec]: GenCodec[MIndexedSeq[T]] = seqCodec[MIndexedSeq, T] + given listCodec[T: GenCodec]: GenCodec[List[T]] = seqCodec[List, T] + given vectorCodec[T: GenCodec]: GenCodec[Vector[T]] = seqCodec[Vector, T] + given bsetCodec[T: GenCodec]: GenCodec[BSet[T]] = setCodec[BSet, T] + given isetCodec[T: GenCodec]: GenCodec[ISet[T]] = setCodec[ISet, T] + given msetCodec[T: GenCodec]: GenCodec[MSet[T]] = setCodec[MSet, T] + given ihashSetCodec[T: GenCodec]: GenCodec[IHashSet[T]] = setCodec[IHashSet, T] + given mhashSetCodec[T: GenCodec]: GenCodec[MHashSet[T]] = setCodec[MHashSet, T] // seqCodec, setCodec, jCollectionCodec, mapCodec, jMapCodec, fallbackMapCodec and fallbackJMapCodec // have these weird return types (e.g. GenCodec[C[T] with BSeq[T]] instead of just GenCodec[C[T]]) because it's a // workaround for https://groups.google.com/forum/#!topic/scala-user/O_fkaChTtg4 - implicit def seqCodec[C[X] <: BSeq[X], T: GenCodec]( - implicit fac: Factory[T, C[T]] + given seqCodec[C[X] <: BSeq[X], T: GenCodec](using + fac: Factory[T, C[T]] ): GenCodec[C[T] with BSeq[T]] = nullableList[C[T] with BSeq[T]](_.collectTo[T, C[T]], (lo, c) => c.writeToList(lo)) - implicit def setCodec[C[X] <: BSet[X], T: GenCodec]( - implicit fac: Factory[T, C[T]] + given setCodec[C[X] <: BSet[X], T: GenCodec](using + fac: Factory[T, C[T]] ): GenCodec[C[T] with BSet[T]] = nullableList[C[T] with BSet[T]](_.collectTo[T, C[T]], (lo, c) => c.writeToList(lo)) - implicit def jCollectionCodec[C[X] <: JCollection[X], T: GenCodec]( - implicit cbf: JFactory[T, C[T]] + given jCollectionCodec[C[X] <: JCollection[X], T: GenCodec](using + cbf: JFactory[T, C[T]] ): GenCodec[C[T] with JCollection[T]] = nullableList[C[T]](_.collectTo[T, C[T]], (lo, c) => c.asScala.writeToList(lo)) - implicit def mapCodec[M[X, Y] <: BMap[X, Y], K: GenKeyCodec, V: GenCodec]( - implicit fac: Factory[(K, V), M[K, V]] + given mapCodec[M[X, Y] <: BMap[X, Y], K: GenKeyCodec, V: GenCodec](using + fac: Factory[(K, V), M[K, V]] ): GenObjectCodec[M[K, V]] = nullableObject[M[K, V]]( _.collectTo[K, V, M[K, V]], (oo, value) => value.writeToObject(oo), ) - implicit def jMapCodec[M[X, Y] <: JMap[X, Y], K: GenKeyCodec, V: GenCodec]( - implicit cbf: JFactory[(K, V), M[K, V]] + given jMapCodec[M[X, Y] <: JMap[X, Y], K: GenKeyCodec, V: GenCodec](using + cbf: JFactory[(K, V), M[K, V]] ): GenObjectCodec[M[K, V]] = nullableObject[M[K, V]]( _.collectTo[K, V, M[K, V]], (oo, value) => value.asScala.writeToObject(oo), ) - implicit def optionCodec[T: GenCodec]: GenCodec[Option[T]] = create[Option[T]]( + given optionCodec[T: GenCodec]: GenCodec[Option[T]] = create[Option[T]]( input => if (input.legacyOptionEncoding) { val li = input.readList() @@ -555,10 +555,10 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { }, ) - implicit def nOptCodec[T: GenCodec]: GenCodec[NOpt[T]] = + given nOptCodec[T: GenCodec]: GenCodec[NOpt[T]] = new Transformed[NOpt[T], Option[T]](optionCodec[T], _.toOption, _.toNOpt) - implicit def optCodec[T: GenCodec]: GenCodec[Opt[T]] = + given optCodec[T: GenCodec]: GenCodec[Opt[T]] = create[Opt[T]]( i => if (i.readNull()) Opt.Empty else Opt(read[T](i)), (o, vo) => @@ -568,13 +568,13 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { }, ) - implicit def optArgCodec[T: GenCodec]: GenCodec[OptArg[T]] = + given optArgCodec[T: GenCodec]: GenCodec[OptArg[T]] = new Transformed[OptArg[T], Opt[T]](optCodec[T], _.toOpt, _.toOptArg) - implicit def optRefCodec[T >: Null: GenCodec]: GenCodec[OptRef[T]] = + given optRefCodec[T >: Null: GenCodec]: GenCodec[OptRef[T]] = new Transformed[OptRef[T], Opt[T]](optCodec[T], _.toOpt, _.toOptRef) - implicit def eitherCodec[A: GenCodec, B: GenCodec]: GenCodec[Either[A, B]] = nullableObject( + given eitherCodec[A: GenCodec, B: GenCodec]: GenCodec[Either[A, B]] = nullableObject( oi => { val fi = oi.nextField() fi.fieldName match { @@ -592,17 +592,17 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { }, ) - implicit def jEnumCodec[E <: Enum[E]: ClassTag]: GenCodec[E] = nullableSimple( + given jEnumCodec[E <: Enum[E]: ClassTag]: GenCodec[E] = nullableSimple( in => Enum.valueOf(classTag[E].runtimeClass.asInstanceOf[Class[E]], in.readString()), (out, value) => out.writeString(value.name), ) // Warning! Changing the order of implicit params of this method causes divergent implicit expansion (WTF?) - implicit def fromTransparentWrapping[R, T](implicit tw: TransparentWrapping[R, T], wrappedCodec: GenCodec[R]) + given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrappedCodec: GenCodec[R]) : GenCodec[T] = new Transformed(wrappedCodec, tw.unwrap, tw.wrap) - implicit def fromFallback[T](implicit fallback: Fallback[GenCodec[T]]): GenCodec[T] = + given fromFallback[T](using fallback: Fallback[GenCodec[T]]): GenCodec[T] = fallback.value } @@ -611,5 +611,5 @@ trait RecursiveAutoCodecs { this: GenCodec.type => def materializeRecursively[T]: GenCodec[T] = ??? // TODO[scala3-port]: GenCodec.materializeImplicitly (Scala 2 macro def) (L) - implicit def materializeImplicitly[T](implicit allow: AllowImplicitMacro[GenCodec[T]]): GenCodec[T] = ??? + given materializeImplicitly[T](using allow: AllowImplicitMacro[GenCodec[T]]): GenCodec[T] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala index e57d4f574..8c2812816 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala @@ -60,37 +60,37 @@ object GenKeyCodec { } } - implicit lazy val BooleanKeyCodec: GenKeyCodec[Boolean] = create(_.toBoolean, _.toString) - implicit lazy val CharKeyCodec: GenKeyCodec[Char] = create(_.charAt(0), _.toString) - implicit lazy val ByteKeyCodec: GenKeyCodec[Byte] = create(_.toByte, _.toString) - implicit lazy val ShortKeyCodec: GenKeyCodec[Short] = create(_.toShort, _.toString) - implicit lazy val IntKeyCodec: GenKeyCodec[Int] = create(_.toInt, _.toString) - implicit lazy val LongKeyCodec: GenKeyCodec[Long] = create(_.toLong, _.toString) - implicit lazy val BigIntKeyCodec: GenKeyCodec[BigInt] = create(BigInt(_), _.toString) - - implicit lazy val JBooleanKeyCodec: GenKeyCodec[JBoolean] = create(_.toBoolean, _.toString) - implicit lazy val JCharacterKeyCodec: GenKeyCodec[JCharacter] = create(_.charAt(0), _.toString) - implicit lazy val JByteKeyCodec: GenKeyCodec[JByte] = create(_.toByte, _.toString) - implicit lazy val JShortKeyCodec: GenKeyCodec[JShort] = create(_.toShort, _.toString) - implicit lazy val JIntKeyCodec: GenKeyCodec[JInteger] = create(_.toInt, _.toString) - implicit lazy val JLongKeyCodec: GenKeyCodec[JLong] = create(_.toLong, _.toString) - implicit lazy val JBigIntegerKeyCodec: GenKeyCodec[JBigInteger] = create(new JBigInteger(_), _.toString) - - implicit lazy val StringKeyCodec: GenKeyCodec[String] = create(identity, identity) - implicit lazy val SymbolKeyCodec: GenKeyCodec[Symbol] = create(Symbol(_), _.name) - implicit lazy val UuidCodec: GenKeyCodec[UUID] = create(UUID.fromString, _.toString) - - implicit lazy val TimestampKeyCodec: GenKeyCodec[Timestamp] = GenKeyCodec.create(Timestamp.parse, _.toString) - implicit lazy val BytesKeyCodec: GenKeyCodec[Bytes] = GenKeyCodec.create(Bytes.fromBase64(_), _.base64) - - implicit def jEnumKeyCodec[E <: Enum[E]](implicit ct: ClassTag[E]): GenKeyCodec[E] = + given GenKeyCodec[Boolean] = create(_.toBoolean, _.toString) + given GenKeyCodec[Char] = create(_.charAt(0), _.toString) + given GenKeyCodec[Byte] = create(_.toByte, _.toString) + given GenKeyCodec[Short] = create(_.toShort, _.toString) + given GenKeyCodec[Int] = create(_.toInt, _.toString) + given GenKeyCodec[Long] = create(_.toLong, _.toString) + given GenKeyCodec[BigInt] = create(BigInt(_), _.toString) + + given GenKeyCodec[JBoolean] = create(_.toBoolean, _.toString) + given GenKeyCodec[JCharacter] = create(_.charAt(0), _.toString) + given GenKeyCodec[JByte] = create(_.toByte, _.toString) + given GenKeyCodec[JShort] = create(_.toShort, _.toString) + given GenKeyCodec[JInteger] = create(_.toInt, _.toString) + given GenKeyCodec[JLong] = create(_.toLong, _.toString) + given GenKeyCodec[JBigInteger] = create(new JBigInteger(_), _.toString) + + given GenKeyCodec[String] = create(identity, identity) + given GenKeyCodec[Symbol] = create(Symbol(_), _.name) + given GenKeyCodec[UUID] = create(UUID.fromString, _.toString) + + given GenKeyCodec[Timestamp] = GenKeyCodec.create(Timestamp.parse, _.toString) + given GenKeyCodec[Bytes] = GenKeyCodec.create(Bytes.fromBase64(_), _.base64) + + given jEnumKeyCodec[E <: Enum[E]](using ct: ClassTag[E]): GenKeyCodec[E] = GenKeyCodec.create( string => Enum.valueOf(ct.runtimeClass.asInstanceOf[Class[E]], string), e => e.name(), ) // Warning! Changing the order of implicit params of this method causes divergent implicit expansion (WTF?) - implicit def fromTransparentWrapping[R, T](implicit tw: TransparentWrapping[R, T], wrappedCodec: GenKeyCodec[R]) + given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrappedCodec: GenKeyCodec[R]) : GenKeyCodec[T] = new Transformed(wrappedCodec, tw.unwrap, tw.wrap) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenObjectCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenObjectCodec.scala index 08a0c2260..b1500adb9 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenObjectCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenObjectCodec.scala @@ -53,7 +53,7 @@ object GenObjectCodec { } // Warning! Changing the order of implicit params of this method causes divergent implicit expansion (WTF?) - implicit def fromTransparentWrapping[R, T](implicit tw: TransparentWrapping[R, T], wrappedCodec: GenObjectCodec[R]) + given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrappedCodec: GenObjectCodec[R]) : GenObjectCodec[T] = new Transformed(wrappedCodec, tw.unwrap, tw.wrap) diff --git a/core/src/main/scala/com/avsystem/commons/serialization/HasGenCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/HasGenCodec.scala index c75b3977a..108d0c4f6 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/HasGenCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/HasGenCodec.scala @@ -14,19 +14,19 @@ import scala.annotation.nowarn * etc. */ abstract class HasGenCodec[T](implicit macroCodec: MacroInstances[Unit, () => GenCodec[T]]) { - implicit val codec: GenCodec[T] = macroCodec((), this).apply() + given codec: GenCodec[T] = macroCodec((), this).apply() } /** Like [[HasGenCodec]] but materializes an [[ApplyUnapplyCodec]] instead of just [[GenCodec]]. */ abstract class HasApplyUnapplyCodec[T](implicit macroCodec: MacroInstances[Unit, () => ApplyUnapplyCodec[T]]) { - implicit val codec: ApplyUnapplyCodec[T] = macroCodec((), this).apply() + given codec: ApplyUnapplyCodec[T] = macroCodec((), this).apply() } /** Like [[HasGenCodec]] but materializes a [[GenObjectCodec]] instead of just [[GenCodec]]. */ abstract class HasGenObjectCodec[T](implicit macroCodec: MacroInstances[Unit, () => GenObjectCodec[T]]) { - implicit val codec: GenObjectCodec[T] = macroCodec((), this).apply() + given codec: GenObjectCodec[T] = macroCodec((), this).apply() } /** A version of [[HasGenCodec]] which injects additional implicits into macro materialization. Implicits are imported @@ -41,7 +41,7 @@ abstract class HasGenCodecWithDeps[D, T]( private[serialization] def this(applyUnapplyProvider: ValueOf[D], instances: MacroInstances[D, () => GenCodec[T]]) = this()(instances, applyUnapplyProvider.toScala) - implicit val codec: GenCodec[T] = macroCodec(deps.value, this).apply() + given codec: GenCodec[T] = macroCodec(deps.value, this).apply() } /** A version of [[HasApplyUnapplyCodecWithDeps]] which injects additional implicits into macro materialization. @@ -59,7 +59,7 @@ abstract class HasApplyUnapplyCodecWithDeps[D, T]( instances: MacroInstances[D, () => ApplyUnapplyCodec[T]], ) = this()(instances, applyUnapplyProvider.toScala) - implicit val codec: ApplyUnapplyCodec[T] = macroCodec(deps.value, this).apply() + given codec: ApplyUnapplyCodec[T] = macroCodec(deps.value, this).apply() } /** A version of [[HasGenObjectCodec]] which injects additional implicits into macro materialization. Implicits are @@ -77,7 +77,7 @@ abstract class HasGenObjectCodecWithDeps[D, T]( instances: MacroInstances[D, () => GenObjectCodec[T]], ) = this()(instances, applyUnapplyProvider.toScala) - implicit val codec: GenObjectCodec[T] = macroCodec(deps.value, this).apply() + given codec: GenObjectCodec[T] = macroCodec(deps.value, this).apply() } trait PolyCodec[C[_]] { @@ -87,7 +87,7 @@ trait PolyCodec[C[_]] { /** Like [[HasGenCodec]] but for parameterized (generic) data types. */ abstract class HasPolyGenCodec[C[_]](implicit macroCodec: MacroInstances[Unit, PolyCodec[C]]) { - implicit def codec[T: GenCodec]: GenCodec[C[T]] = macroCodec((), this).codec + given codec[T: GenCodec]: GenCodec[C[T]] = macroCodec((), this).codec } /** A version of [[HasPolyGenCodec]] which injects additional implicits into macro materialization. Implicits are @@ -103,7 +103,7 @@ abstract class HasPolyGenCodecWithDeps[D, C[_]]( private[serialization] def this(applyUnapplyProvider: ValueOf[D], instances: MacroInstances[D, PolyCodec[C]]) = this()(instances, applyUnapplyProvider.toScala) - implicit def codec[T: GenCodec]: GenCodec[C[T]] = macroCodec(deps.value, this).codec + given codec[T: GenCodec]: GenCodec[C[T]] = macroCodec(deps.value, this).codec } trait PolyObjectCodec[C[_]] { @@ -113,7 +113,7 @@ trait PolyObjectCodec[C[_]] { /** Like [[HasGenObjectCodec]] but for parameterized (generic) data types. */ abstract class HasPolyGenObjectCodec[C[_]](implicit macroCodec: MacroInstances[Unit, PolyObjectCodec[C]]) { - implicit def codec[T: GenCodec]: GenObjectCodec[C[T]] = macroCodec((), this).codec + given codec[T: GenCodec]: GenObjectCodec[C[T]] = macroCodec((), this).codec } /** A version of [[HasPolyGenObjectCodec]] which injects additional implicits into macro materialization. Implicits are @@ -129,7 +129,7 @@ abstract class HasPolyGenObjectCodecWithDeps[D, C[_]]( private[serialization] def this(applyUnapplyProvider: ValueOf[D], instances: MacroInstances[D, PolyObjectCodec[C]]) = this()(instances, applyUnapplyProvider.toScala) - implicit def codec[T: GenCodec]: GenObjectCodec[C[T]] = macroCodec(deps.value, this).codec + given codec[T: GenCodec]: GenObjectCodec[C[T]] = macroCodec(deps.value, this).codec } trait GadtCodec[C[_]] { @@ -141,8 +141,8 @@ trait GadtCodec[C[_]] { */ abstract class HasGadtCodec[C[_]](implicit macroCodec: MacroInstances[Unit, GadtCodec[C]]) { // TODO[scala3-port]: C[_] existential narrowed to C[Any] (Scala 3 forbids HKT wildcard application) (S) - implicit lazy val wildcardCodec: GenCodec[C[Any]] = macroCodec((), this).codec[Any].asInstanceOf[GenCodec[C[Any]]] - implicit def codec[T]: GenCodec[C[T]] = wildcardCodec.asInstanceOf[GenCodec[C[T]]] + given wildcardCodec: GenCodec[C[Any]] = macroCodec((), this).codec[Any].asInstanceOf[GenCodec[C[Any]]] + given codec[T]: GenCodec[C[T]] = wildcardCodec.asInstanceOf[GenCodec[C[T]]] } trait RecursiveCodec[T] { @@ -153,7 +153,7 @@ trait RecursiveCodec[T] { /** Like [[HasGenCodec]] but uses [[GenCodec.materializeRecursively]] for materialization. */ abstract class HasRecursiveGenCodec[T](implicit instances: MacroInstances[Unit, RecursiveCodec[T]]) { - implicit lazy val codec: GenCodec[T] = instances((), this).codec + given codec: GenCodec[T] = instances((), this).codec } trait CodecWithKeyCodec[T] { @@ -166,8 +166,8 @@ trait CodecWithKeyCodec[T] { * that wraps exactly one field for which [[GenKeyCodec]] exists. */ abstract class HasGenAndKeyCodec[T](implicit instances: MacroInstances[Unit, CodecWithKeyCodec[T]]) { - implicit lazy val codec: GenCodec[T] = instances((), this).codec - implicit lazy val keyCodec: GenKeyCodec[T] = instances((), this).keyCodec + given codec: GenCodec[T] = instances((), this).codec + given keyCodec: GenKeyCodec[T] = instances((), this).keyCodec } trait AUCodec[AU, T] { @@ -189,6 +189,6 @@ abstract class HasGenCodecFromAU[AU, T]( private[serialization] def this(applyUnapplyProvider: ValueOf[AU], instances: MacroInstances[Unit, AUCodec[AU, T]]) = this()(instances, applyUnapplyProvider.toScala) - implicit final lazy val codec: GenCodec[T] = + given codec: GenCodec[T] = instances((), this).codec(applyUnapplyProvider.value) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/SerializationName.scala b/core/src/main/scala/com/avsystem/commons/serialization/SerializationName.scala index 8b6a9bfe1..4e570d352 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/SerializationName.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/SerializationName.scala @@ -5,12 +5,12 @@ import com.avsystem.commons.misc.{AnnotationOf, SimpleClassName} case class SerializationName[T](name: String) extends AnyVal object SerializationName extends SerializationNameLowPrio { - def of[T](implicit sn: SerializationName[T]): String = sn.name + def of[T](using sn: SerializationName[T]): String = sn.name - implicit def fromNameAnnot[T](implicit nameAnnot: AnnotationOf[name, T]): SerializationName[T] = + given fromNameAnnot[T](using nameAnnot: AnnotationOf[name, T]): SerializationName[T] = SerializationName(nameAnnot.annot.name) } trait SerializationNameLowPrio { this: SerializationName.type => - implicit def fromSimpleClassName[T: SimpleClassName]: SerializationName[T] = + given fromSimpleClassName[T: SimpleClassName]: SerializationName[T] = SerializationName(SimpleClassName.of[T]) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/TransparentWrapperCompanion.scala b/core/src/main/scala/com/avsystem/commons/serialization/TransparentWrapperCompanion.scala index c4298720a..04556ea77 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/TransparentWrapperCompanion.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/TransparentWrapperCompanion.scala @@ -26,7 +26,7 @@ object TransparentWrapping { * [[transparent]] annotation where possible. */ abstract class TransparentWrapperCompanion[R, T] extends TransparentWrapping[R, T] with (R => T) { - implicit def self: TransparentWrapping[R, T] = this + given self: TransparentWrapping[R, T] = this def apply(r: R): T def unapply(t: T): Option[R] @@ -34,7 +34,7 @@ abstract class TransparentWrapperCompanion[R, T] extends TransparentWrapping[R, final def wrap(r: R): T = apply(r) final def unwrap(t: T): R = unapply(t).getOrElse(throw new NoSuchElementException(s"unapply for $t failed")) - implicit def ordering(implicit wrappedOrdering: Ordering[R]): Ordering[T] = + given ordering(using wrappedOrdering: Ordering[R]): Ordering[T] = Ordering.by(unwrap) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala b/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala index da9b9f70a..660fdffe8 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala @@ -5,23 +5,23 @@ trait TupleGenCodecs { this: GenCodec.type => // TODO[scala3-port]: mkTupleCodec (Scala 2 macro def) (L) private def mkTupleCodec[T](elementCodecs: GenCodec[?]*): GenCodec[T] = ??? - implicit def tuple2Codec[T1, T2](implicit r1: GenCodec[T1], r2: GenCodec[T2]): GenCodec[(T1, T2)] = + given tuple2Codec[T1, T2](using r1: GenCodec[T1], r2: GenCodec[T2]): GenCodec[(T1, T2)] = mkTupleCodec(r1, r2) - implicit def tuple3Codec[T1, T2, T3](implicit r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3]) + given tuple3Codec[T1, T2, T3](using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3]) : GenCodec[(T1, T2, T3)] = mkTupleCodec(r1, r2, r3) - implicit def tuple4Codec[T1, T2, T3, T4]( - implicit r1: GenCodec[T1], + given tuple4Codec[T1, T2, T3, T4]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], ): GenCodec[(T1, T2, T3, T4)] = mkTupleCodec(r1, r2, r3, r4) - implicit def tuple5Codec[T1, T2, T3, T4, T5]( - implicit r1: GenCodec[T1], + given tuple5Codec[T1, T2, T3, T4, T5]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -29,8 +29,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5)] = mkTupleCodec(r1, r2, r3, r4, r5) - implicit def tuple6Codec[T1, T2, T3, T4, T5, T6]( - implicit r1: GenCodec[T1], + given tuple6Codec[T1, T2, T3, T4, T5, T6]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -39,8 +39,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6)] = mkTupleCodec(r1, r2, r3, r4, r5, r6) - implicit def tuple7Codec[T1, T2, T3, T4, T5, T6, T7]( - implicit r1: GenCodec[T1], + given tuple7Codec[T1, T2, T3, T4, T5, T6, T7]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -50,8 +50,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7) - implicit def tuple8Codec[T1, T2, T3, T4, T5, T6, T7, T8]( - implicit r1: GenCodec[T1], + given tuple8Codec[T1, T2, T3, T4, T5, T6, T7, T8]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -62,8 +62,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8) - implicit def tuple9Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9]( - implicit r1: GenCodec[T1], + given tuple9Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -75,8 +75,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9) - implicit def tuple10Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]( - implicit r1: GenCodec[T1], + given tuple10Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -89,8 +89,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) - implicit def tuple11Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]( - implicit r1: GenCodec[T1], + given tuple11Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -104,8 +104,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11) - implicit def tuple12Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]( - implicit r1: GenCodec[T1], + given tuple12Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -120,8 +120,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12) - implicit def tuple13Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]( - implicit r1: GenCodec[T1], + given tuple13Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -137,8 +137,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13) - implicit def tuple14Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]( - implicit r1: GenCodec[T1], + given tuple14Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -155,8 +155,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14) - implicit def tuple15Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]( - implicit r1: GenCodec[T1], + given tuple15Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -174,8 +174,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15) - implicit def tuple16Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]( - implicit r1: GenCodec[T1], + given tuple16Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -194,8 +194,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16) - implicit def tuple17Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]( - implicit r1: GenCodec[T1], + given tuple17Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -215,8 +215,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17) - implicit def tuple18Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]( - implicit r1: GenCodec[T1], + given tuple18Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -237,8 +237,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18) - implicit def tuple19Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]( - implicit r1: GenCodec[T1], + given tuple19Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -260,8 +260,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19) - implicit def tuple20Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]( - implicit r1: GenCodec[T1], + given tuple20Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -284,7 +284,7 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20) - implicit def tuple21Codec[ + given tuple21Codec[ T1, T2, T3, @@ -306,8 +306,7 @@ trait TupleGenCodecs { this: GenCodec.type => T19, T20, T21, - ](implicit - r1: GenCodec[T1], + ](using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -331,7 +330,7 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20, r21) - implicit def tuple22Codec[ + given tuple22Codec[ T1, T2, T3, @@ -354,8 +353,7 @@ trait TupleGenCodecs { this: GenCodec.type => T20, T21, T22, - ](implicit - r1: GenCodec[T1], + ](using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], diff --git a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala index b29a238de..0a4e0fbea 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala @@ -267,6 +267,6 @@ abstract class HasPolyCborCodec[C[_]]( ) { private lazy val validatedInstances = instances(CborOptimizedCodecs, this).setup(_.metadata[Nothing].validate()) - implicit def codec[T: GenCodec]: GenObjectCodec[C[T]] = + given codec[T: GenCodec]: GenObjectCodec[C[T]] = validatedInstances.metadata[T].adjustCodec(validatedInstances.stdCodec[T]) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala index e0deb42e2..d295d8518 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala @@ -18,17 +18,23 @@ trait CborOptimizedCodecs { * serialization. If the key type has a `GenKeyCodec` then this `GenCodec` behaves exactly the same as the standard * one for non-CBOR inputs/outputs. */ - implicit def cborMapCodec[M[X, Y] <: BMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec]( - implicit fac: Factory[(K, V), M[K, V]] - ): GenObjectCodec[M[K, V]] = mkMapCodec(implicit keyCodec => GenCodec.mapCodec[M, K, V]) - - implicit def cborJMapCodec[M[X, Y] <: JMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec]( - implicit fac: JFactory[(K, V), M[K, V]] - ): GenObjectCodec[M[K, V]] = mkMapCodec(implicit keyCodec => GenCodec.jMapCodec[M, K, V]) + given cborMapCodec[M[X, Y] <: BMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec](using + fac: Factory[(K, V), M[K, V]] + ): GenObjectCodec[M[K, V]] = mkMapCodec(keyCodec => { + given GenKeyCodec[K] = keyCodec + GenCodec.mapCodec[M, K, V] + }) + + given cborJMapCodec[M[X, Y] <: JMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec](using + fac: JFactory[(K, V), M[K, V]] + ): GenObjectCodec[M[K, V]] = mkMapCodec(keyCodec => { + given GenKeyCodec[K] = keyCodec + GenCodec.jMapCodec[M, K, V] + }) private def mkMapCodec[M[X, Y] <: AnyRef, K: GenCodec: OptGenKeyCodec, V: GenCodec]( mkStdCodec: GenKeyCodec[K] => GenObjectCodec[M[K, V]] - )(implicit fac: Factory[(K, V), M[K, V]] + )(using fac: Factory[(K, V), M[K, V]] ): GenObjectCodec[M[K, V]] = { val hexKeysStdCodec = mkStdCodec(new GenKeyCodec[K] { def read(key: String): K = CborInput.readRawCbor[K](RawCbor.fromHex(key)) @@ -97,10 +103,10 @@ class OOOFieldCborRawKeysCodec[T](stdObjectCodec: OOOFieldsObjectCodec[T], keyCo */ case class OptGenKeyCodec[K](keyCodec: Opt[GenKeyCodec[K]]) object OptGenKeyCodec extends OptGenKeyCodecLowPriority { - def apply[K](implicit optGenKeyCodec: OptGenKeyCodec[K]): OptGenKeyCodec[K] = optGenKeyCodec + def apply[K](using optGenKeyCodec: OptGenKeyCodec[K]): OptGenKeyCodec[K] = optGenKeyCodec - implicit def fromKeyCodec[K: GenKeyCodec]: OptGenKeyCodec[K] = OptGenKeyCodec(Opt(GenKeyCodec[K])) + given fromKeyCodec[K: GenKeyCodec]: OptGenKeyCodec[K] = OptGenKeyCodec(Opt(GenKeyCodec[K])) } trait OptGenKeyCodecLowPriority { this: OptGenKeyCodec.type => - implicit def noKeyCodec[K]: OptGenKeyCodec[K] = OptGenKeyCodec(Opt.Empty) + given noKeyCodec[K]: OptGenKeyCodec[K] = OptGenKeyCodec(Opt.Empty) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/cbor/RawCbor.scala b/core/src/main/scala/com/avsystem/commons/serialization/cbor/RawCbor.scala index 08f716755..d3165c040 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/cbor/RawCbor.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/cbor/RawCbor.scala @@ -64,7 +64,7 @@ object RawCbor extends TypeMarker[RawCbor] { ): RawCbor = RawCbor(CborOutput.write(value, keyCodec, sizePolicy)) - implicit val codec: GenCodec[RawCbor] = + given codec: GenCodec[RawCbor] = GenCodec.nonNull( input => input.readCustom(RawCbor).getOrElse(RawCbor(input.readSimple().readBinary())), (output, cbor) => diff --git a/core/src/main/scala/com/avsystem/commons/serialization/json/WrappedJson.scala b/core/src/main/scala/com/avsystem/commons/serialization/json/WrappedJson.scala index 6f97936f8..49bf9ec66 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/json/WrappedJson.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/json/WrappedJson.scala @@ -11,7 +11,7 @@ import com.avsystem.commons.serialization.GenCodec */ final case class WrappedJson(value: String) extends AnyVal with CaseMethods object WrappedJson { - implicit val codec: GenCodec[WrappedJson] = GenCodec.create( + given codec: GenCodec[WrappedJson] = GenCodec.create( in => WrappedJson(in.readCustom(RawJson).getOrElse(in.readSimple().readString())), (out, v) => if (!out.writeCustom(RawJson, v.value)) out.writeSimple().writeString(v.value), ) diff --git a/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala b/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala index cd61185a6..6632bae00 100644 --- a/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala +++ b/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala @@ -7,21 +7,21 @@ package tuples trait TupleDerivation[C[_]] { case class ElementInstances[T, I](instances: I) object ElementInstances { - implicit def tuple1Instances[T1](implicit i1: C[T1]): ElementInstances[Tuple1[T1], Tuple1[C[T1]]] = + given tuple1Instances[T1](using i1: C[T1]): ElementInstances[Tuple1[T1], Tuple1[C[T1]]] = ElementInstances(Tuple1(i1)) - implicit def tuple2Instances[T1, T2](implicit i1: C[T1], i2: C[T2]): ElementInstances[(T1, T2), (C[T1], C[T2])] = + given tuple2Instances[T1, T2](using i1: C[T1], i2: C[T2]): ElementInstances[(T1, T2), (C[T1], C[T2])] = ElementInstances((i1, i2)) - implicit def tuple3Instances[T1, T2, T3](implicit i1: C[T1], i2: C[T2], i3: C[T3]) + given tuple3Instances[T1, T2, T3](using i1: C[T1], i2: C[T2], i3: C[T3]) : ElementInstances[(T1, T2, T3), (C[T1], C[T2], C[T3])] = ElementInstances((i1, i2, i3)) - implicit def tuple4Instances[T1, T2, T3, T4](implicit i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4]) + given tuple4Instances[T1, T2, T3, T4](using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4]) : ElementInstances[(T1, T2, T3, T4), (C[T1], C[T2], C[T3], C[T4])] = ElementInstances((i1, i2, i3, i4)) - implicit def tuple5Instances[T1, T2, T3, T4, T5](implicit i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], i5: C[T5]) + given tuple5Instances[T1, T2, T3, T4, T5](using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], i5: C[T5]) : ElementInstances[(T1, T2, T3, T4, T5), (C[T1], C[T2], C[T3], C[T4], C[T5])] = ElementInstances((i1, i2, i3, i4, i5)) - implicit def tuple6Instances[T1, T2, T3, T4, T5, T6]( - implicit i1: C[T1], + given tuple6Instances[T1, T2, T3, T4, T5, T6]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -29,8 +29,8 @@ trait TupleDerivation[C[_]] { i6: C[T6], ): ElementInstances[(T1, T2, T3, T4, T5, T6), (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6])] = ElementInstances((i1, i2, i3, i4, i5, i6)) - implicit def tuple7Instances[T1, T2, T3, T4, T5, T6, T7]( - implicit i1: C[T1], + given tuple7Instances[T1, T2, T3, T4, T5, T6, T7]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -39,8 +39,8 @@ trait TupleDerivation[C[_]] { i7: C[T7], ): ElementInstances[(T1, T2, T3, T4, T5, T6, T7), (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7])] = ElementInstances((i1, i2, i3, i4, i5, i6, i7)) - implicit def tuple8Instances[T1, T2, T3, T4, T5, T6, T7, T8]( - implicit i1: C[T1], + given tuple8Instances[T1, T2, T3, T4, T5, T6, T7, T8]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -50,8 +50,8 @@ trait TupleDerivation[C[_]] { i8: C[T8], ): ElementInstances[(T1, T2, T3, T4, T5, T6, T7, T8), (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8])] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8)) - implicit def tuple9Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9]( - implicit i1: C[T1], + given tuple9Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -65,8 +65,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9)) - implicit def tuple10Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]( - implicit i1: C[T1], + given tuple10Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -81,8 +81,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10)) - implicit def tuple11Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]( - implicit i1: C[T1], + given tuple11Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -98,8 +98,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10], C[T11]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11)) - implicit def tuple12Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]( - implicit i1: C[T1], + given tuple12Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -116,8 +116,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10], C[T11], C[T12]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12)) - implicit def tuple13Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]( - implicit i1: C[T1], + given tuple13Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -135,8 +135,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10], C[T11], C[T12], C[T13]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13)) - implicit def tuple14Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]( - implicit i1: C[T1], + given tuple14Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -155,8 +155,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10], C[T11], C[T12], C[T13], C[T14]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14)) - implicit def tuple15Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]( - implicit i1: C[T1], + given tuple15Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -176,8 +176,8 @@ trait TupleDerivation[C[_]] { (C[T1], C[T2], C[T3], C[T4], C[T5], C[T6], C[T7], C[T8], C[T9], C[T10], C[T11], C[T12], C[T13], C[T14], C[T15]), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15)) - implicit def tuple16Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]( - implicit i1: C[T1], + given tuple16Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -215,8 +215,8 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16)) - implicit def tuple17Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]( - implicit i1: C[T1], + given tuple17Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -256,8 +256,8 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17)) - implicit def tuple18Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]( - implicit i1: C[T1], + given tuple18Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -299,8 +299,8 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18)) - implicit def tuple19Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]( - implicit i1: C[T1], + given tuple19Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -344,7 +344,7 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19)) - implicit def tuple20Instances[ + given tuple20Instances[ T1, T2, T3, @@ -365,8 +365,7 @@ trait TupleDerivation[C[_]] { T18, T19, T20, - ](implicit - i1: C[T1], + ](using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -412,7 +411,7 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19, i20)) - implicit def tuple21Instances[ + given tuple21Instances[ T1, T2, T3, @@ -434,8 +433,7 @@ trait TupleDerivation[C[_]] { T19, T20, T21, - ](implicit - i1: C[T1], + ](using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -483,7 +481,7 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19, i20, i21)) - implicit def tuple22Instances[ + given tuple22Instances[ T1, T2, T3, @@ -506,8 +504,7 @@ trait TupleDerivation[C[_]] { T20, T21, T22, - ](implicit - i1: C[T1], + ](using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -569,7 +566,7 @@ object GenTupleDerivation { val instParams = js.map(j => s"i$j: C[T$j]").mkString(",") val instTypes = js.map(j => s"C[T$j]").mkString(",") val instances = js.map(j => s"i$j").mkString(",") - println(s"def tuple${i}Instances[$tuple](implicit $instParams): ElementInstances[($tuple),($instTypes)] =\nElementInstances(($instances))") + println(s"def tuple${i}Instances[$tuple](using $instParams): ElementInstances[($tuple),($instTypes)] =\nElementInstances(($instances))") } } } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala index 8df8eb4a6..f586ff52e 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala @@ -21,7 +21,7 @@ sealed trait EntityIdMode[E, ID] { case EntityIdMode.Explicit() => format.fieldRefFor(MongoRef.RootRef(format), MongoEntity.Id) case EntityIdMode.Auto(idWrapping) => - val idCodec = GenCodec.fromTransparentWrapping(idWrapping, summon[GenCodec[ObjectId]]) + val idCodec = GenCodec.fromTransparentWrapping(using idWrapping, summon[GenCodec[ObjectId]]) MongoRef.FieldRef(MongoRef.RootRef(format), mongoId.Id, MongoFormat.Opaque(idCodec), Opt.Empty) } } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala index ddd69634b..a51c2bd5a 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala @@ -24,5 +24,5 @@ abstract class ObjectIdWrapperCompanion[ID] extends TransparentWrapperCompanion[ */ def get(): ID = wrap(ObjectId.get()) - given codec: GenCodec[ID] = GenCodec.fromTransparentWrapping(this, summon[GenCodec[ObjectId]]) + given codec: GenCodec[ID] = GenCodec.fromTransparentWrapping(using this, summon[GenCodec[ObjectId]]) } From 8e484e2817b219d3269034b06a5446134cb84168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 20:18:15 +0200 Subject: [PATCH 06/14] =?UTF-8?q?refactor(scala-3):=20implicit=20val/def?= =?UTF-8?q?=20=E2=86=92=20given=20for=20hocon,=20benchmark,=20residuals=20?= =?UTF-8?q?+=20fork-shape=20drift=20+=20@deprecated=20shims?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Translated from origin/master@39c047eb + ebffde26 + 848b8e9e. Residual core conversions: TypedMap.typedMapCodec/codecMapping, di/Component.info, di/Components.ambiguousArbitraryComponent1/2 + inject, concurrent/BlockingUtils.scheduler, js/NativeFormatOptions ctx param-list to `using`. hocon: ConfigCompanion HoconGenCodecs codec instances + DefaultConfigCompanion using-param, HTree EnumCtx param-list to `using`. benchmark: GenCodecBenchmarks + StreamInputOutputBenchmark codec instances. mongo: BsonRefKeyElementHandling.elementCodec. Fork-shape drift fixes folded in (initial regex `implicit\s+(def|val)` missed `implicit lazy val`): - OptArg int conversions → given Conversion (intToOptArgLong, intToOptArgDouble) to match fork shape. - GenCodec residual `implicit lazy val` → given (covers ~14 named Phase-2-retained codec accessors); GenRef.codec/SimpleRawRef.codec; CborAdtMetadata HasCborCodec/HasCborCodecWithDeps codec instances. - SealedUtils.codec/keyCodec, TypedMap.Entry.pairToEntry, ValueEnum.valName/enumCtx, AbstractValueEnum (implicit val) → (using val), ObservableBlockingIterator scheduler. - Components.autoComponent preserved as implicit def with rationale (by-name parameter + macro-stub body; non-inline given Conversion cannot carry by-name semantics). Named-import source-compat shims (preserve downstream named-import lookup post-anonymous-given conversion): - BoxingUnboxing.scala: 14 @deprecated def shims (7 Boxing + 7 Unboxing) — each `@deprecated("Use summon[Boxing[X,Y]]", "scala-3-port") def NAME: Boxing[X, Y] = summon`. - GenKeyCodec.scala: 18 @deprecated def shims for primitive KeyCodecs (BooleanKeyCodec, CharKeyCodec, IntKeyCodec, etc.). Reverted: `RunNowEC.Implicits.executionContext` / `RunInQueueEC.Implicits.executionContext` kept as `implicit val` — the wildcard-import-into-Implicits-object idiom is the public API (`import RunNowEC.Implicits._`); converting to `given` breaks downstream callers and our own tests since wildcard `_` imports do not capture givens. Fork preserves this pattern as well. scalafmt applied. Co-Authored-By: Claude Opus 4.7 --- .../commons/ser/GenCodecBenchmarks.scala | 6 +- .../ser/StreamInputOutputBenchmark.scala | 4 +- .../nativejs/NativeFormatOptions.scala | 6 +- .../commons/concurrent/BlockingUtils.scala | 4 +- .../ObservableBlockingIterator.scala | 2 +- .../concurrent/executionContexts.scala | 6 +- .../com/avsystem/commons/di/Component.scala | 2 +- .../com/avsystem/commons/di/Components.scala | 9 +- .../avsystem/commons/meta/OptionLike.scala | 4 +- .../commons/misc/BoxingUnboxing.scala | 32 +++++++ .../com/avsystem/commons/misc/OptArg.scala | 8 +- .../avsystem/commons/misc/SealedUtils.scala | 4 +- .../com/avsystem/commons/misc/TypedMap.scala | 6 +- .../com/avsystem/commons/misc/ValueEnum.scala | 6 +- .../commons/serialization/GenCodec.scala | 90 +++++++++---------- .../commons/serialization/GenKeyCodec.scala | 38 ++++++++ .../commons/serialization/GenRef.scala | 4 +- .../serialization/TupleGenCodecs.scala | 54 ++--------- .../serialization/cbor/CborAdtMetadata.scala | 4 +- .../cbor/CborOptimizedCodecs.scala | 15 ++-- .../commons/tuples/TupleDerivation.scala | 30 ++----- .../commons/hocon/ConfigCompanion.scala | 34 +++---- .../com/avsystem/commons/hocon/HTree.scala | 4 +- .../core/ops/BsonRefKeyElementHandling.scala | 2 +- .../commons/mongo/sync/MongoOps.scala | 3 +- .../commons/mongo/typed/EntityIdMode.scala | 5 +- .../commons/mongo/typed/MongoFormat.scala | 24 +++-- 27 files changed, 201 insertions(+), 205 deletions(-) diff --git a/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/GenCodecBenchmarks.scala b/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/GenCodecBenchmarks.scala index 9d4fbad3e..da06eecbf 100644 --- a/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/GenCodecBenchmarks.scala +++ b/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/GenCodecBenchmarks.scala @@ -18,13 +18,13 @@ class GenCodecBenchmarks { @Benchmark def cleanSomeWriting: String = { - implicit val cleanCodec: GenCodec[Option[String]] = GenCodecBenchmarks.cleanOptionCodec[String] + given cleanCodec: GenCodec[Option[String]] = GenCodecBenchmarks.cleanOptionCodec[String] JsonStringOutput.write(GenCodecBenchmarks.somes) } @Benchmark def cleanNoneWriting: String = { - implicit val cleanCodec: GenCodec[Option[String]] = GenCodecBenchmarks.cleanOptionCodec[String] + given cleanCodec: GenCodec[Option[String]] = GenCodecBenchmarks.cleanOptionCodec[String] JsonStringOutput.write(GenCodecBenchmarks.nones) } @@ -34,7 +34,7 @@ class GenCodecBenchmarks { } object GenCodecBenchmarks { - implicit def cleanOptionCodec[T: GenCodec]: GenCodec[Option[T]] = + given cleanOptionCodec[T: GenCodec]: GenCodec[Option[T]] = GenCodec.create[Option[T]]( i => if (i.readNull()) None else Some(GenCodec.read[T](i)), (o, vo) => diff --git a/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/StreamInputOutputBenchmark.scala b/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/StreamInputOutputBenchmark.scala index 0c9aff3bd..b3419e7b6 100644 --- a/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/StreamInputOutputBenchmark.scala +++ b/benchmark/jvm/src/main/scala/com/avsystem/commons/ser/StreamInputOutputBenchmark.scala @@ -11,8 +11,8 @@ case class Toplevel(int: Int, nested: Nested, str: String) case class Nested(list: List[Int], int: Int) object Toplevel { - implicit val nestedCodec: GenCodec[Nested] = GenCodec.materialize[Nested] - implicit val codec: GenCodec[Toplevel] = GenCodec.materialize[Toplevel] + given nestedCodec: GenCodec[Nested] = GenCodec.materialize[Nested] + given codec: GenCodec[Toplevel] = GenCodec.materialize[Toplevel] } @Warmup(iterations = 10) diff --git a/core/js/src/main/scala/com/avsystem/commons/serialization/nativejs/NativeFormatOptions.scala b/core/js/src/main/scala/com/avsystem/commons/serialization/nativejs/NativeFormatOptions.scala index b16cf1c65..f43e5feb3 100644 --- a/core/js/src/main/scala/com/avsystem/commons/serialization/nativejs/NativeFormatOptions.scala +++ b/core/js/src/main/scala/com/avsystem/commons/serialization/nativejs/NativeFormatOptions.scala @@ -6,7 +6,7 @@ import com.avsystem.commons.misc.{AbstractValueEnum, AbstractValueEnumCompanion, /** Specifies format used by `NativeJsonOutput.writeLong` / `NativeJsonInput.readLong` to represent [[Long]]. JS does * not support 64-bit representation. */ -final class NativeLongFormat(implicit ctx: EnumCtx) extends AbstractValueEnum +final class NativeLongFormat(using ctx: EnumCtx) extends AbstractValueEnum object NativeLongFormat extends AbstractValueEnumCompanion[NativeLongFormat] { final val RawString: Value = new NativeLongFormat final val JsNumber: Value = new NativeLongFormat @@ -16,7 +16,7 @@ object NativeLongFormat extends AbstractValueEnumCompanion[NativeLongFormat] { /** Specifies format used by `NativeJsonOutput.writeTimestamp` / `NativeJsonInput.readTimestamp` to represent * timestamps. */ -final class NativeDateFormat(implicit ctx: EnumCtx) extends AbstractValueEnum +final class NativeDateFormat(using ctx: EnumCtx) extends AbstractValueEnum object NativeDateFormat extends AbstractValueEnumCompanion[NativeDateFormat] { final val RawString: Value = new NativeDateFormat final val JsNumber: Value = new NativeDateFormat @@ -27,7 +27,7 @@ object NativeDateFormat extends AbstractValueEnumCompanion[NativeDateFormat] { * * Note that [[scala.scalajs.js.JSON.stringify]] does not know how to serialize a BigInt and throws an error */ -final class NativeBigIntFormat(implicit ctx: EnumCtx) extends AbstractValueEnum +final class NativeBigIntFormat(using ctx: EnumCtx) extends AbstractValueEnum object NativeBigIntFormat extends AbstractValueEnumCompanion[NativeBigIntFormat] { final val RawString: Value = new NativeBigIntFormat final val JsBigInt: Value = new NativeBigIntFormat diff --git a/core/jvm/src/main/scala/com/avsystem/commons/concurrent/BlockingUtils.scala b/core/jvm/src/main/scala/com/avsystem/commons/concurrent/BlockingUtils.scala index 985aa1408..191853846 100644 --- a/core/jvm/src/main/scala/com/avsystem/commons/concurrent/BlockingUtils.scala +++ b/core/jvm/src/main/scala/com/avsystem/commons/concurrent/BlockingUtils.scala @@ -15,7 +15,7 @@ abstract class BlockingUtils { /** Default scheduler used to run `Task`s and `Observable`s. This scheduler is not meant for blocking code. */ - implicit def scheduler: Scheduler + given scheduler: Scheduler /** Scheduler used for running blocking code. */ @@ -71,6 +71,6 @@ abstract class BlockingUtils { } object DefaultBlocking extends BlockingUtils { - implicit def scheduler: Scheduler = Scheduler.global + given scheduler: Scheduler = Scheduler.global lazy val ioScheduler: Scheduler = Scheduler.io() } diff --git a/core/jvm/src/main/scala/com/avsystem/commons/concurrent/ObservableBlockingIterator.scala b/core/jvm/src/main/scala/com/avsystem/commons/concurrent/ObservableBlockingIterator.scala index 7ae37a2b4..e29fd711d 100644 --- a/core/jvm/src/main/scala/com/avsystem/commons/concurrent/ObservableBlockingIterator.scala +++ b/core/jvm/src/main/scala/com/avsystem/commons/concurrent/ObservableBlockingIterator.scala @@ -19,7 +19,7 @@ class ObservableBlockingIterator[T]( timeout: Long, unit: TimeUnit, bufferSize: Int, -)(implicit val scheduler: Scheduler +)(using val scheduler: Scheduler ) extends CloseableIterator[T] with Subscriber[T] { diff --git a/core/src/main/scala/com/avsystem/commons/concurrent/executionContexts.scala b/core/src/main/scala/com/avsystem/commons/concurrent/executionContexts.scala index e694434f5..7a8b6d670 100644 --- a/core/src/main/scala/com/avsystem/commons/concurrent/executionContexts.scala +++ b/core/src/main/scala/com/avsystem/commons/concurrent/executionContexts.scala @@ -67,13 +67,13 @@ class RunInQueueEC extends ExecutionContextExecutor { } trait HasExecutionContext { - protected implicit def executionContext: ExecutionContext + protected given executionContext: ExecutionContext } trait HasRunNowEC extends HasExecutionContext { - protected implicit final def executionContext: ExecutionContext = RunNowEC + protected implicit val executionContext: ExecutionContext = RunNowEC } trait HasRunInQueueEC extends HasExecutionContext { - protected implicit final def executionContext: ExecutionContext = RunInQueueEC + protected implicit val executionContext: ExecutionContext = RunInQueueEC } diff --git a/core/src/main/scala/com/avsystem/commons/di/Component.scala b/core/src/main/scala/com/avsystem/commons/di/Component.scala index 0551161ea..d80bc8ae7 100644 --- a/core/src/main/scala/com/avsystem/commons/di/Component.scala +++ b/core/src/main/scala/com/avsystem/commons/di/Component.scala @@ -34,7 +34,7 @@ object ComponentInfo { ) @compileTimeOnly("implicit ComponentInfo is only available inside code passed to component/singleton macro") - implicit def info: ComponentInfo = sys.error("stub") + given info: ComponentInfo = sys.error("stub") } /** Represents a lazily initialized component in a dependency injection setting. The name "component" indicates that the diff --git a/core/src/main/scala/com/avsystem/commons/di/Components.scala b/core/src/main/scala/com/avsystem/commons/di/Components.scala index d635108b9..2c12698a1 100644 --- a/core/src/main/scala/com/avsystem/commons/di/Components.scala +++ b/core/src/main/scala/com/avsystem/commons/di/Components.scala @@ -43,11 +43,12 @@ trait Components extends ComponentsLowPrio { // avoids divergent implicit expansion involving `inject` // this is not strictly necessary but makes compiler error messages nicer // i.e. the compiler will emit "could not find implicit value" instead of "divergent implicit expansion" - implicit def ambiguousArbitraryComponent1[T]: Component[T] = null - implicit def ambiguousArbitraryComponent2[T]: Component[T] = null + given ambiguousArbitraryComponent1[T]: Component[T] = null + given ambiguousArbitraryComponent2[T]: Component[T] = null // TODO[scala3-port]: autoComponent (Scala 2 macro def) (L) - implicit def autoComponent[T](definition: => T)(implicit sourceInfo: SourceInfo): AutoComponent[T] = ??? + // Kept as `implicit def`: macro-stubbed and takes a by-name parameter, which a non-inline `given Conversion` cannot carry. + implicit def autoComponent[T](definition: => T)(using sourceInfo: SourceInfo): AutoComponent[T] = ??? // TODO[scala3-port]: optEmptyComponent (depends on stubbed singleton macro) (S) protected def optEmptyComponent: Component[Opt[Nothing]] = ??? @@ -65,5 +66,5 @@ trait ComponentsLowPrio { @compileTimeOnly( "implicit Component[T] => implicit T inference only works inside code passed to component/singleton macro" ) - implicit def inject[T](implicit component: Component[T]): T = sys.error("stub") + given inject[T](using component: Component[T]): T = sys.error("stub") } diff --git a/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala b/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala index 43c0114c9..59d2e885c 100644 --- a/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala +++ b/core/src/main/scala/com/avsystem/commons/meta/OptionLike.scala @@ -82,8 +82,6 @@ object AutoOptionalParam { } trait AutoOptionalParams { - given allAutoOptionalParams[T](using - optionLike: OptionLike[T] - ): AutoOptionalParam[T] = AutoOptionalParam[T] + given allAutoOptionalParams[T](using optionLike: OptionLike[T]): AutoOptionalParam[T] = AutoOptionalParam[T] } object AutoOptionalParams extends AutoOptionalParams diff --git a/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala b/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala index 2a92ba25e..a709efa7c 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala @@ -12,6 +12,22 @@ object Boxing extends LowPrioBoxing { given Boxing[Long, JLong] = fromImplicitConv given Boxing[Float, JFloat] = fromImplicitConv given Boxing[Double, JDouble] = fromImplicitConv + + // Source-compat aliases for callers that previously referenced these by name. + @deprecated("Use summon[Boxing[Boolean, JBoolean]]", since = "scala-3-port") + def BooleanBoxing: Boxing[Boolean, JBoolean] = summon + @deprecated("Use summon[Boxing[Byte, JByte]]", since = "scala-3-port") + def ByteBoxing: Boxing[Byte, JByte] = summon + @deprecated("Use summon[Boxing[Short, JShort]]", since = "scala-3-port") + def ShortBoxing: Boxing[Short, JShort] = summon + @deprecated("Use summon[Boxing[Int, JInteger]]", since = "scala-3-port") + def IntBoxing: Boxing[Int, JInteger] = summon + @deprecated("Use summon[Boxing[Long, JLong]]", since = "scala-3-port") + def LongBoxing: Boxing[Long, JLong] = summon + @deprecated("Use summon[Boxing[Float, JFloat]]", since = "scala-3-port") + def FloatBoxing: Boxing[Float, JFloat] = summon + @deprecated("Use summon[Boxing[Double, JDouble]]", since = "scala-3-port") + def DoubleBoxing: Boxing[Double, JDouble] = summon } trait LowPrioBoxing { this: Boxing.type => given nullableBoxing[A >: Null]: Boxing[A, A] = Boxing(identity) @@ -28,6 +44,22 @@ object Unboxing extends LowPrioUnboxing { given Unboxing[Long, JLong] = fromImplicitConv given Unboxing[Float, JFloat] = fromImplicitConv given Unboxing[Double, JDouble] = fromImplicitConv + + // Source-compat aliases for callers that previously referenced these by name. + @deprecated("Use summon[Unboxing[Boolean, JBoolean]]", since = "scala-3-port") + def BooleanUnboxing: Unboxing[Boolean, JBoolean] = summon + @deprecated("Use summon[Unboxing[Byte, JByte]]", since = "scala-3-port") + def ByteUnboxing: Unboxing[Byte, JByte] = summon + @deprecated("Use summon[Unboxing[Short, JShort]]", since = "scala-3-port") + def ShortUnboxing: Unboxing[Short, JShort] = summon + @deprecated("Use summon[Unboxing[Int, JInteger]]", since = "scala-3-port") + def IntUnboxing: Unboxing[Int, JInteger] = summon + @deprecated("Use summon[Unboxing[Long, JLong]]", since = "scala-3-port") + def LongUnboxing: Unboxing[Long, JLong] = summon + @deprecated("Use summon[Unboxing[Float, JFloat]]", since = "scala-3-port") + def FloatUnboxing: Unboxing[Float, JFloat] = summon + @deprecated("Use summon[Unboxing[Double, JDouble]]", since = "scala-3-port") + def DoubleUnboxing: Unboxing[Double, JDouble] = summon } trait LowPrioUnboxing { this: Unboxing.type => given nullableUnboxing[A >: Null]: Unboxing[A, A] = Unboxing(identity) diff --git a/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala b/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala index 994f6d991..4b8a00eb3 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/OptArg.scala @@ -1,5 +1,7 @@ package com.avsystem.commons.misc +import scala.annotation.targetName + object OptArg { /** This conversion allows you to pass unwrapped values where `OptArg` is required. Kept as `implicit def` (not a @@ -9,8 +11,10 @@ object OptArg { implicit def argToOptArg[A](value: A): OptArg[A] = OptArg(value) // additional implicits to cover most common, safe numeric promotions - implicit def intToOptArgLong(int: Int): OptArg[Long] = OptArg(int) - implicit def intToOptArgDouble(int: Int): OptArg[Double] = OptArg(int) + @targetName("intToOptArgLong") + given Conversion[Int, OptArg[Long]] = OptArg(_) + @targetName("intToOptArgDouble") + given Conversion[Int, OptArg[Double]] = OptArg(_) private object EmptyMarker extends Serializable diff --git a/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala b/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala index 7a2e282d2..5075b004f 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala @@ -123,8 +123,8 @@ trait NamedEnumCompanion[T <: NamedEnum] extends SealedEnumCompanion[T] { ), ) - implicit lazy val keyCodec: GenKeyCodec[T] = GenKeyCodec.create(decode, _.name) - implicit lazy val codec: GenCodec[T] = GenCodec.nullableSimple[T]( + given keyCodec: GenKeyCodec[T] = GenKeyCodec.create(decode, _.name) + given codec: GenCodec[T] = GenCodec.nullableSimple[T]( input => decode(input.readString()), (output, value) => output.writeString(value.name), ) diff --git a/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala b/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala index f34d3fed6..c7634d765 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala @@ -72,7 +72,7 @@ class TypedMap[K[_]](val raw: Map[K[Any], Any]) extends AnyVal { object TypedMap { case class Entry[K[_], T](pair: (K[T], T)) object Entry { - implicit def pairToEntry[K[_], T](pair: (K[T], T)): Entry[K, T] = Entry(pair) + given [K[_], T] => Conversion[(K[T], T), Entry[K, T]] = Entry(_) } def empty[K[_]]: TypedMap[K] = @@ -88,7 +88,7 @@ object TypedMap { def valueCodec[T](key: K[T]): GenCodec[T] } - implicit def typedMapCodec[K[_]](implicit keyCodec: GenKeyCodec[K[Any]], codecMapping: GenCodecMapping[K]) + given typedMapCodec[K[_]](using keyCodec: GenKeyCodec[K[Any]], codecMapping: GenCodecMapping[K]) : GenObjectCodec[TypedMap[K]] = new GenCodec.ObjectCodec[TypedMap[K]] { def nullable = false @@ -122,7 +122,7 @@ trait TypedKey[T] { def valueCodec: GenCodec[T] } object TypedKey { - implicit def codecMapping[K[X] <: TypedKey[X]]: GenCodecMapping[K] = + given codecMapping[K[X] <: TypedKey[X]]: GenCodecMapping[K] = new GenCodecMapping[K] { def valueCodec[T](key: K[T]): GenCodec[T] = key.valueCodec } diff --git a/core/src/main/scala/com/avsystem/commons/misc/ValueEnum.scala b/core/src/main/scala/com/avsystem/commons/misc/ValueEnum.scala index 341c9f75a..718a38970 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/ValueEnum.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/ValueEnum.scala @@ -59,7 +59,7 @@ trait ValueEnum extends NamedEnum { * compatibility it's better to extend this abstract class rather than [[ValueEnum]] trait directly. See [[ValueEnum]] * documentation for more information on value-based enums. */ -abstract class AbstractValueEnum(protected implicit val enumCtx: EnumCtx) extends ValueEnum +abstract class AbstractValueEnum(using protected val enumCtx: EnumCtx) extends ValueEnum @implicitNotFound( "Value based enum must be assigned to a public, final, non-lazy val in its companion object " + @@ -123,9 +123,9 @@ trait ValueEnumCompanion[T <: ValueEnum] extends NamedEnumCompanion[T] { compani protected[this] final class ValName(val valName: String) // TODO[scala3-port]: ValueEnumCompanion.valName (Scala 2 macro def) (L) - protected[this] implicit def valName: ValName = ??? + protected[this] given valName: ValName = ??? - protected[this] implicit def enumCtx(implicit valName: ValName): EnumCtx = + protected[this] given enumCtx(using valName: ValName): EnumCtx = new Ctx(valName.valName, currentOrdinal) } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala index 1fc3434a3..b401287ea 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala @@ -348,53 +348,53 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { private def notNull = throw new ReadFailure("not null") - implicit lazy val NothingCodec: GenCodec[Nothing] = + given NothingCodec: GenCodec[Nothing] = create[Nothing](_ => throw new ReadFailure("read Nothing"), (_, _) => throw new WriteFailure("write Nothing")) - implicit lazy val NullCodec: GenCodec[Null] = + given NullCodec: GenCodec[Null] = create[Null](i => if (i.readNull()) null else notNull, (o, _) => o.writeNull()) - implicit lazy val UnitCodec: GenCodec[Unit] = + given UnitCodec: GenCodec[Unit] = create[Unit](i => if (i.readNull()) () else notNull, (o, _) => o.writeNull()) - implicit lazy val VoidCodec: GenCodec[Void] = + given VoidCodec: GenCodec[Void] = create[Void](i => if (i.readNull()) null else notNull, (o, _) => o.writeNull()) - implicit lazy val BooleanCodec: GenCodec[Boolean] = nonNullSimple(_.readBoolean(), _ writeBoolean _) - implicit lazy val CharCodec: GenCodec[Char] = nonNullSimple(_.readChar(), _ writeChar _) - implicit lazy val ByteCodec: GenCodec[Byte] = nonNullSimple(_.readByte(), _ writeByte _) - implicit lazy val ShortCodec: GenCodec[Short] = nonNullSimple(_.readShort(), _ writeShort _) - implicit lazy val IntCodec: GenCodec[Int] = nonNullSimple(_.readInt(), _ writeInt _) - implicit lazy val LongCodec: GenCodec[Long] = nonNullSimple(_.readLong(), _ writeLong _) - implicit lazy val FloatCodec: GenCodec[Float] = nonNullSimple(_.readFloat(), _ writeFloat _) - implicit lazy val DoubleCodec: GenCodec[Double] = nonNullSimple(_.readDouble(), _ writeDouble _) - implicit lazy val BigIntCodec: GenCodec[BigInt] = nullableSimple(_.readBigInt(), _ writeBigInt _) - implicit lazy val BigDecimalCodec: GenCodec[BigDecimal] = nullableSimple(_.readBigDecimal(), _ writeBigDecimal _) - - implicit lazy val JBooleanCodec: GenCodec[JBoolean] = nullableSimple(_.readBoolean(), _ writeBoolean _) - implicit lazy val JCharacterCodec: GenCodec[JCharacter] = nullableSimple(_.readChar(), _ writeChar _) - implicit lazy val JByteCodec: GenCodec[JByte] = nullableSimple(_.readByte(), _ writeByte _) - implicit lazy val JShortCodec: GenCodec[JShort] = nullableSimple(_.readShort(), _ writeShort _) - implicit lazy val JIntegerCodec: GenCodec[JInteger] = nullableSimple(_.readInt(), _ writeInt _) - implicit lazy val JLongCodec: GenCodec[JLong] = nullableSimple(_.readLong(), _ writeLong _) - implicit lazy val JFloatCodec: GenCodec[JFloat] = nullableSimple(_.readFloat(), _ writeFloat _) - implicit lazy val JDoubleCodec: GenCodec[JDouble] = nullableSimple(_.readDouble(), _ writeDouble _) - implicit lazy val JBigIntegerCodec: GenCodec[JBigInteger] = + given BooleanCodec: GenCodec[Boolean] = nonNullSimple(_.readBoolean(), _ writeBoolean _) + given CharCodec: GenCodec[Char] = nonNullSimple(_.readChar(), _ writeChar _) + given ByteCodec: GenCodec[Byte] = nonNullSimple(_.readByte(), _ writeByte _) + given ShortCodec: GenCodec[Short] = nonNullSimple(_.readShort(), _ writeShort _) + given IntCodec: GenCodec[Int] = nonNullSimple(_.readInt(), _ writeInt _) + given LongCodec: GenCodec[Long] = nonNullSimple(_.readLong(), _ writeLong _) + given FloatCodec: GenCodec[Float] = nonNullSimple(_.readFloat(), _ writeFloat _) + given DoubleCodec: GenCodec[Double] = nonNullSimple(_.readDouble(), _ writeDouble _) + given BigIntCodec: GenCodec[BigInt] = nullableSimple(_.readBigInt(), _ writeBigInt _) + given BigDecimalCodec: GenCodec[BigDecimal] = nullableSimple(_.readBigDecimal(), _ writeBigDecimal _) + + given JBooleanCodec: GenCodec[JBoolean] = nullableSimple(_.readBoolean(), _ writeBoolean _) + given JCharacterCodec: GenCodec[JCharacter] = nullableSimple(_.readChar(), _ writeChar _) + given JByteCodec: GenCodec[JByte] = nullableSimple(_.readByte(), _ writeByte _) + given JShortCodec: GenCodec[JShort] = nullableSimple(_.readShort(), _ writeShort _) + given JIntegerCodec: GenCodec[JInteger] = nullableSimple(_.readInt(), _ writeInt _) + given JLongCodec: GenCodec[JLong] = nullableSimple(_.readLong(), _ writeLong _) + given JFloatCodec: GenCodec[JFloat] = nullableSimple(_.readFloat(), _ writeFloat _) + given JDoubleCodec: GenCodec[JDouble] = nullableSimple(_.readDouble(), _ writeDouble _) + given JBigIntegerCodec: GenCodec[JBigInteger] = nullableSimple(_.readBigInt().bigInteger, (o, v) => o.writeBigInt(BigInt(v))) - implicit lazy val JBigDecimalCodec: GenCodec[JBigDecimal] = + given JBigDecimalCodec: GenCodec[JBigDecimal] = nullableSimple(_.readBigDecimal().bigDecimal, (o, v) => o.writeBigDecimal(BigDecimal(v))) - implicit lazy val JDateCodec: GenCodec[JDate] = + given JDateCodec: GenCodec[JDate] = nullableSimple(i => new JDate(i.readTimestamp()), (o, d) => o.writeTimestamp(d.getTime)) - implicit lazy val StringCodec: GenCodec[String] = + given StringCodec: GenCodec[String] = nullableSimple(_.readString(), _ writeString _) - implicit lazy val SymbolCodec: GenCodec[Symbol] = + given SymbolCodec: GenCodec[Symbol] = nullableSimple(i => Symbol(i.readString()), (o, s) => o.writeString(s.name)) - implicit lazy val ByteArrayCodec: GenCodec[Array[Byte]] = + given ByteArrayCodec: GenCodec[Array[Byte]] = nullableSimple(_.readBinary(), _ writeBinary _) - implicit lazy val UuidCodec: GenCodec[UUID] = + given UuidCodec: GenCodec[UUID] = nullableSimple(i => UUID.fromString(i.readString()), (o, v) => o.writeString(v.toString)) - implicit lazy val TimestampCodec: GenCodec[Timestamp] = + given TimestampCodec: GenCodec[Timestamp] = GenCodec.nonNullSimple(i => Timestamp(i.readTimestamp()), (o, t) => o.writeTimestamp(t.millis)) - implicit lazy val BytesCodec: GenCodec[Bytes] = + given BytesCodec: GenCodec[Bytes] = GenCodec.nullableSimple(i => Bytes(i.readBinary()), (o, b) => o.writeBinary(b.bytes)) private implicit class IterableOps[A](private val coll: BIterable[A]) extends AnyVal { @@ -503,32 +503,25 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { // have these weird return types (e.g. GenCodec[C[T] with BSeq[T]] instead of just GenCodec[C[T]]) because it's a // workaround for https://groups.google.com/forum/#!topic/scala-user/O_fkaChTtg4 - given seqCodec[C[X] <: BSeq[X], T: GenCodec](using - fac: Factory[T, C[T]] - ): GenCodec[C[T] with BSeq[T]] = + given seqCodec[C[X] <: BSeq[X], T: GenCodec](using fac: Factory[T, C[T]]): GenCodec[C[T] with BSeq[T]] = nullableList[C[T] with BSeq[T]](_.collectTo[T, C[T]], (lo, c) => c.writeToList(lo)) - given setCodec[C[X] <: BSet[X], T: GenCodec](using - fac: Factory[T, C[T]] - ): GenCodec[C[T] with BSet[T]] = + given setCodec[C[X] <: BSet[X], T: GenCodec](using fac: Factory[T, C[T]]): GenCodec[C[T] with BSet[T]] = nullableList[C[T] with BSet[T]](_.collectTo[T, C[T]], (lo, c) => c.writeToList(lo)) - given jCollectionCodec[C[X] <: JCollection[X], T: GenCodec](using - cbf: JFactory[T, C[T]] - ): GenCodec[C[T] with JCollection[T]] = + given jCollectionCodec[C[X] <: JCollection[X], T: GenCodec](using cbf: JFactory[T, C[T]]) + : GenCodec[C[T] with JCollection[T]] = nullableList[C[T]](_.collectTo[T, C[T]], (lo, c) => c.asScala.writeToList(lo)) - given mapCodec[M[X, Y] <: BMap[X, Y], K: GenKeyCodec, V: GenCodec](using - fac: Factory[(K, V), M[K, V]] - ): GenObjectCodec[M[K, V]] = + given mapCodec[M[X, Y] <: BMap[X, Y], K: GenKeyCodec, V: GenCodec](using fac: Factory[(K, V), M[K, V]]) + : GenObjectCodec[M[K, V]] = nullableObject[M[K, V]]( _.collectTo[K, V, M[K, V]], (oo, value) => value.writeToObject(oo), ) - given jMapCodec[M[X, Y] <: JMap[X, Y], K: GenKeyCodec, V: GenCodec](using - cbf: JFactory[(K, V), M[K, V]] - ): GenObjectCodec[M[K, V]] = + given jMapCodec[M[X, Y] <: JMap[X, Y], K: GenKeyCodec, V: GenCodec](using cbf: JFactory[(K, V), M[K, V]]) + : GenObjectCodec[M[K, V]] = nullableObject[M[K, V]]( _.collectTo[K, V, M[K, V]], (oo, value) => value.asScala.writeToObject(oo), @@ -598,8 +591,7 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { ) // Warning! Changing the order of implicit params of this method causes divergent implicit expansion (WTF?) - given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrappedCodec: GenCodec[R]) - : GenCodec[T] = + given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrappedCodec: GenCodec[R]): GenCodec[T] = new Transformed(wrappedCodec, tw.unwrap, tw.wrap) given fromFallback[T](using fallback: Fallback[GenCodec[T]]): GenCodec[T] = diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala index 8c2812816..87a90f23a 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala @@ -93,4 +93,42 @@ object GenKeyCodec { given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrappedCodec: GenKeyCodec[R]) : GenKeyCodec[T] = new Transformed(wrappedCodec, tw.unwrap, tw.wrap) + + // Source-compat aliases for callers that previously referenced these by name. + @deprecated("Use summon[GenKeyCodec[Boolean]]", since = "scala-3-port") + def BooleanKeyCodec: GenKeyCodec[Boolean] = summon + @deprecated("Use summon[GenKeyCodec[Char]]", since = "scala-3-port") + def CharKeyCodec: GenKeyCodec[Char] = summon + @deprecated("Use summon[GenKeyCodec[Byte]]", since = "scala-3-port") + def ByteKeyCodec: GenKeyCodec[Byte] = summon + @deprecated("Use summon[GenKeyCodec[Short]]", since = "scala-3-port") + def ShortKeyCodec: GenKeyCodec[Short] = summon + @deprecated("Use summon[GenKeyCodec[Int]]", since = "scala-3-port") + def IntKeyCodec: GenKeyCodec[Int] = summon + @deprecated("Use summon[GenKeyCodec[Long]]", since = "scala-3-port") + def LongKeyCodec: GenKeyCodec[Long] = summon + @deprecated("Use summon[GenKeyCodec[BigInt]]", since = "scala-3-port") + def BigIntKeyCodec: GenKeyCodec[BigInt] = summon + @deprecated("Use summon[GenKeyCodec[JBoolean]]", since = "scala-3-port") + def JBooleanKeyCodec: GenKeyCodec[JBoolean] = summon + @deprecated("Use summon[GenKeyCodec[JCharacter]]", since = "scala-3-port") + def JCharacterKeyCodec: GenKeyCodec[JCharacter] = summon + @deprecated("Use summon[GenKeyCodec[JByte]]", since = "scala-3-port") + def JByteKeyCodec: GenKeyCodec[JByte] = summon + @deprecated("Use summon[GenKeyCodec[JShort]]", since = "scala-3-port") + def JShortKeyCodec: GenKeyCodec[JShort] = summon + @deprecated("Use summon[GenKeyCodec[JInteger]]", since = "scala-3-port") + def JIntKeyCodec: GenKeyCodec[JInteger] = summon + @deprecated("Use summon[GenKeyCodec[JLong]]", since = "scala-3-port") + def JLongKeyCodec: GenKeyCodec[JLong] = summon + @deprecated("Use summon[GenKeyCodec[JBigInteger]]", since = "scala-3-port") + def JBigIntegerKeyCodec: GenKeyCodec[JBigInteger] = summon + @deprecated("Use summon[GenKeyCodec[String]]", since = "scala-3-port") + def StringKeyCodec: GenKeyCodec[String] = summon + @deprecated("Use summon[GenKeyCodec[Symbol]]", since = "scala-3-port") + def SymbolKeyCodec: GenKeyCodec[Symbol] = summon + @deprecated("Use summon[GenKeyCodec[Timestamp]]", since = "scala-3-port") + def TimestampKeyCodec: GenKeyCodec[Timestamp] = summon + @deprecated("Use summon[GenKeyCodec[Bytes]]", since = "scala-3-port") + def BytesKeyCodec: GenKeyCodec[Bytes] = summon } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenRef.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenRef.scala index 4592a49a7..8aa941684 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenRef.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenRef.scala @@ -19,7 +19,7 @@ object RawRef { case class Composite(left: RawRef, right: RawRef) extends RawRef case object Identity extends RawRef - implicit val codec: GenCodec[RawRef] = GenCodec.materialize[RawRef] + given codec: GenCodec[RawRef] = GenCodec.materialize[RawRef] def create[S]: Creator[S] = new Creator[S] {} @@ -30,7 +30,7 @@ object RawRef { } object SimpleRawRef { - implicit val codec: GenCodec[SimpleRawRef] = GenCodec.materialize[SimpleRawRef] + given codec: GenCodec[SimpleRawRef] = GenCodec.materialize[SimpleRawRef] } case class GenRef[-S, +T](fun: S => T, rawRef: RawRef) { diff --git a/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala b/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala index 660fdffe8..663dc03f2 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/TupleGenCodecs.scala @@ -8,8 +8,7 @@ trait TupleGenCodecs { this: GenCodec.type => given tuple2Codec[T1, T2](using r1: GenCodec[T1], r2: GenCodec[T2]): GenCodec[(T1, T2)] = mkTupleCodec(r1, r2) - given tuple3Codec[T1, T2, T3](using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3]) - : GenCodec[(T1, T2, T3)] = + given tuple3Codec[T1, T2, T3](using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3]): GenCodec[(T1, T2, T3)] = mkTupleCodec(r1, r2, r3) given tuple4Codec[T1, T2, T3, T4]( @@ -284,29 +283,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20) - given tuple21Codec[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - ](using r1: GenCodec[T1], + given tuple21Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], @@ -330,30 +308,8 @@ trait TupleGenCodecs { this: GenCodec.type => ): GenCodec[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21)] = mkTupleCodec(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20, r21) - given tuple22Codec[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - ](using r1: GenCodec[T1], + given tuple22Codec[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]( + using r1: GenCodec[T1], r2: GenCodec[T2], r3: GenCodec[T3], r4: GenCodec[T4], diff --git a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala index 0a4e0fbea..962525afd 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborAdtMetadata.scala @@ -17,7 +17,7 @@ import scala.annotation.nowarn * map keys can be of arbitrary type and not just strings */ abstract class HasCborCodec[T](implicit instances: MacroInstances[CborOptimizedCodecs, CborAdtInstances[T]]) { - implicit lazy val codec: GenObjectCodec[T] = instances(CborOptimizedCodecs, this).cborCodec + given codec: GenObjectCodec[T] = instances(CborOptimizedCodecs, this).cborCodec } /** Like [[HasCborCodec]] but allows injecting additional implicits - like [[HasGenCodecWithDeps]]. @@ -33,7 +33,7 @@ abstract class HasCborCodecWithDeps[D, T]( instances: MacroInstances[(CborOptimizedCodecs, D), CborAdtInstances[T]], ) = this()(using instances, applyUnapplyProvider.toScala) - implicit lazy val codec: GenObjectCodec[T] = instances((CborOptimizedCodecs, deps.value), this).cborCodec + given codec: GenObjectCodec[T] = instances((CborOptimizedCodecs, deps.value), this).cborCodec } /** Apply this annotation on a sealed trait/class whose companion extends [[HasCborCodec]] in order to customize the diff --git a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala index d295d8518..87b3b0dac 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/cbor/CborOptimizedCodecs.scala @@ -18,19 +18,18 @@ trait CborOptimizedCodecs { * serialization. If the key type has a `GenKeyCodec` then this `GenCodec` behaves exactly the same as the standard * one for non-CBOR inputs/outputs. */ - given cborMapCodec[M[X, Y] <: BMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec](using - fac: Factory[(K, V), M[K, V]] - ): GenObjectCodec[M[K, V]] = mkMapCodec(keyCodec => { + given cborMapCodec[M[X, Y] <: BMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec](using fac: Factory[(K, V), M[K, V]]) + : GenObjectCodec[M[K, V]] = mkMapCodec { keyCodec => given GenKeyCodec[K] = keyCodec GenCodec.mapCodec[M, K, V] - }) + } - given cborJMapCodec[M[X, Y] <: JMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec](using - fac: JFactory[(K, V), M[K, V]] - ): GenObjectCodec[M[K, V]] = mkMapCodec(keyCodec => { + given cborJMapCodec[M[X, Y] <: JMap[X, Y], K: GenCodec: OptGenKeyCodec, V: GenCodec]( + using fac: JFactory[(K, V), M[K, V]] + ): GenObjectCodec[M[K, V]] = mkMapCodec { keyCodec => given GenKeyCodec[K] = keyCodec GenCodec.jMapCodec[M, K, V] - }) + } private def mkMapCodec[M[X, Y] <: AnyRef, K: GenCodec: OptGenKeyCodec, V: GenCodec]( mkStdCodec: GenKeyCodec[K] => GenObjectCodec[M[K, V]] diff --git a/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala b/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala index 6632bae00..77111e129 100644 --- a/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala +++ b/core/src/main/scala/com/avsystem/commons/tuples/TupleDerivation.scala @@ -344,28 +344,8 @@ trait TupleDerivation[C[_]] { ), ] = ElementInstances((i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19)) - given tuple20Instances[ - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - ](using i1: C[T1], + given tuple20Instances[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]( + using i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -433,7 +413,8 @@ trait TupleDerivation[C[_]] { T19, T20, T21, - ](using i1: C[T1], + ](using + i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], @@ -504,7 +485,8 @@ trait TupleDerivation[C[_]] { T20, T21, T22, - ](using i1: C[T1], + ](using + i1: C[T1], i2: C[T2], i3: C[T3], i4: C[T4], diff --git a/hocon/src/main/scala/com/avsystem/commons/hocon/ConfigCompanion.scala b/hocon/src/main/scala/com/avsystem/commons/hocon/ConfigCompanion.scala index 99ac75f59..3211e33a3 100644 --- a/hocon/src/main/scala/com/avsystem/commons/hocon/ConfigCompanion.scala +++ b/hocon/src/main/scala/com/avsystem/commons/hocon/ConfigCompanion.scala @@ -11,16 +11,16 @@ import scala.concurrent.duration.* import scala.jdk.javaapi.DurationConverters trait HoconGenCodecs { - implicit def configCodec: GenCodec[Config] = HoconGenCodecs.ConfigCodec - implicit def finiteDurationCodec: GenCodec[FiniteDuration] = HoconGenCodecs.FiniteDurationCodec - implicit def jDurationCodec: GenCodec[JDuration] = HoconGenCodecs.JavaDurationCodec - implicit def periodCodec: GenCodec[Period] = HoconGenCodecs.PeriodCodec - implicit def sizeInBytesCodec: GenCodec[SizeInBytes] = HoconGenCodecs.SizeInBytesCodec - implicit def classKeyCodec: GenKeyCodec[Class[?]] = HoconGenCodecs.ClassKeyCodec - implicit def classCodec: GenCodec[Class[?]] = HoconGenCodecs.ClassCodec + given configCodec: GenCodec[Config] = HoconGenCodecs.ConfigCodec + given finiteDurationCodec: GenCodec[FiniteDuration] = HoconGenCodecs.FiniteDurationCodec + given jDurationCodec: GenCodec[JDuration] = HoconGenCodecs.JavaDurationCodec + given periodCodec: GenCodec[Period] = HoconGenCodecs.PeriodCodec + given sizeInBytesCodec: GenCodec[SizeInBytes] = HoconGenCodecs.SizeInBytesCodec + given classKeyCodec: GenKeyCodec[Class[?]] = HoconGenCodecs.ClassKeyCodec + given classCodec: GenCodec[Class[?]] = HoconGenCodecs.ClassCodec } object HoconGenCodecs { - implicit final val ConfigCodec: GenCodec[Config] = GenCodec.nullable( + given ConfigCodec: GenCodec[Config] = GenCodec.nullable( input => input.readCustom(ConfigValueMarker).fold(ConfigFactory.parseString(input.readSimple().readString())) { case obj: ConfigObject => obj.toConfig @@ -33,7 +33,7 @@ object HoconGenCodecs { }, ) - implicit final val FiniteDurationCodec: GenCodec[FiniteDuration] = GenCodec.nullable( + given FiniteDurationCodec: GenCodec[FiniteDuration] = GenCodec.nullable( input => input.readCustom(DurationMarker).map(DurationConverters.toScala).getOrElse(input.readSimple().readLong().millis), (output, value) => @@ -41,26 +41,26 @@ object HoconGenCodecs { output.writeSimple().writeLong(value.toMillis), ) - implicit final val JavaDurationCodec: GenCodec[JDuration] = GenCodec.nullable( + given JavaDurationCodec: GenCodec[JDuration] = GenCodec.nullable( input => input.readCustom(DurationMarker).getOrElse(JDuration.ofMillis(input.readSimple().readLong())), (output, value) => if (!output.writeCustom(DurationMarker, value)) output.writeSimple().writeLong(value.toMillis), ) - implicit final val PeriodCodec: GenCodec[Period] = GenCodec.nullable( + given PeriodCodec: GenCodec[Period] = GenCodec.nullable( input => input.readCustom(PeriodMarker).getOrElse(Period.parse(input.readSimple().readString())), (output, value) => if (!output.writeCustom(PeriodMarker, value)) output.writeSimple().writeString(value.toString), ) - implicit final val SizeInBytesCodec: GenCodec[SizeInBytes] = GenCodec.nonNull( + given SizeInBytesCodec: GenCodec[SizeInBytes] = GenCodec.nonNull( input => SizeInBytes(input.readCustom(SizeInBytesMarker).getOrElse(input.readSimple().readLong())), (output, value) => if (!output.writeCustom(SizeInBytesMarker, value.bytes)) output.writeSimple().writeLong(value.bytes), ) - implicit final val ClassKeyCodec: GenKeyCodec[Class[?]] = + given ClassKeyCodec: GenKeyCodec[Class[?]] = GenKeyCodec.create(Class.forName, _.getName) - implicit final val ClassCodec: GenCodec[Class[?]] = + given ClassCodec: GenCodec[Class[?]] = GenCodec.nullableString(Class.forName, _.getName) } @@ -72,9 +72,9 @@ trait ConfigObjectCodec[T] { abstract class AbstractConfigCompanion[Implicits <: HoconGenCodecs, T]( implicits: Implicits -)(implicit instances: MacroInstances[Implicits, ConfigObjectCodec[T]] +)(using instances: MacroInstances[Implicits, ConfigObjectCodec[T]] ) { - implicit lazy val codec: GenCodec[T] = instances(implicits, this).objectCodec + given codec: GenCodec[T] = instances(implicits, this).objectCodec final def read(config: Config): T = HoconInput.read[T](config) } @@ -86,5 +86,5 @@ abstract class AbstractConfigCompanion[Implicits <: HoconGenCodecs, T]( * that it automatically imports codecs from [[HoconGenCodecs]] - codecs for third party types often used in * configuration. */ -abstract class DefaultConfigCompanion[T](implicit macroCodec: MacroInstances[HoconGenCodecs, ConfigObjectCodec[T]]) +abstract class DefaultConfigCompanion[T](using macroCodec: MacroInstances[HoconGenCodecs, ConfigObjectCodec[T]]) extends AbstractConfigCompanion[HoconGenCodecs, T](DefaultHoconGenCodecs) diff --git a/hocon/src/main/scala/com/avsystem/commons/hocon/HTree.scala b/hocon/src/main/scala/com/avsystem/commons/hocon/HTree.scala index 16ec7d191..f3c6327e5 100644 --- a/hocon/src/main/scala/com/avsystem/commons/hocon/HTree.scala +++ b/hocon/src/main/scala/com/avsystem/commons/hocon/HTree.scala @@ -56,12 +56,12 @@ object HTree { final case class HQualifiedInclude(qualifier: HIncludeQualifier, target: HString)(val tokens: HTokenRange) extends HRegularIncludeTarget - final class HIncludeQualifier(implicit enumCtx: EnumCtx) extends AbstractValueEnum + final class HIncludeQualifier(using enumCtx: EnumCtx) extends AbstractValueEnum object HIncludeQualifier extends AbstractValueEnumCompanion[HIncludeQualifier] { final val Classpath, File, Url: Value = new HIncludeQualifier } - final class HStringSyntax(implicit enumCtx: EnumCtx) extends AbstractValueEnum + final class HStringSyntax(using enumCtx: EnumCtx) extends AbstractValueEnum object HStringSyntax extends AbstractValueEnumCompanion[HStringSyntax] { final val Whitespace, Unquoted, Quoted, Multiline: Value = new HStringSyntax } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefKeyElementHandling.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefKeyElementHandling.scala index d86cfbab5..8ba4dd057 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefKeyElementHandling.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/core/ops/BsonRefKeyElementHandling.scala @@ -6,7 +6,7 @@ import com.avsystem.commons.serialization.GenCodec import org.bson.BsonValue trait BsonRefKeyElementHandling[E, C[T] <: Iterable[T]] extends KeyElementHandling[E] with BsonRefKeyHandling[C[E]] { - protected implicit def elementCodec: GenCodec[E] + protected given elementCodec: GenCodec[E] override protected def encodeElement(e: E): BsonValue = BsonValueOutput.write(e) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala index d1f39b134..b7489c313 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/sync/MongoOps.scala @@ -20,8 +20,7 @@ trait MongoOps { object MongoOps { final class DBOps(private val db: MongoDatabase) extends AnyVal { - def getCollection[A](name: String, codec: BsonCodec[A, BsonDocument])(using ct: ClassTag[A]) - : MongoCollection[A] = { + def getCollection[A](name: String, codec: BsonCodec[A, BsonDocument])(using ct: ClassTag[A]): MongoCollection[A] = { val mongoCodec = new MongoCodec[A, BsonDocument](codec, db.getCodecRegistry) val registry = CodecRegistries.fromRegistries( CodecRegistries.fromCodecs(mongoCodec), diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala index f586ff52e..64a64a72c 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala @@ -31,7 +31,6 @@ object EntityIdMode { given explicitIdMode[E <: MongoEntity[ID], ID]: EntityIdMode[E, ID] = Explicit() - given autoIdMode[E <: AutoIdMongoEntity[ID], ID](using - idWrapping: TransparentWrapping[ObjectId, ID] - ): EntityIdMode[E, ID] = Auto(idWrapping) + given autoIdMode[E <: AutoIdMongoEntity[ID], ID](using idWrapping: TransparentWrapping[ObjectId, ID]) + : EntityIdMode[E, ID] = Auto(idWrapping) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala index 58fc4c441..c7f1d7e85 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala @@ -93,32 +93,28 @@ object MongoFormat extends MetadataCompanion[MongoFormat] with MongoFormatLowPri wrappedFormat: MongoFormat[R], ) extends MongoFormat[T] - given collectionFormat[C[X] <: Iterable[X], T](using - collectionCodec: GenCodec[C[T]], - elementFormat: MongoFormat[T], - ): MongoFormat[C[T]] = CollectionFormat(collectionCodec, elementFormat) + given collectionFormat[C[X] <: Iterable[X], T](using collectionCodec: GenCodec[C[T]], elementFormat: MongoFormat[T]) + : MongoFormat[C[T]] = CollectionFormat(collectionCodec, elementFormat) - given dictionaryFormat[M[X, Y] <: BMap[X, Y], K, V](using - mapCodec: GenCodec[M[K, V]], + given dictionaryFormat[M[X, Y] <: BMap[X, Y], K, V]( + using mapCodec: GenCodec[M[K, V]], keyCodec: GenKeyCodec[K], valueFormat: MongoFormat[V], ): MongoFormat[M[K, V]] = DictionaryFormat(mapCodec, keyCodec, valueFormat) // TODO[scala3-port]: K[_] → K[Any] workaround for Scala 3 wildcard-as-type-arg restriction (S) - given typedMapFormat[K[_]](using - keyCodec: GenKeyCodec[K[Any]], - valueFormats: MongoFormatMapping[K], - ): MongoFormat[TypedMap[K]] = + given typedMapFormat[K[_]](using keyCodec: GenKeyCodec[K[Any]], valueFormats: MongoFormatMapping[K]) + : MongoFormat[TypedMap[K]] = TypedMapFormat[K](TypedMap.typedMapCodec, keyCodec, valueFormats) - given optionalFormat[O, T](using - optionLike: OptionLike.Aux[O, T], + given optionalFormat[O, T]( + using optionLike: OptionLike.Aux[O, T], optionCodec: GenCodec[O], wrappedFormat: MongoFormat[T], ): MongoFormat[O] = OptionalFormat(optionCodec, optionLike, wrappedFormat) - given transparentFormat[R, T](using - codec: GenCodec[T], + given transparentFormat[R, T]( + using codec: GenCodec[T], wrapping: TransparentWrapping[R, T], wrappedFormat: MongoFormat[R], ): MongoFormat[T] = TransparentFormat(codec, wrapping, wrappedFormat) From e921a8f05adb1813dac38638ef0b0f519869e344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 20:19:44 +0200 Subject: [PATCH 07/14] =?UTF-8?q?docs(migration):=20record=20implicit=20?= =?UTF-8?q?=E2=86=92=20given=20+=20(implicit=20X)=20=E2=86=92=20(using=20X?= =?UTF-8?q?)=20source-compat=20impact?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Document slice 3.3 outcomes in MIGRATION.md §3: - implicit val/def → given (typeclass instances) and the anonymous- given pattern; named-import source-compat impact. - (implicit X: T) → (using X: T) parameter list sweep across mongo. - BsonGenCodecs export-given + @deprecated shim pattern. - Borderline preservations: OptArg.argToOptArg (erasure-bridge), GenRef.fun2GenRef (Phase-2 stub), RunNowEC/RunInQueueEC Implicits.executionContext (wildcard-import idiom), autoComponent (by-name + macro-stub). - @deprecated def shims for renamed BoxingUnboxing + GenKeyCodec primitive givens (32 shims total) — emit deprecation warnings at named call sites and direct callers to `summon[T]`. Co-Authored-By: Claude Opus 4.7 --- MIGRATION.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/MIGRATION.md b/MIGRATION.md index b99395701..9af96e39b 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -54,6 +54,31 @@ the bottom of this file. Restoration ships incrementally per feature area. compiles). - `enum` was renamed to `e` at one call site in `GenKeyCodec` (`enum` is reserved in Scala 3). - `@targetName` annotation added to `CloseableIterator` overloaded methods. +- `implicit val/def` typeclass instances rewritten to `given` across `serialization`, `cbor`, + `meta`, `misc`, `tuples` (slice 3.3). Named-import callers that referenced these by name + (e.g. `GenCodec.bseqCodec`, `GenKeyCodec.IntKeyCodec`, `TypeString.codec`) must switch to + `summon[GenCodec[BSeq[T]]]` or use `import X.given` for given-import semantics. Anonymous + `given T = …` preferred for canonical instances per fork pattern. +- Named-import compatibility shims: `@deprecated def NAME: T = summon[T]` aliases added in + `BoxingUnboxing` (`BooleanBoxing` … `DoubleBoxing`, `BooleanUnboxing` … `DoubleUnboxing`) + and `GenKeyCodec` (`BooleanKeyCodec` … `BytesKeyCodec`) so downstream callers using + `GenKeyCodec.IntKeyCodec`-style named lookup keep compiling. Each shim emits a deprecation + warning pointing to `summon[T]`. Mirrors `BsonGenCodecs` source-compat layer from fork + commit `8f70be80`. +- `OptArg.argToOptArg` PRESERVED as `implicit def` — polymorphic `Conversion[A, OptArg[A]]` + would generate a clashing JVM erasure bridge (both `A` and the `OptArg` value class erase to + `Object`). Verbatim explanatory comment from fork `39c047eb` retained inline. +- `GenRef.fun2GenRef` PRESERVED as `implicit def` (currently a `???` Phase-2 stub; Phase 4 + feature-port will restore the macro-splice body; macro-splice-over-inline-arg rationale per + fork `ebffde26` documented as preservation rule). +- `RunNowEC.Implicits.executionContext` / `RunInQueueEC.Implicits.executionContext` PRESERVED + as `implicit val` — the wildcard-import-into-`Implicits`-object idiom is the public API + (`import RunNowEC.Implicits._`). Converting to `given` would silently stop providing the EC + to wildcard-import callers (givens require `import X.given`). +- `(implicit X: T)` parameter lists left in place across slice-3.1 extension-shim sites + (`SharedExtensions.implicit def *Ops`, jiop, jsiop, `Components.autoComponent`, etc.). Those + are conversion shims for `implicit class` value-class wrappers and are being rewritten to + `extension` blocks in slice 3.1 (PR #868), which deletes the conversion entirely. ### mongo @@ -63,10 +88,33 @@ the bottom of this file. Restoration ships incrementally per feature area. Scala 3 forbids type projections on non-concrete prefixes). Public-API signature change. - `BsonValueOutput.write` / `BsonValueInput.read` call sites require explicit `using` keyword. - `MongoPolyDataCompanion` / `TypedMapFormat` / `TypedMapRefOps` widened from `K[_]` / `D[_]` to `K[Any]` / `D[Any]`. +- `(implicit X: T)` parameter lists rewritten to `(using X: T)` across 19 mongo files in + slice 3.3 (BsonCodec, BsonRef, DocKey, Filter, GenCodecProvider, BsonRefIterable*, Sorting, + MongoOps, TextSearchLanguage, DataTypeDsl, MongoEntityCompanion, MongoIndex, + MongoPolyDataCompanion, MongoRef, MongoUpdateOperator, ProjectionZippers, QueryOperatorsDsl, + TypedMongoCollection). Source-compat: positional call sites unchanged (Scala 3 accepts both + syntaxes); named-arg call sites must update from `foo(x = …)` to `foo(using x = …)`. +- `BsonGenCodecs` rewritten per fork `8f70be80`: trait uses `export BsonGenCodecs.given`, + object holds anonymous `given GenCodec[X] = …` declarations + `@deprecated def name: T = summon` + shims for source-compat with named-import callers (`BsonGenCodecs.objectIdCodec`, etc.). +- `MongoFormat.codec` / `MongoAdtFormat.codec`/`dataClassTag` are now `given` in trait + declarations; consumers using `import meta.format._` to bring `codec`/`dataClassTag` into + implicit scope must switch to `import meta.format.{given, _}` for given-import semantics + (already applied internally in `TypedMongoCollection.mkNativeCollection`). +- `KeyGetter.bsonRefKeyGetter` / `docKeyKeyGetter` rewritten from `implicit object … extends T` + to `given X: T with { … }`. Source-compat: positional resolution unchanged; `import X._` + callers must switch to `import X.given`. ### hocon - `SealedEnumCompanion.values` override now `lazy val` (see core notes). +- `HoconGenCodecs` codec instances (`ConfigCodec`, `FiniteDurationCodec`, `JavaDurationCodec`, + `PeriodCodec`, `SizeInBytesCodec`, `ClassKeyCodec`, `ClassCodec`) rewritten from + `implicit final val` to `given` (slice 3.3). Same named-import caveat as the core entry + applies. +- `ConfigObjectCompanion.codec` instance and `DefaultConfigCompanion` macro-instance + parameter rewritten to `using`. +- `HTree.HIncludeQualifier` / `HStringSyntax` constructor implicit param rewritten to `using`. ## 4. Binary-compat breaks From cf28f2968a8904b17c4ec2c8670f93f7099728df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 22:08:11 +0200 Subject: [PATCH 08/14] refactor(scala-3): bump @deprecated since to 3.0.0 32 @deprecated shims in BoxingUnboxing (14) and GenKeyCodec (18) had since="scala-3-port" placeholder. Bumped to since="3.0.0" to match the upstream release version they will ship under. --- .../commons/misc/BoxingUnboxing.scala | 28 +++++++-------- .../commons/serialization/GenKeyCodec.scala | 36 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala b/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala index a709efa7c..8d9ebf24d 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala @@ -14,19 +14,19 @@ object Boxing extends LowPrioBoxing { given Boxing[Double, JDouble] = fromImplicitConv // Source-compat aliases for callers that previously referenced these by name. - @deprecated("Use summon[Boxing[Boolean, JBoolean]]", since = "scala-3-port") + @deprecated("Use summon[Boxing[Boolean, JBoolean]]", since = "3.0.0") def BooleanBoxing: Boxing[Boolean, JBoolean] = summon - @deprecated("Use summon[Boxing[Byte, JByte]]", since = "scala-3-port") + @deprecated("Use summon[Boxing[Byte, JByte]]", since = "3.0.0") def ByteBoxing: Boxing[Byte, JByte] = summon - @deprecated("Use summon[Boxing[Short, JShort]]", since = "scala-3-port") + @deprecated("Use summon[Boxing[Short, JShort]]", since = "3.0.0") def ShortBoxing: Boxing[Short, JShort] = summon - @deprecated("Use summon[Boxing[Int, JInteger]]", since = "scala-3-port") + @deprecated("Use summon[Boxing[Int, JInteger]]", since = "3.0.0") def IntBoxing: Boxing[Int, JInteger] = summon - @deprecated("Use summon[Boxing[Long, JLong]]", since = "scala-3-port") + @deprecated("Use summon[Boxing[Long, JLong]]", since = "3.0.0") def LongBoxing: Boxing[Long, JLong] = summon - @deprecated("Use summon[Boxing[Float, JFloat]]", since = "scala-3-port") + @deprecated("Use summon[Boxing[Float, JFloat]]", since = "3.0.0") def FloatBoxing: Boxing[Float, JFloat] = summon - @deprecated("Use summon[Boxing[Double, JDouble]]", since = "scala-3-port") + @deprecated("Use summon[Boxing[Double, JDouble]]", since = "3.0.0") def DoubleBoxing: Boxing[Double, JDouble] = summon } trait LowPrioBoxing { this: Boxing.type => @@ -46,19 +46,19 @@ object Unboxing extends LowPrioUnboxing { given Unboxing[Double, JDouble] = fromImplicitConv // Source-compat aliases for callers that previously referenced these by name. - @deprecated("Use summon[Unboxing[Boolean, JBoolean]]", since = "scala-3-port") + @deprecated("Use summon[Unboxing[Boolean, JBoolean]]", since = "3.0.0") def BooleanUnboxing: Unboxing[Boolean, JBoolean] = summon - @deprecated("Use summon[Unboxing[Byte, JByte]]", since = "scala-3-port") + @deprecated("Use summon[Unboxing[Byte, JByte]]", since = "3.0.0") def ByteUnboxing: Unboxing[Byte, JByte] = summon - @deprecated("Use summon[Unboxing[Short, JShort]]", since = "scala-3-port") + @deprecated("Use summon[Unboxing[Short, JShort]]", since = "3.0.0") def ShortUnboxing: Unboxing[Short, JShort] = summon - @deprecated("Use summon[Unboxing[Int, JInteger]]", since = "scala-3-port") + @deprecated("Use summon[Unboxing[Int, JInteger]]", since = "3.0.0") def IntUnboxing: Unboxing[Int, JInteger] = summon - @deprecated("Use summon[Unboxing[Long, JLong]]", since = "scala-3-port") + @deprecated("Use summon[Unboxing[Long, JLong]]", since = "3.0.0") def LongUnboxing: Unboxing[Long, JLong] = summon - @deprecated("Use summon[Unboxing[Float, JFloat]]", since = "scala-3-port") + @deprecated("Use summon[Unboxing[Float, JFloat]]", since = "3.0.0") def FloatUnboxing: Unboxing[Float, JFloat] = summon - @deprecated("Use summon[Unboxing[Double, JDouble]]", since = "scala-3-port") + @deprecated("Use summon[Unboxing[Double, JDouble]]", since = "3.0.0") def DoubleUnboxing: Unboxing[Double, JDouble] = summon } trait LowPrioUnboxing { this: Unboxing.type => diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala index 87a90f23a..3df5c3f82 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala @@ -95,40 +95,40 @@ object GenKeyCodec { new Transformed(wrappedCodec, tw.unwrap, tw.wrap) // Source-compat aliases for callers that previously referenced these by name. - @deprecated("Use summon[GenKeyCodec[Boolean]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[Boolean]]", since = "3.0.0") def BooleanKeyCodec: GenKeyCodec[Boolean] = summon - @deprecated("Use summon[GenKeyCodec[Char]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[Char]]", since = "3.0.0") def CharKeyCodec: GenKeyCodec[Char] = summon - @deprecated("Use summon[GenKeyCodec[Byte]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[Byte]]", since = "3.0.0") def ByteKeyCodec: GenKeyCodec[Byte] = summon - @deprecated("Use summon[GenKeyCodec[Short]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[Short]]", since = "3.0.0") def ShortKeyCodec: GenKeyCodec[Short] = summon - @deprecated("Use summon[GenKeyCodec[Int]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[Int]]", since = "3.0.0") def IntKeyCodec: GenKeyCodec[Int] = summon - @deprecated("Use summon[GenKeyCodec[Long]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[Long]]", since = "3.0.0") def LongKeyCodec: GenKeyCodec[Long] = summon - @deprecated("Use summon[GenKeyCodec[BigInt]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[BigInt]]", since = "3.0.0") def BigIntKeyCodec: GenKeyCodec[BigInt] = summon - @deprecated("Use summon[GenKeyCodec[JBoolean]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[JBoolean]]", since = "3.0.0") def JBooleanKeyCodec: GenKeyCodec[JBoolean] = summon - @deprecated("Use summon[GenKeyCodec[JCharacter]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[JCharacter]]", since = "3.0.0") def JCharacterKeyCodec: GenKeyCodec[JCharacter] = summon - @deprecated("Use summon[GenKeyCodec[JByte]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[JByte]]", since = "3.0.0") def JByteKeyCodec: GenKeyCodec[JByte] = summon - @deprecated("Use summon[GenKeyCodec[JShort]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[JShort]]", since = "3.0.0") def JShortKeyCodec: GenKeyCodec[JShort] = summon - @deprecated("Use summon[GenKeyCodec[JInteger]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[JInteger]]", since = "3.0.0") def JIntKeyCodec: GenKeyCodec[JInteger] = summon - @deprecated("Use summon[GenKeyCodec[JLong]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[JLong]]", since = "3.0.0") def JLongKeyCodec: GenKeyCodec[JLong] = summon - @deprecated("Use summon[GenKeyCodec[JBigInteger]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[JBigInteger]]", since = "3.0.0") def JBigIntegerKeyCodec: GenKeyCodec[JBigInteger] = summon - @deprecated("Use summon[GenKeyCodec[String]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[String]]", since = "3.0.0") def StringKeyCodec: GenKeyCodec[String] = summon - @deprecated("Use summon[GenKeyCodec[Symbol]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[Symbol]]", since = "3.0.0") def SymbolKeyCodec: GenKeyCodec[Symbol] = summon - @deprecated("Use summon[GenKeyCodec[Timestamp]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[Timestamp]]", since = "3.0.0") def TimestampKeyCodec: GenKeyCodec[Timestamp] = summon - @deprecated("Use summon[GenKeyCodec[Bytes]]", since = "scala-3-port") + @deprecated("Use summon[GenKeyCodec[Bytes]]", since = "3.0.0") def BytesKeyCodec: GenKeyCodec[Bytes] = summon } From a2bdaae046f12350d4a9b5ad90a0381e94b4e091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 22:38:41 +0200 Subject: [PATCH 09/14] =?UTF-8?q?refactor(scala-3,core):=20GenCodec=20prim?= =?UTF-8?q?itive=20givens=20=E2=86=92=20anonymous=20+=20@deprecated=20shim?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Match fork shape (origin/master@39c047eb + ebffde26): all 31 named primitive codecs become anonymous `given GenCodec[T] = …`, with `@deprecated def NAME = summon[T]` shims (since = "3.0.0") preserving source-compat for named-import callers. `macroCodecs.scala` pattern matches now reference the primitive codecs via the compiler-generated mangled names (`given_GenCodec_Boolean`, `_Int`, `_Long`, `_Double`, etc.). Co-Authored-By: Claude Opus 4.7 --- .../commons/serialization/GenCodec.scala | 127 +++++++++++++----- .../commons/serialization/macroCodecs.scala | 8 +- 2 files changed, 99 insertions(+), 36 deletions(-) diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala index b401287ea..75d5a6c63 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala @@ -348,55 +348,118 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { private def notNull = throw new ReadFailure("not null") - given NothingCodec: GenCodec[Nothing] = + given GenCodec[Nothing] = create[Nothing](_ => throw new ReadFailure("read Nothing"), (_, _) => throw new WriteFailure("write Nothing")) - given NullCodec: GenCodec[Null] = + given GenCodec[Null] = create[Null](i => if (i.readNull()) null else notNull, (o, _) => o.writeNull()) - given UnitCodec: GenCodec[Unit] = + given GenCodec[Unit] = create[Unit](i => if (i.readNull()) () else notNull, (o, _) => o.writeNull()) - given VoidCodec: GenCodec[Void] = + given GenCodec[Void] = create[Void](i => if (i.readNull()) null else notNull, (o, _) => o.writeNull()) - given BooleanCodec: GenCodec[Boolean] = nonNullSimple(_.readBoolean(), _ writeBoolean _) - given CharCodec: GenCodec[Char] = nonNullSimple(_.readChar(), _ writeChar _) - given ByteCodec: GenCodec[Byte] = nonNullSimple(_.readByte(), _ writeByte _) - given ShortCodec: GenCodec[Short] = nonNullSimple(_.readShort(), _ writeShort _) - given IntCodec: GenCodec[Int] = nonNullSimple(_.readInt(), _ writeInt _) - given LongCodec: GenCodec[Long] = nonNullSimple(_.readLong(), _ writeLong _) - given FloatCodec: GenCodec[Float] = nonNullSimple(_.readFloat(), _ writeFloat _) - given DoubleCodec: GenCodec[Double] = nonNullSimple(_.readDouble(), _ writeDouble _) - given BigIntCodec: GenCodec[BigInt] = nullableSimple(_.readBigInt(), _ writeBigInt _) - given BigDecimalCodec: GenCodec[BigDecimal] = nullableSimple(_.readBigDecimal(), _ writeBigDecimal _) - - given JBooleanCodec: GenCodec[JBoolean] = nullableSimple(_.readBoolean(), _ writeBoolean _) - given JCharacterCodec: GenCodec[JCharacter] = nullableSimple(_.readChar(), _ writeChar _) - given JByteCodec: GenCodec[JByte] = nullableSimple(_.readByte(), _ writeByte _) - given JShortCodec: GenCodec[JShort] = nullableSimple(_.readShort(), _ writeShort _) - given JIntegerCodec: GenCodec[JInteger] = nullableSimple(_.readInt(), _ writeInt _) - given JLongCodec: GenCodec[JLong] = nullableSimple(_.readLong(), _ writeLong _) - given JFloatCodec: GenCodec[JFloat] = nullableSimple(_.readFloat(), _ writeFloat _) - given JDoubleCodec: GenCodec[JDouble] = nullableSimple(_.readDouble(), _ writeDouble _) - given JBigIntegerCodec: GenCodec[JBigInteger] = + given GenCodec[Boolean] = nonNullSimple(_.readBoolean(), _ writeBoolean _) + given GenCodec[Char] = nonNullSimple(_.readChar(), _ writeChar _) + given GenCodec[Byte] = nonNullSimple(_.readByte(), _ writeByte _) + given GenCodec[Short] = nonNullSimple(_.readShort(), _ writeShort _) + given GenCodec[Int] = nonNullSimple(_.readInt(), _ writeInt _) + given GenCodec[Long] = nonNullSimple(_.readLong(), _ writeLong _) + given GenCodec[Float] = nonNullSimple(_.readFloat(), _ writeFloat _) + given GenCodec[Double] = nonNullSimple(_.readDouble(), _ writeDouble _) + given GenCodec[BigInt] = nullableSimple(_.readBigInt(), _ writeBigInt _) + given GenCodec[BigDecimal] = nullableSimple(_.readBigDecimal(), _ writeBigDecimal _) + + given GenCodec[JBoolean] = nullableSimple(_.readBoolean(), _ writeBoolean _) + given GenCodec[JCharacter] = nullableSimple(_.readChar(), _ writeChar _) + given GenCodec[JByte] = nullableSimple(_.readByte(), _ writeByte _) + given GenCodec[JShort] = nullableSimple(_.readShort(), _ writeShort _) + given GenCodec[JInteger] = nullableSimple(_.readInt(), _ writeInt _) + given GenCodec[JLong] = nullableSimple(_.readLong(), _ writeLong _) + given GenCodec[JFloat] = nullableSimple(_.readFloat(), _ writeFloat _) + given GenCodec[JDouble] = nullableSimple(_.readDouble(), _ writeDouble _) + given GenCodec[JBigInteger] = nullableSimple(_.readBigInt().bigInteger, (o, v) => o.writeBigInt(BigInt(v))) - given JBigDecimalCodec: GenCodec[JBigDecimal] = + given GenCodec[JBigDecimal] = nullableSimple(_.readBigDecimal().bigDecimal, (o, v) => o.writeBigDecimal(BigDecimal(v))) - given JDateCodec: GenCodec[JDate] = + given GenCodec[JDate] = nullableSimple(i => new JDate(i.readTimestamp()), (o, d) => o.writeTimestamp(d.getTime)) - given StringCodec: GenCodec[String] = + given GenCodec[String] = nullableSimple(_.readString(), _ writeString _) - given SymbolCodec: GenCodec[Symbol] = + given GenCodec[Symbol] = nullableSimple(i => Symbol(i.readString()), (o, s) => o.writeString(s.name)) - given ByteArrayCodec: GenCodec[Array[Byte]] = + given GenCodec[Array[Byte]] = nullableSimple(_.readBinary(), _ writeBinary _) - given UuidCodec: GenCodec[UUID] = + given GenCodec[UUID] = nullableSimple(i => UUID.fromString(i.readString()), (o, v) => o.writeString(v.toString)) - given TimestampCodec: GenCodec[Timestamp] = + given GenCodec[Timestamp] = GenCodec.nonNullSimple(i => Timestamp(i.readTimestamp()), (o, t) => o.writeTimestamp(t.millis)) - given BytesCodec: GenCodec[Bytes] = + given GenCodec[Bytes] = GenCodec.nullableSimple(i => Bytes(i.readBinary()), (o, b) => o.writeBinary(b.bytes)) + @deprecated("use summon[GenCodec[Nothing]]", since = "3.0.0") + def NothingCodec: GenCodec[Nothing] = summon[GenCodec[Nothing]] + @deprecated("use summon[GenCodec[Null]]", since = "3.0.0") + def NullCodec: GenCodec[Null] = summon[GenCodec[Null]] + @deprecated("use summon[GenCodec[Unit]]", since = "3.0.0") + def UnitCodec: GenCodec[Unit] = summon[GenCodec[Unit]] + @deprecated("use summon[GenCodec[Void]]", since = "3.0.0") + def VoidCodec: GenCodec[Void] = summon[GenCodec[Void]] + @deprecated("use summon[GenCodec[Boolean]]", since = "3.0.0") + def BooleanCodec: GenCodec[Boolean] = summon[GenCodec[Boolean]] + @deprecated("use summon[GenCodec[Char]]", since = "3.0.0") + def CharCodec: GenCodec[Char] = summon[GenCodec[Char]] + @deprecated("use summon[GenCodec[Byte]]", since = "3.0.0") + def ByteCodec: GenCodec[Byte] = summon[GenCodec[Byte]] + @deprecated("use summon[GenCodec[Short]]", since = "3.0.0") + def ShortCodec: GenCodec[Short] = summon[GenCodec[Short]] + @deprecated("use summon[GenCodec[Int]]", since = "3.0.0") + def IntCodec: GenCodec[Int] = summon[GenCodec[Int]] + @deprecated("use summon[GenCodec[Long]]", since = "3.0.0") + def LongCodec: GenCodec[Long] = summon[GenCodec[Long]] + @deprecated("use summon[GenCodec[Float]]", since = "3.0.0") + def FloatCodec: GenCodec[Float] = summon[GenCodec[Float]] + @deprecated("use summon[GenCodec[Double]]", since = "3.0.0") + def DoubleCodec: GenCodec[Double] = summon[GenCodec[Double]] + @deprecated("use summon[GenCodec[BigInt]]", since = "3.0.0") + def BigIntCodec: GenCodec[BigInt] = summon[GenCodec[BigInt]] + @deprecated("use summon[GenCodec[BigDecimal]]", since = "3.0.0") + def BigDecimalCodec: GenCodec[BigDecimal] = summon[GenCodec[BigDecimal]] + @deprecated("use summon[GenCodec[JBoolean]]", since = "3.0.0") + def JBooleanCodec: GenCodec[JBoolean] = summon[GenCodec[JBoolean]] + @deprecated("use summon[GenCodec[JCharacter]]", since = "3.0.0") + def JCharacterCodec: GenCodec[JCharacter] = summon[GenCodec[JCharacter]] + @deprecated("use summon[GenCodec[JByte]]", since = "3.0.0") + def JByteCodec: GenCodec[JByte] = summon[GenCodec[JByte]] + @deprecated("use summon[GenCodec[JShort]]", since = "3.0.0") + def JShortCodec: GenCodec[JShort] = summon[GenCodec[JShort]] + @deprecated("use summon[GenCodec[JInteger]]", since = "3.0.0") + def JIntegerCodec: GenCodec[JInteger] = summon[GenCodec[JInteger]] + @deprecated("use summon[GenCodec[JLong]]", since = "3.0.0") + def JLongCodec: GenCodec[JLong] = summon[GenCodec[JLong]] + @deprecated("use summon[GenCodec[JFloat]]", since = "3.0.0") + def JFloatCodec: GenCodec[JFloat] = summon[GenCodec[JFloat]] + @deprecated("use summon[GenCodec[JDouble]]", since = "3.0.0") + def JDoubleCodec: GenCodec[JDouble] = summon[GenCodec[JDouble]] + @deprecated("use summon[GenCodec[JBigInteger]]", since = "3.0.0") + def JBigIntegerCodec: GenCodec[JBigInteger] = summon[GenCodec[JBigInteger]] + @deprecated("use summon[GenCodec[JBigDecimal]]", since = "3.0.0") + def JBigDecimalCodec: GenCodec[JBigDecimal] = summon[GenCodec[JBigDecimal]] + @deprecated("use summon[GenCodec[JDate]]", since = "3.0.0") + def JDateCodec: GenCodec[JDate] = summon[GenCodec[JDate]] + @deprecated("use summon[GenCodec[String]]", since = "3.0.0") + def StringCodec: GenCodec[String] = summon[GenCodec[String]] + @deprecated("use summon[GenCodec[Symbol]]", since = "3.0.0") + def SymbolCodec: GenCodec[Symbol] = summon[GenCodec[Symbol]] + @deprecated("use summon[GenCodec[Array[Byte]]]", since = "3.0.0") + def ByteArrayCodec: GenCodec[Array[Byte]] = summon[GenCodec[Array[Byte]]] + @deprecated("use summon[GenCodec[UUID]]", since = "3.0.0") + def UuidCodec: GenCodec[UUID] = summon[GenCodec[UUID]] + @deprecated("use summon[GenCodec[Timestamp]]", since = "3.0.0") + def TimestampCodec: GenCodec[Timestamp] = summon[GenCodec[Timestamp]] + @deprecated("use summon[GenCodec[Bytes]]", since = "3.0.0") + def BytesCodec: GenCodec[Bytes] = summon[GenCodec[Bytes]] + private implicit class IterableOps[A](private val coll: BIterable[A]) extends AnyVal { def writeToList(lo: ListOutput)(implicit writer: GenCodec[A]): Unit = { lo.declareSizeOf(coll) diff --git a/core/src/main/scala/com/avsystem/commons/serialization/macroCodecs.scala b/core/src/main/scala/com/avsystem/commons/serialization/macroCodecs.scala index 251ed0237..74c23c506 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/macroCodecs.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/macroCodecs.scala @@ -43,7 +43,7 @@ abstract class ApplyUnapplyCodec[T]( protected final def writeField(output: ObjectOutput, idx: Int, value: Boolean): Unit = deps(idx) match { - case GenCodec.BooleanCodec => writeField(fieldNames(idx), output, value) + case GenCodec.given_GenCodec_Boolean => writeField(fieldNames(idx), output, value) case codec: GenCodec[Boolean @unchecked] => writeField(fieldNames(idx), output, value, codec) } @@ -54,7 +54,7 @@ abstract class ApplyUnapplyCodec[T]( protected final def writeField(output: ObjectOutput, idx: Int, value: Int): Unit = deps(idx) match { - case GenCodec.IntCodec => writeField(fieldNames(idx), output, value) + case GenCodec.given_GenCodec_Int => writeField(fieldNames(idx), output, value) case codec: GenCodec[Int @unchecked] => writeField(fieldNames(idx), output, value, codec) } @@ -65,7 +65,7 @@ abstract class ApplyUnapplyCodec[T]( protected final def writeField(output: ObjectOutput, idx: Int, value: Long): Unit = deps(idx) match { - case GenCodec.LongCodec => writeField(fieldNames(idx), output, value) + case GenCodec.given_GenCodec_Long => writeField(fieldNames(idx), output, value) case codec: GenCodec[Long @unchecked] => writeField(fieldNames(idx), output, value, codec) } @@ -76,7 +76,7 @@ abstract class ApplyUnapplyCodec[T]( protected final def writeField(output: ObjectOutput, idx: Int, value: Double): Unit = deps(idx) match { - case GenCodec.DoubleCodec => writeField(fieldNames(idx), output, value) + case GenCodec.given_GenCodec_Double => writeField(fieldNames(idx), output, value) case codec: GenCodec[Double @unchecked] => writeField(fieldNames(idx), output, value, codec) } From 442087e17f2edb39f1a2cf1b23bc63f11ec45830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 22:51:27 +0200 Subject: [PATCH 10/14] =?UTF-8?q?refactor(scala-3,core):=20BoxingUnboxing?= =?UTF-8?q?=20givens=20=E2=86=92=20Scala=203.6=20named=20context-function?= =?UTF-8?q?=20form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert BoxingUnboxing given declarations to the Scala 3.6 named context-function form. Drop the @deprecated def shims introduced during the initial anonymous-given pass — the named 3.6 form restores name-stable lookup, so the shims are redundant. Co-Authored-By: Claude Opus 4.7 --- .../commons/misc/BoxingUnboxing.scala | 64 +++++-------------- 1 file changed, 16 insertions(+), 48 deletions(-) diff --git a/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala b/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala index 8d9ebf24d..1858b55f7 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/BoxingUnboxing.scala @@ -5,62 +5,30 @@ case class Boxing[-A, +B](fun: A => B) extends AnyVal object Boxing extends LowPrioBoxing { def fromImplicitConv[A, B](using conv: A => B): Boxing[A, B] = Boxing(conv) - given Boxing[Boolean, JBoolean] = fromImplicitConv - given Boxing[Byte, JByte] = fromImplicitConv - given Boxing[Short, JShort] = fromImplicitConv - given Boxing[Int, JInteger] = fromImplicitConv - given Boxing[Long, JLong] = fromImplicitConv - given Boxing[Float, JFloat] = fromImplicitConv - given Boxing[Double, JDouble] = fromImplicitConv - - // Source-compat aliases for callers that previously referenced these by name. - @deprecated("Use summon[Boxing[Boolean, JBoolean]]", since = "3.0.0") - def BooleanBoxing: Boxing[Boolean, JBoolean] = summon - @deprecated("Use summon[Boxing[Byte, JByte]]", since = "3.0.0") - def ByteBoxing: Boxing[Byte, JByte] = summon - @deprecated("Use summon[Boxing[Short, JShort]]", since = "3.0.0") - def ShortBoxing: Boxing[Short, JShort] = summon - @deprecated("Use summon[Boxing[Int, JInteger]]", since = "3.0.0") - def IntBoxing: Boxing[Int, JInteger] = summon - @deprecated("Use summon[Boxing[Long, JLong]]", since = "3.0.0") - def LongBoxing: Boxing[Long, JLong] = summon - @deprecated("Use summon[Boxing[Float, JFloat]]", since = "3.0.0") - def FloatBoxing: Boxing[Float, JFloat] = summon - @deprecated("Use summon[Boxing[Double, JDouble]]", since = "3.0.0") - def DoubleBoxing: Boxing[Double, JDouble] = summon + given BooleanBoxing: Boxing[Boolean, JBoolean] = fromImplicitConv + given ByteBoxing: Boxing[Byte, JByte] = fromImplicitConv + given ShortBoxing: Boxing[Short, JShort] = fromImplicitConv + given IntBoxing: Boxing[Int, JInteger] = fromImplicitConv + given LongBoxing: Boxing[Long, JLong] = fromImplicitConv + given FloatBoxing: Boxing[Float, JFloat] = fromImplicitConv + given DoubleBoxing: Boxing[Double, JDouble] = fromImplicitConv } trait LowPrioBoxing { this: Boxing.type => - given nullableBoxing[A >: Null]: Boxing[A, A] = Boxing(identity) + given nullableBoxing: [A >: Null] => Boxing[A, A] = Boxing(identity) } case class Unboxing[+A, -B](fun: B => A) extends AnyVal object Unboxing extends LowPrioUnboxing { def fromImplicitConv[A, B](using conv: B => A): Unboxing[A, B] = Unboxing(conv) - given Unboxing[Boolean, JBoolean] = fromImplicitConv - given Unboxing[Byte, JByte] = fromImplicitConv - given Unboxing[Short, JShort] = fromImplicitConv - given Unboxing[Int, JInteger] = fromImplicitConv - given Unboxing[Long, JLong] = fromImplicitConv - given Unboxing[Float, JFloat] = fromImplicitConv - given Unboxing[Double, JDouble] = fromImplicitConv - - // Source-compat aliases for callers that previously referenced these by name. - @deprecated("Use summon[Unboxing[Boolean, JBoolean]]", since = "3.0.0") - def BooleanUnboxing: Unboxing[Boolean, JBoolean] = summon - @deprecated("Use summon[Unboxing[Byte, JByte]]", since = "3.0.0") - def ByteUnboxing: Unboxing[Byte, JByte] = summon - @deprecated("Use summon[Unboxing[Short, JShort]]", since = "3.0.0") - def ShortUnboxing: Unboxing[Short, JShort] = summon - @deprecated("Use summon[Unboxing[Int, JInteger]]", since = "3.0.0") - def IntUnboxing: Unboxing[Int, JInteger] = summon - @deprecated("Use summon[Unboxing[Long, JLong]]", since = "3.0.0") - def LongUnboxing: Unboxing[Long, JLong] = summon - @deprecated("Use summon[Unboxing[Float, JFloat]]", since = "3.0.0") - def FloatUnboxing: Unboxing[Float, JFloat] = summon - @deprecated("Use summon[Unboxing[Double, JDouble]]", since = "3.0.0") - def DoubleUnboxing: Unboxing[Double, JDouble] = summon + given BooleanUnboxing: Unboxing[Boolean, JBoolean] = fromImplicitConv + given ByteUnboxing: Unboxing[Byte, JByte] = fromImplicitConv + given ShortUnboxing: Unboxing[Short, JShort] = fromImplicitConv + given IntUnboxing: Unboxing[Int, JInteger] = fromImplicitConv + given LongUnboxing: Unboxing[Long, JLong] = fromImplicitConv + given FloatUnboxing: Unboxing[Float, JFloat] = fromImplicitConv + given DoubleUnboxing: Unboxing[Double, JDouble] = fromImplicitConv } trait LowPrioUnboxing { this: Unboxing.type => - given nullableUnboxing[A >: Null]: Unboxing[A, A] = Unboxing(identity) + given nullableUnboxing: [A >: Null] => Unboxing[A, A] = Unboxing(identity) } From 41bf942ee2390567764e7a40235e65d67b2f5830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 22:51:35 +0200 Subject: [PATCH 11/14] =?UTF-8?q?refactor(scala-3,core):=20GenKeyCodec=20g?= =?UTF-8?q?ivens=20=E2=86=92=20Scala=203.6=20named=20context-function=20fo?= =?UTF-8?q?rm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert GenKeyCodec given declarations to the Scala 3.6 named context-function form. Drop the @deprecated def shims introduced during the initial anonymous-given pass — the named 3.6 form restores name-stable lookup, so the shims are redundant. Co-Authored-By: Claude Opus 4.7 --- .../commons/serialization/GenKeyCodec.scala | 89 ++++++------------- 1 file changed, 26 insertions(+), 63 deletions(-) diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala index 3df5c3f82..20021057b 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenKeyCodec.scala @@ -60,75 +60,38 @@ object GenKeyCodec { } } - given GenKeyCodec[Boolean] = create(_.toBoolean, _.toString) - given GenKeyCodec[Char] = create(_.charAt(0), _.toString) - given GenKeyCodec[Byte] = create(_.toByte, _.toString) - given GenKeyCodec[Short] = create(_.toShort, _.toString) - given GenKeyCodec[Int] = create(_.toInt, _.toString) - given GenKeyCodec[Long] = create(_.toLong, _.toString) - given GenKeyCodec[BigInt] = create(BigInt(_), _.toString) - - given GenKeyCodec[JBoolean] = create(_.toBoolean, _.toString) - given GenKeyCodec[JCharacter] = create(_.charAt(0), _.toString) - given GenKeyCodec[JByte] = create(_.toByte, _.toString) - given GenKeyCodec[JShort] = create(_.toShort, _.toString) - given GenKeyCodec[JInteger] = create(_.toInt, _.toString) - given GenKeyCodec[JLong] = create(_.toLong, _.toString) - given GenKeyCodec[JBigInteger] = create(new JBigInteger(_), _.toString) - - given GenKeyCodec[String] = create(identity, identity) - given GenKeyCodec[Symbol] = create(Symbol(_), _.name) - given GenKeyCodec[UUID] = create(UUID.fromString, _.toString) - - given GenKeyCodec[Timestamp] = GenKeyCodec.create(Timestamp.parse, _.toString) - given GenKeyCodec[Bytes] = GenKeyCodec.create(Bytes.fromBase64(_), _.base64) - - given jEnumKeyCodec[E <: Enum[E]](using ct: ClassTag[E]): GenKeyCodec[E] = + given BooleanKeyCodec: GenKeyCodec[Boolean] = create(_.toBoolean, _.toString) + given CharKeyCodec: GenKeyCodec[Char] = create(_.charAt(0), _.toString) + given ByteKeyCodec: GenKeyCodec[Byte] = create(_.toByte, _.toString) + given ShortKeyCodec: GenKeyCodec[Short] = create(_.toShort, _.toString) + given IntKeyCodec: GenKeyCodec[Int] = create(_.toInt, _.toString) + given LongKeyCodec: GenKeyCodec[Long] = create(_.toLong, _.toString) + given BigIntKeyCodec: GenKeyCodec[BigInt] = create(BigInt(_), _.toString) + + given JBooleanKeyCodec: GenKeyCodec[JBoolean] = create(_.toBoolean, _.toString) + given JCharacterKeyCodec: GenKeyCodec[JCharacter] = create(_.charAt(0), _.toString) + given JByteKeyCodec: GenKeyCodec[JByte] = create(_.toByte, _.toString) + given JShortKeyCodec: GenKeyCodec[JShort] = create(_.toShort, _.toString) + given JIntKeyCodec: GenKeyCodec[JInteger] = create(_.toInt, _.toString) + given JLongKeyCodec: GenKeyCodec[JLong] = create(_.toLong, _.toString) + given JBigIntegerKeyCodec: GenKeyCodec[JBigInteger] = create(new JBigInteger(_), _.toString) + + given StringKeyCodec: GenKeyCodec[String] = create(identity, identity) + given SymbolKeyCodec: GenKeyCodec[Symbol] = create(Symbol(_), _.name) + given UUIDKeyCodec: GenKeyCodec[UUID] = create(UUID.fromString, _.toString) + + given TimestampKeyCodec: GenKeyCodec[Timestamp] = GenKeyCodec.create(Timestamp.parse, _.toString) + given BytesKeyCodec: GenKeyCodec[Bytes] = GenKeyCodec.create(Bytes.fromBase64(_), _.base64) + + given jEnumKeyCodec: [E <: Enum[E]] => (ct: ClassTag[E]) => GenKeyCodec[E] = GenKeyCodec.create( string => Enum.valueOf(ct.runtimeClass.asInstanceOf[Class[E]], string), e => e.name(), ) // Warning! Changing the order of implicit params of this method causes divergent implicit expansion (WTF?) - given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrappedCodec: GenKeyCodec[R]) - : GenKeyCodec[T] = + given fromTransparentWrapping + : [R, T] => (tw: TransparentWrapping[R, T]) => (wrappedCodec: GenKeyCodec[R]) => GenKeyCodec[T] = new Transformed(wrappedCodec, tw.unwrap, tw.wrap) - // Source-compat aliases for callers that previously referenced these by name. - @deprecated("Use summon[GenKeyCodec[Boolean]]", since = "3.0.0") - def BooleanKeyCodec: GenKeyCodec[Boolean] = summon - @deprecated("Use summon[GenKeyCodec[Char]]", since = "3.0.0") - def CharKeyCodec: GenKeyCodec[Char] = summon - @deprecated("Use summon[GenKeyCodec[Byte]]", since = "3.0.0") - def ByteKeyCodec: GenKeyCodec[Byte] = summon - @deprecated("Use summon[GenKeyCodec[Short]]", since = "3.0.0") - def ShortKeyCodec: GenKeyCodec[Short] = summon - @deprecated("Use summon[GenKeyCodec[Int]]", since = "3.0.0") - def IntKeyCodec: GenKeyCodec[Int] = summon - @deprecated("Use summon[GenKeyCodec[Long]]", since = "3.0.0") - def LongKeyCodec: GenKeyCodec[Long] = summon - @deprecated("Use summon[GenKeyCodec[BigInt]]", since = "3.0.0") - def BigIntKeyCodec: GenKeyCodec[BigInt] = summon - @deprecated("Use summon[GenKeyCodec[JBoolean]]", since = "3.0.0") - def JBooleanKeyCodec: GenKeyCodec[JBoolean] = summon - @deprecated("Use summon[GenKeyCodec[JCharacter]]", since = "3.0.0") - def JCharacterKeyCodec: GenKeyCodec[JCharacter] = summon - @deprecated("Use summon[GenKeyCodec[JByte]]", since = "3.0.0") - def JByteKeyCodec: GenKeyCodec[JByte] = summon - @deprecated("Use summon[GenKeyCodec[JShort]]", since = "3.0.0") - def JShortKeyCodec: GenKeyCodec[JShort] = summon - @deprecated("Use summon[GenKeyCodec[JInteger]]", since = "3.0.0") - def JIntKeyCodec: GenKeyCodec[JInteger] = summon - @deprecated("Use summon[GenKeyCodec[JLong]]", since = "3.0.0") - def JLongKeyCodec: GenKeyCodec[JLong] = summon - @deprecated("Use summon[GenKeyCodec[JBigInteger]]", since = "3.0.0") - def JBigIntegerKeyCodec: GenKeyCodec[JBigInteger] = summon - @deprecated("Use summon[GenKeyCodec[String]]", since = "3.0.0") - def StringKeyCodec: GenKeyCodec[String] = summon - @deprecated("Use summon[GenKeyCodec[Symbol]]", since = "3.0.0") - def SymbolKeyCodec: GenKeyCodec[Symbol] = summon - @deprecated("Use summon[GenKeyCodec[Timestamp]]", since = "3.0.0") - def TimestampKeyCodec: GenKeyCodec[Timestamp] = summon - @deprecated("Use summon[GenKeyCodec[Bytes]]", since = "3.0.0") - def BytesKeyCodec: GenKeyCodec[Bytes] = summon } From f080b1c41218d15a14cbf815ed19daf0139b1889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 22:53:41 +0200 Subject: [PATCH 12/14] =?UTF-8?q?refactor(scala-3,core):=20SealedUtils=20+?= =?UTF-8?q?=20TypedMap=20givens=20=E2=86=92=20Scala=203.6=20named=20contex?= =?UTF-8?q?t-function=20form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert SealedUtils and TypedMap given declarations to the Scala 3.6 named context-function form. Co-Authored-By: Claude Opus 4.7 --- .../main/scala/com/avsystem/commons/misc/SealedUtils.scala | 3 +-- .../src/main/scala/com/avsystem/commons/misc/TypedMap.scala | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala b/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala index 5075b004f..293dd5b4f 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/SealedUtils.scala @@ -153,8 +153,7 @@ object OrderedEnum { private object reusableOrdering extends Ordering[OrderedEnum] { def compare(x: OrderedEnum, y: OrderedEnum) = Integer.compare(x.sourceInfo.offset, y.sourceInfo.offset) } - given ordering[T <: OrderedEnum]: Ordering[T] = - reusableOrdering.asInstanceOf[Ordering[T]] + given ordering: [T <: OrderedEnum] => Ordering[T] = reusableOrdering.asInstanceOf[Ordering[T]] } abstract class AbstractNamedEnumCompanion[T <: NamedEnum] diff --git a/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala b/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala index c7634d765..b86944e70 100644 --- a/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala +++ b/core/src/main/scala/com/avsystem/commons/misc/TypedMap.scala @@ -88,8 +88,8 @@ object TypedMap { def valueCodec[T](key: K[T]): GenCodec[T] } - given typedMapCodec[K[_]](using keyCodec: GenKeyCodec[K[Any]], codecMapping: GenCodecMapping[K]) - : GenObjectCodec[TypedMap[K]] = + given typedMapCodec: [K[_]] => (keyCodec: GenKeyCodec[K[Any]], codecMapping: GenCodecMapping[K]) + => GenObjectCodec[TypedMap[K]] = new GenCodec.ObjectCodec[TypedMap[K]] { def nullable = false def readObject(input: ObjectInput): TypedMap[K] = { @@ -122,7 +122,7 @@ trait TypedKey[T] { def valueCodec: GenCodec[T] } object TypedKey { - given codecMapping[K[X] <: TypedKey[X]]: GenCodecMapping[K] = + given codecMapping: [K[X] <: TypedKey[X]] => GenCodecMapping[K] = new GenCodecMapping[K] { def valueCodec[T](key: K[T]): GenCodec[T] = key.valueCodec } From c716bc5f9055805ee2dff1ce98241f3369ebe8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 23:08:49 +0200 Subject: [PATCH 13/14] =?UTF-8?q?refactor(scala-3,core):=20GenCodec=20give?= =?UTF-8?q?ns=20=E2=86=92=20named=20Scala=203.6=20form,=20drop=20@deprecat?= =?UTF-8?q?ed=20shims?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert anonymous primitive + parameterized givens to named form: Primitives (29 givens): given NothingCodec: GenCodec[Nothing] = ... (etc.) Restored original NothingCodec/NullCodec/UnitCodec/.../BytesCodec identifiers as named givens, removing the parallel '@deprecated def NAME = summon' source-compat shims. Parameterized (named Scala 3.6 context-function form): given arrayCodec: [T: ClassTag: GenCodec] => GenCodec[Array[T]] given seqCodec: [C[X] <: BSeq[X], T: GenCodec] => Factory[T, C[T]] => GenCodec[...] given setCodec / jCollectionCodec / mapCodec / jMapCodec — same shape given optionCodec: [T: GenCodec] => GenCodec[Option[T]] given optCodec / nOptCodec / optArgCodec / optRefCodec / eitherCodec / jEnumCodec given fromTransparentWrapping (companion + OOOFieldsObjectCodec): [R, T] => ... given fromFallback / materializeImplicitly: [T] => ... macroCodecs.scala: pattern-match cases updated from compiler-mangled 'GenCodec.given_GenCodec_Boolean/Int/Long/Double' to the new stable named-given identifiers 'GenCodec.BooleanCodec/IntCodec/LongCodec/DoubleCodec'. User directive 2026-06-01: all givens in this slice should be named. Named givens restore the original API names as the primary identifiers. --- .../commons/serialization/GenCodec.scala | 170 ++++++------------ .../commons/serialization/macroCodecs.scala | 8 +- 2 files changed, 58 insertions(+), 120 deletions(-) diff --git a/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala b/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala index 75d5a6c63..04e63b366 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/GenCodec.scala @@ -307,8 +307,8 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { def nullable: Boolean = wrapped.nullable } - given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrapped: OOOFieldsObjectCodec[R]) - : OOOFieldsObjectCodec[T] = + given fromTransparentWrapping: [R, T] => (tw: TransparentWrapping[R, T]) => (wrapped: OOOFieldsObjectCodec[R]) + => OOOFieldsObjectCodec[T] = new Transformed(wrapped, tw.unwrap, tw.wrap) } @@ -348,118 +348,55 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { private def notNull = throw new ReadFailure("not null") - given GenCodec[Nothing] = + given NothingCodec: GenCodec[Nothing] = create[Nothing](_ => throw new ReadFailure("read Nothing"), (_, _) => throw new WriteFailure("write Nothing")) - given GenCodec[Null] = + given NullCodec: GenCodec[Null] = create[Null](i => if (i.readNull()) null else notNull, (o, _) => o.writeNull()) - given GenCodec[Unit] = + given UnitCodec: GenCodec[Unit] = create[Unit](i => if (i.readNull()) () else notNull, (o, _) => o.writeNull()) - given GenCodec[Void] = + given VoidCodec: GenCodec[Void] = create[Void](i => if (i.readNull()) null else notNull, (o, _) => o.writeNull()) - given GenCodec[Boolean] = nonNullSimple(_.readBoolean(), _ writeBoolean _) - given GenCodec[Char] = nonNullSimple(_.readChar(), _ writeChar _) - given GenCodec[Byte] = nonNullSimple(_.readByte(), _ writeByte _) - given GenCodec[Short] = nonNullSimple(_.readShort(), _ writeShort _) - given GenCodec[Int] = nonNullSimple(_.readInt(), _ writeInt _) - given GenCodec[Long] = nonNullSimple(_.readLong(), _ writeLong _) - given GenCodec[Float] = nonNullSimple(_.readFloat(), _ writeFloat _) - given GenCodec[Double] = nonNullSimple(_.readDouble(), _ writeDouble _) - given GenCodec[BigInt] = nullableSimple(_.readBigInt(), _ writeBigInt _) - given GenCodec[BigDecimal] = nullableSimple(_.readBigDecimal(), _ writeBigDecimal _) - - given GenCodec[JBoolean] = nullableSimple(_.readBoolean(), _ writeBoolean _) - given GenCodec[JCharacter] = nullableSimple(_.readChar(), _ writeChar _) - given GenCodec[JByte] = nullableSimple(_.readByte(), _ writeByte _) - given GenCodec[JShort] = nullableSimple(_.readShort(), _ writeShort _) - given GenCodec[JInteger] = nullableSimple(_.readInt(), _ writeInt _) - given GenCodec[JLong] = nullableSimple(_.readLong(), _ writeLong _) - given GenCodec[JFloat] = nullableSimple(_.readFloat(), _ writeFloat _) - given GenCodec[JDouble] = nullableSimple(_.readDouble(), _ writeDouble _) - given GenCodec[JBigInteger] = + given BooleanCodec: GenCodec[Boolean] = nonNullSimple(_.readBoolean(), _ writeBoolean _) + given CharCodec: GenCodec[Char] = nonNullSimple(_.readChar(), _ writeChar _) + given ByteCodec: GenCodec[Byte] = nonNullSimple(_.readByte(), _ writeByte _) + given ShortCodec: GenCodec[Short] = nonNullSimple(_.readShort(), _ writeShort _) + given IntCodec: GenCodec[Int] = nonNullSimple(_.readInt(), _ writeInt _) + given LongCodec: GenCodec[Long] = nonNullSimple(_.readLong(), _ writeLong _) + given FloatCodec: GenCodec[Float] = nonNullSimple(_.readFloat(), _ writeFloat _) + given DoubleCodec: GenCodec[Double] = nonNullSimple(_.readDouble(), _ writeDouble _) + given BigIntCodec: GenCodec[BigInt] = nullableSimple(_.readBigInt(), _ writeBigInt _) + given BigDecimalCodec: GenCodec[BigDecimal] = nullableSimple(_.readBigDecimal(), _ writeBigDecimal _) + + given JBooleanCodec: GenCodec[JBoolean] = nullableSimple(_.readBoolean(), _ writeBoolean _) + given JCharacterCodec: GenCodec[JCharacter] = nullableSimple(_.readChar(), _ writeChar _) + given JByteCodec: GenCodec[JByte] = nullableSimple(_.readByte(), _ writeByte _) + given JShortCodec: GenCodec[JShort] = nullableSimple(_.readShort(), _ writeShort _) + given JIntegerCodec: GenCodec[JInteger] = nullableSimple(_.readInt(), _ writeInt _) + given JLongCodec: GenCodec[JLong] = nullableSimple(_.readLong(), _ writeLong _) + given JFloatCodec: GenCodec[JFloat] = nullableSimple(_.readFloat(), _ writeFloat _) + given JDoubleCodec: GenCodec[JDouble] = nullableSimple(_.readDouble(), _ writeDouble _) + given JBigIntegerCodec: GenCodec[JBigInteger] = nullableSimple(_.readBigInt().bigInteger, (o, v) => o.writeBigInt(BigInt(v))) - given GenCodec[JBigDecimal] = + given JBigDecimalCodec: GenCodec[JBigDecimal] = nullableSimple(_.readBigDecimal().bigDecimal, (o, v) => o.writeBigDecimal(BigDecimal(v))) - given GenCodec[JDate] = + given JDateCodec: GenCodec[JDate] = nullableSimple(i => new JDate(i.readTimestamp()), (o, d) => o.writeTimestamp(d.getTime)) - given GenCodec[String] = + given StringCodec: GenCodec[String] = nullableSimple(_.readString(), _ writeString _) - given GenCodec[Symbol] = + given SymbolCodec: GenCodec[Symbol] = nullableSimple(i => Symbol(i.readString()), (o, s) => o.writeString(s.name)) - given GenCodec[Array[Byte]] = + given ByteArrayCodec: GenCodec[Array[Byte]] = nullableSimple(_.readBinary(), _ writeBinary _) - given GenCodec[UUID] = + given UuidCodec: GenCodec[UUID] = nullableSimple(i => UUID.fromString(i.readString()), (o, v) => o.writeString(v.toString)) - given GenCodec[Timestamp] = + given TimestampCodec: GenCodec[Timestamp] = GenCodec.nonNullSimple(i => Timestamp(i.readTimestamp()), (o, t) => o.writeTimestamp(t.millis)) - given GenCodec[Bytes] = + given BytesCodec: GenCodec[Bytes] = GenCodec.nullableSimple(i => Bytes(i.readBinary()), (o, b) => o.writeBinary(b.bytes)) - @deprecated("use summon[GenCodec[Nothing]]", since = "3.0.0") - def NothingCodec: GenCodec[Nothing] = summon[GenCodec[Nothing]] - @deprecated("use summon[GenCodec[Null]]", since = "3.0.0") - def NullCodec: GenCodec[Null] = summon[GenCodec[Null]] - @deprecated("use summon[GenCodec[Unit]]", since = "3.0.0") - def UnitCodec: GenCodec[Unit] = summon[GenCodec[Unit]] - @deprecated("use summon[GenCodec[Void]]", since = "3.0.0") - def VoidCodec: GenCodec[Void] = summon[GenCodec[Void]] - @deprecated("use summon[GenCodec[Boolean]]", since = "3.0.0") - def BooleanCodec: GenCodec[Boolean] = summon[GenCodec[Boolean]] - @deprecated("use summon[GenCodec[Char]]", since = "3.0.0") - def CharCodec: GenCodec[Char] = summon[GenCodec[Char]] - @deprecated("use summon[GenCodec[Byte]]", since = "3.0.0") - def ByteCodec: GenCodec[Byte] = summon[GenCodec[Byte]] - @deprecated("use summon[GenCodec[Short]]", since = "3.0.0") - def ShortCodec: GenCodec[Short] = summon[GenCodec[Short]] - @deprecated("use summon[GenCodec[Int]]", since = "3.0.0") - def IntCodec: GenCodec[Int] = summon[GenCodec[Int]] - @deprecated("use summon[GenCodec[Long]]", since = "3.0.0") - def LongCodec: GenCodec[Long] = summon[GenCodec[Long]] - @deprecated("use summon[GenCodec[Float]]", since = "3.0.0") - def FloatCodec: GenCodec[Float] = summon[GenCodec[Float]] - @deprecated("use summon[GenCodec[Double]]", since = "3.0.0") - def DoubleCodec: GenCodec[Double] = summon[GenCodec[Double]] - @deprecated("use summon[GenCodec[BigInt]]", since = "3.0.0") - def BigIntCodec: GenCodec[BigInt] = summon[GenCodec[BigInt]] - @deprecated("use summon[GenCodec[BigDecimal]]", since = "3.0.0") - def BigDecimalCodec: GenCodec[BigDecimal] = summon[GenCodec[BigDecimal]] - @deprecated("use summon[GenCodec[JBoolean]]", since = "3.0.0") - def JBooleanCodec: GenCodec[JBoolean] = summon[GenCodec[JBoolean]] - @deprecated("use summon[GenCodec[JCharacter]]", since = "3.0.0") - def JCharacterCodec: GenCodec[JCharacter] = summon[GenCodec[JCharacter]] - @deprecated("use summon[GenCodec[JByte]]", since = "3.0.0") - def JByteCodec: GenCodec[JByte] = summon[GenCodec[JByte]] - @deprecated("use summon[GenCodec[JShort]]", since = "3.0.0") - def JShortCodec: GenCodec[JShort] = summon[GenCodec[JShort]] - @deprecated("use summon[GenCodec[JInteger]]", since = "3.0.0") - def JIntegerCodec: GenCodec[JInteger] = summon[GenCodec[JInteger]] - @deprecated("use summon[GenCodec[JLong]]", since = "3.0.0") - def JLongCodec: GenCodec[JLong] = summon[GenCodec[JLong]] - @deprecated("use summon[GenCodec[JFloat]]", since = "3.0.0") - def JFloatCodec: GenCodec[JFloat] = summon[GenCodec[JFloat]] - @deprecated("use summon[GenCodec[JDouble]]", since = "3.0.0") - def JDoubleCodec: GenCodec[JDouble] = summon[GenCodec[JDouble]] - @deprecated("use summon[GenCodec[JBigInteger]]", since = "3.0.0") - def JBigIntegerCodec: GenCodec[JBigInteger] = summon[GenCodec[JBigInteger]] - @deprecated("use summon[GenCodec[JBigDecimal]]", since = "3.0.0") - def JBigDecimalCodec: GenCodec[JBigDecimal] = summon[GenCodec[JBigDecimal]] - @deprecated("use summon[GenCodec[JDate]]", since = "3.0.0") - def JDateCodec: GenCodec[JDate] = summon[GenCodec[JDate]] - @deprecated("use summon[GenCodec[String]]", since = "3.0.0") - def StringCodec: GenCodec[String] = summon[GenCodec[String]] - @deprecated("use summon[GenCodec[Symbol]]", since = "3.0.0") - def SymbolCodec: GenCodec[Symbol] = summon[GenCodec[Symbol]] - @deprecated("use summon[GenCodec[Array[Byte]]]", since = "3.0.0") - def ByteArrayCodec: GenCodec[Array[Byte]] = summon[GenCodec[Array[Byte]]] - @deprecated("use summon[GenCodec[UUID]]", since = "3.0.0") - def UuidCodec: GenCodec[UUID] = summon[GenCodec[UUID]] - @deprecated("use summon[GenCodec[Timestamp]]", since = "3.0.0") - def TimestampCodec: GenCodec[Timestamp] = summon[GenCodec[Timestamp]] - @deprecated("use summon[GenCodec[Bytes]]", since = "3.0.0") - def BytesCodec: GenCodec[Bytes] = summon[GenCodec[Bytes]] - private implicit class IterableOps[A](private val coll: BIterable[A]) extends AnyVal { def writeToList(lo: ListOutput)(implicit writer: GenCodec[A]): Unit = { lo.declareSizeOf(coll) @@ -530,7 +467,7 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { } } - given arrayCodec[T: ClassTag: GenCodec]: GenCodec[Array[T]] = + given arrayCodec: [T: ClassTag: GenCodec] => GenCodec[Array[T]] = nullableList[Array[T]]( _.iterator(read[T]).toArray[T], (lo, arr) => { @@ -566,31 +503,31 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { // have these weird return types (e.g. GenCodec[C[T] with BSeq[T]] instead of just GenCodec[C[T]]) because it's a // workaround for https://groups.google.com/forum/#!topic/scala-user/O_fkaChTtg4 - given seqCodec[C[X] <: BSeq[X], T: GenCodec](using fac: Factory[T, C[T]]): GenCodec[C[T] with BSeq[T]] = + given seqCodec: [C[X] <: BSeq[X], T: GenCodec] => (fac: Factory[T, C[T]]) => GenCodec[C[T] with BSeq[T]] = nullableList[C[T] with BSeq[T]](_.collectTo[T, C[T]], (lo, c) => c.writeToList(lo)) - given setCodec[C[X] <: BSet[X], T: GenCodec](using fac: Factory[T, C[T]]): GenCodec[C[T] with BSet[T]] = + given setCodec: [C[X] <: BSet[X], T: GenCodec] => (fac: Factory[T, C[T]]) => GenCodec[C[T] with BSet[T]] = nullableList[C[T] with BSet[T]](_.collectTo[T, C[T]], (lo, c) => c.writeToList(lo)) - given jCollectionCodec[C[X] <: JCollection[X], T: GenCodec](using cbf: JFactory[T, C[T]]) - : GenCodec[C[T] with JCollection[T]] = + given jCollectionCodec: [C[X] <: JCollection[X], T: GenCodec] => (cbf: JFactory[T, C[T]]) + => GenCodec[C[T] with JCollection[T]] = nullableList[C[T]](_.collectTo[T, C[T]], (lo, c) => c.asScala.writeToList(lo)) - given mapCodec[M[X, Y] <: BMap[X, Y], K: GenKeyCodec, V: GenCodec](using fac: Factory[(K, V), M[K, V]]) - : GenObjectCodec[M[K, V]] = + given mapCodec: [M[X, Y] <: BMap[X, Y], K: GenKeyCodec, V: GenCodec] => (fac: Factory[(K, V), M[K, V]]) + => GenObjectCodec[M[K, V]] = nullableObject[M[K, V]]( _.collectTo[K, V, M[K, V]], (oo, value) => value.writeToObject(oo), ) - given jMapCodec[M[X, Y] <: JMap[X, Y], K: GenKeyCodec, V: GenCodec](using cbf: JFactory[(K, V), M[K, V]]) - : GenObjectCodec[M[K, V]] = + given jMapCodec: [M[X, Y] <: JMap[X, Y], K: GenKeyCodec, V: GenCodec] => (cbf: JFactory[(K, V), M[K, V]]) + => GenObjectCodec[M[K, V]] = nullableObject[M[K, V]]( _.collectTo[K, V, M[K, V]], (oo, value) => value.asScala.writeToObject(oo), ) - given optionCodec[T: GenCodec]: GenCodec[Option[T]] = create[Option[T]]( + given optionCodec: [T: GenCodec] => GenCodec[Option[T]] = create[Option[T]]( input => if (input.legacyOptionEncoding) { val li = input.readList() @@ -611,10 +548,10 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { }, ) - given nOptCodec[T: GenCodec]: GenCodec[NOpt[T]] = + given nOptCodec: [T: GenCodec] => GenCodec[NOpt[T]] = new Transformed[NOpt[T], Option[T]](optionCodec[T], _.toOption, _.toNOpt) - given optCodec[T: GenCodec]: GenCodec[Opt[T]] = + given optCodec: [T: GenCodec] => GenCodec[Opt[T]] = create[Opt[T]]( i => if (i.readNull()) Opt.Empty else Opt(read[T](i)), (o, vo) => @@ -624,13 +561,13 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { }, ) - given optArgCodec[T: GenCodec]: GenCodec[OptArg[T]] = + given optArgCodec: [T: GenCodec] => GenCodec[OptArg[T]] = new Transformed[OptArg[T], Opt[T]](optCodec[T], _.toOpt, _.toOptArg) - given optRefCodec[T >: Null: GenCodec]: GenCodec[OptRef[T]] = + given optRefCodec: [T >: Null: GenCodec] => GenCodec[OptRef[T]] = new Transformed[OptRef[T], Opt[T]](optCodec[T], _.toOpt, _.toOptRef) - given eitherCodec[A: GenCodec, B: GenCodec]: GenCodec[Either[A, B]] = nullableObject( + given eitherCodec: [A: GenCodec, B: GenCodec] => GenCodec[Either[A, B]] = nullableObject( oi => { val fi = oi.nextField() fi.fieldName match { @@ -648,16 +585,17 @@ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs { }, ) - given jEnumCodec[E <: Enum[E]: ClassTag]: GenCodec[E] = nullableSimple( + given jEnumCodec: [E <: Enum[E]: ClassTag] => GenCodec[E] = nullableSimple( in => Enum.valueOf(classTag[E].runtimeClass.asInstanceOf[Class[E]], in.readString()), (out, value) => out.writeString(value.name), ) // Warning! Changing the order of implicit params of this method causes divergent implicit expansion (WTF?) - given fromTransparentWrapping[R, T](using tw: TransparentWrapping[R, T], wrappedCodec: GenCodec[R]): GenCodec[T] = + given fromTransparentWrapping + : [R, T] => (tw: TransparentWrapping[R, T]) => (wrappedCodec: GenCodec[R]) => GenCodec[T] = new Transformed(wrappedCodec, tw.unwrap, tw.wrap) - given fromFallback[T](using fallback: Fallback[GenCodec[T]]): GenCodec[T] = + given fromFallback: [T] => (fallback: Fallback[GenCodec[T]]) => GenCodec[T] = fallback.value } @@ -666,5 +604,5 @@ trait RecursiveAutoCodecs { this: GenCodec.type => def materializeRecursively[T]: GenCodec[T] = ??? // TODO[scala3-port]: GenCodec.materializeImplicitly (Scala 2 macro def) (L) - given materializeImplicitly[T](using allow: AllowImplicitMacro[GenCodec[T]]): GenCodec[T] = ??? + given materializeImplicitly: [T] => (allow: AllowImplicitMacro[GenCodec[T]]) => GenCodec[T] = ??? } diff --git a/core/src/main/scala/com/avsystem/commons/serialization/macroCodecs.scala b/core/src/main/scala/com/avsystem/commons/serialization/macroCodecs.scala index 74c23c506..251ed0237 100644 --- a/core/src/main/scala/com/avsystem/commons/serialization/macroCodecs.scala +++ b/core/src/main/scala/com/avsystem/commons/serialization/macroCodecs.scala @@ -43,7 +43,7 @@ abstract class ApplyUnapplyCodec[T]( protected final def writeField(output: ObjectOutput, idx: Int, value: Boolean): Unit = deps(idx) match { - case GenCodec.given_GenCodec_Boolean => writeField(fieldNames(idx), output, value) + case GenCodec.BooleanCodec => writeField(fieldNames(idx), output, value) case codec: GenCodec[Boolean @unchecked] => writeField(fieldNames(idx), output, value, codec) } @@ -54,7 +54,7 @@ abstract class ApplyUnapplyCodec[T]( protected final def writeField(output: ObjectOutput, idx: Int, value: Int): Unit = deps(idx) match { - case GenCodec.given_GenCodec_Int => writeField(fieldNames(idx), output, value) + case GenCodec.IntCodec => writeField(fieldNames(idx), output, value) case codec: GenCodec[Int @unchecked] => writeField(fieldNames(idx), output, value, codec) } @@ -65,7 +65,7 @@ abstract class ApplyUnapplyCodec[T]( protected final def writeField(output: ObjectOutput, idx: Int, value: Long): Unit = deps(idx) match { - case GenCodec.given_GenCodec_Long => writeField(fieldNames(idx), output, value) + case GenCodec.LongCodec => writeField(fieldNames(idx), output, value) case codec: GenCodec[Long @unchecked] => writeField(fieldNames(idx), output, value, codec) } @@ -76,7 +76,7 @@ abstract class ApplyUnapplyCodec[T]( protected final def writeField(output: ObjectOutput, idx: Int, value: Double): Unit = deps(idx) match { - case GenCodec.given_GenCodec_Double => writeField(fieldNames(idx), output, value) + case GenCodec.DoubleCodec => writeField(fieldNames(idx), output, value) case codec: GenCodec[Double @unchecked] => writeField(fieldNames(idx), output, value, codec) } From 4128fd3bceb0d3eed92abfc260e6a1bafbec8f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Mon, 1 Jun 2026 22:54:58 +0200 Subject: [PATCH 14/14] =?UTF-8?q?refactor(scala-3,mongo):=20MongoFormat=20?= =?UTF-8?q?+=20BsonGenCodecs=20givens=20=E2=86=92=20Scala=203.6=20named=20?= =?UTF-8?q?context-function=20form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert MongoFormat and BsonGenCodecs given declarations to the Scala 3.6 named context-function form. Drop the @deprecated def shims introduced during the initial BsonGenCodecs anonymous-given pass — named 3.6 form restores name-stable lookup. Update EntityIdMode and ObjectIdWrapperCompanion call sites accordingly. Co-Authored-By: Claude Opus 4.7 --- .../commons/mongo/BsonGenCodecs.scala | 72 +++++-------------- .../commons/mongo/typed/EntityIdMode.scala | 2 +- .../commons/mongo/typed/MongoFormat.scala | 28 ++++---- .../typed/ObjectIdWrapperCompanion.scala | 2 +- 4 files changed, 34 insertions(+), 70 deletions(-) diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala index 464809825..d2a1ea9b7 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/BsonGenCodecs.scala @@ -16,22 +16,22 @@ trait BsonGenCodecs { object BsonGenCodecs { // needed so that ObjectId can be used as ID type in AutoIdMongoEntity // (TransparentWrapping is used in EntityIdMode) - given TransparentWrapping[ObjectId, ObjectId] = TransparentWrapping.identity + given objectIdIdentityWrapping: TransparentWrapping[ObjectId, ObjectId] = TransparentWrapping.identity - given GenCodec[ObjectId] = GenCodec.nullable( + given objectIdCodec: GenCodec[ObjectId] = GenCodec.nullable( i => i.readCustom(ObjectIdMarker).getOrElse(new ObjectId(i.readSimple().readString())), (o, v) => if (!o.writeCustom(ObjectIdMarker, v)) o.writeSimple().writeString(v.toHexString), ) - given GenKeyCodec[ObjectId] = + given objectIdKeyCodec: GenKeyCodec[ObjectId] = GenKeyCodec.create(new ObjectId(_), _.toHexString) - given GenCodec[Decimal128] = GenCodec.nullable( + given decimal128Codec: GenCodec[Decimal128] = GenCodec.nullable( i => i.readCustom(Decimal128Marker).getOrElse(new Decimal128(i.readSimple().readBigDecimal().bigDecimal)), (o, v) => if (!o.writeCustom(Decimal128Marker, v)) o.writeSimple().writeBigDecimal(v.bigDecimalValue()), ) - given GenCodec[BsonValue] = GenCodec.create( + given bsonValueCodec: GenCodec[BsonValue] = GenCodec.create( i => i.readCustom(BsonValueMarker).getOrElse { val reader = new BsonBinaryReader(ByteBuffer.wrap(i.readSimple().readBinary())) @@ -51,61 +51,25 @@ object BsonGenCodecs { private def bsonValueSubCodec[T <: BsonValue](fromBsonValue: BsonValue => T): GenCodec[T] = summon[GenCodec[BsonValue]].transform(identity, fromBsonValue) - given GenCodec[BsonArray] = bsonValueSubCodec(_.asArray()) - given GenCodec[BsonBinary] = bsonValueSubCodec(_.asBinary()) - given GenCodec[BsonBoolean] = bsonValueSubCodec(_.asBoolean()) - given GenCodec[BsonDateTime] = bsonValueSubCodec(_.asDateTime()) - given GenCodec[BsonDocument] = bsonValueSubCodec(_.asDocument()) - given GenCodec[BsonDecimal128] = bsonValueSubCodec(_.asDecimal128()) - given GenCodec[BsonDouble] = bsonValueSubCodec(_.asDouble()) - given GenCodec[BsonInt32] = bsonValueSubCodec(_.asInt32()) - given GenCodec[BsonInt64] = bsonValueSubCodec(_.asInt64()) + given bsonArrayCodec: GenCodec[BsonArray] = bsonValueSubCodec(_.asArray()) + given bsonBinaryCodec: GenCodec[BsonBinary] = bsonValueSubCodec(_.asBinary()) + given bsonBooleanCodec: GenCodec[BsonBoolean] = bsonValueSubCodec(_.asBoolean()) + given bsonDateTimeCodec: GenCodec[BsonDateTime] = bsonValueSubCodec(_.asDateTime()) + given bsonDocumentCodec: GenCodec[BsonDocument] = bsonValueSubCodec(_.asDocument()) + given bsonDecimal128Codec: GenCodec[BsonDecimal128] = bsonValueSubCodec(_.asDecimal128()) + given bsonDoubleCodec: GenCodec[BsonDouble] = bsonValueSubCodec(_.asDouble()) + given bsonInt32Codec: GenCodec[BsonInt32] = bsonValueSubCodec(_.asInt32()) + given bsonInt64Codec: GenCodec[BsonInt64] = bsonValueSubCodec(_.asInt64()) - given GenCodec[BsonNull] = + given bsonNullCodec: GenCodec[BsonNull] = bsonValueSubCodec { bv => if (bv.isNull) BsonNull.VALUE else throw new ReadFailure("Input did not contain expected null value") } - given GenCodec[BsonObjectId] = + given bsonObjectIdCodec: GenCodec[BsonObjectId] = summon[GenCodec[ObjectId]].transform(_.getValue, new BsonObjectId(_)) - given GenCodec[BsonString] = - GenCodec.StringCodec.transform(_.getValue, new BsonString(_)) - - // Source-compat aliases for callers that previously referenced these by name. - @deprecated("Use summon[TransparentWrapping[ObjectId, ObjectId]]", since = "scala-3") - def objectIdIdentityWrapping: TransparentWrapping[ObjectId, ObjectId] = summon - @deprecated("Use summon[GenCodec[ObjectId]]", since = "scala-3") - def objectIdCodec: GenCodec[ObjectId] = summon - @deprecated("Use summon[GenKeyCodec[ObjectId]]", since = "scala-3") - def objectIdKeyCodec: GenKeyCodec[ObjectId] = summon - @deprecated("Use summon[GenCodec[Decimal128]]", since = "scala-3") - def decimal128Codec: GenCodec[Decimal128] = summon - @deprecated("Use summon[GenCodec[BsonValue]]", since = "scala-3") - def bsonValueCodec: GenCodec[BsonValue] = summon - @deprecated("Use summon[GenCodec[BsonArray]]", since = "scala-3") - def bsonArrayCodec: GenCodec[BsonArray] = summon - @deprecated("Use summon[GenCodec[BsonBinary]]", since = "scala-3") - def bsonBinaryCodec: GenCodec[BsonBinary] = summon - @deprecated("Use summon[GenCodec[BsonBoolean]]", since = "scala-3") - def bsonBooleanCodec: GenCodec[BsonBoolean] = summon - @deprecated("Use summon[GenCodec[BsonDateTime]]", since = "scala-3") - def bsonDateTimeCodec: GenCodec[BsonDateTime] = summon - @deprecated("Use summon[GenCodec[BsonDocument]]", since = "scala-3") - def bsonDocumentCodec: GenCodec[BsonDocument] = summon - @deprecated("Use summon[GenCodec[BsonDecimal128]]", since = "scala-3") - def bsonDecimal128Codec: GenCodec[BsonDecimal128] = summon - @deprecated("Use summon[GenCodec[BsonDouble]]", since = "scala-3") - def bsonDoubleCodec: GenCodec[BsonDouble] = summon - @deprecated("Use summon[GenCodec[BsonInt32]]", since = "scala-3") - def bsonInt32Codec: GenCodec[BsonInt32] = summon - @deprecated("Use summon[GenCodec[BsonInt64]]", since = "scala-3") - def bsonInt64Codec: GenCodec[BsonInt64] = summon - @deprecated("Use summon[GenCodec[BsonNull]]", since = "scala-3") - def bsonNullCodec: GenCodec[BsonNull] = summon - @deprecated("Use summon[GenCodec[BsonObjectId]]", since = "scala-3") - def bsonObjectIdCodec: GenCodec[BsonObjectId] = summon - @deprecated("Use summon[GenCodec[BsonString]]", since = "scala-3") - def bsonStringCodec: GenCodec[BsonString] = summon + given bsonStringCodec: GenCodec[BsonString] = + summon[GenCodec[String]].transform(_.getValue, new BsonString(_)) } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala index 64a64a72c..fbf0fa11e 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/EntityIdMode.scala @@ -21,7 +21,7 @@ sealed trait EntityIdMode[E, ID] { case EntityIdMode.Explicit() => format.fieldRefFor(MongoRef.RootRef(format), MongoEntity.Id) case EntityIdMode.Auto(idWrapping) => - val idCodec = GenCodec.fromTransparentWrapping(using idWrapping, summon[GenCodec[ObjectId]]) + val idCodec = GenCodec.fromTransparentWrapping(using idWrapping)(using summon[GenCodec[ObjectId]]) MongoRef.FieldRef(MongoRef.RootRef(format), mongoId.Id, MongoFormat.Opaque(idCodec), Opt.Empty) } } diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala index c7f1d7e85..cc36aa229 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/MongoFormat.scala @@ -93,31 +93,31 @@ object MongoFormat extends MetadataCompanion[MongoFormat] with MongoFormatLowPri wrappedFormat: MongoFormat[R], ) extends MongoFormat[T] - given collectionFormat[C[X] <: Iterable[X], T](using collectionCodec: GenCodec[C[T]], elementFormat: MongoFormat[T]) - : MongoFormat[C[T]] = CollectionFormat(collectionCodec, elementFormat) + given collectionFormat: [C[X] <: Iterable[X], T] => (collectionCodec: GenCodec[C[T]]) => (elementFormat: MongoFormat[T]) + => MongoFormat[C[T]] = CollectionFormat(collectionCodec, elementFormat) - given dictionaryFormat[M[X, Y] <: BMap[X, Y], K, V]( - using mapCodec: GenCodec[M[K, V]], + given dictionaryFormat: [M[X, Y] <: BMap[X, Y], K, V] => ( + mapCodec: GenCodec[M[K, V]], keyCodec: GenKeyCodec[K], valueFormat: MongoFormat[V], - ): MongoFormat[M[K, V]] = DictionaryFormat(mapCodec, keyCodec, valueFormat) + ) => MongoFormat[M[K, V]] = DictionaryFormat(mapCodec, keyCodec, valueFormat) // TODO[scala3-port]: K[_] → K[Any] workaround for Scala 3 wildcard-as-type-arg restriction (S) - given typedMapFormat[K[_]](using keyCodec: GenKeyCodec[K[Any]], valueFormats: MongoFormatMapping[K]) - : MongoFormat[TypedMap[K]] = + given typedMapFormat: [K[_]] => (keyCodec: GenKeyCodec[K[Any]]) => (valueFormats: MongoFormatMapping[K]) + => MongoFormat[TypedMap[K]] = TypedMapFormat[K](TypedMap.typedMapCodec, keyCodec, valueFormats) - given optionalFormat[O, T]( - using optionLike: OptionLike.Aux[O, T], + given optionalFormat: [O, T] => ( + optionLike: OptionLike.Aux[O, T], optionCodec: GenCodec[O], wrappedFormat: MongoFormat[T], - ): MongoFormat[O] = OptionalFormat(optionCodec, optionLike, wrappedFormat) + ) => MongoFormat[O] = OptionalFormat(optionCodec, optionLike, wrappedFormat) - given transparentFormat[R, T]( - using codec: GenCodec[T], + given transparentFormat: [R, T] => ( + codec: GenCodec[T], wrapping: TransparentWrapping[R, T], wrappedFormat: MongoFormat[R], - ): MongoFormat[T] = TransparentFormat(codec, wrapping, wrappedFormat) + ) => MongoFormat[T] = TransparentFormat(codec, wrapping, wrappedFormat) implicit class collectionFormatOps[C[X] <: Iterable[X], T](private val format: MongoFormat[C[T]]) extends AnyVal { def assumeCollection: CollectionFormat[C, T] = format match { @@ -154,7 +154,7 @@ object MongoFormat extends MetadataCompanion[MongoFormat] with MongoFormatLowPri } } trait MongoFormatLowPriority { this: MongoFormat.type => - given leafFormat[T: GenCodec]: MongoFormat[T] = Opaque(GenCodec[T]) + given leafFormat: [T: GenCodec] => MongoFormat[T] = Opaque(GenCodec[T]) } sealed trait MongoAdtFormat[T] extends MongoFormat[T] with TypedMetadata[T] { diff --git a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala index a51c2bd5a..9a05c5eea 100644 --- a/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala +++ b/mongo/jvm/src/main/scala/com/avsystem/commons/mongo/typed/ObjectIdWrapperCompanion.scala @@ -24,5 +24,5 @@ abstract class ObjectIdWrapperCompanion[ID] extends TransparentWrapperCompanion[ */ def get(): ID = wrap(ObjectId.get()) - given codec: GenCodec[ID] = GenCodec.fromTransparentWrapping(using this, summon[GenCodec[ObjectId]]) + given codec: GenCodec[ID] = GenCodec.fromTransparentWrapping(using this)(using summon[GenCodec[ObjectId]]) }