From f2d40eae3f6f30cc4eb364c20868d04628a31873 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 22 Apr 2024 16:43:04 +0100 Subject: [PATCH 01/59] namings and packages: scala 2 macro universe isolated --- .../macros/ClassConstructorMacro.scala | 2 +- .../macros/ConstructorMacros.scala | 30 +++++----- .../macros/FactoryConstructorMacro.scala | 4 +- .../macros/HasConstructorMacro.scala | 2 +- .../macros/TraitConstructorMacro.scala | 2 +- .../UnsupportedWiringException.scala | 2 +- .../model/reflection/ReflectionProvider.scala | 6 +- .../ReflectionProviderDefaultImpl.scala | 57 +++++++++---------- .../macros/DIUniverseLiftables.scala | 18 +++--- .../reflection/macros/FunctoidMacro.scala | 7 +-- .../universe/StaticDIUniverse.scala | 8 +-- .../universe/WithDIAssociation.scala | 8 +-- .../model/reflection/universe/WithDIKey.scala | 41 +++++-------- .../reflection/universe/WithDISafeType.scala | 12 ++-- .../universe/WithDISymbolInfo.scala | 32 +++++------ .../reflection/universe/WithDIWiring.scala | 22 +++---- 16 files changed, 120 insertions(+), 133 deletions(-) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{ => model}/reflection/ReflectionProviderDefaultImpl.scala (83%) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ClassConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ClassConstructorMacro.scala index cf3bf3519c..d238ea81e0 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ClassConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ClassConstructorMacro.scala @@ -2,8 +2,8 @@ package izumi.distage.constructors.macros import izumi.distage.constructors.{ClassConstructor, DebugProperties} import izumi.distage.model.providers.Functoid +import izumi.distage.model.reflection.ReflectionProviderDefaultImpl import izumi.distage.model.reflection.universe.StaticDIUniverse -import izumi.distage.reflection.ReflectionProviderDefaultImpl import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import scala.annotation.nowarn diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ConstructorMacros.scala index 5791750102..ae80affbd0 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ConstructorMacros.scala @@ -42,8 +42,8 @@ object ZEnvConstructorMacros { abstract class TraitConstructorMacros extends ConstructorMacrosBase { import c.universe._ - def mkTraitConstructorProvider[T: c.WeakTypeTag](wiring: u.Wiring.SingletonWiring.Trait): c.Expr[Functoid[T]] = { - val u.Wiring.SingletonWiring.Trait(targetType, classParameters, methods, _) = wiring + def mkTraitConstructorProvider[T: c.WeakTypeTag](wiring: u.MacroWiring.MacroSingletonWiring.Trait): c.Expr[Functoid[T]] = { + val u.MacroWiring.MacroSingletonWiring.Trait(targetType, classParameters, methods, _) = wiring val traitParameters = methods.map(_.asParameter) generateProvider[T, ProviderType.Trait.type](classParameters :+ traitParameters) { @@ -68,9 +68,9 @@ abstract class TraitConstructorMacros extends ConstructorMacrosBase { } } - def symbolToTrait(reflectionProvider: ReflectionProvider.Aux[u.type])(targetType: Type): u.Wiring.SingletonWiring.Trait = { + def symbolToTrait(reflectionProvider: ReflectionProvider.Aux[u.type])(targetType: Type): u.MacroWiring.MacroSingletonWiring.Trait = { reflectionProvider.symbolToWiring(targetType) match { - case trait0: u.Wiring.SingletonWiring.Trait => trait0 + case trait0: u.MacroWiring.MacroSingletonWiring.Trait => trait0 case wiring => throw new RuntimeException(s"""Tried to create a `TraitConstructor[$targetType]`, but `$targetType` is not a trait or an abstract class! | |Inferred wiring is: $wiring""".stripMargin) @@ -90,8 +90,8 @@ object TraitConstructorMacros { abstract class FactoryConstructorMacros extends ConstructorMacrosBase { import c.universe._ - def generateFactoryMethod(dependencyArgMap: Map[u.DIKey.BasicKey, c.Tree])(factoryMethod0: u.Wiring.Factory.FactoryMethod): c.Tree = { - val u.Wiring.Factory.FactoryMethod(factoryMethod, productConstructor, _) = factoryMethod0 + def generateFactoryMethod(dependencyArgMap: Map[u.MacroDIKey.BasicKey, c.Tree])(factoryMethod0: u.MacroWiring.Factory.FactoryMethod): c.Tree = { + val u.MacroWiring.Factory.FactoryMethod(factoryMethod, productConstructor, _) = factoryMethod0 val (methodArgListDecls, methodArgList) = { @nowarn("msg=outer reference") @@ -156,23 +156,23 @@ abstract class FactoryConstructorMacros extends ConstructorMacrosBase { """ } - def mkAnyConstructorFunction(wiring: u.Wiring.SingletonWiring): (List[u.Association.Parameter], Tree) = { + def mkAnyConstructorFunction(wiring: u.MacroWiring.MacroSingletonWiring): (List[u.Association.Parameter], Tree) = { wiring match { - case w: u.Wiring.SingletonWiring.Class => + case w: u.MacroWiring.MacroSingletonWiring.Class => mkClassConstructorFunction(w) - case w: u.Wiring.SingletonWiring.Trait => + case w: u.MacroWiring.MacroSingletonWiring.Trait => mkTraitConstructorFunction(w) } } - def mkClassConstructorFunction(w: u.Wiring.SingletonWiring.Class): (List[u.Association.Parameter], Tree) = { - val u.Wiring.SingletonWiring.Class(targetType, classParameters, _) = w + def mkClassConstructorFunction(w: u.MacroWiring.MacroSingletonWiring.Class): (List[u.Association.Parameter], Tree) = { + val u.MacroWiring.MacroSingletonWiring.Class(targetType, classParameters, _) = w val (associations, ctorArgs, ctorArgNamesLists) = CtorArgument.unzipLists(classParameters.map(_.map(mkCtorArgument(_)))) (associations, q"(..$ctorArgs) => new $targetType(...$ctorArgNamesLists)") } - def mkTraitConstructorFunction(wiring: u.Wiring.SingletonWiring.Trait): (List[u.Association.Parameter], Tree) = { - val u.Wiring.SingletonWiring.Trait(targetType, classParameters, methods, _) = wiring + def mkTraitConstructorFunction(wiring: u.MacroWiring.MacroSingletonWiring.Trait): (List[u.Association.Parameter], Tree) = { + val u.MacroWiring.MacroSingletonWiring.Trait(targetType, classParameters, methods, _) = wiring val (ctorAssociations, classCtorArgs, ctorParams) = CtorArgument.unzipLists(classParameters.map(_.map(mkCtorArgument(_)))) val (traitAssociations, traitCtorArgs, wireMethods) = methods.map(mkCtorArgument(_)).unzip3(CtorArgument.asTraitMethod) @@ -185,9 +185,9 @@ abstract class FactoryConstructorMacros extends ConstructorMacrosBase { ) } - def symbolToFactory(reflectionProvider: ReflectionProvider.Aux[u.type])(targetType: Type): u.Wiring.Factory = { + def symbolToFactory(reflectionProvider: ReflectionProvider.Aux[u.type])(targetType: Type): u.MacroWiring.Factory = { reflectionProvider.symbolToAnyWiring(targetType) match { - case factory: u.Wiring.Factory => factory + case factory: u.MacroWiring.Factory => factory case wiring => throw new RuntimeException(s"""Tried to create a `FactoryConstructor[$targetType]`, but `$targetType` is not a factory! | |Inferred wiring is: $wiring""".stripMargin) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/FactoryConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/FactoryConstructorMacro.scala index e9eaa769fd..8f94df6b45 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/FactoryConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/FactoryConstructorMacro.scala @@ -3,8 +3,8 @@ package izumi.distage.constructors.macros import izumi.distage.constructors.{DebugProperties, FactoryConstructor} import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider.ProviderType +import izumi.distage.model.reflection.ReflectionProviderDefaultImpl import izumi.distage.model.reflection.universe.StaticDIUniverse -import izumi.distage.reflection.ReflectionProviderDefaultImpl import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import scala.reflect.macros.blackbox @@ -24,7 +24,7 @@ object FactoryConstructorMacro { val impls = FactoryConstructorMacros(c)(macroUniverse) import impls.{c => _, u => _, _} - val macroUniverse.Wiring.Factory.WithProductDeps(factoryMethods, classParameters, methods, factoryProductsDeps) = symbolToFactory(reflectionProvider)(targetType) + val macroUniverse.MacroWiring.Factory.WithProductDeps(factoryMethods, classParameters, methods, factoryProductsDeps) = symbolToFactory(reflectionProvider)(targetType) val allParameters = classParameters :+ (methods ++ factoryProductsDeps).map(_.asParameter) if (factoryMethods.isEmpty) { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/HasConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/HasConstructorMacro.scala index 882ec5e284..19a2c70d9f 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/HasConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/HasConstructorMacro.scala @@ -3,8 +3,8 @@ package izumi.distage.constructors.macros import izumi.distage.constructors.{DebugProperties, ZEnvConstructor} import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider.ProviderType +import izumi.distage.model.reflection.ReflectionProviderDefaultImpl import izumi.distage.model.reflection.universe.StaticDIUniverse -import izumi.distage.reflection.ReflectionProviderDefaultImpl import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import zio.ZEnvironment diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/TraitConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/TraitConstructorMacro.scala index a3405c0f0b..0d92d941d8 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/TraitConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/TraitConstructorMacro.scala @@ -2,8 +2,8 @@ package izumi.distage.constructors.macros import izumi.distage.constructors.{DebugProperties, TraitConstructor} import izumi.distage.model.providers.Functoid +import izumi.distage.model.reflection.ReflectionProviderDefaultImpl import izumi.distage.model.reflection.universe.StaticDIUniverse -import izumi.distage.reflection.ReflectionProviderDefaultImpl import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import scala.reflect.macros.blackbox diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala index 148a455c52..9696aa7a4a 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala @@ -3,4 +3,4 @@ package izumi.distage.model.exceptions.reflection import izumi.distage.model.exceptions.DIException import izumi.distage.model.reflection.universe.DIUniverse -class UnsupportedWiringException(message: String, val tpe: DIUniverse#SafeType) extends DIException(message) +class UnsupportedWiringException(message: String, val tpe: DIUniverse#MacroSafeType) extends DIException(message) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProvider.scala index 4573ed0054..eafb06cea4 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProvider.scala @@ -6,11 +6,11 @@ trait ReflectionProvider { val u: DIUniverse import u._ - def parameterToAssociation(parameterSymbol: SymbolInfo): Association.Parameter + def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter def constructorParameterLists(tpe: TypeNative): List[List[Association.Parameter]] - def symbolToAnyWiring(tpe: TypeNative): Wiring - def symbolToWiring(tpe: TypeNative): Wiring + def symbolToAnyWiring(tpe: TypeNative): MacroWiring + def symbolToWiring(tpe: TypeNative): MacroWiring def zioHasParameters(transformName: String => String)(deepIntersection: List[TypeNative]): List[Association.Parameter] def isConcrete(tpe: TypeNative): Boolean diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProviderDefaultImpl.scala similarity index 83% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/ReflectionProviderDefaultImpl.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProviderDefaultImpl.scala index 674479cb69..1e923e69f8 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProviderDefaultImpl.scala @@ -1,10 +1,9 @@ -package izumi.distage.reflection +package izumi.distage.model.reflection import izumi.distage.model.definition.{Id, With} import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException -import izumi.distage.model.reflection.ReflectionProvider import izumi.distage.model.reflection.universe.DIUniverse import izumi.fundamentals.reflection.{JSRAnnotationTools, ReflectionUtil} @@ -14,7 +13,7 @@ import scala.annotation.nowarn trait ReflectionProviderDefaultImpl extends ReflectionProvider { import u.u.{Annotation, LiteralApi} - import u.{Association, DIKey, MethodSymbNative, SafeType, SymbNative, SymbolInfo, TypeNative, Wiring, stringIdContract} + import u.{Association, MacroDIKey, MacroSafeType, MacroSymbolInfo, MacroWiring, MethodSymbNative, SymbNative, TypeNative, stringIdContract} private[this] object Id { def unapply(ann: Annotation): Option[String] = { @@ -31,7 +30,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } } - private[this] def withIdKeyFromAnnotation(parameterSymbol: SymbolInfo, typeKey: DIKey.TypeKey): DIKey.BasicKey = { + private[this] def withIdKeyFromAnnotation(parameterSymbol: MacroSymbolInfo, typeKey: MacroDIKey.TypeKey): MacroDIKey.BasicKey = { parameterSymbol.findUniqueAnnotation(typeOfIdAnnotation) match { case Some(Id(name)) => typeKey.named(name) @@ -47,21 +46,21 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } } - def symbolToAnyWiring(tpe: TypeNative): Wiring = { + def symbolToAnyWiring(tpe: TypeNative): MacroWiring = { tpe match { case FactorySymbol(symbolMethods, dependencyMethods) => val factoryMethods = symbolMethods.map(_.asMethod).map(factoryMethod(tpe)) val traitMethods = dependencyMethods.map(methodToAssociation(tpe, _)) val classParameters = constructorParameterLists(tpe) - Wiring.Factory(factoryMethods, classParameters, traitMethods) + MacroWiring.Factory(factoryMethods, classParameters, traitMethods) case _ => mkConstructorWiring(factoryMethod = u.u.NoSymbol, tpe = tpe) } } - override def symbolToWiring(tpe: TypeNative): Wiring = { + override def symbolToWiring(tpe: TypeNative): MacroWiring = { mkConstructorWiring(factoryMethod = u.u.NoSymbol, tpe = tpe) } @@ -70,19 +69,19 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { deepIntersection.map { hasTpe => val tpe = hasTpe.dealias - val syntheticSymbolInfo = SymbolInfo.Static.syntheticFromType(transformName)(tpe) + val syntheticSymbolInfo = MacroSymbolInfo.Static.syntheticFromType(transformName)(tpe) Association.Parameter(syntheticSymbolInfo, keyFromSymbolResultType(syntheticSymbolInfo)) } } - private def factoryMethod(tpe: u.TypeNative)(factoryMethod: u.u.MethodSymbol): u.Wiring.Factory.FactoryMethod = { - val factoryMethodSymb = SymbolInfo.Runtime(factoryMethod, tpe, wasGeneric = false) + private def factoryMethod(tpe: u.TypeNative)(factoryMethod: u.u.MethodSymbol): u.MacroWiring.Factory.FactoryMethod = { + val factoryMethodSymb = MacroSymbolInfo.Runtime(factoryMethod, tpe, wasGeneric = false) val resultType = ReflectionUtil.norm(u.u: u.u.type) { resultOfFactoryMethod(factoryMethodSymb) .asSeenFrom(tpe, tpe.typeSymbol) } - val alreadyInSignature = factoryMethod.paramLists.flatten.map(symbol => keyFromParameter(SymbolInfo.Runtime(symbol, tpe, wasGeneric = false))) + val alreadyInSignature = factoryMethod.paramLists.flatten.map(symbol => keyFromParameter(MacroSymbolInfo.Runtime(symbol, tpe, wasGeneric = false))) val resultTypeWiring = mkConstructorWiring(factoryMethod, resultType) val excessiveTypes = alreadyInSignature.toSet -- resultTypeWiring.requiredKeys @@ -96,19 +95,19 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { ) } - Wiring.Factory.FactoryMethod(factoryMethodSymb, resultTypeWiring, alreadyInSignature) + MacroWiring.Factory.FactoryMethod(factoryMethodSymb, resultTypeWiring, alreadyInSignature) } override def constructorParameterLists(tpe: TypeNative): List[List[Association.Parameter]] = { selectConstructorArguments(tpe).toList.flatten.map(_.map(parameterToAssociation)) } - private[this] def mkConstructorWiring(factoryMethod: SymbNative, tpe: TypeNative): Wiring.SingletonWiring = { + private[this] def mkConstructorWiring(factoryMethod: SymbNative, tpe: TypeNative): MacroWiring.MacroSingletonWiring = { tpe match { case ConcreteSymbol(t) => - Wiring.SingletonWiring.Class(t, constructorParameterLists(t), getPrefix(t)) + MacroWiring.MacroSingletonWiring.Class(t, constructorParameterLists(t), getPrefix(t)) case AbstractSymbol(t) => - Wiring.SingletonWiring.Trait(t, constructorParameterLists(t), traitMethods(t), getPrefix(t)) + MacroWiring.MacroSingletonWiring.Trait(t, constructorParameterLists(t), traitMethods(t), getPrefix(t)) case FactorySymbol(mms, _) => throw new UnsupportedWiringException( @@ -122,11 +121,11 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { | | * $mms |""".stripMargin, - SafeType.create(tpe), + MacroSafeType.create(tpe), ) case _ => - val safeType = SafeType.create(tpe) + val safeType = MacroSafeType.create(tpe) val factoryMsg = if (factoryMethod != u.u.NoSymbol) { s""" | * When trying to create an implementation for result of `$factoryMethod` of factory `${factoryMethod.owner}` @@ -136,7 +135,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } } - private[this] def getPrefix(tpe: TypeNative): Option[DIKey] = { + private[this] def getPrefix(tpe: TypeNative): Option[MacroDIKey] = { if (tpe.typeSymbol.isStatic) { None } else { @@ -144,11 +143,11 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { typeRef .map(_.pre) .filterNot(m => m.termSymbol.isModule && m.termSymbol.isStatic) - .map(v => DIKey.TypeKey(SafeType.create(v))) + .map(v => MacroDIKey.TypeKey(MacroSafeType.create(v))) } } - private[this] def resultOfFactoryMethod(symbolInfo: SymbolInfo): TypeNative = { + private[this] def resultOfFactoryMethod(symbolInfo: MacroSymbolInfo): TypeNative = { symbolInfo.findUniqueAnnotation(typeOfWithAnnotation) match { case Some(With(tpe)) => tpe @@ -165,26 +164,26 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { declaredAbstractMethods.map(methodToAssociation(tpe, _)) } - override def parameterToAssociation(parameterSymbol: SymbolInfo): Association.Parameter = { + override def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter = { val key = keyFromParameter(parameterSymbol) Association.Parameter(parameterSymbol, key) } private[this] def methodToAssociation(definingClass: TypeNative, method: MethodSymbNative): Association.AbstractMethod = { - val methodSymb = SymbolInfo.Runtime(method, definingClass, wasGeneric = false) + val methodSymb = MacroSymbolInfo.Runtime(method, definingClass, wasGeneric = false) Association.AbstractMethod(methodSymb, keyFromSymbolResultType(methodSymb)) } - private[this] def keyFromParameter(parameterSymbol: SymbolInfo): DIKey.BasicKey = { + private[this] def keyFromParameter(parameterSymbol: MacroSymbolInfo): MacroDIKey.BasicKey = { val paramType = if (parameterSymbol.isByName) { parameterSymbol.finalResultType.typeArgs.head.finalResultType } else parameterSymbol.finalResultType - val typeKey = DIKey.TypeKey(SafeType.create(paramType)) + val typeKey = MacroDIKey.TypeKey(MacroSafeType.create(paramType)) withIdKeyFromAnnotation(parameterSymbol, typeKey) } - private[this] def keyFromSymbolResultType(methodSymbol: SymbolInfo): DIKey.BasicKey = { - val typeKey = DIKey.TypeKey(SafeType.create(methodSymbol.finalResultType)) + private[this] def keyFromSymbolResultType(methodSymbol: MacroSymbolInfo): MacroDIKey.BasicKey = { + val typeKey = MacroDIKey.TypeKey(MacroSafeType.create(methodSymbol.finalResultType)) withIdKeyFromAnnotation(methodSymbol, typeKey) } @@ -205,7 +204,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } // symbolintrospector - private[this] def selectConstructorArguments(tpe: TypeNative): Option[List[List[SymbolInfo]]] = { + private[this] def selectConstructorArguments(tpe: TypeNative): Option[List[List[MacroSymbolInfo]]] = { selectConstructorMethod(tpe).map { selectedConstructor => val originalParamListTypes = selectedConstructor.paramLists.map(_.map(_.typeSignature)) @@ -217,9 +216,9 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { case (origTypes, params) => origTypes.zip(params).map { case (o: u.u.AnnotatedTypeApi, p) => - SymbolInfo.Runtime(p, tpe, o.underlying.typeSymbol.isParameter, o.annotations) + MacroSymbolInfo.Runtime(p, tpe, o.underlying.typeSymbol.isParameter, o.annotations) case (o, p) => - SymbolInfo.Runtime(p, tpe, wasGeneric = o.typeSymbol.isParameter) + MacroSymbolInfo.Runtime(p, tpe, wasGeneric = o.typeSymbol.isParameter) } } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/DIUniverseLiftables.scala index e4eeeb8b0c..8882739451 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/DIUniverseLiftables.scala @@ -15,22 +15,22 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { // DIKey - protected[this] implicit val liftableTypeKey: Liftable[DIKey.TypeKey] = { - case DIKey.TypeKey(tpe) => q""" + protected[this] implicit val liftableTypeKey: Liftable[MacroDIKey.TypeKey] = { + case MacroDIKey.TypeKey(tpe) => q""" { new $modelReflectionPkg.DIKey.TypeKey(${liftTypeToSafeType(tpe.typeNative)}) } """ } - protected[this] implicit val liftableIdKey: Liftable[DIKey.IdKey[?]] = { - case idKey: DIKey.IdKey[?] => + protected[this] implicit val liftableIdKey: Liftable[MacroDIKey.IdKey[?]] = { + case idKey: MacroDIKey.IdKey[?] => val lifted = idKey.idContract.liftable(idKey.id) q"""{ new $modelReflectionPkg.DIKey.IdKey(${liftTypeToSafeType(idKey.tpe.typeNative)}, $lifted) }""" } - protected[this] implicit val liftableBasicDIKey: Liftable[DIKey.BasicKey] = { - Liftable[DIKey.BasicKey] { - case t: DIKey.TypeKey => q"${liftableTypeKey(t)}" - case i: DIKey.IdKey[?] => q"${liftableIdKey(i)}" + protected[this] implicit val liftableBasicDIKey: Liftable[MacroDIKey.BasicKey] = { + Liftable[MacroDIKey.BasicKey] { + case t: MacroDIKey.TypeKey => q"${liftableTypeKey(t)}" + case i: MacroDIKey.IdKey[?] => q"${liftableIdKey(i)}" } } @@ -41,7 +41,7 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { // types must all be resolved anyway - they cannot contain polymorphic // components, unlike general method symbols (info for which we don't generate). // (annotations always empty currently) - protected[this] implicit val liftableSymbolInfo: Liftable[SymbolInfo] = { + protected[this] implicit val liftableSymbolInfo: Liftable[MacroSymbolInfo] = { info => q"""{ $modelReflectionPkg.SymbolInfo( name = ${info.name}, diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/FunctoidMacro.scala index d33d49554e..6d6200f4f9 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/FunctoidMacro.scala @@ -2,11 +2,10 @@ package izumi.distage.model.reflection.macros import izumi.distage.constructors.DebugProperties import izumi.distage.model.providers.Functoid -import izumi.distage.model.reflection.Provider +import izumi.distage.model.reflection.{Provider, ReflectionProviderDefaultImpl} import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.model.reflection.universe.StaticDIUniverse import izumi.distage.model.reflection.universe.StaticDIUniverse.Aux -import izumi.distage.reflection.ReflectionProviderDefaultImpl import izumi.fundamentals.reflection.TrivialMacroLogger import scala.annotation.nowarn @@ -110,7 +109,7 @@ class FunctoidMacro(val c: blackbox.Context) { protected[this] def analyzeMethodRef(lambdaArgs: List[Symbol], body: Tree): List[Association.Parameter] = { def association(p: Symbol): Association.Parameter = { - reflectionProvider.parameterToAssociation(SymbolInfo.Runtime(p)) + reflectionProvider.parameterToAssociation(MacroSymbolInfo.Runtime(p)) } val lambdaParams = lambdaArgs.map(association) @@ -192,7 +191,7 @@ class FunctoidMacro(val c: blackbox.Context) { protected[this] def analyzeValRef(sig: Type): List[Association.Parameter] = { widenFunctionObject(sig).typeArgs.init.map { tpe => - val symbol = SymbolInfo.Static.syntheticFromType(c.freshName)(tpe) + val symbol = MacroSymbolInfo.Static.syntheticFromType(c.freshName)(tpe) reflectionProvider.parameterToAssociation(symbol) } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/StaticDIUniverse.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/StaticDIUniverse.scala index ae1f9e00bc..03e3b90c58 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/StaticDIUniverse.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/StaticDIUniverse.scala @@ -8,8 +8,8 @@ import scala.reflect.macros.blackbox trait StaticDIUniverse extends DIUniverse { self => override val u: SingletonUniverse - override type IdContract[T] = IdContractImpl[T] - class IdContractImpl[T: u.Liftable] extends IdContractApi[T] { + override type MacroIdContract[T] = IdContractImpl[T] + class IdContractImpl[T: u.Liftable] extends MacroIdContractApi[T] { override def repr(v: T): String = v.toString val liftable: u.Liftable[T] = implicitly @@ -22,8 +22,8 @@ object StaticDIUniverse { new StaticDIUniverse { self => override val u: c.universe.type = c.universe override protected val typeOfDistageAnnotation: TypeNative = u.typeOf[DIStageAnnotation] - override implicit val stringIdContract: IdContract[String] = new IdContractImpl[String] - override implicit def singletonStringIdContract[S <: String with Singleton]: IdContract[S] = new IdContractImpl[S] + override implicit val stringIdContract: MacroIdContract[String] = new IdContractImpl[String] + override implicit def singletonStringIdContract[S <: String with Singleton]: MacroIdContract[S] = new IdContractImpl[S] } } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIAssociation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIAssociation.scala index 6d42e433e6..a1b0ac8120 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIAssociation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIAssociation.scala @@ -5,8 +5,8 @@ import scala.reflect.macros.blackbox private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISafeType with WithDIKey with WithDISymbolInfo => sealed trait Association { - def symbol: SymbolInfo - def key: DIKey.BasicKey + def symbol: MacroSymbolInfo + def key: MacroDIKey.BasicKey final def name: String = symbol.name /** methods are always by-name */ @@ -34,14 +34,14 @@ private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISafeT } object Association { - case class Parameter(symbol: SymbolInfo, key: DIKey.BasicKey) extends Association { + case class Parameter(symbol: MacroSymbolInfo, key: MacroDIKey.BasicKey) extends Association { override final def isByName: Boolean = symbol.isByName override final def asParameter: Association.Parameter = this override final def asParameterTpe: TypeNative = tpe } // tpe is never by-name for `AbstractMethod` - case class AbstractMethod(symbol: SymbolInfo, key: DIKey.BasicKey) extends Association { + case class AbstractMethod(symbol: MacroSymbolInfo, key: MacroDIKey.BasicKey) extends Association { override final def isByName: Boolean = true override final def asParameter: Parameter = Parameter(symbol.withIsByName(true).withTpe(asParameterTpe), key) override final def asParameterTpe: TypeNative = u.appliedType(u.definitions.ByNameParamClass, tpe) // force by-name diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIKey.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIKey.scala index 45cfe50480..01e60eb1ba 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIKey.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIKey.scala @@ -1,48 +1,37 @@ package izumi.distage.model.reflection.universe -import izumi.distage.model.definition.ImplDef private[distage] trait WithDIKey { this: DIUniverseBase with WithDISafeType => - sealed trait DIKey { - def tpe: SafeType + sealed trait MacroDIKey { + def tpe: MacroSafeType } - object DIKey { - sealed trait BasicKey extends DIKey { - def withTpe(tpe: SafeType): DIKey.BasicKey + object MacroDIKey { + sealed trait BasicKey extends MacroDIKey { + def withTpe(tpe: MacroSafeType): MacroDIKey.BasicKey } - case class TypeKey(tpe: SafeType) extends BasicKey { - final def named[I: IdContract](id: I): IdKey[I] = IdKey(tpe, id) + case class TypeKey(tpe: MacroSafeType) extends BasicKey { + final def named[I: MacroIdContract](id: I): IdKey[I] = IdKey(tpe, id) - override final def withTpe(tpe: SafeType): DIKey.TypeKey = copy(tpe = tpe) + override final def withTpe(tpe: MacroSafeType): MacroDIKey.TypeKey = copy(tpe = tpe) override final def toString: String = s"{type.${tpe.toString}}" } - case class IdKey[I: IdContract](tpe: SafeType, id: I) extends BasicKey { - final val idContract: IdContract[I] = implicitly + case class IdKey[I: MacroIdContract](tpe: MacroSafeType, id: I) extends BasicKey { + final val idContract: MacroIdContract[I] = implicitly - override final def withTpe(tpe: SafeType): DIKey.IdKey[I] = copy(tpe = tpe) + override final def withTpe(tpe: MacroSafeType): MacroDIKey.IdKey[I] = copy(tpe = tpe) override final def toString: String = s"{type.${tpe.toString}@${idContract.repr(id)}}" } - - /** - * @param set Key of the parent Set. `set.tpe` must be of type `Set[T]` - * @param reference Key of `this` individual element. `reference.tpe` must be a subtype of `T` - */ - case class SetElementKey(set: DIKey, reference: DIKey, disambiguator: Option[ImplDef]) extends DIKey { - override final def tpe: SafeType = reference.tpe - - override final def toString: String = s"{set.$set/${reference.toString}#${disambiguator.fold("0")(_.hashCode.toString)}" - } } - trait IdContractApi[T] { + trait MacroIdContractApi[T] { def repr(v: T): String } - type IdContract[T] <: IdContractApi[T] + type MacroIdContract[T] <: MacroIdContractApi[T] - implicit def stringIdContract: IdContract[String] - implicit def singletonStringIdContract[S <: String with Singleton]: IdContract[S] + implicit def stringIdContract: MacroIdContract[String] + implicit def singletonStringIdContract[S <: String with Singleton]: MacroIdContract[S] } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISafeType.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISafeType.scala index 40e0708b42..7cc67413f2 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISafeType.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISafeType.scala @@ -6,9 +6,9 @@ import izumi.reflect.macrortti.{LightTypeTag, LightTypeTagImpl} private[distage] trait WithDISafeType { this: DIUniverseBase => // TODO: hotspot, hashcode on keys is inefficient - case class SafeType private ( + class MacroSafeType private( private[reflection] val typeNative: TypeNative, - private[WithDISafeType] val tag: LightTypeTag, + private[MacroSafeType] val tag: LightTypeTag, ) extends CachedHashcode with CachedRepr { @@ -17,7 +17,7 @@ private[distage] trait WithDISafeType { this: DIUniverseBase => override final def equals(obj: Any): Boolean = { obj match { - case that: SafeType => + case that: MacroSafeType => tag =:= that.tag case _ => false @@ -25,9 +25,9 @@ private[distage] trait WithDISafeType { this: DIUniverseBase => } } - object SafeType { - def create(tpe: TypeNative): SafeType = { - new SafeType(tpe, LightTypeTagImpl.makeLightTypeTag(u)(tpe)) + object MacroSafeType { + def create(tpe: TypeNative): MacroSafeType = { + new MacroSafeType(tpe, LightTypeTagImpl.makeLightTypeTag(u)(tpe)) } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISymbolInfo.scala index 6e8816399e..007f8bf3c3 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISymbolInfo.scala @@ -5,7 +5,7 @@ import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => - sealed trait SymbolInfo { + sealed trait MacroSymbolInfo { def name: String def finalResultType: TypeNative final def nonByNameFinalResultType: TypeNative = if (isByName) ReflectionUtil.stripByName(u: u.type)(finalResultType) else finalResultType @@ -15,15 +15,15 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => def annotations: List[u.Annotation] - def withTpe(tpe: TypeNative): SymbolInfo - def withIsByName(boolean: Boolean): SymbolInfo - def withAnnotations(annotations: List[u.Annotation]): SymbolInfo + def withTpe(tpe: TypeNative): MacroSymbolInfo + def withIsByName(boolean: Boolean): MacroSymbolInfo + def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo // def typeSignatureArgs: List[SymbolInfo] = underlying.typeSignature.typeArgs.map(_.typeSymbol).map(s => Runtime(s, definingClass)) } protected def typeOfDistageAnnotation: TypeNative - object SymbolInfo { + object MacroSymbolInfo { /** * You can downcast from SymbolInfo if you need access to the underlying symbol reference (for example, to use a Mirror) @@ -35,11 +35,11 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => isByName: Boolean, wasGeneric: Boolean, annotations: List[u.Annotation], - ) extends SymbolInfo { + ) extends MacroSymbolInfo { override final val name: String = underlying.name.toTermName.toString - override final def withTpe(tpe: TypeNative): SymbolInfo = copy(finalResultType = tpe) - override final def withIsByName(boolean: Boolean): SymbolInfo = copy(isByName = boolean) - override final def withAnnotations(annotations: List[u.Annotation]): SymbolInfo = copy(annotations = annotations) + override final def withTpe(tpe: TypeNative): MacroSymbolInfo = copy(finalResultType = tpe) + override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) + override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) } private[distage] object Runtime { @@ -75,14 +75,14 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => annotations: List[u.Annotation], isByName: Boolean, wasGeneric: Boolean, - ) extends SymbolInfo { - override final def withTpe(tpe: TypeNative): SymbolInfo = copy(finalResultType = tpe) - override final def withIsByName(boolean: Boolean): SymbolInfo = copy(isByName = boolean) - override final def withAnnotations(annotations: List[u.Annotation]): SymbolInfo = copy(annotations = annotations) + ) extends MacroSymbolInfo { + override final def withTpe(tpe: TypeNative): MacroSymbolInfo = copy(finalResultType = tpe) + override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) + override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) } object Static { - def syntheticFromType(transformName: String => String)(tpe: TypeNative): SymbolInfo.Static = { - SymbolInfo.Static( + def syntheticFromType(transformName: String => String)(tpe: TypeNative): MacroSymbolInfo.Static = { + MacroSymbolInfo.Static( name = transformName(tpe.typeSymbol.name.toString), finalResultType = tpe, annotations = AnnotationTools.getAllTypeAnnotations(u)(tpe), @@ -92,7 +92,7 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => } } - implicit final class SymbolInfoExtensions(symbolInfo: SymbolInfo) { + implicit final class SymbolInfoExtensions(symbolInfo: MacroSymbolInfo) { def findUniqueAnnotation(annType: TypeNative): Option[u.Annotation] = { val distageAnnos = symbolInfo.annotations.filter(t => t.tree.tpe <:< typeOfDistageAnnotation).toSet diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIWiring.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIWiring.scala index 8ea9a6cb6a..3c459afe8d 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIWiring.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIWiring.scala @@ -4,26 +4,26 @@ import scala.annotation.nowarn trait WithDIWiring { this: DIUniverseBase with WithDISafeType with WithDIKey with WithDIAssociation with WithDISymbolInfo => - sealed trait Wiring - object Wiring { - sealed trait SingletonWiring extends Wiring { - def prefix: Option[DIKey] + sealed trait MacroWiring + object MacroWiring { + sealed trait MacroSingletonWiring extends MacroWiring { + def prefix: Option[MacroDIKey] def instanceType: TypeNative def associations: Seq[Association] - def requiredKeys: Set[DIKey] = associations.map(_.key).toSet ++ prefix.toSet + def requiredKeys: Set[MacroDIKey] = associations.map(_.key).toSet ++ prefix.toSet } - object SingletonWiring { - case class Class(instanceType: TypeNative, classParameters: List[List[Association.Parameter]], prefix: Option[DIKey]) extends SingletonWiring { + object MacroSingletonWiring { + case class Class(instanceType: TypeNative, classParameters: List[List[Association.Parameter]], prefix: Option[MacroDIKey]) extends MacroSingletonWiring { override lazy val associations: List[Association] = classParameters.flatten } - case class Trait(instanceType: TypeNative, classParameters: List[List[Association.Parameter]], methods: List[Association.AbstractMethod], prefix: Option[DIKey]) - extends SingletonWiring { + case class Trait(instanceType: TypeNative, classParameters: List[List[Association.Parameter]], methods: List[Association.AbstractMethod], prefix: Option[MacroDIKey]) + extends MacroSingletonWiring { override lazy val associations: List[Association] = classParameters.flatten ++ methods } } case class Factory(factoryMethods: List[Factory.FactoryMethod], classParameters: List[List[Association.Parameter]], methods: List[Association.AbstractMethod]) - extends Wiring { + extends MacroWiring { @nowarn("msg=Unused import") final def factoryProductDepsFromObjectGraph: List[Association] = { import izumi.fundamentals.collections.IzCollections._ @@ -43,7 +43,7 @@ trait WithDIWiring { this: DIUniverseBase with WithDISafeType with WithDIKey wit } } - case class FactoryMethod(factoryMethod: SymbolInfo.Runtime, wireWith: SingletonWiring, methodArgumentKeys: Seq[DIKey]) { + case class FactoryMethod(factoryMethod: MacroSymbolInfo.Runtime, wireWith: MacroSingletonWiring, methodArgumentKeys: Seq[MacroDIKey]) { def objectGraphDeps: Seq[Association] = wireWith.associations.filterNot(methodArgumentKeys contains _.key) } } From 2cded91c3ac387a38836bbcc986bd9472e38ffc3 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 22 Apr 2024 17:19:39 +0100 Subject: [PATCH 02/59] wip --- .../izumi/distage/constructors/constructors.scala | 6 +++--- .../definition/dsl/AbstractBindingDefDSLMacro.scala | 3 +-- .../macros/ClassConstructorMacro.scala | 4 ++-- .../macros/ConstructorMacros.scala | 10 +++++----- .../macros/FactoryConstructorMacro.scala | 6 +++--- .../macros/HasConstructorMacro.scala | 6 +++--- .../macros/MakeMacro.scala | 2 +- .../macros/TraitConstructorMacro.scala | 6 +++--- .../{constructors => reflection}/macros/package.scala | 2 +- .../distage/roles/model/definition/RoleModuleDef.scala | 2 +- 10 files changed, 23 insertions(+), 24 deletions(-) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{constructors => reflection}/macros/ClassConstructorMacro.scala (97%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{constructors => reflection}/macros/ConstructorMacros.scala (99%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{constructors => reflection}/macros/FactoryConstructorMacro.scala (95%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{constructors => reflection}/macros/HasConstructorMacro.scala (95%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{constructors => reflection}/macros/MakeMacro.scala (98%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{constructors => reflection}/macros/TraitConstructorMacro.scala (92%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{constructors => reflection}/macros/package.scala (95%) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/constructors.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/constructors.scala index ff35049b1b..880851251d 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/constructors.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/constructors.scala @@ -1,6 +1,6 @@ package izumi.distage.constructors -import izumi.distage.constructors.macros.* +import izumi.distage.reflection.macros.* import izumi.distage.model.definition.dsl.ModuleDefDSL import izumi.distage.model.exceptions.macros.{TraitInitializationFailedException, UnsupportedDefinitionException} import izumi.distage.model.providers.Functoid @@ -105,12 +105,12 @@ object ZEnvConstructor { implicit def materialize[T]: ZEnvConstructor[T] = macro ZEnvConstructorMacro.mkZEnvConstructor[T] } -private[constructors] sealed trait ClassConstructorOptionalMakeDSL[T] extends Any { +private[distage] sealed trait ClassConstructorOptionalMakeDSL[T] extends Any { def provider: Functoid[T] } object ClassConstructorOptionalMakeDSL { - private[constructors] final class Impl[T](val provider: Functoid[T]) extends AnyVal with ClassConstructorOptionalMakeDSL[T] + private[distage] final class Impl[T](val provider: Functoid[T]) extends AnyVal with ClassConstructorOptionalMakeDSL[T] @inline def apply[T](functoid: Functoid[T]): ClassConstructorOptionalMakeDSL.Impl[T] = { new ClassConstructorOptionalMakeDSL.Impl[T](functoid) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala index 58b042149d..8cbc95e331 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala @@ -1,7 +1,6 @@ package izumi.distage.model.definition.dsl -import izumi.distage.constructors.macros.MakeMacro - +import izumi.distage.reflection.macros.MakeMacro import scala.language.experimental.macros trait AbstractBindingDefDSLMacro[BindDSL[_]] { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ClassConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ClassConstructorMacro.scala similarity index 97% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ClassConstructorMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ClassConstructorMacro.scala index d238ea81e0..00a6018ec9 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ClassConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ClassConstructorMacro.scala @@ -1,4 +1,4 @@ -package izumi.distage.constructors.macros +package izumi.distage.reflection.macros import izumi.distage.constructors.{ClassConstructor, DebugProperties} import izumi.distage.model.providers.Functoid @@ -12,7 +12,7 @@ import scala.reflect.macros.blackbox object ClassConstructorMacro { def mkClassConstructor[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[ClassConstructor[T]] = { - import c.universe._ + import c.universe.* val macroUniverse = StaticDIUniverse(c) val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ConstructorMacros.scala similarity index 99% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ConstructorMacros.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ConstructorMacros.scala index ae80affbd0..9604c438b6 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ConstructorMacros.scala @@ -1,4 +1,4 @@ -package izumi.distage.constructors.macros +package izumi.distage.reflection.macros import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider.ProviderType @@ -11,7 +11,7 @@ import scala.annotation.{nowarn, tailrec} import scala.reflect.macros.blackbox abstract class ClassConstructorMacros extends ConstructorMacrosBase { - import c.universe._ + import c.universe.* def mkClassConstructorProvider[T: c.WeakTypeTag](reflectionProvider: ReflectionProvider.Aux[u.type])(targetType: Type): c.Expr[Functoid[T]] = { val associations = reflectionProvider.constructorParameterLists(targetType) @@ -40,7 +40,7 @@ object ZEnvConstructorMacros { } abstract class TraitConstructorMacros extends ConstructorMacrosBase { - import c.universe._ + import c.universe.* def mkTraitConstructorProvider[T: c.WeakTypeTag](wiring: u.MacroWiring.MacroSingletonWiring.Trait): c.Expr[Functoid[T]] = { val u.MacroWiring.MacroSingletonWiring.Trait(targetType, classParameters, methods, _) = wiring @@ -88,7 +88,7 @@ object TraitConstructorMacros { } abstract class FactoryConstructorMacros extends ConstructorMacrosBase { - import c.universe._ + import c.universe.* def generateFactoryMethod(dependencyArgMap: Map[u.MacroDIKey.BasicKey, c.Tree])(factoryMethod0: u.MacroWiring.Factory.FactoryMethod): c.Tree = { val u.MacroWiring.Factory.FactoryMethod(factoryMethod, productConstructor, _) = factoryMethod0 @@ -209,7 +209,7 @@ abstract class ConstructorMacrosBase { val c: blackbox.Context val u: StaticDIUniverse.Aux[c.universe.type] - import c.universe._ + import c.universe.* def mkCtorArgument(association: u.Association): CtorArgument = { val (argName, freshArgName) = association.ctorArgumentExpr(c) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/FactoryConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FactoryConstructorMacro.scala similarity index 95% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/FactoryConstructorMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FactoryConstructorMacro.scala index 8f94df6b45..2d2fa501d8 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/FactoryConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FactoryConstructorMacro.scala @@ -1,4 +1,4 @@ -package izumi.distage.constructors.macros +package izumi.distage.reflection.macros import izumi.distage.constructors.{DebugProperties, FactoryConstructor} import izumi.distage.model.providers.Functoid @@ -12,7 +12,7 @@ import scala.reflect.macros.blackbox object FactoryConstructorMacro { def mkFactoryConstructor[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[FactoryConstructor[T]] = { - import c.universe._ + import c.universe.* val macroUniverse = StaticDIUniverse(c) val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) @@ -22,7 +22,7 @@ object FactoryConstructorMacro { requireConcreteTypeConstructor(c)("FactoryConstructor", targetType) val impls = FactoryConstructorMacros(c)(macroUniverse) - import impls.{c => _, u => _, _} + import impls.{c as _, u as _, *} val macroUniverse.MacroWiring.Factory.WithProductDeps(factoryMethods, classParameters, methods, factoryProductsDeps) = symbolToFactory(reflectionProvider)(targetType) val allParameters = classParameters :+ (methods ++ factoryProductsDeps).map(_.asParameter) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/HasConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/HasConstructorMacro.scala similarity index 95% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/HasConstructorMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/HasConstructorMacro.scala index 19a2c70d9f..1207334254 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/HasConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/HasConstructorMacro.scala @@ -1,4 +1,4 @@ -package izumi.distage.constructors.macros +package izumi.distage.reflection.macros import izumi.distage.constructors.{DebugProperties, ZEnvConstructor} import izumi.distage.model.providers.Functoid @@ -15,8 +15,8 @@ object ZEnvConstructorMacro { def mkZEnvConstructor[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[ZEnvConstructor[T]] = { val macroUniverse = StaticDIUniverse(c) val impls = ZEnvConstructorMacros(c)(macroUniverse) - import c.universe._ - import impls.{c => _, u => _, _} + import c.universe.* + import impls.{c as _, u as _, *} val targetType = weakTypeOf[T].dealias requireConcreteTypeConstructor(c)("ZEnvConstructor", targetType) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/MakeMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/MakeMacro.scala similarity index 98% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/MakeMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/MakeMacro.scala index c12ddc8961..b424188ef3 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/MakeMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/MakeMacro.scala @@ -1,4 +1,4 @@ -package izumi.distage.constructors.macros +package izumi.distage.reflection.macros import izumi.distage.constructors.{ClassConstructorOptionalMakeDSL, DebugProperties} import izumi.distage.model.definition.dsl.ModuleDefDSL diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/TraitConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/TraitConstructorMacro.scala similarity index 92% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/TraitConstructorMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/TraitConstructorMacro.scala index 0d92d941d8..e6f1aa3bd0 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/TraitConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/TraitConstructorMacro.scala @@ -1,4 +1,4 @@ -package izumi.distage.constructors.macros +package izumi.distage.reflection.macros import izumi.distage.constructors.{DebugProperties, TraitConstructor} import izumi.distage.model.providers.Functoid @@ -13,8 +13,8 @@ object TraitConstructorMacro { def mkTraitConstructor[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[TraitConstructor[T]] = { val macroUniverse = StaticDIUniverse(c) val impls = TraitConstructorMacros(c)(macroUniverse) - import c.universe._ - import impls.{c => _, u => _, _} + import c.universe.* + import impls.{c as _, u as _, *} val targetType = ReflectionUtil.norm(c.universe: c.universe.type)(weakTypeOf[T].dealias) requireConcreteTypeConstructor(c)("TraitConstructor", targetType) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/package.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/package.scala similarity index 95% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/package.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/package.scala index a7e31c6974..874b4e5c7e 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/macros/package.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/package.scala @@ -1,4 +1,4 @@ -package izumi.distage.constructors +package izumi.distage.reflection import izumi.fundamentals.reflection.ReflectionUtil diff --git a/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala b/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala index 4796167ff5..1ee89192be 100644 --- a/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala +++ b/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala @@ -1,8 +1,8 @@ package izumi.distage.roles.model.definition -import izumi.distage.constructors.macros.MakeMacro import izumi.distage.model.definition.ModuleDef import izumi.distage.model.definition.dsl.ModuleDefDSL.MakeDSL +import izumi.distage.reflection.macros.MakeMacro import izumi.distage.roles.model.RoleDescriptor.GetRoleDescriptor import izumi.distage.roles.model.definition.RoleModuleDef.RoleModuleDefMacros From 4eecc078aeece8a33c1d713ba7608c0c42958225 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 22 Apr 2024 17:28:30 +0100 Subject: [PATCH 03/59] wip --- .../model/reflection/{macros => }/FunctoidMacro.scala | 9 ++++----- .../{providers => reflection}/FunctoidMacroMethods.scala | 6 ++++-- .../{macros => universe}/DIUniverseLiftables.scala | 8 +++----- .../reflection/{ => universe}/ReflectionProvider.scala | 6 ++---- .../{ => universe}/ReflectionProviderDefaultImpl.scala | 3 +-- .../reflection/macros/ClassConstructorMacro.scala | 3 +-- .../distage/reflection/macros/ConstructorMacros.scala | 5 ++--- .../reflection/macros/FactoryConstructorMacro.scala | 3 +-- .../distage/reflection/macros/HasConstructorMacro.scala | 3 +-- .../reflection/macros/TraitConstructorMacro.scala | 3 +-- .../distage/model/definition/dsl/ModuleDefDSL.scala | 2 +- .../scala/izumi/distage/model/providers/Functoid.scala | 2 +- 12 files changed, 22 insertions(+), 31 deletions(-) rename distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/{macros => }/FunctoidMacro.scala (97%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/model/{providers => reflection}/FunctoidMacroMethods.scala (96%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/{macros => universe}/DIUniverseLiftables.scala (94%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/{ => universe}/ReflectionProvider.scala (85%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/{ => universe}/ReflectionProviderDefaultImpl.scala (99%) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacro.scala similarity index 97% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/FunctoidMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacro.scala index 6d6200f4f9..9078e8b0d0 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacro.scala @@ -1,11 +1,10 @@ -package izumi.distage.model.reflection.macros +package izumi.distage.model.reflection import izumi.distage.constructors.DebugProperties import izumi.distage.model.providers.Functoid -import izumi.distage.model.reflection.{Provider, ReflectionProviderDefaultImpl} import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.model.reflection.universe.StaticDIUniverse import izumi.distage.model.reflection.universe.StaticDIUniverse.Aux +import izumi.distage.model.reflection.universe.{DIUniverseLiftables, ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.TrivialMacroLogger import scala.annotation.nowarn @@ -27,8 +26,8 @@ class FunctoidMacro(val c: blackbox.Context) { private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) private final val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) - import c.universe._ - import macroUniverse._ + import c.universe.* + import macroUniverse.* case class ExtractedInfo(associations: List[Association.Parameter], isValReference: Boolean) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/providers/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacroMethods.scala similarity index 96% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/providers/FunctoidMacroMethods.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacroMethods.scala index a81ebbc44e..ef7b4fb649 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/providers/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacroMethods.scala @@ -1,9 +1,11 @@ -package izumi.distage.model.providers +package izumi.distage.model.reflection + +import izumi.distage.model.providers.Functoid -import izumi.distage.model.reflection.macros.FunctoidMacro import scala.language.experimental.macros import scala.language.implicitConversions + trait FunctoidMacroMethods { implicit def apply[R](fun: () => R): Functoid[R] = macro FunctoidMacro.impl[R] implicit def apply[R](fun: (?) => R): Functoid[R] = macro FunctoidMacro.impl[R] diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverseLiftables.scala similarity index 94% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/DIUniverseLiftables.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverseLiftables.scala index 8882739451..96fd07b5ab 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/macros/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverseLiftables.scala @@ -1,11 +1,9 @@ -package izumi.distage.model.reflection.macros - -import izumi.distage.model.reflection.universe._ +package izumi.distage.model.reflection.universe class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { - import u._ - import u.u._ + import u.* + import u.u.* protected[this] val modelReflectionPkg: Tree = q"_root_.izumi.distage.model.reflection" diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProvider.scala similarity index 85% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProvider.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProvider.scala index eafb06cea4..47e1699e76 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProvider.scala @@ -1,10 +1,8 @@ -package izumi.distage.model.reflection - -import izumi.distage.model.reflection.universe.DIUniverse +package izumi.distage.model.reflection.universe trait ReflectionProvider { val u: DIUniverse - import u._ + import u.* def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProviderDefaultImpl.scala similarity index 99% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProviderDefaultImpl.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProviderDefaultImpl.scala index 1e923e69f8..7b08e7c8e5 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProviderDefaultImpl.scala @@ -1,10 +1,9 @@ -package izumi.distage.model.reflection +package izumi.distage.model.reflection.universe import izumi.distage.model.definition.{Id, With} import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException -import izumi.distage.model.reflection.universe.DIUniverse import izumi.fundamentals.reflection.{JSRAnnotationTools, ReflectionUtil} import scala.annotation.nowarn diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ClassConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ClassConstructorMacro.scala index 00a6018ec9..74c7682900 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ClassConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ClassConstructorMacro.scala @@ -2,8 +2,7 @@ package izumi.distage.reflection.macros import izumi.distage.constructors.{ClassConstructor, DebugProperties} import izumi.distage.model.providers.Functoid -import izumi.distage.model.reflection.ReflectionProviderDefaultImpl -import izumi.distage.model.reflection.universe.StaticDIUniverse +import izumi.distage.model.reflection.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import scala.annotation.nowarn diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ConstructorMacros.scala index 9604c438b6..cf581377bc 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ConstructorMacros.scala @@ -2,9 +2,8 @@ package izumi.distage.reflection.macros import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.model.reflection.macros.DIUniverseLiftables -import izumi.distage.model.reflection.universe.StaticDIUniverse -import izumi.distage.model.reflection.{Provider, ReflectionProvider} +import izumi.distage.model.reflection.universe.{DIUniverseLiftables, ReflectionProvider, StaticDIUniverse} +import izumi.distage.model.reflection.Provider import izumi.fundamentals.reflection.ReflectionUtil import scala.annotation.{nowarn, tailrec} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FactoryConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FactoryConstructorMacro.scala index 2d2fa501d8..152828fb11 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FactoryConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FactoryConstructorMacro.scala @@ -3,8 +3,7 @@ package izumi.distage.reflection.macros import izumi.distage.constructors.{DebugProperties, FactoryConstructor} import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.model.reflection.ReflectionProviderDefaultImpl -import izumi.distage.model.reflection.universe.StaticDIUniverse +import izumi.distage.model.reflection.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import scala.reflect.macros.blackbox diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/HasConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/HasConstructorMacro.scala index 1207334254..b216d3dc01 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/HasConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/HasConstructorMacro.scala @@ -3,8 +3,7 @@ package izumi.distage.reflection.macros import izumi.distage.constructors.{DebugProperties, ZEnvConstructor} import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.model.reflection.ReflectionProviderDefaultImpl -import izumi.distage.model.reflection.universe.StaticDIUniverse +import izumi.distage.model.reflection.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import zio.ZEnvironment diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/TraitConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/TraitConstructorMacro.scala index e6f1aa3bd0..93c085718d 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/TraitConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/TraitConstructorMacro.scala @@ -2,8 +2,7 @@ package izumi.distage.reflection.macros import izumi.distage.constructors.{DebugProperties, TraitConstructor} import izumi.distage.model.providers.Functoid -import izumi.distage.model.reflection.ReflectionProviderDefaultImpl -import izumi.distage.model.reflection.universe.StaticDIUniverse +import izumi.distage.model.reflection.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import scala.reflect.macros.blackbox diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala index dedf20f60a..f75cc0fdcf 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala @@ -169,7 +169,7 @@ object ModuleDefDSL { * * Functoid forms an applicative functor via its [[izumi.distage.model.providers.Functoid.pure]] & [[izumi.distage.model.providers.Functoid#map2]] methods * - * @see [[izumi.distage.model.reflection.macros.FunctoidMacro]]] + * @see [[izumi.distage.model.reflection.FunctoidMacro]]] * @see Functoid is based on the Magnet Pattern: [[http://spray.io/blog/2012-12-13-the-magnet-pattern/]] * @see Essentially Functoid is a function-like entity with additional properties, so it's funny name is reasonable enough: [[https://en.wiktionary.org/wiki/-oid#English]] */ diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index 30d6c63d67..e88413b3ac 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -71,7 +71,7 @@ import scala.annotation.unused * * @note `javax.inject.Named` annotation is also supported * - * @see [[izumi.distage.model.reflection.macros.FunctoidMacro]]] + * @see [[FunctoidMacro]]] * @see Functoid is based on the Magnet Pattern: [[http://spray.io/blog/2012-12-13-the-magnet-pattern/]] * @see Essentially Functoid is a function-like entity with additional properties, so it's funny name is reasonable enough: [[https://en.wiktionary.org/wiki/-oid#English]] */ From 9d65d855e9c3dab582159ea9e0464083f887d379 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 22 Apr 2024 17:33:48 +0100 Subject: [PATCH 04/59] wip --- .../scala-2/izumi/distage/constructors/constructors.scala | 2 +- .../model/definition/dsl/AbstractBindingDefDSLMacro.scala | 2 +- .../macros/{ => constructors}/ClassConstructorMacro.scala | 2 +- .../macros/{ => constructors}/ConstructorMacros.scala | 4 ++-- .../macros/{ => constructors}/FactoryConstructorMacro.scala | 2 +- .../macros/{ => constructors}/HasConstructorMacro.scala | 2 +- .../reflection/macros/{ => constructors}/MakeMacro.scala | 2 +- .../macros/{ => constructors}/TraitConstructorMacro.scala | 2 +- .../reflection/macros/{ => constructors}/package.scala | 6 +++--- .../distage/roles/model/definition/RoleModuleDef.scala | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/{ => constructors}/ClassConstructorMacro.scala (98%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/{ => constructors}/ConstructorMacros.scala (99%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/{ => constructors}/FactoryConstructorMacro.scala (97%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/{ => constructors}/HasConstructorMacro.scala (97%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/{ => constructors}/MakeMacro.scala (98%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/{ => constructors}/TraitConstructorMacro.scala (96%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/{ => constructors}/package.scala (74%) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/constructors.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/constructors.scala index 880851251d..9130a889af 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/constructors.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/constructors/constructors.scala @@ -1,6 +1,6 @@ package izumi.distage.constructors -import izumi.distage.reflection.macros.* +import izumi.distage.reflection.macros.constructors.* import izumi.distage.model.definition.dsl.ModuleDefDSL import izumi.distage.model.exceptions.macros.{TraitInitializationFailedException, UnsupportedDefinitionException} import izumi.distage.model.providers.Functoid diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala index 8cbc95e331..40d92651f6 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala @@ -1,6 +1,6 @@ package izumi.distage.model.definition.dsl -import izumi.distage.reflection.macros.MakeMacro +import izumi.distage.reflection.macros.constructors.MakeMacro import scala.language.experimental.macros trait AbstractBindingDefDSLMacro[BindDSL[_]] { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ClassConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala similarity index 98% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ClassConstructorMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala index 74c7682900..487b64f7e3 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ClassConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala @@ -1,4 +1,4 @@ -package izumi.distage.reflection.macros +package izumi.distage.reflection.macros.constructors import izumi.distage.constructors.{ClassConstructor, DebugProperties} import izumi.distage.model.providers.Functoid diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala similarity index 99% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ConstructorMacros.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala index cf581377bc..eb5fd18ed4 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala @@ -1,9 +1,9 @@ -package izumi.distage.reflection.macros +package izumi.distage.reflection.macros.constructors import izumi.distage.model.providers.Functoid +import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.model.reflection.universe.{DIUniverseLiftables, ReflectionProvider, StaticDIUniverse} -import izumi.distage.model.reflection.Provider import izumi.fundamentals.reflection.ReflectionUtil import scala.annotation.{nowarn, tailrec} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FactoryConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala similarity index 97% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FactoryConstructorMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala index 152828fb11..2afae012ca 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FactoryConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala @@ -1,4 +1,4 @@ -package izumi.distage.reflection.macros +package izumi.distage.reflection.macros.constructors import izumi.distage.constructors.{DebugProperties, FactoryConstructor} import izumi.distage.model.providers.Functoid diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/HasConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala similarity index 97% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/HasConstructorMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala index b216d3dc01..c06f7d3c5a 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/HasConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala @@ -1,4 +1,4 @@ -package izumi.distage.reflection.macros +package izumi.distage.reflection.macros.constructors import izumi.distage.constructors.{DebugProperties, ZEnvConstructor} import izumi.distage.model.providers.Functoid diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/MakeMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/MakeMacro.scala similarity index 98% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/MakeMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/MakeMacro.scala index b424188ef3..79e08ea107 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/MakeMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/MakeMacro.scala @@ -1,4 +1,4 @@ -package izumi.distage.reflection.macros +package izumi.distage.reflection.macros.constructors import izumi.distage.constructors.{ClassConstructorOptionalMakeDSL, DebugProperties} import izumi.distage.model.definition.dsl.ModuleDefDSL diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/TraitConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala similarity index 96% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/TraitConstructorMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala index 93c085718d..c794fc3e20 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/TraitConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala @@ -1,4 +1,4 @@ -package izumi.distage.reflection.macros +package izumi.distage.reflection.macros.constructors import izumi.distage.constructors.{DebugProperties, TraitConstructor} import izumi.distage.model.providers.Functoid diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/package.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/package.scala similarity index 74% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/package.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/package.scala index 874b4e5c7e..97973581e9 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/package.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/package.scala @@ -1,12 +1,12 @@ -package izumi.distage.reflection +package izumi.distage.reflection.macros import izumi.fundamentals.reflection.ReflectionUtil import scala.reflect.macros.blackbox -package object macros { +package object constructors { - private[macros] def requireConcreteTypeConstructor(c: blackbox.Context)(macroName: String, tpe: c.Type): Unit = { + private[constructors] def requireConcreteTypeConstructor(c: blackbox.Context)(macroName: String, tpe: c.Type): Unit = { if (!ReflectionUtil.allPartsStrong(tpe.dealias.typeConstructor)) { c.abort( c.enclosingPosition, diff --git a/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala b/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala index 1ee89192be..745e2cd5d9 100644 --- a/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala +++ b/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala @@ -2,7 +2,7 @@ package izumi.distage.roles.model.definition import izumi.distage.model.definition.ModuleDef import izumi.distage.model.definition.dsl.ModuleDefDSL.MakeDSL -import izumi.distage.reflection.macros.MakeMacro +import izumi.distage.reflection.macros.constructors.MakeMacro import izumi.distage.roles.model.RoleDescriptor.GetRoleDescriptor import izumi.distage.roles.model.definition.RoleModuleDef.RoleModuleDefMacros From 2c77ee5aeabd904cbfd16de7e6dd351fb961181c Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 22 Apr 2024 17:57:05 +0100 Subject: [PATCH 05/59] wip --- .../exceptions/reflection/UnsupportedWiringException.scala | 2 +- .../reflection => reflection/macros}/FunctoidMacro.scala | 7 ++++--- .../macros}/FunctoidMacroMethods.scala | 2 +- .../macros/constructors/ClassConstructorMacro.scala | 2 +- .../reflection/macros/constructors/ConstructorMacros.scala | 2 +- .../macros/constructors/FactoryConstructorMacro.scala | 2 +- .../macros/constructors/HasConstructorMacro.scala | 2 +- .../macros/constructors/TraitConstructorMacro.scala | 2 +- .../macros}/universe/DIUniverseLiftables.scala | 2 +- .../macros}/universe/ReflectionProvider.scala | 4 +++- .../macros}/universe/ReflectionProviderDefaultImpl.scala | 3 ++- .../macros}/universe/StaticDIUniverse.scala | 3 ++- .../macros/universe/impl}/DIUniverse.scala | 2 +- .../macros/universe/impl}/DIUniverseBase.scala | 2 +- .../macros/universe/impl}/WithDIAssociation.scala | 6 +++--- .../macros/universe/impl}/WithDIKey.scala | 3 +-- .../macros/universe/impl}/WithDISafeType.scala | 2 +- .../macros/universe/impl}/WithDISymbolInfo.scala | 4 ++-- .../macros/universe/impl}/WithDIWiring.scala | 2 +- .../izumi/distage/constructors/ClassConstructorMacro.scala | 4 +++- .../izumi/distage/constructors/ConstructorUtil.scala | 5 +++-- .../distage/constructors/FactoryConstructorMacro.scala | 3 ++- .../izumi/distage/constructors/HasConstructorMacro.scala | 3 ++- .../izumi/distage/constructors/TraitConstructorMacro.scala | 3 ++- .../macros}/FunctoidMacroMethods.scala | 4 +++- .../izumi/distage/model/definition/dsl/ModuleDefDSL.scala | 2 +- .../scala/izumi/distage/model/providers/Functoid.scala | 3 ++- 27 files changed, 47 insertions(+), 34 deletions(-) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection => reflection/macros}/FunctoidMacro.scala (96%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection => reflection/macros}/FunctoidMacroMethods.scala (98%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection => reflection/macros}/universe/DIUniverseLiftables.scala (97%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection => reflection/macros}/universe/ReflectionProvider.scala (85%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection => reflection/macros}/universe/ReflectionProviderDefaultImpl.scala (99%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection => reflection/macros}/universe/StaticDIUniverse.scala (90%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection/universe => reflection/macros/universe/impl}/DIUniverse.scala (72%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection/universe => reflection/macros/universe/impl}/DIUniverseBase.scala (76%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection/universe => reflection/macros/universe/impl}/WithDIAssociation.scala (95%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection/universe => reflection/macros/universe/impl}/WithDIKey.scala (95%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection/universe => reflection/macros/universe/impl}/WithDISafeType.scala (94%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection/universe => reflection/macros/universe/impl}/WithDISymbolInfo.scala (97%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/{model/reflection/universe => reflection/macros/universe/impl}/WithDIWiring.scala (97%) rename distage/distage-core-api/src/main/scala-3/izumi/distage/{model/providers => reflection/macros}/FunctoidMacroMethods.scala (99%) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala index 9696aa7a4a..20c86963f6 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala @@ -1,6 +1,6 @@ package izumi.distage.model.exceptions.reflection import izumi.distage.model.exceptions.DIException -import izumi.distage.model.reflection.universe.DIUniverse +import izumi.distage.reflection.macros.universe.impl.DIUniverse class UnsupportedWiringException(message: String, val tpe: DIUniverse#MacroSafeType) extends DIException(message) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala similarity index 96% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacro.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 9078e8b0d0..cb9efd90fc 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -1,10 +1,11 @@ -package izumi.distage.model.reflection +package izumi.distage.reflection.macros import izumi.distage.constructors.DebugProperties import izumi.distage.model.providers.Functoid +import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.model.reflection.universe.StaticDIUniverse.Aux -import izumi.distage.model.reflection.universe.{DIUniverseLiftables, ReflectionProviderDefaultImpl, StaticDIUniverse} +import izumi.distage.reflection.macros.universe.StaticDIUniverse.Aux +import izumi.distage.reflection.macros.universe.{DIUniverseLiftables, ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.TrivialMacroLogger import scala.annotation.nowarn diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala similarity index 98% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacroMethods.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index ef7b4fb649..4b9f9918a2 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -1,4 +1,4 @@ -package izumi.distage.model.reflection +package izumi.distage.reflection.macros import izumi.distage.model.providers.Functoid diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala index 487b64f7e3..dc26146733 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala @@ -2,7 +2,7 @@ package izumi.distage.reflection.macros.constructors import izumi.distage.constructors.{ClassConstructor, DebugProperties} import izumi.distage.model.providers.Functoid -import izumi.distage.model.reflection.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} +import izumi.distage.reflection.macros.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import scala.annotation.nowarn diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala index eb5fd18ed4..ff17ef566f 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala @@ -3,7 +3,7 @@ package izumi.distage.reflection.macros.constructors import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.model.reflection.universe.{DIUniverseLiftables, ReflectionProvider, StaticDIUniverse} +import izumi.distage.reflection.macros.universe.{DIUniverseLiftables, ReflectionProvider, StaticDIUniverse} import izumi.fundamentals.reflection.ReflectionUtil import scala.annotation.{nowarn, tailrec} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala index 2afae012ca..ec8c9116be 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala @@ -3,7 +3,7 @@ package izumi.distage.reflection.macros.constructors import izumi.distage.constructors.{DebugProperties, FactoryConstructor} import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.model.reflection.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} +import izumi.distage.reflection.macros.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import scala.reflect.macros.blackbox diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala index c06f7d3c5a..9bee90599d 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala @@ -3,7 +3,7 @@ package izumi.distage.reflection.macros.constructors import izumi.distage.constructors.{DebugProperties, ZEnvConstructor} import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.model.reflection.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} +import izumi.distage.reflection.macros.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import zio.ZEnvironment diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala index c794fc3e20..08d613b590 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala @@ -2,7 +2,7 @@ package izumi.distage.reflection.macros.constructors import izumi.distage.constructors.{DebugProperties, TraitConstructor} import izumi.distage.model.providers.Functoid -import izumi.distage.model.reflection.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} +import izumi.distage.reflection.macros.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger} import scala.reflect.macros.blackbox diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala similarity index 97% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverseLiftables.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index 96fd07b5ab..023e92c79a 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -1,4 +1,4 @@ -package izumi.distage.model.reflection.universe +package izumi.distage.reflection.macros.universe class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala similarity index 85% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProvider.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala index 47e1699e76..6785bf9d10 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala @@ -1,4 +1,6 @@ -package izumi.distage.model.reflection.universe +package izumi.distage.reflection.macros.universe + +import izumi.distage.reflection.macros.universe.impl.DIUniverse trait ReflectionProvider { val u: DIUniverse diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala similarity index 99% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProviderDefaultImpl.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index 7b08e7c8e5..ba9213cf8c 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -1,9 +1,10 @@ -package izumi.distage.model.reflection.universe +package izumi.distage.reflection.macros.universe import izumi.distage.model.definition.{Id, With} import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException +import izumi.distage.reflection.macros.universe.impl.DIUniverse import izumi.fundamentals.reflection.{JSRAnnotationTools, ReflectionUtil} import scala.annotation.nowarn diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/StaticDIUniverse.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala similarity index 90% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/StaticDIUniverse.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala index 03e3b90c58..2baf8f65c6 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/StaticDIUniverse.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala @@ -1,6 +1,7 @@ -package izumi.distage.model.reflection.universe +package izumi.distage.reflection.macros.universe import izumi.distage.model.definition.DIStageAnnotation +import izumi.distage.reflection.macros.universe.impl.DIUniverse import izumi.fundamentals.reflection.SingletonUniverse import scala.reflect.macros.blackbox diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverse.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala similarity index 72% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverse.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala index 317e805377..a677e92803 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverse.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala @@ -1,3 +1,3 @@ -package izumi.distage.model.reflection.universe +package izumi.distage.reflection.macros.universe.impl trait DIUniverse extends DIUniverseBase with WithDISafeType with WithDISymbolInfo with WithDIKey with WithDIAssociation with WithDIWiring diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverseBase.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala similarity index 76% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverseBase.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala index be20f93722..84aca7d891 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/DIUniverseBase.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala @@ -1,4 +1,4 @@ -package izumi.distage.model.reflection.universe +package izumi.distage.reflection.macros.universe.impl import scala.reflect.api.Universe diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIAssociation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala similarity index 95% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIAssociation.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala index a1b0ac8120..1b8fb82499 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIAssociation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala @@ -1,4 +1,4 @@ -package izumi.distage.model.reflection.universe +package izumi.distage.reflection.macros.universe.impl import scala.reflect.macros.blackbox @@ -23,12 +23,12 @@ private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISafeT def asParameterTpe: TypeNative final def ctorArgumentExpr(c: blackbox.Context): (u.Tree, u.Tree) = { - import u._ + import u.* val freshArgName = u.TermName(c.freshName(name)) (q"val $freshArgName: $asParameterTpe", Liftable.liftName(freshArgName)) } final def traitMethodExpr(impl: u.Tree): u.Tree = { - import u._ + import u.* q"final lazy val ${TermName(name)}: $nonBynameTpe = $impl" } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIKey.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala similarity index 95% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIKey.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala index 01e60eb1ba..43eacf7132 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIKey.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala @@ -1,5 +1,4 @@ -package izumi.distage.model.reflection.universe - +package izumi.distage.reflection.macros.universe.impl private[distage] trait WithDIKey { this: DIUniverseBase with WithDISafeType => diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISafeType.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala similarity index 94% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISafeType.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala index 7cc67413f2..fd130d5ad9 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISafeType.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala @@ -1,4 +1,4 @@ -package izumi.distage.model.reflection.universe +package izumi.distage.reflection.macros.universe.impl import izumi.fundamentals.platform.cache.{CachedHashcode, CachedRepr} import izumi.reflect.macrortti.{LightTypeTag, LightTypeTagImpl} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala similarity index 97% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISymbolInfo.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index 007f8bf3c3..c68323078c 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -1,4 +1,4 @@ -package izumi.distage.model.reflection.universe +package izumi.distage.reflection.macros.universe.impl import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} @@ -97,7 +97,7 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => val distageAnnos = symbolInfo.annotations.filter(t => t.tree.tpe <:< typeOfDistageAnnotation).toSet if (distageAnnos.size > 1) { - import izumi.fundamentals.platform.strings.IzString._ + import izumi.fundamentals.platform.strings.IzString.* throw new AnnotationConflictException(s"Multiple DI annotations on symbol `$symbolInfo` in ${symbolInfo.finalResultType}: ${distageAnnos.niceList()}") } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIWiring.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala similarity index 97% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIWiring.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala index 3c459afe8d..505441cb76 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/reflection/universe/WithDIWiring.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala @@ -1,4 +1,4 @@ -package izumi.distage.model.reflection.universe +package izumi.distage.reflection.macros.universe.impl import scala.annotation.nowarn diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ClassConstructorMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ClassConstructorMacro.scala index e0ae506871..c80f37ebb4 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ClassConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ClassConstructorMacro.scala @@ -1,6 +1,8 @@ package izumi.distage.constructors -import izumi.distage.model.providers.{Functoid, FunctoidMacro} +import izumi.distage.model.providers.Functoid +import izumi.distage.reflection.macros.FunctoidMacro + import izumi.distage.model.reflection.Provider.ProviderType import scala.quoted.{Expr, Quotes, Type} diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala index 9e35aad013..f60aa133f6 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala @@ -6,8 +6,9 @@ import izumi.fundamentals.platform.reflection.ReflectionUtil import scala.annotation.{nowarn, tailrec} import scala.quoted.{Expr, Quotes, Type} import scala.collection.mutable -import izumi.distage.model.providers.{Functoid, FunctoidMacro} -import izumi.distage.model.providers.FunctoidMacro.FunctoidParametersMacro +import izumi.distage.model.providers.Functoid +import izumi.distage.reflection.macros.FunctoidMacro +import izumi.distage.reflection.macros.FunctoidMacro.FunctoidParametersMacro import izumi.distage.model.reflection.Provider.{ProviderImpl, ProviderType} import izumi.fundamentals.reflection.ReflectiveCall import izumi.reflect.WeakTag diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/FactoryConstructorMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/FactoryConstructorMacro.scala index 97b3bb965a..82c6590d5b 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/FactoryConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/FactoryConstructorMacro.scala @@ -1,6 +1,7 @@ package izumi.distage.constructors -import izumi.distage.model.providers.{Functoid, FunctoidMacro} +import izumi.distage.model.providers.Functoid +import izumi.distage.reflection.macros.FunctoidMacro import izumi.distage.model.reflection.Provider.ProviderType import izumi.fundamentals.platform.exceptions.IzThrowable.toRichThrowable import izumi.fundamentals.reflection.ReflectiveCall diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/HasConstructorMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/HasConstructorMacro.scala index 67d1f3417c..5fb8c85c3b 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/HasConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/HasConstructorMacro.scala @@ -1,6 +1,7 @@ package izumi.distage.constructors -import izumi.distage.model.providers.{Functoid, FunctoidMacro} +import izumi.distage.model.providers.Functoid +import izumi.distage.reflection.macros.FunctoidMacro import izumi.distage.model.reflection.Provider.ProviderType import izumi.fundamentals.platform.exceptions.IzThrowable.toRichThrowable import izumi.fundamentals.platform.reflection.ReflectionUtil diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/TraitConstructorMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/TraitConstructorMacro.scala index 5cd89d0213..06926b5938 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/TraitConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/TraitConstructorMacro.scala @@ -1,6 +1,7 @@ package izumi.distage.constructors -import izumi.distage.model.providers.{Functoid, FunctoidMacro} +import izumi.distage.model.providers.Functoid +import izumi.distage.reflection.macros.FunctoidMacro import izumi.distage.model.reflection.Provider.ProviderType import izumi.fundamentals.platform.exceptions.IzThrowable.toRichThrowable import izumi.reflect.WeakTag diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/model/providers/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala similarity index 99% rename from distage/distage-core-api/src/main/scala-3/izumi/distage/model/providers/FunctoidMacroMethods.scala rename to distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index a014b6f249..f07a72644f 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/model/providers/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -1,10 +1,12 @@ -package izumi.distage.model.providers +package izumi.distage.reflection.macros + import izumi.distage.model.reflection.Provider.{ProviderImpl, ProviderType} import izumi.distage.model.reflection.* import izumi.reflect.Tag import izumi.distage.model.definition.Id import izumi.fundamentals.platform.reflection.ReflectionUtil +import izumi.distage.model.providers.Functoid import scala.annotation.{tailrec, targetName} import scala.collection.immutable.List diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala index f75cc0fdcf..cc2ed8ce97 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala @@ -169,7 +169,7 @@ object ModuleDefDSL { * * Functoid forms an applicative functor via its [[izumi.distage.model.providers.Functoid.pure]] & [[izumi.distage.model.providers.Functoid#map2]] methods * - * @see [[izumi.distage.model.reflection.FunctoidMacro]]] + * @see [[izumi.distage.reflection.macros.FunctoidMacro]]] * @see Functoid is based on the Magnet Pattern: [[http://spray.io/blog/2012-12-13-the-magnet-pattern/]] * @see Essentially Functoid is a function-like entity with additional properties, so it's funny name is reasonable enough: [[https://en.wiktionary.org/wiki/-oid#English]] */ diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index e88413b3ac..e2bd790c19 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -6,6 +6,7 @@ import izumi.distage.model.exceptions.runtime.TODOBindingException import izumi.distage.model.reflection.LinkedParameter import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.model.reflection.* +import izumi.distage.reflection.macros.FunctoidMacroMethods import izumi.fundamentals.platform.language.CodePositionMaterializer import izumi.fundamentals.platform.language.Quirks.* import izumi.reflect.Tag @@ -71,7 +72,7 @@ import scala.annotation.unused * * @note `javax.inject.Named` annotation is also supported * - * @see [[FunctoidMacro]]] + * @see [[izumi.distage.reflection.macros.FunctoidMacro]]] * @see Functoid is based on the Magnet Pattern: [[http://spray.io/blog/2012-12-13-the-magnet-pattern/]] * @see Essentially Functoid is a function-like entity with additional properties, so it's funny name is reasonable enough: [[https://en.wiktionary.org/wiki/-oid#English]] */ From 49999d8c7f6b55247b8a750ccaf02ff8bf260f28 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 23 Apr 2024 15:26:51 +0100 Subject: [PATCH 06/59] wip --- build.sbt | 162 +++++++++--------- .../macros/universe/impl/WithDISafeType.scala | 16 +- .../platform/functional/package.scala | 0 .../distage/model/reflection/SafeType.scala | 5 +- .../distage/model/reflection/SymbolInfo.scala | 0 5 files changed, 94 insertions(+), 89 deletions(-) rename fundamentals/{fundamentals-bio => fundamentals-functional}/src/main/scala/izumi/fundamentals/platform/functional/package.scala (100%) rename {distage/distage-core-api => fundamentals/fundamentals-reflection}/src/main/scala/izumi/distage/model/reflection/SafeType.scala (91%) rename {distage/distage-core-api => fundamentals/fundamentals-reflection}/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala (100%) diff --git a/build.sbt b/build.sbt index aaa621b3fe..95ea589eb4 100644 --- a/build.sbt +++ b/build.sbt @@ -21,7 +21,7 @@ lazy val `fundamentals-functional` = project.in(file("fundamentals/fundamentals- ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -131,7 +131,7 @@ lazy val `fundamentals-functional` = project.in(file("fundamentals/fundamentals- "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -142,7 +142,7 @@ lazy val `fundamentals-functional` = project.in(file("fundamentals/fundamentals- case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -208,7 +208,7 @@ lazy val `fundamentals-collections` = project.in(file("fundamentals/fundamentals ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -318,7 +318,7 @@ lazy val `fundamentals-collections` = project.in(file("fundamentals/fundamentals "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -329,7 +329,7 @@ lazy val `fundamentals-collections` = project.in(file("fundamentals/fundamentals case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -393,7 +393,7 @@ lazy val `fundamentals-literals` = project.in(file("fundamentals/fundamentals-li ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -503,7 +503,7 @@ lazy val `fundamentals-literals` = project.in(file("fundamentals/fundamentals-li "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -514,7 +514,7 @@ lazy val `fundamentals-literals` = project.in(file("fundamentals/fundamentals-li case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -582,7 +582,7 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -692,7 +692,7 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -703,7 +703,7 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -751,7 +751,7 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp } }, Test / packageDoc / publishArtifact := false, Compile / doc / sources := { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq.empty + case (_, "3.4.1") => Seq.empty case (_, _) => (Compile / doc / sources).value } } ) @@ -782,7 +782,7 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -892,7 +892,7 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -903,7 +903,7 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -972,7 +972,7 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -1082,7 +1082,7 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -1093,7 +1093,7 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -1173,7 +1173,7 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -1283,7 +1283,7 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -1294,7 +1294,7 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -1364,7 +1364,7 @@ lazy val `fundamentals-reflection` = project.in(file("fundamentals/fundamentals- ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -1474,7 +1474,7 @@ lazy val `fundamentals-reflection` = project.in(file("fundamentals/fundamentals- "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -1485,7 +1485,7 @@ lazy val `fundamentals-reflection` = project.in(file("fundamentals/fundamentals- case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -1565,7 +1565,7 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -1675,7 +1675,7 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -1686,7 +1686,7 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -1734,7 +1734,7 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) } }, Test / packageDoc / publishArtifact := false, Compile / doc / sources := { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq.empty + case (_, "3.4.1") => Seq.empty case (_, _) => (Compile / doc / sources).value } } ) @@ -1768,7 +1768,7 @@ lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -1878,7 +1878,7 @@ lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -1889,7 +1889,7 @@ lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -1956,7 +1956,7 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core- ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -2066,7 +2066,7 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core- "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -2077,7 +2077,7 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core- case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -2144,7 +2144,7 @@ lazy val `distage-framework-api` = project.in(file("distage/distage-framework-ap ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -2254,7 +2254,7 @@ lazy val `distage-framework-api` = project.in(file("distage/distage-framework-ap "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -2265,7 +2265,7 @@ lazy val `distage-framework-api` = project.in(file("distage/distage-framework-ap case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -2339,7 +2339,7 @@ lazy val `distage-core` = project.in(file("distage/distage-core")) ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -2449,7 +2449,7 @@ lazy val `distage-core` = project.in(file("distage/distage-core")) "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -2460,7 +2460,7 @@ lazy val `distage-core` = project.in(file("distage/distage-core")) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -2531,7 +2531,7 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -2641,7 +2641,7 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -2652,7 +2652,7 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -2722,7 +2722,7 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -2832,7 +2832,7 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -2843,7 +2843,7 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -2918,7 +2918,7 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -3028,7 +3028,7 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -3039,7 +3039,7 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -3126,7 +3126,7 @@ lazy val `distage-framework` = project.in(file("distage/distage-framework")) ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -3236,7 +3236,7 @@ lazy val `distage-framework` = project.in(file("distage/distage-framework")) "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -3247,7 +3247,7 @@ lazy val `distage-framework` = project.in(file("distage/distage-framework")) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -3323,7 +3323,7 @@ lazy val `distage-framework-docker` = project.in(file("distage/distage-framework ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -3433,7 +3433,7 @@ lazy val `distage-framework-docker` = project.in(file("distage/distage-framework "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -3444,7 +3444,7 @@ lazy val `distage-framework-docker` = project.in(file("distage/distage-framework case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -3510,7 +3510,7 @@ lazy val `distage-testkit-core` = project.in(file("distage/distage-testkit-core" ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -3620,7 +3620,7 @@ lazy val `distage-testkit-core` = project.in(file("distage/distage-testkit-core" "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -3631,7 +3631,7 @@ lazy val `distage-testkit-core` = project.in(file("distage/distage-testkit-core" case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -3706,7 +3706,7 @@ lazy val `distage-testkit-scalatest` = project.in(file("distage/distage-testkit- ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -3816,7 +3816,7 @@ lazy val `distage-testkit-scalatest` = project.in(file("distage/distage-testkit- "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -3827,7 +3827,7 @@ lazy val `distage-testkit-scalatest` = project.in(file("distage/distage-testkit- case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -3894,7 +3894,7 @@ lazy val `distage-testkit-scalatest-sbt-module-filtering-test` = project.in(file ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -4004,7 +4004,7 @@ lazy val `distage-testkit-scalatest-sbt-module-filtering-test` = project.in(file "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -4015,7 +4015,7 @@ lazy val `distage-testkit-scalatest-sbt-module-filtering-test` = project.in(file case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -4088,7 +4088,7 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core")) ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -4198,7 +4198,7 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core")) "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -4209,7 +4209,7 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core")) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -4281,7 +4281,7 @@ lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-renderi ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -4391,7 +4391,7 @@ lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-renderi "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -4402,7 +4402,7 @@ lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-renderi case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -4469,7 +4469,7 @@ lazy val `logstage-adapter-slf4j` = project.in(file("logstage/logstage-adapter-s ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -4579,7 +4579,7 @@ lazy val `logstage-adapter-slf4j` = project.in(file("logstage/logstage-adapter-s "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -4590,7 +4590,7 @@ lazy val `logstage-adapter-slf4j` = project.in(file("logstage/logstage-adapter-s case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -4661,7 +4661,7 @@ lazy val `logstage-sink-slf4j` = project.in(file("logstage/logstage-sink-slf4j") ) .settings( crossScalaVersions := Seq( - "3.4.0", + "3.4.1", "2.13.13", "2.12.19" ), @@ -4771,7 +4771,7 @@ lazy val `logstage-sink-slf4j` = project.in(file("logstage/logstage-sink-slf4j") "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -4782,7 +4782,7 @@ lazy val `logstage-sink-slf4j` = project.in(file("logstage/logstage-sink-slf4j") case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -4990,7 +4990,7 @@ lazy val `microsite` = project.in(file("doc/microsite")) "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -5001,7 +5001,7 @@ lazy val `microsite` = project.in(file("doc/microsite")) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", @@ -5238,7 +5238,7 @@ lazy val `sbt-izumi-deps` = project.in(file("sbt-plugins/sbt-izumi-deps")) "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" ) - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Yretain-trees", "-language:3.4", "-release:8", @@ -5249,7 +5249,7 @@ lazy val `sbt-izumi-deps` = project.in(file("sbt-plugins/sbt-izumi-deps")) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.0") => Seq( + case (_, "3.4.1") => Seq( "-Wconf:any:verbose", "-Wconf:msg=.this. qualifier will be deprecated:silent", "-Wconf:msg=scala.compiletime.uninitialized:silent", diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala index fd130d5ad9..fec9973f30 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala @@ -1,20 +1,22 @@ package izumi.distage.reflection.macros.universe.impl -import izumi.fundamentals.platform.cache.{CachedHashcode, CachedRepr} import izumi.reflect.macrortti.{LightTypeTag, LightTypeTagImpl} private[distage] trait WithDISafeType { this: DIUniverseBase => - // TODO: hotspot, hashcode on keys is inefficient - class MacroSafeType private( + class MacroSafeType private ( private[reflection] val typeNative: TypeNative, private[MacroSafeType] val tag: LightTypeTag, - ) extends CachedHashcode - with CachedRepr { + ) { - override final protected def hash: Int = tag.hashCode() - override final protected def repr: String = tag.repr + // hashcode is already cached in the underlying code + @inline override def hashCode: Int = { + tag.hashCode() + } + @inline override def toString: String = { + tag.repr + } override final def equals(obj: Any): Boolean = { obj match { case that: MacroSafeType => diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/fundamentals/platform/functional/package.scala b/fundamentals/fundamentals-functional/src/main/scala/izumi/fundamentals/platform/functional/package.scala similarity index 100% rename from fundamentals/fundamentals-bio/src/main/scala/izumi/fundamentals/platform/functional/package.scala rename to fundamentals/fundamentals-functional/src/main/scala/izumi/fundamentals/platform/functional/package.scala diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SafeType.scala b/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/SafeType.scala similarity index 91% rename from distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SafeType.scala rename to fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/SafeType.scala index 8406cba89c..cfc4d6148a 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SafeType.scala +++ b/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/SafeType.scala @@ -20,6 +20,7 @@ final class SafeType(private[distage] val anyTag: AnyTag) { } } + // hashcode is already cached in the underlying code @inline override def hashCode: Int = { anyTag.hashCode() } @@ -34,10 +35,12 @@ final class SafeType(private[distage] val anyTag: AnyTag) { } } -object SafeType { +trait SafeTypeTools { def get[T: Tag]: SafeType = new SafeType(Tag[T]) def getK[K[_]: TagK]: SafeType = new SafeType(TagK[K]) def unsafeGetWeak[T](implicit weakTag: WeakTag[T]): SafeType = new SafeType(WeakTag[T]) +} +object SafeType extends SafeTypeTools { lazy val identityEffectType: SafeType = SafeType.getK[Identity] } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala b/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala similarity index 100% rename from distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala rename to fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala From 65f196ce7f6dfcddba7d8b4b885fc2d509a91b76 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 23 Apr 2024 17:51:59 +0100 Subject: [PATCH 07/59] wip --- .../scala/izumi/distage/AbstractLocator.scala | 8 ++++---- .../scala/izumi/distage/model/Locator.scala | 10 +++++----- .../distage/model/reflection/Provider.scala | 17 ++++++----------- .../distage/model/reflection/TypedRef.scala | 11 ++++++++++- .../distage/fixtures/Scala3TraitCases.scala | 1 - .../model/reflection/GenericTypedRef.scala | 7 +++++++ 6 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/AbstractLocator.scala b/distage/distage-core-api/src/main/scala/izumi/distage/AbstractLocator.scala index 6c4590ee9b..97529e54bb 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/AbstractLocator.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/AbstractLocator.scala @@ -9,7 +9,7 @@ import izumi.reflect.Tag trait AbstractLocator extends Locator { protected def lookupLocalUnsafe(key: DIKey): Option[Any] - private[distage] final def lookupLocal[T: Tag](key: DIKey): Option[TypedRef[T]] = { + private[distage] final def lookupLocal[T: Tag](key: DIKey): Option[GenericTypedRef[T]] = { lookupLocalUnsafe(key) .map { value => @@ -38,7 +38,7 @@ trait AbstractLocator extends Locator { lookupRef(key).map(_.value) } - override final def lookupRefOrThrow[T: Tag](key: DIKey): TypedRef[T] = { + override final def lookupRefOrThrow[T: Tag](key: DIKey): GenericTypedRef[T] = { lookupRef(key) match { case Some(value) => value @@ -47,11 +47,11 @@ trait AbstractLocator extends Locator { } } - override final def lookupRef[T: Tag](key: DIKey): Option[TypedRef[T]] = { + override final def lookupRef[T: Tag](key: DIKey): Option[GenericTypedRef[T]] = { recursiveLookup(key, this) } - private[this] final def recursiveLookup[T: Tag](key: DIKey, locator: Locator): Option[TypedRef[T]] = { + private[this] final def recursiveLookup[T: Tag](key: DIKey, locator: Locator): Option[GenericTypedRef[T]] = { locator .lookupLocal[T](key) .orElse(locator.parent.flatMap(p => recursiveLookup[T](key, p))) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/Locator.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/Locator.scala index d142e62096..87aacf434e 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/Locator.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/Locator.scala @@ -8,7 +8,7 @@ import izumi.distage.model.providers.Functoid import izumi.distage.model.provisioning.OpStatus import izumi.distage.model.provisioning.PlanInterpreter.Finalizer import izumi.distage.model.references.IdentifiedRef -import izumi.distage.model.reflection.{DIKey, TypedRef} +import izumi.distage.model.reflection.{DIKey, GenericTypedRef} import izumi.functional.lifecycle.Lifecycle import izumi.functional.quasi.QuasiPrimitives import izumi.reflect.{Tag, TagK} @@ -36,10 +36,10 @@ trait Locator { def lookupInstance[T: Tag](key: DIKey): Option[T] def finalizers[F[_]: TagK]: collection.Seq[Finalizer[F]] - private[distage] def lookupLocal[T: Tag](key: DIKey): Option[TypedRef[T]] + private[distage] def lookupLocal[T: Tag](key: DIKey): Option[GenericTypedRef[T]] - def lookupRefOrThrow[T: Tag](key: DIKey): TypedRef[T] - def lookupRef[T: Tag](key: DIKey): Option[TypedRef[T]] + def lookupRefOrThrow[T: Tag](key: DIKey): GenericTypedRef[T] + def lookupRef[T: Tag](key: DIKey): Option[GenericTypedRef[T]] /** The plan that produced this object graph */ def plan: Plan @@ -97,7 +97,7 @@ trait Locator { /** Same as [[run]] but returns `None` if any of the arguments could not be fulfilled */ final def runOption[T](function: Functoid[T]): Option[T] = { val fn = function.get - val args: Option[Queue[TypedRef[Any]]] = fn.diKeys.foldLeft(Option(Queue.empty[TypedRef[Any]])) { + val args: Option[Queue[GenericTypedRef[Any]]] = fn.diKeys.foldLeft(Option(Queue.empty[GenericTypedRef[Any]])) { (maybeQueue, key) => maybeQueue.flatMap { queue => diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala index 2e90c5510e..ca96c87e39 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala @@ -13,7 +13,7 @@ trait Provider { def fun: Seq[Any] => Any def providerType: ProviderType - def unsafeApply(refs: Seq[TypedRef[?]]): Any = { + def unsafeApply(refs: Seq[GenericTypedRef[?]]): Any = { val args = verifyArgs(refs) fun(args) } @@ -40,17 +40,12 @@ trait Provider { "π:" + providerType.toString } - protected[this] def verifyArgs(refs: Seq[TypedRef[?]]): Seq[Any] = { + protected[this] def verifyArgs(refs: Seq[GenericTypedRef[?]]): Seq[Any] = { val (newArgs, types, typesCmp) = parameters .zip(refs).map { - case (param, TypedRef(v, tpe, isByName)) => - val newArg = if (param.isByName && !isByName) { - () => v - } else if (isByName && !param.isByName) { - v.asInstanceOf[Function0[Any]].apply() - } else v - - (newArg, tpe, tpe <:< param.key.tpe) + case (param, ref) => + val newArg = ref.asArgument(param.isByName) + (newArg, ref.tpe, ref.tpe <:< param.key.tpe) }.unzip3 val countOk = refs.size == parameters.size @@ -95,7 +90,7 @@ object Provider { def this(parameters: Seq[LinkedParameter], ret: SafeType, fun: Seq[Any] => Any, providerType: ProviderType) = this(parameters, ret, fun, fun, providerType) - override def unsafeApply(refs: Seq[TypedRef[?]]): A = + override def unsafeApply(refs: Seq[GenericTypedRef[?]]): A = super.unsafeApply(refs).asInstanceOf[A] override def unsafeMap(newRet: SafeType, f: Any => ?): ProviderImpl[?] = diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/TypedRef.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/TypedRef.scala index 98d9e2460c..3b1997e19d 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/TypedRef.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/TypedRef.scala @@ -3,12 +3,21 @@ package izumi.distage.model.reflection import izumi.distage.model.provisioning.proxies.ProxyDispatcher.ByNameDispatcher import izumi.reflect.Tag -final case class TypedRef[+T](private val v: T, tpe: SafeType, isByName: Boolean) { +final case class TypedRef[+T](private val v: T, tpe: SafeType, isByName: Boolean) extends GenericTypedRef[T] { def value: T = v match { case d: ByNameDispatcher => d.apply().asInstanceOf[T] case o => o } + + def asArgument(byName: Boolean): Any = { + if (byName && !isByName) { + () => v + } else if (isByName && !byName) { + v.asInstanceOf[Function0[Any]].apply() + } else v + } } + object TypedRef { def apply[T: Tag](value: T): TypedRef[T] = TypedRef(value, SafeType.get[T], isByName = false) def byName[T: Tag](value: => T): TypedRef[T] = TypedRef((() => value).asInstanceOf[T], SafeType.get[T], isByName = true) diff --git a/distage/distage-core/src/test/scala-3/izumi/distage/fixtures/Scala3TraitCases.scala b/distage/distage-core/src/test/scala-3/izumi/distage/fixtures/Scala3TraitCases.scala index 1948296853..e8a467e08a 100644 --- a/distage/distage-core/src/test/scala-3/izumi/distage/fixtures/Scala3TraitCases.scala +++ b/distage/distage-core/src/test/scala-3/izumi/distage/fixtures/Scala3TraitCases.scala @@ -2,7 +2,6 @@ package izumi.distage.fixtures import izumi.distage.constructors.TraitConstructor import izumi.distage.model.definition.With -import izumi.distage.model.reflection.TypedRef object Scala3TraitCases { diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala b/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala new file mode 100644 index 0000000000..57354cc8be --- /dev/null +++ b/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala @@ -0,0 +1,7 @@ +package izumi.distage.model.reflection + +trait GenericTypedRef[+T] { + def value: T + def asArgument(byName: Boolean): Any + def tpe: SafeType +} From 2cd11e73035bc8571f9a18d4d28fb7b8f5080afb Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 23 Apr 2024 18:21:46 +0100 Subject: [PATCH 08/59] wip --- .../scala/izumi/distage/docker/bundled/PostgresDocker.scala | 2 +- .../scala/izumi/distage/docker/impl/ContainerResource.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/bundled/PostgresDocker.scala b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/bundled/PostgresDocker.scala index e5ca73bf76..90e6699262 100644 --- a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/bundled/PostgresDocker.scala +++ b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/bundled/PostgresDocker.scala @@ -16,7 +16,7 @@ object PostgresDocker extends ContainerDef { override def config: Config = { Config( registry = Some("public.ecr.aws"), - image = "docker/library/postgres:16-alpine", + image = "docker/library/postgres:16", ports = Seq(primaryPort), env = Map("POSTGRES_PASSWORD" -> "postgres"), healthCheck = ContainerHealthCheck.postgreSqlProtocolCheck(primaryPort, "postgres", "postgres"), diff --git a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/ContainerResource.scala b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/ContainerResource.scala index 4f6ae6788c..4e2763de30 100644 --- a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/ContainerResource.scala +++ b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/ContainerResource.scala @@ -357,7 +357,7 @@ open class ContainerResource[F[_], Tag]( .mut(config.platform)(_.withPlatform(_)) .mut(registryAuth)(_.withAuthConfig(_)) .mut(volumes.nonEmpty)(_.withVolumes(volumes.map(_.getVolume).asJava)) - .mut(volumes.nonEmpty)(_.withBinds(volumes.toList.asJava)) + .mut(volumes.nonEmpty)(c => c.withHostConfig(c.getHostConfig.withBinds(volumes.toList.asJava))) .map(c => c.withHostConfig(c.getHostConfig.withAutoRemove(config.autoRemove))) .get From 78acd7dd40a4f5c630eb4949d8ff0eb9a9f5e8fb Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 23 Apr 2024 19:07:36 +0100 Subject: [PATCH 09/59] proxy initialization improvements --- ...yStrategyDefaultImplPlatformSpecific.scala | 17 ++++++++--------- .../sequential/FwdrefLoopBreaker.scala | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/distage/distage-core/.jvm/src/main/scala/izumi/distage/provisioning/strategies/ProxyStrategyDefaultImplPlatformSpecific.scala b/distage/distage-core/.jvm/src/main/scala/izumi/distage/provisioning/strategies/ProxyStrategyDefaultImplPlatformSpecific.scala index 4bed5a47a0..b4389cfde0 100644 --- a/distage/distage-core/.jvm/src/main/scala/izumi/distage/provisioning/strategies/ProxyStrategyDefaultImplPlatformSpecific.scala +++ b/distage/distage-core/.jvm/src/main/scala/izumi/distage/provisioning/strategies/ProxyStrategyDefaultImplPlatformSpecific.scala @@ -2,11 +2,9 @@ package izumi.distage.provisioning.strategies import izumi.distage.model.definition.errors.ProvisionerIssue import izumi.distage.model.plan.ExecutableOp.{ProxyOp, WiringOp} -import izumi.distage.model.plan.Wiring import izumi.distage.model.provisioning.ProvisioningKeyProvider import izumi.distage.model.provisioning.proxies.ProxyProvider import izumi.distage.model.provisioning.proxies.ProxyProvider.{DeferredInit, ProxyContext, ProxyParams} -import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.model.reflection.{DIKey, LinkedParameter, MirrorProvider, SafeType} import izumi.fundamentals.reflection.TypeUtil @@ -29,10 +27,10 @@ abstract class ProxyStrategyDefaultImplPlatformSpecific( for { allArgsAsNull <- { op.op match { - case WiringOp.CallProvider(_, f: Wiring.SingletonWiring.Function, _) if f.provider.providerType eq ProviderType.Class => + case p: WiringOp.CallProvider => // for class constructors, try to fetch known dependencies from the object graph import izumi.functional.IzEither.* - f.associations + p.wiring.associations .map(a => fetchNonforwardRefParamWithClass(context, op.forwardRefs, a)) .biSequence .map(_.toArray: Array[(Class[?], Any)]) @@ -41,12 +39,13 @@ abstract class ProxyStrategyDefaultImplPlatformSpecific( missing => ProvisionerIssue.MissingRef(op.target, "Proxy precondition failed: non-forwarding key expected to be in context but wasn't", missing.toSet) ) - case _ => + case _ => // monadic op or createset // otherwise fill everything with nulls - Right( - runtimeClass.getConstructors.head.getParameterTypes - .map(clazz => clazz -> TypeUtil.defaultValue(clazz)): Array[(Class[?], Any)] - ) + runtimeClass.getConstructors.toList + .sortBy(_.getParameters.length) + .headOption + .map(_.getParameterTypes.map(clazz => clazz -> TypeUtil.defaultValue(clazz)): Array[(Class[?], Any)]) + .toRight(ProvisionerIssue.UnsupportedOp(tpe, op, "cannot find suitable constructor for proxy")) } } } yield { diff --git a/distage/distage-core/src/main/scala/izumi/distage/planning/sequential/FwdrefLoopBreaker.scala b/distage/distage-core/src/main/scala/izumi/distage/planning/sequential/FwdrefLoopBreaker.scala index d8a30ddc10..702197320c 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/planning/sequential/FwdrefLoopBreaker.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/planning/sequential/FwdrefLoopBreaker.scala @@ -4,7 +4,7 @@ import izumi.distage.model.definition.errors.DIError.LoopResolutionError import izumi.distage.model.definition.errors.DIError.LoopResolutionError.NoAppropriateResolutionFound import izumi.distage.model.plan.ExecutableOp import izumi.distage.model.plan.ExecutableOp.WiringOp.ReferenceKey -import izumi.distage.model.plan.ExecutableOp.{ImportOp, InstantiationOp, SemiplanOp} +import izumi.distage.model.plan.ExecutableOp.{ImportOp, InstantiationOp, SemiplanOp, WiringOp} import izumi.distage.model.reflection.{DIKey, MirrorProvider} import izumi.distage.planning.sequential.FwdrefLoopBreaker.BreakAt import izumi.fundamentals.collections.nonempty.NEList @@ -33,11 +33,22 @@ object FwdrefLoopBreaker { false case _: ImportOp => false - case _: InstantiationOp => - provider.canBeProxied(key.tpe) + case i: InstantiationOp => + i match { + case _: ExecutableOp.CreateSet => + true + case _: ExecutableOp.MonadicOp => + provider.canBeProxied(key.tpe) + case op: ExecutableOp.WiringOp => + op match { + case _: WiringOp.CallProvider => + provider.canBeProxied(key.tpe) + case _ => + false + } + } } } - } } From 66651dfb85d6f83a8386240b5b6346a291dafa14 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 23 Apr 2024 20:31:41 +0100 Subject: [PATCH 10/59] wip --- .../constructors/ConstructorMacros.scala | 4 +- .../FactoryConstructorMacro.scala | 2 +- .../constructors/HasConstructorMacro.scala | 2 +- .../constructors/ClassConstructorMacro.scala | 2 +- .../FactoryConstructorMacro.scala | 2 +- .../constructors/HasConstructorMacro.scala | 2 +- .../constructors/TraitConstructorMacro.scala | 2 +- .../distage/model/providers/Functoid.scala | 7 +-- .../distage/model/reflection/Provider.scala | 51 +++++++++++-------- 9 files changed, 42 insertions(+), 32 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala index ff17ef566f..437812399b 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala @@ -14,7 +14,7 @@ abstract class ClassConstructorMacros extends ConstructorMacrosBase { def mkClassConstructorProvider[T: c.WeakTypeTag](reflectionProvider: ReflectionProvider.Aux[u.type])(targetType: Type): c.Expr[Functoid[T]] = { val associations = reflectionProvider.constructorParameterLists(targetType) - generateProvider[T, ProviderType.Class.type](associations)(args => q"new $targetType(...$args)") + generateProvider[T, ProviderType.Constructor.type](associations)(args => q"new $targetType(...$args)") } } object ClassConstructorMacros { @@ -45,7 +45,7 @@ abstract class TraitConstructorMacros extends ConstructorMacrosBase { val u.MacroWiring.MacroSingletonWiring.Trait(targetType, classParameters, methods, _) = wiring val traitParameters = methods.map(_.asParameter) - generateProvider[T, ProviderType.Trait.type](classParameters :+ traitParameters) { + generateProvider[T, ProviderType.Constructor.type](classParameters :+ traitParameters) { argss => q"_root_.izumi.distage.constructors.TraitConstructor.wrapInitialization[$targetType](${val methodDefs = methods.zip(argss.last).map { case (method, paramSeqIndexTree) => method.traitMethodExpr(paramSeqIndexTree) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala index ec8c9116be..6d1e8298d1 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala @@ -30,7 +30,7 @@ object FactoryConstructorMacro { c.abort(c.enclosingPosition, s"No factory methods found in $targetType") } - val provider: c.Expr[Functoid[T]] = generateProvider[T, ProviderType.Factory.type](allParameters) { + val provider: c.Expr[Functoid[T]] = generateProvider[T, ProviderType.Constructor.type](allParameters) { argss => val dependencyArgMap = allParameters.iterator.flatten.map(_.key).zip(argss.iterator.flatten).toMap logger.log(s"""Got associations: $allParameters diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala index 9bee90599d..f741f232fc 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala @@ -34,7 +34,7 @@ object ZEnvConstructorMacro { val params = reflectionProvider.zioHasParameters(c.freshName)(deepIntersection) val provider: c.Expr[Functoid[ZEnvironment[T]]] = { - generateProvider[ZEnvironment[T], ProviderType.ZIOEnvironment.type](params :: Nil) { + generateProvider[ZEnvironment[T], ProviderType.Constructor.type](params :: Nil) { case (headParam :: params) :: Nil => params.foldLeft(q"_root_.zio.ZEnvironment.apply($headParam)") { (expr, arg) => q"$expr.add($arg)" diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ClassConstructorMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ClassConstructorMacro.scala index c80f37ebb4..e585af59f8 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ClassConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ClassConstructorMacro.scala @@ -70,7 +70,7 @@ object ClassConstructorMacro { val paramss = util.extractConstructorParamLists(typeRepr) val lamExpr = util.wrapCtorApplicationIntoFunctoidRawLambda[R](paramss, ctorTreeParameterized) - val f = util.makeFunctoid[R](paramss.flatten, lamExpr, '{ ProviderType.Class }) + val f = util.makeFunctoid[R](paramss.flatten, lamExpr, '{ ProviderType.Constructor }) '{ new ClassConstructor[R](${ f }) } case None => diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/FactoryConstructorMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/FactoryConstructorMacro.scala index 82c6590d5b..d792e88274 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/FactoryConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/FactoryConstructorMacro.scala @@ -111,7 +111,7 @@ object FactoryConstructorMacro { // ) // } - val f = util.makeFunctoid[R](lamParams, lamExpr, '{ ProviderType.Factory }) + val f = util.makeFunctoid[R](lamParams, lamExpr, '{ ProviderType.Constructor }) '{ new FactoryConstructor[R](${ f }) } } catch { case t: scala.quoted.runtime.StopMacroExpansion => throw t; case NonFatal(t) => qctx.reflect.report.errorAndAbort(t.stacktraceString) } diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/HasConstructorMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/HasConstructorMacro.scala index 5fb8c85c3b..49b3e74e75 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/HasConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/HasConstructorMacro.scala @@ -64,7 +64,7 @@ object ZEnvConstructorMacro { }).changeOwner(lambdaSym) } - val f = util.makeFunctoid[ZEnvironment[R]](lamParams, lamExpr, '{ ProviderType.ZIOEnvironment }) + val f = util.makeFunctoid[ZEnvironment[R]](lamParams, lamExpr, '{ ProviderType.Constructor }) '{ new ZEnvConstructor[R](${ f }) } } } catch { case t: scala.quoted.runtime.StopMacroExpansion => throw t; case t: Throwable => qctx.reflect.report.errorAndAbort(t.stacktraceString) } diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/TraitConstructorMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/TraitConstructorMacro.scala index 06926b5938..5300b29767 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/TraitConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/TraitConstructorMacro.scala @@ -73,7 +73,7 @@ object TraitConstructorMacro { // ) // } - val f = util.makeFunctoid[R](lamParams, lamExpr, '{ ProviderType.Trait }) + val f = util.makeFunctoid[R](lamParams, lamExpr, '{ ProviderType.Constructor }) '{ new TraitConstructor[R](${ f }) } } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index e2bd790c19..4276bbda9e 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -174,7 +174,7 @@ object Functoid extends FunctoidMacroMethods with FunctoidLifecycleAdapters { Provider.ProviderImpl[A]( parameters = Seq.empty, ret = SafeType.get[A], - originalFun = () => a, + underlying = () => a, fun = (_: Seq[Any]) => a, providerType = ProviderType.Function, ) @@ -186,8 +186,9 @@ object Functoid extends FunctoidMacroMethods with FunctoidLifecycleAdapters { Provider.ProviderImpl[A]( parameters = Seq.empty, ret = SafeType.get[A], + underlying = a.asInstanceOf[AnyRef], fun = (_: Seq[Any]) => a, - providerType = ProviderType.Singleton, + providerType = ProviderType.Constructor, ) ) } @@ -202,7 +203,7 @@ object Functoid extends FunctoidMacroMethods with FunctoidLifecycleAdapters { Provider.ProviderImpl( parameters = Seq(LinkedParameter(symbolInfo, key)), ret = retTpe, - originalFun = f, + underlying = f, fun = (s: Seq[Any]) => f(s.head.asInstanceOf[A]), providerType = ProviderType.Function, ) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala index ca96c87e39..eb9ecdba73 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala @@ -8,8 +8,10 @@ trait Provider { final def diKeys: Seq[DIKey] = parameters.map(_.key) final def argTypes: Seq[SafeType] = parameters.map(_.key.tpe) final def arity: Int = parameters.size + def ret: SafeType - def originalFun: AnyRef + // either a function or a constant value + def underlying: AnyRef def fun: Seq[Any] => Any def providerType: ProviderType @@ -23,23 +25,29 @@ trait Provider { def addUnused(keys: Iterable[DIKey]): Provider def replaceKeys(f: DIKey => DIKey): Provider - private val eqField: AnyRef = { - if (providerType eq ProviderType.Function) originalFun - else if (providerType eq ProviderType.FunctionWithUnusedKeys) (originalFun, diKeys) - else ret + private val comparable: AnyRef = { + providerType match { + case ProviderType.Constructor => (ret, diKeys) + case ProviderType.Function => (underlying, diKeys) + case ProviderType.Constant => (underlying, diKeys) + } } + override final def equals(obj: Any): Boolean = obj match { - case that: Provider => eqField == that.eqField + case that: Provider => comparable == that.comparable case _ => false } - override final def hashCode(): Int = eqField.hashCode() + override final def hashCode(): Int = comparable.hashCode() + override final def toString: String = s"$funString(${argTypes.mkString(", ")}): $ret" - final def funString: String = if (providerType eq ProviderType.Function) { - "ƒ:" + originalFun.toString - } else { - "π:" + providerType.toString + final def funString: String = providerType match { + case ProviderType.Constant => s"κ:$underlying" + case ProviderType.Constructor => s"π:$providerType" + case ProviderType.Function => s"ƒ:$underlying" } + if (providerType eq ProviderType.Function) {} else {} + protected[this] def verifyArgs(refs: Seq[GenericTypedRef[?]]): Seq[Any] = { val (newArgs, types, typesCmp) = parameters .zip(refs).map { @@ -71,19 +79,21 @@ object Provider { sealed trait ProviderType object ProviderType { - case object Class extends ProviderType - case object Trait extends ProviderType - case object ZIOEnvironment extends ProviderType - case object Factory extends ProviderType - case object Singleton extends ProviderType + case object Constant extends ProviderType + + /** Function generated by any of the "constructor" macros + */ + case object Constructor extends ProviderType + + /** Function captured by the Functoid macro any provider transformed by the unsafeMap helper method + */ case object Function extends ProviderType - case object FunctionWithUnusedKeys extends ProviderType } final case class ProviderImpl[+A]( parameters: Seq[LinkedParameter], ret: SafeType, - originalFun: AnyRef, + underlying: AnyRef, fun: Seq[Any] => Any, providerType: ProviderType, ) extends Provider { @@ -96,15 +106,14 @@ object Provider { override def unsafeMap(newRet: SafeType, f: Any => ?): ProviderImpl[?] = copy( ret = newRet, - originalFun = f, + underlying = f, fun = xs => f.apply(fun(xs)), providerType = ProviderType.Function, ) override def addUnused(keys: Iterable[DIKey]): Provider = copy( - parameters = parameters ++ keys.map(key => LinkedParameter(SymbolInfo("", key.tpe, isByName = false, wasGeneric = false), key)), - providerType = ProviderType.FunctionWithUnusedKeys, + parameters = parameters ++ keys.map(key => LinkedParameter(SymbolInfo("", key.tpe, isByName = false, wasGeneric = false), key)) ) override def replaceKeys(f: DIKey => DIKey): Provider = copy(parameters.map(_.replaceKey(f))) From efc87b334496bd58b3bcb8cac7e583e259931f0d Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 24 Apr 2024 15:09:36 +0100 Subject: [PATCH 11/59] wip --- .../distage/model/definition/Bindings.scala | 2 +- .../dsl/AbstractBindingDefDSL.scala | 8 ++--- .../model/plan/repr/KeyMinimizer.scala | 12 +------- .../distage/model/reflection/DIKey.scala | 25 ++-------------- .../model/reflection/MultiSetImplId.scala | 11 +++++++ .../distage/model/reflection/SetKeyMeta.scala | 29 +++++++++++++++++++ .../izumi/distage/planning/AutoSetHook.scala | 2 +- .../distage/model/definition/Identifier.scala | 1 + .../distage/model/reflection/IdContract.scala | 0 9 files changed, 50 insertions(+), 40 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/MultiSetImplId.scala create mode 100644 distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala rename {distage/distage-core-api => fundamentals/fundamentals-reflection}/src/main/scala/izumi/distage/model/definition/Identifier.scala (99%) rename {distage/distage-core-api => fundamentals/fundamentals-reflection}/src/main/scala/izumi/distage/model/reflection/IdContract.scala (100%) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/Bindings.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/Bindings.scala index 04fb3c1faf..9db1f2330b 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/Bindings.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/Bindings.scala @@ -4,7 +4,7 @@ import izumi.distage.Subcontext import izumi.distage.constructors.{ClassConstructor, FactoryConstructor, TraitConstructor} import izumi.distage.model.definition.Binding.{EmptySetBinding, SetElementBinding, SingletonBinding} import izumi.distage.model.providers.Functoid -import izumi.distage.model.reflection.DIKey.SetKeyMeta +import izumi.distage.model.reflection.SetKeyMeta import izumi.distage.model.reflection.{DIKey, SafeType} import izumi.fundamentals.platform.language.CodePositionMaterializer import izumi.reflect.Tag diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala index 8ee35e17c0..1fa52b0391 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala @@ -3,14 +3,14 @@ package izumi.distage.model.definition.dsl import izumi.distage.constructors.{FactoryConstructor, TraitConstructor} import izumi.distage.model.definition.* import izumi.distage.model.definition.Binding.{EmptySetBinding, ImplBinding, SetElementBinding, SingletonBinding} +import izumi.distage.model.definition.dsl.AbstractBindingDefDSL.* import izumi.distage.model.definition.dsl.AbstractBindingDefDSL.SetElementInstruction.ElementAddTags import izumi.distage.model.definition.dsl.AbstractBindingDefDSL.SetInstruction.{AddTagsAll, SetIdAll} import izumi.distage.model.definition.dsl.AbstractBindingDefDSL.SingletonInstruction.* -import izumi.distage.model.definition.dsl.AbstractBindingDefDSL.* import izumi.distage.model.exceptions.dsl.InvalidFunctoidModifier import izumi.distage.model.providers.Functoid -import izumi.distage.model.reflection.DIKey -import izumi.distage.model.reflection.DIKey.SetKeyMeta +import izumi.distage.model.reflection.{DIKey, MultiSetImplId} +import izumi.distage.model.reflection.SetKeyMeta import izumi.fundamentals.platform.language.{CodePositionMaterializer, SourceFilePosition} import izumi.reflect.Tag @@ -499,7 +499,7 @@ object AbstractBindingDefDSL { private[this] val ops: mutable.Queue[MultiSetElementInstruction] = mutable.Queue.empty def interpret(setKey: DIKey.BasicKey): Seq[Binding] = { - val valueProxyKey = DIKey.IdKey(implDef.implType, DIKey.MultiSetImplId(setKey, implDef)) + val valueProxyKey = DIKey.IdKey(implDef.implType, MultiSetImplId(setKey, implDef)) val valueProxyBinding = SingletonBinding(valueProxyKey, implDef, Set.empty, pos) val elementKey = DIKey.SetElementKey(setKey, valueProxyKey, SetKeyMeta.WithImpl(implDef)) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/KeyMinimizer.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/KeyMinimizer.scala index cedd1caff9..f5d56ce6dc 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/KeyMinimizer.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/KeyMinimizer.scala @@ -1,7 +1,5 @@ package izumi.distage.model.plan.repr -import izumi.distage.model.reflection.DIKey.SetKeyMeta - import scala.annotation.nowarn import izumi.distage.model.reflection.* import izumi.fundamentals.collections.IzCollections.* @@ -95,15 +93,7 @@ class KeyMinimizer( case DIKey.SetElementKey(set, reference, disambiguator) => val base = s"${renderKey(set)}/${renderKey(reference)}" - val drepr = (disambiguator match { - case SetKeyMeta.NoMeta => - None - case SetKeyMeta.WithImpl(disambiguator) => - Some(s"impl:${disambiguator.hashCode}") - case SetKeyMeta.WithAutoset(base) => - Some(s"autoset:${renderKey(base)}") - }).map(v => "#" + v).getOrElse("") - + val drepr = disambiguator.repr(renderKey) val fullDis = styled(drepr, c.BLUE) showKeyData("set", s"$base$fullDis") } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/DIKey.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/DIKey.scala index a6aeb724af..6d89dfd859 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/DIKey.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/DIKey.scala @@ -1,6 +1,6 @@ package izumi.distage.model.reflection -import izumi.distage.model.definition.{Identifier, ImplDef} +import izumi.distage.model.definition.Identifier import izumi.fundamentals.platform.cache.CachedProductHashcode import izumi.reflect.Tag @@ -50,23 +50,9 @@ object DIKey { override def tpe: SafeType = reference.tpe override def toString: String = { - val drepr = (disambiguator match { - case SetKeyMeta.NoMeta => - None - case SetKeyMeta.WithImpl(disambiguator) => - Some(s"impl:${disambiguator.hashCode}") - case SetKeyMeta.WithAutoset(base) => - Some(s"autoset:${base.toString}") - }).map(v => "#" + v).getOrElse("") - s"{set.$set/${reference.toString}$drepr" + s"{set.$set/${reference.toString}${disambiguator.repr(_.toString)}" } } - sealed trait SetKeyMeta - object SetKeyMeta { - case object NoMeta extends SetKeyMeta - final case class WithImpl(disambiguator: ImplDef) extends SetKeyMeta - final case class WithAutoset(base: DIKey) extends SetKeyMeta - } final case class ProxyInitKey(proxied: DIKey) extends DIKey { override def tpe: SafeType = proxied.tpe @@ -85,11 +71,4 @@ object DIKey { final case class EffectKey(key: DIKey, tpe: SafeType) extends DIKey { override def toString: String = s"{effect.${key.toString}/$tpe}" } - - final case class MultiSetImplId(set: DIKey, impl: ImplDef) - object MultiSetImplId { - implicit object SetImplIdContract extends IdContract[MultiSetImplId] { - override def repr(v: MultiSetImplId): String = s"set/${v.set}#${v.impl.hashCode}" - } - } } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/MultiSetImplId.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/MultiSetImplId.scala new file mode 100644 index 0000000000..4aeedb683a --- /dev/null +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/MultiSetImplId.scala @@ -0,0 +1,11 @@ +package izumi.distage.model.reflection + +import izumi.distage.model.definition.ImplDef + +final case class MultiSetImplId(set: DIKey, impl: ImplDef) + +object MultiSetImplId { + implicit object SetImplIdContract extends IdContract[MultiSetImplId] { + override def repr(v: MultiSetImplId): String = s"set/${v.set}#${v.impl.hashCode}" + } +} diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala new file mode 100644 index 0000000000..1b2ab1ca97 --- /dev/null +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala @@ -0,0 +1,29 @@ +package izumi.distage.model.reflection + +import izumi.fundamentals.platform.language.Quirks.Discarder + +sealed trait SetKeyMeta { + def repr(render: DIKey => String): String +} + +object SetKeyMeta { + case object NoMeta extends SetKeyMeta { + override def repr(render: DIKey => String): String = { + render.discard() + "" + } + } + + // disambiguator is only used in comparisons + final case class WithImpl(disambiguator: AnyRef) extends SetKeyMeta { + override def repr(render: DIKey => String): String = { + render.discard() + s"#impl:${disambiguator.hashCode}" + } + } + final case class WithAutoset(base: DIKey) extends SetKeyMeta { + override def repr(render: DIKey => String): String = { + s"#autoset:${render(base)}" + } + } +} diff --git a/distage/distage-core/src/main/scala/izumi/distage/planning/AutoSetHook.scala b/distage/distage-core/src/main/scala/izumi/distage/planning/AutoSetHook.scala index 13867dd77a..a4eacf8581 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/planning/AutoSetHook.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/planning/AutoSetHook.scala @@ -4,7 +4,7 @@ import izumi.distage.model.definition.Binding.{EmptySetBinding, ImplBinding, Set import izumi.distage.model.definition.{Binding, Identifier, ImplDef, ModuleBase} import izumi.distage.model.planning.PlanningHook import izumi.distage.model.reflection.* -import izumi.distage.model.reflection.DIKey.{SetElementKey, SetKeyMeta} +import izumi.distage.model.reflection.DIKey.{SetElementKey} import izumi.distage.planning.AutoSetHook.InclusionPredicate import izumi.fundamentals.platform.language.{CodePosition, CodePositionMaterializer} import izumi.reflect.Tag diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/Identifier.scala b/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/definition/Identifier.scala similarity index 99% rename from distage/distage-core-api/src/main/scala/izumi/distage/model/definition/Identifier.scala rename to fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/definition/Identifier.scala index 0a006c233d..fa6d4376e5 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/Identifier.scala +++ b/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/definition/Identifier.scala @@ -1,6 +1,7 @@ package izumi.distage.model.definition import izumi.distage.model.reflection.IdContract + import scala.language.implicitConversions /** diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/IdContract.scala b/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/IdContract.scala similarity index 100% rename from distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/IdContract.scala rename to fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/IdContract.scala From a6e322d32ee09afc415d6ebcd5c80d6b69fb9477 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 24 Apr 2024 15:49:05 +0100 Subject: [PATCH 12/59] wip --- build.sbt | 200 +--------------- .../UnsafeProviderCallArgsMismatched.scala | 6 - .../distage/model/providers/Functoid.scala | 217 +----------------- .../providers/FunctoidConstructors.scala | 35 +++ .../providers/FunctoidLifecycleAdapters.scala | 108 +++++++++ .../model/providers/SimpleFunctoids.scala | 86 +++++++ .../model/provisioning/PlanInterpreter.scala | 2 + .../build/test/BuildAttributesMacroTest.scala | 0 .../reflection/JSRAnnotationTools.scala | 0 .../reflection/JSRAnnotationTools.scala | 0 .../build/BuildAttributeMacroImpl.scala | 0 .../platform/build/BuildAttributes.scala | 0 .../platform/build/MacroParameters.scala | 0 .../platform/build/MacroParametersImpl.scala | 0 .../reflection/AnnotationTools.scala | 0 .../reflection/ReflectionUtil.scala | 0 .../fundamentals/reflection/package.scala | 0 .../platform/build/BuildAttributes.scala | 0 .../platform/build/BuildAttributesImpl.scala | 0 .../platform/build/MacroParameters.scala | 0 .../platform/build/MacroParametersImpl.scala | 0 .../platform/reflection/ReflectionUtil.scala | 0 .../distage/model/definition/Identifier.scala | 0 .../distage/model/reflection/DIKey.scala | 0 .../model/reflection/GenericTypedRef.scala | 0 .../distage/model/reflection/IdContract.scala | 0 .../model/reflection/LinkedParameter.scala | 0 .../distage/model/reflection/Provider.scala | 5 +- .../distage/model/reflection/SafeType.scala | 0 .../distage/model/reflection/SetKeyMeta.scala | 0 .../distage/model/reflection/SymbolInfo.scala | 0 .../fundamentals/platform/build/package.scala | 0 .../platform/cache/CachedHashcode.scala | 6 + .../cache/CachedProductHashcode.scala | 5 - .../reflection/ReflectiveCall.scala | 0 .../fundamentals/reflection/TypeUtil.scala | 0 project/Deps.sc | 27 ++- 37 files changed, 260 insertions(+), 437 deletions(-) delete mode 100644 distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/runtime/UnsafeProviderCallArgsMismatched.scala create mode 100644 distage/distage-core-api/src/main/scala/izumi/distage/model/providers/FunctoidConstructors.scala create mode 100644 distage/distage-core-api/src/main/scala/izumi/distage/model/providers/FunctoidLifecycleAdapters.scala create mode 100644 distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala rename fundamentals/{fundamentals-reflection => fundamentals-platform}/.jvm/test/scala/izumi/fundamentals/platform/build/test/BuildAttributesMacroTest.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-2.12/izumi/fundamentals/reflection/JSRAnnotationTools.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-2.13/izumi/fundamentals/reflection/JSRAnnotationTools.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-2/izumi/fundamentals/platform/build/BuildAttributeMacroImpl.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-2/izumi/fundamentals/platform/build/BuildAttributes.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-2/izumi/fundamentals/platform/build/MacroParameters.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-2/izumi/fundamentals/platform/build/MacroParametersImpl.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-2/izumi/fundamentals/reflection/AnnotationTools.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-2/izumi/fundamentals/reflection/ReflectionUtil.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-2/izumi/fundamentals/reflection/package.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-3/izumi/fundamentals/platform/build/BuildAttributes.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-3/izumi/fundamentals/platform/build/BuildAttributesImpl.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-3/izumi/fundamentals/platform/build/MacroParameters.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-3/izumi/fundamentals/platform/build/MacroParametersImpl.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala-3/izumi/fundamentals/platform/reflection/ReflectionUtil.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala/izumi/distage/model/definition/Identifier.scala (100%) rename {distage/distage-core-api => fundamentals/fundamentals-platform}/src/main/scala/izumi/distage/model/reflection/DIKey.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala/izumi/distage/model/reflection/IdContract.scala (100%) rename {distage/distage-core-api => fundamentals/fundamentals-platform}/src/main/scala/izumi/distage/model/reflection/LinkedParameter.scala (100%) rename {distage/distage-core-api => fundamentals/fundamentals-platform}/src/main/scala/izumi/distage/model/reflection/Provider.scala (94%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala/izumi/distage/model/reflection/SafeType.scala (100%) rename {distage/distage-core-api => fundamentals/fundamentals-platform}/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala/izumi/fundamentals/platform/build/package.scala (100%) create mode 100644 fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/CachedHashcode.scala rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala/izumi/fundamentals/reflection/ReflectiveCall.scala (100%) rename fundamentals/{fundamentals-reflection => fundamentals-platform}/src/main/scala/izumi/fundamentals/reflection/TypeUtil.scala (100%) diff --git a/build.sbt b/build.sbt index 95ea589eb4..6f6ffc95d0 100644 --- a/build.sbt +++ b/build.sbt @@ -956,14 +956,15 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-platform")) .dependsOn( + `fundamentals-functional` % "test->compile;compile->compile", `fundamentals-language` % "test->compile;compile->compile", - `fundamentals-collections` % "test->compile;compile->compile", - `fundamentals-reflection` % "test->compile;compile->compile" + `fundamentals-collections` % "test->compile;compile->compile" ) .settings( libraryDependencies ++= Seq( "org.scala-lang.modules" %% "scala-collection-compat" % V.collection_compat, - "org.scalatest" %% "scalatest" % V.scalatest % Test + "org.scalatest" %% "scalatest" % V.scalatest % Test, + "dev.zio" %% "izumi-reflect" % V.izumi_reflect ), libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq( compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full), @@ -1347,195 +1348,6 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- .enablePlugins(SitePreviewPlugin) .disablePlugins(AssemblyPlugin) -lazy val `fundamentals-reflection` = project.in(file("fundamentals/fundamentals-reflection")) - .dependsOn( - `fundamentals-functional` % "test->compile;compile->compile" - ) - .settings( - libraryDependencies ++= Seq( - "org.scala-lang.modules" %% "scala-collection-compat" % V.collection_compat, - "org.scalatest" %% "scalatest" % V.scalatest % Test, - "dev.zio" %% "izumi-reflect" % V.izumi_reflect - ), - libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq( - compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full), - "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided - ) else Seq.empty } - ) - .settings( - crossScalaVersions := Seq( - "3.4.1", - "2.13.13", - "2.12.19" - ), - scalaVersion := crossScalaVersions.value.head, - organization := "io.7mind.izumi", - Compile / unmanagedSourceDirectories += baseDirectory.value / ".jvm/src/main/scala" , - Compile / unmanagedSourceDirectories ++= (scalaBinaryVersion.value :: CrossVersion.partialVersion(scalaVersion.value).toList.map(_._1)) - .map(v => baseDirectory.value / s".jvm/src/main/scala-$v").distinct, - Compile / unmanagedResourceDirectories += baseDirectory.value / ".jvm/src/main/resources" , - Test / unmanagedSourceDirectories += baseDirectory.value / ".jvm/src/test/scala" , - Test / unmanagedSourceDirectories ++= (scalaBinaryVersion.value :: CrossVersion.partialVersion(scalaVersion.value).toList.map(_._1)) - .map(v => baseDirectory.value / s".jvm/src/test/scala-$v").distinct, - Test / unmanagedResourceDirectories += baseDirectory.value / ".jvm/src/test/resources" , - scalacOptions ++= Seq( - s"-Xmacro-settings:product-name=${name.value}", - s"-Xmacro-settings:product-version=${version.value}", - s"-Xmacro-settings:product-group=${organization.value}", - s"-Xmacro-settings:scala-version=${scalaVersion.value}", - s"-Xmacro-settings:scala-versions=${crossScalaVersions.value.mkString(":")}" - ), - Compile / unmanagedSourceDirectories ++= { - val version = scalaVersion.value - val crossVersions = crossScalaVersions.value - import Ordering.Implicits._ - val ltEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ <= CrossVersion.partialVersion(version)).flatten - (Compile / unmanagedSourceDirectories).value.flatMap { - case dir if dir.getPath.endsWith("scala") => ltEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n+") } - case _ => Seq.empty - } - }, - Test / unmanagedSourceDirectories ++= { - val version = scalaVersion.value - val crossVersions = crossScalaVersions.value - import Ordering.Implicits._ - val ltEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ <= CrossVersion.partialVersion(version)).flatten - (Test / unmanagedSourceDirectories).value.flatMap { - case dir if dir.getPath.endsWith("scala") => ltEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n+") } - case _ => Seq.empty - } - }, - Test / testOptions += Tests.Argument("-oDF"), - scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.12.19") => Seq( - "-Wconf:any:error", - "-release:8", - "-explaintypes", - "-Xsource:3", - "-P:kind-projector:underscore-placeholders", - "-Ypartial-unification", - if (insideCI.value) "-Wconf:any:error" else "-Wconf:any:warning", - "-Wconf:cat=optimizer:warning", - "-Wconf:cat=other-match-analysis:error", - "-Ybackend-parallelism", - math.min(16, math.max(1, sys.runtime.availableProcessors() - 1)).toString, - "-Xlint:adapted-args", - "-Xlint:by-name-right-associative", - "-Xlint:constant", - "-Xlint:delayedinit-select", - "-Xlint:doc-detached", - "-Xlint:inaccessible", - "-Xlint:infer-any", - "-Xlint:missing-interpolator", - "-Xlint:nullary-override", - "-Xlint:nullary-unit", - "-Xlint:option-implicit", - "-Xlint:package-object-classes", - "-Xlint:poly-implicit-overload", - "-Xlint:private-shadow", - "-Xlint:stars-align", - "-Xlint:type-parameter-shadow", - "-Xlint:unsound-match", - "-opt-warnings:_", - "-Ywarn-extra-implicit", - "-Ywarn-unused:_", - "-Ywarn-adapted-args", - "-Ywarn-dead-code", - "-Ywarn-inaccessible", - "-Ywarn-infer-any", - "-Ywarn-nullary-override", - "-Ywarn-nullary-unit", - "-Ywarn-numeric-widen", - "-Ywarn-unused-import", - "-Ywarn-value-discard", - "-Ycache-plugin-class-loader:always", - "-Ycache-macro-class-loader:last-modified" - ) - case (_, "2.13.13") => Seq( - "-Wconf:any:error", - "-release:8", - "-explaintypes", - "-P:kind-projector:underscore-placeholders", - if (insideCI.value) "-Wconf:any:error" else "-Wconf:any:warning", - "-Wconf:cat=optimizer:warning", - "-Wconf:cat=other-match-analysis:error", - "-Vimplicits", - "-Vtype-diffs", - "-Ybackend-parallelism", - math.min(16, math.max(1, sys.runtime.availableProcessors() - 1)).toString, - "-Wdead-code", - "-Wextra-implicit", - "-Wnumeric-widen", - "-Woctal-literal", - "-Wvalue-discard", - "-Wunused:_", - "-Wmacros:after", - "-Ycache-plugin-class-loader:always", - "-Ycache-macro-class-loader:last-modified", - "-Wunused:-synthetics" - ) - case (_, "3.4.1") => Seq( - "-Yretain-trees", - "-language:3.4", - "-release:8", - "-Ykind-projector:underscores", - "-no-indent", - "-explain" - ) - case (_, _) => Seq.empty - } }, - scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "3.4.1") => Seq( - "-Wconf:any:verbose", - "-Wconf:msg=.this. qualifier will be deprecated:silent", - "-Wconf:msg=scala.compiletime.uninitialized:silent", - "-Wconf:msg=`using` clause:silent", - "-Wconf:msg=eta-expanded even though:silent", - "-Wconf:msg=The syntax ..function:silent", - "-Wconf:msg=method contains is not declared infix:silent", - "-Wconf:msg=method in is not declared infix:silent" - ) - case (_, _) => Seq( - "-Wconf:msg=parameter.*x\\$4.in.anonymous.function.is.never.used:silent", - "-Wconf:msg=constructor.modifiers.are.assumed.by.synthetic.*method:silent", - "-Wconf:msg=package.object.inheritance:silent", - "-Wconf:cat=lint-eta-sam:silent" - ) - } }, - scalacOptions -= "-Wconf:any:warning", - scalacOptions += "-Wconf:cat=deprecation:warning", - scalacOptions += "-Wconf:msg=legacy-binding:silent", - scalacOptions += "-Wconf:msg=nowarn:silent", - Compile / sbt.Keys.doc / scalacOptions -= "-Wconf:any:error", - scalacOptions ++= Seq( - s"-Xmacro-settings:scalatest-version=${V.scalatest}", - s"-Xmacro-settings:is-ci=${insideCI.value}" - ), - scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (false, "2.12.19") => Seq( - "-opt:l:inline", - "-opt-inline-from:izumi.**" - ) - case (false, "2.13.13") => Seq( - "-opt:l:inline", - "-opt-inline-from:izumi.**" - ) - case (_, _) => Seq.empty - } }, - scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( - "-Xsource:3", - "-Xmigration", - "-Wconf:cat=scala3-migration:silent", - "-Wconf:cat=other-migration:silent" - ) - case (_, _) => Seq.empty - } }, - Test / packageDoc / publishArtifact := false - ) - .enablePlugins(SitePreviewPlugin) - .disablePlugins(AssemblyPlugin) - lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) .dependsOn( `fundamentals-language` % "test->compile;compile->compile", @@ -1743,7 +1555,6 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) .dependsOn( - `fundamentals-reflection` % "test->compile;compile->compile", `fundamentals-platform` % "test->compile;compile->compile", `fundamentals-bio` % "test->compile;compile->compile" ) @@ -4842,7 +4653,6 @@ lazy val `microsite` = project.in(file("doc/microsite")) `fundamentals-language` % "test->compile;compile->compile", `fundamentals-platform` % "test->compile;compile->compile", `fundamentals-json-circe` % "test->compile;compile->compile", - `fundamentals-reflection` % "test->compile;compile->compile", `fundamentals-bio` % "test->compile;compile->compile", `distage-core-api` % "test->compile;compile->compile", `distage-core-proxy-bytebuddy` % "test->compile;compile->compile", @@ -5317,7 +5127,6 @@ lazy val `fundamentals` = (project in file(".agg/fundamentals-fundamentals")) `fundamentals-language`, `fundamentals-platform`, `fundamentals-json-circe`, - `fundamentals-reflection`, `fundamentals-bio` ) @@ -5335,7 +5144,6 @@ lazy val `fundamentals-jvm` = (project in file(".agg/fundamentals-fundamentals-j `fundamentals-language`, `fundamentals-platform`, `fundamentals-json-circe`, - `fundamentals-reflection`, `fundamentals-bio` ) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/runtime/UnsafeProviderCallArgsMismatched.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/runtime/UnsafeProviderCallArgsMismatched.scala deleted file mode 100644 index 6bcbc38608..0000000000 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/runtime/UnsafeProviderCallArgsMismatched.scala +++ /dev/null @@ -1,6 +0,0 @@ -package izumi.distage.model.exceptions.runtime - -import izumi.distage.model.exceptions.DIException -import izumi.distage.model.reflection.SafeType - -class UnsafeProviderCallArgsMismatched(message: String, val expected: Seq[SafeType], val actual: Seq[SafeType], val actualValues: Seq[Any]) extends DIException(message) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index 4276bbda9e..4df3c850ec 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -1,18 +1,10 @@ package izumi.distage.model.providers -import izumi.distage.constructors.{ClassConstructor, FactoryConstructor, TraitConstructor, ZEnvConstructor} import izumi.distage.model.definition.Identifier -import izumi.distage.model.exceptions.runtime.TODOBindingException -import izumi.distage.model.reflection.LinkedParameter -import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.model.reflection.* import izumi.distage.reflection.macros.FunctoidMacroMethods -import izumi.fundamentals.platform.language.CodePositionMaterializer import izumi.fundamentals.platform.language.Quirks.* import izumi.reflect.Tag -import zio.ZEnvironment -import zio.managed.ZManaged -import zio.stacktracer.TracingImplicits.disableAutoTrace import scala.annotation.unchecked.uncheckedVariance import scala.annotation.unused @@ -157,221 +149,14 @@ final case class Functoid[+A](get: Provider) { @inline private def getRetTag: Tag[A @uncheckedVariance] = Tag(get.ret.closestClass, get.ret.tag) } -object Functoid extends FunctoidMacroMethods with FunctoidLifecycleAdapters { +object Functoid extends FunctoidMacroMethods with FunctoidLifecycleAdapters with FunctoidConstructors with SimpleFunctoids { implicit final class SyntaxMapSame[A](private val functoid: Functoid[A]) extends AnyVal { def mapSame(f: A => A): Functoid[A] = functoid.map(f)(functoid.getRetTag) } - def identity[A: Tag]: Functoid[A] = identityKey(DIKey.get[A]).asInstanceOf[Functoid[A]] - def pure[A: Tag](a: A): Functoid[A] = lift(a) def unit: Functoid[Unit] = pure(()) - def lift[A: Tag](a: => A): Functoid[A] = { - new Functoid[A]( - Provider.ProviderImpl[A]( - parameters = Seq.empty, - ret = SafeType.get[A], - underlying = () => a, - fun = (_: Seq[Any]) => a, - providerType = ProviderType.Function, - ) - ) - } - - def singleton[A <: Singleton: Tag](a: A): Functoid[A] = { - new Functoid[A]( - Provider.ProviderImpl[A]( - parameters = Seq.empty, - ret = SafeType.get[A], - underlying = a.asInstanceOf[AnyRef], - fun = (_: Seq[Any]) => a, - providerType = ProviderType.Constructor, - ) - ) - } - - def single[A: Tag, B: Tag](f: A => B): Functoid[B] = { - val key = DIKey.get[A] - val tpe = key.tpe - val retTpe = SafeType.get[B] - val symbolInfo = firstParamSymbolInfo(tpe) - - new Functoid[B]( - Provider.ProviderImpl( - parameters = Seq(LinkedParameter(symbolInfo, key)), - ret = retTpe, - underlying = f, - fun = (s: Seq[Any]) => f(s.head.asInstanceOf[A]), - providerType = ProviderType.Function, - ) - ) - } - - /** Derive constructor for a concrete class `A` using [[ClassConstructor]] */ - def makeClass[A: ClassConstructor]: Functoid[A] = ClassConstructor[A] - - /** - * Derive constructor for an abstract class or a trait `A` using [[TraitConstructor]] - * - * @see [[https://izumi.7mind.io/distage/basics.html#auto-traits Auto-Traits feature]] - */ - def makeTrait[A: TraitConstructor]: Functoid[A] = TraitConstructor[A] - - /** - * Derive constructor for a "factory-like" abstract class or a trait `A` using [[FactoryConstructor]] - * - * @see [[https://izumi.7mind.io/distage/basics.html#auto-factories Auto-Factories feature]] - */ - def makeFactory[A: FactoryConstructor]: Functoid[A] = FactoryConstructor[A] - - /** - * Derive constructor for a `zio.ZEnvironment` value `A` using [[ZEnvConstructor]] - * - * @see [[https://izumi.7mind.io/distage/basics.html#zio-environment-bindings ZIO Environment bindings]] - */ - def makeHas[A: ZEnvConstructor]: Functoid[ZEnvironment[A]] = ZEnvConstructor[A] - - @deprecated("Same as `makeClass`, use `makeClass`") - /** @deprecated Same as `makeClass`, use `makeClass` */ - def makeAny[A: ClassConstructor]: Functoid[A] = ClassConstructor[A] - - def todoProvider(key: DIKey)(implicit pos: CodePositionMaterializer): Functoid[Nothing] = { - new Functoid[Nothing]( - Provider.ProviderImpl( - parameters = Seq.empty, - ret = key.tpe, - fun = _ => throw new TODOBindingException(s"Tried to instantiate a 'TODO' binding for $key defined at ${pos.get}!", key, pos), - providerType = ProviderType.Function, - ) - ) - } - - def identityKey(key: DIKey): Functoid[?] = { - val tpe = key.tpe - val symbolInfo = firstParamSymbolInfo(tpe) - - new Functoid( - Provider.ProviderImpl( - parameters = Seq(LinkedParameter(symbolInfo, key)), - ret = tpe, - fun = (_: Seq[Any]).head, - providerType = ProviderType.Function, - ) - ) - } - - @inline private[this] def firstParamSymbolInfo(tpe: SafeType): SymbolInfo = { - SymbolInfo( - name = "x$1", - finalResultType = tpe, - isByName = false, - wasGeneric = false, - ) - } - -} - -private[providers] trait FunctoidLifecycleAdapters { - - import cats.effect.kernel.{Resource, Sync} - import izumi.reflect.{Tag, TagK} - import izumi.functional.lifecycle.Lifecycle - import zio.* - import scala.language.implicitConversions - - /** - * Allows you to bind [[cats.effect.Resource]]-based constructors in `ModuleDef`: - * - * Example: - * {{{ - * import cats.effect._ - * - * val catsResource = Resource.liftF(IO(5)) - * - * val module = new distage.ModuleDef { - * make[Int].fromResource(catsResource) - * } - * }}} - * - * @note binding a cats Resource[F, A] will add a - * dependency on `Sync[F]` for your corresponding `F` type - * (`Sync[F]` instance will generally be provided automatically via [[izumi.distage.modules.DefaultModule]]) - */ - implicit final def providerFromCats[F[_]: TagK, A]( - resource: => Resource[F, A] - )(implicit tag: Tag[Lifecycle.FromCats[F, A]] - ): Functoid[Lifecycle.FromCats[F, A]] = { - Functoid.identity[Sync[F]].map { - implicit sync: Sync[F] => - Lifecycle.fromCats(resource)(sync) - } - } - - /** - * Allows you to bind Scoped [[zio.ZIO]]-based constructors in `ModuleDef`: - */ - implicit final def providerFromZIOScoped[R, E, A]( - scoped: => ZIO[Scope & R, E, A] - )(implicit tag: Tag[Lifecycle.FromZIO[R, E, A]] - ): Functoid[Lifecycle.FromZIO[R, E, A]] = { - Functoid.lift(Lifecycle.fromZIO[R](scoped)) - } - - /** - * Allows you to bind Scoped [[zio.ZIO]]-based constructors in `ModuleDef`: - */ - // workaround for inference issues with `E=Nothing`, scalac error: Couldn't find Tag[FromZIO[Any, E, Clock]] when binding ZManaged[Any, Nothing, Clock] - implicit final def providerFromZIOScopedNothing[R, A]( - scoped: => ZIO[Scope & R, Nothing, A] - )(implicit tag: Tag[Lifecycle.FromZIO[R, Nothing, A]] - ): Functoid[Lifecycle.FromZIO[R, Nothing, A]] = { - Functoid.lift(Lifecycle.fromZIO[R](scoped)) - } - - /** - * Allows you to bind [[zio.managed.ZManaged]]-based constructors in `ModuleDef`: - */ - implicit final def providerFromZManaged[R, E, A]( - managed: => ZManaged[R, E, A] - )(implicit tag: Tag[Lifecycle.FromZIO[R, E, A]] - ): Functoid[Lifecycle.FromZIO[R, E, A]] = { - Functoid.lift(Lifecycle.fromZManaged(managed)) - } - - /** - * Allows you to bind [[zio.managed.ZManaged]]-based constructors in `ModuleDef`: - */ - // workaround for inference issues with `E=Nothing`, scalac error: Couldn't find Tag[FromZIO[Any, E, Clock]] when binding ZManaged[Any, Nothing, Clock] - implicit final def providerFromZManagedNothing[R, A]( - managed: => ZManaged[R, Nothing, A] - )(implicit tag: Tag[Lifecycle.FromZIO[R, Nothing, A]] - ): Functoid[Lifecycle.FromZIO[R, Nothing, A]] = { - Functoid.lift(Lifecycle.fromZManaged(managed)) - } - - /** - * Allows you to bind [[zio.ZLayer]]-based constructors in `ModuleDef`: - */ - implicit final def providerFromZLayer[R, E, A: Tag]( - layer: => ZLayer[R, E, A] - )(implicit tag: Tag[Lifecycle.FromZIO[R, E, A]] - ): Functoid[Lifecycle.FromZIO[R, E, A]] = { - Functoid.lift(Lifecycle.fromZLayer(layer)(zio.Tag[A])) - } - - /** - * Allows you to bind [[zio.ZLayer]]-based constructors in `ModuleDef`: - */ - // workaround for inference issues with `E=Nothing`, scalac error: Couldn't find Tag[FromZIO[Any, E, Clock]] when binding ZManaged[Any, Nothing, Clock] - implicit final def providerFromZLayerNothing[R, A: Tag]( - layer: => ZLayer[R, Nothing, A] - )(implicit tag: Tag[Lifecycle.FromZIO[R, Nothing, A]] - ): Functoid[Lifecycle.FromZIO[R, Nothing, A]] = { - Functoid.lift(Lifecycle.fromZLayer(layer)(zio.Tag[A])) - } - - disableAutoTrace.discard() } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/FunctoidConstructors.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/FunctoidConstructors.scala new file mode 100644 index 0000000000..f51396d585 --- /dev/null +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/FunctoidConstructors.scala @@ -0,0 +1,35 @@ +package izumi.distage.model.providers + +import izumi.distage.constructors.{ClassConstructor, FactoryConstructor, TraitConstructor, ZEnvConstructor} +import zio.ZEnvironment + +private[providers] trait FunctoidConstructors { + /** Derive constructor for a concrete class `A` using [[ClassConstructor]] */ + def makeClass[A: ClassConstructor]: Functoid[A] = ClassConstructor[A] + + /** + * Derive constructor for an abstract class or a trait `A` using [[TraitConstructor]] + * + * @see [[https://izumi.7mind.io/distage/basics.html#auto-traits Auto-Traits feature]] + */ + def makeTrait[A: TraitConstructor]: Functoid[A] = TraitConstructor[A] + + /** + * Derive constructor for a "factory-like" abstract class or a trait `A` using [[FactoryConstructor]] + * + * @see [[https://izumi.7mind.io/distage/basics.html#auto-factories Auto-Factories feature]] + */ + def makeFactory[A: FactoryConstructor]: Functoid[A] = FactoryConstructor[A] + + /** + * Derive constructor for a `zio.ZEnvironment` value `A` using [[ZEnvConstructor]] + * + * @see [[https://izumi.7mind.io/distage/basics.html#zio-environment-bindings ZIO Environment bindings]] + */ + def makeHas[A: ZEnvConstructor]: Functoid[ZEnvironment[A]] = ZEnvConstructor[A] + + @deprecated("Same as `makeClass`, use `makeClass`") + /** @deprecated Same as `makeClass`, use `makeClass` */ + def makeAny[A: ClassConstructor]: Functoid[A] = ClassConstructor[A] + +} diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/FunctoidLifecycleAdapters.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/FunctoidLifecycleAdapters.scala new file mode 100644 index 0000000000..8978bc1c63 --- /dev/null +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/FunctoidLifecycleAdapters.scala @@ -0,0 +1,108 @@ +package izumi.distage.model.providers + +import izumi.fundamentals.platform.language.Quirks.Discarder +import zio.managed.ZManaged +import zio.stacktracer.TracingImplicits.disableAutoTrace + +private[providers] trait FunctoidLifecycleAdapters { + + import cats.effect.kernel.{Resource, Sync} + import izumi.functional.lifecycle.Lifecycle + import izumi.reflect.{Tag, TagK} + import zio.* + + import scala.language.implicitConversions + + /** + * Allows you to bind [[cats.effect.Resource]]-based constructors in `ModuleDef`: + * + * Example: + * {{{ + * import cats.effect._ + * + * val catsResource = Resource.liftF(IO(5)) + * + * val module = new distage.ModuleDef { + * make[Int].fromResource(catsResource) + * } + * }}} + * + * @note binding a cats Resource[F, A] will add a + * dependency on `Sync[F]` for your corresponding `F` type + * (`Sync[F]` instance will generally be provided automatically via [[izumi.distage.modules.DefaultModule]]) + */ + implicit final def providerFromCats[F[_]: TagK, A]( + resource: => Resource[F, A] + )(implicit tag: Tag[Lifecycle.FromCats[F, A]] + ): Functoid[Lifecycle.FromCats[F, A]] = { + Functoid.identity[Sync[F]].map { + implicit sync: Sync[F] => + Lifecycle.fromCats(resource)(sync) + } + } + + /** + * Allows you to bind Scoped [[zio.ZIO]]-based constructors in `ModuleDef`: + */ + implicit final def providerFromZIOScoped[R, E, A]( + scoped: => ZIO[Scope & R, E, A] + )(implicit tag: Tag[Lifecycle.FromZIO[R, E, A]] + ): Functoid[Lifecycle.FromZIO[R, E, A]] = { + Functoid.lift(Lifecycle.fromZIO[R](scoped)) + } + + /** + * Allows you to bind Scoped [[zio.ZIO]]-based constructors in `ModuleDef`: + */ + // workaround for inference issues with `E=Nothing`, scalac error: Couldn't find Tag[FromZIO[Any, E, Clock]] when binding ZManaged[Any, Nothing, Clock] + implicit final def providerFromZIOScopedNothing[R, A]( + scoped: => ZIO[Scope & R, Nothing, A] + )(implicit tag: Tag[Lifecycle.FromZIO[R, Nothing, A]] + ): Functoid[Lifecycle.FromZIO[R, Nothing, A]] = { + Functoid.lift(Lifecycle.fromZIO[R](scoped)) + } + + /** + * Allows you to bind [[zio.managed.ZManaged]]-based constructors in `ModuleDef`: + */ + implicit final def providerFromZManaged[R, E, A]( + managed: => ZManaged[R, E, A] + )(implicit tag: Tag[Lifecycle.FromZIO[R, E, A]] + ): Functoid[Lifecycle.FromZIO[R, E, A]] = { + Functoid.lift(Lifecycle.fromZManaged(managed)) + } + + /** + * Allows you to bind [[zio.managed.ZManaged]]-based constructors in `ModuleDef`: + */ + // workaround for inference issues with `E=Nothing`, scalac error: Couldn't find Tag[FromZIO[Any, E, Clock]] when binding ZManaged[Any, Nothing, Clock] + implicit final def providerFromZManagedNothing[R, A]( + managed: => ZManaged[R, Nothing, A] + )(implicit tag: Tag[Lifecycle.FromZIO[R, Nothing, A]] + ): Functoid[Lifecycle.FromZIO[R, Nothing, A]] = { + Functoid.lift(Lifecycle.fromZManaged(managed)) + } + + /** + * Allows you to bind [[zio.ZLayer]]-based constructors in `ModuleDef`: + */ + implicit final def providerFromZLayer[R, E, A: Tag]( + layer: => ZLayer[R, E, A] + )(implicit tag: Tag[Lifecycle.FromZIO[R, E, A]] + ): Functoid[Lifecycle.FromZIO[R, E, A]] = { + Functoid.lift(Lifecycle.fromZLayer(layer)(zio.Tag[A])) + } + + /** + * Allows you to bind [[zio.ZLayer]]-based constructors in `ModuleDef`: + */ + // workaround for inference issues with `E=Nothing`, scalac error: Couldn't find Tag[FromZIO[Any, E, Clock]] when binding ZManaged[Any, Nothing, Clock] + implicit final def providerFromZLayerNothing[R, A: Tag]( + layer: => ZLayer[R, Nothing, A] + )(implicit tag: Tag[Lifecycle.FromZIO[R, Nothing, A]] + ): Functoid[Lifecycle.FromZIO[R, Nothing, A]] = { + Functoid.lift(Lifecycle.fromZLayer(layer)(zio.Tag[A])) + } + + disableAutoTrace.discard() +} diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala new file mode 100644 index 0000000000..1feb3f78e2 --- /dev/null +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala @@ -0,0 +1,86 @@ +package izumi.distage.model.providers + +import izumi.distage.model.exceptions.runtime.TODOBindingException +import izumi.distage.model.reflection.Provider.ProviderType +import izumi.distage.model.reflection.* +import izumi.fundamentals.platform.language.CodePositionMaterializer +import izumi.reflect.Tag + +private[providers] trait SimpleFunctoids { + def identity[A: Tag]: Functoid[A] = identityKey(DIKey.get[A]).asInstanceOf[Functoid[A]] + + def lift[A: Tag](a: => A): Functoid[A] = { + new Functoid[A]( + Provider.ProviderImpl[A]( + parameters = Seq.empty, + ret = SafeType.get[A], + underlying = () => a, + fun = (_: Seq[Any]) => a, + providerType = ProviderType.Function, + ) + ) + } + + def singleton[A <: Singleton: Tag](a: A): Functoid[A] = { + new Functoid[A]( + Provider.ProviderImpl[A]( + parameters = Seq.empty, + ret = SafeType.get[A], + underlying = a.asInstanceOf[AnyRef], + fun = (_: Seq[Any]) => a, + providerType = ProviderType.Constructor, + ) + ) + } + + def single[A: Tag, B: Tag](f: A => B): Functoid[B] = { + val key = DIKey.get[A] + val tpe = key.tpe + val retTpe = SafeType.get[B] + val symbolInfo = firstParamSymbolInfo(tpe) + + new Functoid[B]( + Provider.ProviderImpl( + parameters = Seq(LinkedParameter(symbolInfo, key)), + ret = retTpe, + underlying = f, + fun = (s: Seq[Any]) => f(s.head.asInstanceOf[A]), + providerType = ProviderType.Function, + ) + ) + } + + def todoProvider(key: DIKey)(implicit pos: CodePositionMaterializer): Functoid[Nothing] = { + new Functoid[Nothing]( + Provider.ProviderImpl( + parameters = Seq.empty, + ret = key.tpe, + fun = _ => throw new TODOBindingException(s"Tried to instantiate a 'TODO' binding for $key defined at ${pos.get}!", key, pos), + providerType = ProviderType.Function, + ) + ) + } + + def identityKey(key: DIKey): Functoid[?] = { + val tpe = key.tpe + val symbolInfo = firstParamSymbolInfo(tpe) + + new Functoid( + Provider.ProviderImpl( + parameters = Seq(LinkedParameter(symbolInfo, key)), + ret = tpe, + fun = (_: Seq[Any]).head, + providerType = ProviderType.Function, + ) + ) + } + + @inline private[this] def firstParamSymbolInfo(tpe: SafeType): SymbolInfo = { + SymbolInfo( + name = "x$1", + finalResultType = tpe, + isByName = false, + wasGeneric = false, + ) + } +} diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/provisioning/PlanInterpreter.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/provisioning/PlanInterpreter.scala index 1f38dea6b4..95054e5181 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/provisioning/PlanInterpreter.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/provisioning/PlanInterpreter.scala @@ -11,6 +11,7 @@ import izumi.distage.model.plan.Plan import izumi.distage.model.provisioning.PlanInterpreter.{FailedProvision, FinalizerFilter} import izumi.distage.model.provisioning.Provision.{ProvisionImmutable, ProvisionInstances} import izumi.distage.model.reflection.* +import izumi.distage.model.reflection.Provider.UnsafeProviderCallArgsMismatched import izumi.functional.quasi.QuasiIO import izumi.fundamentals.platform.IzumiProject import izumi.fundamentals.platform.build.MacroParameters @@ -104,6 +105,7 @@ object PlanInterpreter { case UnexpectedStepProvisioning(op, problem) => val excName = problem match { case di: DIException => di.getClass.getSimpleName + case p: UnsafeProviderCallArgsMismatched => p.getClass.getSimpleName case o => o.getClass.getName } s"Got exception when trying to to execute $op, exception was:\n$excName:\n${stackTrace(problem)}" diff --git a/fundamentals/fundamentals-reflection/.jvm/test/scala/izumi/fundamentals/platform/build/test/BuildAttributesMacroTest.scala b/fundamentals/fundamentals-platform/.jvm/test/scala/izumi/fundamentals/platform/build/test/BuildAttributesMacroTest.scala similarity index 100% rename from fundamentals/fundamentals-reflection/.jvm/test/scala/izumi/fundamentals/platform/build/test/BuildAttributesMacroTest.scala rename to fundamentals/fundamentals-platform/.jvm/test/scala/izumi/fundamentals/platform/build/test/BuildAttributesMacroTest.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-2.12/izumi/fundamentals/reflection/JSRAnnotationTools.scala b/fundamentals/fundamentals-platform/src/main/scala-2.12/izumi/fundamentals/reflection/JSRAnnotationTools.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-2.12/izumi/fundamentals/reflection/JSRAnnotationTools.scala rename to fundamentals/fundamentals-platform/src/main/scala-2.12/izumi/fundamentals/reflection/JSRAnnotationTools.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-2.13/izumi/fundamentals/reflection/JSRAnnotationTools.scala b/fundamentals/fundamentals-platform/src/main/scala-2.13/izumi/fundamentals/reflection/JSRAnnotationTools.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-2.13/izumi/fundamentals/reflection/JSRAnnotationTools.scala rename to fundamentals/fundamentals-platform/src/main/scala-2.13/izumi/fundamentals/reflection/JSRAnnotationTools.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/platform/build/BuildAttributeMacroImpl.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/platform/build/BuildAttributeMacroImpl.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/platform/build/BuildAttributeMacroImpl.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/platform/build/BuildAttributeMacroImpl.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/platform/build/BuildAttributes.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/platform/build/BuildAttributes.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/platform/build/BuildAttributes.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/platform/build/BuildAttributes.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/platform/build/MacroParameters.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/platform/build/MacroParameters.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/platform/build/MacroParameters.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/platform/build/MacroParameters.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/platform/build/MacroParametersImpl.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/platform/build/MacroParametersImpl.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/platform/build/MacroParametersImpl.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/platform/build/MacroParametersImpl.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/reflection/AnnotationTools.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/reflection/AnnotationTools.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/reflection/AnnotationTools.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/reflection/AnnotationTools.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/reflection/ReflectionUtil.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/reflection/ReflectionUtil.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/reflection/ReflectionUtil.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/reflection/ReflectionUtil.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/reflection/package.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/reflection/package.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-2/izumi/fundamentals/reflection/package.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/reflection/package.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-3/izumi/fundamentals/platform/build/BuildAttributes.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/fundamentals/platform/build/BuildAttributes.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-3/izumi/fundamentals/platform/build/BuildAttributes.scala rename to fundamentals/fundamentals-platform/src/main/scala-3/izumi/fundamentals/platform/build/BuildAttributes.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-3/izumi/fundamentals/platform/build/BuildAttributesImpl.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/fundamentals/platform/build/BuildAttributesImpl.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-3/izumi/fundamentals/platform/build/BuildAttributesImpl.scala rename to fundamentals/fundamentals-platform/src/main/scala-3/izumi/fundamentals/platform/build/BuildAttributesImpl.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-3/izumi/fundamentals/platform/build/MacroParameters.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/fundamentals/platform/build/MacroParameters.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-3/izumi/fundamentals/platform/build/MacroParameters.scala rename to fundamentals/fundamentals-platform/src/main/scala-3/izumi/fundamentals/platform/build/MacroParameters.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-3/izumi/fundamentals/platform/build/MacroParametersImpl.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/fundamentals/platform/build/MacroParametersImpl.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-3/izumi/fundamentals/platform/build/MacroParametersImpl.scala rename to fundamentals/fundamentals-platform/src/main/scala-3/izumi/fundamentals/platform/build/MacroParametersImpl.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala-3/izumi/fundamentals/platform/reflection/ReflectionUtil.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/fundamentals/platform/reflection/ReflectionUtil.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala-3/izumi/fundamentals/platform/reflection/ReflectionUtil.scala rename to fundamentals/fundamentals-platform/src/main/scala-3/izumi/fundamentals/platform/reflection/ReflectionUtil.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/definition/Identifier.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/definition/Identifier.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/definition/Identifier.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/definition/Identifier.scala diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/DIKey.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/DIKey.scala similarity index 100% rename from distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/DIKey.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/DIKey.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/IdContract.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/IdContract.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/IdContract.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/IdContract.scala diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/LinkedParameter.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/LinkedParameter.scala similarity index 100% rename from distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/LinkedParameter.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/LinkedParameter.scala diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/Provider.scala similarity index 94% rename from distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/Provider.scala index eb9ecdba73..c462666f63 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/Provider.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/Provider.scala @@ -1,7 +1,6 @@ package izumi.distage.model.reflection -import izumi.distage.model.exceptions.runtime.UnsafeProviderCallArgsMismatched -import izumi.distage.model.reflection.Provider.ProviderType +import izumi.distage.model.reflection.Provider.{ProviderType, UnsafeProviderCallArgsMismatched} trait Provider { def parameters: Seq[LinkedParameter] @@ -76,6 +75,8 @@ trait Provider { } object Provider { + class UnsafeProviderCallArgsMismatched(message: String, val expected: Seq[SafeType], val actual: Seq[SafeType], val actualValues: Seq[Any]) + extends RuntimeException(message) sealed trait ProviderType object ProviderType { diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/SafeType.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SafeType.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/SafeType.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SafeType.scala diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala similarity index 100% rename from distage/distage-core-api/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/platform/build/package.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/build/package.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/platform/build/package.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/build/package.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/CachedHashcode.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/CachedHashcode.scala new file mode 100644 index 0000000000..81de01f222 --- /dev/null +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/CachedHashcode.scala @@ -0,0 +1,6 @@ +package izumi.fundamentals.platform.cache + +trait CachedHashcode { + protected def hash: Int + override final lazy val hashCode: Int = hash +} diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/CachedProductHashcode.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/CachedProductHashcode.scala index d5b916638a..43ebdbbd13 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/CachedProductHashcode.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/CachedProductHashcode.scala @@ -1,10 +1,5 @@ package izumi.fundamentals.platform.cache -trait CachedHashcode { - protected def hash: Int - override final lazy val hashCode: Int = hash -} - trait CachedProductHashcode { this: Product => override final lazy val hashCode: Int = { scala.runtime.ScalaRunTime._hashCode(this) diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/ReflectiveCall.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/reflection/ReflectiveCall.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/ReflectiveCall.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/reflection/ReflectiveCall.scala diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/TypeUtil.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/reflection/TypeUtil.scala similarity index 100% rename from fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/TypeUtil.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/reflection/TypeUtil.scala diff --git a/project/Deps.sc b/project/Deps.sc index 9d6a84f3cf..db869b294b 100644 --- a/project/Deps.sc +++ b/project/Deps.sc @@ -368,7 +368,7 @@ object Izumi { final val literals = ArtifactId("fundamentals-literals") final val typesafeConfig = ArtifactId("fundamentals-typesafe-config") - final val reflection = ArtifactId("fundamentals-reflection") +// final val reflection = ArtifactId("fundamentals-reflection") final val jsonCirce = ArtifactId("fundamentals-json-circe") final lazy val basics = Seq( @@ -482,12 +482,14 @@ object Izumi { Artifact( name = Projects.fundamentals.platform, libs = Seq( - scala_reflect + izumi_reflect in Scope.Compile.all, + scala_reflect, ), depends = Seq( + Projects.fundamentals.functional, Projects.fundamentals.language in Scope.Compile.all, Projects.fundamentals.collections in Scope.Compile.all, - Projects.fundamentals.reflection in Scope.Compile.all, +// Projects.fundamentals.reflection in Scope.Compile.all, ), settings = Seq( "npmDependencies" in (SettingScope.Test, Platform.Js) ++= Seq("hash.js" -> "1.1.7") @@ -515,14 +517,15 @@ object Izumi { "libraryDependencySchemes" in SettingScope.Compile += s""""${circe_core.group}" %% "${circe_core.artifact}_sjs1" % VersionScheme.Always""".raw, ), ), - Artifact( - name = Projects.fundamentals.reflection, - libs = Seq(izumi_reflect in Scope.Compile.all, scala_reflect), - depends = Seq( - Projects.fundamentals.functional - ), - settings = Seq.empty, - ), +// Artifact( +// name = Projects.fundamentals.reflection, +// libs = Seq(izumi_reflect in Scope.Compile.all, scala_reflect), +// depends = Seq( +// Projects.fundamentals.functional, +// Projects.fundamentals.language, +// ), +// settings = Seq.empty, +// ), Artifact( name = Projects.fundamentals.bio, libs = allMonadsOptional ++ @@ -561,7 +564,7 @@ object Izumi { name = Projects.distage.coreApi, libs = allCatsOptional ++ allZioOptional ++ allMonadsTest ++ Seq(scala_reflect) ++ Seq(zio_managed in Scope.Optional.all), depends = Seq( - Projects.fundamentals.reflection, +// Projects.fundamentals.reflection, Projects.fundamentals.platform, Projects.fundamentals.bio, ).map(_ in Scope.Compile.all), From e3187ed1b46d75d296227754ac016fb0b28c9584 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Thu, 25 Apr 2024 16:30:20 +0100 Subject: [PATCH 13/59] wip --- .../reflection/macros/FunctoidMacro.scala | 21 ++--- .../ReflectionProviderDefaultImpl.scala | 90 ++++++++++--------- .../universe/impl/WithDIAssociation.scala | 6 +- 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index cb9efd90fc..cd8d23b9e4 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -21,16 +21,13 @@ import scala.reflect.macros.blackbox * @see [[izumi.distage.constructors.DebugProperties]] */ class FunctoidMacro(val c: blackbox.Context) { - final val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) + type Parameter = macroUniverse.Association.Parameter private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) private final val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) import c.universe.* - import macroUniverse.* - - case class ExtractedInfo(associations: List[Association.Parameter], isValReference: Boolean) def impl[R: c.WeakTypeTag](fun: Tree): c.Expr[Functoid[R]] = { val associations = analyze(fun, weakTypeOf[R]) @@ -51,7 +48,7 @@ class FunctoidMacro(val c: blackbox.Context) { result } - def analyze(tree: Tree, ret: Type): List[Association.Parameter] = tree match { + def analyze(tree: Tree, ret: Type): List[Parameter] = tree match { case Block(List(), inner) => analyze(inner, ret) case Function(args, body) => @@ -81,14 +78,14 @@ class FunctoidMacro(val c: blackbox.Context) { ) } - def generateProvider[R: c.WeakTypeTag](parameters: List[Association.Parameter], fun: Tree): c.Expr[Functoid[R]] = { + def generateProvider[R: c.WeakTypeTag](parameters: List[Parameter], fun: Tree): c.Expr[Functoid[R]] = { val tools = DIUniverseLiftables(macroUniverse) import tools.{liftTypeToSafeType, liftableParameter} val seqName = if (parameters.nonEmpty) TermName(c.freshName("seqAny")) else TermName("_") val casts = parameters.indices.map(i => q"$seqName($i)") - val parametersNoByName = Liftable.liftList[Association.Parameter].apply(parameters) + val parametersNoByName = Liftable.liftList[Parameter].apply(parameters) c.Expr[Functoid[R]] { q"""{ @@ -107,9 +104,9 @@ class FunctoidMacro(val c: blackbox.Context) { } } - protected[this] def analyzeMethodRef(lambdaArgs: List[Symbol], body: Tree): List[Association.Parameter] = { - def association(p: Symbol): Association.Parameter = { - reflectionProvider.parameterToAssociation(MacroSymbolInfo.Runtime(p)) + protected[this] def analyzeMethodRef(lambdaArgs: List[Symbol], body: Tree): List[Parameter] = { + def association(p: Symbol): Parameter = { + reflectionProvider.parameterToAssociation(macroUniverse.MacroSymbolInfo.Runtime(p)) } val lambdaParams = lambdaArgs.map(association) @@ -188,10 +185,10 @@ class FunctoidMacro(val c: blackbox.Context) { method.typeSignature.paramLists.flatten } - protected[this] def analyzeValRef(sig: Type): List[Association.Parameter] = { + protected[this] def analyzeValRef(sig: Type): List[Parameter] = { widenFunctionObject(sig).typeArgs.init.map { tpe => - val symbol = MacroSymbolInfo.Static.syntheticFromType(c.freshName)(tpe) + val symbol = macroUniverse.MacroSymbolInfo.Static.syntheticFromType(c.freshName)(tpe) reflectionProvider.parameterToAssociation(symbol) } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index ba9213cf8c..e0c2a30634 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -65,38 +65,6 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } - override def zioHasParameters(transformName: String => String)(deepIntersection: List[u.TypeNative]): List[u.Association.Parameter] = { - deepIntersection.map { - hasTpe => - val tpe = hasTpe.dealias - val syntheticSymbolInfo = MacroSymbolInfo.Static.syntheticFromType(transformName)(tpe) - Association.Parameter(syntheticSymbolInfo, keyFromSymbolResultType(syntheticSymbolInfo)) - } - } - - private def factoryMethod(tpe: u.TypeNative)(factoryMethod: u.u.MethodSymbol): u.MacroWiring.Factory.FactoryMethod = { - val factoryMethodSymb = MacroSymbolInfo.Runtime(factoryMethod, tpe, wasGeneric = false) - val resultType = ReflectionUtil.norm(u.u: u.u.type) { - resultOfFactoryMethod(factoryMethodSymb) - .asSeenFrom(tpe, tpe.typeSymbol) - } - - val alreadyInSignature = factoryMethod.paramLists.flatten.map(symbol => keyFromParameter(MacroSymbolInfo.Runtime(symbol, tpe, wasGeneric = false))) - val resultTypeWiring = mkConstructorWiring(factoryMethod, resultType) - - val excessiveTypes = alreadyInSignature.toSet -- resultTypeWiring.requiredKeys - if (excessiveTypes.nonEmpty) { - throw new UnsupportedDefinitionException( - s"""Augmentation failure. - | * Type $tpe has been considered a factory because of abstract method `${factoryMethodSymb.name}: ${factoryMethodSymb.typeSignatureInDefiningClass}` with result type `$resultType` - | * But method signature contains types not required by constructor of the result type: $excessiveTypes - | * Only the following types are required: ${resultTypeWiring.requiredKeys} - | * This may happen in case you unintentionally bind an abstract type (trait, etc) as implementation type.""".stripMargin - ) - } - - MacroWiring.Factory.FactoryMethod(factoryMethodSymb, resultTypeWiring, alreadyInSignature) - } override def constructorParameterLists(tpe: TypeNative): List[List[Association.Parameter]] = { selectConstructorArguments(tpe).toList.flatten.map(_.map(parameterToAssociation)) } @@ -165,26 +133,60 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } override def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter = { - val key = keyFromParameter(parameterSymbol) - Association.Parameter(parameterSymbol, key) + val key = keyFromSymbol(parameterSymbol) + Association.Parameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) + } + + override def zioHasParameters(transformName: String => String)(deepIntersection: List[u.TypeNative]): List[u.Association.Parameter] = { + deepIntersection.map { + hasTpe => + val tpe = hasTpe.dealias + val syntheticSymbolInfo = MacroSymbolInfo.Static.syntheticFromType(transformName)(tpe) + Association.Parameter(syntheticSymbolInfo, tpeFromSymbol(syntheticSymbolInfo), keyFromSymbol(syntheticSymbolInfo)) + } + } + + private def factoryMethod(tpe: u.TypeNative)(factoryMethod: u.u.MethodSymbol): u.MacroWiring.Factory.FactoryMethod = { + val factoryMethodSymb = MacroSymbolInfo.Runtime(factoryMethod, tpe, wasGeneric = false) + val resultType = ReflectionUtil.norm(u.u: u.u.type) { + resultOfFactoryMethod(factoryMethodSymb) + .asSeenFrom(tpe, tpe.typeSymbol) + } + + val alreadyInSignature = factoryMethod.paramLists.flatten.map(symbol => keyFromSymbol(MacroSymbolInfo.Runtime(symbol, tpe, wasGeneric = false))) + val resultTypeWiring = mkConstructorWiring(factoryMethod, resultType) + + val excessiveTypes = alreadyInSignature.toSet -- resultTypeWiring.requiredKeys + if (excessiveTypes.nonEmpty) { + throw new UnsupportedDefinitionException( + s"""Augmentation failure. + | * Type $tpe has been considered a factory because of abstract method `${factoryMethodSymb.name}: ${factoryMethodSymb.typeSignatureInDefiningClass}` with result type `$resultType` + | * But method signature contains types not required by constructor of the result type: $excessiveTypes + | * Only the following types are required: ${resultTypeWiring.requiredKeys} + | * This may happen in case you unintentionally bind an abstract type (trait, etc) as implementation type.""".stripMargin + ) + } + + MacroWiring.Factory.FactoryMethod(factoryMethodSymb, resultTypeWiring, alreadyInSignature) } private[this] def methodToAssociation(definingClass: TypeNative, method: MethodSymbNative): Association.AbstractMethod = { val methodSymb = MacroSymbolInfo.Runtime(method, definingClass, wasGeneric = false) - Association.AbstractMethod(methodSymb, keyFromSymbolResultType(methodSymb)) + Association.AbstractMethod(methodSymb, tpeFromSymbol(methodSymb), keyFromSymbol(methodSymb)) } - private[this] def keyFromParameter(parameterSymbol: MacroSymbolInfo): MacroDIKey.BasicKey = { - val paramType = if (parameterSymbol.isByName) { + private[this] def tpeFromSymbol(parameterSymbol: MacroSymbolInfo): u.MacroSafeType = { + val paramType = if (parameterSymbol.isByName) { // this will never be true for a method symbol parameterSymbol.finalResultType.typeArgs.head.finalResultType - } else parameterSymbol.finalResultType - val typeKey = MacroDIKey.TypeKey(MacroSafeType.create(paramType)) - withIdKeyFromAnnotation(parameterSymbol, typeKey) + } else { + parameterSymbol.finalResultType + } + MacroSafeType.create(paramType) } - - private[this] def keyFromSymbolResultType(methodSymbol: MacroSymbolInfo): MacroDIKey.BasicKey = { - val typeKey = MacroDIKey.TypeKey(MacroSafeType.create(methodSymbol.finalResultType)) - withIdKeyFromAnnotation(methodSymbol, typeKey) + private[this] def keyFromSymbol(parameterSymbol: MacroSymbolInfo): MacroDIKey.BasicKey = { + val tpe = tpeFromSymbol(parameterSymbol) + val typeKey = MacroDIKey.TypeKey(tpe) + withIdKeyFromAnnotation(parameterSymbol, typeKey) } private[this] object ConcreteSymbol { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala index 1b8fb82499..e9d9e3de9d 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala @@ -34,16 +34,16 @@ private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISafeT } object Association { - case class Parameter(symbol: MacroSymbolInfo, key: MacroDIKey.BasicKey) extends Association { + case class Parameter(symbol: MacroSymbolInfo, stpe: MacroSafeType, key: MacroDIKey.BasicKey) extends Association { override final def isByName: Boolean = symbol.isByName override final def asParameter: Association.Parameter = this override final def asParameterTpe: TypeNative = tpe } // tpe is never by-name for `AbstractMethod` - case class AbstractMethod(symbol: MacroSymbolInfo, key: MacroDIKey.BasicKey) extends Association { + case class AbstractMethod(symbol: MacroSymbolInfo, stpe: MacroSafeType, key: MacroDIKey.BasicKey) extends Association { override final def isByName: Boolean = true - override final def asParameter: Parameter = Parameter(symbol.withIsByName(true).withTpe(asParameterTpe), key) + override final def asParameter: Parameter = Parameter(symbol.withIsByName(true).withTpe(asParameterTpe), stpe, key) override final def asParameterTpe: TypeNative = u.appliedType(u.definitions.ByNameParamClass, tpe) // force by-name } } From fe039a443070ee1f4927f0676471e362429896c8 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 8 May 2024 20:17:29 +0100 Subject: [PATCH 14/59] wip --- .../reflection/macros/FunctoidMacro.scala | 2 +- .../macros/universe/DIUniverseLiftables.scala | 2 +- .../macros/universe/ReflectionProvider.scala | 2 + .../ReflectionProviderDefaultImpl.scala | 2 +- .../macros/universe/StaticDIUniverse.scala | 2 + .../macros/universe/impl/DIUniverseBase.scala | 3 + .../universe/impl/WithDISymbolInfo.scala | 71 ++++++++++++++++++- .../docker/bundled/PostgresFlyWayDocker.scala | 2 +- 8 files changed, 81 insertions(+), 5 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index cd8d23b9e4..dd2a492b58 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -157,7 +157,7 @@ class FunctoidMacro(val c: blackbox.Context) { case (mArg, lArg) => mArg.copy( symbol = lArg.symbol.withAnnotations(mArg.symbol.annotations), - key = mArg.key.withTpe(lArg.key.tpe), + key = mArg.key.withTpe(lArg.stpe), ) } } else { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index 023e92c79a..6aa3d884df 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -53,7 +53,7 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { // converts Association.Parameter to LinkedParameter implicit val liftableParameter: Liftable[Association.Parameter] = { - case Association.Parameter(symbol, key) => + case Association.Parameter(symbol, _, key) => q"new $modelReflectionPkg.LinkedParameter($symbol, $key)" } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala index 6785bf9d10..28b2aeb9b6 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala @@ -16,6 +16,8 @@ trait ReflectionProvider { def isConcrete(tpe: TypeNative): Boolean def isWireableAbstract(tpe: TypeNative): Boolean def isFactory(tpe: TypeNative): Boolean + + def selectConstructorMethod(tpe: TypeNative): Option[MethodSymbNative] } object ReflectionProvider { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index e0c2a30634..692b6d34c0 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -226,7 +226,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } } - private[this] def selectConstructorMethod(tpe: TypeNative): Option[MethodSymbNative] = { + def selectConstructorMethod(tpe: TypeNative): Option[MethodSymbNative] = { val constructor = findConstructor(tpe) if (!constructor.isTerm) { None diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala index 2baf8f65c6..23d4ffa4f9 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala @@ -25,6 +25,8 @@ object StaticDIUniverse { override protected val typeOfDistageAnnotation: TypeNative = u.typeOf[DIStageAnnotation] override implicit val stringIdContract: MacroIdContract[String] = new IdContractImpl[String] override implicit def singletonStringIdContract[S <: String with Singleton]: MacroIdContract[S] = new IdContractImpl[S] + + override val rp: ReflectionProvider = ReflectionProviderDefaultImpl.apply(this) } } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala index 84aca7d891..d121d07b3f 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala @@ -1,9 +1,12 @@ package izumi.distage.reflection.macros.universe.impl +import izumi.distage.reflection.macros.universe.ReflectionProvider + import scala.reflect.api.Universe trait DIUniverseBase { val u: Universe + val rp: ReflectionProvider type TypeNative = u.Type type SymbNative = u.Symbol diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index c68323078c..6076f11e2a 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -5,6 +5,70 @@ import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => + sealed trait FriendlyAnnoParams + object FriendlyAnnoParams { + case class Full(values: List[(String, FriendlyAnnotationValue)]) extends FriendlyAnnoParams + case class Values(values: List[FriendlyAnnotationValue]) extends FriendlyAnnoParams + + } + case class FriendlyAnnotation(fqn: String, params: FriendlyAnnoParams) + sealed trait FriendlyAnnotationValue + object FriendlyAnnotation { + case class StringValue(value: String) extends FriendlyAnnotationValue + case class IntValue(value: Int) extends FriendlyAnnotationValue + case class LongValue(value: Long) extends FriendlyAnnotationValue + case class UnknownConst(value: Any) extends FriendlyAnnotationValue + case class Unknown() extends FriendlyAnnotationValue + } + + def makeFriendly(anno: u.Annotation): FriendlyAnnotation = { + import u.* + + val tpe = anno.tree.tpe.finalResultType +// val tag = LightTypeTagImpl.makeLightTypeTag(u)(tpe) +// println(tag) + val annoName = tpe.typeSymbol.fullName + val paramTrees = anno.tree.children.tail + val values = paramTrees.map { + p => + (p: @unchecked) match { + case Literal(Constant(c)) => + c match { + case v: String => + FriendlyAnnotation.StringValue(v) + case v: Int => + FriendlyAnnotation.IntValue(v) + case v: Long => + FriendlyAnnotation.LongValue(v) + case v => + FriendlyAnnotation.UnknownConst(v) + } + case _ => + FriendlyAnnotation.Unknown() + } + } + + val constructor = rp.selectConstructorMethod(tpe.asInstanceOf[rp.u.TypeNative]) + +// println((anno, u.showRaw(anno.tree.children.head))) + println(tpe) + val avals = constructor match { + case Some(c) => + c.paramLists match { + case params :: Nil => + val names = params.map(_.name.decodedName.toString) + assert(names.size == values.size) + FriendlyAnnoParams.Full(names.zip(values)) + case _ => + FriendlyAnnoParams.Values(values) + } + case _ => + FriendlyAnnoParams.Values(values) + } + + FriendlyAnnotation(annoName, avals) + } + sealed trait MacroSymbolInfo { def name: String def finalResultType: TypeNative @@ -105,7 +169,12 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => } private[this] def findAnnotation(tgtAnnType: TypeNative): Option[u.Annotation] = { - symbolInfo.annotations.find(a => AnnotationTools.annotationTypeEq(u)(tgtAnnType, a)) + val r = symbolInfo.annotations.find(a => AnnotationTools.annotationTypeEq(u)(tgtAnnType, a)) + r.foreach { + a => + println(makeFriendly(a)) + } + r } } diff --git a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/bundled/PostgresFlyWayDocker.scala b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/bundled/PostgresFlyWayDocker.scala index 8de8416631..71a72fdbdb 100644 --- a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/bundled/PostgresFlyWayDocker.scala +++ b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/bundled/PostgresFlyWayDocker.scala @@ -115,7 +115,7 @@ class PostgresFlyWayDockerModule[F[_]: TagK]( .connectToNetwork(PostgresFlyWayDocker.FlyWayNetwork) .modifyConfig { Functoid { // FIXME: explicit `Functoid` application required on Scala 3 due to https://github.com/lampepfl/dotty/issues/16108 - (postgresContainer: PostgresFlyWayDocker.Container @Id("postgres-flyway-proxy"), cfg: PostgresFlyWayDocker.Cfg) => + (postgresContainer: PostgresFlyWayDocker.Container @Id(name = "postgres-flyway-proxy"), cfg: PostgresFlyWayDocker.Cfg) => PostgresFlyWayDocker.FlyWay.applyCfg(postgresContainer.hostName, cfg) } } From 6c7957627e72deaa4a65bc5a06cd6eee62dd8661 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 27 May 2024 16:59:34 +0100 Subject: [PATCH 15/59] wip --- .../macros/universe/ReflectionProvider.scala | 1 + .../ReflectionProviderDefaultImpl.scala | 67 ++++--- .../universe/impl/WithDIAssociation.scala | 5 + .../universe/impl/WithDISymbolInfo.scala | 165 ++++++++++++------ 4 files changed, 156 insertions(+), 82 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala index 28b2aeb9b6..a8c8e078c1 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala @@ -7,6 +7,7 @@ trait ReflectionProvider { import u.* def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter + def parameterToAssociation2(parameterSymbol: MacroSymbolInfo): Association.CompactParameter def constructorParameterLists(tpe: TypeNative): List[List[Association.Parameter]] def symbolToAnyWiring(tpe: TypeNative): MacroWiring diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index 692b6d34c0..2941780880 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -4,26 +4,16 @@ import izumi.distage.model.definition.{Id, With} import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException -import izumi.distage.reflection.macros.universe.impl.DIUniverse -import izumi.fundamentals.reflection.{JSRAnnotationTools, ReflectionUtil} +import izumi.distage.reflection.macros.universe.impl.{DIUniverse, FriendlyAnnoParams, FriendlyAnnotationValue} +import izumi.fundamentals.reflection.ReflectionUtil import scala.annotation.nowarn @nowarn("msg=outer reference") trait ReflectionProviderDefaultImpl extends ReflectionProvider { - - import u.u.{Annotation, LiteralApi} + import u.u.Annotation import u.{Association, MacroDIKey, MacroSafeType, MacroSymbolInfo, MacroWiring, MethodSymbNative, SymbNative, TypeNative, stringIdContract} - private[this] object Id { - def unapply(ann: Annotation): Option[String] = { - ann.tree.children.tail.collectFirst { - case l: LiteralApi if l.value.value.isInstanceOf[String] => - l.value.value.asInstanceOf[String] - } - } - } - private[this] object With { def unapply(ann: Annotation): Option[TypeNative] = { ann.tree.tpe.typeArgs.headOption @@ -31,18 +21,42 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } private[this] def withIdKeyFromAnnotation(parameterSymbol: MacroSymbolInfo, typeKey: MacroDIKey.TypeKey): MacroDIKey.BasicKey = { - parameterSymbol.findUniqueAnnotation(typeOfIdAnnotation) match { - case Some(Id(name)) => - typeKey.named(name) - case Some(v) => - throw new BadIdAnnotationException(typeOfIdAnnotation.toString, v) - case None => - JSRAnnotationTools.uniqueJSRNameAnno(u.u)(parameterSymbol.annotations) match { - case Some(value) => - typeKey.named(value) - case None => - typeKey + val maybeDistageName = parameterSymbol.findUniqueFriendlyAnno(a => a.fqn == typeOfIdAnnotation.typeSymbol.fullName).map { + value => + value.params match { + case FriendlyAnnoParams.Full(values) => + values.toMap.get("name") match { + case Some(value: FriendlyAnnotationValue.StringValue) => + value.value + case _ => + throw new BadIdAnnotationException(value.toString, value) + } + + case FriendlyAnnoParams.Values(_) => + throw new BadIdAnnotationException(value.toString, value) } + + } + +// parameterSymbol.findUniqueFriendlyAnno(a => a.fqn.endsWith(".Named")) match { +// case Some(value) => +// System.out.println(s"${System.nanoTime()} $value") +// case None => +// } + + lazy val maybeJSRName = parameterSymbol.findUniqueFriendlyAnno(a => a.fqn.endsWith(".Named")).flatMap { + value => + value.params.values match { + case FriendlyAnnotationValue.StringValue(head) :: Nil => + Some(head) + case _ => + None + } + } + + maybeDistageName.orElse(maybeJSRName) match { + case Some(value) => typeKey.named(value) + case None => typeKey } } @@ -137,6 +151,11 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { Association.Parameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) } + override def parameterToAssociation2(parameterSymbol: MacroSymbolInfo): Association.CompactParameter = { + val key = keyFromSymbol(parameterSymbol) + Association.CompactParameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) + } + override def zioHasParameters(transformName: String => String)(deepIntersection: List[u.TypeNative]): List[u.Association.Parameter] = { deepIntersection.map { hasTpe => diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala index e9d9e3de9d..8a2e5d18d4 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala @@ -34,6 +34,11 @@ private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISafeT } object Association { + case class CompactParameter(symbol: MacroSymbolInfoCompact, stpe: MacroSafeType, key: MacroDIKey.BasicKey) { + final def isByName: Boolean = symbol.isByName + final def asParameter: Association.CompactParameter = this + } + case class Parameter(symbol: MacroSymbolInfo, stpe: MacroSafeType, key: MacroDIKey.BasicKey) extends Association { override final def isByName: Boolean = symbol.isByName override final def asParameter: Association.Parameter = this diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index 6076f11e2a..e9af32f405 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -3,24 +3,41 @@ package izumi.distage.reflection.macros.universe.impl import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} -trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => +sealed trait FriendlyAnnoParams { + def values: List[FriendlyAnnotationValue] +} +object FriendlyAnnoParams { + case class Full(named: List[(String, FriendlyAnnotationValue)]) extends FriendlyAnnoParams { + override def values: List[FriendlyAnnotationValue] = named.map(_._2) + } + case class Values(values: List[FriendlyAnnotationValue]) extends FriendlyAnnoParams - sealed trait FriendlyAnnoParams - object FriendlyAnnoParams { - case class Full(values: List[(String, FriendlyAnnotationValue)]) extends FriendlyAnnoParams - case class Values(values: List[FriendlyAnnotationValue]) extends FriendlyAnnoParams +} +case class FriendlyAnnotation(fqn: String, params: FriendlyAnnoParams) +sealed trait FriendlyAnnotationValue +object FriendlyAnnotationValue { + case class StringValue(value: String) extends FriendlyAnnotationValue + case class IntValue(value: Int) extends FriendlyAnnotationValue + case class LongValue(value: Long) extends FriendlyAnnotationValue + case class UnsetValue() extends FriendlyAnnotationValue + case class UnknownConst(value: Any) extends FriendlyAnnotationValue + case class Unknown() extends FriendlyAnnotationValue +} - } - case class FriendlyAnnotation(fqn: String, params: FriendlyAnnoParams) - sealed trait FriendlyAnnotationValue - object FriendlyAnnotation { - case class StringValue(value: String) extends FriendlyAnnotationValue - case class IntValue(value: Int) extends FriendlyAnnotationValue - case class LongValue(value: Long) extends FriendlyAnnotationValue - case class UnknownConst(value: Any) extends FriendlyAnnotationValue - case class Unknown() extends FriendlyAnnotationValue - } +trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => + private def convertConst(c: Any) = { + c match { + case v: String => + FriendlyAnnotationValue.StringValue(v) + case v: Int => + FriendlyAnnotationValue.IntValue(v) + case v: Long => + FriendlyAnnotationValue.LongValue(v) + case v => + FriendlyAnnotationValue.UnknownConst(v) + } + } def makeFriendly(anno: u.Annotation): FriendlyAnnotation = { import u.* @@ -29,47 +46,60 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => // println(tag) val annoName = tpe.typeSymbol.fullName val paramTrees = anno.tree.children.tail - val values = paramTrees.map { - p => - (p: @unchecked) match { - case Literal(Constant(c)) => - c match { - case v: String => - FriendlyAnnotation.StringValue(v) - case v: Int => - FriendlyAnnotation.IntValue(v) - case v: Long => - FriendlyAnnotation.LongValue(v) - case v => - FriendlyAnnotation.UnknownConst(v) - } - case _ => - FriendlyAnnotation.Unknown() - } - } - val constructor = rp.selectConstructorMethod(tpe.asInstanceOf[rp.u.TypeNative]) - -// println((anno, u.showRaw(anno.tree.children.head))) - println(tpe) - val avals = constructor match { - case Some(c) => - c.paramLists match { - case params :: Nil => - val names = params.map(_.name.decodedName.toString) - assert(names.size == values.size) - FriendlyAnnoParams.Full(names.zip(values)) - case _ => - FriendlyAnnoParams.Values(values) - } - case _ => - FriendlyAnnoParams.Values(values) + val avals = if (tpe.typeSymbol.isJavaAnnotation) { + val pairs = paramTrees.map { + p => + (p: @unchecked) match { + case NamedArg(Ident(TermName(name)), Literal(Constant(c))) => + (Some(name), convertConst(c)) + case a => + (None, FriendlyAnnotationValue.UnknownConst(s"$a ${u.showRaw(a)}")) + } + } + + val names = pairs.map(_._1).collect { case Some(name) => name } + val values = pairs.map(_._2) + assert(names.size >= values.size, s"Java annotation structure disbalance: names=$names values=$values") + FriendlyAnnoParams.Full(names.zip(values ++ List.fill(names.size - values.size)(FriendlyAnnotationValue.UnsetValue()))) + } else { + val values = paramTrees.map { + p => + (p: @unchecked) match { + case Literal(Constant(c)) => + convertConst(c) + case a => + FriendlyAnnotationValue.UnknownConst(s"$a ${u.showRaw(a)}") + } + } + val constructor = rp.selectConstructorMethod(tpe.asInstanceOf[rp.u.TypeNative]) + constructor match { + case Some(c) => + c.paramLists match { + case params :: Nil => + val names = params.map(_.name.decodedName.toString) + assert(names.size >= values.size, s"Annotation structure disbalance: names=$names values=$values") + FriendlyAnnoParams.Full(names.zip(values ++ List.fill(names.size - values.size)(FriendlyAnnotationValue.UnsetValue()))) + case _ => + FriendlyAnnoParams.Values(values) + } + + case _ => + FriendlyAnnoParams.Values(values) + } } FriendlyAnnotation(annoName, avals) } - sealed trait MacroSymbolInfo { + sealed trait MacroSymbolInfoCompact { + def name: String + def isByName: Boolean + def wasGeneric: Boolean + def friendlyAnnotations: List[FriendlyAnnotation] + } + + sealed trait MacroSymbolInfo extends MacroSymbolInfoCompact { def name: String def finalResultType: TypeNative final def nonByNameFinalResultType: TypeNative = if (isByName) ReflectionUtil.stripByName(u: u.type)(finalResultType) else finalResultType @@ -78,6 +108,7 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => def wasGeneric: Boolean def annotations: List[u.Annotation] + def friendlyAnnotations: List[FriendlyAnnotation] def withTpe(tpe: TypeNative): MacroSymbolInfo def withIsByName(boolean: Boolean): MacroSymbolInfo @@ -99,6 +130,7 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => isByName: Boolean, wasGeneric: Boolean, annotations: List[u.Annotation], + friendlyAnnotations: List[FriendlyAnnotation], ) extends MacroSymbolInfo { override final val name: String = underlying.name.toTermName.toString override final def withTpe(tpe: TypeNative): MacroSymbolInfo = copy(finalResultType = tpe) @@ -107,28 +139,37 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => } private[distage] object Runtime { - def apply(underlying: SymbNative, definingClass: TypeNative, wasGeneric: Boolean, moreAnnotations: List[u.Annotation] = Nil): Runtime = { + def apply( + underlying: SymbNative, + definingClass: TypeNative, + wasGeneric: Boolean, + moreAnnotations: List[u.Annotation] = Nil, + ): Runtime = { val tpeIn = underlying .typeSignatureIn(definingClass) .asSeenFrom(definingClass, definingClass.typeSymbol) + val annos = (AnnotationTools.getAllAnnotations(u: u.type)(underlying) ++ moreAnnotations).distinct new Runtime( underlying = underlying, typeSignatureInDefiningClass = tpeIn, finalResultType = tpeIn.finalResultType, isByName = underlying.isTerm && underlying.asTerm.isByNameParam, wasGeneric = wasGeneric, - annotations = (AnnotationTools.getAllAnnotations(u: u.type)(underlying) ++ moreAnnotations).distinct, + annotations = annos, + friendlyAnnotations = annos.map(makeFriendly), ) } def apply(underlying: SymbNative): Runtime = { + val annos = AnnotationTools.getAllAnnotations(u: u.type)(underlying).distinct new Runtime( underlying = underlying, typeSignatureInDefiningClass = underlying.typeSignature, finalResultType = underlying.typeSignature, isByName = (underlying.isTerm && underlying.asTerm.isByNameParam) || ReflectionUtil.isByName(u)(underlying.typeSignature), wasGeneric = underlying.typeSignature.typeSymbol.isParameter, - annotations = AnnotationTools.getAllAnnotations(u: u.type)(underlying).distinct, + annotations = annos, + friendlyAnnotations = annos.map(makeFriendly), ) } } @@ -137,6 +178,7 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => name: String, finalResultType: TypeNative, annotations: List[u.Annotation], + friendlyAnnotations: List[FriendlyAnnotation], isByName: Boolean, wasGeneric: Boolean, ) extends MacroSymbolInfo { @@ -146,10 +188,12 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => } object Static { def syntheticFromType(transformName: String => String)(tpe: TypeNative): MacroSymbolInfo.Static = { + val annos = AnnotationTools.getAllTypeAnnotations(u)(tpe) MacroSymbolInfo.Static( name = transformName(tpe.typeSymbol.name.toString), finalResultType = tpe, - annotations = AnnotationTools.getAllTypeAnnotations(u)(tpe), + annotations = annos, + friendlyAnnotations = annos.map(makeFriendly), isByName = tpe.typeSymbol.isClass && tpe.typeSymbol.asClass == u.definitions.ByNameParamClass, wasGeneric = tpe.typeSymbol.isParameter, ) @@ -157,6 +201,15 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => } implicit final class SymbolInfoExtensions(symbolInfo: MacroSymbolInfo) { + def findUniqueFriendlyAnno(p: FriendlyAnnotation => Boolean): Option[FriendlyAnnotation] = { + val annos = symbolInfo.friendlyAnnotations.filter(p) + if (annos.size > 1) { + import izumi.fundamentals.platform.strings.IzString.* + throw new AnnotationConflictException(s"Multiple DI annotations on symbol `$symbolInfo` in ${symbolInfo.finalResultType}: ${annos.niceList()}") + } + annos.headOption + } + def findUniqueAnnotation(annType: TypeNative): Option[u.Annotation] = { val distageAnnos = symbolInfo.annotations.filter(t => t.tree.tpe <:< typeOfDistageAnnotation).toSet @@ -170,10 +223,6 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => private[this] def findAnnotation(tgtAnnType: TypeNative): Option[u.Annotation] = { val r = symbolInfo.annotations.find(a => AnnotationTools.annotationTypeEq(u)(tgtAnnType, a)) - r.foreach { - a => - println(makeFriendly(a)) - } r } } From 4fdd5b2bd3ae3d2bf9d2a2a1d3e1976ca5104d2c Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 27 May 2024 17:09:46 +0100 Subject: [PATCH 16/59] wip --- .../reflection/macros/FunctoidMacro.scala | 16 +++++++++------- .../macros/universe/DIUniverseLiftables.scala | 6 ++++++ .../macros/universe/impl/WithDISymbolInfo.scala | 3 +++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index dd2a492b58..2b5af708b1 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -22,7 +22,7 @@ import scala.reflect.macros.blackbox */ class FunctoidMacro(val c: blackbox.Context) { final val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) - type Parameter = macroUniverse.Association.Parameter + type Parameter = macroUniverse.Association.CompactParameter private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) private final val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) @@ -37,7 +37,7 @@ class FunctoidMacro(val c: blackbox.Context) { s"""DIKeyWrappedFunction info: | Symbol: ${fun.symbol}\n | IsMethodSymbol: ${Option(fun.symbol).exists(_.isMethod)}\n - | Extracted Annotations: ${associations.flatMap(_.symbol.annotations)}\n + | Extracted Annotations: ${associations.flatMap(_.symbol.friendlyAnnotations)}\n | Extracted DIKeys: ${associations.map(_.key)}\n | argument: ${showCode(fun)}\n | argumentTree: ${showRaw(fun)}\n @@ -80,13 +80,15 @@ class FunctoidMacro(val c: blackbox.Context) { def generateProvider[R: c.WeakTypeTag](parameters: List[Parameter], fun: Tree): c.Expr[Functoid[R]] = { val tools = DIUniverseLiftables(macroUniverse) - import tools.{liftTypeToSafeType, liftableParameter} + import tools.{liftTypeToSafeType, liftableCompactParameter} val seqName = if (parameters.nonEmpty) TermName(c.freshName("seqAny")) else TermName("_") val casts = parameters.indices.map(i => q"$seqName($i)") val parametersNoByName = Liftable.liftList[Parameter].apply(parameters) +// val parametersNoByName = q"???" + c.Expr[Functoid[R]] { q"""{ val fun = $fun @@ -106,7 +108,7 @@ class FunctoidMacro(val c: blackbox.Context) { protected[this] def analyzeMethodRef(lambdaArgs: List[Symbol], body: Tree): List[Parameter] = { def association(p: Symbol): Parameter = { - reflectionProvider.parameterToAssociation(macroUniverse.MacroSymbolInfo.Runtime(p)) + reflectionProvider.parameterToAssociation2(macroUniverse.MacroSymbolInfo.Runtime(p)) } val lambdaParams = lambdaArgs.map(association) @@ -128,7 +130,7 @@ class FunctoidMacro(val c: blackbox.Context) { val annotationsOnMethodAreNonEmptyAndASuperset: Boolean = { import scala.collection.compat._ methodReferenceParams.sizeCompare(lambdaParams) == 0 && - methodReferenceParams.exists(_.symbol.annotations.nonEmpty) + methodReferenceParams.exists(_.symbol.friendlyAnnotations.nonEmpty) } // // this is somewhat superfluous since normally lambda parameters can't be annotated in source code at all @@ -156,7 +158,7 @@ class FunctoidMacro(val c: blackbox.Context) { methodReferenceParams.zip(lambdaParams).map { case (mArg, lArg) => mArg.copy( - symbol = lArg.symbol.withAnnotations(mArg.symbol.annotations), + symbol = lArg.symbol.withFriendlyAnnotations(mArg.symbol.friendlyAnnotations), key = mArg.key.withTpe(lArg.stpe), ) } @@ -189,7 +191,7 @@ class FunctoidMacro(val c: blackbox.Context) { widenFunctionObject(sig).typeArgs.init.map { tpe => val symbol = macroUniverse.MacroSymbolInfo.Static.syntheticFromType(c.freshName)(tpe) - reflectionProvider.parameterToAssociation(symbol) + reflectionProvider.parameterToAssociation2(symbol) } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index 6aa3d884df..6ad077c709 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -57,6 +57,12 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { q"new $modelReflectionPkg.LinkedParameter($symbol, $key)" } + implicit val liftableCompactParameter: Liftable[Association.CompactParameter] = { + case Association.CompactParameter(symbol, _, key) => + // TODO: XXX + q"new $modelReflectionPkg.LinkedParameter(${symbol.asInstanceOf[MacroSymbolInfo]}, $key)" +// q"new $modelReflectionPkg.CompactParameter(${symbol.asInstanceOf[MacroSymbolInfo]}, $stpe, $key)" + } } object DIUniverseLiftables { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index e9af32f405..212dd7625f 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -97,6 +97,7 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => def isByName: Boolean def wasGeneric: Boolean def friendlyAnnotations: List[FriendlyAnnotation] + def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact } sealed trait MacroSymbolInfo extends MacroSymbolInfoCompact { @@ -136,6 +137,7 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => override final def withTpe(tpe: TypeNative): MacroSymbolInfo = copy(finalResultType = tpe) override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) + override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) } private[distage] object Runtime { @@ -185,6 +187,7 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => override final def withTpe(tpe: TypeNative): MacroSymbolInfo = copy(finalResultType = tpe) override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) + override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) } object Static { def syntheticFromType(transformName: String => String)(tpe: TypeNative): MacroSymbolInfo.Static = { From 63b823236dff126507f2f59e3e15b61a8250a88f Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 29 May 2024 16:58:00 +0100 Subject: [PATCH 17/59] wip --- .../reflection/macros/FunctoidMacro.scala | 7 ++-- .../universe/impl/FriendlyAnnotation.scala | 32 +++++++++++++++++++ .../universe/impl/WithDISymbolInfo.scala | 29 ----------------- 3 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnotation.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 2b5af708b1..15a4f2ad97 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -21,12 +21,13 @@ import scala.reflect.macros.blackbox * @see [[izumi.distage.constructors.DebugProperties]] */ class FunctoidMacro(val c: blackbox.Context) { - final val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) - type Parameter = macroUniverse.Association.CompactParameter - private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) + + protected final val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) private final val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) + type Parameter = macroUniverse.Association.CompactParameter + import c.universe.* def impl[R: c.WeakTypeTag](fun: Tree): c.Expr[Functoid[R]] = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnotation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnotation.scala new file mode 100644 index 0000000000..2613219430 --- /dev/null +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnotation.scala @@ -0,0 +1,32 @@ +package izumi.distage.reflection.macros.universe.impl + +case class FriendlyAnnotation(fqn: String, params: FriendlyAnnoParams) + +sealed trait FriendlyAnnoParams { + def values: List[FriendlyAnnotationValue] +} +object FriendlyAnnoParams { + case class Full(named: List[(String, FriendlyAnnotationValue)]) extends FriendlyAnnoParams { + override def values: List[FriendlyAnnotationValue] = named.map(_._2) + } + case class Values(values: List[FriendlyAnnotationValue]) extends FriendlyAnnoParams + +} + +sealed trait FriendlyAnnotationValue +object FriendlyAnnotationValue { + case class StringValue(value: String) extends FriendlyAnnotationValue + case class IntValue(value: Int) extends FriendlyAnnotationValue + case class LongValue(value: Long) extends FriendlyAnnotationValue + case class UnsetValue() extends FriendlyAnnotationValue + case class UnknownConst(value: Any) extends FriendlyAnnotationValue + case class Unknown() extends FriendlyAnnotationValue +} + +trait MacroSymbolInfoCompact { + def name: String + def isByName: Boolean + def wasGeneric: Boolean + def friendlyAnnotations: List[FriendlyAnnotation] + def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index 212dd7625f..b1d778e179 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -3,27 +3,6 @@ package izumi.distage.reflection.macros.universe.impl import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} -sealed trait FriendlyAnnoParams { - def values: List[FriendlyAnnotationValue] -} -object FriendlyAnnoParams { - case class Full(named: List[(String, FriendlyAnnotationValue)]) extends FriendlyAnnoParams { - override def values: List[FriendlyAnnotationValue] = named.map(_._2) - } - case class Values(values: List[FriendlyAnnotationValue]) extends FriendlyAnnoParams - -} -case class FriendlyAnnotation(fqn: String, params: FriendlyAnnoParams) -sealed trait FriendlyAnnotationValue -object FriendlyAnnotationValue { - case class StringValue(value: String) extends FriendlyAnnotationValue - case class IntValue(value: Int) extends FriendlyAnnotationValue - case class LongValue(value: Long) extends FriendlyAnnotationValue - case class UnsetValue() extends FriendlyAnnotationValue - case class UnknownConst(value: Any) extends FriendlyAnnotationValue - case class Unknown() extends FriendlyAnnotationValue -} - trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => private def convertConst(c: Any) = { @@ -92,14 +71,6 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => FriendlyAnnotation(annoName, avals) } - sealed trait MacroSymbolInfoCompact { - def name: String - def isByName: Boolean - def wasGeneric: Boolean - def friendlyAnnotations: List[FriendlyAnnotation] - def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact - } - sealed trait MacroSymbolInfo extends MacroSymbolInfoCompact { def name: String def finalResultType: TypeNative From 7ba1936cc2219c569dc5238305f4d01f8de5da5b Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 29 May 2024 17:32:20 +0100 Subject: [PATCH 18/59] wip --- .../reflection/macros/FunctoidMacro.scala | 27 ++++++++++--------- .../macros/universe/DIUniverseLiftables.scala | 22 ++++++++------- .../ReflectionProviderDefaultImpl.scala | 24 ++++++++--------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 15a4f2ad97..dc7e9b9338 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -21,14 +21,22 @@ import scala.reflect.macros.blackbox * @see [[izumi.distage.constructors.DebugProperties]] */ class FunctoidMacro(val c: blackbox.Context) { + import c.universe.* + private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) protected final val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) - private final val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) - type Parameter = macroUniverse.Association.CompactParameter - import c.universe.* + private final val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) + + private def symbolToParam(p: Symbol): Parameter = { + reflectionProvider.parameterToAssociation2(macroUniverse.MacroSymbolInfo.Runtime(p)) + } + private def typeToParam(tpe: Type): Parameter = { + val symbol = macroUniverse.MacroSymbolInfo.Static.syntheticFromType(c.freshName)(tpe) + reflectionProvider.parameterToAssociation2(symbol) + } def impl[R: c.WeakTypeTag](fun: Tree): c.Expr[Functoid[R]] = { val associations = analyze(fun, weakTypeOf[R]) @@ -108,16 +116,13 @@ class FunctoidMacro(val c: blackbox.Context) { } protected[this] def analyzeMethodRef(lambdaArgs: List[Symbol], body: Tree): List[Parameter] = { - def association(p: Symbol): Parameter = { - reflectionProvider.parameterToAssociation2(macroUniverse.MacroSymbolInfo.Runtime(p)) - } - val lambdaParams = lambdaArgs.map(association) + val lambdaParams = lambdaArgs.map(symbolToParam) val methodReferenceParams = body match { case Apply(f, args) if args.map(_.symbol) == lambdaArgs => logger.log(s"Matched function body as a method reference - consists of a single call to a function $f with the same arguments as lambda- ${showRaw(body)}") - extractMethodReferenceParams(f.symbol).map(association) + extractMethodReferenceParams(f.symbol).map(symbolToParam) case _ => logger.log(s"Function body didn't match as a variable or a method reference - ${showRaw(body)}") @@ -189,11 +194,7 @@ class FunctoidMacro(val c: blackbox.Context) { } protected[this] def analyzeValRef(sig: Type): List[Parameter] = { - widenFunctionObject(sig).typeArgs.init.map { - tpe => - val symbol = macroUniverse.MacroSymbolInfo.Static.syntheticFromType(c.freshName)(tpe) - reflectionProvider.parameterToAssociation2(symbol) - } + widenFunctionObject(sig).typeArgs.init.map(typeToParam) } protected[this] def widenFunctionObject(sig: Type): Type = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index 6ad077c709..7367be488f 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -11,18 +11,21 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { q"{ $modelReflectionPkg.SafeType.get[${Liftable.liftType(tpe)}] }" } - // DIKey + def liftMacroTypeToSafeType(tpe: MacroSafeType): Tree = { + liftTypeToSafeType(tpe.typeNative) + } + // DIKey protected[this] implicit val liftableTypeKey: Liftable[MacroDIKey.TypeKey] = { case MacroDIKey.TypeKey(tpe) => q""" - { new $modelReflectionPkg.DIKey.TypeKey(${liftTypeToSafeType(tpe.typeNative)}) } + { new $modelReflectionPkg.DIKey.TypeKey(${liftMacroTypeToSafeType(tpe)}) } """ } protected[this] implicit val liftableIdKey: Liftable[MacroDIKey.IdKey[?]] = { case idKey: MacroDIKey.IdKey[?] => val lifted = idKey.idContract.liftable(idKey.id) - q"""{ new $modelReflectionPkg.DIKey.IdKey(${liftTypeToSafeType(idKey.tpe.typeNative)}, $lifted) }""" + q"""{ new $modelReflectionPkg.DIKey.IdKey(${liftMacroTypeToSafeType(idKey.tpe)}, $lifted) }""" } protected[this] implicit val liftableBasicDIKey: Liftable[MacroDIKey.BasicKey] = { @@ -39,9 +42,8 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { // types must all be resolved anyway - they cannot contain polymorphic // components, unlike general method symbols (info for which we don't generate). // (annotations always empty currently) - protected[this] implicit val liftableSymbolInfo: Liftable[MacroSymbolInfo] = { - info => - q"""{ $modelReflectionPkg.SymbolInfo( + protected[this] def lifSymbolInfo(info: MacroSymbolInfo): Tree = { + q"""{ $modelReflectionPkg.SymbolInfo( name = ${info.name}, finalResultType = ${liftTypeToSafeType(info.nonByNameFinalResultType)}, isByName = ${info.isByName}, @@ -54,14 +56,14 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { // converts Association.Parameter to LinkedParameter implicit val liftableParameter: Liftable[Association.Parameter] = { case Association.Parameter(symbol, _, key) => - q"new $modelReflectionPkg.LinkedParameter($symbol, $key)" + val symTree = lifSymbolInfo(symbol) + q"new $modelReflectionPkg.LinkedParameter($symTree, $key)" } implicit val liftableCompactParameter: Liftable[Association.CompactParameter] = { case Association.CompactParameter(symbol, _, key) => - // TODO: XXX - q"new $modelReflectionPkg.LinkedParameter(${symbol.asInstanceOf[MacroSymbolInfo]}, $key)" -// q"new $modelReflectionPkg.CompactParameter(${symbol.asInstanceOf[MacroSymbolInfo]}, $stpe, $key)" + val symTree = lifSymbolInfo(symbol.asInstanceOf[MacroSymbolInfo]) + q"new $modelReflectionPkg.LinkedParameter($symTree, $key)" } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index 2941780880..bdff978d2e 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -84,6 +84,18 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } private[this] def mkConstructorWiring(factoryMethod: SymbNative, tpe: TypeNative): MacroWiring.MacroSingletonWiring = { + def getPrefix(tpe: TypeNative): Option[MacroDIKey] = { + if (tpe.typeSymbol.isStatic) { + None + } else { + val typeRef = ReflectionUtil.toTypeRef[u.u.type](tpe) + typeRef + .map(_.pre) + .filterNot(m => m.termSymbol.isModule && m.termSymbol.isStatic) + .map(v => MacroDIKey.TypeKey(MacroSafeType.create(v))) + } + } + tpe match { case ConcreteSymbol(t) => MacroWiring.MacroSingletonWiring.Class(t, constructorParameterLists(t), getPrefix(t)) @@ -117,18 +129,6 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } } - private[this] def getPrefix(tpe: TypeNative): Option[MacroDIKey] = { - if (tpe.typeSymbol.isStatic) { - None - } else { - val typeRef = ReflectionUtil.toTypeRef[u.u.type](tpe) - typeRef - .map(_.pre) - .filterNot(m => m.termSymbol.isModule && m.termSymbol.isStatic) - .map(v => MacroDIKey.TypeKey(MacroSafeType.create(v))) - } - } - private[this] def resultOfFactoryMethod(symbolInfo: MacroSymbolInfo): TypeNative = { symbolInfo.findUniqueAnnotation(typeOfWithAnnotation) match { case Some(With(tpe)) => From 2067e9661a05aa0c1e5afe801dac1ba57b7b11bb Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 29 May 2024 19:56:33 +0100 Subject: [PATCH 19/59] wip --- .../model/definition/dsl/LifecycleTagMacro.scala | 2 +- .../distage/reflection/macros/FunctoidMacro.scala | 9 +++++---- .../macros/universe/DIUniverseLiftables.scala | 3 ++- .../reflection/macros/universe/StaticDIUniverse.scala | 1 + .../macros/universe/impl/DIUniverseBase.scala | 2 ++ .../macros/universe/impl/WithDISafeType.scala | 11 +++++++++-- .../macros/universe/impl/WithDISymbolInfo.scala | 4 +++- project/Versions.scala | 2 +- 8 files changed, 24 insertions(+), 10 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/LifecycleTagMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/LifecycleTagMacro.scala index 166d41714a..d40f52c35b 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/LifecycleTagMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/LifecycleTagMacro.scala @@ -8,7 +8,7 @@ import scala.reflect.macros.blackbox object LifecycleTagMacro { def fakeResourceTagMacroIntellijWorkaroundImpl[R <: Lifecycle[Any, Any]: c.WeakTypeTag](c: blackbox.Context): c.Expr[Nothing] = { val tagMacro = new TagMacro(c) - tagMacro.makeTagImpl[R] // run the macro AGAIN, to get a fresh error message + val _ = tagMacro.makeWeakTag[R] // run the macro AGAIN, to get a fresh error message val tagTrace = tagMacro.getImplicitError() c.abort(c.enclosingPosition, s"could not find implicit ResourceTag for ${c.universe.weakTypeOf[R]}!\n$tagTrace") diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index dc7e9b9338..f2c17bb406 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -89,14 +89,15 @@ class FunctoidMacro(val c: blackbox.Context) { def generateProvider[R: c.WeakTypeTag](parameters: List[Parameter], fun: Tree): c.Expr[Functoid[R]] = { val tools = DIUniverseLiftables(macroUniverse) - import tools.{liftTypeToSafeType, liftableCompactParameter} + import tools.liftableCompactParameter val seqName = if (parameters.nonEmpty) TermName(c.freshName("seqAny")) else TermName("_") val casts = parameters.indices.map(i => q"$seqName($i)") val parametersNoByName = Liftable.liftList[Parameter].apply(parameters) -// val parametersNoByName = q"???" + val retTpe = weakTypeOf[R] + val retTagTree = macroUniverse.MacroSafeType.create(retTpe).tagTree.asInstanceOf[c.Tree] c.Expr[Functoid[R]] { q"""{ @@ -105,7 +106,7 @@ class FunctoidMacro(val c: blackbox.Context) { new ${weakTypeOf[Functoid[R]]}( new ${weakTypeOf[Provider.ProviderImpl[R]]}( $parametersNoByName, - ${liftTypeToSafeType(weakTypeOf[R])}, + $retTagTree, fun, { ($seqName: _root_.scala.Seq[_root_.scala.Any]) => fun.asInstanceOf[(..${casts.map(_ => definitions.AnyTpe)}) => ${definitions.AnyTpe}](..$casts) }, ${symbolOf[ProviderType.Function.type].asClass.module}, @@ -134,7 +135,7 @@ class FunctoidMacro(val c: blackbox.Context) { @nowarn("msg=Unused import") val annotationsOnMethodAreNonEmptyAndASuperset: Boolean = { - import scala.collection.compat._ + import scala.collection.compat.* methodReferenceParams.sizeCompare(lambdaParams) == 0 && methodReferenceParams.exists(_.symbol.friendlyAnnotations.nonEmpty) } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index 7367be488f..f08a759383 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -8,11 +8,12 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { protected[this] val modelReflectionPkg: Tree = q"_root_.izumi.distage.model.reflection" def liftTypeToSafeType(tpe: TypeNative): Tree = { + q"{ $modelReflectionPkg.SafeType.get[${Liftable.liftType(tpe)}] }" } def liftMacroTypeToSafeType(tpe: MacroSafeType): Tree = { - liftTypeToSafeType(tpe.typeNative) + tpe.tagTree.asInstanceOf[Tree] } // DIKey diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala index 23d4ffa4f9..b3bdff9ddf 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala @@ -21,6 +21,7 @@ object StaticDIUniverse { type Aux[U] = StaticDIUniverse { val u: U } def apply(c: blackbox.Context): StaticDIUniverse.Aux[c.universe.type] = { new StaticDIUniverse { self => + override val ctx: blackbox.Context = c override val u: c.universe.type = c.universe override protected val typeOfDistageAnnotation: TypeNative = u.typeOf[DIStageAnnotation] override implicit val stringIdContract: MacroIdContract[String] = new IdContractImpl[String] diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala index d121d07b3f..6f7d370115 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala @@ -3,8 +3,10 @@ package izumi.distage.reflection.macros.universe.impl import izumi.distage.reflection.macros.universe.ReflectionProvider import scala.reflect.api.Universe +import scala.reflect.macros.blackbox trait DIUniverseBase { + val ctx: blackbox.Context val u: Universe val rp: ReflectionProvider diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala index fec9973f30..c5a9e857e9 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala @@ -5,7 +5,8 @@ import izumi.reflect.macrortti.{LightTypeTag, LightTypeTagImpl} private[distage] trait WithDISafeType { this: DIUniverseBase => class MacroSafeType private ( - private[reflection] val typeNative: TypeNative, +// private[reflection] val typeNative: TypeNative, + private[reflection] val tagTree: ctx.Tree, private[MacroSafeType] val tag: LightTypeTag, ) { @@ -28,8 +29,14 @@ private[distage] trait WithDISafeType { this: DIUniverseBase => } object MacroSafeType { + import ctx.universe.* + protected[this] val modelReflectionPkg: ctx.Tree = q"_root_.izumi.distage.model.reflection" + def create(tpe: TypeNative): MacroSafeType = { - new MacroSafeType(tpe, LightTypeTagImpl.makeLightTypeTag(u)(tpe)) + val ltt = LightTypeTagImpl.makeLightTypeTag(u)(tpe) + val tagTree = q"{ $modelReflectionPkg.SafeType.get[${Liftable.liftType(tpe.asInstanceOf[ctx.Type])}] }" + + new MacroSafeType(tagTree, ltt) } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index b1d778e179..27a875fb36 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -74,7 +74,9 @@ trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => sealed trait MacroSymbolInfo extends MacroSymbolInfoCompact { def name: String def finalResultType: TypeNative - final def nonByNameFinalResultType: TypeNative = if (isByName) ReflectionUtil.stripByName(u: u.type)(finalResultType) else finalResultType + final def nonByNameFinalResultType: TypeNative = { + if (isByName) ReflectionUtil.stripByName(u: u.type)(finalResultType) else finalResultType + } def isByName: Boolean def wasGeneric: Boolean diff --git a/project/Versions.scala b/project/Versions.scala index acc25d3678..0ff6f0ad1b 100644 --- a/project/Versions.scala +++ b/project/Versions.scala @@ -1,6 +1,6 @@ object V { // izumi - val izumi_reflect = "2.3.9" + val izumi_reflect = "2.3.10-SNAPSHOT" // foundation val collection_compat = "2.12.0" From 89efa9f1fb761c4ac2021d0e276549c5bc5d0dc3 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 29 May 2024 20:37:28 +0100 Subject: [PATCH 20/59] wip --- .../UnsupportedWiringException.scala | 4 +- .../reflection/macros/FunctoidMacro.scala | 3 +- .../constructors/ConstructorMacros.scala | 8 +++- .../macros/universe/DIUniverseLiftables.scala | 11 ++--- .../ReflectionProviderDefaultImpl.scala | 14 +++--- .../macros/universe/impl/DIUniverse.scala | 2 +- .../macros/universe/impl/MacroSafeType.scala | 40 +++++++++++++++++ .../universe/impl/WithDIAssociation.scala | 3 +- .../macros/universe/impl/WithDIKey.scala | 2 +- .../macros/universe/impl/WithDISafeType.scala | 43 ------------------- .../universe/impl/WithDISymbolInfo.scala | 2 +- .../macros/universe/impl/WithDIWiring.scala | 10 +++-- 12 files changed, 75 insertions(+), 67 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/MacroSafeType.scala delete mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala index 20c86963f6..e249ec9f27 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala @@ -1,6 +1,6 @@ package izumi.distage.model.exceptions.reflection import izumi.distage.model.exceptions.DIException -import izumi.distage.reflection.macros.universe.impl.DIUniverse +import izumi.distage.reflection.macros.universe.impl.MacroSafeType -class UnsupportedWiringException(message: String, val tpe: DIUniverse#MacroSafeType) extends DIException(message) +class UnsupportedWiringException(message: String, val tpe: MacroSafeType) extends DIException(message) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index f2c17bb406..7e56540006 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -5,6 +5,7 @@ import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.reflection.macros.universe.StaticDIUniverse.Aux +import izumi.distage.reflection.macros.universe.impl.MacroSafeType import izumi.distage.reflection.macros.universe.{DIUniverseLiftables, ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.TrivialMacroLogger @@ -97,7 +98,7 @@ class FunctoidMacro(val c: blackbox.Context) { val parametersNoByName = Liftable.liftList[Parameter].apply(parameters) val retTpe = weakTypeOf[R] - val retTagTree = macroUniverse.MacroSafeType.create(retTpe).tagTree.asInstanceOf[c.Tree] + val retTagTree = MacroSafeType.create(c)(retTpe).tagTree.asInstanceOf[c.Tree] c.Expr[Functoid[R]] { q"""{ diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala index 437812399b..c9b47fbe46 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala @@ -3,6 +3,7 @@ package izumi.distage.reflection.macros.constructors import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType +import izumi.distage.reflection.macros.universe.impl.MacroSafeType import izumi.distage.reflection.macros.universe.{DIUniverseLiftables, ReflectionProvider, StaticDIUniverse} import izumi.fundamentals.reflection.ReflectionUtil @@ -291,7 +292,7 @@ abstract class ConstructorMacrosBase { )(fun: List[List[Tree]] => Tree ): c.Expr[Functoid[T]] = { val tools = DIUniverseLiftables(u) - import tools.{liftTypeToSafeType, liftableParameter} + import tools.liftableParameter val seqName = if (parameters.exists(_.nonEmpty)) TermName(c.freshName("seqAny")) else TermName("_") @@ -310,12 +311,15 @@ abstract class ConstructorMacrosBase { }) } + val retTpe = weakTypeOf[T] + val retTagTree = MacroSafeType.create(c)(retTpe).tagTree.asInstanceOf[c.Tree] + c.Expr[Functoid[T]] { q"""{ new ${weakTypeOf[Functoid[T]]}( new ${weakTypeOf[Provider.ProviderImpl[T]]}( ${Liftable.liftList.apply(parameters.flatten)}, - ${liftTypeToSafeType(weakTypeOf[T])}, + $retTagTree, { ($seqName: _root_.scala.Seq[_root_.scala.Any]) => ${fun(casts)}: ${weakTypeOf[T]} }, ${symbolOf[P].asClass.module}, ) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index f08a759383..03030cd2a7 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -1,5 +1,7 @@ package izumi.distage.reflection.macros.universe +import izumi.distage.reflection.macros.universe.impl.MacroSafeType + class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { import u.* @@ -7,15 +9,14 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { protected[this] val modelReflectionPkg: Tree = q"_root_.izumi.distage.model.reflection" - def liftTypeToSafeType(tpe: TypeNative): Tree = { - - q"{ $modelReflectionPkg.SafeType.get[${Liftable.liftType(tpe)}] }" - } - def liftMacroTypeToSafeType(tpe: MacroSafeType): Tree = { tpe.tagTree.asInstanceOf[Tree] } + private def liftTypeToSafeType(tpe: TypeNative): Tree = { + q"{ $modelReflectionPkg.SafeType.get[${Liftable.liftType(tpe)}] }" + } + // DIKey protected[this] implicit val liftableTypeKey: Liftable[MacroDIKey.TypeKey] = { case MacroDIKey.TypeKey(tpe) => q""" diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index bdff978d2e..ea61f95e5b 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -11,8 +11,10 @@ import scala.annotation.nowarn @nowarn("msg=outer reference") trait ReflectionProviderDefaultImpl extends ReflectionProvider { + + import izumi.distage.reflection.macros.universe.impl.MacroSafeType import u.u.Annotation - import u.{Association, MacroDIKey, MacroSafeType, MacroSymbolInfo, MacroWiring, MethodSymbNative, SymbNative, TypeNative, stringIdContract} + import u.{Association, MacroDIKey, MacroSymbolInfo, MacroWiring, MethodSymbNative, SymbNative, TypeNative, stringIdContract} private[this] object With { def unapply(ann: Annotation): Option[TypeNative] = { @@ -92,7 +94,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { typeRef .map(_.pre) .filterNot(m => m.termSymbol.isModule && m.termSymbol.isStatic) - .map(v => MacroDIKey.TypeKey(MacroSafeType.create(v))) + .map(v => MacroDIKey.TypeKey(MacroSafeType.create(u.ctx)(v.asInstanceOf[u.ctx.Type]))) } } @@ -115,11 +117,11 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { | | * $mms |""".stripMargin, - MacroSafeType.create(tpe), + MacroSafeType.create(u.ctx)(tpe.asInstanceOf[u.ctx.Type]), ) case _ => - val safeType = MacroSafeType.create(tpe) + val safeType = MacroSafeType.create(u.ctx)(tpe.asInstanceOf[u.ctx.Type]) val factoryMsg = if (factoryMethod != u.u.NoSymbol) { s""" | * When trying to create an implementation for result of `$factoryMethod` of factory `${factoryMethod.owner}` @@ -194,13 +196,13 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { Association.AbstractMethod(methodSymb, tpeFromSymbol(methodSymb), keyFromSymbol(methodSymb)) } - private[this] def tpeFromSymbol(parameterSymbol: MacroSymbolInfo): u.MacroSafeType = { + private[this] def tpeFromSymbol(parameterSymbol: MacroSymbolInfo): MacroSafeType = { val paramType = if (parameterSymbol.isByName) { // this will never be true for a method symbol parameterSymbol.finalResultType.typeArgs.head.finalResultType } else { parameterSymbol.finalResultType } - MacroSafeType.create(paramType) + MacroSafeType.create(u.ctx)(paramType.asInstanceOf[u.ctx.Type]) } private[this] def keyFromSymbol(parameterSymbol: MacroSymbolInfo): MacroDIKey.BasicKey = { val tpe = tpeFromSymbol(parameterSymbol) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala index a677e92803..0f79698606 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala @@ -1,3 +1,3 @@ package izumi.distage.reflection.macros.universe.impl -trait DIUniverse extends DIUniverseBase with WithDISafeType with WithDISymbolInfo with WithDIKey with WithDIAssociation with WithDIWiring +trait DIUniverse extends DIUniverseBase with WithDISymbolInfo with WithDIKey with WithDIAssociation with WithDIWiring diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/MacroSafeType.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/MacroSafeType.scala new file mode 100644 index 0000000000..4d59bb498f --- /dev/null +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/MacroSafeType.scala @@ -0,0 +1,40 @@ +package izumi.distage.reflection.macros.universe.impl + +import izumi.reflect.macrortti.{LightTypeTag, LightTypeTagImpl} + +import scala.reflect.macros.blackbox + +final class MacroSafeType private ( + private[reflection] val tagTree: scala.reflect.api.Universe#Tree, + private val tag: LightTypeTag, +) { + + // hashcode is already cached in the underlying code + @inline override def hashCode: Int = { + tag.hashCode() + } + + @inline override def toString: String = { + tag.repr + } + override def equals(obj: Any): Boolean = { + obj match { + case that: MacroSafeType => + tag =:= that.tag + case _ => + false + } + } +} + +object MacroSafeType { + def create(ctx: blackbox.Context)(tpe: ctx.Type): MacroSafeType = { + import ctx.universe.* + val modelReflectionPkg: ctx.Tree = q"_root_.izumi.distage.model.reflection" + + val ltt = LightTypeTagImpl.makeLightTypeTag(ctx.universe)(tpe) + val tagTree = q"{ $modelReflectionPkg.SafeType.get[${ctx.universe.Liftable.liftType(tpe)}] }" + + new MacroSafeType(tagTree, ltt) + } +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala index 8a2e5d18d4..b8a6f8f9b1 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala @@ -2,7 +2,7 @@ package izumi.distage.reflection.macros.universe.impl import scala.reflect.macros.blackbox -private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISafeType with WithDIKey with WithDISymbolInfo => +private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDIKey with WithDISymbolInfo => sealed trait Association { def symbol: MacroSymbolInfo @@ -36,7 +36,6 @@ private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISafeT object Association { case class CompactParameter(symbol: MacroSymbolInfoCompact, stpe: MacroSafeType, key: MacroDIKey.BasicKey) { final def isByName: Boolean = symbol.isByName - final def asParameter: Association.CompactParameter = this } case class Parameter(symbol: MacroSymbolInfo, stpe: MacroSafeType, key: MacroDIKey.BasicKey) extends Association { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala index 43eacf7132..67fc467ef8 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala @@ -1,6 +1,6 @@ package izumi.distage.reflection.macros.universe.impl -private[distage] trait WithDIKey { this: DIUniverseBase with WithDISafeType => +private[distage] trait WithDIKey { this: DIUniverseBase => sealed trait MacroDIKey { def tpe: MacroSafeType diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala deleted file mode 100644 index c5a9e857e9..0000000000 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISafeType.scala +++ /dev/null @@ -1,43 +0,0 @@ -package izumi.distage.reflection.macros.universe.impl - -import izumi.reflect.macrortti.{LightTypeTag, LightTypeTagImpl} - -private[distage] trait WithDISafeType { this: DIUniverseBase => - - class MacroSafeType private ( -// private[reflection] val typeNative: TypeNative, - private[reflection] val tagTree: ctx.Tree, - private[MacroSafeType] val tag: LightTypeTag, - ) { - - // hashcode is already cached in the underlying code - @inline override def hashCode: Int = { - tag.hashCode() - } - - @inline override def toString: String = { - tag.repr - } - override final def equals(obj: Any): Boolean = { - obj match { - case that: MacroSafeType => - tag =:= that.tag - case _ => - false - } - } - } - - object MacroSafeType { - import ctx.universe.* - protected[this] val modelReflectionPkg: ctx.Tree = q"_root_.izumi.distage.model.reflection" - - def create(tpe: TypeNative): MacroSafeType = { - val ltt = LightTypeTagImpl.makeLightTypeTag(u)(tpe) - val tagTree = q"{ $modelReflectionPkg.SafeType.get[${Liftable.liftType(tpe.asInstanceOf[ctx.Type])}] }" - - new MacroSafeType(tagTree, ltt) - } - } - -} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index 27a875fb36..48ff445a82 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -3,7 +3,7 @@ package izumi.distage.reflection.macros.universe.impl import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} -trait WithDISymbolInfo { this: DIUniverseBase with WithDISafeType => +trait WithDISymbolInfo { this: DIUniverseBase => private def convertConst(c: Any) = { c match { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala index 505441cb76..d26524c7f5 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala @@ -2,7 +2,7 @@ package izumi.distage.reflection.macros.universe.impl import scala.annotation.nowarn -trait WithDIWiring { this: DIUniverseBase with WithDISafeType with WithDIKey with WithDIAssociation with WithDISymbolInfo => +trait WithDIWiring { this: DIUniverseBase with WithDIKey with WithDIAssociation with WithDISymbolInfo => sealed trait MacroWiring object MacroWiring { @@ -16,8 +16,12 @@ trait WithDIWiring { this: DIUniverseBase with WithDISafeType with WithDIKey wit case class Class(instanceType: TypeNative, classParameters: List[List[Association.Parameter]], prefix: Option[MacroDIKey]) extends MacroSingletonWiring { override lazy val associations: List[Association] = classParameters.flatten } - case class Trait(instanceType: TypeNative, classParameters: List[List[Association.Parameter]], methods: List[Association.AbstractMethod], prefix: Option[MacroDIKey]) - extends MacroSingletonWiring { + case class Trait( + instanceType: TypeNative, + classParameters: List[List[Association.Parameter]], + methods: List[Association.AbstractMethod], + prefix: Option[MacroDIKey], + ) extends MacroSingletonWiring { override lazy val associations: List[Association] = classParameters.flatten ++ methods } } From bef9760a21e42a78ac8753e61553bf79833d05e9 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 29 May 2024 21:04:29 +0100 Subject: [PATCH 21/59] wip --- .../constructors/ConstructorMacros.scala | 4 +- .../macros/universe/DIUniverseLiftables.scala | 11 +++-- .../ReflectionProviderDefaultImpl.scala | 4 +- .../macros/universe/StaticDIUniverse.scala | 9 ---- .../macros/universe/impl/WithDIKey.scala | 41 +++++++------------ 5 files changed, 24 insertions(+), 45 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala index c9b47fbe46..9b0d86ab4b 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala @@ -3,7 +3,7 @@ package izumi.distage.reflection.macros.constructors import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.reflection.macros.universe.impl.MacroSafeType +import izumi.distage.reflection.macros.universe.impl.{MacroDIKey, MacroSafeType} import izumi.distage.reflection.macros.universe.{DIUniverseLiftables, ReflectionProvider, StaticDIUniverse} import izumi.fundamentals.reflection.ReflectionUtil @@ -90,7 +90,7 @@ object TraitConstructorMacros { abstract class FactoryConstructorMacros extends ConstructorMacrosBase { import c.universe.* - def generateFactoryMethod(dependencyArgMap: Map[u.MacroDIKey.BasicKey, c.Tree])(factoryMethod0: u.MacroWiring.Factory.FactoryMethod): c.Tree = { + def generateFactoryMethod(dependencyArgMap: Map[MacroDIKey.BasicKey, c.Tree])(factoryMethod0: u.MacroWiring.Factory.FactoryMethod): c.Tree = { val u.MacroWiring.Factory.FactoryMethod(factoryMethod, productConstructor, _) = factoryMethod0 val (methodArgListDecls, methodArgList) = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index 03030cd2a7..7cc1c9d0c6 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -1,6 +1,6 @@ package izumi.distage.reflection.macros.universe -import izumi.distage.reflection.macros.universe.impl.MacroSafeType +import izumi.distage.reflection.macros.universe.impl.{MacroDIKey, MacroSafeType} class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { @@ -24,16 +24,15 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { """ } - protected[this] implicit val liftableIdKey: Liftable[MacroDIKey.IdKey[?]] = { - case idKey: MacroDIKey.IdKey[?] => - val lifted = idKey.idContract.liftable(idKey.id) - q"""{ new $modelReflectionPkg.DIKey.IdKey(${liftMacroTypeToSafeType(idKey.tpe)}, $lifted) }""" + protected[this] implicit val liftableIdKey: Liftable[MacroDIKey.IdKey] = { + case idKey: MacroDIKey.IdKey => + q"""{ new $modelReflectionPkg.DIKey.IdKey(${liftMacroTypeToSafeType(idKey.tpe)}, ${idKey.id}) }""" } protected[this] implicit val liftableBasicDIKey: Liftable[MacroDIKey.BasicKey] = { Liftable[MacroDIKey.BasicKey] { case t: MacroDIKey.TypeKey => q"${liftableTypeKey(t)}" - case i: MacroDIKey.IdKey[?] => q"${liftableIdKey(i)}" + case i: MacroDIKey.IdKey => q"${liftableIdKey(i)}" } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index ea61f95e5b..b6af374982 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -4,7 +4,7 @@ import izumi.distage.model.definition.{Id, With} import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException -import izumi.distage.reflection.macros.universe.impl.{DIUniverse, FriendlyAnnoParams, FriendlyAnnotationValue} +import izumi.distage.reflection.macros.universe.impl.{DIUniverse, FriendlyAnnoParams, FriendlyAnnotationValue, MacroDIKey} import izumi.fundamentals.reflection.ReflectionUtil import scala.annotation.nowarn @@ -14,7 +14,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { import izumi.distage.reflection.macros.universe.impl.MacroSafeType import u.u.Annotation - import u.{Association, MacroDIKey, MacroSymbolInfo, MacroWiring, MethodSymbNative, SymbNative, TypeNative, stringIdContract} + import u.{Association, MacroSymbolInfo, MacroWiring, MethodSymbNative, SymbNative, TypeNative} private[this] object With { def unapply(ann: Annotation): Option[TypeNative] = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala index b3bdff9ddf..c17bd3f763 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala @@ -8,13 +8,6 @@ import scala.reflect.macros.blackbox trait StaticDIUniverse extends DIUniverse { self => override val u: SingletonUniverse - - override type MacroIdContract[T] = IdContractImpl[T] - class IdContractImpl[T: u.Liftable] extends MacroIdContractApi[T] { - override def repr(v: T): String = v.toString - - val liftable: u.Liftable[T] = implicitly - } } object StaticDIUniverse { @@ -24,8 +17,6 @@ object StaticDIUniverse { override val ctx: blackbox.Context = c override val u: c.universe.type = c.universe override protected val typeOfDistageAnnotation: TypeNative = u.typeOf[DIStageAnnotation] - override implicit val stringIdContract: MacroIdContract[String] = new IdContractImpl[String] - override implicit def singletonStringIdContract[S <: String with Singleton]: MacroIdContract[S] = new IdContractImpl[S] override val rp: ReflectionProvider = ReflectionProviderDefaultImpl.apply(this) } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala index 67fc467ef8..4603aa6ecc 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala @@ -1,36 +1,25 @@ package izumi.distage.reflection.macros.universe.impl -private[distage] trait WithDIKey { this: DIUniverseBase => +private[distage] trait WithDIKey { this: DIUniverseBase => } - sealed trait MacroDIKey { - def tpe: MacroSafeType - } - - object MacroDIKey { - sealed trait BasicKey extends MacroDIKey { - def withTpe(tpe: MacroSafeType): MacroDIKey.BasicKey - } - - case class TypeKey(tpe: MacroSafeType) extends BasicKey { - final def named[I: MacroIdContract](id: I): IdKey[I] = IdKey(tpe, id) +sealed trait MacroDIKey { + def tpe: MacroSafeType +} - override final def withTpe(tpe: MacroSafeType): MacroDIKey.TypeKey = copy(tpe = tpe) - override final def toString: String = s"{type.${tpe.toString}}" - } +object MacroDIKey { + sealed trait BasicKey extends MacroDIKey { + def withTpe(tpe: MacroSafeType): MacroDIKey.BasicKey + } - case class IdKey[I: MacroIdContract](tpe: MacroSafeType, id: I) extends BasicKey { - final val idContract: MacroIdContract[I] = implicitly + case class TypeKey(tpe: MacroSafeType) extends BasicKey { + final def named(id: String): IdKey = IdKey(tpe, id) - override final def withTpe(tpe: MacroSafeType): MacroDIKey.IdKey[I] = copy(tpe = tpe) - override final def toString: String = s"{type.${tpe.toString}@${idContract.repr(id)}}" - } + override final def withTpe(tpe: MacroSafeType): MacroDIKey.TypeKey = copy(tpe = tpe) + override final def toString: String = s"{type.${tpe.toString}}" } - trait MacroIdContractApi[T] { - def repr(v: T): String + case class IdKey(tpe: MacroSafeType, id: String) extends BasicKey { + override final def withTpe(tpe: MacroSafeType): MacroDIKey.IdKey = copy(tpe = tpe) + override final def toString: String = s"{type.${tpe.toString}@$id}" } - type MacroIdContract[T] <: MacroIdContractApi[T] - - implicit def stringIdContract: MacroIdContract[String] - implicit def singletonStringIdContract[S <: String with Singleton]: MacroIdContract[S] } From 61791a981e200a82f00d9df59351848d5cd9b224 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Fri, 31 May 2024 16:59:22 +0100 Subject: [PATCH 22/59] wip --- .../reflection/macros/FunctoidMacro.scala | 4 +- .../macros/universe/DIUniverseLiftables.scala | 41 +++++++++++-------- .../macros/universe/ReflectionProvider.scala | 4 +- .../ReflectionProviderDefaultImpl.scala | 6 +-- .../universe/impl/WithDIAssociation.scala | 7 ++-- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 7e56540006..a46eade7ef 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -5,7 +5,7 @@ import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.reflection.macros.universe.StaticDIUniverse.Aux -import izumi.distage.reflection.macros.universe.impl.MacroSafeType +import izumi.distage.reflection.macros.universe.impl.{CompactParameter, MacroSafeType} import izumi.distage.reflection.macros.universe.{DIUniverseLiftables, ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.TrivialMacroLogger @@ -27,7 +27,7 @@ class FunctoidMacro(val c: blackbox.Context) { private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) protected final val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) - type Parameter = macroUniverse.Association.CompactParameter + type Parameter = CompactParameter private final val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index 7cc1c9d0c6..6a632b1980 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -1,6 +1,6 @@ package izumi.distage.reflection.macros.universe -import izumi.distage.reflection.macros.universe.impl.{MacroDIKey, MacroSafeType} +import izumi.distage.reflection.macros.universe.impl.{CompactParameter, MacroDIKey, MacroSafeType} class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { @@ -38,32 +38,37 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { // SymbolInfo - // currently only function parameter symbols are spliced by this - // So, `liftableSafeType` is fine and will work, since parameter - // types must all be resolved anyway - they cannot contain polymorphic - // components, unlike general method symbols (info for which we don't generate). - // (annotations always empty currently) - protected[this] def lifSymbolInfo(info: MacroSymbolInfo): Tree = { - q"""{ $modelReflectionPkg.SymbolInfo( +// protected[this] def lifSymbolInfo(info: MacroSymbolInfo): Tree = {} + + // Associations + + // converts Association.Parameter to LinkedParameter + implicit val liftableParameter: Liftable[Association.Parameter] = { + case Association.Parameter(info, _, key) => + // currently only function parameter symbols are spliced by this + // So, `liftableSafeType` is fine and will work, since parameter + // types must all be resolved anyway - they cannot contain polymorphic + // components, unlike general method symbols (info for which we don't generate). + // (annotations always empty currently) + val symTree = q"""{ $modelReflectionPkg.SymbolInfo( name = ${info.name}, finalResultType = ${liftTypeToSafeType(info.nonByNameFinalResultType)}, isByName = ${info.isByName}, wasGeneric = ${info.wasGeneric} ) }""" - } - - // Associations - // converts Association.Parameter to LinkedParameter - implicit val liftableParameter: Liftable[Association.Parameter] = { - case Association.Parameter(symbol, _, key) => - val symTree = lifSymbolInfo(symbol) q"new $modelReflectionPkg.LinkedParameter($symTree, $key)" } - implicit val liftableCompactParameter: Liftable[Association.CompactParameter] = { - case Association.CompactParameter(symbol, _, key) => - val symTree = lifSymbolInfo(symbol.asInstanceOf[MacroSymbolInfo]) + implicit val liftableCompactParameter: Liftable[CompactParameter] = { + case CompactParameter(info, _, key) => +// val symTree = lifSymbolInfo(symbol.asInstanceOf[MacroSymbolInfo]) + val symTree = q"""{ $modelReflectionPkg.SymbolInfo( + name = ${info.name}, + finalResultType = ${liftTypeToSafeType(info.asInstanceOf[MacroSymbolInfo].nonByNameFinalResultType)}, + isByName = ${info.isByName}, + wasGeneric = ${info.wasGeneric} + ) }""" q"new $modelReflectionPkg.LinkedParameter($symTree, $key)" } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala index a8c8e078c1..b00f2250a8 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala @@ -1,13 +1,13 @@ package izumi.distage.reflection.macros.universe -import izumi.distage.reflection.macros.universe.impl.DIUniverse +import izumi.distage.reflection.macros.universe.impl.{CompactParameter, DIUniverse} trait ReflectionProvider { val u: DIUniverse import u.* def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter - def parameterToAssociation2(parameterSymbol: MacroSymbolInfo): Association.CompactParameter + def parameterToAssociation2(parameterSymbol: MacroSymbolInfo): CompactParameter def constructorParameterLists(tpe: TypeNative): List[List[Association.Parameter]] def symbolToAnyWiring(tpe: TypeNative): MacroWiring diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index b6af374982..8707f04b0c 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -4,7 +4,7 @@ import izumi.distage.model.definition.{Id, With} import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException -import izumi.distage.reflection.macros.universe.impl.{DIUniverse, FriendlyAnnoParams, FriendlyAnnotationValue, MacroDIKey} +import izumi.distage.reflection.macros.universe.impl.{CompactParameter, DIUniverse, FriendlyAnnoParams, FriendlyAnnotationValue, MacroDIKey} import izumi.fundamentals.reflection.ReflectionUtil import scala.annotation.nowarn @@ -153,9 +153,9 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { Association.Parameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) } - override def parameterToAssociation2(parameterSymbol: MacroSymbolInfo): Association.CompactParameter = { + override def parameterToAssociation2(parameterSymbol: MacroSymbolInfo): CompactParameter = { val key = keyFromSymbol(parameterSymbol) - Association.CompactParameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) + CompactParameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) } override def zioHasParameters(transformName: String => String)(deepIntersection: List[u.TypeNative]): List[u.Association.Parameter] = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala index b8a6f8f9b1..e32a78c48c 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala @@ -34,9 +34,6 @@ private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDIKey w } object Association { - case class CompactParameter(symbol: MacroSymbolInfoCompact, stpe: MacroSafeType, key: MacroDIKey.BasicKey) { - final def isByName: Boolean = symbol.isByName - } case class Parameter(symbol: MacroSymbolInfo, stpe: MacroSafeType, key: MacroDIKey.BasicKey) extends Association { override final def isByName: Boolean = symbol.isByName @@ -53,3 +50,7 @@ private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDIKey w } } + +case class CompactParameter(symbol: MacroSymbolInfoCompact, stpe: MacroSafeType, key: MacroDIKey.BasicKey) { + final def isByName: Boolean = symbol.isByName +} From f3fe19612c57e8c625d27abf0940e921cae6c327 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Fri, 31 May 2024 17:44:13 +0100 Subject: [PATCH 23/59] wip --- .../UnsupportedWiringException.scala | 2 +- .../reflection/macros/FunctoidMacro.scala | 17 +++--- .../constructors/ConstructorMacros.scala | 2 +- .../macros/universe/DIUniverseLiftables.scala | 55 ++----------------- .../macros/universe/ReflectionProvider.scala | 3 +- .../ReflectionProviderDefaultImpl.scala | 7 ++- .../basicuniverse/CompactParameter.scala | 5 ++ .../DIUniverseBasicLiftables.scala | 38 +++++++++++++ .../FriendlyAnnotation.scala | 3 +- .../MacroDIKey.scala} | 4 +- .../MacroSafeType.scala | 2 +- .../macros/universe/impl/DIUniverse.scala | 2 +- .../universe/impl/WithDIAssociation.scala | 8 +-- .../universe/impl/WithDISymbolInfo.scala | 8 ++- .../macros/universe/impl/WithDIWiring.scala | 4 +- 15 files changed, 82 insertions(+), 78 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala create mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/{impl => basicuniverse}/FriendlyAnnotation.scala (91%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/{impl/WithDIKey.scala => basicuniverse/MacroDIKey.scala} (85%) rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/{impl => basicuniverse}/MacroSafeType.scala (94%) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala index e249ec9f27..f576d19637 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/exceptions/reflection/UnsupportedWiringException.scala @@ -1,6 +1,6 @@ package izumi.distage.model.exceptions.reflection import izumi.distage.model.exceptions.DIException -import izumi.distage.reflection.macros.universe.impl.MacroSafeType +import izumi.distage.reflection.macros.universe.basicuniverse.MacroSafeType class UnsupportedWiringException(message: String, val tpe: MacroSafeType) extends DIException(message) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index a46eade7ef..4742745ef8 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -5,8 +5,8 @@ import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.reflection.macros.universe.StaticDIUniverse.Aux -import izumi.distage.reflection.macros.universe.impl.{CompactParameter, MacroSafeType} -import izumi.distage.reflection.macros.universe.{DIUniverseLiftables, ReflectionProviderDefaultImpl, StaticDIUniverse} +import izumi.distage.reflection.macros.universe.basicuniverse.{CompactParameter, DIUniverseBasicLiftables, MacroSafeType} +import izumi.distage.reflection.macros.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.TrivialMacroLogger import scala.annotation.nowarn @@ -22,19 +22,20 @@ import scala.reflect.macros.blackbox * @see [[izumi.distage.constructors.DebugProperties]] */ class FunctoidMacro(val c: blackbox.Context) { + type Parameter = CompactParameter + import c.universe.* private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) - protected final val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) - type Parameter = CompactParameter - - private final val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) - private def symbolToParam(p: Symbol): Parameter = { + val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) + val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) reflectionProvider.parameterToAssociation2(macroUniverse.MacroSymbolInfo.Runtime(p)) } private def typeToParam(tpe: Type): Parameter = { + val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) + val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) val symbol = macroUniverse.MacroSymbolInfo.Static.syntheticFromType(c.freshName)(tpe) reflectionProvider.parameterToAssociation2(symbol) } @@ -89,7 +90,7 @@ class FunctoidMacro(val c: blackbox.Context) { } def generateProvider[R: c.WeakTypeTag](parameters: List[Parameter], fun: Tree): c.Expr[Functoid[R]] = { - val tools = DIUniverseLiftables(macroUniverse) + val tools = new DIUniverseBasicLiftables(c) import tools.liftableCompactParameter val seqName = if (parameters.nonEmpty) TermName(c.freshName("seqAny")) else TermName("_") diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala index 9b0d86ab4b..a25c63499e 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala @@ -3,7 +3,7 @@ package izumi.distage.reflection.macros.constructors import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.reflection.macros.universe.impl.{MacroDIKey, MacroSafeType} +import izumi.distage.reflection.macros.universe.basicuniverse.{MacroDIKey, MacroSafeType} import izumi.distage.reflection.macros.universe.{DIUniverseLiftables, ReflectionProvider, StaticDIUniverse} import izumi.fundamentals.reflection.ReflectionUtil diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index 6a632b1980..99714ec4ed 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -1,50 +1,18 @@ package izumi.distage.reflection.macros.universe -import izumi.distage.reflection.macros.universe.impl.{CompactParameter, MacroDIKey, MacroSafeType} +import izumi.distage.reflection.macros.universe.basicuniverse.DIUniverseBasicLiftables class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { + val basic: DIUniverseBasicLiftables[u.u.type] = DIUniverseBasicLiftables[u.u.type](u.ctx) + import basic.* import u.* import u.u.* - protected[this] val modelReflectionPkg: Tree = q"_root_.izumi.distage.model.reflection" - - def liftMacroTypeToSafeType(tpe: MacroSafeType): Tree = { - tpe.tagTree.asInstanceOf[Tree] - } - - private def liftTypeToSafeType(tpe: TypeNative): Tree = { - q"{ $modelReflectionPkg.SafeType.get[${Liftable.liftType(tpe)}] }" - } - - // DIKey - protected[this] implicit val liftableTypeKey: Liftable[MacroDIKey.TypeKey] = { - case MacroDIKey.TypeKey(tpe) => q""" - { new $modelReflectionPkg.DIKey.TypeKey(${liftMacroTypeToSafeType(tpe)}) } - """ - } - - protected[this] implicit val liftableIdKey: Liftable[MacroDIKey.IdKey] = { - case idKey: MacroDIKey.IdKey => - q"""{ new $modelReflectionPkg.DIKey.IdKey(${liftMacroTypeToSafeType(idKey.tpe)}, ${idKey.id}) }""" - } - - protected[this] implicit val liftableBasicDIKey: Liftable[MacroDIKey.BasicKey] = { - Liftable[MacroDIKey.BasicKey] { - case t: MacroDIKey.TypeKey => q"${liftableTypeKey(t)}" - case i: MacroDIKey.IdKey => q"${liftableIdKey(i)}" - } - } - - // SymbolInfo - -// protected[this] def lifSymbolInfo(info: MacroSymbolInfo): Tree = {} - - // Associations - - // converts Association.Parameter to LinkedParameter implicit val liftableParameter: Liftable[Association.Parameter] = { case Association.Parameter(info, _, key) => + val resultTree = q"{ $modelReflectionPkg.SafeType.get[${Liftable.liftType(info.nonByNameFinalResultType)}] }" +// val keyTree = liftableBasicDIKey.apply(key).asInstanceOf[Tree] // currently only function parameter symbols are spliced by this // So, `liftableSafeType` is fine and will work, since parameter // types must all be resolved anyway - they cannot contain polymorphic @@ -52,7 +20,7 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { // (annotations always empty currently) val symTree = q"""{ $modelReflectionPkg.SymbolInfo( name = ${info.name}, - finalResultType = ${liftTypeToSafeType(info.nonByNameFinalResultType)}, + finalResultType = $resultTree, isByName = ${info.isByName}, wasGeneric = ${info.wasGeneric} ) }""" @@ -60,17 +28,6 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { q"new $modelReflectionPkg.LinkedParameter($symTree, $key)" } - implicit val liftableCompactParameter: Liftable[CompactParameter] = { - case CompactParameter(info, _, key) => -// val symTree = lifSymbolInfo(symbol.asInstanceOf[MacroSymbolInfo]) - val symTree = q"""{ $modelReflectionPkg.SymbolInfo( - name = ${info.name}, - finalResultType = ${liftTypeToSafeType(info.asInstanceOf[MacroSymbolInfo].nonByNameFinalResultType)}, - isByName = ${info.isByName}, - wasGeneric = ${info.wasGeneric} - ) }""" - q"new $modelReflectionPkg.LinkedParameter($symTree, $key)" - } } object DIUniverseLiftables { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala index b00f2250a8..74ec7cfa1f 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala @@ -1,6 +1,7 @@ package izumi.distage.reflection.macros.universe -import izumi.distage.reflection.macros.universe.impl.{CompactParameter, DIUniverse} +import izumi.distage.reflection.macros.universe.basicuniverse.CompactParameter +import izumi.distage.reflection.macros.universe.impl.DIUniverse trait ReflectionProvider { val u: DIUniverse diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index 8707f04b0c..8b143cedb6 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -4,7 +4,8 @@ import izumi.distage.model.definition.{Id, With} import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException -import izumi.distage.reflection.macros.universe.impl.{CompactParameter, DIUniverse, FriendlyAnnoParams, FriendlyAnnotationValue, MacroDIKey} +import izumi.distage.reflection.macros.universe.basicuniverse.{CompactParameter, FriendlyAnnoParams, FriendlyAnnotationValue, MacroDIKey} +import izumi.distage.reflection.macros.universe.impl.DIUniverse import izumi.fundamentals.reflection.ReflectionUtil import scala.annotation.nowarn @@ -12,7 +13,7 @@ import scala.annotation.nowarn @nowarn("msg=outer reference") trait ReflectionProviderDefaultImpl extends ReflectionProvider { - import izumi.distage.reflection.macros.universe.impl.MacroSafeType + import izumi.distage.reflection.macros.universe.basicuniverse.MacroSafeType import u.u.Annotation import u.{Association, MacroSymbolInfo, MacroWiring, MethodSymbNative, SymbNative, TypeNative} @@ -155,7 +156,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { override def parameterToAssociation2(parameterSymbol: MacroSymbolInfo): CompactParameter = { val key = keyFromSymbol(parameterSymbol) - CompactParameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) + basicuniverse.CompactParameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) } override def zioHasParameters(transformName: String => String)(deepIntersection: List[u.TypeNative]): List[u.Association.Parameter] = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala new file mode 100644 index 0000000000..3c33b19b59 --- /dev/null +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala @@ -0,0 +1,5 @@ +package izumi.distage.reflection.macros.universe.basicuniverse + +case class CompactParameter(symbol: MacroSymbolInfoCompact, stpe: MacroSafeType, key: MacroDIKey.BasicKey) { + final def isByName: Boolean = symbol.isByName +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala new file mode 100644 index 0000000000..4260651027 --- /dev/null +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala @@ -0,0 +1,38 @@ +package izumi.distage.reflection.macros.universe.basicuniverse + +import scala.reflect.macros.blackbox + +class DIUniverseBasicLiftables[U <: scala.reflect.api.Universe](val ctx: blackbox.Context) { + val u: U = ctx.universe.asInstanceOf[U] + import u.* + + val modelReflectionPkg: Tree = q"_root_.izumi.distage.model.reflection" + + implicit val liftableMacroSafeType: Liftable[MacroSafeType] = { + stpe => + stpe.tagTree.asInstanceOf[Tree] + } + + implicit val liftableCompactParameter: Liftable[CompactParameter] = { + case CompactParameter(info, _, key) => + val symTree = q"""{ $modelReflectionPkg.SymbolInfo( + name = ${info.name}, + finalResultType = ${info.safeFinalResultType}, + isByName = ${info.isByName}, + wasGeneric = ${info.wasGeneric} + ) }""" + q"new $modelReflectionPkg.LinkedParameter($symTree, $key)" + } + + implicit val liftableBasicDIKey: Liftable[MacroDIKey.BasicKey] = { + Liftable[MacroDIKey.BasicKey] { + case t: MacroDIKey.TypeKey => q"{ new $modelReflectionPkg.DIKey.TypeKey(${t.tpe}) }" + case i: MacroDIKey.IdKey => q"{ new $modelReflectionPkg.DIKey.IdKey(${i.tpe}, ${i.id}) }" + } + } + +} + +object DIUniverseBasicLiftables { + def apply[U <: scala.reflect.api.Universe](c: blackbox.Context): DIUniverseBasicLiftables[U] = new DIUniverseBasicLiftables[U](c) +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnotation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala similarity index 91% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnotation.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala index 2613219430..a7a12cb028 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnotation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala @@ -1,4 +1,4 @@ -package izumi.distage.reflection.macros.universe.impl +package izumi.distage.reflection.macros.universe.basicuniverse case class FriendlyAnnotation(fqn: String, params: FriendlyAnnoParams) @@ -29,4 +29,5 @@ trait MacroSymbolInfoCompact { def wasGeneric: Boolean def friendlyAnnotations: List[FriendlyAnnotation] def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact + def safeFinalResultType: MacroSafeType } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala similarity index 85% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala index 4603aa6ecc..b7967abeef 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIKey.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala @@ -1,6 +1,4 @@ -package izumi.distage.reflection.macros.universe.impl - -private[distage] trait WithDIKey { this: DIUniverseBase => } +package izumi.distage.reflection.macros.universe.basicuniverse sealed trait MacroDIKey { def tpe: MacroSafeType diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/MacroSafeType.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala similarity index 94% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/MacroSafeType.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala index 4d59bb498f..f2dcbe7531 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/MacroSafeType.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala @@ -1,4 +1,4 @@ -package izumi.distage.reflection.macros.universe.impl +package izumi.distage.reflection.macros.universe.basicuniverse import izumi.reflect.macrortti.{LightTypeTag, LightTypeTagImpl} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala index 0f79698606..6553889bc7 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverse.scala @@ -1,3 +1,3 @@ package izumi.distage.reflection.macros.universe.impl -trait DIUniverse extends DIUniverseBase with WithDISymbolInfo with WithDIKey with WithDIAssociation with WithDIWiring +trait DIUniverse extends DIUniverseBase with WithDISymbolInfo with WithDIAssociation with WithDIWiring diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala index e32a78c48c..3ae048f2c3 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala @@ -1,8 +1,10 @@ package izumi.distage.reflection.macros.universe.impl +import izumi.distage.reflection.macros.universe.basicuniverse.{MacroDIKey, MacroSafeType} + import scala.reflect.macros.blackbox -private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDIKey with WithDISymbolInfo => +private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISymbolInfo => sealed trait Association { def symbol: MacroSymbolInfo @@ -50,7 +52,3 @@ private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDIKey w } } - -case class CompactParameter(symbol: MacroSymbolInfoCompact, stpe: MacroSafeType, key: MacroDIKey.BasicKey) { - final def isByName: Boolean = symbol.isByName -} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index 48ff445a82..3ea1a8d086 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -1,6 +1,8 @@ package izumi.distage.reflection.macros.universe.impl import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException +import izumi.distage.reflection.macros.universe.basicuniverse +import izumi.distage.reflection.macros.universe.basicuniverse.{FriendlyAnnoParams, FriendlyAnnotation, FriendlyAnnotationValue, MacroSafeType, MacroSymbolInfoCompact} import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} trait WithDISymbolInfo { this: DIUniverseBase => @@ -21,8 +23,6 @@ trait WithDISymbolInfo { this: DIUniverseBase => import u.* val tpe = anno.tree.tpe.finalResultType -// val tag = LightTypeTagImpl.makeLightTypeTag(u)(tpe) -// println(tag) val annoName = tpe.typeSymbol.fullName val paramTrees = anno.tree.children.tail @@ -68,7 +68,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => } } - FriendlyAnnotation(annoName, avals) + basicuniverse.FriendlyAnnotation(annoName, avals) } sealed trait MacroSymbolInfo extends MacroSymbolInfoCompact { @@ -111,6 +111,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) + override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(ctx)(nonByNameFinalResultType.asInstanceOf[ctx.Type]) } private[distage] object Runtime { @@ -161,6 +162,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) + override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(ctx)(nonByNameFinalResultType.asInstanceOf[ctx.Type]) } object Static { def syntheticFromType(transformName: String => String)(tpe: TypeNative): MacroSymbolInfo.Static = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala index d26524c7f5..407c938dee 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala @@ -1,8 +1,10 @@ package izumi.distage.reflection.macros.universe.impl +import izumi.distage.reflection.macros.universe.basicuniverse.MacroDIKey + import scala.annotation.nowarn -trait WithDIWiring { this: DIUniverseBase with WithDIKey with WithDIAssociation with WithDISymbolInfo => +trait WithDIWiring { this: DIUniverseBase with WithDIAssociation with WithDISymbolInfo => sealed trait MacroWiring object MacroWiring { From b7906b28a873310f09f0a6982f7b8c3614cb661d Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 3 Jun 2024 14:12:54 +0100 Subject: [PATCH 24/59] wip --- .../reflection/macros/FunctoidMacro.scala | 12 +-- .../universe/BaseReflectionProvider.scala | 84 +++++++++++++++++++ .../macros/universe/ReflectionProvider.scala | 2 - .../ReflectionProviderDefaultImpl.scala | 81 +++--------------- .../basicuniverse/FriendlyAnnotation.scala | 16 ++++ .../universe/impl/WithDISymbolInfo.scala | 18 ++-- 6 files changed, 123 insertions(+), 90 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/BaseReflectionProvider.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 4742745ef8..6a830b1973 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -4,9 +4,8 @@ import izumi.distage.constructors.DebugProperties import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.reflection.macros.universe.StaticDIUniverse.Aux +import izumi.distage.reflection.macros.universe.BaseReflectionProvider import izumi.distage.reflection.macros.universe.basicuniverse.{CompactParameter, DIUniverseBasicLiftables, MacroSafeType} -import izumi.distage.reflection.macros.universe.{ReflectionProviderDefaultImpl, StaticDIUniverse} import izumi.fundamentals.reflection.TrivialMacroLogger import scala.annotation.nowarn @@ -29,15 +28,10 @@ class FunctoidMacro(val c: blackbox.Context) { private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) private def symbolToParam(p: Symbol): Parameter = { - val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) - val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) - reflectionProvider.parameterToAssociation2(macroUniverse.MacroSymbolInfo.Runtime(p)) + new BaseReflectionProvider(c).symbolToParameter(p) } private def typeToParam(tpe: Type): Parameter = { - val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) - val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) - val symbol = macroUniverse.MacroSymbolInfo.Static.syntheticFromType(c.freshName)(tpe) - reflectionProvider.parameterToAssociation2(symbol) + new BaseReflectionProvider(c).typeToParameter(tpe) } def impl[R: c.WeakTypeTag](fun: Tree): c.Expr[Functoid[R]] = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/BaseReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/BaseReflectionProvider.scala new file mode 100644 index 0000000000..41effbaf6d --- /dev/null +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/BaseReflectionProvider.scala @@ -0,0 +1,84 @@ +package izumi.distage.reflection.macros.universe + +import izumi.distage.model.definition.Id +import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException +import izumi.distage.reflection.macros.universe.StaticDIUniverse.Aux +import izumi.distage.reflection.macros.universe.basicuniverse.{CompactParameter, FriendlyAnnoParams, FriendlyAnnotationValue, MacroDIKey, MacroSafeType, MacroSymbolInfoCompact} + +import scala.reflect.macros.blackbox + +class BaseReflectionProvider(val c: blackbox.Context) { + private val idAnnotationFqn = c.typeOf[Id].typeSymbol.fullName + + def typeToParameter(t: scala.reflect.api.Universe#Type): CompactParameter = { + val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) + val symbol = macroUniverse.MacroSymbolInfo.Static.syntheticFromType(c.freshName)(t.asInstanceOf[c.Type]) + parameterToAssociation2(symbol) + } + + def symbolToParameter(s: scala.reflect.api.Universe#Symbol): CompactParameter = { + val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) + val info = macroUniverse.MacroSymbolInfo.Runtime(s.asInstanceOf[c.Symbol]) + parameterToAssociation2(info) + } + + private def parameterToAssociation2(parameterSymbol: MacroSymbolInfoCompact): CompactParameter = { + val key = keyFromSymbol(parameterSymbol) + basicuniverse.CompactParameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) + } + + def tpeFromSymbol(parameterSymbol: MacroSymbolInfoCompact): MacroSafeType = { + val paramType = if (parameterSymbol.isByName) { // this will never be true for a method symbol + parameterSymbol.finalResultType.typeArgs.head.finalResultType + } else { + parameterSymbol.finalResultType + } + MacroSafeType.create(c)(paramType.asInstanceOf[c.Type]) + } + + def keyFromSymbol(parameterSymbol: MacroSymbolInfoCompact): MacroDIKey.BasicKey = { + val tpe = tpeFromSymbol(parameterSymbol) + val typeKey = MacroDIKey.TypeKey(tpe) + withIdKeyFromAnnotation(parameterSymbol, typeKey) + } + + private[this] def withIdKeyFromAnnotation(parameterSymbol: MacroSymbolInfoCompact, typeKey: MacroDIKey.TypeKey): MacroDIKey.BasicKey = { + val maybeDistageName = parameterSymbol.findUniqueFriendlyAnno(a => a.fqn == idAnnotationFqn).map { + value => + value.params match { + case FriendlyAnnoParams.Full(values) => + values.toMap.get("name") match { + case Some(value: FriendlyAnnotationValue.StringValue) => + value.value + case _ => + throw new BadIdAnnotationException(value.toString, value) + } + + case FriendlyAnnoParams.Values(_) => + throw new BadIdAnnotationException(value.toString, value) + } + + } + + // parameterSymbol.findUniqueFriendlyAnno(a => a.fqn.endsWith(".Named")) match { + // case Some(value) => + // System.out.println(s"${System.nanoTime()} $value") + // case None => + // } + + lazy val maybeJSRName = parameterSymbol.findUniqueFriendlyAnno(a => a.fqn.endsWith(".Named")).flatMap { + value => + value.params.values match { + case FriendlyAnnotationValue.StringValue(head) :: Nil => + Some(head) + case _ => + None + } + } + + maybeDistageName.orElse(maybeJSRName) match { + case Some(value) => typeKey.named(value) + case None => typeKey + } + } +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala index 74ec7cfa1f..28b2aeb9b6 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala @@ -1,6 +1,5 @@ package izumi.distage.reflection.macros.universe -import izumi.distage.reflection.macros.universe.basicuniverse.CompactParameter import izumi.distage.reflection.macros.universe.impl.DIUniverse trait ReflectionProvider { @@ -8,7 +7,6 @@ trait ReflectionProvider { import u.* def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter - def parameterToAssociation2(parameterSymbol: MacroSymbolInfo): CompactParameter def constructorParameterLists(tpe: TypeNative): List[List[Association.Parameter]] def symbolToAnyWiring(tpe: TypeNative): MacroWiring diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index 8b143cedb6..5428d7247c 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -1,10 +1,9 @@ package izumi.distage.reflection.macros.universe -import izumi.distage.model.definition.{Id, With} +import izumi.distage.model.definition.With import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException -import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException -import izumi.distage.reflection.macros.universe.basicuniverse.{CompactParameter, FriendlyAnnoParams, FriendlyAnnotationValue, MacroDIKey} +import izumi.distage.reflection.macros.universe.basicuniverse.MacroDIKey import izumi.distage.reflection.macros.universe.impl.DIUniverse import izumi.fundamentals.reflection.ReflectionUtil @@ -14,8 +13,10 @@ import scala.annotation.nowarn trait ReflectionProviderDefaultImpl extends ReflectionProvider { import izumi.distage.reflection.macros.universe.basicuniverse.MacroSafeType + import u.* import u.u.Annotation - import u.{Association, MacroSymbolInfo, MacroWiring, MethodSymbNative, SymbNative, TypeNative} + + private lazy val brp = new BaseReflectionProvider(u.ctx) private[this] object With { def unapply(ann: Annotation): Option[TypeNative] = { @@ -23,46 +24,6 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } } - private[this] def withIdKeyFromAnnotation(parameterSymbol: MacroSymbolInfo, typeKey: MacroDIKey.TypeKey): MacroDIKey.BasicKey = { - val maybeDistageName = parameterSymbol.findUniqueFriendlyAnno(a => a.fqn == typeOfIdAnnotation.typeSymbol.fullName).map { - value => - value.params match { - case FriendlyAnnoParams.Full(values) => - values.toMap.get("name") match { - case Some(value: FriendlyAnnotationValue.StringValue) => - value.value - case _ => - throw new BadIdAnnotationException(value.toString, value) - } - - case FriendlyAnnoParams.Values(_) => - throw new BadIdAnnotationException(value.toString, value) - } - - } - -// parameterSymbol.findUniqueFriendlyAnno(a => a.fqn.endsWith(".Named")) match { -// case Some(value) => -// System.out.println(s"${System.nanoTime()} $value") -// case None => -// } - - lazy val maybeJSRName = parameterSymbol.findUniqueFriendlyAnno(a => a.fqn.endsWith(".Named")).flatMap { - value => - value.params.values match { - case FriendlyAnnotationValue.StringValue(head) :: Nil => - Some(head) - case _ => - None - } - } - - maybeDistageName.orElse(maybeJSRName) match { - case Some(value) => typeKey.named(value) - case None => typeKey - } - } - def symbolToAnyWiring(tpe: TypeNative): MacroWiring = { tpe match { case FactorySymbol(symbolMethods, dependencyMethods) => @@ -150,13 +111,8 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } override def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter = { - val key = keyFromSymbol(parameterSymbol) - Association.Parameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) - } - - override def parameterToAssociation2(parameterSymbol: MacroSymbolInfo): CompactParameter = { - val key = keyFromSymbol(parameterSymbol) - basicuniverse.CompactParameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) + val key = brp.keyFromSymbol(parameterSymbol) + Association.Parameter(parameterSymbol, brp.tpeFromSymbol(parameterSymbol), key) } override def zioHasParameters(transformName: String => String)(deepIntersection: List[u.TypeNative]): List[u.Association.Parameter] = { @@ -164,7 +120,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { hasTpe => val tpe = hasTpe.dealias val syntheticSymbolInfo = MacroSymbolInfo.Static.syntheticFromType(transformName)(tpe) - Association.Parameter(syntheticSymbolInfo, tpeFromSymbol(syntheticSymbolInfo), keyFromSymbol(syntheticSymbolInfo)) + Association.Parameter(syntheticSymbolInfo, brp.tpeFromSymbol(syntheticSymbolInfo), brp.keyFromSymbol(syntheticSymbolInfo)) } } @@ -175,7 +131,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { .asSeenFrom(tpe, tpe.typeSymbol) } - val alreadyInSignature = factoryMethod.paramLists.flatten.map(symbol => keyFromSymbol(MacroSymbolInfo.Runtime(symbol, tpe, wasGeneric = false))) + val alreadyInSignature = factoryMethod.paramLists.flatten.map(symbol => brp.keyFromSymbol(MacroSymbolInfo.Runtime(symbol, tpe, wasGeneric = false))) val resultTypeWiring = mkConstructorWiring(factoryMethod, resultType) val excessiveTypes = alreadyInSignature.toSet -- resultTypeWiring.requiredKeys @@ -194,21 +150,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { private[this] def methodToAssociation(definingClass: TypeNative, method: MethodSymbNative): Association.AbstractMethod = { val methodSymb = MacroSymbolInfo.Runtime(method, definingClass, wasGeneric = false) - Association.AbstractMethod(methodSymb, tpeFromSymbol(methodSymb), keyFromSymbol(methodSymb)) - } - - private[this] def tpeFromSymbol(parameterSymbol: MacroSymbolInfo): MacroSafeType = { - val paramType = if (parameterSymbol.isByName) { // this will never be true for a method symbol - parameterSymbol.finalResultType.typeArgs.head.finalResultType - } else { - parameterSymbol.finalResultType - } - MacroSafeType.create(u.ctx)(paramType.asInstanceOf[u.ctx.Type]) - } - private[this] def keyFromSymbol(parameterSymbol: MacroSymbolInfo): MacroDIKey.BasicKey = { - val tpe = tpeFromSymbol(parameterSymbol) - val typeKey = MacroDIKey.TypeKey(tpe) - withIdKeyFromAnnotation(parameterSymbol, typeKey) + Association.AbstractMethod(methodSymb, brp.tpeFromSymbol(methodSymb), brp.keyFromSymbol(methodSymb)) } private[this] object ConcreteSymbol { @@ -323,15 +265,12 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } protected def typeOfWithAnnotation: TypeNative - protected def typeOfIdAnnotation: TypeNative } object ReflectionProviderDefaultImpl { def apply(macroUniverse: DIUniverse): ReflectionProvider.Aux[macroUniverse.type] = { new ReflectionProviderDefaultImpl { override final val u: macroUniverse.type = macroUniverse - - override protected val typeOfIdAnnotation: u.TypeNative = u.u.typeOf[Id] override protected val typeOfWithAnnotation: u.TypeNative = u.u.typeOf[With[Any]] } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala index a7a12cb028..d438f6b38a 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala @@ -1,5 +1,7 @@ package izumi.distage.reflection.macros.universe.basicuniverse +import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException + case class FriendlyAnnotation(fqn: String, params: FriendlyAnnoParams) sealed trait FriendlyAnnoParams { @@ -30,4 +32,18 @@ trait MacroSymbolInfoCompact { def friendlyAnnotations: List[FriendlyAnnotation] def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact def safeFinalResultType: MacroSafeType + def finalResultType: scala.reflect.api.Universe#Type +} + +object MacroSymbolInfoCompact { + implicit final class CompactSymbolInfoExtensions(symbolInfo: MacroSymbolInfoCompact) { + def findUniqueFriendlyAnno(p: FriendlyAnnotation => Boolean): Option[FriendlyAnnotation] = { + val annos = symbolInfo.friendlyAnnotations.filter(p) + if (annos.size > 1) { + import izumi.fundamentals.platform.strings.IzString.* + throw new AnnotationConflictException(s"Multiple DI annotations on symbol `$symbolInfo` in ${symbolInfo.safeFinalResultType}: ${annos.niceList()}") + } + annos.headOption + } + } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index 3ea1a8d086..d4de33024a 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -178,15 +178,17 @@ trait WithDISymbolInfo { this: DIUniverseBase => } } + + implicit final class SymbolInfoExtensions(symbolInfo: MacroSymbolInfo) { - def findUniqueFriendlyAnno(p: FriendlyAnnotation => Boolean): Option[FriendlyAnnotation] = { - val annos = symbolInfo.friendlyAnnotations.filter(p) - if (annos.size > 1) { - import izumi.fundamentals.platform.strings.IzString.* - throw new AnnotationConflictException(s"Multiple DI annotations on symbol `$symbolInfo` in ${symbolInfo.finalResultType}: ${annos.niceList()}") - } - annos.headOption - } +// def findUniqueFriendlyAnno(p: FriendlyAnnotation => Boolean): Option[FriendlyAnnotation] = { +// val annos = symbolInfo.friendlyAnnotations.filter(p) +// if (annos.size > 1) { +// import izumi.fundamentals.platform.strings.IzString.* +// throw new AnnotationConflictException(s"Multiple DI annotations on symbol `$symbolInfo` in ${symbolInfo.finalResultType}: ${annos.niceList()}") +// } +// annos.headOption +// } def findUniqueAnnotation(annType: TypeNative): Option[u.Annotation] = { val distageAnnos = symbolInfo.annotations.filter(t => t.tree.tpe <:< typeOfDistageAnnotation).toSet From 913457f2fb0e3dfd5eca183a2694035e34757eb3 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 3 Jun 2024 14:17:44 +0100 Subject: [PATCH 25/59] wip --- .../izumi/distage/reflection/macros/FunctoidMacro.scala | 3 +-- .../macros/universe/ReflectionProviderDefaultImpl.scala | 2 +- .../universe/{ => basicuniverse}/BaseReflectionProvider.scala | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) rename distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/{ => basicuniverse}/BaseReflectionProvider.scala (93%) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 6a830b1973..7774ff4dc3 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -4,8 +4,7 @@ import izumi.distage.constructors.DebugProperties import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.reflection.macros.universe.BaseReflectionProvider -import izumi.distage.reflection.macros.universe.basicuniverse.{CompactParameter, DIUniverseBasicLiftables, MacroSafeType} +import izumi.distage.reflection.macros.universe.basicuniverse.{BaseReflectionProvider, CompactParameter, DIUniverseBasicLiftables, MacroSafeType} import izumi.fundamentals.reflection.TrivialMacroLogger import scala.annotation.nowarn diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index 5428d7247c..6f53e9db51 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -3,7 +3,7 @@ package izumi.distage.reflection.macros.universe import izumi.distage.model.definition.With import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException -import izumi.distage.reflection.macros.universe.basicuniverse.MacroDIKey +import izumi.distage.reflection.macros.universe.basicuniverse.{BaseReflectionProvider, MacroDIKey} import izumi.distage.reflection.macros.universe.impl.DIUniverse import izumi.fundamentals.reflection.ReflectionUtil diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/BaseReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala similarity index 93% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/BaseReflectionProvider.scala rename to distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala index 41effbaf6d..624c96cd65 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/BaseReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala @@ -1,9 +1,9 @@ -package izumi.distage.reflection.macros.universe +package izumi.distage.reflection.macros.universe.basicuniverse import izumi.distage.model.definition.Id import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.reflection.macros.universe.StaticDIUniverse.Aux -import izumi.distage.reflection.macros.universe.basicuniverse.{CompactParameter, FriendlyAnnoParams, FriendlyAnnotationValue, MacroDIKey, MacroSafeType, MacroSymbolInfoCompact} +import izumi.distage.reflection.macros.universe.{StaticDIUniverse, basicuniverse} import scala.reflect.macros.blackbox From be03bcceff29aa271745279dcd7308423b529668 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 3 Jun 2024 14:50:52 +0100 Subject: [PATCH 26/59] wip --- .../reflection/macros/FunctoidMacro.scala | 2 +- .../constructors/ConstructorMacros.scala | 2 +- .../ReflectionProviderDefaultImpl.scala | 6 +- .../BaseReflectionProvider.scala | 19 +--- .../basicuniverse/ConstructorSelector.scala | 29 ++++++ .../basicuniverse/FriendlyAnnotation.scala | 25 ----- .../basicuniverse/MacroSafeType.scala | 12 +-- .../MacroSymbolInfoCompact.scala | 26 ++++++ .../MacroSymbolInfoCompactImpl.scala | 52 +++++++++++ .../universe/impl/FriendlyAnnoTools.scala | 72 +++++++++++++++ .../universe/impl/WithDISymbolInfo.scala | 92 ++----------------- 11 files changed, 202 insertions(+), 135 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala create mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala create mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala create mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnoTools.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 7774ff4dc3..9f510afd93 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -92,7 +92,7 @@ class FunctoidMacro(val c: blackbox.Context) { val parametersNoByName = Liftable.liftList[Parameter].apply(parameters) val retTpe = weakTypeOf[R] - val retTagTree = MacroSafeType.create(c)(retTpe).tagTree.asInstanceOf[c.Tree] + val retTagTree = MacroSafeType.create(c.universe)(retTpe).tagTree.asInstanceOf[c.Tree] c.Expr[Functoid[R]] { q"""{ diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala index a25c63499e..42454c9a51 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala @@ -312,7 +312,7 @@ abstract class ConstructorMacrosBase { } val retTpe = weakTypeOf[T] - val retTagTree = MacroSafeType.create(c)(retTpe).tagTree.asInstanceOf[c.Tree] + val retTagTree = MacroSafeType.create(c.universe)(retTpe).tagTree.asInstanceOf[c.Tree] c.Expr[Functoid[T]] { q"""{ diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index 6f53e9db51..a58935d597 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -56,7 +56,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { typeRef .map(_.pre) .filterNot(m => m.termSymbol.isModule && m.termSymbol.isStatic) - .map(v => MacroDIKey.TypeKey(MacroSafeType.create(u.ctx)(v.asInstanceOf[u.ctx.Type]))) + .map(v => MacroDIKey.TypeKey(MacroSafeType.create(u.ctx.universe)(v.asInstanceOf[u.ctx.Type]))) } } @@ -79,11 +79,11 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { | | * $mms |""".stripMargin, - MacroSafeType.create(u.ctx)(tpe.asInstanceOf[u.ctx.Type]), + MacroSafeType.create(u.ctx.universe)(tpe.asInstanceOf[u.ctx.Type]), ) case _ => - val safeType = MacroSafeType.create(u.ctx)(tpe.asInstanceOf[u.ctx.Type]) + val safeType = MacroSafeType.create(u.ctx.universe)(tpe.asInstanceOf[u.ctx.Type]) val factoryMsg = if (factoryMethod != u.u.NoSymbol) { s""" | * When trying to create an implementation for result of `$factoryMethod` of factory `${factoryMethod.owner}` diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala index 624c96cd65..91b07b5928 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala @@ -2,8 +2,7 @@ package izumi.distage.reflection.macros.universe.basicuniverse import izumi.distage.model.definition.Id import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException -import izumi.distage.reflection.macros.universe.StaticDIUniverse.Aux -import izumi.distage.reflection.macros.universe.{StaticDIUniverse, basicuniverse} +import izumi.distage.reflection.macros.universe.basicuniverse import scala.reflect.macros.blackbox @@ -11,15 +10,11 @@ class BaseReflectionProvider(val c: blackbox.Context) { private val idAnnotationFqn = c.typeOf[Id].typeSymbol.fullName def typeToParameter(t: scala.reflect.api.Universe#Type): CompactParameter = { - val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) - val symbol = macroUniverse.MacroSymbolInfo.Static.syntheticFromType(c.freshName)(t.asInstanceOf[c.Type]) - parameterToAssociation2(symbol) + parameterToAssociation2(MacroSymbolInfoCompactImpl.syntheticFromType(c.universe)(c.freshName)(t.asInstanceOf[c.universe.Type])) } def symbolToParameter(s: scala.reflect.api.Universe#Symbol): CompactParameter = { - val macroUniverse: Aux[c.universe.type] = StaticDIUniverse(c) - val info = macroUniverse.MacroSymbolInfo.Runtime(s.asInstanceOf[c.Symbol]) - parameterToAssociation2(info) + parameterToAssociation2(MacroSymbolInfoCompactImpl.fromSymbol(c.universe)(s.asInstanceOf[c.universe.Symbol])) } private def parameterToAssociation2(parameterSymbol: MacroSymbolInfoCompact): CompactParameter = { @@ -33,7 +28,7 @@ class BaseReflectionProvider(val c: blackbox.Context) { } else { parameterSymbol.finalResultType } - MacroSafeType.create(c)(paramType.asInstanceOf[c.Type]) + MacroSafeType.create(c.universe)(paramType.asInstanceOf[c.Type]) } def keyFromSymbol(parameterSymbol: MacroSymbolInfoCompact): MacroDIKey.BasicKey = { @@ -60,12 +55,6 @@ class BaseReflectionProvider(val c: blackbox.Context) { } - // parameterSymbol.findUniqueFriendlyAnno(a => a.fqn.endsWith(".Named")) match { - // case Some(value) => - // System.out.println(s"${System.nanoTime()} $value") - // case None => - // } - lazy val maybeJSRName = parameterSymbol.findUniqueFriendlyAnno(a => a.fqn.endsWith(".Named")).flatMap { value => value.params.values match { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala new file mode 100644 index 0000000000..e5e072694f --- /dev/null +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala @@ -0,0 +1,29 @@ +package izumi.distage.reflection.macros.universe.basicuniverse + +class ConstructorSelector(val u: scala.reflect.api.Universe) { + def selectConstructorMethod(tpe: u.Type): Option[scala.reflect.api.Universe#MethodSymbol] = { + val constructor = findConstructor(tpe) + if (!constructor.isTerm) { + None + } else { + Some(constructor.asTerm.alternatives.head.asMethod) + } + } + + @inline private[this] def findConstructor(tpe: u.Type): scala.reflect.api.Universe#Symbol = { + findConstructor0(tpe).getOrElse(u.NoSymbol) + } + + private[this] def findConstructor0(tpe: u.Type): Option[scala.reflect.api.Universe#Symbol] = { + tpe match { + case intersection: u.RefinedTypeApi => + intersection.parents.collectFirst(Function.unlift(findConstructor0)) + case tpe => + if (tpe.typeSymbol.isClass && tpe.typeSymbol.asClass.isTrait) { + tpe.baseClasses.collectFirst(Function.unlift(b => if (b ne tpe.typeSymbol) findConstructor0(b.typeSignature) else None)) + } else { + tpe.decl(u.termNames.CONSTRUCTOR).alternatives.find(_.isPublic) + } + } + } +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala index d438f6b38a..fa6ec43872 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala @@ -1,7 +1,5 @@ package izumi.distage.reflection.macros.universe.basicuniverse -import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException - case class FriendlyAnnotation(fqn: String, params: FriendlyAnnoParams) sealed trait FriendlyAnnoParams { @@ -24,26 +22,3 @@ object FriendlyAnnotationValue { case class UnknownConst(value: Any) extends FriendlyAnnotationValue case class Unknown() extends FriendlyAnnotationValue } - -trait MacroSymbolInfoCompact { - def name: String - def isByName: Boolean - def wasGeneric: Boolean - def friendlyAnnotations: List[FriendlyAnnotation] - def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact - def safeFinalResultType: MacroSafeType - def finalResultType: scala.reflect.api.Universe#Type -} - -object MacroSymbolInfoCompact { - implicit final class CompactSymbolInfoExtensions(symbolInfo: MacroSymbolInfoCompact) { - def findUniqueFriendlyAnno(p: FriendlyAnnotation => Boolean): Option[FriendlyAnnotation] = { - val annos = symbolInfo.friendlyAnnotations.filter(p) - if (annos.size > 1) { - import izumi.fundamentals.platform.strings.IzString.* - throw new AnnotationConflictException(s"Multiple DI annotations on symbol `$symbolInfo` in ${symbolInfo.safeFinalResultType}: ${annos.niceList()}") - } - annos.headOption - } - } -} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala index f2dcbe7531..a2e906a9e0 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala @@ -2,8 +2,6 @@ package izumi.distage.reflection.macros.universe.basicuniverse import izumi.reflect.macrortti.{LightTypeTag, LightTypeTagImpl} -import scala.reflect.macros.blackbox - final class MacroSafeType private ( private[reflection] val tagTree: scala.reflect.api.Universe#Tree, private val tag: LightTypeTag, @@ -28,12 +26,12 @@ final class MacroSafeType private ( } object MacroSafeType { - def create(ctx: blackbox.Context)(tpe: ctx.Type): MacroSafeType = { - import ctx.universe.* - val modelReflectionPkg: ctx.Tree = q"_root_.izumi.distage.model.reflection" + def create(u: scala.reflect.api.Universe)(tpe: scala.reflect.api.Universe#Type): MacroSafeType = { + import u.* + val modelReflectionPkg = q"_root_.izumi.distage.model.reflection" - val ltt = LightTypeTagImpl.makeLightTypeTag(ctx.universe)(tpe) - val tagTree = q"{ $modelReflectionPkg.SafeType.get[${ctx.universe.Liftable.liftType(tpe)}] }" + val ltt = LightTypeTagImpl.makeLightTypeTag(u)(tpe.asInstanceOf[u.Type]) + val tagTree = q"{ $modelReflectionPkg.SafeType.get[${u.Liftable.liftType(tpe.asInstanceOf[u.Type])}] }" new MacroSafeType(tagTree, ltt) } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala new file mode 100644 index 0000000000..ab47354317 --- /dev/null +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala @@ -0,0 +1,26 @@ +package izumi.distage.reflection.macros.universe.basicuniverse + +import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException + +trait MacroSymbolInfoCompact { + def name: String + def isByName: Boolean + def wasGeneric: Boolean + def friendlyAnnotations: List[FriendlyAnnotation] + def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact + def safeFinalResultType: MacroSafeType + def finalResultType: scala.reflect.api.Universe#Type +} + +object MacroSymbolInfoCompact { + implicit final class CompactSymbolInfoExtensions(symbolInfo: MacroSymbolInfoCompact) { + def findUniqueFriendlyAnno(p: FriendlyAnnotation => Boolean): Option[FriendlyAnnotation] = { + val annos = symbolInfo.friendlyAnnotations.filter(p) + if (annos.size > 1) { + import izumi.fundamentals.platform.strings.IzString.* + throw new AnnotationConflictException(s"Multiple DI annotations on symbol `$symbolInfo` in ${symbolInfo.safeFinalResultType}: ${annos.niceList()}") + } + annos.headOption + } + } +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala new file mode 100644 index 0000000000..52c1f73140 --- /dev/null +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala @@ -0,0 +1,52 @@ +package izumi.distage.reflection.macros.universe.basicuniverse + +import izumi.distage.reflection.macros.universe.impl.FriendlyAnnoTools +import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} + +case class MacroSymbolInfoCompactImpl( + name: String, + finalResultType: scala.reflect.api.Universe#Type, + friendlyAnnotations: List[FriendlyAnnotation], + isByName: Boolean, + wasGeneric: Boolean, + safeFinalResultType: MacroSafeType, +) extends MacroSymbolInfoCompact { + override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) +} + +object MacroSymbolInfoCompactImpl { + + def syntheticFromType(u: scala.reflect.api.Universe)(transformName: String => String)(tpe: u.Type): MacroSymbolInfoCompactImpl = { + val annos = AnnotationTools.getAllTypeAnnotations(u)(tpe) + val isByName = tpe.typeSymbol.isClass && tpe.typeSymbol.asClass == u.definitions.ByNameParamClass + val nonByNameFinalResultType = if (isByName) ReflectionUtil.stripByName(u: u.type)(tpe) else tpe + val fst = MacroSafeType.create(u)(nonByNameFinalResultType) + + MacroSymbolInfoCompactImpl( + name = transformName(tpe.typeSymbol.name.toString), + finalResultType = tpe, + friendlyAnnotations = annos.map(FriendlyAnnoTools.makeFriendly(u)), + isByName = isByName, + wasGeneric = tpe.typeSymbol.isParameter, + safeFinalResultType = fst, + ) + } + + def fromSymbol(u: scala.reflect.api.Universe)(underlying: u.Symbol): MacroSymbolInfoCompactImpl = { + val isByName = (underlying.isTerm && underlying.asTerm.isByNameParam) || ReflectionUtil.isByName(u)(underlying.typeSignature) + val annos = AnnotationTools.getAllAnnotations(u)(underlying).distinct + + val tpe = underlying.typeSignature + val nonByNameFinalResultType = if (isByName) ReflectionUtil.stripByName(u: u.type)(tpe) else tpe + val fst = MacroSafeType.create(u)(nonByNameFinalResultType) + + new MacroSymbolInfoCompactImpl( + name = underlying.name.toTermName.toString, + finalResultType = tpe, + friendlyAnnotations = annos.map(FriendlyAnnoTools.makeFriendly(u)), + isByName = isByName, + wasGeneric = underlying.typeSignature.typeSymbol.isParameter, + safeFinalResultType = fst, + ) + } +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnoTools.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnoTools.scala new file mode 100644 index 0000000000..ebe3a65860 --- /dev/null +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnoTools.scala @@ -0,0 +1,72 @@ +package izumi.distage.reflection.macros.universe.impl + +import izumi.distage.reflection.macros.universe.basicuniverse +import izumi.distage.reflection.macros.universe.basicuniverse.{ConstructorSelector, FriendlyAnnoParams, FriendlyAnnotation, FriendlyAnnotationValue} + +object FriendlyAnnoTools { + private def convertConst(c: Any): FriendlyAnnotationValue = { + c match { + case v: String => + FriendlyAnnotationValue.StringValue(v) + case v: Int => + FriendlyAnnotationValue.IntValue(v) + case v: Long => + FriendlyAnnotationValue.LongValue(v) + case v => + FriendlyAnnotationValue.UnknownConst(v) + } + } + def makeFriendly(u: scala.reflect.api.Universe)(anno: u.Annotation): FriendlyAnnotation = { + import u.* + + val tpe = anno.tree.tpe.finalResultType + val annoName = tpe.typeSymbol.fullName + val paramTrees = anno.tree.children.tail + + val avals = if (tpe.typeSymbol.isJavaAnnotation) { + val pairs = paramTrees.map { + p => + (p: @unchecked) match { + case NamedArg(Ident(TermName(name)), Literal(Constant(c))) => + (Some(name), convertConst(c)) + case a => + (None, FriendlyAnnotationValue.UnknownConst(s"$a ${u.showRaw(a)}")) + } + } + + val names = pairs.map(_._1).collect { case Some(name) => name } + val values = pairs.map(_._2) + assert(names.size >= values.size, s"Java annotation structure disbalance: names=$names values=$values") + FriendlyAnnoParams.Full(names.zip(values ++ List.fill(names.size - values.size)(FriendlyAnnotationValue.UnsetValue()))) + } else { + val values = paramTrees.map { + p => + (p: @unchecked) match { + case Literal(Constant(c)) => + convertConst(c) + case a => + FriendlyAnnotationValue.UnknownConst(s"$a ${u.showRaw(a)}") + } + } + + val rp = new ConstructorSelector(u) + val constructor = rp.selectConstructorMethod(tpe.asInstanceOf[rp.u.Type]) + constructor match { + case Some(c) => + c.paramLists match { + case params :: Nil => + val names = params.map(_.name.decodedName.toString) + assert(names.size >= values.size, s"Annotation structure disbalance: names=$names values=$values") + FriendlyAnnoParams.Full(names.zip(values ++ List.fill(names.size - values.size)(FriendlyAnnotationValue.UnsetValue()))) + case _ => + FriendlyAnnoParams.Values(values) + } + + case _ => + FriendlyAnnoParams.Values(values) + } + } + + basicuniverse.FriendlyAnnotation(annoName, avals) + } +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index d4de33024a..1815687ee2 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -1,76 +1,11 @@ package izumi.distage.reflection.macros.universe.impl import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException -import izumi.distage.reflection.macros.universe.basicuniverse -import izumi.distage.reflection.macros.universe.basicuniverse.{FriendlyAnnoParams, FriendlyAnnotation, FriendlyAnnotationValue, MacroSafeType, MacroSymbolInfoCompact} +import izumi.distage.reflection.macros.universe.basicuniverse.{FriendlyAnnotation, MacroSafeType, MacroSymbolInfoCompact} import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} trait WithDISymbolInfo { this: DIUniverseBase => - private def convertConst(c: Any) = { - c match { - case v: String => - FriendlyAnnotationValue.StringValue(v) - case v: Int => - FriendlyAnnotationValue.IntValue(v) - case v: Long => - FriendlyAnnotationValue.LongValue(v) - case v => - FriendlyAnnotationValue.UnknownConst(v) - } - } - def makeFriendly(anno: u.Annotation): FriendlyAnnotation = { - import u.* - - val tpe = anno.tree.tpe.finalResultType - val annoName = tpe.typeSymbol.fullName - val paramTrees = anno.tree.children.tail - - val avals = if (tpe.typeSymbol.isJavaAnnotation) { - val pairs = paramTrees.map { - p => - (p: @unchecked) match { - case NamedArg(Ident(TermName(name)), Literal(Constant(c))) => - (Some(name), convertConst(c)) - case a => - (None, FriendlyAnnotationValue.UnknownConst(s"$a ${u.showRaw(a)}")) - } - } - - val names = pairs.map(_._1).collect { case Some(name) => name } - val values = pairs.map(_._2) - assert(names.size >= values.size, s"Java annotation structure disbalance: names=$names values=$values") - FriendlyAnnoParams.Full(names.zip(values ++ List.fill(names.size - values.size)(FriendlyAnnotationValue.UnsetValue()))) - } else { - val values = paramTrees.map { - p => - (p: @unchecked) match { - case Literal(Constant(c)) => - convertConst(c) - case a => - FriendlyAnnotationValue.UnknownConst(s"$a ${u.showRaw(a)}") - } - } - val constructor = rp.selectConstructorMethod(tpe.asInstanceOf[rp.u.TypeNative]) - constructor match { - case Some(c) => - c.paramLists match { - case params :: Nil => - val names = params.map(_.name.decodedName.toString) - assert(names.size >= values.size, s"Annotation structure disbalance: names=$names values=$values") - FriendlyAnnoParams.Full(names.zip(values ++ List.fill(names.size - values.size)(FriendlyAnnotationValue.UnsetValue()))) - case _ => - FriendlyAnnoParams.Values(values) - } - - case _ => - FriendlyAnnoParams.Values(values) - } - } - - basicuniverse.FriendlyAnnotation(annoName, avals) - } - sealed trait MacroSymbolInfo extends MacroSymbolInfoCompact { def name: String def finalResultType: TypeNative @@ -87,7 +22,6 @@ trait WithDISymbolInfo { this: DIUniverseBase => def withTpe(tpe: TypeNative): MacroSymbolInfo def withIsByName(boolean: Boolean): MacroSymbolInfo def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo - // def typeSignatureArgs: List[SymbolInfo] = underlying.typeSignature.typeArgs.map(_.typeSymbol).map(s => Runtime(s, definingClass)) } protected def typeOfDistageAnnotation: TypeNative @@ -111,7 +45,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) - override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(ctx)(nonByNameFinalResultType.asInstanceOf[ctx.Type]) + override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(ctx.universe)(nonByNameFinalResultType.asInstanceOf[ctx.Type]) } private[distage] object Runtime { @@ -132,7 +66,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => isByName = underlying.isTerm && underlying.asTerm.isByNameParam, wasGeneric = wasGeneric, annotations = annos, - friendlyAnnotations = annos.map(makeFriendly), + friendlyAnnotations = annos.map(FriendlyAnnoTools.makeFriendly(u)), ) } @@ -145,7 +79,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => isByName = (underlying.isTerm && underlying.asTerm.isByNameParam) || ReflectionUtil.isByName(u)(underlying.typeSignature), wasGeneric = underlying.typeSignature.typeSymbol.isParameter, annotations = annos, - friendlyAnnotations = annos.map(makeFriendly), + friendlyAnnotations = annos.map(FriendlyAnnoTools.makeFriendly(u)), ) } } @@ -162,7 +96,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) - override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(ctx)(nonByNameFinalResultType.asInstanceOf[ctx.Type]) + override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(ctx.universe)(nonByNameFinalResultType.asInstanceOf[ctx.Type]) } object Static { def syntheticFromType(transformName: String => String)(tpe: TypeNative): MacroSymbolInfo.Static = { @@ -171,25 +105,14 @@ trait WithDISymbolInfo { this: DIUniverseBase => name = transformName(tpe.typeSymbol.name.toString), finalResultType = tpe, annotations = annos, - friendlyAnnotations = annos.map(makeFriendly), + friendlyAnnotations = annos.map(FriendlyAnnoTools.makeFriendly(u)), isByName = tpe.typeSymbol.isClass && tpe.typeSymbol.asClass == u.definitions.ByNameParamClass, wasGeneric = tpe.typeSymbol.isParameter, ) } } - - implicit final class SymbolInfoExtensions(symbolInfo: MacroSymbolInfo) { -// def findUniqueFriendlyAnno(p: FriendlyAnnotation => Boolean): Option[FriendlyAnnotation] = { -// val annos = symbolInfo.friendlyAnnotations.filter(p) -// if (annos.size > 1) { -// import izumi.fundamentals.platform.strings.IzString.* -// throw new AnnotationConflictException(s"Multiple DI annotations on symbol `$symbolInfo` in ${symbolInfo.finalResultType}: ${annos.niceList()}") -// } -// annos.headOption -// } - def findUniqueAnnotation(annType: TypeNative): Option[u.Annotation] = { val distageAnnos = symbolInfo.annotations.filter(t => t.tree.tpe <:< typeOfDistageAnnotation).toSet @@ -210,3 +133,6 @@ trait WithDISymbolInfo { this: DIUniverseBase => } } + + + From dfe534ffd2ec05be145d1f78bc48428324e7b241 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 3 Jun 2024 14:59:14 +0100 Subject: [PATCH 27/59] wip --- .../reflection/macros/FunctoidMacro.scala | 5 ++-- .../ReflectionProviderDefaultImpl.scala | 29 +++---------------- .../BaseReflectionProvider.scala | 16 +++++----- 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 9f510afd93..46f626627b 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -26,11 +26,12 @@ class FunctoidMacro(val c: blackbox.Context) { private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) + private val brp = new BaseReflectionProvider(c.universe) private def symbolToParam(p: Symbol): Parameter = { - new BaseReflectionProvider(c).symbolToParameter(p) + brp.symbolToParameter(p.asInstanceOf[brp.u.Symbol]) } private def typeToParam(tpe: Type): Parameter = { - new BaseReflectionProvider(c).typeToParameter(tpe) + brp.typeToParameter(tpe.asInstanceOf[brp.u.Type], c.freshName) } def impl[R: c.WeakTypeTag](fun: Tree): c.Expr[Functoid[R]] = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index a58935d597..125de14ba9 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -3,7 +3,7 @@ package izumi.distage.reflection.macros.universe import izumi.distage.model.definition.With import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException -import izumi.distage.reflection.macros.universe.basicuniverse.{BaseReflectionProvider, MacroDIKey} +import izumi.distage.reflection.macros.universe.basicuniverse.{BaseReflectionProvider, ConstructorSelector, MacroDIKey} import izumi.distage.reflection.macros.universe.impl.DIUniverse import izumi.fundamentals.reflection.ReflectionUtil @@ -16,7 +16,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { import u.* import u.u.Annotation - private lazy val brp = new BaseReflectionProvider(u.ctx) + private lazy val brp = new BaseReflectionProvider(u.ctx.universe) private[this] object With { def unapply(ann: Annotation): Option[TypeNative] = { @@ -191,12 +191,8 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } def selectConstructorMethod(tpe: TypeNative): Option[MethodSymbNative] = { - val constructor = findConstructor(tpe) - if (!constructor.isTerm) { - None - } else { - Some(constructor.asTerm.alternatives.head.asMethod) - } + val cs = new ConstructorSelector(u.u) + cs.selectConstructorMethod(tpe.asInstanceOf[cs.u.Type]).map(s => s.asInstanceOf[MethodSymbNative]) } override def isConcrete(tpe: TypeNative): Boolean = { @@ -247,23 +243,6 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { decl.isMethod && decl.isAbstract && !decl.isSynthetic && decl.owner != u.u.definitions.AnyClass } - @inline private[this] def findConstructor(tpe: TypeNative): SymbNative = { - findConstructor0(tpe).getOrElse(u.u.NoSymbol) - } - - private[this] def findConstructor0(tpe: TypeNative): Option[SymbNative] = { - tpe match { - case intersection: u.u.RefinedTypeApi => - intersection.parents.collectFirst(Function.unlift(findConstructor0)) - case tpe => - if (tpe.typeSymbol.isClass && tpe.typeSymbol.asClass.isTrait) { - tpe.baseClasses.collectFirst(Function.unlift(b => if (b ne tpe.typeSymbol) findConstructor0(b.typeSignature) else None)) - } else { - tpe.decl(u.u.termNames.CONSTRUCTOR).alternatives.find(_.isPublic) - } - } - } - protected def typeOfWithAnnotation: TypeNative } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala index 91b07b5928..af4c421fe5 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala @@ -4,17 +4,15 @@ import izumi.distage.model.definition.Id import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.reflection.macros.universe.basicuniverse -import scala.reflect.macros.blackbox +class BaseReflectionProvider(val u: scala.reflect.api.Universe) { + private val idAnnotationFqn = u.typeOf[Id].typeSymbol.fullName -class BaseReflectionProvider(val c: blackbox.Context) { - private val idAnnotationFqn = c.typeOf[Id].typeSymbol.fullName - - def typeToParameter(t: scala.reflect.api.Universe#Type): CompactParameter = { - parameterToAssociation2(MacroSymbolInfoCompactImpl.syntheticFromType(c.universe)(c.freshName)(t.asInstanceOf[c.universe.Type])) + def typeToParameter(t: u.Type, transformName: String => String): CompactParameter = { + parameterToAssociation2(MacroSymbolInfoCompactImpl.syntheticFromType(u)(transformName)(t)) } - def symbolToParameter(s: scala.reflect.api.Universe#Symbol): CompactParameter = { - parameterToAssociation2(MacroSymbolInfoCompactImpl.fromSymbol(c.universe)(s.asInstanceOf[c.universe.Symbol])) + def symbolToParameter(s: u.Symbol): CompactParameter = { + parameterToAssociation2(MacroSymbolInfoCompactImpl.fromSymbol(u)(s)) } private def parameterToAssociation2(parameterSymbol: MacroSymbolInfoCompact): CompactParameter = { @@ -28,7 +26,7 @@ class BaseReflectionProvider(val c: blackbox.Context) { } else { parameterSymbol.finalResultType } - MacroSafeType.create(c.universe)(paramType.asInstanceOf[c.Type]) + MacroSafeType.create(u)(paramType) } def keyFromSymbol(parameterSymbol: MacroSymbolInfoCompact): MacroDIKey.BasicKey = { From ad00ff78cb6a5cffb3f7ce81c947952bf765daaf Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 3 Jun 2024 15:22:53 +0100 Subject: [PATCH 28/59] wip --- .../reflection/macros/FunctoidMacro.scala | 203 +---------------- .../reflection/macros/FunctoidMacroBase.scala | 206 ++++++++++++++++++ .../ReflectionProviderDefaultImpl.scala | 9 +- .../universe/impl/WithDISymbolInfo.scala | 7 +- .../AnnotationConflictException.scala | 5 - .../reflection/BadIdAnnotationException.scala | 6 - .../BaseReflectionProvider.scala | 9 +- .../basicuniverse/CompactParameter.scala | 0 .../basicuniverse/ConstructorSelector.scala | 0 .../DIUniverseBasicLiftables.scala | 0 .../basicuniverse}/FriendlyAnnoTools.scala | 3 +- .../basicuniverse/FriendlyAnnotation.scala | 0 .../universe/basicuniverse/MacroDIKey.scala | 0 .../basicuniverse/MacroSafeType.scala | 0 .../MacroSymbolInfoCompact.scala | 4 +- .../MacroSymbolInfoCompactImpl.scala | 1 - .../AnnotationConflictException.scala | 3 + .../exceptions/BadIdAnnotationException.scala | 4 + 18 files changed, 232 insertions(+), 228 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroBase.scala delete mode 100644 distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/macros/reflection/AnnotationConflictException.scala delete mode 100644 distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/macros/reflection/BadIdAnnotationException.scala rename {distage/distage-core-api/src/main/scala-2 => fundamentals/fundamentals-platform/src/main/scala}/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala (90%) rename {distage/distage-core-api/src/main/scala-2 => fundamentals/fundamentals-platform/src/main/scala}/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala (100%) rename {distage/distage-core-api/src/main/scala-2 => fundamentals/fundamentals-platform/src/main/scala}/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala (100%) rename {distage/distage-core-api/src/main/scala-2 => fundamentals/fundamentals-platform/src/main/scala}/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala (100%) rename {distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl => fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse}/FriendlyAnnoTools.scala (92%) rename {distage/distage-core-api/src/main/scala-2 => fundamentals/fundamentals-platform/src/main/scala}/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala (100%) rename {distage/distage-core-api/src/main/scala-2 => fundamentals/fundamentals-platform/src/main/scala}/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala (100%) rename {distage/distage-core-api/src/main/scala-2 => fundamentals/fundamentals-platform/src/main/scala}/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala (100%) rename {distage/distage-core-api/src/main/scala-2 => fundamentals/fundamentals-platform/src/main/scala}/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala (90%) rename {distage/distage-core-api/src/main/scala-2 => fundamentals/fundamentals-platform/src/main/scala}/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala (96%) create mode 100644 fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/AnnotationConflictException.scala create mode 100644 fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/BadIdAnnotationException.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 46f626627b..f05cb8cc91 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -1,206 +1,7 @@ package izumi.distage.reflection.macros -import izumi.distage.constructors.DebugProperties -import izumi.distage.model.providers.Functoid -import izumi.distage.model.reflection.Provider -import izumi.distage.model.reflection.Provider.ProviderType -import izumi.distage.reflection.macros.universe.basicuniverse.{BaseReflectionProvider, CompactParameter, DIUniverseBasicLiftables, MacroSafeType} -import izumi.fundamentals.reflection.TrivialMacroLogger +import izumi.distage.reflection.macros.universe.DIAnnotationMeta -import scala.annotation.nowarn import scala.reflect.macros.blackbox -/** - * To see macro debug output during compilation, set `-Dizumi.debug.macro.distage.functoid=true` java property! - * - * {{{ - * sbt -Dizumi.debug.macro.distage.functoid=true compile - * }}} - * - * @see [[izumi.distage.constructors.DebugProperties]] - */ -class FunctoidMacro(val c: blackbox.Context) { - type Parameter = CompactParameter - - import c.universe.* - - private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) - - private val brp = new BaseReflectionProvider(c.universe) - private def symbolToParam(p: Symbol): Parameter = { - brp.symbolToParameter(p.asInstanceOf[brp.u.Symbol]) - } - private def typeToParam(tpe: Type): Parameter = { - brp.typeToParameter(tpe.asInstanceOf[brp.u.Type], c.freshName) - } - - def impl[R: c.WeakTypeTag](fun: Tree): c.Expr[Functoid[R]] = { - val associations = analyze(fun, weakTypeOf[R]) - val result = generateProvider[R](associations, fun) - - logger.log( - s"""DIKeyWrappedFunction info: - | Symbol: ${fun.symbol}\n - | IsMethodSymbol: ${Option(fun.symbol).exists(_.isMethod)}\n - | Extracted Annotations: ${associations.flatMap(_.symbol.friendlyAnnotations)}\n - | Extracted DIKeys: ${associations.map(_.key)}\n - | argument: ${showCode(fun)}\n - | argumentTree: ${showRaw(fun)}\n - | argumentType: ${fun.tpe} - | Result code: ${showCode(result.tree)}""".stripMargin - ) - - result - } - - def analyze(tree: Tree, ret: Type): List[Parameter] = tree match { - case Block(List(), inner) => - analyze(inner, ret) - case Function(args, body) => - analyzeMethodRef(args.map(_.symbol), body) - case _ if tree.tpe ne null => - if (tree.tpe.typeSymbol.isModuleClass) { - val functionNClasses = definitions.FunctionClass.seq.toSet[Symbol] - val overridenFunctionNApply = tree.tpe.typeSymbol.info - .decl(TermName("apply")).alternatives - .find(_.overrides.exists(functionNClasses contains _.owner)) - - overridenFunctionNApply.fold(analyzeValRef(tree.tpe)) { - method => analyzeMethodRef(extractMethodReferenceParams(method), tree) - } - } else { - analyzeValRef(tree.tpe) - } - case _ => - c.abort( - tree.pos, - s""" - | Can handle only method references of form (method _) or lambda bodies of form (args => body).\n - | Argument doesn't seem to be a method reference or a lambda:\n - | argument: ${showCode(tree)}\n - | argumentTree: ${showRaw(tree)}\n - | Hint: Try appending _ to your method name""".stripMargin, - ) - } - - def generateProvider[R: c.WeakTypeTag](parameters: List[Parameter], fun: Tree): c.Expr[Functoid[R]] = { - val tools = new DIUniverseBasicLiftables(c) - import tools.liftableCompactParameter - - val seqName = if (parameters.nonEmpty) TermName(c.freshName("seqAny")) else TermName("_") - - val casts = parameters.indices.map(i => q"$seqName($i)") - val parametersNoByName = Liftable.liftList[Parameter].apply(parameters) - - val retTpe = weakTypeOf[R] - val retTagTree = MacroSafeType.create(c.universe)(retTpe).tagTree.asInstanceOf[c.Tree] - - c.Expr[Functoid[R]] { - q"""{ - val fun = $fun - - new ${weakTypeOf[Functoid[R]]}( - new ${weakTypeOf[Provider.ProviderImpl[R]]}( - $parametersNoByName, - $retTagTree, - fun, - { ($seqName: _root_.scala.Seq[_root_.scala.Any]) => fun.asInstanceOf[(..${casts.map(_ => definitions.AnyTpe)}) => ${definitions.AnyTpe}](..$casts) }, - ${symbolOf[ProviderType.Function.type].asClass.module}, - ) - ) - }""" - } - } - - protected[this] def analyzeMethodRef(lambdaArgs: List[Symbol], body: Tree): List[Parameter] = { - - val lambdaParams = lambdaArgs.map(symbolToParam) - val methodReferenceParams = body match { - case Apply(f, args) if args.map(_.symbol) == lambdaArgs => - logger.log(s"Matched function body as a method reference - consists of a single call to a function $f with the same arguments as lambda- ${showRaw(body)}") - - extractMethodReferenceParams(f.symbol).map(symbolToParam) - case _ => - logger.log(s"Function body didn't match as a variable or a method reference - ${showRaw(body)}") - - Nil - } - - logger.log(s"lambda params: $lambdaParams") - logger.log(s"method ref params: $methodReferenceParams") - - @nowarn("msg=Unused import") - val annotationsOnMethodAreNonEmptyAndASuperset: Boolean = { - import scala.collection.compat.* - methodReferenceParams.sizeCompare(lambdaParams) == 0 && - methodReferenceParams.exists(_.symbol.friendlyAnnotations.nonEmpty) - } - -// // this is somewhat superfluous since normally lambda parameters can't be annotated in source code at all -// val annotationsOnMethodAreNonEmptyAndASuperset: Boolean = { -// val annotationsOnLambdaParamSymbols = lambdaParams.iterator.map(_.symbol.annotations) -// val annotationsOnMethod = Predef.wrapRefArray(methodReferenceParams.iterator.map(_.symbol.annotations).toArray) -// -// annotationsOnMethod.exists(_.nonEmpty) && -// annotationsOnLambdaParamSymbols.zipAll(annotationsOnMethod.iterator, null, null).forall { -// case (null, _) => false -// case (_, null) => false -// case (left, right) => -// left.iterator.zipAll(right.iterator, null, null).forall { -// case (l, r) => (l eq null) || l == r -// } -// } -// } - - // if method reference has more annotations, get parameters from reference instead - // to preserve annotations! - if (annotationsOnMethodAreNonEmptyAndASuperset) { - // Use types from the generated lambda, not the method reference, because method reference types maybe generic/unresolved/unrelated - // But lambda params should be sufficiently 'grounded' at this point - // (Besides, lambda types are the ones specified by the caller, we should respect them) - methodReferenceParams.zip(lambdaParams).map { - case (mArg, lArg) => - mArg.copy( - symbol = lArg.symbol.withFriendlyAnnotations(mArg.symbol.friendlyAnnotations), - key = mArg.key.withTpe(lArg.stpe), - ) - } - } else { - lambdaParams - } - } - - protected[this] def extractMethodReferenceParams(symbol: Symbol): List[Symbol] = { - val isSyntheticCaseClassApply = { - symbol.name.decodedName.toString == "apply" && - symbol.isSynthetic && - symbol.owner.companion.isClass && - symbol.owner.companion.asClass.isCaseClass - } - - val method = if (isSyntheticCaseClassApply) { - // since this is a _synthetic_ apply, its signature must match the case class constructor exactly, so we don't check it - val constructor = symbol.owner.companion.asClass.primaryConstructor - logger.log(s"Matched method reference as a synthetic apply corresponding to primary constructor $constructor") - constructor - } else { - symbol.asMethod - } - - method.typeSignature.paramLists.flatten - } - - protected[this] def analyzeValRef(sig: Type): List[Parameter] = { - widenFunctionObject(sig).typeArgs.init.map(typeToParam) - } - - protected[this] def widenFunctionObject(sig: Type): Type = { - (sig match { - case s: SingleTypeApi => - sig.baseType(s.sym.typeSignature.baseClasses.find(definitions.FunctionClass.seq.contains(_)).get) - case _ => - sig - }): @nowarn("msg=outer reference") - } - -} +class FunctoidMacro(ctx: blackbox.Context) extends FunctoidMacroBase(ctx, new DIAnnotationMeta(ctx.universe).idAnnotationFqn) {} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroBase.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroBase.scala new file mode 100644 index 0000000000..06fa766543 --- /dev/null +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroBase.scala @@ -0,0 +1,206 @@ +package izumi.distage.reflection.macros + +import izumi.distage.constructors.DebugProperties +import izumi.distage.model.providers.Functoid +import izumi.distage.model.reflection.Provider +import izumi.distage.model.reflection.Provider.ProviderType +import izumi.distage.reflection.macros.universe.basicuniverse.{BaseReflectionProvider, CompactParameter, DIUniverseBasicLiftables, MacroSafeType} +import izumi.fundamentals.reflection.TrivialMacroLogger + +import scala.annotation.nowarn +import scala.reflect.macros.blackbox + +/** + * To see macro debug output during compilation, set `-Dizumi.debug.macro.distage.functoid=true` java property! + * + * {{{ + * sbt -Dizumi.debug.macro.distage.functoid=true compile + * }}} + * + * @see [[izumi.distage.constructors.DebugProperties]] + */ +abstract class FunctoidMacroBase(val c: blackbox.Context, idAnnotationFqn: String) { + type Parameter = CompactParameter + + import c.universe.* + + private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) + + private val brp = new BaseReflectionProvider(c.universe, idAnnotationFqn) + private def symbolToParam(p: Symbol): Parameter = { + brp.symbolToParameter(p.asInstanceOf[brp.u.Symbol]) + } + private def typeToParam(tpe: Type): Parameter = { + brp.typeToParameter(tpe.asInstanceOf[brp.u.Type], c.freshName) + } + + def impl[R: c.WeakTypeTag](fun: Tree): c.Expr[Functoid[R]] = { + val associations = analyze(fun, weakTypeOf[R]) + val result = generateProvider[R](associations, fun) + + logger.log( + s"""DIKeyWrappedFunction info: + | Symbol: ${fun.symbol}\n + | IsMethodSymbol: ${Option(fun.symbol).exists(_.isMethod)}\n + | Extracted Annotations: ${associations.flatMap(_.symbol.friendlyAnnotations)}\n + | Extracted DIKeys: ${associations.map(_.key)}\n + | argument: ${showCode(fun)}\n + | argumentTree: ${showRaw(fun)}\n + | argumentType: ${fun.tpe} + | Result code: ${showCode(result.tree)}""".stripMargin + ) + + result + } + + def analyze(tree: Tree, ret: Type): List[Parameter] = tree match { + case Block(List(), inner) => + analyze(inner, ret) + case Function(args, body) => + analyzeMethodRef(args.map(_.symbol), body) + case _ if tree.tpe ne null => + if (tree.tpe.typeSymbol.isModuleClass) { + val functionNClasses = definitions.FunctionClass.seq.toSet[Symbol] + val overridenFunctionNApply = tree.tpe.typeSymbol.info + .decl(TermName("apply")).alternatives + .find(_.overrides.exists(functionNClasses contains _.owner)) + + overridenFunctionNApply.fold(analyzeValRef(tree.tpe)) { + method => analyzeMethodRef(extractMethodReferenceParams(method), tree) + } + } else { + analyzeValRef(tree.tpe) + } + case _ => + c.abort( + tree.pos, + s""" + | Can handle only method references of form (method _) or lambda bodies of form (args => body).\n + | Argument doesn't seem to be a method reference or a lambda:\n + | argument: ${showCode(tree)}\n + | argumentTree: ${showRaw(tree)}\n + | Hint: Try appending _ to your method name""".stripMargin, + ) + } + + def generateProvider[R: c.WeakTypeTag](parameters: List[Parameter], fun: Tree): c.Expr[Functoid[R]] = { + val tools = new DIUniverseBasicLiftables(c) + import tools.liftableCompactParameter + + val seqName = if (parameters.nonEmpty) TermName(c.freshName("seqAny")) else TermName("_") + + val casts = parameters.indices.map(i => q"$seqName($i)") + val parametersNoByName = Liftable.liftList[Parameter].apply(parameters) + + val retTpe = weakTypeOf[R] + val retTagTree = MacroSafeType.create(c.universe)(retTpe).tagTree.asInstanceOf[c.Tree] + + c.Expr[Functoid[R]] { + q"""{ + val fun = $fun + + new ${weakTypeOf[Functoid[R]]}( + new ${weakTypeOf[Provider.ProviderImpl[R]]}( + $parametersNoByName, + $retTagTree, + fun, + { ($seqName: _root_.scala.Seq[_root_.scala.Any]) => fun.asInstanceOf[(..${casts.map(_ => definitions.AnyTpe)}) => ${definitions.AnyTpe}](..$casts) }, + ${symbolOf[ProviderType.Function.type].asClass.module}, + ) + ) + }""" + } + } + + protected[this] def analyzeMethodRef(lambdaArgs: List[Symbol], body: Tree): List[Parameter] = { + + val lambdaParams = lambdaArgs.map(symbolToParam) + val methodReferenceParams = body match { + case Apply(f, args) if args.map(_.symbol) == lambdaArgs => + logger.log(s"Matched function body as a method reference - consists of a single call to a function $f with the same arguments as lambda- ${showRaw(body)}") + + extractMethodReferenceParams(f.symbol).map(symbolToParam) + case _ => + logger.log(s"Function body didn't match as a variable or a method reference - ${showRaw(body)}") + + Nil + } + + logger.log(s"lambda params: $lambdaParams") + logger.log(s"method ref params: $methodReferenceParams") + + @nowarn("msg=Unused import") + val annotationsOnMethodAreNonEmptyAndASuperset: Boolean = { + import scala.collection.compat.* + methodReferenceParams.sizeCompare(lambdaParams) == 0 && + methodReferenceParams.exists(_.symbol.friendlyAnnotations.nonEmpty) + } + +// // this is somewhat superfluous since normally lambda parameters can't be annotated in source code at all +// val annotationsOnMethodAreNonEmptyAndASuperset: Boolean = { +// val annotationsOnLambdaParamSymbols = lambdaParams.iterator.map(_.symbol.annotations) +// val annotationsOnMethod = Predef.wrapRefArray(methodReferenceParams.iterator.map(_.symbol.annotations).toArray) +// +// annotationsOnMethod.exists(_.nonEmpty) && +// annotationsOnLambdaParamSymbols.zipAll(annotationsOnMethod.iterator, null, null).forall { +// case (null, _) => false +// case (_, null) => false +// case (left, right) => +// left.iterator.zipAll(right.iterator, null, null).forall { +// case (l, r) => (l eq null) || l == r +// } +// } +// } + + // if method reference has more annotations, get parameters from reference instead + // to preserve annotations! + if (annotationsOnMethodAreNonEmptyAndASuperset) { + // Use types from the generated lambda, not the method reference, because method reference types maybe generic/unresolved/unrelated + // But lambda params should be sufficiently 'grounded' at this point + // (Besides, lambda types are the ones specified by the caller, we should respect them) + methodReferenceParams.zip(lambdaParams).map { + case (mArg, lArg) => + mArg.copy( + symbol = lArg.symbol.withFriendlyAnnotations(mArg.symbol.friendlyAnnotations), + key = mArg.key.withTpe(lArg.stpe), + ) + } + } else { + lambdaParams + } + } + + protected[this] def extractMethodReferenceParams(symbol: Symbol): List[Symbol] = { + val isSyntheticCaseClassApply = { + symbol.name.decodedName.toString == "apply" && + symbol.isSynthetic && + symbol.owner.companion.isClass && + symbol.owner.companion.asClass.isCaseClass + } + + val method = if (isSyntheticCaseClassApply) { + // since this is a _synthetic_ apply, its signature must match the case class constructor exactly, so we don't check it + val constructor = symbol.owner.companion.asClass.primaryConstructor + logger.log(s"Matched method reference as a synthetic apply corresponding to primary constructor $constructor") + constructor + } else { + symbol.asMethod + } + + method.typeSignature.paramLists.flatten + } + + protected[this] def analyzeValRef(sig: Type): List[Parameter] = { + widenFunctionObject(sig).typeArgs.init.map(typeToParam) + } + + protected[this] def widenFunctionObject(sig: Type): Type = { + (sig match { + case s: SingleTypeApi => + sig.baseType(s.sym.typeSignature.baseClasses.find(definitions.FunctionClass.seq.contains(_)).get) + case _ => + sig + }): @nowarn("msg=outer reference") + } + +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index 125de14ba9..fe25d4f091 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -1,6 +1,6 @@ package izumi.distage.reflection.macros.universe -import izumi.distage.model.definition.With +import izumi.distage.model.definition.{Id, With} import izumi.distage.model.exceptions.macros.UnsupportedDefinitionException import izumi.distage.model.exceptions.reflection.UnsupportedWiringException import izumi.distage.reflection.macros.universe.basicuniverse.{BaseReflectionProvider, ConstructorSelector, MacroDIKey} @@ -9,6 +9,10 @@ import izumi.fundamentals.reflection.ReflectionUtil import scala.annotation.nowarn +class DIAnnotationMeta(u: scala.reflect.api.Universe) { + def idAnnotationFqn: String = u.typeOf[Id].typeSymbol.fullName +} + @nowarn("msg=outer reference") trait ReflectionProviderDefaultImpl extends ReflectionProvider { @@ -16,7 +20,8 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { import u.* import u.u.Annotation - private lazy val brp = new BaseReflectionProvider(u.ctx.universe) + private lazy val idAnnotationFqn = new DIAnnotationMeta(u.u).idAnnotationFqn + private lazy val brp = new BaseReflectionProvider(u.ctx.universe, idAnnotationFqn) private[this] object With { def unapply(ann: Annotation): Option[TypeNative] = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index 1815687ee2..60c2f49113 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -1,7 +1,7 @@ package izumi.distage.reflection.macros.universe.impl -import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException -import izumi.distage.reflection.macros.universe.basicuniverse.{FriendlyAnnotation, MacroSafeType, MacroSymbolInfoCompact} +import izumi.distage.reflection.macros.universe.basicuniverse.exceptions.AnnotationConflictException +import izumi.distage.reflection.macros.universe.basicuniverse.{FriendlyAnnoTools, FriendlyAnnotation, MacroSafeType, MacroSymbolInfoCompact} import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} trait WithDISymbolInfo { this: DIUniverseBase => @@ -133,6 +133,3 @@ trait WithDISymbolInfo { this: DIUniverseBase => } } - - - diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/macros/reflection/AnnotationConflictException.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/macros/reflection/AnnotationConflictException.scala deleted file mode 100644 index 44e0a6873d..0000000000 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/macros/reflection/AnnotationConflictException.scala +++ /dev/null @@ -1,5 +0,0 @@ -package izumi.distage.model.exceptions.macros.reflection - -import izumi.distage.model.exceptions.DIException - -class AnnotationConflictException(message: String) extends DIException(message) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/macros/reflection/BadIdAnnotationException.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/macros/reflection/BadIdAnnotationException.scala deleted file mode 100644 index 9fed86544c..0000000000 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/exceptions/macros/reflection/BadIdAnnotationException.scala +++ /dev/null @@ -1,6 +0,0 @@ -package izumi.distage.model.exceptions.macros.reflection - -import izumi.distage.model.exceptions.DIException - -class BadIdAnnotationException(typeOfIdAnnotation: String, value: Any) - extends DIException(s"Wrong annotation value, only constants are supported. Got: @$typeOfIdAnnotation($value)") diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala similarity index 90% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala index af4c421fe5..8ba3bf86cf 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala @@ -1,12 +1,9 @@ package izumi.distage.reflection.macros.universe.basicuniverse -import izumi.distage.model.definition.Id -import izumi.distage.model.exceptions.macros.reflection.BadIdAnnotationException import izumi.distage.reflection.macros.universe.basicuniverse +import izumi.distage.reflection.macros.universe.basicuniverse.exceptions.BadIdAnnotationException -class BaseReflectionProvider(val u: scala.reflect.api.Universe) { - private val idAnnotationFqn = u.typeOf[Id].typeSymbol.fullName - +class BaseReflectionProvider(val u: scala.reflect.api.Universe, idAnnotationFqn: String) { def typeToParameter(t: u.Type, transformName: String => String): CompactParameter = { parameterToAssociation2(MacroSymbolInfoCompactImpl.syntheticFromType(u)(transformName)(t)) } @@ -69,3 +66,5 @@ class BaseReflectionProvider(val u: scala.reflect.api.Universe) { } } } + + diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala similarity index 100% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala similarity index 100% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala similarity index 100% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnoTools.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala similarity index 92% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnoTools.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala index ebe3a65860..b460298183 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/FriendlyAnnoTools.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala @@ -1,7 +1,6 @@ -package izumi.distage.reflection.macros.universe.impl +package izumi.distage.reflection.macros.universe.basicuniverse import izumi.distage.reflection.macros.universe.basicuniverse -import izumi.distage.reflection.macros.universe.basicuniverse.{ConstructorSelector, FriendlyAnnoParams, FriendlyAnnotation, FriendlyAnnotationValue} object FriendlyAnnoTools { private def convertConst(c: Any): FriendlyAnnotationValue = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala similarity index 100% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala similarity index 100% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala similarity index 100% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala similarity index 90% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala index ab47354317..f8de33ad6e 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala @@ -1,6 +1,6 @@ package izumi.distage.reflection.macros.universe.basicuniverse -import izumi.distage.model.exceptions.macros.reflection.AnnotationConflictException +import izumi.distage.reflection.macros.universe.basicuniverse.exceptions.AnnotationConflictException trait MacroSymbolInfoCompact { def name: String @@ -24,3 +24,5 @@ object MacroSymbolInfoCompact { } } } + + diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala similarity index 96% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala index 52c1f73140..3b928f436c 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala @@ -1,6 +1,5 @@ package izumi.distage.reflection.macros.universe.basicuniverse -import izumi.distage.reflection.macros.universe.impl.FriendlyAnnoTools import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} case class MacroSymbolInfoCompactImpl( diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/AnnotationConflictException.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/AnnotationConflictException.scala new file mode 100644 index 0000000000..ef7db1c19e --- /dev/null +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/AnnotationConflictException.scala @@ -0,0 +1,3 @@ +package izumi.distage.reflection.macros.universe.basicuniverse.exceptions + +class AnnotationConflictException(message: String) extends RuntimeException(message) diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/BadIdAnnotationException.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/BadIdAnnotationException.scala new file mode 100644 index 0000000000..0eb4e61bab --- /dev/null +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/BadIdAnnotationException.scala @@ -0,0 +1,4 @@ +package izumi.distage.reflection.macros.universe.basicuniverse.exceptions + +class BadIdAnnotationException(typeOfIdAnnotation: String, value: Any) + extends RuntimeException(s"Wrong annotation value, only constants are supported. Got: @$typeOfIdAnnotation($value)") From 600c0e8dc3b797b261fd0e9c615b2299f37b8eb6 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Jun 2024 16:49:16 +0100 Subject: [PATCH 29/59] wip --- .../distage/model/providers/Functoid.scala | 88 +---------------- .../model/providers/AbstractFunctoid.scala | 95 +++++++++++++++++++ 2 files changed, 98 insertions(+), 85 deletions(-) create mode 100644 fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index 4df3c850ec..66dc9b41df 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -1,14 +1,9 @@ package izumi.distage.model.providers -import izumi.distage.model.definition.Identifier import izumi.distage.model.reflection.* import izumi.distage.reflection.macros.FunctoidMacroMethods -import izumi.fundamentals.platform.language.Quirks.* import izumi.reflect.Tag -import scala.annotation.unchecked.uncheckedVariance -import scala.annotation.unused - /** * A function that receives its arguments from DI object graph, including named instances via [[izumi.distage.model.definition.Id]] annotation. * @@ -68,91 +63,14 @@ import scala.annotation.unused * @see Functoid is based on the Magnet Pattern: [[http://spray.io/blog/2012-12-13-the-magnet-pattern/]] * @see Essentially Functoid is a function-like entity with additional properties, so it's funny name is reasonable enough: [[https://en.wiktionary.org/wiki/-oid#English]] */ -final case class Functoid[+A](get: Provider) { - def map[B: Tag](f: A => B): Functoid[B] = { - copy[B](get = get.unsafeMap(SafeType.get[B], (any: Any) => f(any.asInstanceOf[A]))) - } - - def zip[B](that: Functoid[B]): Functoid[(A, B)] = { - implicit val tagA: Tag[A] = this.getRetTag - implicit val tagB: Tag[B] = that.getRetTag - tagA.discard() // used for assembling Tag[(A, B)] below - tagB.discard() - copy[(A, B)](get = get.unsafeZip(SafeType.get[(A, B)], that.get)) - } - - def map2[B, C: Tag](that: Functoid[B])(f: (A, B) => C): Functoid[C] = { - zip(that).map[C](f.tupled) - } - - /** - * Applicative's `ap` method - can be used to chain transformations like `flatMap`. - * - * Apply a function produced by `that` Functoid to the value produced by `this` Functoid. - * - * Same as - * {{{ - * this.map2(that)((a, f) => f(a)) - * }}} - */ - def flatAp[B: Tag](that: Functoid[A => B]): Functoid[B] = { - map2(that)((a, f) => f(a)) - } - - /** - * Apply a function produced by `this` Functoid to the argument produced by `that` Functoid. - * - * Same as - * {{{ - * this.map2(that)((f, a) => f(a)) - * }}} - */ - def ap[B, C](that: Functoid[B])(implicit @unused ev: A <:< (B => C), tag: Tag[C]): Functoid[C] = { - map2(that)((f, a) => f.asInstanceOf[B => C](a)) - } - - /** Add `B` as an unused dependency of this Functoid */ - def addDependency[B: Tag]: Functoid[A] = addDependency(DIKey[B]) - def addDependency[B: Tag](name: Identifier): Functoid[A] = addDependency(DIKey[B](name)) - def addDependency(key: DIKey): Functoid[A] = addDependencies(key :: Nil) - def addDependencies(keys: Iterable[DIKey]): Functoid[A] = copy[A](get = get.addUnused(keys)) - - /** - * Add an `@Id` annotation to an unannotated parameter `P`, e.g. - * for .annotateParameter("x"), transform lambda `(p: P) => x(p)` - * into `(p: P @Id("x")) => x(p)` - */ - def annotateParameter[P: Tag](name: Identifier): Functoid[A] = { - val paramTpe = SafeType.get[P] - annotateParameterWhen(name) { - case DIKey.TypeKey(tpe, _) => tpe == paramTpe - case _: DIKey.IdKey[?] => false - } - } - /** Add an `@Id(name)` annotation to all unannotated parameters */ - def annotateAllParameters(name: Identifier): Functoid[A] = { - annotateParameterWhen(name) { - case _: DIKey.TypeKey => true - case _: DIKey.IdKey[?] => false - } - } - /** Add an `@Id(name)` annotation to all parameters matching `predicate` */ - def annotateParameterWhen(name: Identifier)(predicate: DIKey.BasicKey => Boolean): Functoid[A] = { - val newProvider = this.get.replaceKeys { - case k: DIKey.BasicKey if predicate(k) => - DIKey.IdKey(k.tpe, name.id, k.mutatorIndex)(name.idContract) - case k => k - } - Functoid(newProvider) - } - - @inline private def getRetTag: Tag[A @uncheckedVariance] = Tag(get.ret.closestClass, get.ret.tag) +final case class Functoid[+A](get: Provider) extends AbstractFunctoid[A, Functoid] { + override protected def create[B](provider: Provider): Functoid[B] = copy(get = provider) } object Functoid extends FunctoidMacroMethods with FunctoidLifecycleAdapters with FunctoidConstructors with SimpleFunctoids { implicit final class SyntaxMapSame[A](private val functoid: Functoid[A]) extends AnyVal { - def mapSame(f: A => A): Functoid[A] = functoid.map(f)(functoid.getRetTag) + def mapSame(f: A => A): Functoid[A] = functoid.map(f)(functoid.returnTypeTag) } def pure[A: Tag](a: A): Functoid[A] = lift(a) diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala new file mode 100644 index 0000000000..b48e590f07 --- /dev/null +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala @@ -0,0 +1,95 @@ +package izumi.distage.model.providers + +import izumi.distage.model.definition.Identifier +import izumi.distage.model.reflection.{DIKey, Provider, SafeType} +import izumi.fundamentals.platform.language.Quirks.Discarder +import izumi.reflect.Tag + +import scala.annotation.unchecked.uncheckedVariance +import scala.annotation.unused + +trait AbstractFunctoid[+A, Self[+K] <: AbstractFunctoid[K, Self]] { + + def get: Provider + + protected def create[B](provider: Provider): Self[B] + + def map[B: Tag](f: A => B): Self[B] = { + create[B](get.unsafeMap(SafeType.get[B], (any: Any) => f(any.asInstanceOf[A]))) + } + + def zip[B](that: Self[B]): Self[(A, B)] = { + implicit val tagA: Tag[A] = this.returnTypeTag + implicit val tagB: Tag[B] = that.returnTypeTag + tagA.discard() // used for assembling Tag[(A, B)] below + tagB.discard() + create[(A, B)](get.unsafeZip(SafeType.get[(A, B)], that.get)) + } + + def map2[B, C: Tag](that: Self[B])(f: (A, B) => C): Self[C] = { + zip(that).map[C](f.tupled) + } + + /** + * Applicative's `ap` method - can be used to chain transformations like `flatMap`. + * + * Apply a function produced by `that` Functoid to the value produced by `this` Functoid. + * + * Same as + * {{{ + * this.map2(that)((a, f) => f(a)) + * }}} + */ + def flatAp[B: Tag](that: Self[A => B]): Self[B] = { + map2(that)((a, f) => f(a)) + } + + /** + * Apply a function produced by `this` Functoid to the argument produced by `that` Functoid. + * + * Same as + * {{{ + * this.map2(that)((f, a) => f(a)) + * }}} + */ + def ap[B, C](that: Self[B])(implicit @unused ev: A <:< (B => C), tag: Tag[C]): Self[C] = { + map2(that)((f, a) => f.asInstanceOf[B => C](a)) + } + + /** Add `B` as an unused dependency of this Functoid */ + def addDependency[B: Tag]: Self[A] = addDependency(DIKey[B]) + def addDependency[B: Tag](name: Identifier): Self[A] = addDependency(DIKey[B](name)) + def addDependency(key: DIKey): Self[A] = addDependencies(key :: Nil) + def addDependencies(keys: Iterable[DIKey]): Self[A] = create[A](get.addUnused(keys)) + + /** + * Add an `@Id` annotation to an unannotated parameter `P`, e.g. + * for .annotateParameter("x"), transform lambda `(p: P) => x(p)` + * into `(p: P @Id("x")) => x(p)` + */ + def annotateParameter[P: Tag](name: Identifier): Self[A] = { + val paramTpe = SafeType.get[P] + annotateParameterWhen(name) { + case DIKey.TypeKey(tpe, _) => tpe == paramTpe + case _: DIKey.IdKey[?] => false + } + } + /** Add an `@Id(name)` annotation to all unannotated parameters */ + def annotateAllParameters(name: Identifier): Self[A] = { + annotateParameterWhen(name) { + case _: DIKey.TypeKey => true + case _: DIKey.IdKey[?] => false + } + } + /** Add an `@Id(name)` annotation to all parameters matching `predicate` */ + def annotateParameterWhen(name: Identifier)(predicate: DIKey.BasicKey => Boolean): Self[A] = { + val newProvider = this.get.replaceKeys { + case k: DIKey.BasicKey if predicate(k) => + DIKey.IdKey(k.tpe, name.id, k.mutatorIndex)(name.idContract) + case k => k + } + create[A](newProvider) + } + + def returnTypeTag: Tag[A @uncheckedVariance] = Tag(get.ret.closestClass, get.ret.tag) +} From df20197c30cc5c5c0665297125e3c8a24c454463 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Jun 2024 17:12:51 +0100 Subject: [PATCH 30/59] wip --- .../izumi/distage/model/providers/AbstractFunctoid.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala index b48e590f07..bd3450f383 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala @@ -93,3 +93,7 @@ trait AbstractFunctoid[+A, Self[+K] <: AbstractFunctoid[K, Self]] { def returnTypeTag: Tag[A @uncheckedVariance] = Tag(get.ret.closestClass, get.ret.tag) } + +final case class BaseFunctoid[+A](get: Provider) extends AbstractFunctoid[A, BaseFunctoid] { + override protected def create[B](provider: Provider): BaseFunctoid[B] = copy(get = provider) +} From 6f8d6c961d56ab36b9bf283ac034e633bd40b06d Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Jun 2024 17:24:40 +0100 Subject: [PATCH 31/59] wip --- .../reflection/macros/FunctoidMacro.scala | 5 +- .../macros/FunctoidMacroMethods.scala | 47 +++++++------ .../distage/model/providers/Functoid.scala | 6 +- .../reflection/macros/FunctoidMacroBase.scala | 69 ++++++++++--------- 4 files changed, 67 insertions(+), 60 deletions(-) rename {distage/distage-core-api/src/main/scala-2 => fundamentals/fundamentals-platform/src/main/scala}/izumi/distage/reflection/macros/FunctoidMacroBase.scala (94%) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index f05cb8cc91..4b4dcb45ba 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -1,7 +1,10 @@ package izumi.distage.reflection.macros +import izumi.distage.model.providers.Functoid import izumi.distage.reflection.macros.universe.DIAnnotationMeta import scala.reflect.macros.blackbox -class FunctoidMacro(ctx: blackbox.Context) extends FunctoidMacroBase(ctx, new DIAnnotationMeta(ctx.universe).idAnnotationFqn) {} +class FunctoidMacro(ctx: blackbox.Context) extends FunctoidMacroBase(ctx, new DIAnnotationMeta(ctx.universe).idAnnotationFqn) { + override implicit def tpe[A: c.WeakTypeTag]: c.Type = c.weakTypeOf[Functoid[A]] +} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index 4b9f9918a2..dbe7f7743f 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -5,29 +5,28 @@ import izumi.distage.model.providers.Functoid import scala.language.experimental.macros import scala.language.implicitConversions - trait FunctoidMacroMethods { - implicit def apply[R](fun: () => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: () => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index 66dc9b41df..6f258de4f0 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -67,7 +67,11 @@ final case class Functoid[+A](get: Provider) extends AbstractFunctoid[A, Functoi override protected def create[B](provider: Provider): Functoid[B] = copy(get = provider) } -object Functoid extends FunctoidMacroMethods with FunctoidLifecycleAdapters with FunctoidConstructors with SimpleFunctoids { +object Functoid extends FunctoidMacroMethods with SimpleFunctoids with FunctoidLifecycleAdapters with FunctoidConstructors { + +// implicit final def convert[R, Self[+A] <: AbstractFunctoid[A, Self]](f: Self[R]): Functoid[R] = { +// new Functoid[R](f.get) +// } implicit final class SyntaxMapSame[A](private val functoid: Functoid[A]) extends AnyVal { def mapSame(f: A => A): Functoid[A] = functoid.map(f)(functoid.returnTypeTag) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroBase.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/FunctoidMacroBase.scala similarity index 94% rename from distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroBase.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/FunctoidMacroBase.scala index 06fa766543..2971d16198 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/FunctoidMacroBase.scala @@ -1,7 +1,5 @@ package izumi.distage.reflection.macros -import izumi.distage.constructors.DebugProperties -import izumi.distage.model.providers.Functoid import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.reflection.macros.universe.basicuniverse.{BaseReflectionProvider, CompactParameter, DIUniverseBasicLiftables, MacroSafeType} @@ -24,7 +22,10 @@ abstract class FunctoidMacroBase(val c: blackbox.Context, idAnnotationFqn: Strin import c.universe.* - private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) + implicit def tpe[A: c.WeakTypeTag]: c.Type + +// private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) + private final val logger = TrivialMacroLogger.make[this.type](c, "xxx") private val brp = new BaseReflectionProvider(c.universe, idAnnotationFqn) private def symbolToParam(p: Symbol): Parameter = { @@ -34,9 +35,9 @@ abstract class FunctoidMacroBase(val c: blackbox.Context, idAnnotationFqn: Strin brp.typeToParameter(tpe.asInstanceOf[brp.u.Type], c.freshName) } - def impl[R: c.WeakTypeTag](fun: Tree): c.Expr[Functoid[R]] = { + def impl[R: c.WeakTypeTag, Ftoid[_]](fun: Tree): c.Expr[Ftoid[R]] = { val associations = analyze(fun, weakTypeOf[R]) - val result = generateProvider[R](associations, fun) + val result = generateProvider[R, Ftoid](associations, fun) logger.log( s"""DIKeyWrappedFunction info: @@ -53,6 +54,35 @@ abstract class FunctoidMacroBase(val c: blackbox.Context, idAnnotationFqn: Strin result } + def generateProvider[R: c.WeakTypeTag, Ftoid[_]](parameters: List[Parameter], fun: Tree): c.Expr[Ftoid[R]] = { + val tools = new DIUniverseBasicLiftables(c) + import tools.liftableCompactParameter + + val seqName = if (parameters.nonEmpty) TermName(c.freshName("seqAny")) else TermName("_") + + val casts = parameters.indices.map(i => q"$seqName($i)") + val parametersNoByName = Liftable.liftList[Parameter].apply(parameters) + + val retTpe = weakTypeOf[R] + val retTagTree = MacroSafeType.create(c.universe)(retTpe).tagTree.asInstanceOf[c.Tree] + + c.Expr[Ftoid[R]] { + q"""{ + val fun = $fun + + new ${tpe[R]}( + new ${weakTypeOf[Provider.ProviderImpl[R]]}( + $parametersNoByName, + $retTagTree, + fun, + { ($seqName: _root_.scala.Seq[_root_.scala.Any]) => fun.asInstanceOf[(..${casts.map(_ => definitions.AnyTpe)}) => ${definitions.AnyTpe}](..$casts) }, + ${symbolOf[ProviderType.Function.type].asClass.module}, + ) + ) + }""" + } + } + def analyze(tree: Tree, ret: Type): List[Parameter] = tree match { case Block(List(), inner) => analyze(inner, ret) @@ -83,35 +113,6 @@ abstract class FunctoidMacroBase(val c: blackbox.Context, idAnnotationFqn: Strin ) } - def generateProvider[R: c.WeakTypeTag](parameters: List[Parameter], fun: Tree): c.Expr[Functoid[R]] = { - val tools = new DIUniverseBasicLiftables(c) - import tools.liftableCompactParameter - - val seqName = if (parameters.nonEmpty) TermName(c.freshName("seqAny")) else TermName("_") - - val casts = parameters.indices.map(i => q"$seqName($i)") - val parametersNoByName = Liftable.liftList[Parameter].apply(parameters) - - val retTpe = weakTypeOf[R] - val retTagTree = MacroSafeType.create(c.universe)(retTpe).tagTree.asInstanceOf[c.Tree] - - c.Expr[Functoid[R]] { - q"""{ - val fun = $fun - - new ${weakTypeOf[Functoid[R]]}( - new ${weakTypeOf[Provider.ProviderImpl[R]]}( - $parametersNoByName, - $retTagTree, - fun, - { ($seqName: _root_.scala.Seq[_root_.scala.Any]) => fun.asInstanceOf[(..${casts.map(_ => definitions.AnyTpe)}) => ${definitions.AnyTpe}](..$casts) }, - ${symbolOf[ProviderType.Function.type].asClass.module}, - ) - ) - }""" - } - } - protected[this] def analyzeMethodRef(lambdaArgs: List[Symbol], body: Tree): List[Parameter] = { val lambdaParams = lambdaArgs.map(symbolToParam) From 39d6921617b402812b9168a361b2d94a35cd61cf Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Jun 2024 17:30:43 +0100 Subject: [PATCH 32/59] wip --- .../reflection/macros/FunctoidMacro.scala | 4 +- .../macros/FunctoidMacroMethods.scala | 50 +++++++++---------- .../distage/model/providers/Functoid.scala | 7 +-- .../reflection/macros/FunctoidMacroBase.scala | 8 +-- 4 files changed, 33 insertions(+), 36 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 4b4dcb45ba..7574bd832b 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -5,6 +5,8 @@ import izumi.distage.reflection.macros.universe.DIAnnotationMeta import scala.reflect.macros.blackbox -class FunctoidMacro(ctx: blackbox.Context) extends FunctoidMacroBase(ctx, new DIAnnotationMeta(ctx.universe).idAnnotationFqn) { +class FunctoidMacro(ctx: blackbox.Context) extends FunctoidMacroBase(ctx) { override implicit def tpe[A: c.WeakTypeTag]: c.Type = c.weakTypeOf[Functoid[A]] + + override def idAnnotationFqn: String = new DIAnnotationMeta(ctx.universe).idAnnotationFqn } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index dbe7f7743f..93aaf17289 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -1,32 +1,30 @@ package izumi.distage.reflection.macros -import izumi.distage.model.providers.Functoid - import scala.language.experimental.macros import scala.language.implicitConversions -trait FunctoidMacroMethods { - implicit def apply[R](fun: () => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] +trait FunctoidMacroMethods[Ftoid[+_]] { + implicit def apply[R](fun: () => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index 6f258de4f0..2506abce92 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -67,12 +67,7 @@ final case class Functoid[+A](get: Provider) extends AbstractFunctoid[A, Functoi override protected def create[B](provider: Provider): Functoid[B] = copy(get = provider) } -object Functoid extends FunctoidMacroMethods with SimpleFunctoids with FunctoidLifecycleAdapters with FunctoidConstructors { - -// implicit final def convert[R, Self[+A] <: AbstractFunctoid[A, Self]](f: Self[R]): Functoid[R] = { -// new Functoid[R](f.get) -// } - +object Functoid extends FunctoidMacroMethods[Functoid] with SimpleFunctoids with FunctoidLifecycleAdapters with FunctoidConstructors { implicit final class SyntaxMapSame[A](private val functoid: Functoid[A]) extends AnyVal { def mapSame(f: A => A): Functoid[A] = functoid.map(f)(functoid.returnTypeTag) } diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/FunctoidMacroBase.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/FunctoidMacroBase.scala index 2971d16198..32de50f914 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/FunctoidMacroBase.scala @@ -17,17 +17,19 @@ import scala.reflect.macros.blackbox * * @see [[izumi.distage.constructors.DebugProperties]] */ -abstract class FunctoidMacroBase(val c: blackbox.Context, idAnnotationFqn: String) { +abstract class FunctoidMacroBase(val c: blackbox.Context) { type Parameter = CompactParameter import c.universe.* - implicit def tpe[A: c.WeakTypeTag]: c.Type + def tpe[A: c.WeakTypeTag]: c.Type + def idAnnotationFqn: String + + private lazy val brp = new BaseReflectionProvider(c.universe, idAnnotationFqn) // private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) private final val logger = TrivialMacroLogger.make[this.type](c, "xxx") - private val brp = new BaseReflectionProvider(c.universe, idAnnotationFqn) private def symbolToParam(p: Symbol): Parameter = { brp.symbolToParameter(p.asInstanceOf[brp.u.Symbol]) } From c7c30ed949efaf1f76f2a92469306eeaf41a7356 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Jun 2024 17:34:55 +0100 Subject: [PATCH 33/59] wip --- .../distage/model/providers/Functoid.scala | 27 +++++++++++++- .../model/providers/SimpleFunctoids.scala | 37 +++++++------------ 2 files changed, 38 insertions(+), 26 deletions(-) rename {distage/distage-core-api => fundamentals/fundamentals-platform}/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala (60%) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index 2506abce92..378d49bba7 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -1,7 +1,10 @@ package izumi.distage.model.providers +import izumi.distage.model.exceptions.runtime.TODOBindingException import izumi.distage.model.reflection.* +import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.reflection.macros.FunctoidMacroMethods +import izumi.fundamentals.platform.language.CodePositionMaterializer import izumi.reflect.Tag /** @@ -64,10 +67,15 @@ import izumi.reflect.Tag * @see Essentially Functoid is a function-like entity with additional properties, so it's funny name is reasonable enough: [[https://en.wiktionary.org/wiki/-oid#English]] */ final case class Functoid[+A](get: Provider) extends AbstractFunctoid[A, Functoid] { - override protected def create[B](provider: Provider): Functoid[B] = copy(get = provider) + override protected def create[B](provider: Provider): Functoid[B] = Functoid.create[B](provider) } -object Functoid extends FunctoidMacroMethods[Functoid] with SimpleFunctoids with FunctoidLifecycleAdapters with FunctoidConstructors { +object Functoid + extends FunctoidMacroMethods[Functoid] + with SimpleFunctoids[Functoid] + with SimpleDistageFunctoids + with FunctoidLifecycleAdapters + with FunctoidConstructors { implicit final class SyntaxMapSame[A](private val functoid: Functoid[A]) extends AnyVal { def mapSame(f: A => A): Functoid[A] = functoid.map(f)(functoid.returnTypeTag) } @@ -76,4 +84,19 @@ object Functoid extends FunctoidMacroMethods[Functoid] with SimpleFunctoids with def unit: Functoid[Unit] = pure(()) + override protected[providers] def create[A](provider: Provider): Functoid[A] = new Functoid[A](provider) + +} + +trait SimpleDistageFunctoids { + def todoProvider(key: DIKey)(implicit pos: CodePositionMaterializer): Functoid[Nothing] = { + Functoid.create[Nothing]( + Provider.ProviderImpl( + parameters = Seq.empty, + ret = key.tpe, + fun = _ => throw new TODOBindingException(s"Tried to instantiate a 'TODO' binding for $key defined at ${pos.get}!", key, pos), + providerType = ProviderType.Function, + ) + ) + } } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala similarity index 60% rename from distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala index 1feb3f78e2..f3efaa50c3 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala @@ -1,16 +1,16 @@ package izumi.distage.model.providers -import izumi.distage.model.exceptions.runtime.TODOBindingException -import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.model.reflection.* -import izumi.fundamentals.platform.language.CodePositionMaterializer +import izumi.distage.model.reflection.Provider.ProviderType import izumi.reflect.Tag -private[providers] trait SimpleFunctoids { - def identity[A: Tag]: Functoid[A] = identityKey(DIKey.get[A]).asInstanceOf[Functoid[A]] +private[providers] trait SimpleFunctoids[Ftoid[+_]] { + protected def create[A](provider: Provider): Ftoid[A] + + def identity[A: Tag]: Ftoid[A] = identityKey(DIKey.get[A]).asInstanceOf[Ftoid[A]] - def lift[A: Tag](a: => A): Functoid[A] = { - new Functoid[A]( + def lift[A: Tag](a: => A): Ftoid[A] = { + create[A]( Provider.ProviderImpl[A]( parameters = Seq.empty, ret = SafeType.get[A], @@ -21,8 +21,8 @@ private[providers] trait SimpleFunctoids { ) } - def singleton[A <: Singleton: Tag](a: A): Functoid[A] = { - new Functoid[A]( + def singleton[A <: Singleton: Tag](a: A): Ftoid[A] = { + create[A]( Provider.ProviderImpl[A]( parameters = Seq.empty, ret = SafeType.get[A], @@ -33,13 +33,13 @@ private[providers] trait SimpleFunctoids { ) } - def single[A: Tag, B: Tag](f: A => B): Functoid[B] = { + def single[A: Tag, B: Tag](f: A => B): Ftoid[B] = { val key = DIKey.get[A] val tpe = key.tpe val retTpe = SafeType.get[B] val symbolInfo = firstParamSymbolInfo(tpe) - new Functoid[B]( + create[B]( Provider.ProviderImpl( parameters = Seq(LinkedParameter(symbolInfo, key)), ret = retTpe, @@ -50,22 +50,11 @@ private[providers] trait SimpleFunctoids { ) } - def todoProvider(key: DIKey)(implicit pos: CodePositionMaterializer): Functoid[Nothing] = { - new Functoid[Nothing]( - Provider.ProviderImpl( - parameters = Seq.empty, - ret = key.tpe, - fun = _ => throw new TODOBindingException(s"Tried to instantiate a 'TODO' binding for $key defined at ${pos.get}!", key, pos), - providerType = ProviderType.Function, - ) - ) - } - - def identityKey(key: DIKey): Functoid[?] = { + def identityKey(key: DIKey): Ftoid[?] = { val tpe = key.tpe val symbolInfo = firstParamSymbolInfo(tpe) - new Functoid( + create( Provider.ProviderImpl( parameters = Seq(LinkedParameter(symbolInfo, key)), ret = tpe, From 62757bc567c2193670c99c98e64ca643b42bfafc Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Jun 2024 17:35:04 +0100 Subject: [PATCH 34/59] wip --- .../distage/model/providers/Functoid.scala | 13 ------------- .../providers/SimpleDistageFunctoids.scala | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleDistageFunctoids.scala diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index 378d49bba7..194d693c6f 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -87,16 +87,3 @@ object Functoid override protected[providers] def create[A](provider: Provider): Functoid[A] = new Functoid[A](provider) } - -trait SimpleDistageFunctoids { - def todoProvider(key: DIKey)(implicit pos: CodePositionMaterializer): Functoid[Nothing] = { - Functoid.create[Nothing]( - Provider.ProviderImpl( - parameters = Seq.empty, - ret = key.tpe, - fun = _ => throw new TODOBindingException(s"Tried to instantiate a 'TODO' binding for $key defined at ${pos.get}!", key, pos), - providerType = ProviderType.Function, - ) - ) - } -} diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleDistageFunctoids.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleDistageFunctoids.scala new file mode 100644 index 0000000000..11339d0354 --- /dev/null +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/SimpleDistageFunctoids.scala @@ -0,0 +1,19 @@ +package izumi.distage.model.providers + +import izumi.distage.model.exceptions.runtime.TODOBindingException +import izumi.distage.model.reflection.Provider.ProviderType +import izumi.distage.model.reflection.{DIKey, Provider} +import izumi.fundamentals.platform.language.CodePositionMaterializer + +trait SimpleDistageFunctoids { + def todoProvider(key: DIKey)(implicit pos: CodePositionMaterializer): Functoid[Nothing] = { + Functoid.create[Nothing]( + Provider.ProviderImpl( + parameters = Seq.empty, + ret = key.tpe, + fun = _ => throw new TODOBindingException(s"Tried to instantiate a 'TODO' binding for $key defined at ${pos.get}!", key, pos), + providerType = ProviderType.Function, + ) + ) + } +} From b7c8e90a46f93237f15ff69906caf64b0ba0fe08 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Jun 2024 17:50:12 +0100 Subject: [PATCH 35/59] wip --- .../reflection/macros/FunctoidMacro.scala | 2 +- .../distage/model/providers/Functoid.scala | 18 ++++-------------- .../model/providers/FunctoidSyntax.scala | 13 +++++++++++++ .../model/providers/SimpleFunctoids.scala | 4 ++++ 4 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/FunctoidSyntax.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 7574bd832b..5d7abccf5e 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -6,7 +6,7 @@ import izumi.distage.reflection.macros.universe.DIAnnotationMeta import scala.reflect.macros.blackbox class FunctoidMacro(ctx: blackbox.Context) extends FunctoidMacroBase(ctx) { - override implicit def tpe[A: c.WeakTypeTag]: c.Type = c.weakTypeOf[Functoid[A]] + override def tpe[A: c.WeakTypeTag]: c.Type = c.weakTypeOf[Functoid[A]] override def idAnnotationFqn: String = new DIAnnotationMeta(ctx.universe).idAnnotationFqn } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index 194d693c6f..e021169e13 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -1,11 +1,9 @@ package izumi.distage.model.providers -import izumi.distage.model.exceptions.runtime.TODOBindingException import izumi.distage.model.reflection.* -import izumi.distage.model.reflection.Provider.ProviderType import izumi.distage.reflection.macros.FunctoidMacroMethods -import izumi.fundamentals.platform.language.CodePositionMaterializer -import izumi.reflect.Tag + +import scala.language.implicitConversions /** * A function that receives its arguments from DI object graph, including named instances via [[izumi.distage.model.definition.Id]] annotation. @@ -75,15 +73,7 @@ object Functoid with SimpleFunctoids[Functoid] with SimpleDistageFunctoids with FunctoidLifecycleAdapters - with FunctoidConstructors { - implicit final class SyntaxMapSame[A](private val functoid: Functoid[A]) extends AnyVal { - def mapSame(f: A => A): Functoid[A] = functoid.map(f)(functoid.returnTypeTag) - } - - def pure[A: Tag](a: A): Functoid[A] = lift(a) - - def unit: Functoid[Unit] = pure(()) - + with FunctoidConstructors + with FunctoidSyntax[Functoid] { override protected[providers] def create[A](provider: Provider): Functoid[A] = new Functoid[A](provider) - } diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/FunctoidSyntax.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/FunctoidSyntax.scala new file mode 100644 index 0000000000..b81f5f61f8 --- /dev/null +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/FunctoidSyntax.scala @@ -0,0 +1,13 @@ +package izumi.distage.model.providers + +import scala.language.implicitConversions + +trait FunctoidSyntax[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { + implicit final def syntaxMapSame[A](functoid: Ftoid[A]): FunctoidSyntax.SyntaxMapSame[A, Ftoid] = new FunctoidSyntax.SyntaxMapSame[A, Ftoid](functoid) +} + +object FunctoidSyntax { + final class SyntaxMapSame[A, Ftoid[+K] <: AbstractFunctoid[K, Ftoid]](private val functoid: Ftoid[A]) extends AnyVal { + def mapSame(f: A => A): Ftoid[A] = functoid.map(f)(functoid.returnTypeTag) + } +} diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala index f3efaa50c3..77bdc93862 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala @@ -7,6 +7,10 @@ import izumi.reflect.Tag private[providers] trait SimpleFunctoids[Ftoid[+_]] { protected def create[A](provider: Provider): Ftoid[A] + def pure[A: Tag](a: A): Ftoid[A] = lift(a) + + def unit: Ftoid[Unit] = pure(()) + def identity[A: Tag]: Ftoid[A] = identityKey(DIKey.get[A]).asInstanceOf[Ftoid[A]] def lift[A: Tag](a: => A): Ftoid[A] = { From 83a169246b2cc82de7947fd99832d336c71c676a Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Jun 2024 17:52:14 +0100 Subject: [PATCH 36/59] wip --- .../main/scala/izumi/distage/model/providers/Functoid.scala | 4 ++-- .../{FunctoidSyntax.scala => SimpleFunctoidSyntax.scala} | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) rename fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/{FunctoidSyntax.scala => SimpleFunctoidSyntax.scala} (52%) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index e021169e13..1d5b8207b8 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -71,9 +71,9 @@ final case class Functoid[+A](get: Provider) extends AbstractFunctoid[A, Functoi object Functoid extends FunctoidMacroMethods[Functoid] with SimpleFunctoids[Functoid] + with SimpleFunctoidSyntax[Functoid] with SimpleDistageFunctoids with FunctoidLifecycleAdapters - with FunctoidConstructors - with FunctoidSyntax[Functoid] { + with FunctoidConstructors { override protected[providers] def create[A](provider: Provider): Functoid[A] = new Functoid[A](provider) } diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/FunctoidSyntax.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala similarity index 52% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/FunctoidSyntax.scala rename to fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala index b81f5f61f8..5e2624a809 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/FunctoidSyntax.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala @@ -2,11 +2,11 @@ package izumi.distage.model.providers import scala.language.implicitConversions -trait FunctoidSyntax[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { - implicit final def syntaxMapSame[A](functoid: Ftoid[A]): FunctoidSyntax.SyntaxMapSame[A, Ftoid] = new FunctoidSyntax.SyntaxMapSame[A, Ftoid](functoid) +trait SimpleFunctoidSyntax[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { + implicit final def syntaxMapSame[A](functoid: Ftoid[A]): SimpleFunctoidSyntax.SyntaxMapSame[A, Ftoid] = new SimpleFunctoidSyntax.SyntaxMapSame[A, Ftoid](functoid) } -object FunctoidSyntax { +object SimpleFunctoidSyntax { final class SyntaxMapSame[A, Ftoid[+K] <: AbstractFunctoid[K, Ftoid]](private val functoid: Ftoid[A]) extends AnyVal { def mapSame(f: A => A): Ftoid[A] = functoid.map(f)(functoid.returnTypeTag) } From 2d9454f732db167f09e4186afb913ada0f6669c3 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 5 Jun 2024 14:27:39 +0100 Subject: [PATCH 37/59] 2.12 fixes --- .../distage/reflection/macros/FunctoidMacro.scala | 2 +- .../izumi/distage/model/providers/Functoid.scala | 2 -- .../universe/basicuniverse/PortableNamedArg.scala | 13 +++++++++++++ .../universe/basicuniverse/PortableNamedArg.scala | 13 +++++++++++++ .../macros/universe}/FunctoidMacroBase.scala | 2 +- .../basicuniverse/BaseReflectionProvider.scala | 0 .../universe/basicuniverse/CompactParameter.scala | 0 .../basicuniverse/ConstructorSelector.scala | 0 .../basicuniverse/DIUniverseBasicLiftables.scala | 0 .../universe/basicuniverse/FriendlyAnnoTools.scala | 13 ++++++++++--- .../macros/universe/basicuniverse/MacroDIKey.scala | 0 .../universe/basicuniverse/MacroSafeType.scala | 0 .../basicuniverse/MacroSymbolInfoCompact.scala | 0 .../basicuniverse/MacroSymbolInfoCompactImpl.scala | 0 14 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 fundamentals/fundamentals-platform/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala create mode 100644 fundamentals/fundamentals-platform/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala rename fundamentals/fundamentals-platform/src/main/{scala/izumi/distage/reflection/macros => scala-2/izumi/distage/reflection/macros/universe}/FunctoidMacroBase.scala (99%) rename fundamentals/fundamentals-platform/src/main/{scala => scala-2}/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala (100%) rename fundamentals/fundamentals-platform/src/main/{scala => scala-2}/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala (100%) rename fundamentals/fundamentals-platform/src/main/{scala => scala-2}/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala (100%) rename fundamentals/fundamentals-platform/src/main/{scala => scala-2}/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala (100%) rename fundamentals/fundamentals-platform/src/main/{scala => scala-2}/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala (86%) rename fundamentals/fundamentals-platform/src/main/{scala => scala-2}/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala (100%) rename fundamentals/fundamentals-platform/src/main/{scala => scala-2}/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala (100%) rename fundamentals/fundamentals-platform/src/main/{scala => scala-2}/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala (100%) rename fundamentals/fundamentals-platform/src/main/{scala => scala-2}/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala (100%) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 5d7abccf5e..5ea7178ff8 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -1,7 +1,7 @@ package izumi.distage.reflection.macros import izumi.distage.model.providers.Functoid -import izumi.distage.reflection.macros.universe.DIAnnotationMeta +import izumi.distage.reflection.macros.universe.{DIAnnotationMeta, FunctoidMacroBase} import scala.reflect.macros.blackbox diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index 1d5b8207b8..a888b41403 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -3,8 +3,6 @@ package izumi.distage.model.providers import izumi.distage.model.reflection.* import izumi.distage.reflection.macros.FunctoidMacroMethods -import scala.language.implicitConversions - /** * A function that receives its arguments from DI object graph, including named instances via [[izumi.distage.model.definition.Id]] annotation. * diff --git a/fundamentals/fundamentals-platform/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala b/fundamentals/fundamentals-platform/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala new file mode 100644 index 0000000000..df141124ce --- /dev/null +++ b/fundamentals/fundamentals-platform/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala @@ -0,0 +1,13 @@ +package izumi.distage.reflection.macros.universe.basicuniverse + +class PortableNamedArg(val u: scala.reflect.api.Universe) { + import u.* + object NArg { + def unapply(tree: TreeApi): Option[(String, Any)] = { + (tree: @unchecked) match { + case AssignOrNamedArg(Ident(TermName(name)), Literal(Constant(c))) => + Some((name, c)) + } + } + } +} diff --git a/fundamentals/fundamentals-platform/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala b/fundamentals/fundamentals-platform/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala new file mode 100644 index 0000000000..ed9ace882c --- /dev/null +++ b/fundamentals/fundamentals-platform/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala @@ -0,0 +1,13 @@ +package izumi.distage.reflection.macros.universe.basicuniverse + +class PortableNamedArg(val u: scala.reflect.api.Universe) { + import u.* + object NArg { + def unapply(tree: TreeApi): Option[(String, Any)] = { + (tree: @unchecked) match { + case NamedArg(Ident(TermName(name)), Literal(Constant(c))) => + Some((name, c)) + } + } + } +} diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/FunctoidMacroBase.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala similarity index 99% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/FunctoidMacroBase.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala index 32de50f914..6fc5e7dd9f 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala @@ -1,4 +1,4 @@ -package izumi.distage.reflection.macros +package izumi.distage.reflection.macros.universe import izumi.distage.model.reflection.Provider import izumi.distage.model.reflection.Provider.ProviderType diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala similarity index 86% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala index b460298183..2efde6fe7f 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala +++ b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala @@ -2,6 +2,10 @@ package izumi.distage.reflection.macros.universe.basicuniverse import izumi.distage.reflection.macros.universe.basicuniverse +import scala.collection.immutable + + + object FriendlyAnnoTools { private def convertConst(c: Any): FriendlyAnnotationValue = { c match { @@ -15,18 +19,21 @@ object FriendlyAnnoTools { FriendlyAnnotationValue.UnknownConst(v) } } + def makeFriendly(u: scala.reflect.api.Universe)(anno: u.Annotation): FriendlyAnnotation = { import u.* + val extractor = new PortableNamedArg(u) val tpe = anno.tree.tpe.finalResultType val annoName = tpe.typeSymbol.fullName val paramTrees = anno.tree.children.tail val avals = if (tpe.typeSymbol.isJavaAnnotation) { - val pairs = paramTrees.map { + val pairs: immutable.List[(Option[String], FriendlyAnnotationValue)] = paramTrees.map { p => - (p: @unchecked) match { - case NamedArg(Ident(TermName(name)), Literal(Constant(c))) => + (p.asInstanceOf[extractor.u.TreeApi]: @unchecked) match { + case extractor.NArg((name, c)) => + // case NamedArg(Ident(TermName(name)), Literal(Constant(c))) => (Some(name), convertConst(c)) case a => (None, FriendlyAnnotationValue.UnknownConst(s"$a ${u.showRaw(a)}")) diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala rename to fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala From 29330e53fa73bde470b5339a4897bd7f061cb1a9 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 5 Jun 2024 14:36:15 +0100 Subject: [PATCH 38/59] wip --- build.sbt | 934 +++++++++++++++--- .../macros/FunctoidMacroMethods.scala | 50 +- .../distage/model/providers/Functoid.scala | 4 +- 3 files changed, 807 insertions(+), 181 deletions(-) diff --git a/build.sbt b/build.sbt index 6f6ffc95d0..8e2025a4f0 100644 --- a/build.sbt +++ b/build.sbt @@ -22,7 +22,7 @@ lazy val `fundamentals-functional` = project.in(file("fundamentals/fundamentals- .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -62,6 +62,26 @@ lazy val `fundamentals-functional` = project.in(file("fundamentals/fundamentals- case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -108,7 +128,7 @@ lazy val `fundamentals-functional` = project.in(file("fundamentals/fundamentals- "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -126,7 +146,7 @@ lazy val `fundamentals-functional` = project.in(file("fundamentals/fundamentals- "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -136,8 +156,12 @@ lazy val `fundamentals-functional` = project.in(file("fundamentals/fundamentals- "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -173,14 +197,14 @@ lazy val `fundamentals-functional` = project.in(file("fundamentals/fundamentals- "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -209,7 +233,7 @@ lazy val `fundamentals-collections` = project.in(file("fundamentals/fundamentals .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -249,6 +273,26 @@ lazy val `fundamentals-collections` = project.in(file("fundamentals/fundamentals case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -295,7 +339,7 @@ lazy val `fundamentals-collections` = project.in(file("fundamentals/fundamentals "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -313,7 +357,7 @@ lazy val `fundamentals-collections` = project.in(file("fundamentals/fundamentals "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -323,8 +367,12 @@ lazy val `fundamentals-collections` = project.in(file("fundamentals/fundamentals "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -360,14 +408,14 @@ lazy val `fundamentals-collections` = project.in(file("fundamentals/fundamentals "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -394,7 +442,7 @@ lazy val `fundamentals-literals` = project.in(file("fundamentals/fundamentals-li .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -434,6 +482,26 @@ lazy val `fundamentals-literals` = project.in(file("fundamentals/fundamentals-li case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -480,7 +548,7 @@ lazy val `fundamentals-literals` = project.in(file("fundamentals/fundamentals-li "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -498,7 +566,7 @@ lazy val `fundamentals-literals` = project.in(file("fundamentals/fundamentals-li "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -508,8 +576,12 @@ lazy val `fundamentals-literals` = project.in(file("fundamentals/fundamentals-li "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -545,14 +617,14 @@ lazy val `fundamentals-literals` = project.in(file("fundamentals/fundamentals-li "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -583,7 +655,7 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -623,6 +695,26 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -669,7 +761,7 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -687,7 +779,7 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -697,8 +789,12 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -734,14 +830,14 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -783,7 +879,7 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -823,6 +919,26 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -869,7 +985,7 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -887,7 +1003,7 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -897,8 +1013,12 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -934,14 +1054,14 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -974,7 +1094,7 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -1014,6 +1134,26 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -1060,7 +1200,7 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -1078,7 +1218,7 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -1088,8 +1228,12 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -1125,14 +1269,14 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -1175,7 +1319,7 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -1215,6 +1359,26 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -1261,7 +1425,7 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -1279,7 +1443,7 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -1289,8 +1453,12 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -1326,14 +1494,14 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -1378,7 +1546,7 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -1418,6 +1586,26 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -1464,7 +1652,7 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -1482,7 +1670,7 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -1492,8 +1680,12 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -1529,14 +1721,14 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -1580,7 +1772,7 @@ lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -1620,6 +1812,26 @@ lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -1666,7 +1878,7 @@ lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -1684,7 +1896,7 @@ lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -1694,8 +1906,12 @@ lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -1731,14 +1947,14 @@ lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -1768,7 +1984,7 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core- .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -1808,6 +2024,26 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core- case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -1854,7 +2090,7 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core- "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -1872,7 +2108,7 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core- "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -1882,8 +2118,12 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core- "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -1919,14 +2159,14 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core- "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -1956,7 +2196,7 @@ lazy val `distage-framework-api` = project.in(file("distage/distage-framework-ap .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -1996,6 +2236,26 @@ lazy val `distage-framework-api` = project.in(file("distage/distage-framework-ap case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -2042,7 +2302,7 @@ lazy val `distage-framework-api` = project.in(file("distage/distage-framework-ap "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -2060,7 +2320,7 @@ lazy val `distage-framework-api` = project.in(file("distage/distage-framework-ap "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -2070,8 +2330,12 @@ lazy val `distage-framework-api` = project.in(file("distage/distage-framework-ap "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -2107,14 +2371,14 @@ lazy val `distage-framework-api` = project.in(file("distage/distage-framework-ap "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -2151,7 +2415,7 @@ lazy val `distage-core` = project.in(file("distage/distage-core")) .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -2191,6 +2455,26 @@ lazy val `distage-core` = project.in(file("distage/distage-core")) case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -2237,7 +2521,7 @@ lazy val `distage-core` = project.in(file("distage/distage-core")) "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -2255,7 +2539,7 @@ lazy val `distage-core` = project.in(file("distage/distage-core")) "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -2265,8 +2549,12 @@ lazy val `distage-core` = project.in(file("distage/distage-core")) "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -2302,14 +2590,14 @@ lazy val `distage-core` = project.in(file("distage/distage-core")) "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -2343,7 +2631,7 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -2383,6 +2671,26 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -2429,7 +2737,7 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -2447,7 +2755,7 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -2457,8 +2765,12 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -2494,14 +2806,14 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -2534,7 +2846,7 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -2574,6 +2886,26 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -2620,7 +2952,7 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -2638,7 +2970,7 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -2648,8 +2980,12 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -2685,14 +3021,14 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -2730,7 +3066,7 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -2770,6 +3106,26 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -2816,7 +3172,7 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -2834,7 +3190,7 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -2844,8 +3200,12 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -2881,14 +3241,14 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -2938,7 +3298,7 @@ lazy val `distage-framework` = project.in(file("distage/distage-framework")) .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -2978,6 +3338,26 @@ lazy val `distage-framework` = project.in(file("distage/distage-framework")) case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -3024,7 +3404,7 @@ lazy val `distage-framework` = project.in(file("distage/distage-framework")) "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -3042,7 +3422,7 @@ lazy val `distage-framework` = project.in(file("distage/distage-framework")) "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -3052,8 +3432,12 @@ lazy val `distage-framework` = project.in(file("distage/distage-framework")) "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -3089,14 +3473,14 @@ lazy val `distage-framework` = project.in(file("distage/distage-framework")) "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -3135,7 +3519,7 @@ lazy val `distage-framework-docker` = project.in(file("distage/distage-framework .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -3175,6 +3559,26 @@ lazy val `distage-framework-docker` = project.in(file("distage/distage-framework case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -3221,7 +3625,7 @@ lazy val `distage-framework-docker` = project.in(file("distage/distage-framework "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -3239,7 +3643,7 @@ lazy val `distage-framework-docker` = project.in(file("distage/distage-framework "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -3249,8 +3653,12 @@ lazy val `distage-framework-docker` = project.in(file("distage/distage-framework "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -3286,14 +3694,14 @@ lazy val `distage-framework-docker` = project.in(file("distage/distage-framework "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -3322,7 +3730,7 @@ lazy val `distage-testkit-core` = project.in(file("distage/distage-testkit-core" .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -3362,6 +3770,26 @@ lazy val `distage-testkit-core` = project.in(file("distage/distage-testkit-core" case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -3408,7 +3836,7 @@ lazy val `distage-testkit-core` = project.in(file("distage/distage-testkit-core" "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -3426,7 +3854,7 @@ lazy val `distage-testkit-core` = project.in(file("distage/distage-testkit-core" "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -3436,8 +3864,12 @@ lazy val `distage-testkit-core` = project.in(file("distage/distage-testkit-core" "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -3473,14 +3905,14 @@ lazy val `distage-testkit-core` = project.in(file("distage/distage-testkit-core" "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -3518,7 +3950,7 @@ lazy val `distage-testkit-scalatest` = project.in(file("distage/distage-testkit- .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -3558,6 +3990,26 @@ lazy val `distage-testkit-scalatest` = project.in(file("distage/distage-testkit- case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -3604,7 +4056,7 @@ lazy val `distage-testkit-scalatest` = project.in(file("distage/distage-testkit- "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -3622,7 +4074,7 @@ lazy val `distage-testkit-scalatest` = project.in(file("distage/distage-testkit- "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -3632,8 +4084,12 @@ lazy val `distage-testkit-scalatest` = project.in(file("distage/distage-testkit- "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -3669,14 +4125,14 @@ lazy val `distage-testkit-scalatest` = project.in(file("distage/distage-testkit- "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -3706,7 +4162,7 @@ lazy val `distage-testkit-scalatest-sbt-module-filtering-test` = project.in(file .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -3746,6 +4202,26 @@ lazy val `distage-testkit-scalatest-sbt-module-filtering-test` = project.in(file case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -3792,7 +4268,7 @@ lazy val `distage-testkit-scalatest-sbt-module-filtering-test` = project.in(file "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -3810,7 +4286,7 @@ lazy val `distage-testkit-scalatest-sbt-module-filtering-test` = project.in(file "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -3820,8 +4296,12 @@ lazy val `distage-testkit-scalatest-sbt-module-filtering-test` = project.in(file "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -3857,14 +4337,14 @@ lazy val `distage-testkit-scalatest-sbt-module-filtering-test` = project.in(file "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -3900,7 +4380,7 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core")) .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -3940,6 +4420,26 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core")) case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -3986,7 +4486,7 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core")) "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -4004,7 +4504,7 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core")) "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -4014,8 +4514,12 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core")) "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -4051,14 +4555,14 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core")) "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -4093,7 +4597,7 @@ lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-renderi .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -4133,6 +4637,26 @@ lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-renderi case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -4179,7 +4703,7 @@ lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-renderi "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -4197,7 +4721,7 @@ lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-renderi "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -4207,8 +4731,12 @@ lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-renderi "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -4244,14 +4772,14 @@ lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-renderi "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -4281,7 +4809,7 @@ lazy val `logstage-adapter-slf4j` = project.in(file("logstage/logstage-adapter-s .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -4321,6 +4849,26 @@ lazy val `logstage-adapter-slf4j` = project.in(file("logstage/logstage-adapter-s case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -4367,7 +4915,7 @@ lazy val `logstage-adapter-slf4j` = project.in(file("logstage/logstage-adapter-s "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -4385,7 +4933,7 @@ lazy val `logstage-adapter-slf4j` = project.in(file("logstage/logstage-adapter-s "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -4395,8 +4943,12 @@ lazy val `logstage-adapter-slf4j` = project.in(file("logstage/logstage-adapter-s "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -4432,14 +4984,14 @@ lazy val `logstage-adapter-slf4j` = project.in(file("logstage/logstage-adapter-s "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -4473,7 +5025,7 @@ lazy val `logstage-sink-slf4j` = project.in(file("logstage/logstage-sink-slf4j") .settings( crossScalaVersions := Seq( "3.4.1", - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -4513,6 +5065,26 @@ lazy val `logstage-sink-slf4j` = project.in(file("logstage/logstage-sink-slf4j") case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -4559,7 +5131,7 @@ lazy val `logstage-sink-slf4j` = project.in(file("logstage/logstage-sink-slf4j") "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -4577,7 +5149,7 @@ lazy val `logstage-sink-slf4j` = project.in(file("logstage/logstage-sink-slf4j") "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -4587,8 +5159,12 @@ lazy val `logstage-sink-slf4j` = project.in(file("logstage/logstage-sink-slf4j") "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -4624,14 +5200,14 @@ lazy val `logstage-sink-slf4j` = project.in(file("logstage/logstage-sink-slf4j") "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -4691,7 +5267,7 @@ lazy val `microsite` = project.in(file("doc/microsite")) ) .settings( crossScalaVersions := Seq( - "2.13.13", + "2.13.14", "2.12.19" ), scalaVersion := crossScalaVersions.value.head, @@ -4731,6 +5307,26 @@ lazy val `microsite` = project.in(file("doc/microsite")) case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -4777,7 +5373,7 @@ lazy val `microsite` = project.in(file("doc/microsite")) "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -4795,7 +5391,7 @@ lazy val `microsite` = project.in(file("doc/microsite")) "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -4805,8 +5401,12 @@ lazy val `microsite` = project.in(file("doc/microsite")) "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -4842,14 +5442,14 @@ lazy val `microsite` = project.in(file("doc/microsite")) "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", @@ -4979,6 +5579,26 @@ lazy val `sbt-izumi-deps` = project.in(file("sbt-plugins/sbt-izumi-deps")) case _ => Seq.empty } }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, Test / testOptions += Tests.Argument("-oDF"), scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { case (_, "2.12.19") => Seq( @@ -5025,7 +5645,7 @@ lazy val `sbt-izumi-deps` = project.in(file("sbt-plugins/sbt-izumi-deps")) "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified" ) - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Wconf:any:error", "-release:8", "-explaintypes", @@ -5043,7 +5663,7 @@ lazy val `sbt-izumi-deps` = project.in(file("sbt-plugins/sbt-izumi-deps")) "-Woctal-literal", "-Wvalue-discard", "-Wunused:_", - "-Wmacros:after", + "-Wmacros:default", "-Ycache-plugin-class-loader:always", "-Ycache-macro-class-loader:last-modified", "-Wunused:-synthetics" @@ -5053,8 +5673,12 @@ lazy val `sbt-izumi-deps` = project.in(file("sbt-plugins/sbt-izumi-deps")) "-language:3.4", "-release:8", "-Ykind-projector:underscores", + "-Yretain-trees", "-no-indent", - "-explain" + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" ) case (_, _) => Seq.empty } }, @@ -5090,14 +5714,14 @@ lazy val `sbt-izumi-deps` = project.in(file("sbt-plugins/sbt-izumi-deps")) "-opt:l:inline", "-opt-inline-from:izumi.**" ) - case (false, "2.13.13") => Seq( + case (false, "2.13.14") => Seq( "-opt:l:inline", "-opt-inline-from:izumi.**" ) case (_, _) => Seq.empty } }, scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { - case (_, "2.13.13") => Seq( + case (_, "2.13.14") => Seq( "-Xsource:3", "-Xmigration", "-Wconf:cat=scala3-migration:silent", diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index 93aaf17289..dbe7f7743f 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -1,30 +1,32 @@ package izumi.distage.reflection.macros +import izumi.distage.model.providers.Functoid + import scala.language.experimental.macros import scala.language.implicitConversions -trait FunctoidMacroMethods[Ftoid[+_]] { - implicit def apply[R](fun: () => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Ftoid[R] = macro FunctoidMacro.impl[R, Ftoid] +trait FunctoidMacroMethods { + implicit def apply[R](fun: () => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index a888b41403..4b3e8329a6 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -67,11 +67,11 @@ final case class Functoid[+A](get: Provider) extends AbstractFunctoid[A, Functoi } object Functoid - extends FunctoidMacroMethods[Functoid] - with SimpleFunctoids[Functoid] + extends SimpleFunctoids[Functoid] with SimpleFunctoidSyntax[Functoid] with SimpleDistageFunctoids with FunctoidLifecycleAdapters + with FunctoidMacroMethods with FunctoidConstructors { override protected[providers] def create[A](provider: Provider): Functoid[A] = new Functoid[A](provider) } From ef13416f75cd69231e47a00e640d00bae255a286 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 5 Jun 2024 14:42:43 +0100 Subject: [PATCH 39/59] scala 3 fixed --- .../dsl/AbstractBindingDefDSL.scala | 4 +-- .../model/providers/AbstractFunctoid.scala | 32 ++++++++----------- .../model/providers/SimpleFunctoids.scala | 4 +-- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala index 1fa52b0391..065cfcca2f 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala @@ -162,7 +162,7 @@ trait AbstractBindingDefDSL[BindDSL[_], BindDSLAfterFrom[_], SetDSL[_]] extends case tpeKey: DIKey.TypeKey => tpeKey -> None case idKey @ DIKey.IdKey(tpe, id, m) => DIKey.TypeKey(tpe, m) -> Some(Identifier.fromIdContract(id)(idKey.idContract)) } - val newProvider: Functoid[T] = f(Functoid.identityKey(key).asInstanceOf[Functoid[T]]) + val newProvider: Functoid[T] = f(Functoid.identityKey[T](key)) val binding = SingletonBinding(tpeKey, ImplDef.ProviderImpl(newProvider.get.ret, newProvider.get), Set.empty, pos.get.position, isMutator = true) val ref = _registered(new SingletonRef(binding)) maybeId.foreach(ref `append` SetId(_)) @@ -415,7 +415,7 @@ object AbstractBindingDefDSL { } case _ => // add an independent mutator instead of modifying the original functoid, if no original functoid is available - val newProvider = functoidModifier(Functoid.identityKey(b.key).asInstanceOf[Functoid[t]]).get + val newProvider = functoidModifier(Functoid.identityKey[t](b.key)).get val newRef = SingletonBinding(b.key, ImplDef.ProviderImpl(newProvider.ret, newProvider), Set.empty, b.origin, isMutator = true) refs = newRef :: refs } diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala index bd3450f383..09c02d2ce8 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala @@ -8,17 +8,17 @@ import izumi.reflect.Tag import scala.annotation.unchecked.uncheckedVariance import scala.annotation.unused -trait AbstractFunctoid[+A, Self[+K] <: AbstractFunctoid[K, Self]] { +trait AbstractFunctoid[+A, Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { def get: Provider - protected def create[B](provider: Provider): Self[B] + protected def create[B](provider: Provider): Ftoid[B] - def map[B: Tag](f: A => B): Self[B] = { + def map[B: Tag](f: A => B): Ftoid[B] = { create[B](get.unsafeMap(SafeType.get[B], (any: Any) => f(any.asInstanceOf[A]))) } - def zip[B](that: Self[B]): Self[(A, B)] = { + def zip[B](that: Ftoid[B]): Ftoid[(A, B)] = { implicit val tagA: Tag[A] = this.returnTypeTag implicit val tagB: Tag[B] = that.returnTypeTag tagA.discard() // used for assembling Tag[(A, B)] below @@ -26,7 +26,7 @@ trait AbstractFunctoid[+A, Self[+K] <: AbstractFunctoid[K, Self]] { create[(A, B)](get.unsafeZip(SafeType.get[(A, B)], that.get)) } - def map2[B, C: Tag](that: Self[B])(f: (A, B) => C): Self[C] = { + def map2[B, C: Tag](that: Ftoid[B])(f: (A, B) => C): Ftoid[C] = { zip(that).map[C](f.tupled) } @@ -40,7 +40,7 @@ trait AbstractFunctoid[+A, Self[+K] <: AbstractFunctoid[K, Self]] { * this.map2(that)((a, f) => f(a)) * }}} */ - def flatAp[B: Tag](that: Self[A => B]): Self[B] = { + def flatAp[B: Tag](that: Ftoid[A => B]): Ftoid[B] = { map2(that)((a, f) => f(a)) } @@ -52,22 +52,22 @@ trait AbstractFunctoid[+A, Self[+K] <: AbstractFunctoid[K, Self]] { * this.map2(that)((f, a) => f(a)) * }}} */ - def ap[B, C](that: Self[B])(implicit @unused ev: A <:< (B => C), tag: Tag[C]): Self[C] = { + def ap[B, C](that: Ftoid[B])(implicit @unused ev: A <:< (B => C), tag: Tag[C]): Ftoid[C] = { map2(that)((f, a) => f.asInstanceOf[B => C](a)) } /** Add `B` as an unused dependency of this Functoid */ - def addDependency[B: Tag]: Self[A] = addDependency(DIKey[B]) - def addDependency[B: Tag](name: Identifier): Self[A] = addDependency(DIKey[B](name)) - def addDependency(key: DIKey): Self[A] = addDependencies(key :: Nil) - def addDependencies(keys: Iterable[DIKey]): Self[A] = create[A](get.addUnused(keys)) + def addDependency[B: Tag]: Ftoid[A] = addDependency(DIKey[B]) + def addDependency[B: Tag](name: Identifier): Ftoid[A] = addDependency(DIKey[B](name)) + def addDependency(key: DIKey): Ftoid[A] = addDependencies(key :: Nil) + def addDependencies(keys: Iterable[DIKey]): Ftoid[A] = create[A](get.addUnused(keys)) /** * Add an `@Id` annotation to an unannotated parameter `P`, e.g. * for .annotateParameter("x"), transform lambda `(p: P) => x(p)` * into `(p: P @Id("x")) => x(p)` */ - def annotateParameter[P: Tag](name: Identifier): Self[A] = { + def annotateParameter[P: Tag](name: Identifier): Ftoid[A] = { val paramTpe = SafeType.get[P] annotateParameterWhen(name) { case DIKey.TypeKey(tpe, _) => tpe == paramTpe @@ -75,14 +75,14 @@ trait AbstractFunctoid[+A, Self[+K] <: AbstractFunctoid[K, Self]] { } } /** Add an `@Id(name)` annotation to all unannotated parameters */ - def annotateAllParameters(name: Identifier): Self[A] = { + def annotateAllParameters(name: Identifier): Ftoid[A] = { annotateParameterWhen(name) { case _: DIKey.TypeKey => true case _: DIKey.IdKey[?] => false } } /** Add an `@Id(name)` annotation to all parameters matching `predicate` */ - def annotateParameterWhen(name: Identifier)(predicate: DIKey.BasicKey => Boolean): Self[A] = { + def annotateParameterWhen(name: Identifier)(predicate: DIKey.BasicKey => Boolean): Ftoid[A] = { val newProvider = this.get.replaceKeys { case k: DIKey.BasicKey if predicate(k) => DIKey.IdKey(k.tpe, name.id, k.mutatorIndex)(name.idContract) @@ -93,7 +93,3 @@ trait AbstractFunctoid[+A, Self[+K] <: AbstractFunctoid[K, Self]] { def returnTypeTag: Tag[A @uncheckedVariance] = Tag(get.ret.closestClass, get.ret.tag) } - -final case class BaseFunctoid[+A](get: Provider) extends AbstractFunctoid[A, BaseFunctoid] { - override protected def create[B](provider: Provider): BaseFunctoid[B] = copy(get = provider) -} diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala index 77bdc93862..eba74cbfc7 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala @@ -54,11 +54,11 @@ private[providers] trait SimpleFunctoids[Ftoid[+_]] { ) } - def identityKey(key: DIKey): Ftoid[?] = { + def identityKey[A](key: DIKey): Ftoid[A] = { val tpe = key.tpe val symbolInfo = firstParamSymbolInfo(tpe) - create( + create[A]( Provider.ProviderImpl( parameters = Seq(LinkedParameter(symbolInfo, key)), ret = tpe, From b4529476513703e4356a72cfb3317dec7617e560 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 5 Jun 2024 15:46:35 +0100 Subject: [PATCH 40/59] wip --- .../dsl/AbstractBindingDefDSLMacro.scala | 2 +- .../ReflectionProviderDefaultImpl.scala | 22 +- .../universe/impl/WithDISymbolInfo.scala | 2 +- .../dsl/AbstractBindingDefDSLMacro.scala | 2 +- .../reflection/macros/FunctoidMacroBase.scala | 247 ++++++++++++++ .../macros/FunctoidMacroMethods.scala | 309 +----------------- .../macros/FunctoidMacroMethodsBase.scala | 58 ++++ .../scala/izumi/distage/AbstractLocator.scala | 2 +- .../distage/model/definition/LocatorDef.scala | 6 +- .../dsl/AbstractBindingDefDSL.scala | 66 ++-- .../model/definition/dsl/IncludesDSL.scala | 8 +- .../model/definition/dsl/ModuleDefDSL.scala | 46 +-- .../model/definition/dsl/TagsDSL.scala | 6 +- .../model/definition/errors/DIError.scala | 2 +- .../errors/DIFailureInterpreter.scala | 2 +- .../distage/model/plan/ExecutableOp.scala | 2 +- .../model/plan/repr/BindingFormatter.scala | 2 +- .../model/plan/repr/KeyMinimizer.scala | 12 +- .../model/planning/ActivationChoices.scala | 4 +- .../proxies/ProxyDispatcher.scala | 2 +- .../ByteBuddyAtomicRefDispatcher.scala | 2 +- .../compat/CatsIOPlatformDependentTest.scala | 2 +- .../extensions/GraphDumpObserver.scala | 4 +- .../compat/CatsIOPlatformDependentTest.scala | 2 +- .../src/main/scala/distage/Injector.scala | 12 +- .../izumi/distage/InjectorDefaultImpl.scala | 10 +- .../scala/izumi/distage/InjectorFactory.scala | 4 +- .../distage/bootstrap/BootstrapLocator.scala | 4 +- .../scala/izumi/distage/model/Injector.scala | 4 +- .../distage/planning/BindingTranslator.scala | 10 +- .../distage/planning/PlannerDefaultImpl.scala | 6 +- .../ForwardingRefResolverDefaultImpl.scala | 4 +- .../solver/GenericSemigraphTraverse.scala | 2 +- .../planning/solver/GraphQueries.scala | 2 +- .../distage/planning/solver/PlanSolver.scala | 2 +- .../planning/solver/PlanVerifier.scala | 16 +- .../provisioning/OperationExecutorImpl.scala | 2 +- ...nInterpreterNonSequentialRuntimeImpl.scala | 14 +- .../distage/config/codec/DIConfigReader.scala | 2 +- .../load/PluginLoaderDefaultImpl.scala | 2 +- .../izumi/distage/plugins/PluginConfig.scala | 2 +- .../model/definition/RoleModuleDef.scala | 2 +- .../model/definition/RoleModuleDef.scala | 2 +- .../distage/docker/ContainerNetworkDef.scala | 8 +- .../distage/docker/DockerContainer.scala | 2 +- .../docker/impl/ContainerResource.scala | 20 +- .../docker/impl/DockerClientWrapper.scala | 2 +- .../fixtures/ReusedOneshotContainer.scala | 2 +- .../framework/PlanCheckMaterializer.scala | 2 +- .../framework/PlanCheckMaterializer.scala | 2 +- .../distage/framework/CheckableApp.scala | 6 +- .../izumi/distage/framework/PlanCheck.scala | 14 +- .../framework/services/ResourceRewriter.scala | 2 +- .../distage/roles/bundled/ConfigWriter.scala | 10 +- .../izumi/distage/roles/bundled/Help.scala | 2 +- .../roles/launcher/ActivationParser.scala | 2 +- .../roles/launcher/LogConfigLoader.scala | 2 +- .../framework/services/RoleAppPlanner.scala | 2 +- .../roles/launcher/AppShutdownStrategy.scala | 4 +- .../launcher/RoleAppActivationParser.scala | 2 +- .../distage/roles/launcher/RoleProvider.scala | 8 +- .../roles/launcher/StartupBanner.scala | 2 +- .../runner/impl/DistageTestRunner.scala | 2 +- .../testkit/runner/impl/TestPlanner.scala | 4 +- .../testkit/runner/impl/TestTreeBuilder.scala | 4 +- .../dstest/DistageAbstractScalatestSpec.scala | 12 +- .../DistageTestsRegistrySingleton.scala | 20 +- .../scalatest/dstest/SafeTestReporter.scala | 4 +- .../distage/DistageScalatestReporter.scala | 2 +- .../DistageScalatestTestSuiteRunner.scala | 2 +- .../testkit/distagesuite/generic/tests.scala | 2 +- .../parallel/DistageParallelLevelTest.scala | 8 +- .../DistageSequentialSuitesTest.scala | 8 +- .../functional/bio/laws/env/EqThrowable.scala | 2 +- .../functional/bio/laws/env/MiniBIOEnv.scala | 2 +- .../functional/bio/CatsConversions.scala | 4 +- .../functional/bio/DivergenceHelper.scala | 4 +- .../bio/ErrorAccumulatingOps2.scala | 2 +- .../main/scala/izumi/functional/bio/IO2.scala | 2 +- .../izumi/functional/bio/impl/BioEither.scala | 2 +- .../bio/impl/PrimitivesFromBIOAndCats.scala | 4 +- .../functional/bio/impl/SchedulerImpl.scala | 2 +- .../functional/bio/retry/RetryPolicy.scala | 2 +- .../izumi/functional/bio/syntax/Syntax2.scala | 28 +- .../functional/lifecycle/Lifecycle.scala | 10 +- .../lifecycle/LifecycleAggregator.scala | 2 +- .../lifecycle/LifecycleMethodImpls.scala | 4 +- .../izumi/functional/quasi/QuasiIO.scala | 4 +- .../fundamentals/graphs/tools/Toposort.scala | 6 +- .../json/flat/JsonFlattener.scala | 4 +- .../json/circe/WithCirceTest.scala | 2 +- .../platform/language/ScalaRelease.scala | 4 +- .../platform/language/newtype.scala | 2 +- .../macros/universe/FunctoidMacroBase.scala | 8 +- .../BaseReflectionProvider.scala | 2 +- .../basicuniverse/ConstructorSelector.scala | 4 +- .../model/providers/SimpleFunctoids.scala | 2 +- .../distage/model/reflection/Provider.scala | 2 +- .../platform/cache/SyncCache.scala | 4 +- .../platform/cli/CLIParserImpl.scala | 2 +- .../platform/cli/ParserFailureHandler.scala | 2 +- .../platform/cli/model/schema/ParserDef.scala | 4 +- .../model/schema/ParserSchemaFormatter.scala | 8 +- .../platform/console/TrivialLogger.scala | 10 +- .../platform/exceptions/IzThrowable.scala | 2 +- .../platform/properties/DebugProperties.scala | 4 +- .../adapter/slf4j/LogstageSlf4jLogger.scala | 2 +- .../adapter/jul/LogstageJulLogger.scala | 4 +- .../macros/ArgumentNameExtractionMacro.scala | 14 +- .../logstage/macros/LogIOMacroMethods.scala | 2 +- .../logstage/macros/LogMessageMacro.scala | 6 +- .../logstage/macros/LoggerMacroMethods.scala | 2 +- .../logstage/api/IzLoggerConvenienceApi.scala | 2 +- .../api/rendering/LogstageReprWriter.scala | 2 +- .../api/rendering/logunits/LogFormat.scala | 14 +- .../api/routing/LogConfigServiceImpl.scala | 6 +- .../src/main/scala/logstage/LogZIO.scala | 8 +- .../main/scala/logstage/LogstageCats.scala | 8 +- .../scala/logstage/strict/LogZIOStrict.scala | 8 +- .../logstage/strict/LogstageCatsStrict.scala | 8 +- 120 files changed, 668 insertions(+), 640 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala create mode 100644 distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethodsBase.scala diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala index 40d92651f6..06f0c4b41e 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala @@ -4,5 +4,5 @@ import izumi.distage.reflection.macros.constructors.MakeMacro import scala.language.experimental.macros trait AbstractBindingDefDSLMacro[BindDSL[_]] { - final protected[this] def make[T]: BindDSL[T] = macro MakeMacro.make[BindDSL, T] + final protected def make[T]: BindDSL[T] = macro MakeMacro.make[BindDSL, T] } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index fe25d4f091..d70569fe12 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -23,7 +23,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { private lazy val idAnnotationFqn = new DIAnnotationMeta(u.u).idAnnotationFqn private lazy val brp = new BaseReflectionProvider(u.ctx.universe, idAnnotationFqn) - private[this] object With { + private object With { def unapply(ann: Annotation): Option[TypeNative] = { ann.tree.tpe.typeArgs.headOption } @@ -52,7 +52,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { selectConstructorArguments(tpe).toList.flatten.map(_.map(parameterToAssociation)) } - private[this] def mkConstructorWiring(factoryMethod: SymbNative, tpe: TypeNative): MacroWiring.MacroSingletonWiring = { + private def mkConstructorWiring(factoryMethod: SymbNative, tpe: TypeNative): MacroWiring.MacroSingletonWiring = { def getPrefix(tpe: TypeNative): Option[MacroDIKey] = { if (tpe.typeSymbol.isStatic) { None @@ -98,7 +98,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } } - private[this] def resultOfFactoryMethod(symbolInfo: MacroSymbolInfo): TypeNative = { + private def resultOfFactoryMethod(symbolInfo: MacroSymbolInfo): TypeNative = { symbolInfo.findUniqueAnnotation(typeOfWithAnnotation) match { case Some(With(tpe)) => tpe @@ -107,7 +107,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } } - private[this] def traitMethods(tpe: TypeNative): List[Association.AbstractMethod] = { + private def traitMethods(tpe: TypeNative): List[Association.AbstractMethod] = { // empty paramLists means parameterless method, List(List()) means nullarg unit method() val declaredAbstractMethods = tpe.members.sorted // preserve same order as definition ordering because we implicitly depend on it elsewhere .filter(isWireableMethod) @@ -153,20 +153,20 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { MacroWiring.Factory.FactoryMethod(factoryMethodSymb, resultTypeWiring, alreadyInSignature) } - private[this] def methodToAssociation(definingClass: TypeNative, method: MethodSymbNative): Association.AbstractMethod = { + private def methodToAssociation(definingClass: TypeNative, method: MethodSymbNative): Association.AbstractMethod = { val methodSymb = MacroSymbolInfo.Runtime(method, definingClass, wasGeneric = false) Association.AbstractMethod(methodSymb, brp.tpeFromSymbol(methodSymb), brp.keyFromSymbol(methodSymb)) } - private[this] object ConcreteSymbol { + private object ConcreteSymbol { def unapply(arg: TypeNative): Option[TypeNative] = Some(arg).filter(isConcrete) } - private[this] object AbstractSymbol { + private object AbstractSymbol { def unapply(arg: TypeNative): Option[TypeNative] = Some(arg).filter(isWireableAbstract) } - private[this] object FactorySymbol { + private object FactorySymbol { def unapply(arg: TypeNative): Option[(List[SymbNative], List[MethodSymbNative])] = { Some(arg) .filter(isFactory) @@ -175,7 +175,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } // symbolintrospector - private[this] def selectConstructorArguments(tpe: TypeNative): Option[List[List[MacroSymbolInfo]]] = { + private def selectConstructorArguments(tpe: TypeNative): Option[List[List[MacroSymbolInfo]]] = { selectConstructorMethod(tpe).map { selectedConstructor => val originalParamListTypes = selectedConstructor.paramLists.map(_.map(_.typeSignature)) @@ -240,11 +240,11 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } } - private[this] def isWireableMethod(decl: SymbNative): Boolean = { + private def isWireableMethod(decl: SymbNative): Boolean = { decl.isMethod && decl.isAbstract && !decl.isSynthetic && decl.owner != u.u.definitions.AnyClass && decl.asMethod.paramLists.isEmpty } - private[this] def isFactoryMethod(decl: SymbNative): Boolean = { + private def isFactoryMethod(decl: SymbNative): Boolean = { decl.isMethod && decl.isAbstract && !decl.isSynthetic && decl.owner != u.u.definitions.AnyClass } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index 60c2f49113..0a84bd3d50 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -124,7 +124,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => findAnnotation(annType) } - private[this] def findAnnotation(tgtAnnType: TypeNative): Option[u.Annotation] = { + private def findAnnotation(tgtAnnType: TypeNative): Option[u.Annotation] = { val r = symbolInfo.annotations.find(a => AnnotationTools.annotationTypeEq(u)(tgtAnnType, a)) r } diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala index 4d456aba69..10164499a1 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/model/definition/dsl/AbstractBindingDefDSLMacro.scala @@ -3,5 +3,5 @@ package izumi.distage.model.definition.dsl import izumi.distage.constructors.MakeMacro trait AbstractBindingDefDSLMacro[BindDSL[_]] { - inline final protected[this] def make[T]: BindDSL[T] = ${ MakeMacro.makeMethod[T, BindDSL[T]] } + inline final protected def make[T]: BindDSL[T] = ${ MakeMacro.makeMethod[T, BindDSL[T]] } } diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala new file mode 100644 index 0000000000..7421bc83d8 --- /dev/null +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala @@ -0,0 +1,247 @@ +package izumi.distage.reflection.macros + +import izumi.distage.model.definition.Id +import izumi.distage.model.providers.AbstractFunctoid +import izumi.distage.model.reflection.* +import izumi.fundamentals.platform.reflection.ReflectionUtil +import izumi.reflect.Tag + +import scala.annotation.tailrec +import scala.collection.immutable.{List, Seq} +import scala.language.implicitConversions +import scala.quoted.{Expr, Quotes, Type} + +trait FunctoidMacroBase[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { + protected def generateFunctoid[R: Type, Q <: Quotes](paramDefs: List[Expr[LinkedParameter]], originalFun: Expr[AnyRef])(using qctx: Q): Expr[Ftoid[R]] + + protected def generateSafeType[R: Type, Q <: Quotes](using qctx: Q): Expr[SafeType] = { + new FunctoidParametersMacro[qctx.type]().safeType[R] + } + + protected def generateRawFnCall[Q <: Quotes](argsCount: Int, rawFn: Expr[Any], args: Expr[Seq[Any]])(using qctx: Q): Expr[Any] = { + import qctx.reflect.* + + val params = List.tabulate(argsCount) { + idx => + '{ $args(${ Expr(idx) }) } + } + + val anyTpe = TypeRepr.of[Any] + val fnType = defn.FunctionClass(argsCount).typeRef.appliedTo(List.fill(argsCount + 1)(anyTpe)) + + val fnAny = fnType.asType match { + case '[a] => + '{ ${ rawFn.asExprOf[Any] }.asInstanceOf[a] } + case _ => + report.errorAndAbort(s"This is totally unexpected: ${fnType.show} type is higher-kinded type constructor, but expected a proper type") + } + + Select.unique(fnAny.asTerm, "apply").appliedToArgs(params.map(_.asTerm)).asExprOf[Any] + } + + final class FunctoidMacroImpl[Q <: Quotes](using val qctx: Q) { + + import qctx.reflect.* + + private val paramsMacro = new FunctoidParametersMacro[qctx.type]() + + def make[R: Type](fun: Expr[AnyRef]): Expr[Ftoid[R]] = { + val parameters = analyze(fun.asTerm) + val out = generateFunctoid[R, Q](parameters, fun) + + // report.warning( + // s"""fun=${fun.show} + // |funType=${fun.asTerm.tpe} + // |funSym=${fun.asTerm.symbol} + // |funTypeSym=${fun.asTerm.tpe.typeSymbol} + // |funTypeSymBases=${fun.asTerm.tpe.baseClasses} + // |outputType=${Type.show[R]} + // |rawOutputType=(${TypeRepr.of[R]}) + // |produced=${out.show}""".stripMargin + // ) + + out + } + + @tailrec def analyze(fun: Term): List[Expr[LinkedParameter]] = fun match { + case Block(List(DefDef(name, (singleParamList: TermParamClause) :: Nil, _, Some(body))), Closure(_, _)) => + analyzeLambdaOrMethodRef(name, singleParamList, body) + case Typed(term, _) => + analyze(term) + case Inlined(_, _, term) => + analyze(term) + case Block(List(), term) => + analyze(term) + case otherExpr => + analyzeTypeOfExpr(otherExpr) + } + + private def analyzeLambdaOrMethodRef(name: String, singleParamList: TermParamClause, body: Term): List[Expr[LinkedParameter]] = { + val methodRefParams = { + @tailrec + def go(t: Tree): List[Symbol] = t match { + case Apply(f, args) if args.map(_.symbol) == singleParamList.params.map(_.symbol) => + f.symbol.paramSymss.filterNot(_.headOption.exists(_.isTypeParam)).flatten + case Inlined(_, _, term) => go(term) + case Block(List(), term) => go(term) + case Typed(term, _) => go(term) + case _ => Nil + } + + go(body) + } + + val annotationsOnMethodAreNonEmptyAndASuperset = { + methodRefParams.sizeCompare(singleParamList.params) == 0 + && methodRefParams.exists(_.annotations.nonEmpty) + } + + // report.info( + // s"""mrefparams = $methodRefParams + // |termclause = $singleParamList + // |body=$body + // |sym=${body match { case Apply(f, _) => f.symbol -> f.symbol.paramSymss; case _ => None }} + // |verdict=$annotationsOnMethodAreNonEmptyAndASuperset + // |""".stripMargin + // ) + + // if method reference has more annotations, get parameters from reference instead + // to preserve annotations! + if (annotationsOnMethodAreNonEmptyAndASuperset) { + // Use types from the generated lambda, not the method reference, because method reference types maybe generic/unresolved/unrelated + // But lambda params should be sufficiently 'grounded' at this point + // (Besides, lambda types are the ones specified by the caller, we should respect them) + singleParamList.params.zip(methodRefParams).map { + case (ValDef(name, tpeTree, _), mSym) => + paramsMacro.makeParam(name, Left(tpeTree), Some(mSym), Right(mSym.owner.typeRef.memberType(mSym))) + } + } else { + singleParamList.params.map { + case valDef @ ValDef(name, tpeTree, _) => + paramsMacro.makeParam(name, Left(tpeTree), Some(valDef.symbol).filterNot(_.isNoSymbol)) + } + } + } + + private def analyzeTypeOfExpr(other: Term): List[Expr[LinkedParameter]] = { + val rawTpe = other.underlying.tpe + val functionTpe = rawTpe.baseClasses.find(_.fullName.startsWith("scala.Function")) match { + case Some(fn) => + rawTpe.baseType(fn) + case None => + report.errorAndAbort(s"Could not find scala.Function* base class for ${rawTpe.show} - not a function! baseClasses were: ${rawTpe.baseClasses}") + } + + functionTpe.typeArgs match { + case Nil => Nil + case o => + val args = o.init + args.iterator.zipWithIndex.map { + (tpe, idx) => + paramsMacro.makeParam(s"arg_$idx", Right(tpe), None) + }.toList + } + } + + } + + final class FunctoidParametersMacro[Q <: Quotes](using val qctx: Q) { + + import qctx.reflect.* + + private val idAnnotationSym: Symbol = TypeRepr.of[Id].typeSymbol + private val maybeJavaxNamedAnnotationSym: Option[Symbol] = scala.util.Try(Symbol.requiredClass("javax.inject.Named")).toOption + + extension (t: Either[TypeTree, TypeRepr]) { + private def _tpe: TypeRepr = t match { + case Right(t) => t + case Left(t) => t.tpe + } + } + + def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol]): Expr[LinkedParameter] = { + makeParam(name, tpe, annotSym, tpe) + } + + def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol], annotTpe: Either[TypeTree, TypeRepr]): Expr[LinkedParameter] = { + val identifier = { + val mbIdIdentifier = ReflectionUtil + .readTypeOrSymbolDIAnnotation(idAnnotationSym)(name, annotSym, annotTpe) { + case aterm @ Apply(Select(New(_), _), c :: _) => + c.asExprOf[String].value.orElse { + report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") + } + case aterm => + report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") + } + mbIdIdentifier.orElse { + maybeJavaxNamedAnnotationSym.flatMap { + namedAnnoSym => + ReflectionUtil.readTypeOrSymbolDIAnnotation(namedAnnoSym)(name, annotSym, annotTpe) { + case aterm @ Apply(Select(New(_), _), c :: _) => + c.asExprOf[String].value.orElse { + report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") + } + case aterm => + report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") + } + } + } + } + + val tpeRepr = tpe._tpe + + val isByName = tpeRepr match { + case ByNameType(_) => true + case _ => false + } + + val wasGeneric = tpeRepr.typeSymbol.isTypeParam // deem abstract type members as generic? No. Because we don't do that in Scala 2 version. + + '{ + LinkedParameter( + SymbolInfo( + name = ${ Expr(name) }, + finalResultType = ${ safeTypeFromRepr(tpeRepr) }, + isByName = ${ Expr(isByName) }, + wasGeneric = ${ Expr(wasGeneric) }, + ), + ${ makeKeyFromRepr(tpeRepr, identifier) }, + ) + } + } + + def safeType[R: Type]: Expr[SafeType] = { + '{ SafeType.get[R](using scala.compiletime.summonInline[Tag[R]]) } + } + + private def makeKeyFromRepr(tpe: TypeRepr, id: Option[String]): Expr[DIKey] = { + val safeTpe = safeTypeFromRepr(tpe) + id match { + case Some(str) => + val strExpr = Expr(str) + '{ new DIKey.IdKey($safeTpe, $strExpr, None)(scala.compiletime.summonInline[IdContract[String]]) } + case None => + '{ new DIKey.TypeKey($safeTpe, None) } + } + } + + private def safeTypeFromRepr(tpe: TypeRepr): Expr[SafeType] = { + dropByName(tpe).asType match { + case '[a] => + '{ SafeType.get[a](using scala.compiletime.summonInline[Tag[a]]) } + case _ => + report.errorAndAbort(s"Cannot generate SafeType from ${tpe.show}, probably that's a bug in Functoid macro") + } + } + + private def dropByName(tpe: TypeRepr): TypeRepr = { + tpe match { + case ByNameType(u) => u + case _ => tpe + } + } + + } + +} diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index f07a72644f..8bebd777b2 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -1,308 +1,31 @@ package izumi.distage.reflection.macros - -import izumi.distage.model.reflection.Provider.{ProviderImpl, ProviderType} -import izumi.distage.model.reflection.* -import izumi.reflect.Tag -import izumi.distage.model.definition.Id -import izumi.fundamentals.platform.reflection.ReflectionUtil import izumi.distage.model.providers.Functoid +import izumi.distage.model.reflection.* +import izumi.distage.model.reflection.Provider.{ProviderImpl, ProviderType} -import scala.annotation.{tailrec, targetName} -import scala.collection.immutable.List import scala.language.implicitConversions import scala.quoted.{Expr, Quotes, Type} -trait FunctoidMacroMethods { - import FunctoidMacro.make - - inline implicit def apply[R](inline fun: () => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) +trait FunctoidMacroMethods extends FunctoidMacroMethodsBase {} - // 23 to 32 - @targetName("apply23") - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - @targetName("apply24") - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - @targetName("apply25") - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - @targetName("apply26") - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - @targetName("apply27") - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - @targetName("apply28") - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - @targetName("apply29") - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - @targetName("apply30") - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) - @targetName("apply31") - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = - make[R](fun) - @targetName("apply32") - inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = - make[R](fun) -} - -object FunctoidMacro { - inline def make[R](inline fun: AnyRef): Functoid[R] = ${ makeImpl[R]('fun) } +object FunctoidMacro extends FunctoidMacroBase[Functoid] { + transparent inline def make[R](inline fun: AnyRef): Functoid[R] = ${ makeImpl[R]('fun) } def makeImpl[R: Type](fun: Expr[AnyRef])(using qctx: Quotes): Expr[Functoid[R]] = new FunctoidMacroImpl[qctx.type]().make(fun) - final class FunctoidMacroImpl[Q <: Quotes](using val qctx: Q) { - - import qctx.reflect.* - - private val paramsMacro = new FunctoidParametersMacro[qctx.type]() - - def make[R: Type](fun: Expr[AnyRef]): Expr[Functoid[R]] = { - val parameters = analyze(fun.asTerm) - val out = generateFunctoid[R](parameters, fun) - -// report.warning( -// s"""fun=${fun.show} -// |funType=${fun.asTerm.tpe} -// |funSym=${fun.asTerm.symbol} -// |funTypeSym=${fun.asTerm.tpe.typeSymbol} -// |funTypeSymBases=${fun.asTerm.tpe.baseClasses} -// |outputType=${Type.show[R]} -// |rawOutputType=(${TypeRepr.of[R]}) -// |produced=${out.show}""".stripMargin -// ) - - out - } - - @tailrec def analyze(fun: Term): List[Expr[LinkedParameter]] = fun match { - case Block(List(DefDef(name, (singleParamList: TermParamClause) :: Nil, _, Some(body))), Closure(_, _)) => - analyzeLambdaOrMethodRef(name, singleParamList, body) - case Typed(term, _) => - analyze(term) - case Inlined(_, _, term) => - analyze(term) - case Block(List(), term) => - analyze(term) - case otherExpr => - analyzeTypeOfExpr(otherExpr) - } - - private def analyzeLambdaOrMethodRef(name: String, singleParamList: TermParamClause, body: Term): List[Expr[LinkedParameter]] = { - val methodRefParams = { - def go(t: Tree): List[Symbol] = t match { - case Apply(f, args) if args.map(_.symbol) == singleParamList.params.map(_.symbol) => - f.symbol.paramSymss.filterNot(_.headOption.exists(_.isTypeParam)).flatten - case Inlined(_, _, term) => go(term) - case Block(List(), term) => go(term) - case Typed(term, _) => go(term) - case _ => Nil - } - go(body) - } - - val annotationsOnMethodAreNonEmptyAndASuperset = { - methodRefParams.sizeCompare(singleParamList.params) == 0 - && methodRefParams.exists(_.annotations.nonEmpty) - } - -// report.info( -// s"""mrefparams = $methodRefParams -// |termclause = $singleParamList -// |body=$body -// |sym=${body match { case Apply(f, _) => f.symbol -> f.symbol.paramSymss; case _ => None }} -// |verdict=$annotationsOnMethodAreNonEmptyAndASuperset -// |""".stripMargin -// ) - - // if method reference has more annotations, get parameters from reference instead - // to preserve annotations! - if (annotationsOnMethodAreNonEmptyAndASuperset) { - // Use types from the generated lambda, not the method reference, because method reference types maybe generic/unresolved/unrelated - // But lambda params should be sufficiently 'grounded' at this point - // (Besides, lambda types are the ones specified by the caller, we should respect them) - singleParamList.params.zip(methodRefParams).map { - case (ValDef(name, tpeTree, _), mSym) => - paramsMacro.makeParam(name, Left(tpeTree), Some(mSym), Right(mSym.owner.typeRef.memberType(mSym))) - } - } else { - singleParamList.params.map { - case valDef @ ValDef(name, tpeTree, _) => - paramsMacro.makeParam(name, Left(tpeTree), Some(valDef.symbol).filterNot(_.isNoSymbol)) - } - } - } - - private def analyzeTypeOfExpr(other: Term): List[Expr[LinkedParameter]] = { - val rawTpe = other.underlying.tpe - val functionTpe = rawTpe.baseClasses.find(_.fullName.startsWith("scala.Function")) match { - case Some(fn) => - rawTpe.baseType(fn) - case None => - report.errorAndAbort(s"Could not find scala.Function* base class for ${rawTpe.show} - not a function! baseClasses were: ${rawTpe.baseClasses}") - } - - functionTpe.typeArgs match { - case Nil => Nil - case o => - val args = o.init - args.iterator.zipWithIndex.map { - (tpe, idx) => - paramsMacro.makeParam(s"arg_$idx", Right(tpe), None) - }.toList - } - } - - private def generateFunctoid[R: Type](paramDefs: List[Expr[LinkedParameter]], originalFun: Expr[AnyRef]): Expr[Functoid[R]] = { - '{ - val rawFn: AnyRef = ${ originalFun } - new Functoid[R]( - new ProviderImpl[R]( - ${ Expr.ofList(paramDefs) }, - ${ paramsMacro.safeType[R] }, - rawFn, - (args: Seq[Any]) => ${ generateRawFnCall(paramDefs.size, 'rawFn, 'args) }, - ProviderType.Function, - ) - ) - } - } - - private def generateRawFnCall(argsCount: Int, rawFn: Expr[Any], args: Expr[Seq[Any]]): Expr[Any] = { - val params = List.tabulate(argsCount) { - idx => - '{ $args(${ Expr(idx) }) } - } - - val anyTpe = TypeRepr.of[Any] - val fnType = defn.FunctionClass(argsCount).typeRef.appliedTo(List.fill(argsCount + 1)(anyTpe)) - - val fnAny = fnType.asType match { - case '[a] => - '{ ${ rawFn.asExprOf[Any] }.asInstanceOf[a] } - case _ => - report.errorAndAbort(s"This is totally unexpected: ${fnType.show} type is higher-kinded type constructor, but expected a proper type") - } - - Select.unique(fnAny.asTerm, "apply").appliedToArgs(params.map(_.asTerm)).asExprOf[Any] - } - - } - - final class FunctoidParametersMacro[Q <: Quotes](using val qctx: Q) { - import qctx.reflect.* - - private val idAnnotationSym: Symbol = TypeRepr.of[Id].typeSymbol - private val maybeJavaxNamedAnnotationSym: Option[Symbol] = scala.util.Try(Symbol.requiredClass("javax.inject.Named")).toOption - - extension (t: Either[TypeTree, TypeRepr]) { - private def _tpe: TypeRepr = t match { - case Right(t) => t - case Left(t) => t.tpe - } - } - - def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol]): Expr[LinkedParameter] = { - makeParam(name, tpe, annotSym, tpe) - } - def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol], annotTpe: Either[TypeTree, TypeRepr]): Expr[LinkedParameter] = { - val identifier = { - val mbIdIdentifier = ReflectionUtil - .readTypeOrSymbolDIAnnotation(idAnnotationSym)(name, annotSym, annotTpe) { - case aterm @ Apply(Select(New(_), _), c :: _) => - c.asExprOf[String].value.orElse { - report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") - } - case aterm => - report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") - } - mbIdIdentifier.orElse { - maybeJavaxNamedAnnotationSym.flatMap { - namedAnnoSym => - ReflectionUtil.readTypeOrSymbolDIAnnotation(namedAnnoSym)(name, annotSym, annotTpe) { - case aterm @ Apply(Select(New(_), _), c :: _) => - c.asExprOf[String].value.orElse { - report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") - } - case aterm => - report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") - } - } - } - } - - val tpeRepr = tpe._tpe - - val isByName = tpeRepr match { - case ByNameType(_) => true - case _ => false - } - - val wasGeneric = tpeRepr.typeSymbol.isTypeParam // deem abstract type members as generic? No. Because we don't do that in Scala 2 version. - - '{ - LinkedParameter( - SymbolInfo( - name = ${ Expr(name) }, - finalResultType = ${ safeTypeFromRepr(tpeRepr) }, - isByName = ${ Expr(isByName) }, - wasGeneric = ${ Expr(wasGeneric) }, - ), - ${ makeKeyFromRepr(tpeRepr, identifier) }, + protected def generateFunctoid[R: Type, Q <: Quotes](paramDefs: List[Expr[LinkedParameter]], originalFun: Expr[AnyRef])(using qctx: Q): Expr[Functoid[R]] = { + '{ + val rawFn: AnyRef = ${ originalFun } + new Functoid[R]( + new ProviderImpl[R]( + ${ Expr.ofList(paramDefs) }, + ${ generateSafeType[R, Q] }, + rawFn, + (args: Seq[Any]) => ${ generateRawFnCall(paramDefs.size, 'rawFn, 'args) }, + ProviderType.Function, ) - } - } - - def safeType[R: Type]: Expr[SafeType] = { - '{ SafeType.get[R](using scala.compiletime.summonInline[Tag[R]]) } - } - - private def makeKeyFromRepr(tpe: TypeRepr, id: Option[String]): Expr[DIKey] = { - val safeTpe = safeTypeFromRepr(tpe) - id match { - case Some(str) => - val strExpr = Expr(str) - '{ new DIKey.IdKey($safeTpe, $strExpr, None)(scala.compiletime.summonInline[IdContract[String]]) } - case None => - '{ new DIKey.TypeKey($safeTpe, None) } - } + ) } - - private def safeTypeFromRepr(tpe: TypeRepr): Expr[SafeType] = { - dropByName(tpe).asType match { - case '[a] => - '{ SafeType.get[a](using scala.compiletime.summonInline[Tag[a]]) } - case _ => - report.errorAndAbort(s"Cannot generate SafeType from ${tpe.show}, probably that's a bug in Functoid macro") - } - } - - private def dropByName(tpe: TypeRepr): TypeRepr = { - tpe match { - case ByNameType(u) => u - case _ => tpe - } - } - } - } diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethodsBase.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethodsBase.scala new file mode 100644 index 0000000000..16e1dcf4eb --- /dev/null +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethodsBase.scala @@ -0,0 +1,58 @@ +package izumi.distage.reflection.macros + +import izumi.distage.model.providers.{AbstractFunctoid, Functoid} + +import scala.annotation.targetName +import scala.language.implicitConversions + +trait FunctoidMacroMethodsBase { + import FunctoidMacro.make + + inline implicit def apply[R](inline fun: () => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + + // 23 to 32 + @targetName("apply23") + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + @targetName("apply24") + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + @targetName("apply25") + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + @targetName("apply26") + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + @targetName("apply27") + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + @targetName("apply28") + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + @targetName("apply29") + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + @targetName("apply30") + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = make[R](fun) + @targetName("apply31") + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = + make[R](fun) + @targetName("apply32") + inline implicit def apply[R](inline fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = + make[R](fun) +} diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/AbstractLocator.scala b/distage/distage-core-api/src/main/scala/izumi/distage/AbstractLocator.scala index 97529e54bb..81c4da2d43 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/AbstractLocator.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/AbstractLocator.scala @@ -51,7 +51,7 @@ trait AbstractLocator extends Locator { recursiveLookup(key, this) } - private[this] final def recursiveLookup[T: Tag](key: DIKey, locator: Locator): Option[GenericTypedRef[T]] = { + private final def recursiveLookup[T: Tag](key: DIKey, locator: Locator): Option[GenericTypedRef[T]] = { locator .lookupLocal[T](key) .orElse(locator.parent.flatMap(p => recursiveLookup[T](key, p))) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/LocatorDef.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/LocatorDef.scala index 2e88905a6d..878a3eae9f 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/LocatorDef.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/LocatorDef.scala @@ -60,7 +60,7 @@ trait LocatorDef extends AbstractLocator with AbstractBindingDefDSL[LocatorDef.B override def parent: Option[Locator] = None - private[this] final lazy val (frozenMap, frozenInstances): (Map[DIKey, Any], immutable.Seq[IdentifiedRef]) = { + private final lazy val (frozenMap, frozenInstances): (Map[DIKey, Any], immutable.Seq[IdentifiedRef]) = { val map = new mutable.LinkedHashMap[DIKey, Any] frozenState.foreach { @@ -109,7 +109,7 @@ object LocatorDef { final class BindDSLAfterAlias[T](override protected val mutableState: SingletonRef) extends BindDSLMutBase[T] sealed trait BindDSLMutBase[T] { - protected[this] def mutableState: SingletonRef + protected def mutableState: SingletonRef def aliased[T1 >: T: Tag](implicit pos: CodePositionMaterializer): BindDSLAfterAlias[T] = { addOp(AliasTo(DIKey.get[T1], pos.get.position))(new BindDSLAfterAlias[T](_)) @@ -119,7 +119,7 @@ object LocatorDef { addOp(AliasTo(DIKey.get[T1].named(name), pos.get.position))(new BindDSLAfterAlias[T](_)) } - protected[this] final def addOp[R](op: SingletonInstruction)(newState: SingletonRef => R): R = { + protected final def addOp[R](op: SingletonInstruction)(newState: SingletonRef => R): R = { newState(mutableState.append(op)) } } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala index 065cfcca2f..3777056624 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/AbstractBindingDefDSL.scala @@ -17,8 +17,8 @@ import izumi.reflect.Tag import scala.collection.mutable trait AbstractBindingDefDSL[BindDSL[_], BindDSLAfterFrom[_], SetDSL[_]] extends AbstractBindingDefDSLMacro[BindDSL] { self => - private[this] final val mutableState: mutable.ArrayBuffer[BindingRef] = _initialState - protected[this] def _initialState: mutable.ArrayBuffer[BindingRef] = mutable.ArrayBuffer.empty + private final val mutableState: mutable.ArrayBuffer[BindingRef] = _initialState + protected def _initialState: mutable.ArrayBuffer[BindingRef] = mutable.ArrayBuffer.empty private[definition] def _bindDSL[T](ref: SingletonRef): BindDSL[T] private[definition] def _bindDSLAfterFrom[T](ref: SingletonRef): BindDSLAfterFrom[T] @@ -28,35 +28,35 @@ trait AbstractBindingDefDSL[BindDSL[_], BindDSLAfterFrom[_], SetDSL[_]] extends mutableState.iterator.flatMap(_.interpret()) } - protected[this] def _registered[T <: BindingRef](bindingRef: T): T = { + protected def _registered[T <: BindingRef](bindingRef: T): T = { mutableState += bindingRef bindingRef } - final protected[this] def _make[T: Tag](provider: Functoid[T])(implicit pos: CodePositionMaterializer): BindDSL[T] = { + final protected def _make[T: Tag](provider: Functoid[T])(implicit pos: CodePositionMaterializer): BindDSL[T] = { val ref = _registered(new SingletonRef(Bindings.provider[T](provider))) _bindDSL[T](ref) } /** @see [[https://izumi.7mind.io/distage/basics.html#auto-traits Auto-Traits feature]] */ - final protected[this] def makeTrait[T: Tag: TraitConstructor]: BindDSLAfterFrom[T] = { + final protected def makeTrait[T: Tag: TraitConstructor]: BindDSLAfterFrom[T] = { val ref = _registered(new SingletonRef(Bindings.provider[T](TraitConstructor[T]))) _bindDSLAfterFrom[T](ref) } /** @see [[https://izumi.7mind.io/distage/basics.html#auto-factories Auto-Factories feature]] */ - final protected[this] def makeFactory[T: Tag: FactoryConstructor]: BindDSLAfterFrom[T] = { + final protected def makeFactory[T: Tag: FactoryConstructor]: BindDSLAfterFrom[T] = { val ref = _registered(new SingletonRef(Bindings.provider[T](FactoryConstructor[T]))) _bindDSLAfterFrom[T](ref) } /** @see [[https://izumi.7mind.io/distage/basics.html#subcontexts Subcontexts feature]] */ - final protected[this] def makeSubcontext[T: Tag](submodule: ModuleBase): SubcontextDSL[T] = { + final protected def makeSubcontext[T: Tag](submodule: ModuleBase): SubcontextDSL[T] = { val ref = _registered(new SubcontextRef(Bindings.subcontext[T](submodule, Functoid.identity[T], Set.empty))) new SubcontextDSL[T](ref) } /** @see [[https://izumi.7mind.io/distage/basics.html#subcontexts Subcontexts feature]] */ - final protected[this] def makeSubcontext[T: Tag]: SubcontextDSL[T] = makeSubcontext[T](ModuleBase.empty) + final protected def makeSubcontext[T: Tag]: SubcontextDSL[T] = makeSubcontext[T](ModuleBase.empty) /** * Set bindings are useful for implementing event listeners, plugins, hooks, http routes, etc. @@ -109,13 +109,13 @@ trait AbstractBindingDefDSL[BindDSL[_], BindDSLAfterFrom[_], SetDSL[_]] extends * * @see Guice wiki on Multibindings: https://github.com/google/guice/wiki/Multibindings */ - final protected[this] def many[T](implicit tag: Tag[Set[T]], pos: CodePositionMaterializer): SetDSL[T] = { + final protected def many[T](implicit tag: Tag[Set[T]], pos: CodePositionMaterializer): SetDSL[T] = { val setRef = _registered(new SetRef(Bindings.emptySet[T])) _setDSL(setRef) } /** Same as `make[T].from(implicitly[T])` * */ - final protected[this] def addImplicit[T: Tag](implicit instance: T, pos: CodePositionMaterializer): BindDSLAfterFrom[T] = { + final protected def addImplicit[T: Tag](implicit instance: T, pos: CodePositionMaterializer): BindDSLAfterFrom[T] = { val ref = _registered(new SingletonRef(Bindings.binding(instance))) _bindDSLAfterFrom(ref) } @@ -125,7 +125,7 @@ trait AbstractBindingDefDSL[BindDSL[_], BindDSLAfterFrom[_], SetDSL[_]] extends * * Useful for prototyping. */ - final protected[this] def todo[T: Tag](implicit pos: CodePositionMaterializer): BindDSLAfterFrom[T] = { + final protected def todo[T: Tag](implicit pos: CodePositionMaterializer): BindDSLAfterFrom[T] = { val ref = _registered(new SingletonRef(Bindings.todo(DIKey.get[T])(pos))) _bindDSLAfterFrom(ref) } @@ -156,7 +156,7 @@ trait AbstractBindingDefDSL[BindDSL[_], BindDSLAfterFrom[_], SetDSL[_]] extends * }) * }}} */ - final protected[this] def modify[T]: ModifyDSL[T, BindDSL, BindDSLAfterFrom, SetDSL] = new ModifyDSL[T, BindDSL, BindDSLAfterFrom, SetDSL](this) + final protected def modify[T]: ModifyDSL[T, BindDSL, BindDSLAfterFrom, SetDSL] = new ModifyDSL[T, BindDSL, BindDSLAfterFrom, SetDSL](this) final private def _modify[T](key: DIKey.BasicKey)(f: Functoid[T] => Functoid[T])(implicit pos: CodePositionMaterializer): SingletonRef = { val (tpeKey: DIKey.TypeKey, maybeId) = key match { case tpeKey: DIKey.TypeKey => tpeKey -> None @@ -198,18 +198,18 @@ trait AbstractBindingDefDSL[BindDSL[_], BindDSLAfterFrom[_], SetDSL[_]] extends */ final class MutationContext { abstract class dsl extends AbstractBindingDefDSLMacro[BindDSL] { - final protected[this] def _make[T: Tag](provider: Functoid[T])(implicit pos: CodePositionMaterializer): BindDSL[T] = self._make[T](provider) - final protected[this] def makeTrait[T: Tag: TraitConstructor]: BindDSLAfterFrom[T] = self.makeTrait[T] - final protected[this] def makeFactory[T: Tag: FactoryConstructor]: BindDSLAfterFrom[T] = self.makeFactory[T] - final protected[this] def makeSubcontext[T: Tag](submodule: ModuleBase): SubcontextDSL[T] = self.makeSubcontext[T](submodule) - final protected[this] def makeSubcontext[T: Tag]: SubcontextDSL[T] = self.makeSubcontext[T] + final protected def _make[T: Tag](provider: Functoid[T])(implicit pos: CodePositionMaterializer): BindDSL[T] = self._make[T](provider) + final protected def makeTrait[T: Tag: TraitConstructor]: BindDSLAfterFrom[T] = self.makeTrait[T] + final protected def makeFactory[T: Tag: FactoryConstructor]: BindDSLAfterFrom[T] = self.makeFactory[T] + final protected def makeSubcontext[T: Tag](submodule: ModuleBase): SubcontextDSL[T] = self.makeSubcontext[T](submodule) + final protected def makeSubcontext[T: Tag]: SubcontextDSL[T] = self.makeSubcontext[T] - final protected[this] def many[T](implicit tag: Tag[Set[T]], pos: CodePositionMaterializer): SetDSL[T] = self.many[T] + final protected def many[T](implicit tag: Tag[Set[T]], pos: CodePositionMaterializer): SetDSL[T] = self.many[T] - final protected[this] def addImplicit[T: Tag](implicit instance: T, pos: CodePositionMaterializer): BindDSLAfterFrom[T] = self.addImplicit[T] + final protected def addImplicit[T: Tag](implicit instance: T, pos: CodePositionMaterializer): BindDSLAfterFrom[T] = self.addImplicit[T] - final protected[this] def todo[T: Tag](implicit pos: CodePositionMaterializer): BindDSLAfterFrom[T] = self.todo[T] - final protected[this] def modify[T]: ModifyDSL[T, BindDSL, BindDSLAfterFrom, SetDSL] = self.modify[T] + final protected def todo[T: Tag](implicit pos: CodePositionMaterializer): BindDSLAfterFrom[T] = self.todo[T] + final protected def modify[T]: ModifyDSL[T, BindDSL, BindDSLAfterFrom, SetDSL] = self.modify[T] /** * Avoid `discarded non-Unit value` warning. @@ -219,7 +219,7 @@ trait AbstractBindingDefDSL[BindDSL[_], BindDSLAfterFrom[_], SetDSL[_]] extends @inline final def discard(): Unit = () } } - final protected[this] implicit lazy val mutationContext: MutationContext = new MutationContext + final protected implicit lazy val mutationContext: MutationContext = new MutationContext } @@ -299,11 +299,11 @@ object AbstractBindingDefDSL { modify(f) } - override protected[this] def _modifyBy(f: Functoid[T] => Functoid[T]): ModifyTaggingDSL[T] = by(f) + override protected def _modifyBy(f: Functoid[T] => Functoid[T]): ModifyTaggingDSL[T] = by(f) } trait AddDependencyDSL[T, Self] extends Any { - protected[this] def _modifyBy(f: Functoid[T] => Functoid[T]): Self + protected def _modifyBy(f: Functoid[T] => Functoid[T]): Self def addDependency[B: Tag]: Self = { _modifyBy(_.addDependency[B]) @@ -332,16 +332,16 @@ object AbstractBindingDefDSL { addOp(SubcontextInstruction.SetId(name))(new SubcontextNamedDSL[T](_)) } - override protected[this] def toSame: SubcontextRef => SubcontextDSL[T] = new SubcontextDSL[T](_) + override protected def toSame: SubcontextRef => SubcontextDSL[T] = new SubcontextDSL[T](_) } final class SubcontextNamedDSL[T](override protected val mutableState: SubcontextRef) extends SubcontextDSLBase[T, SubcontextNamedDSL[T]] { - override protected[this] def toSame: SubcontextRef => SubcontextNamedDSL[T] = new SubcontextNamedDSL[T](_) + override protected def toSame: SubcontextRef => SubcontextNamedDSL[T] = new SubcontextNamedDSL[T](_) } sealed abstract class SubcontextDSLBase[T, Self] { - protected[this] def mutableState: SubcontextRef - protected[this] def toSame: SubcontextRef => Self + protected def mutableState: SubcontextRef + protected def toSame: SubcontextRef => Self final def tagged(tags: BindingTag*): Self = { addOp(SubcontextInstruction.AddTags(tags.toSet))(toSame) @@ -371,7 +371,7 @@ object AbstractBindingDefDSL { addOp(SubcontextInstruction.AddLocalDependencies(keys))(toSame) } - protected[this] final def addOp[R](op: SubcontextInstruction)(newState: SubcontextRef => R): R = { + protected final def addOp[R](op: SubcontextInstruction)(newState: SubcontextRef => R): R = { newState(mutableState.append(op)) } } @@ -439,9 +439,9 @@ object AbstractBindingDefDSL { } final class SetRef(initial: EmptySetBinding[DIKey.TypeKey]) extends BindingRef { - private[this] val setOps: mutable.Queue[SetInstruction] = mutable.Queue.empty - private[this] val elems: mutable.Queue[SetElementRef] = mutable.Queue.empty - private[this] val multiElems: mutable.Queue[MultiSetElementRef] = mutable.Queue.empty + private val setOps: mutable.Queue[SetInstruction] = mutable.Queue.empty + private val elems: mutable.Queue[SetElementRef] = mutable.Queue.empty + private val multiElems: mutable.Queue[MultiSetElementRef] = mutable.Queue.empty override def interpret(): collection.Seq[Binding] = { val emptySetBinding = setOps.foldLeft(initial: EmptySetBinding[DIKey.BasicKey]) { @@ -496,7 +496,7 @@ object AbstractBindingDefDSL { } final class MultiSetElementRef(implDef: ImplDef, pos: SourceFilePosition) { - private[this] val ops: mutable.Queue[MultiSetElementInstruction] = mutable.Queue.empty + private val ops: mutable.Queue[MultiSetElementInstruction] = mutable.Queue.empty def interpret(setKey: DIKey.BasicKey): Seq[Binding] = { val valueProxyKey = DIKey.IdKey(implDef.implType, MultiSetImplId(setKey, implDef)) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/IncludesDSL.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/IncludesDSL.scala index bbd08be579..f3d2b43173 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/IncludesDSL.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/IncludesDSL.scala @@ -7,9 +7,9 @@ import izumi.fundamentals.platform.language.Quirks.discard import scala.collection.mutable trait IncludesDSL { - final private[this] val mutableAsIsIncludes: mutable.ArrayBuffer[Include] = _initialIncludes + final private val mutableAsIsIncludes: mutable.ArrayBuffer[Include] = _initialIncludes - protected[this] def _initialIncludes: mutable.ArrayBuffer[Include] = mutable.ArrayBuffer.empty + protected def _initialIncludes: mutable.ArrayBuffer[Include] = mutable.ArrayBuffer.empty final private[dsl] def includes: Iterator[Include] = mutableAsIsIncludes.iterator @@ -17,7 +17,7 @@ trait IncludesDSL { * * WON'T add global tags from [[TagsDSL#tag]] to included bindings. */ - final protected[this] def include(that: ModuleBase, tagMergeStrategy: TagMergePolicy = TagMergePolicy.MergePreferInner): Unit = discard { + final protected def include(that: ModuleBase, tagMergeStrategy: TagMergePolicy = TagMergePolicy.MergePreferInner): Unit = discard { mutableAsIsIncludes += Include(that, tagMergeStrategy) } @@ -26,7 +26,7 @@ trait IncludesDSL { * WILL add global tags from [[TagsDSL#tag]] to included bindings. */ @deprecated("Outer module's tags are now added to included module by default, use regular `include`", "1.2.9") - final protected[this] def includeApplyTags(that: ModuleBase): Unit = { + final protected def includeApplyTags(that: ModuleBase): Unit = { include(that, TagMergePolicy.MergePreferInner) } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala index cc2ed8ce97..8b9b4564f3 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/ModuleDefDSL.scala @@ -85,13 +85,13 @@ trait ModuleDefDSL extends AbstractBindingDefDSL[MakeDSL, MakeDSLUnnamedAfterFro override final def iterator: Iterator[Binding] = freezeIterator() override final def keysIterator: Iterator[DIKey] = freezeIterator().map(_.key) - private[this] final def freeze(): Set[Binding] = { + private final def freeze(): Set[Binding] = { HashSet.newBuilder .++= { freezeIterator() }.result() } - private[this] final def freezeIterator(): Iterator[Binding] = { + private final def freezeIterator(): Iterator[Binding] = { val frozenOuterTags = frozenTags val bindingsWithGlobalTags = frozenState.map(_.addTags(frozenOuterTags)) @@ -327,8 +327,8 @@ object ModuleDefDSL { bind(ImplDef.ProviderImpl(provider.ret, provider)) } - protected[this] def bind(impl: ImplDef): AfterBind - protected[this] def key: DIKey + protected def bind(impl: ImplDef): AfterBind + protected def key: DIKey } trait SetDSLBase[T, AfterAdd, AfterMultiAdd] { @@ -480,8 +480,8 @@ object ModuleDefDSL { final def weakSet[I <: Set[? <: T]: Tag](name: Identifier)(implicit pos: CodePositionMaterializer): AfterAdd = appendElement(ImplDef.ReferenceImpl(SafeType.get[I], DIKey.get[I].named(name), weak = true), pos) - protected[this] def multiSetAdd(newImpl: ImplDef, pos: CodePositionMaterializer): AfterMultiAdd - protected[this] def appendElement(newImpl: ImplDef, pos: CodePositionMaterializer): AfterAdd + protected def multiSetAdd(newImpl: ImplDef, pos: CodePositionMaterializer): AfterMultiAdd + protected def appendElement(newImpl: ImplDef, pos: CodePositionMaterializer): AfterAdd } /** Workaround for https://github.com/lampepfl/dotty/issues/16406#issuecomment-1712058227 */ @@ -655,7 +655,7 @@ object ModuleDefDSL { } - @inline private[this] def provideZEnvLifecycle[R, E, A](lifecycle: Lifecycle[ZIO[R, E, _], A], zenv: ZEnvironment[R]): Lifecycle[ZIO[Any, E, _], A] = { + @inline private def provideZEnvLifecycle[R, E, A](lifecycle: Lifecycle[ZIO[R, E, _], A], zenv: ZEnvironment[R]): Lifecycle[ZIO[Any, E, _], A] = { lifecycle.mapK[ZIO[R, E, _], ZIO[Any, E, _]](Morphism1(_.provideEnvironment(zenv))) } @@ -698,11 +698,11 @@ object ModuleDefDSL { addOp(SetIdFromImplName())(new MakeNamedDSL[T](_, key)) } - override protected[this] def bind(impl: ImplDef): MakeDSLUnnamedAfterFrom[T] = { + override protected def bind(impl: ImplDef): MakeDSLUnnamedAfterFrom[T] = { addOp(SetImpl(impl))(new MakeDSLUnnamedAfterFrom[T](_)) } - override protected[this] def toSame: SingletonRef => MakeDSL[T] = { + override protected def toSame: SingletonRef => MakeDSL[T] = { new MakeDSL[T](_, key) } @@ -714,11 +714,11 @@ object ModuleDefDSL { ) extends MakeDSLMutBase[T, MakeNamedDSL[T]] with MakeDSLBase[T, MakeDSLNamedAfterFrom[T]] { - override protected[this] def bind(impl: ImplDef): MakeDSLNamedAfterFrom[T] = { + override protected def bind(impl: ImplDef): MakeDSLNamedAfterFrom[T] = { addOp(SetImpl(impl))(new MakeDSLNamedAfterFrom[T](_)) } - override protected[this] def toSame: SingletonRef => MakeNamedDSL[T] = { + override protected def toSame: SingletonRef => MakeNamedDSL[T] = { new MakeNamedDSL[T](_, key) } @@ -737,7 +737,7 @@ object ModuleDefDSL { addOp(SetIdFromImplName())(new MakeDSLNamedAfterFrom[T](_)) } - override protected[this] def toSame: SingletonRef => MakeDSLUnnamedAfterFrom[T] = { + override protected def toSame: SingletonRef => MakeDSLUnnamedAfterFrom[T] = { new MakeDSLUnnamedAfterFrom[T](_) } @@ -746,14 +746,14 @@ object ModuleDefDSL { final class MakeDSLNamedAfterFrom[T]( override protected val mutableState: SingletonRef ) extends MakeDSLMutBase[T, MakeDSLNamedAfterFrom[T]] { - override protected[this] def toSame: SingletonRef => MakeDSLNamedAfterFrom[T] = { + override protected def toSame: SingletonRef => MakeDSLNamedAfterFrom[T] = { new MakeDSLNamedAfterFrom[T](_) } } sealed trait MakeDSLMutBase[T, Self <: MakeDSLMutBase[T, Self]] extends Any with AddDependencyDSL[T, Self] { - protected[this] def mutableState: SingletonRef - protected[this] def toSame: SingletonRef => Self + protected def mutableState: SingletonRef + protected def toSame: SingletonRef => Self final def tagged(tags: BindingTag*): Self = { addOp(AddTags(tags.toSet))(toSame) @@ -775,11 +775,11 @@ object ModuleDefDSL { addOp(AliasTo(DIKey.get[T1].named(name), pos.get.position))(toSame) } - protected[this] final def addOp[R](op: SingletonInstruction)(newState: SingletonRef => R): R = { + protected final def addOp[R](op: SingletonInstruction)(newState: SingletonRef => R): R = { newState(mutableState.append(op)) } - override protected[this] def _modifyBy(f: Functoid[T] => Functoid[T]): Self = modifyBy(f) + override protected def _modifyBy(f: Functoid[T] => Functoid[T]): Self = modifyBy(f) } @@ -806,7 +806,7 @@ object ModuleDefDSL { addOp(ElementAddTags(tags.toSet)) } - private[this] def addOp(op: SetElementInstruction): SetElementDSL[T] = { + private def addOp(op: SetElementInstruction): SetElementDSL[T] = { val newState = mutableCursor.append(op) new SetElementDSL[T](mutableState, newState) } @@ -820,25 +820,25 @@ object ModuleDefDSL { def tagged(tags: BindingTag*): MultiSetElementDSL[T] = addOp(MultiAddTags(tags.toSet)) - private[this] def addOp(op: MultiSetElementInstruction): MultiSetElementDSL[T] = { + private def addOp(op: MultiSetElementInstruction): MultiSetElementDSL[T] = { val newState = mutableCursor.append(op) new MultiSetElementDSL[T](mutableState, newState) } } sealed trait SetDSLMutBase[T] extends SetDSLBase[T, SetElementDSL[T], MultiSetElementDSL[T]] { - protected[this] def mutableState: SetRef + protected def mutableState: SetRef - protected[this] final def addOp[R](op: SetInstruction)(nextState: SetRef => R): R = { + protected final def addOp[R](op: SetInstruction)(nextState: SetRef => R): R = { nextState(mutableState.appendOp(op)) } - override protected[this] final def appendElement(newElement: ImplDef, pos: CodePositionMaterializer): SetElementDSL[T] = { + override protected final def appendElement(newElement: ImplDef, pos: CodePositionMaterializer): SetElementDSL[T] = { val mutableCursor = new SetElementRef(newElement, pos.get.position) new SetElementDSL[T](mutableState.appendElem(mutableCursor), mutableCursor) } - override protected[this] final def multiSetAdd(newElements: ImplDef, pos: CodePositionMaterializer): MultiSetElementDSL[T] = { + override protected final def multiSetAdd(newElements: ImplDef, pos: CodePositionMaterializer): MultiSetElementDSL[T] = { val mutableCursor = new MultiSetElementRef(newElements, pos.get.position) new MultiSetElementDSL[T](mutableState.appendMultiElem(mutableCursor), mutableCursor) } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/TagsDSL.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/TagsDSL.scala index 4dfabde874..a76194720f 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/TagsDSL.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/dsl/TagsDSL.scala @@ -6,13 +6,13 @@ import izumi.fundamentals.platform.language.Quirks.discard import scala.collection.mutable trait TagsDSL { - private[this] final val mutableTags: mutable.Set[BindingTag] = _initialTags - protected[this] def _initialTags: mutable.Set[BindingTag] = mutable.HashSet.empty + private final val mutableTags: mutable.Set[BindingTag] = _initialTags + protected def _initialTags: mutable.Set[BindingTag] = mutable.HashSet.empty private[dsl] final def frozenTags: Set[BindingTag] = mutableTags.toSet /** Add `tags` to all bindings in this module, except for [[IncludesDSL#include included]] bindings */ - final protected[this] def tag(tags: BindingTag*): Unit = discard { + final protected def tag(tags: BindingTag*): Unit = discard { mutableTags ++= tags } } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/errors/DIError.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/errors/DIError.scala index 3130ab3da6..acd026a456 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/errors/DIError.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/errors/DIError.scala @@ -140,7 +140,7 @@ object DIError { }.toList.niceList() } } - protected[this] def conflictingAxisTagsHint( + protected def conflictingAxisTagsHint( key: MutSel[DIKey], activeChoices: ActivationChoices, ops: Set[OperationOrigin], diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/errors/DIFailureInterpreter.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/errors/DIFailureInterpreter.scala index d48b992647..5cfe564159 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/errors/DIFailureInterpreter.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/errors/DIFailureInterpreter.scala @@ -27,7 +27,7 @@ class DIFailureInterpreter() { } } - protected[this] def conflictError(issues: List[ConflictResolutionFailed]): InjectorFailed = { + protected def conflictError(issues: List[ConflictResolutionFailed]): InjectorFailed = { val rawIssues = issues.map(_.error) val issueRepr = rawIssues.map(DIError.formatConflict).mkString("\n", "\n", "") diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/ExecutableOp.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/ExecutableOp.scala index 8afb706b37..9a2ed5fe7e 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/ExecutableOp.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/ExecutableOp.scala @@ -138,7 +138,7 @@ object ExecutableOp { } @tailrec - private[this] def opInstanceType(op: ExecutableOp): SafeType = { + private def opInstanceType(op: ExecutableOp): SafeType = { op match { case w: WiringOp => w.wiring.instanceType diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/BindingFormatter.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/BindingFormatter.scala index 5655da9d9e..09e331ad03 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/BindingFormatter.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/BindingFormatter.scala @@ -44,7 +44,7 @@ object BindingFormatter { } } - private[this] def formatTags(tags: Set[BindingTag]) = { + private def formatTags(tags: Set[BindingTag]) = { if (tags.isEmpty) "" else s".tagged($tags)" } } diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/KeyMinimizer.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/KeyMinimizer.scala index f5d56ce6dc..9cac4a3af3 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/KeyMinimizer.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/plan/repr/KeyMinimizer.scala @@ -27,7 +27,7 @@ class KeyMinimizer( } @nowarn("msg=Unused import") - private[this] val index: Map[String, Int] = { + private val index: Map[String, Int] = { import scala.collection.compat._ allKeys.iterator .flatMap(extract) @@ -37,7 +37,7 @@ class KeyMinimizer( .toMap } - private[this] val minimizedLTTRenderables = new LTTRenderables { + private val minimizedLTTRenderables = new LTTRenderables { override def r_SymName(sym: SymName, hasPrefix: Boolean): String = { sym match { case sym: SymName.NamedSymbol => @@ -55,7 +55,7 @@ class KeyMinimizer( } } - private[this] def showKeyData(prefix: String, value: String, idx: Option[Int] = None) = { + private def showKeyData(prefix: String, value: String, idx: Option[Int] = None) = { val prefixRepr = styled(s"{$prefix.", c.GREEN) val suffixRepr = styled(s"}", c.GREEN) val idxrepr = idx.map(i => styled("@μ(" + i.toString + ")", c.RED)).getOrElse("") @@ -63,7 +63,7 @@ class KeyMinimizer( s"$prefixRepr$value$suffixRepr$idxrepr" } - @inline private[this] def renderKey(key: DIKey, rendertype: SafeType => String): String = { + @inline private def renderKey(key: DIKey, rendertype: SafeType => String): String = { // in order to make idea links working we need to put a dot before Position occurence and avoid using # key match { case DIKey.TypeKey(tpe, idx) => @@ -99,7 +99,7 @@ class KeyMinimizer( } } - private[this] def extract(key: DIKey): Set[String] = { + private def extract(key: DIKey): Set[String] = { key match { case k: DIKey.TypeKey => extract(k.tpe) @@ -124,7 +124,7 @@ class KeyMinimizer( } } - private[this] def extract(key: SafeType): Set[String] = { + private def extract(key: SafeType): Set[String] = { RuntimeAPI .unpack(key.tag.ref match { case reference: LightTypeTagRef.AbstractReference => diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/planning/ActivationChoices.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/planning/ActivationChoices.scala index ea6e069243..496a41b51a 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/planning/ActivationChoices.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/planning/ActivationChoices.scala @@ -9,13 +9,13 @@ final case class ActivationChoices(activationChoices: Map[String, AxisPoint]) ex a.collect { case a if !activationChoices.contains(a.axis) => a.axis } } - private[this] def validChoice(a: AxisPoint): Boolean = { + private def validChoice(a: AxisPoint): Boolean = { // forall, as in, AxisPoint without an explicit choice is allowed through and should raise conflict in later stages // if there's another AxisPoint for the same axis (revisit this though) activationChoices.get(a.axis).forall(_ == a) } - private[this] def axisIsConfigured(a: AxisPoint): Boolean = { + private def axisIsConfigured(a: AxisPoint): Boolean = { // forall, as in, AxisPoint without an explicit choice is allowed through and should raise conflict in later stages // if there's another AxisPoint for the same axis (revisit this though) activationChoices.contains(a.axis) // .get(a.axis).contains(a) diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/provisioning/proxies/ProxyDispatcher.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/provisioning/proxies/ProxyDispatcher.scala index b21dcebe9c..a3807709f1 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/provisioning/proxies/ProxyDispatcher.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/provisioning/proxies/ProxyDispatcher.scala @@ -10,7 +10,7 @@ trait ProxyDispatcher { object ProxyDispatcher { trait AtomicProxyDispatcher extends ProxyDispatcher { - protected[this] val reference = new AtomicReference[AnyRef](null) + protected val reference = new AtomicReference[AnyRef](null) override def init(real: Any): Unit = { if (!reference.compareAndSet(null, real.asInstanceOf[AnyRef])) { diff --git a/distage/distage-core-proxy-bytebuddy/src/main/scala/izumi/distage/provisioning/strategies/bytebuddyproxy/ByteBuddyAtomicRefDispatcher.scala b/distage/distage-core-proxy-bytebuddy/src/main/scala/izumi/distage/provisioning/strategies/bytebuddyproxy/ByteBuddyAtomicRefDispatcher.scala index 1165f2dfcb..5dab0cac10 100644 --- a/distage/distage-core-proxy-bytebuddy/src/main/scala/izumi/distage/provisioning/strategies/bytebuddyproxy/ByteBuddyAtomicRefDispatcher.scala +++ b/distage/distage-core-proxy-bytebuddy/src/main/scala/izumi/distage/provisioning/strategies/bytebuddyproxy/ByteBuddyAtomicRefDispatcher.scala @@ -27,7 +27,7 @@ private[distage] class ByteBuddyAtomicRefDispatcher( } } - @inline private[this] final def getRef: AnyRef = { + @inline private final def getRef: AnyRef = { val value = reference.get() if (value ne null) value else nullProxy } diff --git a/distage/distage-core/.js/src/test/scala/izumi/distage/compat/CatsIOPlatformDependentTest.scala b/distage/distage-core/.js/src/test/scala/izumi/distage/compat/CatsIOPlatformDependentTest.scala index 8ae3c8f774..b5ab84cdb5 100644 --- a/distage/distage-core/.js/src/test/scala/izumi/distage/compat/CatsIOPlatformDependentTest.scala +++ b/distage/distage-core/.js/src/test/scala/izumi/distage/compat/CatsIOPlatformDependentTest.scala @@ -4,7 +4,7 @@ import cats.effect.IO trait CatsIOPlatformDependentTest { // FIXME without a working unsafeRunSync we can't run cats support tests on JS... - protected[this] def catsIOUnsafeRunSync[A](io: IO[A]): A = { + protected def catsIOUnsafeRunSync[A](io: IO[A]): A = { io.syncStep(Int.MaxValue).attempt.unsafeRunSync() match { case Left(t) => throw t case Right(Left(_)) => throw new RuntimeException("Failed to evaluate IO synchronously") diff --git a/distage/distage-core/.jvm/src/main/scala/izumi/distage/planning/extensions/GraphDumpObserver.scala b/distage/distage-core/.jvm/src/main/scala/izumi/distage/planning/extensions/GraphDumpObserver.scala index 0af1c1e1fe..2d2e08ae0a 100644 --- a/distage/distage-core/.jvm/src/main/scala/izumi/distage/planning/extensions/GraphDumpObserver.scala +++ b/distage/distage-core/.jvm/src/main/scala/izumi/distage/planning/extensions/GraphDumpObserver.scala @@ -109,7 +109,7 @@ final class GraphDumpObserver() extends PlanningObserver { save(dotfileMin, "aftergc") } - private[this] def save(dotfile: RenderedDot, kind: String): Unit = { + private def save(dotfile: RenderedDot, kind: String): Unit = { val name = s"plan-${System.currentTimeMillis()}-$kind.gv" val last = Paths.get(s"target", s"plan-last-$kind.gv") @@ -121,7 +121,7 @@ final class GraphDumpObserver() extends PlanningObserver { Files.createLink(last, path).discard() } - private[this] def modify(name: String, attrs: mutable.Map[String, String], op: ExecutableOp): Unit = { + private def modify(name: String, attrs: mutable.Map[String, String], op: ExecutableOp): Unit = { val label = op match { case op: ExecutableOp.InstantiationOp => op match { diff --git a/distage/distage-core/.jvm/src/test/scala/izumi/distage/compat/CatsIOPlatformDependentTest.scala b/distage/distage-core/.jvm/src/test/scala/izumi/distage/compat/CatsIOPlatformDependentTest.scala index d9b5f0a358..da02a478df 100644 --- a/distage/distage-core/.jvm/src/test/scala/izumi/distage/compat/CatsIOPlatformDependentTest.scala +++ b/distage/distage-core/.jvm/src/test/scala/izumi/distage/compat/CatsIOPlatformDependentTest.scala @@ -4,5 +4,5 @@ import cats.effect.IO import cats.effect.unsafe.IORuntime trait CatsIOPlatformDependentTest { - protected[this] def catsIOUnsafeRunSync[A](io: IO[A]): A = io.unsafeRunSync()(IORuntime.global) + protected def catsIOUnsafeRunSync[A](io: IO[A]): A = io.unsafeRunSync()(IORuntime.global) } diff --git a/distage/distage-core/src/main/scala/distage/Injector.scala b/distage/distage-core/src/main/scala/distage/Injector.scala index 73e4894c96..9b91d218a9 100644 --- a/distage/distage-core/src/main/scala/distage/Injector.scala +++ b/distage/distage-core/src/main/scala/distage/Injector.scala @@ -149,11 +149,11 @@ object Injector extends InjectorFactory { Injector.providedKeys[F](bootstrapBase, overrides*) } - override protected[this] final def defaultBootstrap: BootstrapContextModule = BootstrapLocator.defaultBootstrap - override protected[this] final def defaultBootstrapActivation: Activation = definition.Activation(Cycles -> cycleChoice) + override protected final def defaultBootstrap: BootstrapContextModule = BootstrapLocator.defaultBootstrap + override protected final def defaultBootstrapActivation: Activation = definition.Activation(Cycles -> cycleChoice) } - private[this] def bootstrap[F[_]: QuasiIO: TagK: DefaultModule]( + private def bootstrap[F[_]: QuasiIO: TagK: DefaultModule]( injectorFactory: InjectorFactory, bootstrapBase: BootstrapContextModule, activation: Activation, @@ -164,7 +164,7 @@ object Injector extends InjectorFactory { inheritWithNewDefaultModuleImpl(injectorFactory, bootstrapLocator, implicitly) } - private[this] def inheritWithNewDefaultModuleImpl[F[_]: QuasiIO: TagK]( + private def inheritWithNewDefaultModuleImpl[F[_]: QuasiIO: TagK]( injectorFactory: InjectorFactory, parent: Locator, defaultModule: DefaultModule[F], @@ -173,7 +173,7 @@ object Injector extends InjectorFactory { new InjectorDefaultImpl(injectorFactory, parent, defaultModule = defaultModule0) } - @inline override protected[this] def defaultBootstrap: BootstrapContextModule = BootstrapLocator.defaultBootstrap - @inline override protected[this] def defaultBootstrapActivation: Activation = BootstrapLocator.defaultBootstrapActivation + @inline override protected def defaultBootstrap: BootstrapContextModule = BootstrapLocator.defaultBootstrap + @inline override protected def defaultBootstrapActivation: Activation = BootstrapLocator.defaultBootstrapActivation } diff --git a/distage/distage-core/src/main/scala/izumi/distage/InjectorDefaultImpl.scala b/distage/distage-core/src/main/scala/izumi/distage/InjectorDefaultImpl.scala index 0395edd899..2b1ed45be0 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/InjectorDefaultImpl.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/InjectorDefaultImpl.scala @@ -29,10 +29,10 @@ final class InjectorDefaultImpl[F[_]]( override val tagK: TagK[F], ) extends Injector[F] { - private[this] val planner: Planner = bootstrapLocator.get[Planner] - private[this] val interpreter: PlanInterpreter = bootstrapLocator.get[PlanInterpreter] + private val planner: Planner = bootstrapLocator.get[Planner] + private val interpreter: PlanInterpreter = bootstrapLocator.get[PlanInterpreter] // passed-through into `Bootloader` - private[this] val bsModule: BootstrapModule = bootstrapLocator.get[BootstrapModule] + private val bsModule: BootstrapModule = bootstrapLocator.get[BootstrapModule] override def plan(input: PlannerInput): Either[NEList[DIError], Plan] = { planner.plan(addSelfInfo(input)) @@ -54,7 +54,7 @@ final class InjectorDefaultImpl[F[_]]( } // TODO: probably this should be a part of the Planner itself - private[this] def addSelfInfo(input: PlannerInput): PlannerInput = { + private def addSelfInfo(input: PlannerInput): PlannerInput = { val selfReflectionModule = InjectorDefaultImpl.selfReflectionModule(parentFactory, bsModule, defaultModule, input.activation, input) input.copy( @@ -114,7 +114,7 @@ object InjectorDefaultImpl { } } - private[this] lazy val selfReflectionKeys: Set[DIKey] = { + private lazy val selfReflectionKeys: Set[DIKey] = { // passing nulls as values to prevent key list getting out of sync val reflectModule = selfReflectionModule(null, null, null, null.asInstanceOf[Activation], null) val onlyKeys = reflectModule.keys diff --git a/distage/distage-core/src/main/scala/izumi/distage/InjectorFactory.scala b/distage/distage-core/src/main/scala/izumi/distage/InjectorFactory.scala index 5c9e6ad475..ac6bcb20dc 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/InjectorFactory.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/InjectorFactory.scala @@ -91,6 +91,6 @@ trait InjectorFactory { new Bootloader(this, bootstrapModule, bootstrapActivation, defaultModule.module, input) } - protected[this] def defaultBootstrap: BootstrapContextModule - protected[this] def defaultBootstrapActivation: Activation + protected def defaultBootstrap: BootstrapContextModule + protected def defaultBootstrapActivation: Activation } diff --git a/distage/distage-core/src/main/scala/izumi/distage/bootstrap/BootstrapLocator.scala b/distage/distage-core/src/main/scala/izumi/distage/bootstrap/BootstrapLocator.scala index 6956f83132..7f83c26f28 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/bootstrap/BootstrapLocator.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/bootstrap/BootstrapLocator.scala @@ -58,8 +58,8 @@ object BootstrapLocator { resource.unsafeGet().throwOnFailure() } - private[this] final val mirrorProvider = MirrorProvider.Impl - private[this] final val fullStackTraces = izumi.distage.DebugProperties.`izumi.distage.interpreter.full-stacktraces`.boolValue(true) + private final val mirrorProvider = MirrorProvider.Impl + private final val fullStackTraces = izumi.distage.DebugProperties.`izumi.distage.interpreter.full-stacktraces`.boolValue(true) private final val bootstrapPlanner: Planner = { val bootstrapObserver = new PlanningObserverAggregate(Set.empty) diff --git a/distage/distage-core/src/main/scala/izumi/distage/model/Injector.scala b/distage/distage-core/src/main/scala/izumi/distage/model/Injector.scala index 1a82d45b5a..2216690496 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/model/Injector.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/model/Injector.scala @@ -300,6 +300,6 @@ trait Injector[F[_]] extends Planner with Producer { def providedKeys: Set[DIKey] def providedEnvironment: InjectorProvidedEnv - protected[this] implicit def tagK: TagK[F] - protected[this] implicit def F: QuasiIO[F] + protected implicit def tagK: TagK[F] + protected implicit def F: QuasiIO[F] } diff --git a/distage/distage-core/src/main/scala/izumi/distage/planning/BindingTranslator.scala b/distage/distage-core/src/main/scala/izumi/distage/planning/BindingTranslator.scala index 5dc75ec16a..0214faef2b 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/planning/BindingTranslator.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/planning/BindingTranslator.scala @@ -63,7 +63,7 @@ object BindingTranslator { } } - private[this] def provisionSingleton[Err](handler: SubcontextHandler[Err], binding: Binding.ImplBinding): Either[Err, Seq[InstantiationOp]] = { + private def provisionSingleton[Err](handler: SubcontextHandler[Err], binding: Binding.ImplBinding): Either[Err, Seq[InstantiationOp]] = { val target = binding.key for { wiring <- implToWiring(handler, binding) @@ -72,7 +72,7 @@ object BindingTranslator { } } - private[this] def wiringToInstantiationOp(target: DIKey, binding: Binding, wiring: Wiring): Seq[InstantiationOp] = { + private def wiringToInstantiationOp(target: DIKey, binding: Binding, wiring: Wiring): Seq[InstantiationOp] = { wiring match { case w: SingletonWiring => Seq(pureWiringToWiringOp(target, binding, w)) @@ -91,7 +91,7 @@ object BindingTranslator { } } - private[this] def pureWiringToWiringOp(target: DIKey, binding: Binding, wiring: SingletonWiring): WiringOp = { + private def pureWiringToWiringOp(target: DIKey, binding: Binding, wiring: SingletonWiring): WiringOp = { val userBinding = OperationOrigin.UserBinding(binding) wiring match { case w: Function => @@ -110,7 +110,7 @@ object BindingTranslator { } } - private[this] def implToWiring[Err](handler: SubcontextHandler[Err], binding: Binding.ImplBinding): Either[Err, Wiring] = { + private def implToWiring[Err](handler: SubcontextHandler[Err], binding: Binding.ImplBinding): Either[Err, Wiring] = { binding.implementation match { case d: ImplDef.DirectImplDef => directImplToPureWiring(handler, binding, d) @@ -131,7 +131,7 @@ object BindingTranslator { } } - private[this] def directImplToPureWiring[Err]( + private def directImplToPureWiring[Err]( handler: SubcontextHandler[Err], binding: Binding, implementation: ImplDef.DirectImplDef, diff --git a/distage/distage-core/src/main/scala/izumi/distage/planning/PlannerDefaultImpl.scala b/distage/distage-core/src/main/scala/izumi/distage/planning/PlannerDefaultImpl.scala index d655d768f4..45aefe07a3 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/planning/PlannerDefaultImpl.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/planning/PlannerDefaultImpl.scala @@ -98,7 +98,7 @@ class PlannerDefaultImpl( hook.hookDefinition(module) } - protected[this] def updateKey(mutSel: MutSel[DIKey]): Either[NEList[DIError], DIKey] = { + protected def updateKey(mutSel: MutSel[DIKey]): Either[NEList[DIError], DIKey] = { mutSel.mut match { case Some(value) => updateKey(mutSel.key, value) @@ -107,7 +107,7 @@ class PlannerDefaultImpl( } } - protected[this] def updateKey(key: DIKey, mindex: Int): Either[NEList[DIError], DIKey] = { + protected def updateKey(key: DIKey, mindex: Int): Either[NEList[DIError], DIKey] = { key match { case DIKey.TypeKey(tpe, _) => Right(DIKey.TypeKey(tpe, Some(mindex))) @@ -125,7 +125,7 @@ class PlannerDefaultImpl( } @nowarn("msg=Unused import") - protected[this] def addImports(plan: DG[DIKey, InstantiationOp], roots: Roots): DG[DIKey, SemiplanOp] = { + protected def addImports(plan: DG[DIKey, InstantiationOp], roots: Roots): DG[DIKey, SemiplanOp] = { val imports = plan.successors.links.view .filterKeys(k => !plan.meta.nodes.contains(k)) diff --git a/distage/distage-core/src/main/scala/izumi/distage/planning/sequential/ForwardingRefResolverDefaultImpl.scala b/distage/distage-core/src/main/scala/izumi/distage/planning/sequential/ForwardingRefResolverDefaultImpl.scala index 87d6b5f9f8..b2cf847944 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/planning/sequential/ForwardingRefResolverDefaultImpl.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/planning/sequential/ForwardingRefResolverDefaultImpl.scala @@ -181,11 +181,11 @@ class ForwardingRefResolverDefaultImpl( } } - private[this] def isInvolvedIntoCycle[T](toPreds: Map[T, Set[T]])(key: T): Boolean = { + private def isInvolvedIntoCycle[T](toPreds: Map[T, Set[T]])(key: T): Boolean = { test(toPreds, Set.empty, key, key) } - private[this] def test[T](toPreds: Map[T, Set[T]], stack: Set[T], toTest: T, needle: T): Boolean = { + private def test[T](toPreds: Map[T, Set[T]], stack: Set[T], toTest: T, needle: T): Boolean = { val deps = toPreds.getOrElse(toTest, Set.empty) if (deps.contains(needle)) { diff --git a/distage/distage-core/src/main/scala/izumi/distage/planning/solver/GenericSemigraphTraverse.scala b/distage/distage-core/src/main/scala/izumi/distage/planning/solver/GenericSemigraphTraverse.scala index 8493a335e2..e7766f2a17 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/planning/solver/GenericSemigraphTraverse.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/planning/solver/GenericSemigraphTraverse.scala @@ -92,7 +92,7 @@ abstract class GenericSemigraphTraverse[Err]( } @nowarn("msg=Unused import") - protected[this] def trace( + protected def trace( allAxis: Map[String, Set[String]], allVisited: mutable.HashSet[(DIKey, Set[AxisPoint])], matrix: ImmutableMultiMap[DIKey, (InstantiationOp, Set[AxisPoint])], diff --git a/distage/distage-core/src/main/scala/izumi/distage/planning/solver/GraphQueries.scala b/distage/distage-core/src/main/scala/izumi/distage/planning/solver/GraphQueries.scala index c155c877a6..03cec74a5d 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/planning/solver/GraphQueries.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/planning/solver/GraphQueries.scala @@ -229,7 +229,7 @@ class GraphQueries( .iterator } - protected[this] def getAxisPoints(b: Binding): Set[AxisPoint] = { + protected def getAxisPoints(b: Binding): Set[AxisPoint] = { b.tags.collect { case AxisTag(axisValue) => axisValue.toAxisPoint diff --git a/distage/distage-core/src/main/scala/izumi/distage/planning/solver/PlanSolver.scala b/distage/distage-core/src/main/scala/izumi/distage/planning/solver/PlanSolver.scala index 03925bf673..14bc0dee97 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/planning/solver/PlanSolver.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/planning/solver/PlanSolver.scala @@ -216,5 +216,5 @@ object PlanSolver { } - private[this] final val enableDebugVerify = DebugProperties.`izumi.distage.debug.verify-all`.boolValue(false) + private final val enableDebugVerify = DebugProperties.`izumi.distage.debug.verify-all`.boolValue(false) } diff --git a/distage/distage-core/src/main/scala/izumi/distage/planning/solver/PlanVerifier.scala b/distage/distage-core/src/main/scala/izumi/distage/planning/solver/PlanVerifier.scala index 1eb90dce3e..223a691505 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/planning/solver/PlanVerifier.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/planning/solver/PlanVerifier.scala @@ -135,7 +135,7 @@ class PlanVerifier( }.toOption.get // traverse can't fail } - protected[this] def checkConflicts( + protected def checkConflicts( allAxis: Map[String, Set[String]], withoutCurrentActivations: Set[(InstantiationOp, Set[AxisPoint], Set[AxisPoint])], execOpIndex: MutableMultiMap[DIKey, InstantiationOp], @@ -161,7 +161,7 @@ class PlanVerifier( } } - protected[this] final def checkForConflictingAxisChoices( + protected final def checkForConflictingAxisChoices( ops: Set[(InstantiationOp, Set[AxisPoint], Set[AxisPoint])] ): List[ConflictingAxisChoices] = { ops.iterator.flatMap { @@ -173,7 +173,7 @@ class PlanVerifier( } /** this method fails in case any bindings in the set have indistinguishable activations */ - protected[this] final def checkForDuplicateActivations( + protected final def checkForDuplicateActivations( ops: Set[(InstantiationOp, Set[AxisPoint], Set[AxisPoint])] ): List[DuplicateActivations] = { val duplicateAxisMap = ops @@ -189,7 +189,7 @@ class PlanVerifier( } /** this method fails in case any bindings in the set have indistinguishable activations */ - @tailrec protected[this] final def checkForUnsolvableConflicts( + @tailrec protected final def checkForUnsolvableConflicts( ops: Set[(InstantiationOp, Set[AxisPoint], Set[AxisPoint])] ): List[UnsolvableConflict] = { // TODO: in case we implement precedence rules the implementation should change @@ -205,7 +205,7 @@ class PlanVerifier( } /** This method fails in case there are missing/uncovered points on any of the reachable axis */ - protected[this] final def checkForUnsaturatedAxis( + protected final def checkForUnsaturatedAxis( allAxis: Map[String, Set[String]], ops: Set[(InstantiationOp, Set[AxisPoint], Set[AxisPoint])], excludedActivations: Set[NESet[AxisPoint]], @@ -229,7 +229,7 @@ class PlanVerifier( } } - protected[this] final def checkForShadowedActivations( + protected final def checkForShadowedActivations( allAxis: Map[String, Set[String]], ops: Set[(ExecutableOp.InstantiationOp, Set[AxisPoint], Set[AxisPoint])], ): List[ShadowedActivation] = { @@ -255,7 +255,7 @@ class PlanVerifier( }.toList } - protected[this] def checkForIncompatibleEffectType( + protected def checkForIncompatibleEffectType( effectType: SafeType, ops: Set[(InstantiationOp, Set[AxisPoint], Set[AxisPoint])], ): List[IncompatibleEffectType] = { @@ -270,7 +270,7 @@ object PlanVerifier { def apply(): PlanVerifier = Default def apply(preps: GraphQueries): PlanVerifier = new PlanVerifier(preps) - private[this] object Default extends PlanVerifier(new GraphQueries(new BindingTranslator.Impl)) + private object Default extends PlanVerifier(new GraphQueries(new BindingTranslator.Impl)) sealed abstract class PlanVerifierResult { def issues: Option[NESet[PlanIssue]] diff --git a/distage/distage-core/src/main/scala/izumi/distage/provisioning/OperationExecutorImpl.scala b/distage/distage-core/src/main/scala/izumi/distage/provisioning/OperationExecutorImpl.scala index 9d64b231a4..a00f2441d3 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/provisioning/OperationExecutorImpl.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/provisioning/OperationExecutorImpl.scala @@ -28,7 +28,7 @@ class OperationExecutorImpl( )((_, trace) => F.pure(Left(UnexpectedStepProvisioning(step, trace.unsafeAttachTraceOrReturnNewThrowable())))) } - private[this] def executeUnsafe[F[_]: TagK]( + private def executeUnsafe[F[_]: TagK]( context: ProvisioningKeyProvider, step: NonImportOp, )(implicit F: QuasiIO[F] diff --git a/distage/distage-core/src/main/scala/izumi/distage/provisioning/PlanInterpreterNonSequentialRuntimeImpl.scala b/distage/distage-core/src/main/scala/izumi/distage/provisioning/PlanInterpreterNonSequentialRuntimeImpl.scala index d56a52b024..d621ce1a84 100644 --- a/distage/distage-core/src/main/scala/izumi/distage/provisioning/PlanInterpreterNonSequentialRuntimeImpl.scala +++ b/distage/distage-core/src/main/scala/izumi/distage/provisioning/PlanInterpreterNonSequentialRuntimeImpl.scala @@ -55,7 +55,7 @@ class PlanInterpreterNonSequentialRuntimeImpl( }).map(_.left.map(_.fail)) } - private[this] def instantiateImpl[F[_]: TagK]( + private def instantiateImpl[F[_]: TagK]( plan: Plan, parentContext: Locator, )(implicit F: QuasiIO[F] @@ -136,7 +136,7 @@ class PlanInterpreterNonSequentialRuntimeImpl( F.pure(Left(ctx.makeFailure(failed, fullStackTraces))) } - private[this] def integrationPlan[F[_]: TagK]( + private def integrationPlan[F[_]: TagK]( state: TraversalState, ctx: ProvisionMutable[F], )(implicit F: QuasiIO[F] @@ -160,7 +160,7 @@ class PlanInterpreterNonSequentialRuntimeImpl( } } - private[this] def prioritize(ops: Iterable[ExecutableOp], integrationPaths: Set[DIKey]): Seq[ExecutableOp] = ArraySeq.unsafeWrapArray { + private def prioritize(ops: Iterable[ExecutableOp], integrationPaths: Set[DIKey]): Seq[ExecutableOp] = ArraySeq.unsafeWrapArray { ops.toArray.sortBy { op => val repr = op.target.tpe.tag.repr @@ -198,7 +198,7 @@ class PlanInterpreterNonSequentialRuntimeImpl( } } - private[this] def addIntegrationCheckResult[F[_]: TagK]( + private def addIntegrationCheckResult[F[_]: TagK]( active: ProvisionMutable[F], integrationCheckFType: SafeType, result: TimedResult.Success, @@ -229,7 +229,7 @@ class PlanInterpreterNonSequentialRuntimeImpl( } } - private[this] def runIfIntegrationCheck[F[_]: TagK](op: NewObjectOp, integrationCheckFType: SafeType)(implicit F: QuasiIO[F]): F[Option[IntegrationCheckFailure]] = { + private def runIfIntegrationCheck[F[_]: TagK](op: NewObjectOp, integrationCheckFType: SafeType)(implicit F: QuasiIO[F]): F[Option[IntegrationCheckFailure]] = { op match { case i: NewObjectOp.CurrentContextInstance => if (i.implType <:< nullType) { @@ -248,7 +248,7 @@ class PlanInterpreterNonSequentialRuntimeImpl( } } - private[this] def checkOrFail[F[_]: TagK](key: DIKey, resource: Any)(implicit F: QuasiIO[F]): F[Option[IntegrationCheckFailure]] = { + private def checkOrFail[F[_]: TagK](key: DIKey, resource: Any)(implicit F: QuasiIO[F]): F[Option[IntegrationCheckFailure]] = { F.suspendF { resource .asInstanceOf[IntegrationCheck[F]] @@ -262,7 +262,7 @@ class PlanInterpreterNonSequentialRuntimeImpl( } } - private[this] def verifyEffectType[F[_]: TagK]( + private def verifyEffectType[F[_]: TagK]( ops: Iterable[ExecutableOp] )(implicit F: QuasiIO[F] ): F[Either[Iterable[IncompatibleEffectTypes], Unit]] = { diff --git a/distage/distage-extension-config/.jvm/src/main/scala/izumi/distage/config/codec/DIConfigReader.scala b/distage/distage-extension-config/.jvm/src/main/scala/izumi/distage/config/codec/DIConfigReader.scala index e96d5e7cdb..e9f9f52ecd 100644 --- a/distage/distage-extension-config/.jvm/src/main/scala/izumi/distage/config/codec/DIConfigReader.scala +++ b/distage/distage-extension-config/.jvm/src/main/scala/izumi/distage/config/codec/DIConfigReader.scala @@ -82,7 +82,7 @@ trait DIConfigReader[A] extends AbstractDIConfigReader[A] { } } - private[this] def unpackResult[T: Tag](config: DistageConfigImpl, path: String)(t: => Try[T]): T = { + private def unpackResult[T: Tag](config: DistageConfigImpl, path: String)(t: => Try[T]): T = { Try(t).flatten match { case Failure(exception) => throw new DIConfigReadException( diff --git a/distage/distage-extension-plugins/.jvm/src/main/scala/izumi/distage/plugins/load/PluginLoaderDefaultImpl.scala b/distage/distage-extension-plugins/.jvm/src/main/scala/izumi/distage/plugins/load/PluginLoaderDefaultImpl.scala index 0f43b30c39..4373592271 100644 --- a/distage/distage-extension-plugins/.jvm/src/main/scala/izumi/distage/plugins/load/PluginLoaderDefaultImpl.scala +++ b/distage/distage-extension-plugins/.jvm/src/main/scala/izumi/distage/plugins/load/PluginLoaderDefaultImpl.scala @@ -20,7 +20,7 @@ class PluginLoaderDefaultImpl extends PluginLoader { LoadedPlugins(loadedPlugins, config.merges, config.overrides) } - protected[this] def scanClasspath(config: PluginConfig): Seq[PluginBase] = { + protected def scanClasspath(config: PluginConfig): Seq[PluginBase] = { val enabledPackages = config.packagesEnabled.filterNot(p => config.packagesDisabled.contains(p) || p == "_root_") val disabledPackages = config.packagesDisabled diff --git a/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/PluginConfig.scala b/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/PluginConfig.scala index ed15c6e79d..d9af064e43 100644 --- a/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/PluginConfig.scala +++ b/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/PluginConfig.scala @@ -64,5 +64,5 @@ object PluginConfig extends PluginConfigStatic { /** A [[PluginConfig]] that returns no plugins */ lazy val empty: PluginConfig = const(Nil) - private[this] lazy val cacheEnabled: Boolean = DebugProperties.`izumi.distage.plugins.cache`.boolValue(true) + private lazy val cacheEnabled: Boolean = DebugProperties.`izumi.distage.plugins.cache`.boolValue(true) } diff --git a/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala b/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala index 745e2cd5d9..860705f067 100644 --- a/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala +++ b/distage/distage-framework-api/src/main/scala-2/izumi/distage/roles/model/definition/RoleModuleDef.scala @@ -10,7 +10,7 @@ import scala.language.experimental.macros import scala.reflect.macros.blackbox trait RoleModuleDef extends ModuleDef { - final protected[this] def makeRole[T](implicit getRoleDescriptor: GetRoleDescriptor[T]): MakeDSL[T] = macro RoleModuleDefMacros.makeRole[T] + final protected def makeRole[T](implicit getRoleDescriptor: GetRoleDescriptor[T]): MakeDSL[T] = macro RoleModuleDefMacros.makeRole[T] } object RoleModuleDef { diff --git a/distage/distage-framework-api/src/main/scala-3/izumi/distage/roles/model/definition/RoleModuleDef.scala b/distage/distage-framework-api/src/main/scala-3/izumi/distage/roles/model/definition/RoleModuleDef.scala index 0ac2186a87..d4bf795da7 100644 --- a/distage/distage-framework-api/src/main/scala-3/izumi/distage/roles/model/definition/RoleModuleDef.scala +++ b/distage/distage-framework-api/src/main/scala-3/izumi/distage/roles/model/definition/RoleModuleDef.scala @@ -9,7 +9,7 @@ import izumi.distage.roles.model.definition.RoleModuleDef.RoleModuleDefMacros import scala.quoted.{Expr, Quotes, Type} trait RoleModuleDef extends ModuleDef { - inline final protected[this] def makeRole[T](implicit getRoleDescriptor: GetRoleDescriptor[T]): MakeDSL[T] = + inline final protected def makeRole[T](implicit getRoleDescriptor: GetRoleDescriptor[T]): MakeDSL[T] = ${ RoleModuleDefMacros.makeRole[T]('getRoleDescriptor) } } diff --git a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/ContainerNetworkDef.scala b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/ContainerNetworkDef.scala index 6e28dde9e9..e623d5a7c9 100644 --- a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/ContainerNetworkDef.scala +++ b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/ContainerNetworkDef.scala @@ -58,8 +58,8 @@ object ContainerNetworkDef { ) extends Lifecycle.Basic[F, ContainerNetwork[T]] { import client.rawClient - private[this] val prefix: String = prefixName.camelToUnderscores.replace("$", "") - private[this] val networkLabels: Map[String, String] = Map( + private val prefix: String = prefixName.camelToUnderscores.replace("$", "") + private val networkLabels: Map[String, String] = Map( DockerConst.Labels.reuseLabel -> Docker.shouldReuse(config.reuse, client.clientConfig.globalReuse).toString, s"${DockerConst.Labels.networkDriverPrefix}.${config.driver}" -> true.toString, DockerConst.Labels.namePrefixLabel -> prefix, @@ -116,7 +116,7 @@ object ContainerNetworkDef { } } - private[this] def createNewRandomizedNetwork(): F[ContainerNetwork[T]] = { + private def createNewRandomizedNetwork(): F[ContainerNetwork[T]] = { F.maybeSuspend { val name = config.name.getOrElse(s"$prefix-${UUID.randomUUID().toString.take(8)}") logger.info(s"Going to create new ${prefix -> "network"}->$name") @@ -130,7 +130,7 @@ object ContainerNetworkDef { } } - private[this] def integrationCheckHack[A](f: => F[A]): F[A] = { + private def integrationCheckHack[A](f: => F[A]): F[A] = { // FIXME: temporary hack to allow missing containers to skip tests (happens when both DockerWrapper & integration check that depends on Docker.Container are memoized) F.definitelyRecoverUnsafeIgnoreTrace(f) { (c: Throwable) => diff --git a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/DockerContainer.scala b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/DockerContainer.scala index 54663f6666..4a29fc1979 100644 --- a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/DockerContainer.scala +++ b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/DockerContainer.scala @@ -183,7 +183,7 @@ object DockerContainer { } } - private[this] def addContainerDependency[T2]( + private def addContainerDependency[T2]( implicit tag: distage.Tag[DockerContainer[T2]], selfTag: distage.Tag[DockerContainer[T]], mutateModule: ModuleDefDSL#MutationContext, diff --git a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/ContainerResource.scala b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/ContainerResource.scala index 4e2763de30..d0d0d73e24 100644 --- a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/ContainerResource.scala +++ b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/ContainerResource.scala @@ -41,7 +41,7 @@ open class ContainerResource[F[_], Tag]( import client.rawClient - protected[this] val stableLabels: Map[String, String] = { + protected val stableLabels: Map[String, String] = { val reuseLabel = Map( DockerConst.Labels.reuseLabel -> Docker.shouldReuse(config.reuse, client.clientConfig.globalReuse).toString, DockerConst.Labels.dependencies -> deps.map(_.id.name).toList.sorted.mkString(";"), @@ -49,7 +49,7 @@ open class ContainerResource[F[_], Tag]( reuseLabel ++ client.labels ++ config.userTags } - protected[this] def toExposedPort(port: DockerPort, number: Int): ExposedPort = { + protected def toExposedPort(port: DockerPort, number: Int): ExposedPort = { port match { case _: DockerPort.TCPBase => ExposedPort.tcp(number) case _: DockerPort.UDPBase => ExposedPort.udp(number) @@ -107,7 +107,7 @@ open class ContainerResource[F[_], Tag]( } } - protected[this] def await(container0: DockerContainer[Tag]): F[DockerContainer[Tag]] = F.tailRecM((container0, 0)) { + protected def await(container0: DockerContainer[Tag]): F[DockerContainer[Tag]] = F.tailRecM((container0, 0)) { case (container, attempt) => F.maybeSuspend { logger.debug(s"Awaiting until alive: $container...") @@ -200,7 +200,7 @@ open class ContainerResource[F[_], Tag]( } } - protected[this] def runReused(imageName: String, imageRegistry: Option[String], registryAuth: Option[AuthConfig], ports: Seq[PortDecl]): F[DockerContainer[Tag]] = { + protected def runReused(imageName: String, imageRegistry: Option[String], registryAuth: Option[AuthConfig], ports: Seq[PortDecl]): F[DockerContainer[Tag]] = { logger.info(s"About to start or find container $imageName, ${config.pullTimeout -> "timeout"}...") fileLockMutex(s"distage-container-resource-$imageName:${config.ports.mkString(";")}") { for { @@ -323,7 +323,7 @@ open class ContainerResource[F[_], Tag]( } } - protected[this] def runNew(imageName: String, imageRegistry: Option[String], registryAuth: Option[AuthConfig], ports: Seq[PortDecl]): F[DockerContainer[Tag]] = { + protected def runNew(imageName: String, imageRegistry: Option[String], registryAuth: Option[AuthConfig], ports: Seq[PortDecl]): F[DockerContainer[Tag]] = { val allPortLabels = ports.flatMap(p => p.labels).toMap ++ stableLabels val baseCmd = rawClient.createContainerCmd(imageName).withLabels(allPortLabels.asJava) @@ -403,7 +403,7 @@ open class ContainerResource[F[_], Tag]( } yield result } - protected[this] def doPull(imageName: String, registry: Option[String], registryAuth: Option[AuthConfig]): F[Unit] = { + protected def doPull(imageName: String, registry: Option[String], registryAuth: Option[AuthConfig]): F[Unit] = { def pullWithRetry(attempt: Int = 0): F[Unit] = { F.maybeSuspend( Try { @@ -457,7 +457,7 @@ open class ContainerResource[F[_], Tag]( } } - protected[this] def inspectContainerAndGetState(containerId: String): Either[Throwable, ContainerState] = { + protected def inspectContainerAndGetState(containerId: String): Either[Throwable, ContainerState] = { try { val status = rawClient.inspectContainerCmd(containerId).exec() status.getState match { @@ -470,7 +470,7 @@ open class ContainerResource[F[_], Tag]( } } - protected[this] def mapContainerPorts(inspection: InspectContainerResponse): Either[UnmappedPorts, ReportedContainerConnectivity] = { + protected def mapContainerPorts(inspection: InspectContainerResponse): Either[UnmappedPorts, ReportedContainerConnectivity] = { val network = inspection.getNetworkSettings val labels = inspection.getConfig.getLabels val ports = config.ports.map { @@ -507,13 +507,13 @@ open class ContainerResource[F[_], Tag]( } } - private[this] def renderImageName(registry: Option[String]) = { + private def renderImageName(registry: Option[String]) = { registry .filterNot(_.contains("index.docker.io")) .fold(config.image)(reg => s"$reg/${config.image}") } - private[this] def fileLockMutex[A]( + private def fileLockMutex[A]( name: String )(effect: // MUST be by-name because of QuasiIO[Identity] diff --git a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/DockerClientWrapper.scala b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/DockerClientWrapper.scala index f972d72f35..85a38dcb09 100644 --- a/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/DockerClientWrapper.scala +++ b/distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/DockerClientWrapper.scala @@ -72,7 +72,7 @@ class DockerClientWrapper[F[_]]( } object DockerClientWrapper { - private[this] val jvmRun: String = UUID.randomUUID().toString + private val jvmRun: String = UUID.randomUUID().toString sealed trait ContainerDestroyMeta object ContainerDestroyMeta { diff --git a/distage/distage-framework-docker/src/test/scala/izumi/distage/testkit/docker/fixtures/ReusedOneshotContainer.scala b/distage/distage-framework-docker/src/test/scala/izumi/distage/testkit/docker/fixtures/ReusedOneshotContainer.scala index 8d3ead98a2..d2f5d31f23 100644 --- a/distage/distage-framework-docker/src/test/scala/izumi/distage/testkit/docker/fixtures/ReusedOneshotContainer.scala +++ b/distage/distage-framework-docker/src/test/scala/izumi/distage/testkit/docker/fixtures/ReusedOneshotContainer.scala @@ -65,7 +65,7 @@ class CmdContainerModule[F[_]: TagK] extends ModuleDef { object CmdContainerModule { def apply[F[_]: TagK]: CmdContainerModule[F] = new CmdContainerModule[F] - private[this] val runId: String = UUID.randomUUID().toString + private val runId: String = UUID.randomUUID().toString val stateFileMount: Mount = Mount("/tmp/", "/tmp/docker-test/") val stateFilePath: String = s"/tmp/docker-test/docker-test-$runId.txt" diff --git a/distage/distage-framework/.jvm/src/main/scala-2/izumi/distage/framework/PlanCheckMaterializer.scala b/distage/distage-framework/.jvm/src/main/scala-2/izumi/distage/framework/PlanCheckMaterializer.scala index 3e18a2ddf5..fdd06cc399 100644 --- a/distage/distage-framework/.jvm/src/main/scala-2/izumi/distage/framework/PlanCheckMaterializer.scala +++ b/distage/distage-framework/.jvm/src/main/scala-2/izumi/distage/framework/PlanCheckMaterializer.scala @@ -171,7 +171,7 @@ object PlanCheckMaterializer { } } - private[this] def instantiateObject[T](u: Universe)(implicit tpe: u.WeakTypeTag[T]): T = { + private def instantiateObject[T](u: Universe)(implicit tpe: u.WeakTypeTag[T]): T = { val symbol = tpe.tpe.erasure.typeSymbol if (symbol.owner.isPackage || symbol.owner.isPackageClass) { val className = s"${symbol.fullName}$$" diff --git a/distage/distage-framework/.jvm/src/main/scala-3/izumi/distage/framework/PlanCheckMaterializer.scala b/distage/distage-framework/.jvm/src/main/scala-3/izumi/distage/framework/PlanCheckMaterializer.scala index 1b6af57296..94657aa6ff 100644 --- a/distage/distage-framework/.jvm/src/main/scala-3/izumi/distage/framework/PlanCheckMaterializer.scala +++ b/distage/distage-framework/.jvm/src/main/scala-3/izumi/distage/framework/PlanCheckMaterializer.scala @@ -167,7 +167,7 @@ object PlanCheckMaterializer extends PlanCheckMaterializerCommon { } } - private[this] def instantiateObject[T: Type](using qctx: Quotes): T = { + private def instantiateObject[T: Type](using qctx: Quotes): T = { import qctx.reflect.* val symbol = TypeRepr.of[T].typeSymbol val className = symbol.fullName.replace("$.", "$") // hack around nested objects diff --git a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/CheckableApp.scala b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/CheckableApp.scala index 53bcfaac3d..20903d908d 100644 --- a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/CheckableApp.scala +++ b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/CheckableApp.scala @@ -115,7 +115,7 @@ abstract class RoleCheckableApp[F[_]](override implicit val tagK: TagK[F]) exten }) } - protected[this] final def roleAppBootModulePlanCheckOverrides( + protected final def roleAppBootModulePlanCheckOverrides( chosenRoles: RoleSelection, chosenConfigResource: Option[(ClassLoader, String)], ): ModuleDef = { @@ -152,7 +152,7 @@ abstract class RoleCheckableApp[F[_]](override implicit val tagK: TagK[F]) exten // keep original ConfigLoader } - private[this] def namePredicateRoleProvider(f: String => Boolean): Functoid[RoleProvider] = { + private def namePredicateRoleProvider(f: String => Boolean): Functoid[RoleProvider] = { // use Auto-Traits feature to override just the few specific methods of a class succinctly @impl trait NamePredicateRoleProvider extends RoleProvider.ReflectiveImpl { override protected def isRoleEnabled(requiredRoles: Set[String])(b: RoleBinding): Boolean = { @@ -167,7 +167,7 @@ abstract class RoleCheckableApp[F[_]](override implicit val tagK: TagK[F]) exten TraitConstructor[NamePredicateRoleProvider] } - private[this] def specificResourceConfigLoader(classLoader: ClassLoader, resourceName: String): ConfigLoader = { + private def specificResourceConfigLoader(classLoader: ClassLoader, resourceName: String): ConfigLoader = { (_: String) => val cfg = ConfigFactory.parseResources(classLoader, resourceName).resolve() if (cfg.origin().resource() eq null) { diff --git a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/PlanCheck.scala b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/PlanCheck.scala index af73bb1124..6f0de102f9 100644 --- a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/PlanCheck.scala +++ b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/PlanCheck.scala @@ -244,7 +244,7 @@ object PlanCheck { } } - private[this] def checkAnyApp[F[_]]( + private def checkAnyApp[F[_]]( planVerifier: PlanVerifier, excludedActivations: Set[NESet[AxisPoint]], checkConfig: Boolean, @@ -309,7 +309,7 @@ object PlanCheck { final case class AllExcluding(excluded: Set[String]) extends RoleSelection } - private[this] def parseRoles(s: String): RoleSelection = { + private def parseRoles(s: String): RoleSelection = { val tokens = s.split(" ").iterator.filter(_.nonEmpty).toList tokens match { case "*" :: Nil => @@ -323,7 +323,7 @@ object PlanCheck { } } - private[this] def throwInvalidRoleSelectionError(s: String): Nothing = { + private def throwInvalidRoleSelectionError(s: String): Nothing = { throw new IllegalArgumentException( s"""Invalid role selection syntax in `$s`. | @@ -336,17 +336,17 @@ object PlanCheck { ) } - private[this] def parseActivations(s: String): Set[NESet[AxisPoint]] = { + private def parseActivations(s: String): Set[NESet[AxisPoint]] = { s.split("\\|").iterator.filter(_.nonEmpty).flatMap { NESet `from` _.split(" ").iterator.filter(_.nonEmpty).map(AxisPoint.parseAxisPoint).toSet }.toSet } - private[this] def defaultLogger(): TrivialLogger = { + private def defaultLogger(): TrivialLogger = { TrivialLogger.make[this.type](DebugProperties.`izumi.debug.macro.distage.plancheck`.name) } - @tailrec private[this] def cutoffMacroTrace(t: Throwable): Unit = { + @tailrec private def cutoffMacroTrace(t: Throwable): Unit = { val trace = t.getStackTrace val cutoffIdx = Some(trace.indexWhere(_.getClassName contains "scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers")).filter(_ > 0) t.setStackTrace(cutoffIdx.fold(trace)(trace.take)) @@ -355,7 +355,7 @@ object PlanCheck { if (t.getCause ne null) cutoffMacroTrace(t.getCause) } // indirection for tailrec - private[this] def cutSuppressed(t: Throwable): Unit = cutoffMacroTrace(t) + private def cutSuppressed(t: Throwable): Unit = cutoffMacroTrace(t) } diff --git a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/services/ResourceRewriter.scala b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/services/ResourceRewriter.scala index b27df18b69..87ae0a380e 100644 --- a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/services/ResourceRewriter.scala +++ b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/services/ResourceRewriter.scala @@ -81,7 +81,7 @@ class ResourceRewriter( } } - @inline private[this] def quickSubtypeCheck(tgt: SafeType, implType: SafeType): Boolean = { + @inline private def quickSubtypeCheck(tgt: SafeType, implType: SafeType): Boolean = { if (tgt.hasPreciseClass && implType.hasPreciseClass) { tgt.closestClass.isAssignableFrom(implType.closestClass) } else { diff --git a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/bundled/ConfigWriter.scala b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/bundled/ConfigWriter.scala index ac2c3a56f8..b71471d0d2 100644 --- a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/bundled/ConfigWriter.scala +++ b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/bundled/ConfigWriter.scala @@ -40,7 +40,7 @@ final class ConfigWriter[F[_]: TagK]( // fixme: always include `activation` section in configs (Used in RoleAppLauncherImpl#configActivationSection, but not seen in config bindings, since it's not read by DI) // should've been unnecessary after https://github.com/7mind/izumi/issues/779 // but, the contents of the MainAppModule (including `"activation"` config read) are not accessible here from `RoleAppPlanner` yet... - private[this] val _HackyMandatorySection = ConfigPath("activation", wildcard = true) + private val _HackyMandatorySection = ConfigPath("activation", wildcard = true) private val configMerger = new ConfigMerger.ConfigMergerImpl(logger) override def start(roleParameters: RawEntrypointParams, @unused freeArgs: Vector[String]): F[Unit] = { @@ -50,7 +50,7 @@ final class ConfigWriter[F[_]: TagK]( } } - private[this] def writeReferenceConfig(options: WriteReference): Unit = { + private def writeReferenceConfig(options: WriteReference): Unit = { val configPath = Paths.get(options.targetDir).toFile logger.info(s"Config ${configPath.getAbsolutePath -> "target directory"}...") @@ -95,7 +95,7 @@ final class ConfigWriter[F[_]: TagK]( } } - private[this] def outputFileName(service: String, version: Option[String], asJson: Boolean, suffix: Option[String]): String = { + private def outputFileName(service: String, version: Option[String], asJson: Boolean, suffix: Option[String]): String = { val extension = if (asJson) "json" else "conf" val vstr = version.getOrElse("0.0.0-UNKNOWN") val suffixStr = suffix.fold("")("-" + _) @@ -103,7 +103,7 @@ final class ConfigWriter[F[_]: TagK]( s"$service$suffixStr-$vstr.$extension" } - private[this] def minimizedConfig(roleConfig: Config, role: RoleBinding): MinimizedConfig = { + private def minimizedConfig(roleConfig: Config, role: RoleBinding): MinimizedConfig = { val excludedActivations = Set.empty[NESet[AxisPoint]] // TODO: val chosenActivations = parseActivations(cfg.excludeActivations) val bindings = roleAppPlanner.bootloader.input.bindings val verifier = PlanVerifier() @@ -121,7 +121,7 @@ final class ConfigWriter[F[_]: TagK]( MinimizedConfig(out, schema) } - private[this] def writeConfig(options: WriteReference, fileName: String, typesafeConfig: Config, schema: Option[Json], subLogger: IzLogger): Try[Unit] = { + private def writeConfig(options: WriteReference, fileName: String, typesafeConfig: Config, schema: Option[Json], subLogger: IzLogger): Try[Unit] = { val configRenderOptions = ConfigRenderOptions.defaults.setOriginComments(false).setComments(false) val target = Paths.get(options.targetDir, fileName) val targetSchema = Paths.get(options.targetDir, s"$fileName.jsonschema") diff --git a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/bundled/Help.scala b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/bundled/Help.scala index d9b36b6886..4e8c15019b 100644 --- a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/bundled/Help.scala +++ b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/bundled/Help.scala @@ -21,7 +21,7 @@ class Help[F[_]]( F.maybeSuspend(showHelp()) } - private[this] def showHelp(): Unit = { + private def showHelp(): Unit = { val descriptors = roleInfo.availableRoleBindings .map(rb => rb.descriptor.parserSchema) diff --git a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/launcher/ActivationParser.scala b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/launcher/ActivationParser.scala index be743db82c..28f230d135 100644 --- a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/launcher/ActivationParser.scala +++ b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/launcher/ActivationParser.scala @@ -15,7 +15,7 @@ import izumi.logstage.api.IzLogger trait ActivationParser extends AbstractActivationParser {} object ActivationParser { - private[this] final val syspropWarnUnsetActivations = DebugProperties.`izumi.distage.roles.activation.warn-unset`.boolValue(true) + private final val syspropWarnUnsetActivations = DebugProperties.`izumi.distage.roles.activation.warn-unset`.boolValue(true) class Impl( parser: RoleAppActivationParser, diff --git a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/launcher/LogConfigLoader.scala b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/launcher/LogConfigLoader.scala index 4ecf7ee293..73d161c83d 100644 --- a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/launcher/LogConfigLoader.scala +++ b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/roles/launcher/LogConfigLoader.scala @@ -65,7 +65,7 @@ object LogConfigLoader { DeclarativeLoggerConfig(format, options, levels, cliOptions.level, jul) } - private[this] def readConfig(config: AppConfig): SinksConfig = { + private def readConfig(config: AppConfig): SinksConfig = { Try(config.config.getConfig("logger")).toEither.left .map(_ => Message("No `logger` section in config. Using defaults.")) .flatMap { diff --git a/distage/distage-framework/src/main/scala/izumi/distage/framework/services/RoleAppPlanner.scala b/distage/distage-framework/src/main/scala/izumi/distage/framework/services/RoleAppPlanner.scala index a98599a264..5e0a729bba 100644 --- a/distage/distage-framework/src/main/scala/izumi/distage/framework/services/RoleAppPlanner.scala +++ b/distage/distage-framework/src/main/scala/izumi/distage/framework/services/RoleAppPlanner.scala @@ -39,7 +39,7 @@ object RoleAppPlanner { )*/ extends RoleAppPlanner { self => - private[this] val runtimeGcRoots: Set[DIKey] = Set( + private val runtimeGcRoots: Set[DIKey] = Set( DIKey.get[QuasiIORunner[F]], DIKey.get[QuasiIO[F]], DIKey.get[QuasiAsync[F]], diff --git a/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/AppShutdownStrategy.scala b/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/AppShutdownStrategy.scala index 767959dc04..eb59a2e091 100644 --- a/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/AppShutdownStrategy.scala +++ b/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/AppShutdownStrategy.scala @@ -47,9 +47,9 @@ trait AppShutdownStrategy[F[_]] extends AppShutdownInitiator { } object AppShutdownStrategy { - private[this] val logger = TrivialLogger.make[FallbackConsoleSink](DebugProperties.`izumi.debug.distage.shutdown`.name) + private val logger = TrivialLogger.make[FallbackConsoleSink](DebugProperties.`izumi.debug.distage.shutdown`.name) - private[this] def makeShutdownHook(logger: IzLogger, cont: () => Unit): Thread = { + private def makeShutdownHook(logger: IzLogger, cont: () => Unit): Thread = { new Thread( () => { logger.warn("Termination signal received") diff --git a/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/RoleAppActivationParser.scala b/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/RoleAppActivationParser.scala index 30bfd69f49..726989c9be 100644 --- a/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/RoleAppActivationParser.scala +++ b/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/RoleAppActivationParser.scala @@ -13,7 +13,7 @@ trait RoleAppActivationParser { } object RoleAppActivationParser { - private[this] final val sysPropIgnoreUnknownActivations = DebugProperties.`izumi.distage.roles.activation.ignore-unknown`.boolValue(false) + private final val sysPropIgnoreUnknownActivations = DebugProperties.`izumi.distage.roles.activation.ignore-unknown`.boolValue(false) class Impl( logger: IzLogger, diff --git a/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/RoleProvider.scala b/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/RoleProvider.scala index e77a3199e2..b6f6dd4d7f 100644 --- a/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/RoleProvider.scala +++ b/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/RoleProvider.scala @@ -22,8 +22,8 @@ trait RoleProvider { } object RoleProvider { - private[this] final val sysPropIgnoreMismatchedEffect = DebugProperties.`izumi.distage.roles.ignore-mismatched-effect`.boolValue(false) - private[this] final val syspropRolesReflection = DebugProperties.`izumi.distage.roles.reflection`.boolValue(true) + private final val sysPropIgnoreMismatchedEffect = DebugProperties.`izumi.distage.roles.ignore-mismatched-effect`.boolValue(false) + private final val syspropRolesReflection = DebugProperties.`izumi.distage.roles.reflection`.boolValue(true) open class NonReflectiveImpl( logger: IzLogger @Id("early"), @@ -31,7 +31,7 @@ object RoleProvider { parameters: RawAppArgs, ) extends RoleProvider { - protected[this] val isIgnoredMismatchedEffect: Boolean = sysPropIgnoreMismatchedEffect || ignoreMismatchedEffect + protected val isIgnoredMismatchedEffect: Boolean = sysPropIgnoreMismatchedEffect || ignoreMismatchedEffect def loadRoles[F[_]: TagK](appModule: ModuleBase): RolesInfo = { val rolesInfo = getInfo( @@ -115,7 +115,7 @@ object RoleProvider { parameters: RawAppArgs, ) extends NonReflectiveImpl(logger, ignoreMismatchedEffect, parameters) { - protected[this] val isReflectionEnabled: Boolean = reflectionEnabled && syspropRolesReflection && IzPlatform.platform != ScalaPlatform.GraalVMNativeImage + protected val isReflectionEnabled: Boolean = reflectionEnabled && syspropRolesReflection && IzPlatform.platform != ScalaPlatform.GraalVMNativeImage override protected def handleMissingStaticMetadata(roleType: SafeType, s: ImplBinding): RoleBinding = { if (isReflectionEnabled) { diff --git a/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/StartupBanner.scala b/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/StartupBanner.scala index 1d1cc39bd9..61b2123b83 100644 --- a/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/StartupBanner.scala +++ b/distage/distage-framework/src/main/scala/izumi/distage/roles/launcher/StartupBanner.scala @@ -24,7 +24,7 @@ object StartupBanner { } } - private[this] def showDepData(logger: IzLogger, msg: String, clazz: Option[IzArtifact]): Unit = { + private def showDepData(logger: IzLogger, msg: String, clazz: Option[IzArtifact]): Unit = { val details = clazz.map(_.toString).getOrElse("{No version data}") logger.info(s"$msg : $details") } diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/DistageTestRunner.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/DistageTestRunner.scala index 043556d0a0..cae8b344df 100644 --- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/DistageTestRunner.scala +++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/DistageTestRunner.scala @@ -116,7 +116,7 @@ class DistageTestRunner[F[_]: TagK, G[_]]( } } - private[this] def logEnvironmentsInfo(envs: Map[PreparedTestEnv, TestTree[F]], duration: FiniteDuration): Unit = { + private def logEnvironmentsInfo(envs: Map[PreparedTestEnv, TestTree[F]], duration: FiniteDuration): Unit = { val testRunnerLogger = { val minimumLogLevel = envs.map(_._1.envExec.logLevel).toSeq.sorted.headOption.getOrElse(Log.Level.Info) IzLogger(minimumLogLevel)("phase" -> "testRunner") diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestPlanner.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestPlanner.scala index fb1198e604..a0125ec4f5 100644 --- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestPlanner.scala +++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestPlanner.scala @@ -227,7 +227,7 @@ class TestPlanner[F[_]: TagK: DefaultModule]( } } - private[this] def prepareTestEnv( + private def prepareTestEnv( envExecutionParams: EnvExecutionParams, env: TestEnvironment, tests: Seq[DistageTest[F]], @@ -348,7 +348,7 @@ class TestPlanner[F[_]: TagK: DefaultModule]( } } - private[this] def prepareSharedPlan( + private def prepareSharedPlan( envKeys: Set[DIKey], runtimeKeys: Set[DIKey], memoizationRoots: Set[DIKey], diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestTreeBuilder.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestTreeBuilder.scala index 5e247f5043..0b8620d313 100644 --- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestTreeBuilder.scala +++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/runner/impl/TestTreeBuilder.scala @@ -24,8 +24,8 @@ object TestTreeBuilder { ) extends TestTreeBuilder[F] { final class MemoizationTreeBuilder(planner: Planner, levelPlan: Plan) { - private[this] val children = TrieMap.empty[Plan, MemoizationTreeBuilder] - private[this] val groups = ArrayBuffer.empty[PackedEnv[F]] + private val children = TrieMap.empty[Plan, MemoizationTreeBuilder] + private val groups = ArrayBuffer.empty[PackedEnv[F]] def toImmutable: TestTree[F] = { toImmutable(Set.empty) diff --git a/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/DistageAbstractScalatestSpec.scala b/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/DistageAbstractScalatestSpec.scala index d7c83a28c0..ffe21916d0 100644 --- a/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/DistageAbstractScalatestSpec.scala +++ b/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/DistageAbstractScalatestSpec.scala @@ -17,7 +17,7 @@ import zio.ZIO import scala.annotation.unused trait WithSingletonTestRegistration[F[_]] extends AbstractDistageSpec[F] { - private[this] lazy val firstRegistration: Boolean = DistageTestsRegistrySingleton.registerSuite[F](this.getClass.getName) + private lazy val firstRegistration: Boolean = DistageTestsRegistrySingleton.registerSuite[F](this.getClass.getName) override def registerTest[A](function: Functoid[F[A]], env: TestEnvironment, pos: SourceFilePosition, id: TestId, meta: SuiteMeta): Unit = { if (firstRegistration) { @@ -33,12 +33,12 @@ trait DistageAbstractScalatestSpec[F[_]] extends ShouldVerb with MustVerb with C override protected def config: TestConfig = TestConfig.forSuite(this.getClass) - final protected[this] lazy val testEnv: TestEnvironment = makeTestEnv() - protected[this] def makeTestEnv(): TestEnvironment = loadEnvironment(config) + final protected lazy val testEnv: TestEnvironment = makeTestEnv() + protected def makeTestEnv(): TestEnvironment = loadEnvironment(config) - protected[this] def distageSuiteName: String = getSimpleNameOfAnObjectsClass(this) + protected def distageSuiteName: String = getSimpleNameOfAnObjectsClass(this) - protected[this] def distageSuiteId: SuiteId = SuiteId(this.getClass.getName) + protected def distageSuiteId: SuiteId = SuiteId(this.getClass.getName) protected implicit val subjectRegistrationFunction1: StringVerbBlockRegistration = new StringVerbBlockRegistration { override def apply(left: String, verb: String, @unused pos: source.Position, f: () => Unit): Unit = { @@ -46,7 +46,7 @@ trait DistageAbstractScalatestSpec[F[_]] extends ShouldVerb with MustVerb with C } } - protected[this] def registerBranch(description: String, verb: String, fun: () => Unit): Unit = { + protected def registerBranch(description: String, verb: String, fun: () => Unit): Unit = { context = Some(SuiteContext(Seq(description, verb))) fun() context = None diff --git a/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/DistageTestsRegistrySingleton.scala b/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/DistageTestsRegistrySingleton.scala index a4a62c467c..c2a9d5d629 100644 --- a/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/DistageTestsRegistrySingleton.scala +++ b/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/DistageTestsRegistrySingleton.scala @@ -14,14 +14,14 @@ import scala.util.chaining.scalaUtilChainingOps object DistageTestsRegistrySingleton { final case class SuiteReporter(tracker: Tracker, reporter: Reporter) - protected[this] type Fake[T] - private[this] object Fake - private[this] val registry = new mutable.HashMap[SafeType, mutable.ArrayBuffer[DistageTest[Fake]]]() - private[this] val statuses = new mutable.HashMap[SafeType, Option[mutable.HashMap[String, StatefulStatus]]]() - private[this] val suiteReporters = new mutable.HashMap[String, Either[mutable.ArrayBuffer[SuiteReporter => Unit], SuiteReporter]]() - private[this] val runTracker = new ConcurrentHashMap[SafeType, Fake.type]() - private[this] val knownSuites = new ConcurrentHashMap[(SafeType, String), Fake.type]() - private[this] val registrationOpen = new AtomicBoolean(true) + protected type Fake[T] + private object Fake + private val registry = new mutable.HashMap[SafeType, mutable.ArrayBuffer[DistageTest[Fake]]]() + private val statuses = new mutable.HashMap[SafeType, Option[mutable.HashMap[String, StatefulStatus]]]() + private val suiteReporters = new mutable.HashMap[String, Either[mutable.ArrayBuffer[SuiteReporter => Unit], SuiteReporter]]() + private val runTracker = new ConcurrentHashMap[SafeType, Fake.type]() + private val knownSuites = new ConcurrentHashMap[(SafeType, String), Fake.type]() + private val registrationOpen = new AtomicBoolean(true) def disableRegistration(): Unit = { registrationOpen.set(false) @@ -106,6 +106,6 @@ object DistageTestsRegistrySingleton { } } - @inline private[this] def castTest[F[_]](t: DistageTest[F]): DistageTest[Fake] = t.asInstanceOf[DistageTest[Fake]] - @inline private[this] def castArray[C[_], F[_]](a: C[DistageTest[Fake]]): C[DistageTest[F]] = a.asInstanceOf[C[DistageTest[F]]] + @inline private def castTest[F[_]](t: DistageTest[F]): DistageTest[Fake] = t.asInstanceOf[DistageTest[Fake]] + @inline private def castArray[C[_], F[_]](a: C[DistageTest[Fake]]): C[DistageTest[F]] = a.asInstanceOf[C[DistageTest[F]]] } diff --git a/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/SafeTestReporter.scala b/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/SafeTestReporter.scala index ae5a666bb6..9d510a1412 100644 --- a/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/SafeTestReporter.scala +++ b/distage/distage-testkit-scalatest/src/main/scala/izumi/distage/testkit/services/scalatest/dstest/SafeTestReporter.scala @@ -38,7 +38,7 @@ class SafeTestReporter(underlying: TestReporter) extends TestReporter { delayReport(scope, None, test, testStatus) } - private[this] def delayReport(scope: ScopeId, depth: Option[Int], test: FullMeta, testReport: TestStatus): Unit = synchronized { + private def delayReport(scope: ScopeId, depth: Option[Int], test: FullMeta, testReport: TestStatus): Unit = synchronized { (runningSuites.get(test.test.id.suite), testReport) match { // if the current test locked this suite, and its execution is done // then we will report all tests that were finished at this point for this suite @@ -55,7 +55,7 @@ class SafeTestReporter(underlying: TestReporter) extends TestReporter { } } - private[this] def putDelayedReport(scope: ScopeId, depth: Option[Int], meta: FullMeta, report: TestStatus): Unit = synchronized { + private def putDelayedReport(scope: ScopeId, depth: Option[Int], meta: FullMeta, report: TestStatus): Unit = synchronized { val buffer = delayedReports.getOrElseUpdate(meta, mutable.Queue.empty) depth match { case Some(value) => diff --git a/distage/distage-testkit-scalatest/src/main/scala/org/scalatest/distage/DistageScalatestReporter.scala b/distage/distage-testkit-scalatest/src/main/scala/org/scalatest/distage/DistageScalatestReporter.scala index 3e1ce88823..bb7ec8c5b2 100644 --- a/distage/distage-testkit-scalatest/src/main/scala/org/scalatest/distage/DistageScalatestReporter.scala +++ b/distage/distage-testkit-scalatest/src/main/scala/org/scalatest/distage/DistageScalatestReporter.scala @@ -197,7 +197,7 @@ class DistageScalatestReporter extends TestReporter { } } - @inline private[this] def doReport(suiteId: SuiteId)(f: Ordinal => Event): Unit = { + @inline private def doReport(suiteId: SuiteId)(f: Ordinal => Event): Unit = { DistageTestsRegistrySingleton.runReport(suiteId.suiteId)(sr => sr.reporter(f(sr.tracker.nextOrdinal()))) } diff --git a/distage/distage-testkit-scalatest/src/main/scala/org/scalatest/distage/DistageScalatestTestSuiteRunner.scala b/distage/distage-testkit-scalatest/src/main/scala/org/scalatest/distage/DistageScalatestTestSuiteRunner.scala index e926069523..f61506caae 100644 --- a/distage/distage-testkit-scalatest/src/main/scala/org/scalatest/distage/DistageScalatestTestSuiteRunner.scala +++ b/distage/distage-testkit-scalatest/src/main/scala/org/scalatest/distage/DistageScalatestTestSuiteRunner.scala @@ -153,7 +153,7 @@ abstract class DistageScalatestTestSuiteRunner[F[_]]( // initialize status early, so that runner can set it to `true` even before this test is discovered // by scalatest, if it was already executed by that time - private[this] val status: StatefulStatus = DistageTestsRegistrySingleton.registerStatus[F](suiteId) + private val status: StatefulStatus = DistageTestsRegistrySingleton.registerStatus[F](suiteId) override protected final def runNestedSuites(args: Args): Status = throw new UnsupportedOperationException override protected final def runTests(testName: Option[String], args: Args): Status = throw new UnsupportedOperationException diff --git a/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/generic/tests.scala b/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/generic/tests.scala index 7bdc827c56..9928e40150 100644 --- a/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/generic/tests.scala +++ b/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/generic/tests.scala @@ -72,7 +72,7 @@ class DistageTestExampleBIOEnv extends SpecZIO with DistageMemoizeExample[Task] object DistageTestExampleBase { class SetCounter { - private[this] val c: AtomicInteger = new AtomicInteger(0) + private val c: AtomicInteger = new AtomicInteger(0) def inc(): Unit = c.incrementAndGet().discard() def get: Int = c.get() } diff --git a/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/parallel/DistageParallelLevelTest.scala b/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/parallel/DistageParallelLevelTest.scala index d1e2ba00ca..e1c26efae5 100644 --- a/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/parallel/DistageParallelLevelTest.scala +++ b/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/parallel/DistageParallelLevelTest.scala @@ -28,9 +28,9 @@ sealed abstract class DistageParallelLevelTest[F[_]: TagK: DefaultModule]( suitesCounter: AtomicInteger )(implicit F: QuasiIO[F] ) extends Spec1[F] { - private[this] final val maxSuites = 3 - private[this] final val maxTests = 2 - private[this] final val testsCounter = new AtomicInteger(0) + private final val maxSuites = 3 + private final val maxTests = 2 + private final val testsCounter = new AtomicInteger(0) override protected def config: TestConfig = { super.config.copy( @@ -43,7 +43,7 @@ sealed abstract class DistageParallelLevelTest[F[_]: TagK: DefaultModule]( ) } - private[this] def checkCounters: QuasiTemporal[F] => F[Unit] = { + private def checkCounters: QuasiTemporal[F] => F[Unit] = { FT => F.suspendF { val testsCounterVal = testsCounter.addAndGet(1) diff --git a/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/sequential/DistageSequentialSuitesTest.scala b/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/sequential/DistageSequentialSuitesTest.scala index aa50d1a516..70657fa97c 100644 --- a/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/sequential/DistageSequentialSuitesTest.scala +++ b/distage/distage-testkit-scalatest/src/test/scala/izumi/distage/testkit/distagesuite/sequential/DistageSequentialSuitesTest.scala @@ -28,9 +28,9 @@ sealed abstract class DistageSequentialSuitesTest[F[_]: TagK: DefaultModule]( suitesCounter: AtomicInteger )(implicit F: QuasiIO[F] ) extends Spec1[F] { - private[this] val maxSuites = 1 - private[this] val maxTests = 2 - private[this] val testsCounter = new AtomicInteger(0) + private val maxSuites = 1 + private val maxTests = 2 + private val testsCounter = new AtomicInteger(0) override protected def config: TestConfig = { super.config.copy( @@ -43,7 +43,7 @@ sealed abstract class DistageSequentialSuitesTest[F[_]: TagK: DefaultModule]( ) } - private[this] def checkCounters: QuasiTemporal[F] => F[Unit] = { + private def checkCounters: QuasiTemporal[F] => F[Unit] = { FT => F.suspendF { val testsCounterVal = testsCounter.addAndGet(1) diff --git a/fundamentals/fundamentals-bio/.jvm/src/test/scala/izumi/functional/bio/laws/env/EqThrowable.scala b/fundamentals/fundamentals-bio/.jvm/src/test/scala/izumi/functional/bio/laws/env/EqThrowable.scala index bbc86a9f46..4e5c09a43e 100644 --- a/fundamentals/fundamentals-bio/.jvm/src/test/scala/izumi/functional/bio/laws/env/EqThrowable.scala +++ b/fundamentals/fundamentals-bio/.jvm/src/test/scala/izumi/functional/bio/laws/env/EqThrowable.scala @@ -16,7 +16,7 @@ trait EqThrowable { this: TestInstances => // Unwraps exceptions that got caught by Future's implementation // and that got wrapped in ExecutionException (`Future(throw ex)`) - private[this] def extractEx(ex: Throwable): Throwable = + private def extractEx(ex: Throwable): Throwable = ex match { case ref: ExecutionException => Option(ref.getCause).getOrElse(ref) diff --git a/fundamentals/fundamentals-bio/.jvm/src/test/scala/izumi/functional/bio/laws/env/MiniBIOEnv.scala b/fundamentals/fundamentals-bio/.jvm/src/test/scala/izumi/functional/bio/laws/env/MiniBIOEnv.scala index e5c643a37b..7498dd3328 100644 --- a/fundamentals/fundamentals-bio/.jvm/src/test/scala/izumi/functional/bio/laws/env/MiniBIOEnv.scala +++ b/fundamentals/fundamentals-bio/.jvm/src/test/scala/izumi/functional/bio/laws/env/MiniBIOEnv.scala @@ -28,6 +28,6 @@ trait MiniBIOEnv extends TestInstances with EqThrowable { equalityTry[A].eqv(tl, tr) } - private[this] def equalityTry[A: Eq]: Eq[Try[A]] = + private def equalityTry[A: Eq]: Eq[Try[A]] = Eq.by(_.toEither) } diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/CatsConversions.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/CatsConversions.scala index 3aa9c39b09..1aa06bc443 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/CatsConversions.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/CatsConversions.scala @@ -224,7 +224,7 @@ object CatsConversions { F.guaranteeOnInterrupt(fa, _ => F.orTerminate(fin)) } - @inline protected[this] final def toPoll(restoreInterruption: RestoreInterruption2[F]): Poll[F[Throwable, _]] = { + @inline protected final def toPoll(restoreInterruption: RestoreInterruption2[F]): Poll[F[Throwable, _]] = { new Poll[F[Throwable, _]] { override def apply[A](fa: F[Throwable, A]): F[Throwable, A] = restoreInterruption(fa) } @@ -528,7 +528,7 @@ object CatsConversions { } - private[this] def isUninterruptibleNoOp[F[+_, +_]](F: Panic2[F]): cats.effect.kernel.CancelScope = { + private def isUninterruptibleNoOp[F[+_, +_]](F: Panic2[F]): cats.effect.kernel.CancelScope = { val unit = F.unit if (F.uninterruptible(unit).asInstanceOf[AnyRef] eq unit.asInstanceOf[AnyRef]) { cats.effect.kernel.CancelScope.Uncancelable diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/DivergenceHelper.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/DivergenceHelper.scala index 414cbb5d72..8421093027 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/DivergenceHelper.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/DivergenceHelper.scala @@ -42,7 +42,7 @@ object DivergenceHelper { * The structural refinement must be placed directly on * the `C` type variable, not through an alias to work. */ - @nowarn("msg=never used") private[this] object Nondivergent { - @nowarn("msg=never used") private[this] type Of[A] = A { type Divergence = Nondivergent } + @nowarn("msg=never used") private object Nondivergent { + @nowarn("msg=never used") private type Of[A] = A { type Divergence = Nondivergent } } } diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/ErrorAccumulatingOps2.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/ErrorAccumulatingOps2.scala index 3a13063f3d..4ac0f18089 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/ErrorAccumulatingOps2.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/ErrorAccumulatingOps2.scala @@ -108,7 +108,7 @@ trait ErrorAccumulatingOps2[F[+_, +_]] { this: Error2[F] => flatTraverseAccumErrors(col)(identity) } - protected[this] def accumulateErrorsImpl[ColL[_], ColR[x] <: IterableOnce[x], E, E1, A, B, B1, AC]( + protected def accumulateErrorsImpl[ColL[_], ColR[x] <: IterableOnce[x], E, E1, A, B, B1, AC]( col: ColR[A] )(effect: A => F[E, B], onLeft: E => IterableOnce[E1], diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/IO2.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/IO2.scala index 04e4d74ea2..5eba83625e 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/IO2.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/IO2.scala @@ -52,7 +52,7 @@ trait IO2[F[+_, +_]] extends Panic2[F] { syncThrowable(effect.get) } - override protected[this] def accumulateErrorsImpl[ColL[_], ColR[x] <: IterableOnce[x], E, E1, A, B, B1, AC]( + override protected def accumulateErrorsImpl[ColL[_], ColR[x] <: IterableOnce[x], E, E1, A, B, B1, AC]( col: ColR[A] )(effect: A => F[E, B], onLeft: E => IterableOnce[E1], diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/BioEither.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/BioEither.scala index 8ea43de1c5..a3d262fee0 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/BioEither.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/BioEither.scala @@ -104,7 +104,7 @@ open class BioEither extends Error2[Either] { Right((bad.result(), good.result())) } - override protected[this] def accumulateErrorsImpl[ColL[_], ColR[x] <: IterableOnce[x], E, E1, A, B, B1, AC]( + override protected def accumulateErrorsImpl[ColL[_], ColR[x] <: IterableOnce[x], E, E1, A, B, B1, AC]( col: ColR[A] )(effect: A => Either[E, B], onLeft: E => IterableOnce[E1], diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/PrimitivesFromBIOAndCats.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/PrimitivesFromBIOAndCats.scala index b2b829cc7e..b7bd510936 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/PrimitivesFromBIOAndCats.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/PrimitivesFromBIOAndCats.scala @@ -5,8 +5,8 @@ import cats.effect.kernel.{Deferred, GenConcurrent, Ref, Sync} import izumi.functional.bio.{Async2, Fork2, Primitives2, Promise2, Ref2, Semaphore2, catz} open class PrimitivesFromBIOAndCats[F[+_, +_]: Async2: Fork2] extends Primitives2[F] { - private[this] val Concurrent: GenConcurrent[F[Throwable, _], Throwable] = catz.BIOToConcurrent(Async2, Async2, Fork2, this) - private[this] val Sync: Sync[F[Throwable, _]] = { + private val Concurrent: GenConcurrent[F[Throwable, _], Throwable] = catz.BIOToConcurrent(Async2, Async2, Fork2, this) + private val Sync: Sync[F[Throwable, _]] = { // pass nulls for blocking and clock since Ref.Make.syncInstance only uses the `delay` method of `Sync` catz.BIOToSync(Async2, null, null) } diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/SchedulerImpl.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/SchedulerImpl.scala index ac70beba91..c3465415d3 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/SchedulerImpl.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/impl/SchedulerImpl.scala @@ -24,7 +24,7 @@ open class SchedulerImpl[F[+_, +_]: Temporal2](implicit clock: Clock2[F]) extend eff.catchAll(err => loop(err, policy.action)(orElse)(eff.catchAll)) } - protected[this] def loop[E, S, A, B]( + protected def loop[E, S, A, B]( in: A, makeDecision: RetryFunction[F, A, S], )(stopper: A => F[E, B] diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/retry/RetryPolicy.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/retry/RetryPolicy.scala index 53f35bbc95..52cac03eaf 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/retry/RetryPolicy.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/retry/RetryPolicy.scala @@ -196,7 +196,7 @@ object RetryPolicy { exponential(baseDelay) && recurs(maxRetries) } - private[this] def multiply(delay: FiniteDuration, multiplier: Long): FiniteDuration = { + private def multiply(delay: FiniteDuration, multiplier: Long): FiniteDuration = { val base = BigInt(delay.toNanos) val result = base * BigInt(multiplier) val cappedResult = result min LongMax diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/syntax/Syntax2.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/syntax/Syntax2.scala index d33dd5a0a9..0a76e9a85d 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/syntax/Syntax2.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/bio/syntax/Syntax2.scala @@ -56,7 +56,7 @@ trait Syntax2 extends Syntax2.ImplicitPuns { object Syntax2 { - class FunctorOps[F[+_, +_], +E, +A](protected[this] val r: F[E, A])(implicit protected[this] val F: Functor2[F]) { + class FunctorOps[F[+_, +_], +E, +A](protected val r: F[E, A])(implicit protected val F: Functor2[F]) { @inline final def map[B](f: A => B): F[E, B] = F.map(r)(f) @inline final infix def as[B](b: => B): F[E, B] = F.map(r)(_ => b) @@ -66,7 +66,7 @@ object Syntax2 { @inline final def fromOptionOr[B](valueOnNone: => B)(implicit ev: A <:< Option[B]): F[E, B] = F.fromOptionOr(valueOnNone, widen) } - final class BifunctorOps[F[+_, +_], +E, +A](protected[this] val r: F[E, A])(implicit protected[this] val F: Bifunctor2[F]) { + final class BifunctorOps[F[+_, +_], +E, +A](protected val r: F[E, A])(implicit protected val F: Bifunctor2[F]) { @inline final def leftMap[E2](f: E => E2): F[E2, A] = F.leftMap(r)(f) @inline final def bimap[E2, B](f: E => E2, g: A => B): F[E2, B] = F.bimap(r)(f, g) @@ -74,7 +74,7 @@ object Syntax2 { @inline final def widenBoth[E1 >: E, A1](implicit @unused ev2: A <:< A1): F[E1, A1] = r.asInstanceOf[F[E1, A1]] } - class ApplicativeOps[F[+_, +_], +E, +A](override protected[this] val r: F[E, A])(implicit override protected[this] val F: Applicative2[F]) extends FunctorOps(r)(F) { + class ApplicativeOps[F[+_, +_], +E, +A](override protected val r: F[E, A])(implicit override protected val F: Applicative2[F]) extends FunctorOps(r)(F) { /** execute two operations in order, return result of second operation */ @inline final def *>[E1 >: E, B](f0: => F[E1, B]): F[E1, B] = F.*>(r, f0) @@ -91,11 +91,11 @@ object Syntax2 { @inline final def forever: F[E, Nothing] = F.forever(r) } - class GuaranteeOps[F[+_, +_], +E, +A](override protected[this] val r: F[E, A])(implicit override protected[this] val F: Guarantee2[F]) extends ApplicativeOps(r)(F) { + class GuaranteeOps[F[+_, +_], +E, +A](override protected val r: F[E, A])(implicit override protected val F: Guarantee2[F]) extends ApplicativeOps(r)(F) { @inline final def guarantee(cleanup: F[Nothing, Unit]): F[E, A] = F.guarantee(r, cleanup) } - class ApplicativeErrorOps[F[+_, +_], +E, +A](override protected[this] val r: F[E, A])(implicit override protected[this] val F: ApplicativeError2[F]) + class ApplicativeErrorOps[F[+_, +_], +E, +A](override protected val r: F[E, A])(implicit override protected val F: ApplicativeError2[F]) extends GuaranteeOps(r)(F) { @inline final def leftMap[E2](f: E => E2): F[E2, A] = F.leftMap(r)(f) @inline final def bimap[E2, B](f: E => E2, g: A => B): F[E2, B] = F.bimap(r)(f, g) @@ -107,7 +107,7 @@ object Syntax2 { @inline final def widenBoth[E1 >: E, A1](implicit @unused ev2: A <:< A1): F[E1, A1] = r.asInstanceOf[F[E1, A1]] } - final class MonadOps[F[+_, +_], +E, +A](override protected[this] val r: F[E, A])(implicit override protected[this] val F: Monad2[F]) extends ApplicativeOps(r)(F) { + final class MonadOps[F[+_, +_], +E, +A](override protected val r: F[E, A])(implicit override protected val F: Monad2[F]) extends ApplicativeOps(r)(F) { @inline final def flatMap[E1 >: E, B](f0: A => F[E1, B]): F[E1, B] = F.flatMap[E1, A, B](r)(f0) @inline final def tap[E1 >: E](f0: A => F[E1, Unit]): F[E1, A] = F.tap(r, f0) @@ -119,7 +119,7 @@ object Syntax2 { @inline final def fromOptionF[E1 >: E, B](fallbackOnNone: => F[E1, B])(implicit ev: A <:< Option[B]): F[E1, B] = F.fromOptionF(fallbackOnNone, r.widen) } - class ErrorOps[F[+_, +_], +E, +A](override protected[this] val r: F[E, A])(implicit override protected[this] val F: Error2[F]) extends ApplicativeErrorOps(r)(F) { + class ErrorOps[F[+_, +_], +E, +A](override protected val r: F[E, A])(implicit override protected val F: Error2[F]) extends ApplicativeErrorOps(r)(F) { // duplicated from MonadOps @inline final def flatMap[E1 >: E, B](f0: A => F[E1, B]): F[E1, B] = F.flatMap[E1, A, B](r)(f0) @inline final def tap[E1 >: E](f0: A => F[E1, Unit]): F[E1, A] = F.tap(r, f0) @@ -177,7 +177,7 @@ object Syntax2 { F.withFilter[E1, A](r)(predicate) } - class BracketOps[F[+_, +_], +E, +A](override protected[this] val r: F[E, A])(implicit override protected[this] val F: Bracket2[F]) extends ErrorOps(r)(F) { + class BracketOps[F[+_, +_], +E, +A](override protected val r: F[E, A])(implicit override protected val F: Bracket2[F]) extends ErrorOps(r)(F) { @inline final def bracket[E1 >: E, B](release: A => F[Nothing, Unit])(use: A => F[E1, B]): F[E1, B] = F.bracket(r: F[E1, A])(release)(use) @inline final def bracketCase[E1 >: E, B](release: (A, Exit[E1, B]) => F[Nothing, Unit])(use: A => F[E1, B]): F[E1, B] = F.bracketCase(r: F[E1, A])(release)(use) @@ -191,7 +191,7 @@ object Syntax2 { F.guaranteeExceptOnInterrupt(r, cleanupOnNonInterruption) } - class PanicOps[F[+_, +_], +E, +A](override protected[this] val r: F[E, A])(implicit override protected[this] val F: Panic2[F]) extends BracketOps(r)(F) { + class PanicOps[F[+_, +_], +E, +A](override protected val r: F[E, A])(implicit override protected val F: Panic2[F]) extends BracketOps(r)(F) { @inline final def sandbox: F[Exit.FailureUninterrupted[E], A] = F.sandbox(r) @inline final def sandboxExit: F[Nothing, Exit.Uninterrupted[E, A]] = F.sandboxExit(r) @@ -213,25 +213,25 @@ object Syntax2 { @inline final def uninterruptible: F[E, A] = F.uninterruptible(r) } - class IOOps[F[+_, +_], +E, +A](override protected[this] val r: F[E, A])(implicit override protected[this] val F: IO2[F]) extends PanicOps(r)(F) { + class IOOps[F[+_, +_], +E, +A](override protected val r: F[E, A])(implicit override protected val F: IO2[F]) extends PanicOps(r)(F) { @inline final def bracketAuto[E1 >: E, B](use: A => F[E1, B])(implicit ev: A <:< AutoCloseable): F[E1, B] = F.bracket[E1, A, B](r)(c => F.sync(c.close()))(use) } - class ParallelOps[F[+_, +_], +E, +A](protected[this] val r: F[E, A])(implicit protected[this] val F: Parallel2[F]) { + class ParallelOps[F[+_, +_], +E, +A](protected val r: F[E, A])(implicit protected val F: Parallel2[F]) { @inline final def zipWithPar[E1 >: E, B, C](that: F[E1, B])(f: (A, B) => C): F[E1, C] = F.zipWithPar(r, that)(f) @inline final infix def zipPar[E1 >: E, B](that: F[E1, B]): F[E1, (A, B)] = F.zipPar(r, that) @inline final infix def zipParLeft[E1 >: E, B](that: F[E1, B]): F[E1, A] = F.zipParLeft(r, that) @inline final infix def zipParRight[E1 >: E, B](that: F[E1, B]): F[E1, B] = F.zipParRight(r, that) } - final class ConcurrentOps[F[+_, +_], +E, +A](override protected[this] val r: F[E, A])(implicit override protected[this] val F: Concurrent2[F]) + final class ConcurrentOps[F[+_, +_], +E, +A](override protected val r: F[E, A])(implicit override protected val F: Concurrent2[F]) extends ParallelOps(r)(F) { @inline final infix def race[E1 >: E, A1 >: A](that: F[E1, A1]): F[E1, A1] = F.race(r, that) @inline final def racePairUnsafe[E1 >: E, A1 >: A]( that: F[E1, A1] ): F[E1, Either[(Exit[E1, A], Fiber2[F, E1, A1]), (Fiber2[F, E1, A], Exit[E1, A1])]] = F.racePairUnsafe(r, that) } - class AsyncOps[F[+_, +_], +E, +A](override protected[this] val r: F[E, A])(implicit override protected[this] val F: Async2[F]) extends IOOps(r)(F) { + class AsyncOps[F[+_, +_], +E, +A](override protected val r: F[E, A])(implicit override protected val F: Async2[F]) extends IOOps(r)(F) { @inline final def zipWithPar[E1 >: E, B, C](that: F[E1, B])(f: (A, B) => C): F[E1, C] = F.zipWithPar(r, that)(f) @inline final infix def zipPar[E1 >: E, B](that: F[E1, B]): F[E1, (A, B)] = F.zipPar(r, that) @inline final infix def zipParLeft[E1 >: E, B](that: F[E1, B]): F[E1, A] = F.zipParLeft(r, that) @@ -243,7 +243,7 @@ object Syntax2 { ): F[E1, Either[(Exit[E1, A], Fiber2[F, E1, A1]), (Fiber2[F, E1, A], Exit[E1, A1])]] = F.racePairUnsafe(r, that) } - final class TemporalOps[F[+_, +_], +E, +A](protected[this] val r: F[E, A])(implicit protected[this] val F: Temporal2[F]) { + final class TemporalOps[F[+_, +_], +E, +A](protected val r: F[E, A])(implicit protected val F: Temporal2[F]) { @inline final def repeatUntil[E2 >: E, A2](tooManyAttemptsError: => E2, sleep: FiniteDuration, maxAttempts: Int)(implicit ev: A <:< Option[A2]): F[E2, A2] = F.repeatUntil[E2, A2](new FunctorOps(r)(F.InnerF).widen)(tooManyAttemptsError, sleep, maxAttempts) diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/Lifecycle.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/Lifecycle.scala index d2db712c61..52967bc187 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/Lifecycle.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/Lifecycle.scala @@ -492,7 +492,7 @@ object Lifecycle extends LifecycleInstances { Left(F.widen(allocatedTo(finalizersRef))) } - private[this] def allocatedTo( + private def allocatedTo( finalizers: kernel.Ref[F, List[F[Unit]]] ): F[A] = { // Because we have `.uninterruptibleMask` now it's safe to use CE Resource's native `allocated` method. @@ -641,7 +641,7 @@ object Lifecycle extends LifecycleInstances { * it can hit a Scalac bug https://github.com/scala/bug/issues/11969 * and fail to compile, in that case you may switch to [[Lifecycle.OfInner]] */ - open class Of[+F[_], +A] private[this] (inner0: () => Lifecycle[F, A], @unused dummy: Boolean = false) extends Lifecycle.OfInner[F, A] { + open class Of[+F[_], +A] private (inner0: () => Lifecycle[F, A], @unused dummy: Boolean = false) extends Lifecycle.OfInner[F, A] { def this(inner: => Lifecycle[F, A]) = this(() => inner) override val lifecycle: Lifecycle[F, A] = inner0() @@ -732,7 +732,7 @@ object Lifecycle extends LifecycleInstances { * } * }}} */ - open class Make[+F[_], A] private[this] (acquire0: () => F[A])(release0: A => F[Unit], @unused dummy: Boolean = false) extends Lifecycle.Basic[F, A] { + open class Make[+F[_], A] private (acquire0: () => F[A])(release0: A => F[Unit], @unused dummy: Boolean = false) extends Lifecycle.Basic[F, A] { def this(acquire: => F[A])(release: A => F[Unit]) = this(() => acquire)(release) override final def acquire: F[A] = acquire0() @@ -771,7 +771,7 @@ object Lifecycle extends LifecycleInstances { * } * }}} */ - open class MakePair[F[_], A] private[this] (acquire0: () => F[(A, F[Unit])], @unused dummy: Boolean = false) extends FromPair[F, A] { + open class MakePair[F[_], A] private (acquire0: () => F[(A, F[Unit])], @unused dummy: Boolean = false) extends FromPair[F, A] { def this(acquire: => F[(A, F[Unit])]) = this(() => acquire) override final def acquire: F[(A, F[Unit])] = acquire0() @@ -794,7 +794,7 @@ object Lifecycle extends LifecycleInstances { * * @note `acquire` is performed interruptibly, unlike in [[Make]] */ - open class LiftF[+F[_]: QuasiApplicative, A] private[this] (acquire0: () => F[A], @unused dummy: Boolean) extends NoCloseBase[F, A] { + open class LiftF[+F[_]: QuasiApplicative, A] private (acquire0: () => F[A], @unused dummy: Boolean) extends NoCloseBase[F, A] { def this(acquire: => F[A]) = this(() => acquire, false) override final type InnerResource = Unit diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/LifecycleAggregator.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/LifecycleAggregator.scala index 019a9af349..379cac610d 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/LifecycleAggregator.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/LifecycleAggregator.scala @@ -67,7 +67,7 @@ object LifecycleAggregator { Lifecycle.make(makeImpl[F, E])(_.releaseAll()) } - private[this] def makeImpl[F[+_, +_]: Panic2: Primitives2, E]: F[Nothing, LifecycleAggregator[F, E]] = { + private def makeImpl[F[+_, +_]: Panic2: Primitives2, E]: F[Nothing, LifecycleAggregator[F, E]] = { for { finalizers <- F.mkRefM(List.empty[(LifecycleAggregator[F, E]#Key, F[E, Unit])]) } yield new LifecycleAggregator[F, E](finalizers) diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/LifecycleMethodImpls.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/LifecycleMethodImpls.scala index 1f395275d5..3600891552 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/LifecycleMethodImpls.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/lifecycle/LifecycleMethodImpls.scala @@ -26,7 +26,7 @@ private[lifecycle] object LifecycleMethodImpls { new Lifecycle[F, B] { override type InnerResource = QuasiRef[F, List[() => F[Unit]]] - private[this] def bracketAppendFinalizer[a, b](finalizers: InnerResource)(lifecycle: Lifecycle[F, a])(use: lifecycle.InnerResource => F[b]): F[b] = { + private def bracketAppendFinalizer[a, b](finalizers: InnerResource)(lifecycle: Lifecycle[F, a])(use: lifecycle.InnerResource => F[b]): F[b] = { F.bracket( acquire = lifecycle.acquire.flatMap { a => @@ -103,7 +103,7 @@ private[lifecycle] object LifecycleMethodImpls { new Lifecycle[F, B] { override type InnerResource = AtomicReference[List[() => F[Unit]]] - private[this] def extractAppendFinalizer[a](finalizers: InnerResource)(lifecycleCtor: () => Lifecycle[F, a]): F[a] = { + private def extractAppendFinalizer[a](finalizers: InnerResource)(lifecycleCtor: () => Lifecycle[F, a]): F[a] = { F.bracket( acquire = { val lifecycle = lifecycleCtor() diff --git a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/quasi/QuasiIO.scala b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/quasi/QuasiIO.scala index d825b6ad2f..917a10b64a 100644 --- a/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/quasi/QuasiIO.scala +++ b/fundamentals/fundamentals-bio/src/main/scala/izumi/functional/quasi/QuasiIO.scala @@ -166,11 +166,11 @@ object QuasiIO extends LowPriorityQuasiIOInstances { override def fail[A](t: => Throwable): Identity[A] = throw t override def traverse[A, B](l: Iterable[A])(f: A => Identity[B]): Identity[List[B]] = l.iterator.map(f).toList override def traverse_[A](l: Iterable[A])(f: A => Identity[Unit]): Identity[Unit] = l.foreach(f) - @inline private[this] def TryWithFatal[A](r: => A): Try[A] = { + @inline private def TryWithFatal[A](r: => A): Try[A] = { try Success(r) catch { case t: Throwable => Failure(t) } } - @inline private[this] def TryNonFatal[A](r: => A): Try[A] = Try(r) + @inline private def TryNonFatal[A](r: => A): Try[A] = Try(r) } } diff --git a/fundamentals/fundamentals-collections/src/main/scala/izumi/fundamentals/graphs/tools/Toposort.scala b/fundamentals/fundamentals-collections/src/main/scala/izumi/fundamentals/graphs/tools/Toposort.scala index e9d9c4b57c..92ec83d7a4 100644 --- a/fundamentals/fundamentals-collections/src/main/scala/izumi/fundamentals/graphs/tools/Toposort.scala +++ b/fundamentals/fundamentals-collections/src/main/scala/izumi/fundamentals/graphs/tools/Toposort.scala @@ -14,7 +14,7 @@ object Toposort { @nowarn("msg=Unused import") @tailrec - private[this] def cycleBreaking[T](predecessors: Map[T, Set[T]], done: Seq[T], break: ToposortLoopBreaker[T]): Either[ToposortError[T], Seq[T]] = { + private def cycleBreaking[T](predecessors: Map[T, Set[T]], done: Seq[T], break: ToposortLoopBreaker[T]): Either[ToposortError[T], Seq[T]] = { import scala.collection.compat._ val (noPreds, hasPreds) = predecessors.partition(_._2.isEmpty) @@ -47,11 +47,11 @@ object Toposort { } } - private[this] def isInvolvedIntoCycle[T](toPreds: Map[T, Set[T]])(key: T): Boolean = { + private def isInvolvedIntoCycle[T](toPreds: Map[T, Set[T]])(key: T): Boolean = { test(toPreds, Set.empty, key, key) } - private[this] def test[T](toPreds: Map[T, Set[T]], stack: Set[T], toTest: T, needle: T): Boolean = { + private def test[T](toPreds: Map[T, Set[T]], stack: Set[T], toTest: T, needle: T): Boolean = { val deps = toPreds.getOrElse(toTest, Set.empty) if (deps.contains(needle)) { diff --git a/fundamentals/fundamentals-json-circe/src/main/scala/izumi/fundamentals/json/flat/JsonFlattener.scala b/fundamentals/fundamentals-json-circe/src/main/scala/izumi/fundamentals/json/flat/JsonFlattener.scala index dbd66ceebe..1489f45aad 100644 --- a/fundamentals/fundamentals-json-circe/src/main/scala/izumi/fundamentals/json/flat/JsonFlattener.scala +++ b/fundamentals/fundamentals-json-circe/src/main/scala/izumi/fundamentals/json/flat/JsonFlattener.scala @@ -214,14 +214,14 @@ class JsonFlattener { } } - @inline private[this] def drop(v: (Seq[PathElement], Char, String)): (Seq[PathElement], Char, String) = { + @inline private def drop(v: (Seq[PathElement], Char, String)): (Seq[PathElement], Char, String) = { v match { case (path, tpe, value) => (path.drop(1), tpe, value) } } - @inline private[this] def inflateParsedNext(pairs: Seq[(Seq[PathElement], Char, String)]): Either[List[UnpackFailure], Json] = { + @inline private def inflateParsedNext(pairs: Seq[(Seq[PathElement], Char, String)]): Either[List[UnpackFailure], Json] = { inflateParsed(pairs.map(drop)) } diff --git a/fundamentals/fundamentals-json-circe/src/test/scala/izumi/fundamentals/json/circe/WithCirceTest.scala b/fundamentals/fundamentals-json-circe/src/test/scala/izumi/fundamentals/json/circe/WithCirceTest.scala index 561c2a85f9..12aa3dbbac 100644 --- a/fundamentals/fundamentals-json-circe/src/test/scala/izumi/fundamentals/json/circe/WithCirceTest.scala +++ b/fundamentals/fundamentals-json-circe/src/test/scala/izumi/fundamentals/json/circe/WithCirceTest.scala @@ -77,7 +77,7 @@ object WithCirceTest { } // workaround https://github.com/milessabin/shapeless/issues/837 - private[this] object codecs extends WithCirce[Nested] + private object codecs extends WithCirce[Nested] sealed trait Enum case object Enum1 extends Enum { diff --git a/fundamentals/fundamentals-language/src/main/scala/izumi/fundamentals/platform/language/ScalaRelease.scala b/fundamentals/fundamentals-language/src/main/scala/izumi/fundamentals/platform/language/ScalaRelease.scala index f2232e556b..f0e6b6ac21 100644 --- a/fundamentals/fundamentals-language/src/main/scala/izumi/fundamentals/platform/language/ScalaRelease.scala +++ b/fundamentals/fundamentals-language/src/main/scala/izumi/fundamentals/platform/language/ScalaRelease.scala @@ -21,13 +21,13 @@ object ScalaRelease { ScalaRelease.Unknown(versionString) } } - private[this] object ParseInt { + private object ParseInt { def unapply(str: String): Option[Int] = { try { Some(Integer.parseInt(str)) } catch { case _: NumberFormatException => None } } } - private[this] object RemoveQualifier { + private object RemoveQualifier { def unapply(str: String): Some[String] = { Some(str.takeWhile(_ != '-')) } diff --git a/fundamentals/fundamentals-language/src/main/scala/izumi/fundamentals/platform/language/newtype.scala b/fundamentals/fundamentals-language/src/main/scala/izumi/fundamentals/platform/language/newtype.scala index a5f1735941..495a35bd2a 100644 --- a/fundamentals/fundamentals-language/src/main/scala/izumi/fundamentals/platform/language/newtype.scala +++ b/fundamentals/fundamentals-language/src/main/scala/izumi/fundamentals/platform/language/newtype.scala @@ -12,6 +12,6 @@ object newtype { final def apply(value: A): T = value.asInstanceOf[T] final def apply[Collection[+_]](collection: Collection[A])(implicit d: DummyImplicit): Collection[T] = collection.asInstanceOf[Collection[T]] - @inline protected[this] def unwrap(value: T): A = value.asInstanceOf[A] + @inline protected def unwrap(value: T): A = value.asInstanceOf[A] } } diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala index 6fc5e7dd9f..ff1c978d92 100644 --- a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala @@ -115,7 +115,7 @@ abstract class FunctoidMacroBase(val c: blackbox.Context) { ) } - protected[this] def analyzeMethodRef(lambdaArgs: List[Symbol], body: Tree): List[Parameter] = { + protected def analyzeMethodRef(lambdaArgs: List[Symbol], body: Tree): List[Parameter] = { val lambdaParams = lambdaArgs.map(symbolToParam) val methodReferenceParams = body match { @@ -173,7 +173,7 @@ abstract class FunctoidMacroBase(val c: blackbox.Context) { } } - protected[this] def extractMethodReferenceParams(symbol: Symbol): List[Symbol] = { + protected def extractMethodReferenceParams(symbol: Symbol): List[Symbol] = { val isSyntheticCaseClassApply = { symbol.name.decodedName.toString == "apply" && symbol.isSynthetic && @@ -193,11 +193,11 @@ abstract class FunctoidMacroBase(val c: blackbox.Context) { method.typeSignature.paramLists.flatten } - protected[this] def analyzeValRef(sig: Type): List[Parameter] = { + protected def analyzeValRef(sig: Type): List[Parameter] = { widenFunctionObject(sig).typeArgs.init.map(typeToParam) } - protected[this] def widenFunctionObject(sig: Type): Type = { + protected def widenFunctionObject(sig: Type): Type = { (sig match { case s: SingleTypeApi => sig.baseType(s.sym.typeSignature.baseClasses.find(definitions.FunctionClass.seq.contains(_)).get) diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala index 8ba3bf86cf..187225255d 100644 --- a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala +++ b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala @@ -32,7 +32,7 @@ class BaseReflectionProvider(val u: scala.reflect.api.Universe, idAnnotationFqn: withIdKeyFromAnnotation(parameterSymbol, typeKey) } - private[this] def withIdKeyFromAnnotation(parameterSymbol: MacroSymbolInfoCompact, typeKey: MacroDIKey.TypeKey): MacroDIKey.BasicKey = { + private def withIdKeyFromAnnotation(parameterSymbol: MacroSymbolInfoCompact, typeKey: MacroDIKey.TypeKey): MacroDIKey.BasicKey = { val maybeDistageName = parameterSymbol.findUniqueFriendlyAnno(a => a.fqn == idAnnotationFqn).map { value => value.params match { diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala index e5e072694f..6c9b8a98c4 100644 --- a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala +++ b/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala @@ -10,11 +10,11 @@ class ConstructorSelector(val u: scala.reflect.api.Universe) { } } - @inline private[this] def findConstructor(tpe: u.Type): scala.reflect.api.Universe#Symbol = { + @inline private def findConstructor(tpe: u.Type): scala.reflect.api.Universe#Symbol = { findConstructor0(tpe).getOrElse(u.NoSymbol) } - private[this] def findConstructor0(tpe: u.Type): Option[scala.reflect.api.Universe#Symbol] = { + private def findConstructor0(tpe: u.Type): Option[scala.reflect.api.Universe#Symbol] = { tpe match { case intersection: u.RefinedTypeApi => intersection.parents.collectFirst(Function.unlift(findConstructor0)) diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala index eba74cbfc7..7b10c7d25b 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala @@ -68,7 +68,7 @@ private[providers] trait SimpleFunctoids[Ftoid[+_]] { ) } - @inline private[this] def firstParamSymbolInfo(tpe: SafeType): SymbolInfo = { + @inline private def firstParamSymbolInfo(tpe: SafeType): SymbolInfo = { SymbolInfo( name = "x$1", finalResultType = tpe, diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/Provider.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/Provider.scala index c462666f63..bbe1a1bab1 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/Provider.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/Provider.scala @@ -47,7 +47,7 @@ trait Provider { if (providerType eq ProviderType.Function) {} else {} - protected[this] def verifyArgs(refs: Seq[GenericTypedRef[?]]): Seq[Any] = { + protected def verifyArgs(refs: Seq[GenericTypedRef[?]]): Seq[Any] = { val (newArgs, types, typesCmp) = parameters .zip(refs).map { case (param, ref) => diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/SyncCache.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/SyncCache.scala index 9600488806..cc4ebbcb34 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/SyncCache.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cache/SyncCache.scala @@ -5,7 +5,7 @@ import izumi.fundamentals.platform.language.Quirks._ import scala.collection.mutable class SyncCache[K, V] { - private[this] val cache = new mutable.HashMap[K, V]() + private val cache = new mutable.HashMap[K, V]() def enumerate(): Seq[(K, V)] = synchronize { cache.toSeq @@ -41,7 +41,7 @@ class SyncCache[K, V] { cache.size } - private[this] def synchronize[T](f: => T): T = { + private def synchronize[T](f: => T): T = { cache.synchronized { f } diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/CLIParserImpl.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/CLIParserImpl.scala index cec368e09d..d18932bc2f 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/CLIParserImpl.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/CLIParserImpl.scala @@ -41,7 +41,7 @@ class CLIParserImpl extends CLIParser { } yield roles } - private[this] def validate(arguments: RawAppArgs): Either[ParserError, Unit] = { + private def validate(arguments: RawAppArgs): Either[ParserError, Unit] = { val bad = arguments.roles.groupBy(_.role).filter(_._2.size > 1) if (bad.nonEmpty) { Left(ParserError.DuplicatedRoles(bad.keySet)) diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/ParserFailureHandler.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/ParserFailureHandler.scala index 46ebc79ec6..bd1b5efdd3 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/ParserFailureHandler.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/ParserFailureHandler.scala @@ -33,7 +33,7 @@ object ParserFailureHandler { } } - private[this] def makeMessage(e: ParserError): String = { + private def makeMessage(e: ParserError): String = { e match { case d: DanglingArgument => s"""Improperly positioned argument '${d.arg}' after valid commandline '${d.processed.mkString(" ")}' diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/model/schema/ParserDef.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/model/schema/ParserDef.scala index c67a80158c..ab4ee1dbdf 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/model/schema/ParserDef.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/model/schema/ParserDef.scala @@ -19,7 +19,7 @@ import scala.collection.mutable * }}} */ trait ParserDef { - private[this] val _all: mutable.LinkedHashMap[String, ArgDef] = mutable.LinkedHashMap[String, ArgDef]() + private val _all: mutable.LinkedHashMap[String, ArgDef] = mutable.LinkedHashMap[String, ArgDef]() def isEmpty: Boolean = _all.isEmpty def nonEmpty: Boolean = _all.nonEmpty @@ -43,7 +43,7 @@ trait ParserDef { arg(name, None, doc, None) } - private[this] def arg(name: String, short: Option[String], doc: String, valueDoc: Option[String]): ArgDef = { + private def arg(name: String, short: Option[String], doc: String, valueDoc: Option[String]): ArgDef = { if (_all.contains(name)) { throw new IllegalArgumentException(s"Parameter $name/$short is already registered!") } diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/model/schema/ParserSchemaFormatter.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/model/schema/ParserSchemaFormatter.scala index b23cc8bf4c..28d6fd0b1b 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/model/schema/ParserSchemaFormatter.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/cli/model/schema/ParserSchemaFormatter.scala @@ -20,7 +20,7 @@ object ParserSchemaFormatter { sb.toString() } - private[this] def formatRoleHelp(rb: RoleParserSchema): String = { + private def formatRoleHelp(rb: RoleParserSchema): String = { val sb = new StringBuilder() if (withColors) { sb.append(Console.GREEN) @@ -62,7 +62,7 @@ object ParserSchemaFormatter { sb.toString() } - private[this] def formatParser(parser: ParserDef, doc: Option[String], notes: Option[String], shift: Int, docShift: Int): String = { + private def formatParser(parser: ParserDef, doc: Option[String], notes: Option[String], shift: Int, docShift: Int): String = { val optDoc = if (parser.nonEmpty) { val opts = parser.enumerate.map(formatArg).mkString("\n\n") Some( @@ -83,13 +83,13 @@ object ParserSchemaFormatter { } - private[this] def formatArg(arg: ArgDef): String = { + private def formatArg(arg: ArgDef): String = { val usage = (arg.name.short.map(_ => formatInfo(short = true, arg)).toSeq ++ Seq(formatInfo(short = false, arg))).mkString(", ") s"$usage\n ${arg.doc}" } - private[this] def formatInfo(short: Boolean, arg: ArgDef): String = { + private def formatInfo(short: Boolean, arg: ArgDef): String = { val name = if (short) { arg.name.short.get } else { diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/console/TrivialLogger.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/console/TrivialLogger.scala index 91f62cb7bb..2f9753a877 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/console/TrivialLogger.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/console/TrivialLogger.scala @@ -58,15 +58,15 @@ final class TrivialLoggerImpl( new TrivialLoggerImpl(config, id, logMessages, logErrors, loggerLevel + delta) } - @inline private[this] def format(s: => String): String = { + @inline private def format(s: => String): String = { s"$id: $s" } - @inline private[this] def formatError(s: => String, e: => Throwable): String = { + @inline private def formatError(s: => String, e: => Throwable): String = { s"$id: $s\n${e.stacktraceString}" } - @inline private[this] def flush(level: Level, s: => String): Unit = { + @inline private def flush(level: Level, s: => String): Unit = { level match { case Level.Info => if (logMessages) { @@ -98,10 +98,10 @@ object TrivialLogger { new TrivialLoggerImpl(config, classTag[T].runtimeClass.getSimpleName, logMessages, logErrors, loggerLevel = 0) } - private[this] val enabled = new mutable.HashMap[String, Boolean]() + private val enabled = new mutable.HashMap[String, Boolean]() @nowarn("msg=return statement uses an exception") - private[this] def checkLog(sysProperty: String, config: Config, default: Boolean): Boolean = enabled.synchronized { + private def checkLog(sysProperty: String, config: Config, default: Boolean): Boolean = enabled.synchronized { def check(): Boolean = { val parts = sysProperty.split('.') diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/exceptions/IzThrowable.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/exceptions/IzThrowable.scala index aa4bc122d4..8f6239c19d 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/exceptions/IzThrowable.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/exceptions/IzThrowable.scala @@ -67,7 +67,7 @@ final class IzThrowableStackTop(t: Throwable, acceptedPackages: Set[String]) { t } - private[this] def stackTop(throwable: Throwable): Option[StackTraceElement] = { + private def stackTop(throwable: Throwable): Option[StackTraceElement] = { throwable.getStackTrace.find { frame => !frame.isNativeMethod && acceptedPackages.exists(frame.getClassName.startsWith) diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/properties/DebugProperties.scala b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/properties/DebugProperties.scala index f371f8d24c..e1d27bf982 100644 --- a/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/properties/DebugProperties.scala +++ b/fundamentals/fundamentals-platform/src/main/scala/izumi/fundamentals/platform/properties/DebugProperties.scala @@ -15,9 +15,9 @@ import izumi.fundamentals.platform.strings.IzString._ * }}} */ trait DebugProperties { - @inline protected[this] final def BoolProperty(name: String): BooleanProperty = new BooleanProperty(name) + @inline protected final def BoolProperty(name: String): BooleanProperty = new BooleanProperty(name) - @inline protected[this] final def StrProperty(name: String): StrProperty = new StrProperty(name) + @inline protected final def StrProperty(name: String): StrProperty = new StrProperty(name) } final case class BooleanProperty(name: String) extends AnyVal { diff --git a/logstage/logstage-adapter-slf4j/src/main/scala/izumi/logstage/adapter/slf4j/LogstageSlf4jLogger.scala b/logstage/logstage-adapter-slf4j/src/main/scala/izumi/logstage/adapter/slf4j/LogstageSlf4jLogger.scala index d0861487df..82066ec0b8 100644 --- a/logstage/logstage-adapter-slf4j/src/main/scala/izumi/logstage/adapter/slf4j/LogstageSlf4jLogger.scala +++ b/logstage/logstage-adapter-slf4j/src/main/scala/izumi/logstage/adapter/slf4j/LogstageSlf4jLogger.scala @@ -24,7 +24,7 @@ class LogstageSlf4jLogger(name: String, router: LogRouter) extends Logger { } } - @inline private[this] def mkEntry(level: Level, message: String, args: => Seq[Any], marker: => Option[Marker]): Entry = { + @inline private def mkEntry(level: Level, message: String, args: => Seq[Any], marker: => Option[Marker]): Entry = { val thread = Thread.currentThread() val threadData = ThreadData(thread.getName, thread.getId) diff --git a/logstage/logstage-core/.jvm/src/main/scala/izumi/logstage/adapter/jul/LogstageJulLogger.scala b/logstage/logstage-core/.jvm/src/main/scala/izumi/logstage/adapter/jul/LogstageJulLogger.scala index ca9600cd9e..a77af5cf92 100644 --- a/logstage/logstage-core/.jvm/src/main/scala/izumi/logstage/adapter/jul/LogstageJulLogger.scala +++ b/logstage/logstage-core/.jvm/src/main/scala/izumi/logstage/adapter/jul/LogstageJulLogger.scala @@ -40,7 +40,7 @@ class LogstageJulLogger(router: LogRouter) extends java.util.logging.Handler wit } } - @inline private[this] def mkEntry(record: LogRecord): Log.Entry = { + @inline private def mkEntry(record: LogRecord): Log.Entry = { val loggerName = Option(record.getLoggerName).getOrElse("unknown") val id = Log.LoggerId(loggerName) @@ -132,7 +132,7 @@ trait JULTools { def rootRef(): Logger = LogManager.getLogManager.getLogger("") - private[this] def forEachHandler(logger: Logger)(action: (Logger, java.util.logging.Handler) => Unit): Unit = { + private def forEachHandler(logger: Logger)(action: (Logger, java.util.logging.Handler) => Unit): Unit = { logger.synchronized { val handlers = logger.getHandlers for (handler <- handlers) { diff --git a/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/ArgumentNameExtractionMacro.scala b/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/ArgumentNameExtractionMacro.scala index bb3406348e..4edb1d56fc 100644 --- a/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/ArgumentNameExtractionMacro.scala +++ b/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/ArgumentNameExtractionMacro.scala @@ -14,7 +14,7 @@ class ArgumentNameExtractionMacro[C <: blackbox.Context](final val c: C, strict: import ExtractedName._ import c.universe._ - @inline private[this] final def debug(arg: Tree, s: => String): Unit = { + @inline private final def debug(arg: Tree, s: => String): Unit = { if (applyDebug) { c.warning(arg.pos, s) } @@ -94,7 +94,7 @@ class ArgumentNameExtractionMacro[C <: blackbox.Context](final val c: C, strict: } @tailrec - private[this] def extract(arg: Tree, acc: Seq[String]): Option[Seq[String]] = { + private def extract(arg: Tree, acc: Seq[String]): Option[Seq[String]] = { arg match { case Select(Ident(TermName("scala")), TermName("Predef")) => debug(arg, s"END-PREDEF") @@ -191,7 +191,7 @@ class ArgumentNameExtractionMacro[C <: blackbox.Context](final val c: C, strict: q"_root_.scala.collection.immutable.List(..$expressions)" } } - private[this] def reifiedPrefixedValue(param: Tree, value: Tree, prefix: String): Expr[LogArg] = { + private def reifiedPrefixedValue(param: Tree, value: Tree, prefix: String): Expr[LogArg] = { val prefixRepr = c.Expr[String](Literal(Constant(prefix))) val paramExpr = c.Expr[Any](param) val valueExpr = c.Expr[Any](value) @@ -200,7 +200,7 @@ class ArgumentNameExtractionMacro[C <: blackbox.Context](final val c: C, strict: } } - private[this] def reifiedExtractedHidden(param: Tree, s: String): Expr[LogArg] = { + private def reifiedExtractedHidden(param: Tree, s: String): Expr[LogArg] = { val paramRepTree = c.Expr[String](Literal(Constant(s))) val expr = c.Expr[Any](param) reify { @@ -208,7 +208,7 @@ class ArgumentNameExtractionMacro[C <: blackbox.Context](final val c: C, strict: } } - private[this] def reifiedExtracted(param: Tree, s: Seq[String]): Expr[LogArg] = { + private def reifiedExtracted(param: Tree, s: Seq[String]): Expr[LogArg] = { val list = c.Expr[Seq[String]](q"List(..$s)") val expr = c.Expr[Any](param) reify { @@ -216,7 +216,7 @@ class ArgumentNameExtractionMacro[C <: blackbox.Context](final val c: C, strict: } } - private[this] def findCodec(param: Tree, tpe: Type): Expr[Option[LogstageCodec[Any]]] = { + private def findCodec(param: Tree, tpe: Type): Expr[Option[LogstageCodec[Any]]] = { val maybeCodec = scala.util.Try(c.inferImplicitValue(appliedType(weakTypeOf[LogstageCodec[Nothing]].typeConstructor, tpe), silent = false)) debug(param, s"Logstage codec for argument $param of type `$tpe` == $maybeCodec") @@ -231,7 +231,7 @@ class ArgumentNameExtractionMacro[C <: blackbox.Context](final val c: C, strict: c.Expr[Option[LogstageCodec[Any]]](q"$tc") } - @inline private[this] def findCodec(param: Tree): Expr[Option[LogstageCodec[Any]]] = findCodec(param, param.tpe) + @inline private def findCodec(param: Tree): Expr[Option[LogstageCodec[Any]]] = findCodec(param, param.tpe) } object ArgumentNameExtractionMacro { diff --git a/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LogIOMacroMethods.scala b/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LogIOMacroMethods.scala index 8bc10c13ef..6cbf7b38ae 100644 --- a/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LogIOMacroMethods.scala +++ b/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LogIOMacroMethods.scala @@ -79,7 +79,7 @@ object LogIOMacroMethods { doLog(c)(message, Level.Crit, EncodingMode.Raw) } - private[this] def doLog[F[_]]( + private def doLog[F[_]]( c: blackbox.Context { type PrefixType = AbstractLogIO[F] } )(message: c.Expr[String], level: Level, diff --git a/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LogMessageMacro.scala b/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LogMessageMacro.scala index 373fba8da7..a319101284 100644 --- a/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LogMessageMacro.scala +++ b/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LogMessageMacro.scala @@ -10,7 +10,7 @@ final class LogMessageMacro(override val c: blackbox.Context) extends LogMessage final class LogMessageMacroStrict(override val c: blackbox.Context) extends LogMessageMacro0(c, true) class LogMessageMacro0[C <: blackbox.Context](val c: C, strict: Boolean) { - private[this] final val nameExtractor = new ArgumentNameExtractionMacro[c.type](c, strict) + private final val nameExtractor = new ArgumentNameExtractionMacro[c.type](c, strict) import c.universe._ @@ -24,7 +24,7 @@ class LogMessageMacro0[C <: blackbox.Context](val c: C, strict: Boolean) { } @scala.annotation.tailrec - private[this] def processExpr(message: c.Tree, isMultiline: Boolean): c.Expr[Message] = { + private def processExpr(message: c.Tree, isMultiline: Boolean): c.Expr[Message] = { sealed trait Chunk { def tree: Tree } @@ -211,7 +211,7 @@ class LogMessageMacro0[C <: blackbox.Context](val c: C, strict: Boolean) { } } - private[this] def createMessageExpr(stringContext: c.Tree, namedArgs: c.Expr[List[LogArg]]): c.Expr[Message] = { + private def createMessageExpr(stringContext: c.Tree, namedArgs: c.Expr[List[LogArg]]): c.Expr[Message] = { reify { Message( c.Expr[StringContext](stringContext).splice, diff --git a/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LoggerMacroMethods.scala b/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LoggerMacroMethods.scala index 2d3c29074d..ea0b6fb4bc 100644 --- a/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LoggerMacroMethods.scala +++ b/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LoggerMacroMethods.scala @@ -81,7 +81,7 @@ object LoggerMacroMethods { doLog(c)(message, Level.Crit, EncodingMode.Raw) } - private[this] def doLog(c: blackbox.Context { type PrefixType = AbstractLogger })(message: c.Expr[String], level: Level, mode: EncodingMode): c.Expr[Unit] = { + private def doLog(c: blackbox.Context { type PrefixType = AbstractLogger })(message: c.Expr[String], level: Level, mode: EncodingMode): c.Expr[Unit] = { val m: c.Expr[Message] = mode.fold(c.universe.reify(Message.raw(message.splice))) { strict => new LogMessageMacro0[c.type](c, strict = strict).logMessageMacro(message) diff --git a/logstage/logstage-core/src/main/scala/izumi/logstage/api/IzLoggerConvenienceApi.scala b/logstage/logstage-core/src/main/scala/izumi/logstage/api/IzLoggerConvenienceApi.scala index 1fb55119fd..310bd6a5d1 100644 --- a/logstage/logstage-core/src/main/scala/izumi/logstage/api/IzLoggerConvenienceApi.scala +++ b/logstage/logstage-core/src/main/scala/izumi/logstage/api/IzLoggerConvenienceApi.scala @@ -67,5 +67,5 @@ trait IzLoggerConvenienceApi[Logger <: RoutingLogger] { */ final lazy val DebugLogger = make(LogRouter.debugRouter) - protected[this] def make(r: LogRouter, context: CustomContext = CustomContext.empty): Logger + protected def make(r: LogRouter, context: CustomContext = CustomContext.empty): Logger } diff --git a/logstage/logstage-core/src/main/scala/izumi/logstage/api/rendering/LogstageReprWriter.scala b/logstage/logstage-core/src/main/scala/izumi/logstage/api/rendering/LogstageReprWriter.scala index 632153ec6b..1f0fe15566 100644 --- a/logstage/logstage-core/src/main/scala/izumi/logstage/api/rendering/LogstageReprWriter.scala +++ b/logstage/logstage-core/src/main/scala/izumi/logstage/api/rendering/LogstageReprWriter.scala @@ -100,7 +100,7 @@ class LogstageReprWriter(@unused colored: Boolean) extends ExtendedLogstageWrite override def write(a: BigInt): Unit = str(a) - @inline private[this] def str(a: Any): Unit = { + @inline private def str(a: Any): Unit = { stack.push(Token.Value(a.toString)) } } diff --git a/logstage/logstage-core/src/main/scala/izumi/logstage/api/rendering/logunits/LogFormat.scala b/logstage/logstage-core/src/main/scala/izumi/logstage/api/rendering/logunits/LogFormat.scala index 9e0235cf28..ed0e9f6de7 100644 --- a/logstage/logstage-core/src/main/scala/izumi/logstage/api/rendering/logunits/LogFormat.scala +++ b/logstage/logstage-core/src/main/scala/izumi/logstage/api/rendering/logunits/LogFormat.scala @@ -87,7 +87,7 @@ object LogFormat { } } - @inline private[this] def processUnbalanced( + @inline private def processUnbalanced( occurences: mutable.HashMap[String, Int], withColors: Boolean, hideKeys: Boolean, @@ -110,7 +110,7 @@ object LogFormat { } } - @inline private[this] def process( + @inline private def process( occurences: mutable.HashMap[String, Int], templateBuilder: mutable.StringBuilder, messageBuilder: mutable.StringBuilder, @@ -163,7 +163,7 @@ object LogFormat { } } - @inline private[this] def normalizeName(s: String): String = { + @inline private def normalizeName(s: String): String = { if (s.forall(_.isUpper) || s.startsWith("UNNAMED:") || s.startsWith("EXPRESSION:")) { s } else { @@ -172,17 +172,17 @@ object LogFormat { } } - @inline private[this] def handle(part: String): String = { + @inline private def handle(part: String): String = { StringContext.processEscapes(part) } - @inline private[this] def formatKvStrings(withColor: Boolean, name: String, value: String): String = { + @inline private def formatKvStrings(withColor: Boolean, name: String, value: String): String = { val key = wrapped(withColor, Console.GREEN, name) val v = wrapped(withColor, Console.CYAN, value) s"$key=$v" } - @inline private[this] def argToString(codec: Option[LogstageCodec[Any]], argValue: Any, withColors: Boolean): String = { + @inline private def argToString(codec: Option[LogstageCodec[Any]], argValue: Any, withColors: Boolean): String = { argValue match { case null => wrapped(withColors, Console.YELLOW, "null") @@ -213,7 +213,7 @@ object LogFormat { protected def toString(argValue: Any): String - @inline private[this] def wrapped(withColors: Boolean, color: String, message: String): String = { + @inline private def wrapped(withColors: Boolean, color: String, message: String): String = { if (withColors) { s"$color$message${Console.RESET}" } else { diff --git a/logstage/logstage-core/src/main/scala/izumi/logstage/api/routing/LogConfigServiceImpl.scala b/logstage/logstage-core/src/main/scala/izumi/logstage/api/routing/LogConfigServiceImpl.scala index d00a20281c..cfdfb2eb0f 100644 --- a/logstage/logstage-core/src/main/scala/izumi/logstage/api/routing/LogConfigServiceImpl.scala +++ b/logstage/logstage-core/src/main/scala/izumi/logstage/api/routing/LogConfigServiceImpl.scala @@ -15,9 +15,9 @@ class LogConfigServiceImpl(loggerConfig: LoggerConfig) extends LogConfigService LogEntryConfig(configFor(e.context.static.id).sinks) } - private[this] val configTree = LogConfigServiceImpl.build(loggerConfig) + private val configTree = LogConfigServiceImpl.build(loggerConfig) - @inline private[this] def configFor(e: Log.LoggerId): LoggerPathConfig = { + @inline private def configFor(e: Log.LoggerId): LoggerPathConfig = { val configPath = findConfig(e.id.split('.').toList, List.empty, configTree) configPath .collect { @@ -44,7 +44,7 @@ class LogConfigServiceImpl(loggerConfig: LoggerConfig) extends LogConfigService // (loggerConfig.root.sinks ++ loggerConfig.entries.values.flatMap(_.sinks)).foreach(_.close()) // } - private[this] def print(node: LogTreeNode, level: Int): String = { + private def print(node: LogTreeNode, level: Int): String = { val sub = node.sub.values.map(s => print(s, level + 1)) def reprCfg(cfg: LoggerPathConfig) = { diff --git a/logstage/logstage-core/src/main/scala/logstage/LogZIO.scala b/logstage/logstage-core/src/main/scala/logstage/LogZIO.scala index 7b738320a2..3bcfdd532a 100644 --- a/logstage/logstage-core/src/main/scala/logstage/LogZIO.scala +++ b/logstage/logstage-core/src/main/scala/logstage/LogZIO.scala @@ -60,7 +60,7 @@ object LogZIO { withFiberId(logger.withCustomContext(context)) } - override protected[this] def wrap[A](f: AbstractLogger => A): IO[Nothing, A] = { + override protected def wrap[A](f: AbstractLogger => A): IO[Nothing, A] = { addFiberIdToLogger(logger)(logger => ZIO.succeed(f(logger))) } } @@ -72,7 +72,7 @@ object LogZIO { withDynamicContext(logger.withCustomContext(context))(dynamic) } - override protected[this] def wrap[A](f: AbstractLogger => A): ZIO[R, Nothing, A] = { + override protected def wrap[A](f: AbstractLogger => A): ZIO[R, Nothing, A] = { dynamic.flatMap(dynCtx => ZIO.succeed(f(logger.withCustomContext(dynCtx)))) } } @@ -84,7 +84,7 @@ object LogZIO { withFiberId(logger.withCustomContext(context)) } - override protected[this] def wrap[A](f: AbstractLoggerF[IO[Nothing, _]] => IO[Nothing, A]): IO[Nothing, A] = { + override protected def wrap[A](f: AbstractLoggerF[IO[Nothing, _]] => IO[Nothing, A]): IO[Nothing, A] = { addFiberIdToLogger(logger)(f) } } @@ -96,7 +96,7 @@ object LogZIO { withDynamicContext(logger.withCustomContext(context))(dynamic) } - override protected[this] def wrap[A](f: AbstractLoggerF[ZIO[R, Nothing, _]] => ZIO[R, Nothing, A]): ZIO[R, Nothing, A] = { + override protected def wrap[A](f: AbstractLoggerF[ZIO[R, Nothing, _]] => ZIO[R, Nothing, A]): ZIO[R, Nothing, A] = { dynamic.flatMap(dynCtx => f(logger.withCustomContext(dynCtx))) } } diff --git a/logstage/logstage-core/src/main/scala/logstage/LogstageCats.scala b/logstage/logstage-core/src/main/scala/logstage/LogstageCats.scala index 8dbba08332..e812c67d21 100644 --- a/logstage/logstage-core/src/main/scala/logstage/LogstageCats.scala +++ b/logstage/logstage-core/src/main/scala/logstage/LogstageCats.scala @@ -15,7 +15,7 @@ object LogstageCats { withDynamicContext(logger.withCustomContext(context))(dynamic) } - override protected[this] def wrap[T](f: AbstractLogger => T): F[T] = { + override protected def wrap[T](f: AbstractLogger => T): F[T] = { dynamic.flatMap(dynCtx => SyncSafe1[F].syncSafe(f(logger.withCustomContext(dynCtx)))) } } @@ -27,7 +27,7 @@ object LogstageCats { withDynamicContext(logger.withCustomContext(context))(dynamic) } - override protected[this] def wrap[A](f: AbstractLoggerF[F] => F[A]): F[A] = { + override protected def wrap[A](f: AbstractLoggerF[F] => F[A]): F[A] = { dynamic.flatMap(dynCtx => f(logger.withCustomContext(dynCtx))) } } @@ -38,7 +38,7 @@ object LogstageCats { )(F: SyncSafe1[F] ) extends UnsafeLogIOSyncSafeInstance[F](logger)(F) with LogIO[F] { - protected[this] def wrap[A](f: AbstractLogger => A): F[A] + protected def wrap[A](f: AbstractLogger => A): F[A] override final def unsafeLog(entry: Entry): F[Unit] = wrap(_.unsafeLog(entry)) override final def log(entry: Entry): F[Unit] = wrap(_.log(entry)) @@ -50,7 +50,7 @@ object LogstageCats { )(F: SyncSafe1[F] ) extends UnsafeLogIOSyncSafeInstanceF[F](logger)(F) with LogIO[F] { - protected[this] def wrap[A](f: AbstractLoggerF[F] => F[A]): F[A] + protected def wrap[A](f: AbstractLoggerF[F] => F[A]): F[A] override final def unsafeLog(entry: Entry): F[Unit] = wrap(_.unsafeLog(entry)) override final def log(entry: Entry): F[Unit] = wrap(_.log(entry)) diff --git a/logstage/logstage-core/src/main/scala/logstage/strict/LogZIOStrict.scala b/logstage/logstage-core/src/main/scala/logstage/strict/LogZIOStrict.scala index a9459a871a..d0d5d670f3 100644 --- a/logstage/logstage-core/src/main/scala/logstage/strict/LogZIOStrict.scala +++ b/logstage/logstage-core/src/main/scala/logstage/strict/LogZIOStrict.scala @@ -30,7 +30,7 @@ object LogZIOStrict { withFiberIdStrict(logger.withCustomContext(context)) } - override protected[this] def wrap[A](f: AbstractLogger => A): IO[Nothing, A] = { + override protected def wrap[A](f: AbstractLogger => A): IO[Nothing, A] = { LogZIO.addFiberIdToLogger(logger)(logger => ZIO.succeed(f(logger))) } } @@ -42,7 +42,7 @@ object LogZIOStrict { withDynamicContextStrict(logger.withCustomContext(context))(dynamic) } - override protected[this] def wrap[A](f: AbstractLogger => A): ZIO[R, Nothing, A] = { + override protected def wrap[A](f: AbstractLogger => A): ZIO[R, Nothing, A] = { dynamic.flatMap(dynCtx => ZIO.succeed(f(logger.withCustomContext(dynCtx)))) } } @@ -54,7 +54,7 @@ object LogZIOStrict { withFiberIdStrict(logger.withCustomContext(context)) } - override protected[this] def wrap[A](f: AbstractLoggerF[IO[Nothing, _]] => IO[Nothing, A]): IO[Nothing, A] = { + override protected def wrap[A](f: AbstractLoggerF[IO[Nothing, _]] => IO[Nothing, A]): IO[Nothing, A] = { LogZIO.addFiberIdToLogger(logger)(f) } } @@ -66,7 +66,7 @@ object LogZIOStrict { withDynamicContextStrict(logger.withCustomContext(context))(dynamic) } - override protected[this] def wrap[A](f: AbstractLoggerF[ZIO[R, Nothing, _]] => ZIO[R, Nothing, A]): ZIO[R, Nothing, A] = { + override protected def wrap[A](f: AbstractLoggerF[ZIO[R, Nothing, _]] => ZIO[R, Nothing, A]): ZIO[R, Nothing, A] = { dynamic.flatMap(dynCtx => f(logger.withCustomContext(dynCtx))) } } diff --git a/logstage/logstage-core/src/main/scala/logstage/strict/LogstageCatsStrict.scala b/logstage/logstage-core/src/main/scala/logstage/strict/LogstageCatsStrict.scala index bc4014fe57..beaf5d0154 100644 --- a/logstage/logstage-core/src/main/scala/logstage/strict/LogstageCatsStrict.scala +++ b/logstage/logstage-core/src/main/scala/logstage/strict/LogstageCatsStrict.scala @@ -16,7 +16,7 @@ object LogstageCatsStrict { withDynamicContextStrict(logger.withCustomContext(context))(dynamic) } - override protected[this] def wrap[T](f: AbstractLogger => T): F[T] = { + override protected def wrap[T](f: AbstractLogger => T): F[T] = { dynamic.flatMap(ctx => SyncSafe1[F].syncSafe(f(logger.withCustomContext(ctx)))) } } @@ -28,7 +28,7 @@ object LogstageCatsStrict { withDynamicContextStrict(logger.withCustomContext(context))(dynamic) } - override protected[this] def wrap[A](f: AbstractLoggerF[F] => F[A]): F[A] = { + override protected def wrap[A](f: AbstractLoggerF[F] => F[A]): F[A] = { dynamic.flatMap(ctx => f(logger.withCustomContext(ctx))) } } @@ -40,7 +40,7 @@ object LogstageCatsStrict { ) extends UnsafeLogIOSyncSafeInstance[F](logger)(F) with LogIOStrict[F] { - protected[this] def wrap[A](f: AbstractLogger => A): F[A] + protected def wrap[A](f: AbstractLogger => A): F[A] override final def unsafeLog(entry: Entry): F[Unit] = wrap(_.unsafeLog(entry)) override final def log(entry: Entry): F[Unit] = wrap(_.log(entry)) @@ -53,7 +53,7 @@ object LogstageCatsStrict { ) extends UnsafeLogIOSyncSafeInstanceF[F](logger)(F) with LogIOStrict[F] { - protected[this] def wrap[A](f: AbstractLoggerF[F] => F[A]): F[A] + protected def wrap[A](f: AbstractLoggerF[F] => F[A]): F[A] override final def unsafeLog(entry: Entry): F[Unit] = wrap(_.unsafeLog(entry)) override final def log(entry: Entry): F[Unit] = wrap(_.log(entry)) From fafb7d65a91f6b37837a40dddea38dd828ec731f Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 5 Jun 2024 15:59:15 +0100 Subject: [PATCH 41/59] wip --- .../constructors/ConstructorUtil.scala | 5 +- .../reflection/macros/FunctoidMacroBase.scala | 108 +----------------- .../macros/FunctoidMacroHelpers.scala | 12 ++ .../macros/FunctoidMacroMethods.scala | 2 +- .../macros/FunctoidParametersMacro.scala | 103 +++++++++++++++++ 5 files changed, 119 insertions(+), 111 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala create mode 100644 distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala index f60aa133f6..e4865084fc 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala @@ -7,8 +7,7 @@ import scala.annotation.{nowarn, tailrec} import scala.quoted.{Expr, Quotes, Type} import scala.collection.mutable import izumi.distage.model.providers.Functoid -import izumi.distage.reflection.macros.FunctoidMacro -import izumi.distage.reflection.macros.FunctoidMacro.FunctoidParametersMacro +import izumi.distage.reflection.macros.{FunctoidMacro, FunctoidMacroHelpers, FunctoidParametersMacro} import izumi.distage.model.reflection.Provider.{ProviderImpl, ProviderType} import izumi.fundamentals.reflection.ReflectiveCall import izumi.reflect.WeakTag @@ -168,7 +167,7 @@ class ConstructorUtil[Q <: Quotes](using val qctx: Q) { self => new Functoid[R]( new ProviderImpl[R]( ${ Expr.ofList(paramDefs) }, - ${ paramsMacro.safeType[R] }, + ${ FunctoidMacroHelpers.generateSafeType[R, Q] }, ${ argsLambda }, ${ providerType }, ) diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala index 7421bc83d8..e8a8467799 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala @@ -1,10 +1,7 @@ package izumi.distage.reflection.macros -import izumi.distage.model.definition.Id import izumi.distage.model.providers.AbstractFunctoid import izumi.distage.model.reflection.* -import izumi.fundamentals.platform.reflection.ReflectionUtil -import izumi.reflect.Tag import scala.annotation.tailrec import scala.collection.immutable.{List, Seq} @@ -13,12 +10,8 @@ import scala.quoted.{Expr, Quotes, Type} trait FunctoidMacroBase[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { protected def generateFunctoid[R: Type, Q <: Quotes](paramDefs: List[Expr[LinkedParameter]], originalFun: Expr[AnyRef])(using qctx: Q): Expr[Ftoid[R]] - - protected def generateSafeType[R: Type, Q <: Quotes](using qctx: Q): Expr[SafeType] = { - new FunctoidParametersMacro[qctx.type]().safeType[R] - } - protected def generateRawFnCall[Q <: Quotes](argsCount: Int, rawFn: Expr[Any], args: Expr[Seq[Any]])(using qctx: Q): Expr[Any] = { + protected final def generateRawFnCall[Q <: Quotes](argsCount: Int, rawFn: Expr[Any], args: Expr[Seq[Any]])(using qctx: Q): Expr[Any] = { import qctx.reflect.* val params = List.tabulate(argsCount) { @@ -145,103 +138,4 @@ trait FunctoidMacroBase[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { } - final class FunctoidParametersMacro[Q <: Quotes](using val qctx: Q) { - - import qctx.reflect.* - - private val idAnnotationSym: Symbol = TypeRepr.of[Id].typeSymbol - private val maybeJavaxNamedAnnotationSym: Option[Symbol] = scala.util.Try(Symbol.requiredClass("javax.inject.Named")).toOption - - extension (t: Either[TypeTree, TypeRepr]) { - private def _tpe: TypeRepr = t match { - case Right(t) => t - case Left(t) => t.tpe - } - } - - def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol]): Expr[LinkedParameter] = { - makeParam(name, tpe, annotSym, tpe) - } - - def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol], annotTpe: Either[TypeTree, TypeRepr]): Expr[LinkedParameter] = { - val identifier = { - val mbIdIdentifier = ReflectionUtil - .readTypeOrSymbolDIAnnotation(idAnnotationSym)(name, annotSym, annotTpe) { - case aterm @ Apply(Select(New(_), _), c :: _) => - c.asExprOf[String].value.orElse { - report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") - } - case aterm => - report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") - } - mbIdIdentifier.orElse { - maybeJavaxNamedAnnotationSym.flatMap { - namedAnnoSym => - ReflectionUtil.readTypeOrSymbolDIAnnotation(namedAnnoSym)(name, annotSym, annotTpe) { - case aterm @ Apply(Select(New(_), _), c :: _) => - c.asExprOf[String].value.orElse { - report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") - } - case aterm => - report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") - } - } - } - } - - val tpeRepr = tpe._tpe - - val isByName = tpeRepr match { - case ByNameType(_) => true - case _ => false - } - - val wasGeneric = tpeRepr.typeSymbol.isTypeParam // deem abstract type members as generic? No. Because we don't do that in Scala 2 version. - - '{ - LinkedParameter( - SymbolInfo( - name = ${ Expr(name) }, - finalResultType = ${ safeTypeFromRepr(tpeRepr) }, - isByName = ${ Expr(isByName) }, - wasGeneric = ${ Expr(wasGeneric) }, - ), - ${ makeKeyFromRepr(tpeRepr, identifier) }, - ) - } - } - - def safeType[R: Type]: Expr[SafeType] = { - '{ SafeType.get[R](using scala.compiletime.summonInline[Tag[R]]) } - } - - private def makeKeyFromRepr(tpe: TypeRepr, id: Option[String]): Expr[DIKey] = { - val safeTpe = safeTypeFromRepr(tpe) - id match { - case Some(str) => - val strExpr = Expr(str) - '{ new DIKey.IdKey($safeTpe, $strExpr, None)(scala.compiletime.summonInline[IdContract[String]]) } - case None => - '{ new DIKey.TypeKey($safeTpe, None) } - } - } - - private def safeTypeFromRepr(tpe: TypeRepr): Expr[SafeType] = { - dropByName(tpe).asType match { - case '[a] => - '{ SafeType.get[a](using scala.compiletime.summonInline[Tag[a]]) } - case _ => - report.errorAndAbort(s"Cannot generate SafeType from ${tpe.show}, probably that's a bug in Functoid macro") - } - } - - private def dropByName(tpe: TypeRepr): TypeRepr = { - tpe match { - case ByNameType(u) => u - case _ => tpe - } - } - - } - } diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala new file mode 100644 index 0000000000..f6d49bc0c1 --- /dev/null +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala @@ -0,0 +1,12 @@ +package izumi.distage.reflection.macros + +import izumi.distage.model.reflection.SafeType +import izumi.reflect.Tag + +import scala.quoted.{Expr, Quotes, Type} + +object FunctoidMacroHelpers { + final def generateSafeType[R: Type, Q <: Quotes](using qctx: Q): Expr[SafeType] = { + '{ SafeType.get[R](using scala.compiletime.summonInline[Tag[R]]) } + } +} diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index 8bebd777b2..f52a9f12a2 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -20,7 +20,7 @@ object FunctoidMacro extends FunctoidMacroBase[Functoid] { new Functoid[R]( new ProviderImpl[R]( ${ Expr.ofList(paramDefs) }, - ${ generateSafeType[R, Q] }, + ${ FunctoidMacroHelpers.generateSafeType[R, Q] }, rawFn, (args: Seq[Any]) => ${ generateRawFnCall(paramDefs.size, 'rawFn, 'args) }, ProviderType.Function, diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala new file mode 100644 index 0000000000..5b294b5cf6 --- /dev/null +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala @@ -0,0 +1,103 @@ +package izumi.distage.reflection.macros + +import izumi.distage.model.definition.Id +import izumi.distage.model.reflection.* +import izumi.fundamentals.platform.reflection.ReflectionUtil +import izumi.reflect.Tag + +import scala.quoted.{Expr, Quotes} + +final class FunctoidParametersMacro[Q <: Quotes](using val qctx: Q) { + + import qctx.reflect.* + + private val idAnnotationSym: Symbol = TypeRepr.of[Id].typeSymbol + private val maybeJavaxNamedAnnotationSym: Option[Symbol] = scala.util.Try(Symbol.requiredClass("javax.inject.Named")).toOption + + extension (t: Either[TypeTree, TypeRepr]) { + private def _tpe: TypeRepr = t match { + case Right(t) => t + case Left(t) => t.tpe + } + } + + def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol]): Expr[LinkedParameter] = { + makeParam(name, tpe, annotSym, tpe) + } + + def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol], annotTpe: Either[TypeTree, TypeRepr]): Expr[LinkedParameter] = { + val identifier = { + val mbIdIdentifier = ReflectionUtil + .readTypeOrSymbolDIAnnotation(idAnnotationSym)(name, annotSym, annotTpe) { + case aterm @ Apply(Select(New(_), _), c :: _) => + c.asExprOf[String].value.orElse { + report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") + } + case aterm => + report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") + } + mbIdIdentifier.orElse { + maybeJavaxNamedAnnotationSym.flatMap { + namedAnnoSym => + ReflectionUtil.readTypeOrSymbolDIAnnotation(namedAnnoSym)(name, annotSym, annotTpe) { + case aterm @ Apply(Select(New(_), _), c :: _) => + c.asExprOf[String].value.orElse { + report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") + } + case aterm => + report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") + } + } + } + } + + val tpeRepr = tpe._tpe + + val isByName = tpeRepr match { + case ByNameType(_) => true + case _ => false + } + + val wasGeneric = tpeRepr.typeSymbol.isTypeParam // deem abstract type members as generic? No. Because we don't do that in Scala 2 version. + + '{ + LinkedParameter( + SymbolInfo( + name = ${ Expr(name) }, + finalResultType = ${ safeTypeFromRepr(tpeRepr) }, + isByName = ${ Expr(isByName) }, + wasGeneric = ${ Expr(wasGeneric) }, + ), + ${ makeKeyFromRepr(tpeRepr, identifier) }, + ) + } + } + + private def makeKeyFromRepr(tpe: TypeRepr, id: Option[String]): Expr[DIKey] = { + val safeTpe = safeTypeFromRepr(tpe) + id match { + case Some(str) => + val strExpr = Expr(str) + '{ new DIKey.IdKey($safeTpe, $strExpr, None)(scala.compiletime.summonInline[IdContract[String]]) } + case None => + '{ new DIKey.TypeKey($safeTpe, None) } + } + } + + private def safeTypeFromRepr(tpe: TypeRepr): Expr[SafeType] = { + dropByName(tpe).asType match { + case '[a] => + '{ SafeType.get[a](using scala.compiletime.summonInline[Tag[a]]) } + case _ => + report.errorAndAbort(s"Cannot generate SafeType from ${tpe.show}, probably that's a bug in Functoid macro") + } + } + + private def dropByName(tpe: TypeRepr): TypeRepr = { + tpe match { + case ByNameType(u) => u + case _ => tpe + } + } + +} From 2b6e7e0c687785378d0dc3be7de52aad7375b44b Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 5 Jun 2024 16:25:00 +0100 Subject: [PATCH 42/59] wip --- .../macros/FunctoidMacroMethods.scala | 2 +- .../macros/FunctoidParametersMacro.scala | 2 +- .../reflection/macros/FunctoidMacroBase.scala | 18 ++++++++++++------ .../macros/FunctoidMacroHelpers.scala | 0 .../macros/FunctoidParametersMacroBase.scala | 13 +++++++++++++ 5 files changed, 27 insertions(+), 8 deletions(-) rename {distage/distage-core-api => fundamentals/fundamentals-platform}/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala (91%) rename {distage/distage-core-api => fundamentals/fundamentals-platform}/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala (100%) create mode 100644 fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index f52a9f12a2..307d2fc665 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -12,7 +12,7 @@ trait FunctoidMacroMethods extends FunctoidMacroMethodsBase {} object FunctoidMacro extends FunctoidMacroBase[Functoid] { transparent inline def make[R](inline fun: AnyRef): Functoid[R] = ${ makeImpl[R]('fun) } - def makeImpl[R: Type](fun: Expr[AnyRef])(using qctx: Quotes): Expr[Functoid[R]] = new FunctoidMacroImpl[qctx.type]().make(fun) + def makeImpl[R: Type](fun: Expr[AnyRef])(using qctx: Quotes): Expr[Functoid[R]] = new FunctoidMacroImpl[qctx.type](new FunctoidParametersMacro[qctx.type]()).make(fun) protected def generateFunctoid[R: Type, Q <: Quotes](paramDefs: List[Expr[LinkedParameter]], originalFun: Expr[AnyRef])(using qctx: Q): Expr[Functoid[R]] = { '{ diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala index 5b294b5cf6..4d3ecf25f3 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala @@ -7,7 +7,7 @@ import izumi.reflect.Tag import scala.quoted.{Expr, Quotes} -final class FunctoidParametersMacro[Q <: Quotes](using val qctx: Q) { +final class FunctoidParametersMacro[Q <: Quotes & Singleton](using val qctx: Q) extends FunctoidParametersMacroBase[Q] { import qctx.reflect.* diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala similarity index 91% rename from distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala rename to fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala index e8a8467799..868379656d 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala @@ -32,12 +32,9 @@ trait FunctoidMacroBase[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { Select.unique(fnAny.asTerm, "apply").appliedToArgs(params.map(_.asTerm)).asExprOf[Any] } - final class FunctoidMacroImpl[Q <: Quotes](using val qctx: Q) { - + final class FunctoidMacroImpl[Q <: Quotes & Singleton](using val qctx: Q)(val paramsMacro: FunctoidParametersMacroBase[qctx.type]) { import qctx.reflect.* - private val paramsMacro = new FunctoidParametersMacro[qctx.type]() - def make[R: Type](fun: Expr[AnyRef]): Expr[Ftoid[R]] = { val parameters = analyze(fun.asTerm) val out = generateFunctoid[R, Q](parameters, fun) @@ -106,12 +103,21 @@ trait FunctoidMacroBase[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { // (Besides, lambda types are the ones specified by the caller, we should respect them) singleParamList.params.zip(methodRefParams).map { case (ValDef(name, tpeTree, _), mSym) => - paramsMacro.makeParam(name, Left(tpeTree), Some(mSym), Right(mSym.owner.typeRef.memberType(mSym))) + paramsMacro.makeParam( + name, + Left(tpeTree), + Some(mSym), + Right(mSym.owner.typeRef.memberType(mSym)), + ) } } else { singleParamList.params.map { case valDef @ ValDef(name, tpeTree, _) => - paramsMacro.makeParam(name, Left(tpeTree), Some(valDef.symbol).filterNot(_.isNoSymbol)) + paramsMacro.makeParam( + name, + Left(tpeTree), + Some(valDef.symbol).filterNot(_.isNoSymbol), + ) } } } diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala similarity index 100% rename from distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala rename to fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala new file mode 100644 index 0000000000..fc52ebe8c6 --- /dev/null +++ b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala @@ -0,0 +1,13 @@ +package izumi.distage.reflection.macros + +import izumi.distage.model.reflection.LinkedParameter + +import scala.quoted.{Expr, Quotes} + +trait FunctoidParametersMacroBase[Q <: Quotes & Singleton] { + val qctx: Q + + import qctx.reflect.* + def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol]): Expr[LinkedParameter] + def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol], annotTpe: Either[TypeTree, TypeRepr]): Expr[LinkedParameter] +} From eb3c4195aa4b040a43d10b04d8047696d781a2d4 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 5 Jun 2024 16:26:16 +0100 Subject: [PATCH 43/59] wip --- .../distage/reflection/macros/FunctoidParametersMacro.scala | 2 +- .../izumi/distage/reflection/macros/FunctoidMacroBase.scala | 2 +- .../distage/reflection/macros/FunctoidParametersMacroBase.scala | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala index 4d3ecf25f3..e52de6f6ea 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala @@ -7,7 +7,7 @@ import izumi.reflect.Tag import scala.quoted.{Expr, Quotes} -final class FunctoidParametersMacro[Q <: Quotes & Singleton](using val qctx: Q) extends FunctoidParametersMacroBase[Q] { +final class FunctoidParametersMacro[Q <: Quotes](using val qctx: Q) extends FunctoidParametersMacroBase[Q] { import qctx.reflect.* diff --git a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala index 868379656d..d5cd517522 100644 --- a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala @@ -32,7 +32,7 @@ trait FunctoidMacroBase[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { Select.unique(fnAny.asTerm, "apply").appliedToArgs(params.map(_.asTerm)).asExprOf[Any] } - final class FunctoidMacroImpl[Q <: Quotes & Singleton](using val qctx: Q)(val paramsMacro: FunctoidParametersMacroBase[qctx.type]) { + final class FunctoidMacroImpl[Q <: Quotes](using val qctx: Q)(val paramsMacro: FunctoidParametersMacroBase[qctx.type]) { import qctx.reflect.* def make[R: Type](fun: Expr[AnyRef]): Expr[Ftoid[R]] = { diff --git a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala index fc52ebe8c6..5b79cc718d 100644 --- a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala +++ b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala @@ -4,7 +4,7 @@ import izumi.distage.model.reflection.LinkedParameter import scala.quoted.{Expr, Quotes} -trait FunctoidParametersMacroBase[Q <: Quotes & Singleton] { +trait FunctoidParametersMacroBase[Q <: Quotes] { val qctx: Q import qctx.reflect.* From 61634e2ecdc517b9710f051b223357a9dcda0105 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 5 Jun 2024 16:39:13 +0100 Subject: [PATCH 44/59] scala 3 done (more or less) --- .../constructors/ConstructorUtil.scala | 4 +- .../macros/FunctoidMacroMethods.scala | 6 ++- .../reflection/macros/IdExtractorImpl.scala | 37 +++++++++++++++++++ .../macros/FunctoidParametersMacro.scala | 32 +--------------- .../reflection/macros/IdExtractor.scala | 11 ++++++ 5 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/IdExtractorImpl.scala rename {distage/distage-core-api => fundamentals/fundamentals-platform}/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala (56%) create mode 100644 fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/IdExtractor.scala diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala index e4865084fc..4eb19d8082 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/constructors/ConstructorUtil.scala @@ -7,7 +7,7 @@ import scala.annotation.{nowarn, tailrec} import scala.quoted.{Expr, Quotes, Type} import scala.collection.mutable import izumi.distage.model.providers.Functoid -import izumi.distage.reflection.macros.{FunctoidMacro, FunctoidMacroHelpers, FunctoidParametersMacro} +import izumi.distage.reflection.macros.{FunctoidMacro, FunctoidMacroHelpers, FunctoidParametersMacro, IdExtractorImpl} import izumi.distage.model.reflection.Provider.{ProviderImpl, ProviderType} import izumi.fundamentals.reflection.ReflectiveCall import izumi.reflect.WeakTag @@ -120,6 +120,7 @@ class ConstructorUtil[Q <: Quotes](using val qctx: Q) { self => import qctx.reflect.* private val withAnnotationSym: Symbol = TypeRepr.of[With].typeSymbol + private val paramsMacro = new FunctoidParametersMacro[qctx.type](new IdExtractorImpl[qctx.type]()) final case class ParamRepr(name: String, mbSymbol: Option[Symbol], tpe: TypeRepr) @@ -157,7 +158,6 @@ class ConstructorUtil[Q <: Quotes](using val qctx: Q) { self => } def makeFunctoid[R: Type](params: List[ParamRepr], argsLambda: Expr[Seq[Any] => R], providerType: Expr[ProviderType]): Expr[Functoid[R]] = { - val paramsMacro = new FunctoidParametersMacro[qctx.type] val paramDefs = params.map { case ParamRepr(n, s, t) => paramsMacro.makeParam(n, Right(t), s) diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index 307d2fc665..e18434afb6 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -12,7 +12,11 @@ trait FunctoidMacroMethods extends FunctoidMacroMethodsBase {} object FunctoidMacro extends FunctoidMacroBase[Functoid] { transparent inline def make[R](inline fun: AnyRef): Functoid[R] = ${ makeImpl[R]('fun) } - def makeImpl[R: Type](fun: Expr[AnyRef])(using qctx: Quotes): Expr[Functoid[R]] = new FunctoidMacroImpl[qctx.type](new FunctoidParametersMacro[qctx.type]()).make(fun) + def makeImpl[R: Type](fun: Expr[AnyRef])(using qctx: Quotes): Expr[Functoid[R]] = { + val idExtractor = new IdExtractorImpl[qctx.type]() + val paramMacro = new FunctoidParametersMacro[qctx.type](idExtractor) + new FunctoidMacroImpl[qctx.type](paramMacro).make(fun) + } protected def generateFunctoid[R: Type, Q <: Quotes](paramDefs: List[Expr[LinkedParameter]], originalFun: Expr[AnyRef])(using qctx: Q): Expr[Functoid[R]] = { '{ diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/IdExtractorImpl.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/IdExtractorImpl.scala new file mode 100644 index 0000000000..f6900b26bc --- /dev/null +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/IdExtractorImpl.scala @@ -0,0 +1,37 @@ +package izumi.distage.reflection.macros + +import izumi.distage.model.definition.Id +import izumi.fundamentals.platform.reflection.ReflectionUtil + +import scala.quoted.Quotes + +final class IdExtractorImpl[Q <: Quotes](using val qctx: Q) extends IdExtractor[Q] { + import qctx.reflect.* + + private val idAnnotationSym: Symbol = TypeRepr.of[Id].typeSymbol + private val maybeJavaxNamedAnnotationSym: Option[Symbol] = scala.util.Try(Symbol.requiredClass("javax.inject.Named")).toOption + + def extractId(name: String, annotSym: Option[Symbol], annotTpe: Either[TypeTree, TypeRepr]): Option[String] = { + ReflectionUtil + .readTypeOrSymbolDIAnnotation(idAnnotationSym)(name, annotSym, annotTpe) { + case aterm @ Apply(Select(New(_), _), c :: _) => + c.asExprOf[String].value.orElse { + report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") + } + case aterm => + report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") + }.orElse { + maybeJavaxNamedAnnotationSym.flatMap { + namedAnnoSym => + ReflectionUtil.readTypeOrSymbolDIAnnotation(namedAnnoSym)(name, annotSym, annotTpe) { + case aterm @ Apply(Select(New(_), _), c :: _) => + c.asExprOf[String].value.orElse { + report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") + } + case aterm => + report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") + } + } + } + } +} diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala similarity index 56% rename from distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala rename to fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala index e52de6f6ea..6a9ee58160 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala +++ b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala @@ -1,19 +1,14 @@ package izumi.distage.reflection.macros -import izumi.distage.model.definition.Id import izumi.distage.model.reflection.* -import izumi.fundamentals.platform.reflection.ReflectionUtil import izumi.reflect.Tag import scala.quoted.{Expr, Quotes} -final class FunctoidParametersMacro[Q <: Quotes](using val qctx: Q) extends FunctoidParametersMacroBase[Q] { +final class FunctoidParametersMacro[Q <: Quotes](using val qctx: Q)(idExtractor: IdExtractor[qctx.type]) extends FunctoidParametersMacroBase[Q] { import qctx.reflect.* - private val idAnnotationSym: Symbol = TypeRepr.of[Id].typeSymbol - private val maybeJavaxNamedAnnotationSym: Option[Symbol] = scala.util.Try(Symbol.requiredClass("javax.inject.Named")).toOption - extension (t: Either[TypeTree, TypeRepr]) { private def _tpe: TypeRepr = t match { case Right(t) => t @@ -26,30 +21,7 @@ final class FunctoidParametersMacro[Q <: Quotes](using val qctx: Q) extends Func } def makeParam(name: String, tpe: Either[TypeTree, TypeRepr], annotSym: Option[Symbol], annotTpe: Either[TypeTree, TypeRepr]): Expr[LinkedParameter] = { - val identifier = { - val mbIdIdentifier = ReflectionUtil - .readTypeOrSymbolDIAnnotation(idAnnotationSym)(name, annotSym, annotTpe) { - case aterm @ Apply(Select(New(_), _), c :: _) => - c.asExprOf[String].value.orElse { - report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") - } - case aterm => - report.errorAndAbort(s"distage.Id annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") - } - mbIdIdentifier.orElse { - maybeJavaxNamedAnnotationSym.flatMap { - namedAnnoSym => - ReflectionUtil.readTypeOrSymbolDIAnnotation(namedAnnoSym)(name, annotSym, annotTpe) { - case aterm @ Apply(Select(New(_), _), c :: _) => - c.asExprOf[String].value.orElse { - report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got ${c.show} in tree ${aterm.show} ($aterm)") - } - case aterm => - report.errorAndAbort(s"javax.inject.Named annotation expects one literal String argument but got malformed tree ${aterm.show} ($aterm)") - } - } - } - } + val identifier = idExtractor.extractId(name, annotSym, annotTpe) val tpeRepr = tpe._tpe diff --git a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/IdExtractor.scala b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/IdExtractor.scala new file mode 100644 index 0000000000..f7a16973a8 --- /dev/null +++ b/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/IdExtractor.scala @@ -0,0 +1,11 @@ +package izumi.distage.reflection.macros + +import scala.quoted.Quotes + +trait IdExtractor[Q <: Quotes] { + val qctx: Q + + import qctx.reflect.* + + def extractId(name: String, annotSym: Option[Symbol], annotTpe: Either[TypeTree, TypeRepr]): Option[String] +} From 50e3681f1c889ce814d00c0967b0442b9b240c8e Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Wed, 5 Jun 2024 16:43:02 +0100 Subject: [PATCH 45/59] i/r 2.3.10 --- project/Versions.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Versions.scala b/project/Versions.scala index 0ff6f0ad1b..6355f08352 100644 --- a/project/Versions.scala +++ b/project/Versions.scala @@ -1,6 +1,6 @@ object V { // izumi - val izumi_reflect = "2.3.10-SNAPSHOT" + val izumi_reflect = "2.3.10" // foundation val collection_compat = "2.12.0" From 61385421ee10a177e6826356048bdb26d4da4585 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Thu, 6 Jun 2024 16:34:53 +0100 Subject: [PATCH 46/59] fundamentals-functoid --- build.sbt | 219 ++++++++++++++++++ .../basicuniverse/PortableNamedArg.scala | 0 .../reflection/JSRAnnotationTools.scala | 0 .../basicuniverse/PortableNamedArg.scala | 0 .../reflection/JSRAnnotationTools.scala | 0 .../macros/universe/FunctoidMacroBase.scala | 0 .../BaseReflectionProvider.scala | 0 .../basicuniverse/CompactParameter.scala | 0 .../basicuniverse/ConstructorSelector.scala | 0 .../DIUniverseBasicLiftables.scala | 0 .../basicuniverse/FriendlyAnnoTools.scala | 0 .../universe/basicuniverse/MacroDIKey.scala | 0 .../basicuniverse/MacroSafeType.scala | 0 .../MacroSymbolInfoCompact.scala | 0 .../MacroSymbolInfoCompactImpl.scala | 0 .../reflection/AnnotationTools.scala | 0 .../reflection/macros/FunctoidMacroBase.scala | 0 .../macros/FunctoidMacroHelpers.scala | 0 .../macros/FunctoidParametersMacro.scala | 0 .../macros/FunctoidParametersMacroBase.scala | 0 .../reflection/macros/IdExtractor.scala | 0 .../distage/model/definition/Identifier.scala | 0 .../model/providers/AbstractFunctoid.scala | 0 .../providers/SimpleFunctoidSyntax.scala | 0 .../model/providers/SimpleFunctoids.scala | 0 .../distage/model/reflection/DIKey.scala | 0 .../model/reflection/GenericTypedRef.scala | 0 .../distage/model/reflection/IdContract.scala | 0 .../model/reflection/LinkedParameter.scala | 0 .../distage/model/reflection/Provider.scala | 0 .../distage/model/reflection/SafeType.scala | 0 .../distage/model/reflection/SetKeyMeta.scala | 0 .../distage/model/reflection/SymbolInfo.scala | 0 .../basicuniverse/FriendlyAnnotation.scala | 0 .../AnnotationConflictException.scala | 0 .../exceptions/BadIdAnnotationException.scala | 0 project/Deps.sc | 20 ++ 37 files changed, 239 insertions(+) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2.12/izumi/fundamentals/reflection/JSRAnnotationTools.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2.13/izumi/fundamentals/reflection/JSRAnnotationTools.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-2/izumi/fundamentals/reflection/AnnotationTools.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala-3/izumi/distage/reflection/macros/IdExtractor.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/definition/Identifier.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/reflection/DIKey.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/reflection/IdContract.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/reflection/LinkedParameter.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/reflection/Provider.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/reflection/SafeType.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/AnnotationConflictException.scala (100%) rename fundamentals/{fundamentals-platform => fundamentals-functoid}/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/BadIdAnnotationException.scala (100%) diff --git a/build.sbt b/build.sbt index 8e2025a4f0..5cf3adb1ed 100644 --- a/build.sbt +++ b/build.sbt @@ -1289,6 +1289,221 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl .enablePlugins(SitePreviewPlugin) .disablePlugins(AssemblyPlugin) +lazy val `fundamentals-functoid` = project.in(file("fundamentals/fundamentals-functoid")) + .dependsOn( + `fundamentals-platform` % "test->compile;compile->compile", + `fundamentals-language` % "test->compile;compile->compile", + `fundamentals-collections` % "test->compile;compile->compile" + ) + .settings( + libraryDependencies ++= Seq( + "org.scala-lang.modules" %% "scala-collection-compat" % V.collection_compat, + "org.scalatest" %% "scalatest" % V.scalatest % Test, + "dev.zio" %% "izumi-reflect" % V.izumi_reflect + ), + libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq( + compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full), + "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided + ) else Seq.empty } + ) + .settings( + crossScalaVersions := Seq( + "3.4.1", + "2.13.14", + "2.12.19" + ), + scalaVersion := crossScalaVersions.value.head, + organization := "io.7mind.izumi", + Compile / unmanagedSourceDirectories += baseDirectory.value / ".jvm/src/main/scala" , + Compile / unmanagedSourceDirectories ++= (scalaBinaryVersion.value :: CrossVersion.partialVersion(scalaVersion.value).toList.map(_._1)) + .map(v => baseDirectory.value / s".jvm/src/main/scala-$v").distinct, + Compile / unmanagedResourceDirectories += baseDirectory.value / ".jvm/src/main/resources" , + Test / unmanagedSourceDirectories += baseDirectory.value / ".jvm/src/test/scala" , + Test / unmanagedSourceDirectories ++= (scalaBinaryVersion.value :: CrossVersion.partialVersion(scalaVersion.value).toList.map(_._1)) + .map(v => baseDirectory.value / s".jvm/src/test/scala-$v").distinct, + Test / unmanagedResourceDirectories += baseDirectory.value / ".jvm/src/test/resources" , + scalacOptions ++= Seq( + s"-Xmacro-settings:product-name=${name.value}", + s"-Xmacro-settings:product-version=${version.value}", + s"-Xmacro-settings:product-group=${organization.value}", + s"-Xmacro-settings:scala-version=${scalaVersion.value}", + s"-Xmacro-settings:scala-versions=${crossScalaVersions.value.mkString(":")}" + ), + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val ltEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ <= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => ltEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n+") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val ltEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ <= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => ltEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n+") } + case _ => Seq.empty + } + }, + Compile / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Compile / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / unmanagedSourceDirectories ++= { + val version = scalaVersion.value + val crossVersions = crossScalaVersions.value + import Ordering.Implicits._ + val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten + (Test / unmanagedSourceDirectories).value.flatMap { + case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$m.$n-") } + case _ => Seq.empty + } + }, + Test / testOptions += Tests.Argument("-oDF"), + scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { + case (_, "2.12.19") => Seq( + "-Wconf:any:error", + "-release:8", + "-explaintypes", + "-Xsource:3", + "-P:kind-projector:underscore-placeholders", + "-Ypartial-unification", + if (insideCI.value) "-Wconf:any:error" else "-Wconf:any:warning", + "-Wconf:cat=optimizer:warning", + "-Wconf:cat=other-match-analysis:error", + "-Ybackend-parallelism", + math.min(16, math.max(1, sys.runtime.availableProcessors() - 1)).toString, + "-Xlint:adapted-args", + "-Xlint:by-name-right-associative", + "-Xlint:constant", + "-Xlint:delayedinit-select", + "-Xlint:doc-detached", + "-Xlint:inaccessible", + "-Xlint:infer-any", + "-Xlint:missing-interpolator", + "-Xlint:nullary-override", + "-Xlint:nullary-unit", + "-Xlint:option-implicit", + "-Xlint:package-object-classes", + "-Xlint:poly-implicit-overload", + "-Xlint:private-shadow", + "-Xlint:stars-align", + "-Xlint:type-parameter-shadow", + "-Xlint:unsound-match", + "-opt-warnings:_", + "-Ywarn-extra-implicit", + "-Ywarn-unused:_", + "-Ywarn-adapted-args", + "-Ywarn-dead-code", + "-Ywarn-inaccessible", + "-Ywarn-infer-any", + "-Ywarn-nullary-override", + "-Ywarn-nullary-unit", + "-Ywarn-numeric-widen", + "-Ywarn-unused-import", + "-Ywarn-value-discard", + "-Ycache-plugin-class-loader:always", + "-Ycache-macro-class-loader:last-modified" + ) + case (_, "2.13.14") => Seq( + "-Wconf:any:error", + "-release:8", + "-explaintypes", + "-P:kind-projector:underscore-placeholders", + if (insideCI.value) "-Wconf:any:error" else "-Wconf:any:warning", + "-Wconf:cat=optimizer:warning", + "-Wconf:cat=other-match-analysis:error", + "-Vimplicits", + "-Vtype-diffs", + "-Ybackend-parallelism", + math.min(16, math.max(1, sys.runtime.availableProcessors() - 1)).toString, + "-Wdead-code", + "-Wextra-implicit", + "-Wnumeric-widen", + "-Woctal-literal", + "-Wvalue-discard", + "-Wunused:_", + "-Wmacros:default", + "-Ycache-plugin-class-loader:always", + "-Ycache-macro-class-loader:last-modified", + "-Wunused:-synthetics" + ) + case (_, "3.4.1") => Seq( + "-Yretain-trees", + "-language:3.4", + "-release:8", + "-Ykind-projector:underscores", + "-Yretain-trees", + "-no-indent", + "-explain", + "-explain-types", + "-Xmax-inlines:64", + "-Wconf:msg=eta-expanded even though:silent" + ) + case (_, _) => Seq.empty + } }, + scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { + case (_, "3.4.1") => Seq( + "-Wconf:any:verbose", + "-Wconf:msg=.this. qualifier will be deprecated:silent", + "-Wconf:msg=scala.compiletime.uninitialized:silent", + "-Wconf:msg=`using` clause:silent", + "-Wconf:msg=eta-expanded even though:silent", + "-Wconf:msg=The syntax ..function:silent", + "-Wconf:msg=method contains is not declared infix:silent", + "-Wconf:msg=method in is not declared infix:silent" + ) + case (_, _) => Seq( + "-Wconf:msg=parameter.*x\\$4.in.anonymous.function.is.never.used:silent", + "-Wconf:msg=constructor.modifiers.are.assumed.by.synthetic.*method:silent", + "-Wconf:msg=package.object.inheritance:silent", + "-Wconf:cat=lint-eta-sam:silent" + ) + } }, + scalacOptions -= "-Wconf:any:warning", + scalacOptions += "-Wconf:cat=deprecation:warning", + scalacOptions += "-Wconf:msg=legacy-binding:silent", + scalacOptions += "-Wconf:msg=nowarn:silent", + Compile / sbt.Keys.doc / scalacOptions -= "-Wconf:any:error", + scalacOptions ++= Seq( + s"-Xmacro-settings:scalatest-version=${V.scalatest}", + s"-Xmacro-settings:is-ci=${insideCI.value}" + ), + scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { + case (false, "2.12.19") => Seq( + "-opt:l:inline", + "-opt-inline-from:izumi.**" + ) + case (false, "2.13.14") => Seq( + "-opt:l:inline", + "-opt-inline-from:izumi.**" + ) + case (_, _) => Seq.empty + } }, + scalacOptions ++= { (isSnapshot.value, scalaVersion.value) match { + case (_, "2.13.14") => Seq( + "-Xsource:3", + "-Xmigration", + "-Wconf:cat=scala3-migration:silent", + "-Wconf:cat=other-migration:silent" + ) + case (_, _) => Seq.empty + } }, + Test / packageDoc / publishArtifact := false + ) + .enablePlugins(SitePreviewPlugin) + .disablePlugins(AssemblyPlugin) + lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals-json-circe")) .dependsOn( `fundamentals-platform` % "test->compile;compile->compile" @@ -1748,6 +1963,7 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) .dependsOn( `fundamentals-platform` % "test->compile;compile->compile", + `fundamentals-functoid` % "test->compile;compile->compile", `fundamentals-bio` % "test->compile;compile->compile" ) .settings( @@ -5228,6 +5444,7 @@ lazy val `microsite` = project.in(file("doc/microsite")) `fundamentals-orphans` % "test->compile;compile->compile", `fundamentals-language` % "test->compile;compile->compile", `fundamentals-platform` % "test->compile;compile->compile", + `fundamentals-functoid` % "test->compile;compile->compile", `fundamentals-json-circe` % "test->compile;compile->compile", `fundamentals-bio` % "test->compile;compile->compile", `distage-core-api` % "test->compile;compile->compile", @@ -5750,6 +5967,7 @@ lazy val `fundamentals` = (project in file(".agg/fundamentals-fundamentals")) `fundamentals-orphans`, `fundamentals-language`, `fundamentals-platform`, + `fundamentals-functoid`, `fundamentals-json-circe`, `fundamentals-bio` ) @@ -5767,6 +5985,7 @@ lazy val `fundamentals-jvm` = (project in file(".agg/fundamentals-fundamentals-j `fundamentals-orphans`, `fundamentals-language`, `fundamentals-platform`, + `fundamentals-functoid`, `fundamentals-json-circe`, `fundamentals-bio` ) diff --git a/fundamentals/fundamentals-platform/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala b/fundamentals/fundamentals-functoid/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2.12/izumi/fundamentals/reflection/JSRAnnotationTools.scala b/fundamentals/fundamentals-functoid/src/main/scala-2.12/izumi/fundamentals/reflection/JSRAnnotationTools.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2.12/izumi/fundamentals/reflection/JSRAnnotationTools.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2.12/izumi/fundamentals/reflection/JSRAnnotationTools.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala b/fundamentals/fundamentals-functoid/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2.13/izumi/fundamentals/reflection/JSRAnnotationTools.scala b/fundamentals/fundamentals-functoid/src/main/scala-2.13/izumi/fundamentals/reflection/JSRAnnotationTools.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2.13/izumi/fundamentals/reflection/JSRAnnotationTools.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2.13/izumi/fundamentals/reflection/JSRAnnotationTools.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroDIKey.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/reflection/AnnotationTools.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/fundamentals/reflection/AnnotationTools.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-2/izumi/fundamentals/reflection/AnnotationTools.scala rename to fundamentals/fundamentals-functoid/src/main/scala-2/izumi/fundamentals/reflection/AnnotationTools.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala b/fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala rename to fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala b/fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala rename to fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroHelpers.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala b/fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala rename to fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacro.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala b/fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala rename to fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidParametersMacroBase.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/IdExtractor.scala b/fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/IdExtractor.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala-3/izumi/distage/reflection/macros/IdExtractor.scala rename to fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/IdExtractor.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/definition/Identifier.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/definition/Identifier.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/definition/Identifier.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/definition/Identifier.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/DIKey.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/DIKey.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/DIKey.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/DIKey.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/GenericTypedRef.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/IdContract.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/IdContract.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/IdContract.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/IdContract.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/LinkedParameter.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/LinkedParameter.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/LinkedParameter.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/LinkedParameter.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/Provider.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/Provider.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/Provider.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/Provider.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SafeType.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/SafeType.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SafeType.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/SafeType.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/SetKeyMeta.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/SymbolInfo.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnotation.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/AnnotationConflictException.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/AnnotationConflictException.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/AnnotationConflictException.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/AnnotationConflictException.scala diff --git a/fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/BadIdAnnotationException.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/BadIdAnnotationException.scala similarity index 100% rename from fundamentals/fundamentals-platform/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/BadIdAnnotationException.scala rename to fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/reflection/macros/universe/basicuniverse/exceptions/BadIdAnnotationException.scala diff --git a/project/Deps.sc b/project/Deps.sc index db869b294b..8a1475aa29 100644 --- a/project/Deps.sc +++ b/project/Deps.sc @@ -361,6 +361,7 @@ object Izumi { final val collections = ArtifactId("fundamentals-collections") final val platform = ArtifactId("fundamentals-platform") + final val functoid = ArtifactId("fundamentals-functoid") final val language = ArtifactId("fundamentals-language") final val functional = ArtifactId("fundamentals-functional") final val bio = ArtifactId("fundamentals-bio") @@ -373,6 +374,7 @@ object Izumi { final lazy val basics = Seq( platform, + functoid, collections, functional, ).map(_ in Scope.Runtime.all) @@ -496,6 +498,23 @@ object Izumi { ), plugins = Plugins(Seq(Plugin("ScalaJSBundlerPlugin", Platform.Js))), ), + Artifact( + name = Projects.fundamentals.functoid, + libs = Seq( + izumi_reflect in Scope.Compile.all, + scala_reflect, + ), + depends = Seq( + Projects.fundamentals.platform, + Projects.fundamentals.language in Scope.Compile.all, + Projects.fundamentals.collections in Scope.Compile.all, + // Projects.fundamentals.reflection in Scope.Compile.all, + ), +// settings = Seq( +// "npmDependencies" in (SettingScope.Test, Platform.Js) ++= Seq("hash.js" -> "1.1.7") +// ), +// plugins = Plugins(Seq(Plugin("ScalaJSBundlerPlugin", Platform.Js))), + ), Artifact( name = Projects.fundamentals.jsonCirce, libs = Seq( @@ -566,6 +585,7 @@ object Izumi { depends = Seq( // Projects.fundamentals.reflection, Projects.fundamentals.platform, + Projects.fundamentals.functoid, Projects.fundamentals.bio, ).map(_ in Scope.Compile.all), platforms = Targets.cross3, From c4fde73e975985ad11cb7c7e9190ed43a6f28871 Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:02:07 +0100 Subject: [PATCH 47/59] LifecycleTagMacro: add Try just in case --- .../izumi/distage/model/definition/dsl/LifecycleTagMacro.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/LifecycleTagMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/LifecycleTagMacro.scala index d40f52c35b..2b342865ee 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/LifecycleTagMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/model/definition/dsl/LifecycleTagMacro.scala @@ -4,11 +4,12 @@ import izumi.distage.model.definition.Lifecycle import izumi.reflect.TagMacro import scala.reflect.macros.blackbox +import scala.util.Try object LifecycleTagMacro { def fakeResourceTagMacroIntellijWorkaroundImpl[R <: Lifecycle[Any, Any]: c.WeakTypeTag](c: blackbox.Context): c.Expr[Nothing] = { val tagMacro = new TagMacro(c) - val _ = tagMacro.makeWeakTag[R] // run the macro AGAIN, to get a fresh error message + val _ = Try(tagMacro.makeWeakTag[R]) // run the macro AGAIN, to get a fresh error message val tagTrace = tagMacro.getImplicitError() c.abort(c.enclosingPosition, s"could not find implicit ResourceTag for ${c.universe.weakTypeOf[R]}!\n$tagTrace") From 45290f18ec3129777a99d1e3e4f9d531f7d543e2 Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:02:40 +0100 Subject: [PATCH 48/59] Make DIAnnotationMeta just a function --- .../izumi/distage/reflection/macros/FunctoidMacro.scala | 3 +-- .../macros/universe/ReflectionProviderDefaultImpl.scala | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 5ea7178ff8..26e868593b 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -7,6 +7,5 @@ import scala.reflect.macros.blackbox class FunctoidMacro(ctx: blackbox.Context) extends FunctoidMacroBase(ctx) { override def tpe[A: c.WeakTypeTag]: c.Type = c.weakTypeOf[Functoid[A]] - - override def idAnnotationFqn: String = new DIAnnotationMeta(ctx.universe).idAnnotationFqn + override def idAnnotationFqn: String = DIAnnotationMeta.idAnnotationFqn(ctx.universe) } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index d70569fe12..fac8a5a87e 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -9,8 +9,8 @@ import izumi.fundamentals.reflection.ReflectionUtil import scala.annotation.nowarn -class DIAnnotationMeta(u: scala.reflect.api.Universe) { - def idAnnotationFqn: String = u.typeOf[Id].typeSymbol.fullName +object DIAnnotationMeta { + def idAnnotationFqn(u: scala.reflect.api.Universe): String = u.typeOf[Id].typeSymbol.fullName } @nowarn("msg=outer reference") @@ -20,7 +20,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { import u.* import u.u.Annotation - private lazy val idAnnotationFqn = new DIAnnotationMeta(u.u).idAnnotationFqn + private lazy val idAnnotationFqn = DIAnnotationMeta.idAnnotationFqn(u.u) private lazy val brp = new BaseReflectionProvider(u.ctx.universe, idAnnotationFqn) private object With { From 9ebdfecf3f43a6d4f2596d97ca8953374d42a914 Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:03:42 +0100 Subject: [PATCH 49/59] Return ProviderType.Singleton --- .../distage/model/providers/SimpleFunctoids.scala | 2 +- .../izumi/distage/model/reflection/Provider.scala | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala index 7b10c7d25b..e0afa51321 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoids.scala @@ -32,7 +32,7 @@ private[providers] trait SimpleFunctoids[Ftoid[+_]] { ret = SafeType.get[A], underlying = a.asInstanceOf[AnyRef], fun = (_: Seq[Any]) => a, - providerType = ProviderType.Constructor, + providerType = ProviderType.Singleton, ) ) } diff --git a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/Provider.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/Provider.scala index bbe1a1bab1..d561f743c6 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/Provider.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/Provider.scala @@ -28,7 +28,7 @@ trait Provider { providerType match { case ProviderType.Constructor => (ret, diKeys) case ProviderType.Function => (underlying, diKeys) - case ProviderType.Constant => (underlying, diKeys) + case ProviderType.Singleton => (underlying, diKeys) } } @@ -40,13 +40,11 @@ trait Provider { override final def toString: String = s"$funString(${argTypes.mkString(", ")}): $ret" final def funString: String = providerType match { - case ProviderType.Constant => s"κ:$underlying" + case ProviderType.Singleton => s"κ:$underlying" case ProviderType.Constructor => s"π:$providerType" case ProviderType.Function => s"ƒ:$underlying" } - if (providerType eq ProviderType.Function) {} else {} - protected def verifyArgs(refs: Seq[GenericTypedRef[?]]): Seq[Any] = { val (newArgs, types, typesCmp) = parameters .zip(refs).map { @@ -80,14 +78,13 @@ object Provider { sealed trait ProviderType object ProviderType { - case object Constant extends ProviderType + /** Reference to a singleton object or a literal constant. */ + case object Singleton extends ProviderType - /** Function generated by any of the "constructor" macros - */ + /** Function generated by any of the "constructor" macros */ case object Constructor extends ProviderType - /** Function captured by the Functoid macro any provider transformed by the unsafeMap helper method - */ + /** Function captured by the Functoid macro any provider transformed by the unsafeMap helper method */ case object Function extends ProviderType } From efc5b28501cd93a3c5cedbe11736ef2136a2ce04 Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:04:00 +0100 Subject: [PATCH 50/59] package-private `Functoid#returnTypeTag` --- .../scala/izumi/distage/model/providers/AbstractFunctoid.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala index 09c02d2ce8..c4b93d7294 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala @@ -91,5 +91,5 @@ trait AbstractFunctoid[+A, Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { create[A](newProvider) } - def returnTypeTag: Tag[A @uncheckedVariance] = Tag(get.ret.closestClass, get.ret.tag) + private[distage] def returnTypeTag: Tag[A @uncheckedVariance] = Tag(get.ret.closestClass, get.ret.tag) } From a3c0f8e4fad3883c9360da1aadccb3288b08fa8e Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:39:13 +0100 Subject: [PATCH 51/59] Return DebugProperties for Functoid --- .../izumi/distage/constructors/DebugProperties.scala | 4 ++-- .../reflection/macros/universe/FunctoidMacroBase.scala | 3 +-- .../reflection/macros/universe/DebugProperties.scala | 10 ++++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/reflection/macros/universe/DebugProperties.scala diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/constructors/DebugProperties.scala b/distage/distage-core-api/src/main/scala/izumi/distage/constructors/DebugProperties.scala index 8db1bd1bdf..be6545545e 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/constructors/DebugProperties.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/constructors/DebugProperties.scala @@ -3,13 +3,13 @@ package izumi.distage.constructors import izumi.fundamentals.platform.properties /** - * Java properties that control debug output of [[izumi.distage.constructors]] & [[izumi.distage.model.providers.Functoid]] macros + * Java properties that control debug output of [[izumi.distage.constructors]] macros * * @see [[DebugProperties]] + * @see [[izumi.distage.reflection.macros.universe.DebugProperties]] for [[izumi.distage.model.providers.Functoid]] debug output */ object DebugProperties extends properties.DebugProperties { final val `izumi.debug.macro.distage.constructors` = BoolProperty("izumi.debug.macro.distage.constructors") - final val `izumi.debug.macro.distage.functoid` = BoolProperty("izumi.debug.macro.distage.functoid") final val `izumi.distage.rendering.colored` = BoolProperty("izumi.distage.rendering.colored") final val `izumi.distage.rendering.colored.forced` = BoolProperty("izumi.distage.rendering.colored.forced") } diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala index ff1c978d92..715ae8cbc8 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala @@ -27,8 +27,7 @@ abstract class FunctoidMacroBase(val c: blackbox.Context) { private lazy val brp = new BaseReflectionProvider(c.universe, idAnnotationFqn) -// private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) - private final val logger = TrivialMacroLogger.make[this.type](c, "xxx") + private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) private def symbolToParam(p: Symbol): Parameter = { brp.symbolToParameter(p.asInstanceOf[brp.u.Symbol]) diff --git a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/reflection/macros/universe/DebugProperties.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/reflection/macros/universe/DebugProperties.scala new file mode 100644 index 0000000000..35e6f45922 --- /dev/null +++ b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/reflection/macros/universe/DebugProperties.scala @@ -0,0 +1,10 @@ +package izumi.distage.reflection.macros.universe + +/** + * Java properties that control debug output of [[izumi.distage.model.providers.Functoid]] macros + * + * @see [[DebugProperties]] + */ +object DebugProperties extends izumi.fundamentals.platform.properties.DebugProperties { + final val `izumi.debug.macro.distage.functoid` = BoolProperty("izumi.debug.macro.distage.functoid") +} From d71311c4b864ad2df843fdbb40c95de1407420c7 Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:43:58 +0100 Subject: [PATCH 52/59] remove asInstanceOfs, pass Functoid type in FunctoidMacroBase constructor parameter --- .../reflection/macros/FunctoidMacro.scala | 2 +- .../macros/FunctoidMacroMethods.scala | 46 +++++++++---------- .../constructors/ConstructorMacros.scala | 2 +- .../macros/universe/DIUniverseLiftables.scala | 6 +-- .../ReflectionProviderDefaultImpl.scala | 8 ++-- .../universe/impl/WithDISymbolInfo.scala | 4 +- .../distage/model/providers/Functoid.scala | 2 +- .../macros/universe/FunctoidMacroBase.scala | 24 +++++----- .../BaseReflectionProvider.scala | 9 ++-- .../basicuniverse/ConstructorSelector.scala | 8 ++-- .../DIUniverseBasicLiftables.scala | 9 ++-- .../basicuniverse/MacroSafeType.scala | 11 +++-- .../MacroSymbolInfoCompact.scala | 3 +- .../MacroSymbolInfoCompactImpl.scala | 4 +- 14 files changed, 68 insertions(+), 70 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala index 26e868593b..02d70577f1 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacro.scala @@ -5,7 +5,7 @@ import izumi.distage.reflection.macros.universe.{DIAnnotationMeta, FunctoidMacro import scala.reflect.macros.blackbox -class FunctoidMacro(ctx: blackbox.Context) extends FunctoidMacroBase(ctx) { +final class FunctoidMacro(ctx: blackbox.Context) extends FunctoidMacroBase[Functoid](ctx) { override def tpe[A: c.WeakTypeTag]: c.Type = c.weakTypeOf[Functoid[A]] override def idAnnotationFqn: String = DIAnnotationMeta.idAnnotationFqn(ctx.universe) } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index dbe7f7743f..9ef34e2840 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -6,27 +6,27 @@ import scala.language.experimental.macros import scala.language.implicitConversions trait FunctoidMacroMethods { - implicit def apply[R](fun: () => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] - implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R, Functoid] + implicit def apply[R](fun: () => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] + implicit def apply[R](fun: (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) => R): Functoid[R] = macro FunctoidMacro.impl[R] } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala index 42454c9a51..7bba5ef886 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ConstructorMacros.scala @@ -312,7 +312,7 @@ abstract class ConstructorMacrosBase { } val retTpe = weakTypeOf[T] - val retTagTree = MacroSafeType.create(c.universe)(retTpe).tagTree.asInstanceOf[c.Tree] + val retTagTree = MacroSafeType.create(c.universe)(retTpe).tagTree(c.universe) c.Expr[Functoid[T]] { q"""{ diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index 99714ec4ed..5635d066b8 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -4,9 +4,9 @@ import izumi.distage.reflection.macros.universe.basicuniverse.DIUniverseBasicLif class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { - val basic: DIUniverseBasicLiftables[u.u.type] = DIUniverseBasicLiftables[u.u.type](u.ctx) - import basic.* - import u.* + val basic: DIUniverseBasicLiftables[u.u.type] = DIUniverseBasicLiftables[u.u.type](u.u) + import basic.{modelReflectionPkg, liftableBasicDIKey} + import u.Association import u.u.* implicit val liftableParameter: Liftable[Association.Parameter] = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index fac8a5a87e..0778df69dd 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -61,7 +61,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { typeRef .map(_.pre) .filterNot(m => m.termSymbol.isModule && m.termSymbol.isStatic) - .map(v => MacroDIKey.TypeKey(MacroSafeType.create(u.ctx.universe)(v.asInstanceOf[u.ctx.Type]))) + .map(v => MacroDIKey.TypeKey(MacroSafeType.create(u.u)(v))) } } @@ -84,11 +84,11 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { | | * $mms |""".stripMargin, - MacroSafeType.create(u.ctx.universe)(tpe.asInstanceOf[u.ctx.Type]), + MacroSafeType.create(u.u)(tpe), ) case _ => - val safeType = MacroSafeType.create(u.ctx.universe)(tpe.asInstanceOf[u.ctx.Type]) + val safeType = MacroSafeType.create(u.u)(tpe) val factoryMsg = if (factoryMethod != u.u.NoSymbol) { s""" | * When trying to create an implementation for result of `$factoryMethod` of factory `${factoryMethod.owner}` @@ -197,7 +197,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { def selectConstructorMethod(tpe: TypeNative): Option[MethodSymbNative] = { val cs = new ConstructorSelector(u.u) - cs.selectConstructorMethod(tpe.asInstanceOf[cs.u.Type]).map(s => s.asInstanceOf[MethodSymbNative]) + cs.selectConstructorMethod(tpe).map(s => s.asInstanceOf[MethodSymbNative]) } override def isConcrete(tpe: TypeNative): Boolean = { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index 0a84bd3d50..c636f6328c 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -45,7 +45,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) - override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(ctx.universe)(nonByNameFinalResultType.asInstanceOf[ctx.Type]) + override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(u)(nonByNameFinalResultType) } private[distage] object Runtime { @@ -96,7 +96,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) - override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(ctx.universe)(nonByNameFinalResultType.asInstanceOf[ctx.Type]) + override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(u)(nonByNameFinalResultType) } object Static { def syntheticFromType(transformName: String => String)(tpe: TypeNative): MacroSymbolInfo.Static = { diff --git a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala index 4b3e8329a6..7a9fdb8d0d 100644 --- a/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala +++ b/distage/distage-core-api/src/main/scala/izumi/distage/model/providers/Functoid.scala @@ -54,7 +54,7 @@ import izumi.distage.reflection.macros.FunctoidMacroMethods * make[X].from(X.apply _) // summons special Int * }}} * - * Functoid forms an applicative functor via its [[izumi.distage.model.providers.Functoid.pure]] & [[izumi.distage.model.providers.Functoid#map2]] methods + * Functoid forms an applicative functor via its [[izumi.distage.model.providers.Functoid.pure]] & [[izumi.distage.model.providers.AbstractFunctoid.map2]] methods * * @note `javax.inject.Named` annotation is also supported * diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala index 715ae8cbc8..2340c071d8 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala @@ -17,28 +17,28 @@ import scala.reflect.macros.blackbox * * @see [[izumi.distage.constructors.DebugProperties]] */ -abstract class FunctoidMacroBase(val c: blackbox.Context) { +abstract class FunctoidMacroBase[Ftoid[_]](val c: blackbox.Context) { type Parameter = CompactParameter import c.universe.* - def tpe[A: c.WeakTypeTag]: c.Type + def tpe[A: WeakTypeTag]: Type def idAnnotationFqn: String - private lazy val brp = new BaseReflectionProvider(c.universe, idAnnotationFqn) + private lazy val brp: BaseReflectionProvider[c.universe.type] = new BaseReflectionProvider(c.universe, idAnnotationFqn) private final val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.functoid`.name) private def symbolToParam(p: Symbol): Parameter = { - brp.symbolToParameter(p.asInstanceOf[brp.u.Symbol]) + brp.symbolToParameter(p) } private def typeToParam(tpe: Type): Parameter = { - brp.typeToParameter(tpe.asInstanceOf[brp.u.Type], c.freshName) + brp.typeToParameter(tpe, c.freshName) } - def impl[R: c.WeakTypeTag, Ftoid[_]](fun: Tree): c.Expr[Ftoid[R]] = { + def impl[R: WeakTypeTag](fun: Tree): Tree = { val associations = analyze(fun, weakTypeOf[R]) - val result = generateProvider[R, Ftoid](associations, fun) + val result = generateProvider[R](associations, fun) logger.log( s"""DIKeyWrappedFunction info: @@ -49,14 +49,14 @@ abstract class FunctoidMacroBase(val c: blackbox.Context) { | argument: ${showCode(fun)}\n | argumentTree: ${showRaw(fun)}\n | argumentType: ${fun.tpe} - | Result code: ${showCode(result.tree)}""".stripMargin + | Result code: ${showCode(result)}""".stripMargin ) result } - def generateProvider[R: c.WeakTypeTag, Ftoid[_]](parameters: List[Parameter], fun: Tree): c.Expr[Ftoid[R]] = { - val tools = new DIUniverseBasicLiftables(c) + def generateProvider[R: WeakTypeTag](parameters: List[Parameter], fun: Tree): Tree = { + val tools = new DIUniverseBasicLiftables(c.universe) import tools.liftableCompactParameter val seqName = if (parameters.nonEmpty) TermName(c.freshName("seqAny")) else TermName("_") @@ -65,9 +65,9 @@ abstract class FunctoidMacroBase(val c: blackbox.Context) { val parametersNoByName = Liftable.liftList[Parameter].apply(parameters) val retTpe = weakTypeOf[R] - val retTagTree = MacroSafeType.create(c.universe)(retTpe).tagTree.asInstanceOf[c.Tree] + val retTagTree = MacroSafeType.create(c.universe)(retTpe).tagTree(c.universe) - c.Expr[Ftoid[R]] { + { q"""{ val fun = $fun diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala index 187225255d..eb1d699a4e 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala @@ -3,7 +3,7 @@ package izumi.distage.reflection.macros.universe.basicuniverse import izumi.distage.reflection.macros.universe.basicuniverse import izumi.distage.reflection.macros.universe.basicuniverse.exceptions.BadIdAnnotationException -class BaseReflectionProvider(val u: scala.reflect.api.Universe, idAnnotationFqn: String) { +class BaseReflectionProvider[U <: scala.reflect.api.Universe & Singleton](val u: U, idAnnotationFqn: String) { def typeToParameter(t: u.Type, transformName: String => String): CompactParameter = { parameterToAssociation2(MacroSymbolInfoCompactImpl.syntheticFromType(u)(transformName)(t)) } @@ -18,10 +18,11 @@ class BaseReflectionProvider(val u: scala.reflect.api.Universe, idAnnotationFqn: } def tpeFromSymbol(parameterSymbol: MacroSymbolInfoCompact): MacroSafeType = { + val tpe = parameterSymbol.finalResultTypeIn(u) val paramType = if (parameterSymbol.isByName) { // this will never be true for a method symbol - parameterSymbol.finalResultType.typeArgs.head.finalResultType + tpe.typeArgs.head.finalResultType } else { - parameterSymbol.finalResultType + tpe } MacroSafeType.create(u)(paramType) } @@ -66,5 +67,3 @@ class BaseReflectionProvider(val u: scala.reflect.api.Universe, idAnnotationFqn: } } } - - diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala index 6c9b8a98c4..ae0f048820 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala @@ -1,7 +1,7 @@ package izumi.distage.reflection.macros.universe.basicuniverse -class ConstructorSelector(val u: scala.reflect.api.Universe) { - def selectConstructorMethod(tpe: u.Type): Option[scala.reflect.api.Universe#MethodSymbol] = { +class ConstructorSelector[U <: scala.reflect.api.Universe & Singleton](val u: U) { + def selectConstructorMethod(tpe: u.Type): Option[u.MethodSymbol] = { val constructor = findConstructor(tpe) if (!constructor.isTerm) { None @@ -10,11 +10,11 @@ class ConstructorSelector(val u: scala.reflect.api.Universe) { } } - @inline private def findConstructor(tpe: u.Type): scala.reflect.api.Universe#Symbol = { + @inline private def findConstructor(tpe: u.Type): u.Symbol = { findConstructor0(tpe).getOrElse(u.NoSymbol) } - private def findConstructor0(tpe: u.Type): Option[scala.reflect.api.Universe#Symbol] = { + private def findConstructor0(tpe: u.Type): Option[u.Symbol] = { tpe match { case intersection: u.RefinedTypeApi => intersection.parents.collectFirst(Function.unlift(findConstructor0)) diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala index 4260651027..c60a93f6ea 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala @@ -1,16 +1,13 @@ package izumi.distage.reflection.macros.universe.basicuniverse -import scala.reflect.macros.blackbox - -class DIUniverseBasicLiftables[U <: scala.reflect.api.Universe](val ctx: blackbox.Context) { - val u: U = ctx.universe.asInstanceOf[U] +class DIUniverseBasicLiftables[U <: scala.reflect.api.Universe & Singleton](val u: U) { import u.* val modelReflectionPkg: Tree = q"_root_.izumi.distage.model.reflection" implicit val liftableMacroSafeType: Liftable[MacroSafeType] = { stpe => - stpe.tagTree.asInstanceOf[Tree] + stpe.tagTree(u) } implicit val liftableCompactParameter: Liftable[CompactParameter] = { @@ -34,5 +31,5 @@ class DIUniverseBasicLiftables[U <: scala.reflect.api.Universe](val ctx: blackbo } object DIUniverseBasicLiftables { - def apply[U <: scala.reflect.api.Universe](c: blackbox.Context): DIUniverseBasicLiftables[U] = new DIUniverseBasicLiftables[U](c) + def apply[U <: scala.reflect.api.Universe & Singleton](u: U): DIUniverseBasicLiftables[U] = new DIUniverseBasicLiftables[U](u) } diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala index a2e906a9e0..4dbbb36aef 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSafeType.scala @@ -3,7 +3,7 @@ package izumi.distage.reflection.macros.universe.basicuniverse import izumi.reflect.macrortti.{LightTypeTag, LightTypeTagImpl} final class MacroSafeType private ( - private[reflection] val tagTree: scala.reflect.api.Universe#Tree, + private[reflection] val tagTree0: scala.reflect.api.Universe#Tree, private val tag: LightTypeTag, ) { @@ -15,6 +15,9 @@ final class MacroSafeType private ( @inline override def toString: String = { tag.repr } + + @inline def tagTree(u: scala.reflect.api.Universe): u.Tree = tagTree0.asInstanceOf[u.Tree] + override def equals(obj: Any): Boolean = { obj match { case that: MacroSafeType => @@ -26,12 +29,12 @@ final class MacroSafeType private ( } object MacroSafeType { - def create(u: scala.reflect.api.Universe)(tpe: scala.reflect.api.Universe#Type): MacroSafeType = { + def create(u: scala.reflect.api.Universe)(tpe: u.Type): MacroSafeType = { import u.* val modelReflectionPkg = q"_root_.izumi.distage.model.reflection" - val ltt = LightTypeTagImpl.makeLightTypeTag(u)(tpe.asInstanceOf[u.Type]) - val tagTree = q"{ $modelReflectionPkg.SafeType.get[${u.Liftable.liftType(tpe.asInstanceOf[u.Type])}] }" + val ltt = LightTypeTagImpl.makeLightTypeTag(u)(tpe) + val tagTree = q"{ $modelReflectionPkg.SafeType.get[${u.Liftable.liftType(tpe)}] }" new MacroSafeType(tagTree, ltt) } diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala index f8de33ad6e..764128016d 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompact.scala @@ -10,6 +10,7 @@ trait MacroSymbolInfoCompact { def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact def safeFinalResultType: MacroSafeType def finalResultType: scala.reflect.api.Universe#Type + @inline final def finalResultTypeIn(u: scala.reflect.api.Universe): u.Type = finalResultType.asInstanceOf[u.Type] } object MacroSymbolInfoCompact { @@ -24,5 +25,3 @@ object MacroSymbolInfoCompact { } } } - - diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala index 3b928f436c..6dd754b3c7 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/MacroSymbolInfoCompactImpl.scala @@ -2,7 +2,7 @@ package izumi.distage.reflection.macros.universe.basicuniverse import izumi.fundamentals.reflection.{AnnotationTools, ReflectionUtil} -case class MacroSymbolInfoCompactImpl( +final case class MacroSymbolInfoCompactImpl( name: String, finalResultType: scala.reflect.api.Universe#Type, friendlyAnnotations: List[FriendlyAnnotation], @@ -10,7 +10,7 @@ case class MacroSymbolInfoCompactImpl( wasGeneric: Boolean, safeFinalResultType: MacroSafeType, ) extends MacroSymbolInfoCompact { - override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) + override def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) } object MacroSymbolInfoCompactImpl { From b44fe4c2ac2c8a968407e3e6257783f4ea24e54d Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:49:10 +0200 Subject: [PATCH 53/59] Cleanup and remove unused code --- .../constructors/ClassConstructorMacro.scala | 2 +- .../FactoryConstructorMacro.scala | 2 +- .../constructors/HasConstructorMacro.scala | 2 +- .../constructors/TraitConstructorMacro.scala | 2 +- .../macros/universe/DIUniverseLiftables.scala | 2 +- .../macros/universe/ReflectionProvider.scala | 4 +- .../ReflectionProviderDefaultImpl.scala | 8 ++-- .../macros/universe/StaticDIUniverse.scala | 9 +---- .../macros/universe/impl/DIUniverseBase.scala | 5 --- .../universe/impl/WithDIAssociation.scala | 13 ++++--- .../universe/impl/WithDISymbolInfo.scala | 39 +++++++++---------- .../macros/universe/impl/WithDIWiring.scala | 4 +- .../macros/FunctoidMacroMethods.scala | 2 +- .../BaseReflectionProvider.scala | 2 +- .../basicuniverse/CompactParameter.scala | 4 +- .../basicuniverse/ConstructorSelector.scala | 2 +- .../DIUniverseBasicLiftables.scala | 4 +- .../basicuniverse/FriendlyAnnoTools.scala | 16 +++----- 18 files changed, 53 insertions(+), 69 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala index dc26146733..499392dcce 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/ClassConstructorMacro.scala @@ -13,7 +13,7 @@ object ClassConstructorMacro { def mkClassConstructor[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[ClassConstructor[T]] = { import c.universe.* - val macroUniverse = StaticDIUniverse(c) + val macroUniverse = StaticDIUniverse(c.universe) val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) val targetType = ReflectionUtil.norm(c.universe: c.universe.type)(weakTypeOf[T].dealias) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala index 6d1e8298d1..ba062cacf1 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/FactoryConstructorMacro.scala @@ -13,7 +13,7 @@ object FactoryConstructorMacro { def mkFactoryConstructor[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[FactoryConstructor[T]] = { import c.universe.* - val macroUniverse = StaticDIUniverse(c) + val macroUniverse = StaticDIUniverse(c.universe) val reflectionProvider = ReflectionProviderDefaultImpl(macroUniverse) val logger = TrivialMacroLogger.make[this.type](c, DebugProperties.`izumi.debug.macro.distage.constructors`.name) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala index f741f232fc..7b66ae7ba5 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/HasConstructorMacro.scala @@ -12,7 +12,7 @@ import scala.reflect.macros.blackbox object ZEnvConstructorMacro { def mkZEnvConstructor[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[ZEnvConstructor[T]] = { - val macroUniverse = StaticDIUniverse(c) + val macroUniverse = StaticDIUniverse(c.universe) val impls = ZEnvConstructorMacros(c)(macroUniverse) import c.universe.* import impls.{c as _, u as _, *} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala index 08d613b590..198be7929c 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/constructors/TraitConstructorMacro.scala @@ -10,7 +10,7 @@ import scala.reflect.macros.blackbox object TraitConstructorMacro { def mkTraitConstructor[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[TraitConstructor[T]] = { - val macroUniverse = StaticDIUniverse(c) + val macroUniverse = StaticDIUniverse(c.universe) val impls = TraitConstructorMacros(c)(macroUniverse) import c.universe.* import impls.{c as _, u as _, *} diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala index 5635d066b8..e11ce079aa 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/DIUniverseLiftables.scala @@ -10,7 +10,7 @@ class DIUniverseLiftables[D <: StaticDIUniverse](val u: D) { import u.u.* implicit val liftableParameter: Liftable[Association.Parameter] = { - case Association.Parameter(info, _, key) => + case Association.Parameter(info, key) => val resultTree = q"{ $modelReflectionPkg.SafeType.get[${Liftable.liftType(info.nonByNameFinalResultType)}] }" // val keyTree = liftableBasicDIKey.apply(key).asInstanceOf[Tree] // currently only function parameter symbols are spliced by this diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala index 28b2aeb9b6..7645f62ffc 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProvider.scala @@ -6,7 +6,7 @@ trait ReflectionProvider { val u: DIUniverse import u.* - def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter + protected def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter def constructorParameterLists(tpe: TypeNative): List[List[Association.Parameter]] def symbolToAnyWiring(tpe: TypeNative): MacroWiring @@ -17,7 +17,7 @@ trait ReflectionProvider { def isWireableAbstract(tpe: TypeNative): Boolean def isFactory(tpe: TypeNative): Boolean - def selectConstructorMethod(tpe: TypeNative): Option[MethodSymbNative] + protected def selectConstructorMethod(tpe: TypeNative): Option[MethodSymbNative] } object ReflectionProvider { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index 0778df69dd..6cbf03d1ab 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -21,7 +21,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { import u.u.Annotation private lazy val idAnnotationFqn = DIAnnotationMeta.idAnnotationFqn(u.u) - private lazy val brp = new BaseReflectionProvider(u.ctx.universe, idAnnotationFqn) + private lazy val brp = new BaseReflectionProvider(u.u, idAnnotationFqn) private object With { def unapply(ann: Annotation): Option[TypeNative] = { @@ -117,7 +117,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { override def parameterToAssociation(parameterSymbol: MacroSymbolInfo): Association.Parameter = { val key = brp.keyFromSymbol(parameterSymbol) - Association.Parameter(parameterSymbol, brp.tpeFromSymbol(parameterSymbol), key) + Association.Parameter(parameterSymbol, key) } override def zioHasParameters(transformName: String => String)(deepIntersection: List[u.TypeNative]): List[u.Association.Parameter] = { @@ -125,7 +125,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { hasTpe => val tpe = hasTpe.dealias val syntheticSymbolInfo = MacroSymbolInfo.Static.syntheticFromType(transformName)(tpe) - Association.Parameter(syntheticSymbolInfo, brp.tpeFromSymbol(syntheticSymbolInfo), brp.keyFromSymbol(syntheticSymbolInfo)) + Association.Parameter(syntheticSymbolInfo, brp.keyFromSymbol(syntheticSymbolInfo)) } } @@ -155,7 +155,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { private def methodToAssociation(definingClass: TypeNative, method: MethodSymbNative): Association.AbstractMethod = { val methodSymb = MacroSymbolInfo.Runtime(method, definingClass, wasGeneric = false) - Association.AbstractMethod(methodSymb, brp.tpeFromSymbol(methodSymb), brp.keyFromSymbol(methodSymb)) + Association.AbstractMethod(methodSymb, brp.keyFromSymbol(methodSymb)) } private object ConcreteSymbol { diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala index c17bd3f763..2af6e40ca4 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/StaticDIUniverse.scala @@ -4,21 +4,16 @@ import izumi.distage.model.definition.DIStageAnnotation import izumi.distage.reflection.macros.universe.impl.DIUniverse import izumi.fundamentals.reflection.SingletonUniverse -import scala.reflect.macros.blackbox - trait StaticDIUniverse extends DIUniverse { self => override val u: SingletonUniverse } object StaticDIUniverse { type Aux[U] = StaticDIUniverse { val u: U } - def apply(c: blackbox.Context): StaticDIUniverse.Aux[c.universe.type] = { + def apply(universe: scala.reflect.api.Universe): StaticDIUniverse.Aux[universe.type] = { new StaticDIUniverse { self => - override val ctx: blackbox.Context = c - override val u: c.universe.type = c.universe + override val u: universe.type = universe override protected val typeOfDistageAnnotation: TypeNative = u.typeOf[DIStageAnnotation] - - override val rp: ReflectionProvider = ReflectionProviderDefaultImpl.apply(this) } } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala index 6f7d370115..84aca7d891 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/DIUniverseBase.scala @@ -1,14 +1,9 @@ package izumi.distage.reflection.macros.universe.impl -import izumi.distage.reflection.macros.universe.ReflectionProvider - import scala.reflect.api.Universe -import scala.reflect.macros.blackbox trait DIUniverseBase { - val ctx: blackbox.Context val u: Universe - val rp: ReflectionProvider type TypeNative = u.Type type SymbNative = u.Symbol diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala index 3ae048f2c3..f48aef4948 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIAssociation.scala @@ -1,13 +1,14 @@ package izumi.distage.reflection.macros.universe.impl -import izumi.distage.reflection.macros.universe.basicuniverse.{MacroDIKey, MacroSafeType} +import izumi.distage.reflection.macros.universe.basicuniverse.MacroDIKey import scala.reflect.macros.blackbox private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISymbolInfo => sealed trait Association { - def symbol: MacroSymbolInfo + protected def symbol: MacroSymbolInfo + def key: MacroDIKey.BasicKey final def name: String = symbol.name @@ -22,7 +23,7 @@ private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISymbo final def nonBynameTpe: TypeNative = symbol.nonByNameFinalResultType /** always by-name for methods, - may be by-name for parameters */ - def asParameterTpe: TypeNative + protected def asParameterTpe: TypeNative final def ctorArgumentExpr(c: blackbox.Context): (u.Tree, u.Tree) = { import u.* @@ -37,16 +38,16 @@ private[distage] trait WithDIAssociation { this: DIUniverseBase with WithDISymbo object Association { - case class Parameter(symbol: MacroSymbolInfo, stpe: MacroSafeType, key: MacroDIKey.BasicKey) extends Association { + case class Parameter(protected val symbol: MacroSymbolInfo, key: MacroDIKey.BasicKey) extends Association { override final def isByName: Boolean = symbol.isByName override final def asParameter: Association.Parameter = this override final def asParameterTpe: TypeNative = tpe } // tpe is never by-name for `AbstractMethod` - case class AbstractMethod(symbol: MacroSymbolInfo, stpe: MacroSafeType, key: MacroDIKey.BasicKey) extends Association { + case class AbstractMethod(protected val symbol: MacroSymbolInfo, key: MacroDIKey.BasicKey) extends Association { override final def isByName: Boolean = true - override final def asParameter: Parameter = Parameter(symbol.withIsByName(true).withTpe(asParameterTpe), stpe, key) + override final def asParameter: Parameter = Parameter(symbol.withIsByName(true).withTpe(asParameterTpe), key) override final def asParameterTpe: TypeNative = u.appliedType(u.definitions.ByNameParamClass, tpe) // force by-name } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala index c636f6328c..33a874c0ad 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDISymbolInfo.scala @@ -16,12 +16,12 @@ trait WithDISymbolInfo { this: DIUniverseBase => def isByName: Boolean def wasGeneric: Boolean - def annotations: List[u.Annotation] + protected def annotations: List[u.Annotation] def friendlyAnnotations: List[FriendlyAnnotation] def withTpe(tpe: TypeNative): MacroSymbolInfo def withIsByName(boolean: Boolean): MacroSymbolInfo - def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo +// def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo } protected def typeOfDistageAnnotation: TypeNative @@ -37,13 +37,13 @@ trait WithDISymbolInfo { this: DIUniverseBase => finalResultType: TypeNative, isByName: Boolean, wasGeneric: Boolean, - annotations: List[u.Annotation], + protected val annotations: List[u.Annotation], friendlyAnnotations: List[FriendlyAnnotation], ) extends MacroSymbolInfo { override final val name: String = underlying.name.toTermName.toString override final def withTpe(tpe: TypeNative): MacroSymbolInfo = copy(finalResultType = tpe) override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) - override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) +// override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(u)(nonByNameFinalResultType) } @@ -70,31 +70,31 @@ trait WithDISymbolInfo { this: DIUniverseBase => ) } - def apply(underlying: SymbNative): Runtime = { - val annos = AnnotationTools.getAllAnnotations(u: u.type)(underlying).distinct - new Runtime( - underlying = underlying, - typeSignatureInDefiningClass = underlying.typeSignature, - finalResultType = underlying.typeSignature, - isByName = (underlying.isTerm && underlying.asTerm.isByNameParam) || ReflectionUtil.isByName(u)(underlying.typeSignature), - wasGeneric = underlying.typeSignature.typeSymbol.isParameter, - annotations = annos, - friendlyAnnotations = annos.map(FriendlyAnnoTools.makeFriendly(u)), - ) - } +// def apply(underlying: SymbNative): Runtime = { +// val annos = AnnotationTools.getAllAnnotations(u: u.type)(underlying).distinct +// new Runtime( +// underlying = underlying, +// typeSignatureInDefiningClass = underlying.typeSignature, +// finalResultType = underlying.typeSignature, +// isByName = (underlying.isTerm && underlying.asTerm.isByNameParam) || ReflectionUtil.isByName(u)(underlying.typeSignature), +// wasGeneric = underlying.typeSignature.typeSymbol.isParameter, +// annotations = annos, +// friendlyAnnotations = annos.map(FriendlyAnnoTools.makeFriendly(u)), +// ) +// } } case class Static( name: String, finalResultType: TypeNative, - annotations: List[u.Annotation], + protected val annotations: List[u.Annotation], friendlyAnnotations: List[FriendlyAnnotation], isByName: Boolean, wasGeneric: Boolean, ) extends MacroSymbolInfo { override final def withTpe(tpe: TypeNative): MacroSymbolInfo = copy(finalResultType = tpe) override final def withIsByName(boolean: Boolean): MacroSymbolInfo = copy(isByName = boolean) - override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) +// override final def withAnnotations(annotations: List[u.Annotation]): MacroSymbolInfo = copy(annotations = annotations) override final def withFriendlyAnnotations(annotations: List[FriendlyAnnotation]): MacroSymbolInfoCompact = copy(friendlyAnnotations = annotations) override final def safeFinalResultType: MacroSafeType = MacroSafeType.create(u)(nonByNameFinalResultType) } @@ -125,8 +125,7 @@ trait WithDISymbolInfo { this: DIUniverseBase => } private def findAnnotation(tgtAnnType: TypeNative): Option[u.Annotation] = { - val r = symbolInfo.annotations.find(a => AnnotationTools.annotationTypeEq(u)(tgtAnnType, a)) - r + symbolInfo.annotations.find(a => AnnotationTools.annotationTypeEq(u)(tgtAnnType, a)) } } diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala index 407c938dee..3430ae3f65 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/impl/WithDIWiring.scala @@ -9,9 +9,9 @@ trait WithDIWiring { this: DIUniverseBase with WithDIAssociation with WithDISymb sealed trait MacroWiring object MacroWiring { sealed trait MacroSingletonWiring extends MacroWiring { - def prefix: Option[MacroDIKey] + protected def prefix: Option[MacroDIKey] def instanceType: TypeNative - def associations: Seq[Association] + protected[WithDIWiring] def associations: Seq[Association] def requiredKeys: Set[MacroDIKey] = associations.map(_.key).toSet ++ prefix.toSet } object MacroSingletonWiring { diff --git a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala index e18434afb6..6ec705e2d0 100644 --- a/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala +++ b/distage/distage-core-api/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroMethods.scala @@ -7,7 +7,7 @@ import izumi.distage.model.reflection.Provider.{ProviderImpl, ProviderType} import scala.language.implicitConversions import scala.quoted.{Expr, Quotes, Type} -trait FunctoidMacroMethods extends FunctoidMacroMethodsBase {} +trait FunctoidMacroMethods extends FunctoidMacroMethodsBase object FunctoidMacro extends FunctoidMacroBase[Functoid] { transparent inline def make[R](inline fun: AnyRef): Functoid[R] = ${ makeImpl[R]('fun) } diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala index eb1d699a4e..e76f87404a 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/BaseReflectionProvider.scala @@ -14,7 +14,7 @@ class BaseReflectionProvider[U <: scala.reflect.api.Universe & Singleton](val u: private def parameterToAssociation2(parameterSymbol: MacroSymbolInfoCompact): CompactParameter = { val key = keyFromSymbol(parameterSymbol) - basicuniverse.CompactParameter(parameterSymbol, tpeFromSymbol(parameterSymbol), key) + basicuniverse.CompactParameter(parameterSymbol, key) } def tpeFromSymbol(parameterSymbol: MacroSymbolInfoCompact): MacroSafeType = { diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala index 3c33b19b59..ef5ea9ca8f 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/CompactParameter.scala @@ -1,5 +1,5 @@ package izumi.distage.reflection.macros.universe.basicuniverse -case class CompactParameter(symbol: MacroSymbolInfoCompact, stpe: MacroSafeType, key: MacroDIKey.BasicKey) { - final def isByName: Boolean = symbol.isByName +final case class CompactParameter(symbol: MacroSymbolInfoCompact, key: MacroDIKey.BasicKey) { + def isByName: Boolean = symbol.isByName } diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala index ae0f048820..25ac6e8a00 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/ConstructorSelector.scala @@ -1,6 +1,6 @@ package izumi.distage.reflection.macros.universe.basicuniverse -class ConstructorSelector[U <: scala.reflect.api.Universe & Singleton](val u: U) { +final class ConstructorSelector[U <: scala.reflect.api.Universe & Singleton](val u: U) { def selectConstructorMethod(tpe: u.Type): Option[u.MethodSymbol] = { val constructor = findConstructor(tpe) if (!constructor.isTerm) { diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala index c60a93f6ea..7a2a9bfa92 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/DIUniverseBasicLiftables.scala @@ -1,6 +1,6 @@ package izumi.distage.reflection.macros.universe.basicuniverse -class DIUniverseBasicLiftables[U <: scala.reflect.api.Universe & Singleton](val u: U) { +final class DIUniverseBasicLiftables[U <: scala.reflect.api.Universe & Singleton](val u: U) { import u.* val modelReflectionPkg: Tree = q"_root_.izumi.distage.model.reflection" @@ -11,7 +11,7 @@ class DIUniverseBasicLiftables[U <: scala.reflect.api.Universe & Singleton](val } implicit val liftableCompactParameter: Liftable[CompactParameter] = { - case CompactParameter(info, _, key) => + case CompactParameter(info, key) => val symTree = q"""{ $modelReflectionPkg.SymbolInfo( name = ${info.name}, finalResultType = ${info.safeFinalResultType}, diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala index 2efde6fe7f..4cb742be74 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala @@ -4,8 +4,6 @@ import izumi.distage.reflection.macros.universe.basicuniverse import scala.collection.immutable - - object FriendlyAnnoTools { private def convertConst(c: Any): FriendlyAnnotationValue = { c match { @@ -30,14 +28,10 @@ object FriendlyAnnoTools { val avals = if (tpe.typeSymbol.isJavaAnnotation) { val pairs: immutable.List[(Option[String], FriendlyAnnotationValue)] = paramTrees.map { - p => - (p.asInstanceOf[extractor.u.TreeApi]: @unchecked) match { - case extractor.NArg((name, c)) => - // case NamedArg(Ident(TermName(name)), Literal(Constant(c))) => - (Some(name), convertConst(c)) - case a => - (None, FriendlyAnnotationValue.UnknownConst(s"$a ${u.showRaw(a)}")) - } + case extractor.NArg((name, c)) => + (Some(name), convertConst(c)) + case a => + (None, FriendlyAnnotationValue.UnknownConst(s"$a ${u.showRaw(a)}")) } val names = pairs.map(_._1).collect { case Some(name) => name } @@ -56,7 +50,7 @@ object FriendlyAnnoTools { } val rp = new ConstructorSelector(u) - val constructor = rp.selectConstructorMethod(tpe.asInstanceOf[rp.u.Type]) + val constructor = rp.selectConstructorMethod(tpe) constructor match { case Some(c) => c.paramLists match { From d5d297ce2a97855128366a2546402181d5fc2a27 Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:49:40 +0200 Subject: [PATCH 54/59] Don't duplicate -Yretain-trees --- build.sbt | 27 --------------------------- project/Deps.sc | 3 +-- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/build.sbt b/build.sbt index 5cf3adb1ed..873450f9ff 100644 --- a/build.sbt +++ b/build.sbt @@ -152,7 +152,6 @@ lazy val `fundamentals-functional` = project.in(file("fundamentals/fundamentals- "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -363,7 +362,6 @@ lazy val `fundamentals-collections` = project.in(file("fundamentals/fundamentals "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -572,7 +570,6 @@ lazy val `fundamentals-literals` = project.in(file("fundamentals/fundamentals-li "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -785,7 +782,6 @@ lazy val `fundamentals-orphans` = project.in(file("fundamentals/fundamentals-orp "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -1009,7 +1005,6 @@ lazy val `fundamentals-language` = project.in(file("fundamentals/fundamentals-la "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -1224,7 +1219,6 @@ lazy val `fundamentals-platform` = project.in(file("fundamentals/fundamentals-pl "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -1439,7 +1433,6 @@ lazy val `fundamentals-functoid` = project.in(file("fundamentals/fundamentals-fu "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -1664,7 +1657,6 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals- "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -1891,7 +1883,6 @@ lazy val `fundamentals-bio` = project.in(file("fundamentals/fundamentals-bio")) "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -2118,7 +2109,6 @@ lazy val `distage-core-api` = project.in(file("distage/distage-core-api")) "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -2330,7 +2320,6 @@ lazy val `distage-core-proxy-bytebuddy` = project.in(file("distage/distage-core- "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -2542,7 +2531,6 @@ lazy val `distage-framework-api` = project.in(file("distage/distage-framework-ap "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -2761,7 +2749,6 @@ lazy val `distage-core` = project.in(file("distage/distage-core")) "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -2977,7 +2964,6 @@ lazy val `distage-extension-config` = project.in(file("distage/distage-extension "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -3192,7 +3178,6 @@ lazy val `distage-extension-logstage` = project.in(file("distage/distage-extensi "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -3412,7 +3397,6 @@ lazy val `distage-extension-plugins` = project.in(file("distage/distage-extensio "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -3644,7 +3628,6 @@ lazy val `distage-framework` = project.in(file("distage/distage-framework")) "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -3865,7 +3848,6 @@ lazy val `distage-framework-docker` = project.in(file("distage/distage-framework "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -4076,7 +4058,6 @@ lazy val `distage-testkit-core` = project.in(file("distage/distage-testkit-core" "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -4296,7 +4277,6 @@ lazy val `distage-testkit-scalatest` = project.in(file("distage/distage-testkit- "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -4508,7 +4488,6 @@ lazy val `distage-testkit-scalatest-sbt-module-filtering-test` = project.in(file "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -4726,7 +4705,6 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core")) "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -4943,7 +4921,6 @@ lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-renderi "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -5155,7 +5132,6 @@ lazy val `logstage-adapter-slf4j` = project.in(file("logstage/logstage-adapter-s "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -5371,7 +5347,6 @@ lazy val `logstage-sink-slf4j` = project.in(file("logstage/logstage-sink-slf4j") "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -5614,7 +5589,6 @@ lazy val `microsite` = project.in(file("doc/microsite")) "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", @@ -5886,7 +5860,6 @@ lazy val `sbt-izumi-deps` = project.in(file("sbt-plugins/sbt-izumi-deps")) "-Wunused:-synthetics" ) case (_, "3.4.1") => Seq( - "-Yretain-trees", "-language:3.4", "-release:8", "-Ykind-projector:underscores", diff --git a/project/Deps.sc b/project/Deps.sc index 8a1475aa29..f854561f92 100644 --- a/project/Deps.sc +++ b/project/Deps.sc @@ -312,8 +312,7 @@ object Izumi { (Seq[Const]("-Wconf:any:error") ++ Defaults.Scala213Options ++ Seq[Const]("-Wunused:-synthetics")).filterNot(_ == ("-Xsource:3-cross": Const)), SettingKey(Some(scala300), None) := Seq[Const]( - "-Yretain-trees", // FIXME required - "-language:3.4", + "-language:3.4" ) ++ Defaults.Scala3Options, SettingKey.Default := Const.EmptySeq, ), From 5cac779012f2292daa058366ecd3c8073d8b17be Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:49:59 +0200 Subject: [PATCH 55/59] fix PortableNamedArg non-exhaustive match --- .../macros/universe/basicuniverse/PortableNamedArg.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala b/fundamentals/fundamentals-functoid/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala index ed9ace882c..22f82efd0b 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2.13/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala @@ -1,12 +1,14 @@ package izumi.distage.reflection.macros.universe.basicuniverse -class PortableNamedArg(val u: scala.reflect.api.Universe) { +class PortableNamedArg[U <: scala.reflect.api.Universe & Singleton](val u: U) { import u.* object NArg { def unapply(tree: TreeApi): Option[(String, Any)] = { (tree: @unchecked) match { case NamedArg(Ident(TermName(name)), Literal(Constant(c))) => Some((name, c)) + case _ => + None } } } From a4c713238fc6e2988c859e6f146911fbda94a545 Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:50:36 +0200 Subject: [PATCH 56/59] revert change to lambda tpes - switch to lambda arg key type (exchange key types, not other types) --- .../distage/reflection/macros/universe/FunctoidMacroBase.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala index 2340c071d8..940dd62064 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala @@ -164,7 +164,7 @@ abstract class FunctoidMacroBase[Ftoid[_]](val c: blackbox.Context) { case (mArg, lArg) => mArg.copy( symbol = lArg.symbol.withFriendlyAnnotations(mArg.symbol.friendlyAnnotations), - key = mArg.key.withTpe(lArg.stpe), + key = mArg.key.withTpe(lArg.key.tpe), ) } } else { From a064989577eb7a27c298c7ea0b8016386d7f7842 Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:13:29 +0200 Subject: [PATCH 57/59] fix merge error --- .../izumi/distage/framework/PlanCheck.scala | 31 +++---------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/PlanCheck.scala b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/PlanCheck.scala index 3fb050ea0c..0ec732eb12 100644 --- a/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/PlanCheck.scala +++ b/distage/distage-framework/.jvm/src/main/scala/izumi/distage/framework/PlanCheck.scala @@ -299,12 +299,6 @@ object PlanCheck { } } - private def parseActivations(s: String): Set[NESet[AxisPoint]] = { - s.split("\\|").iterator.filter(_.nonEmpty).flatMap { - NESet `from` _.split(" ").iterator.filter(_.nonEmpty).map(AxisPoint.parseAxisPoint).toSet - }.toSet - } - private def defaultLogger(): TrivialLogger = { TrivialLogger.make[this.type](DebugProperties.`izumi.debug.macro.distage.plancheck`.name) } @@ -361,27 +355,12 @@ object PlanCheck { ) } - private def parseActivations(s: String): Set[NESet[AxisPoint]] = { - s.split("\\|").iterator.filter(_.nonEmpty).flatMap { - NESet `from` _.split(" ").iterator.filter(_.nonEmpty).map(AxisPoint.parseAxisPoint).toSet - }.toSet - } - - private def defaultLogger(): TrivialLogger = { - TrivialLogger.make[this.type](DebugProperties.`izumi.debug.macro.distage.plancheck`.name) - } - - @tailrec private def cutoffMacroTrace(t: Throwable): Unit = { - val trace = t.getStackTrace - val cutoffIdx = Some(trace.indexWhere(_.getClassName contains "scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers")).filter(_ > 0) - t.setStackTrace(cutoffIdx.fold(trace)(trace.take)) - val suppressed = t.getSuppressed - suppressed.foreach(cutSuppressed) - if (t.getCause ne null) cutoffMacroTrace(t.getCause) - } - // indirection for tailrec - private def cutSuppressed(t: Throwable): Unit = cutoffMacroTrace(t) + } + private def parseActivations(s: String): Set[NESet[AxisPoint]] = { + s.split("\\|").iterator.filter(_.nonEmpty).flatMap { + NESet `from` _.split(" ").iterator.filter(_.nonEmpty).map(AxisPoint.parseAxisPoint).toSet + }.toSet } } From 5c39ae9167f826530bd1edbebd071f0e123cd900 Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:31:37 +0200 Subject: [PATCH 58/59] Intellij highlighting and naming fix --- .../distage/reflection/macros/FunctoidMacroBase.scala | 2 +- .../izumi/distage/model/providers/AbstractFunctoid.scala | 7 +++---- .../distage/model/providers/SimpleFunctoidSyntax.scala | 4 ++-- .../scala/izumi/distage/model/reflection/SafeType.scala | 6 +++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala b/fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala index d5cd517522..7cc4ad44e9 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-3/izumi/distage/reflection/macros/FunctoidMacroBase.scala @@ -8,7 +8,7 @@ import scala.collection.immutable.{List, Seq} import scala.language.implicitConversions import scala.quoted.{Expr, Quotes, Type} -trait FunctoidMacroBase[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { +trait FunctoidMacroBase[Ftoid[+X] <: AbstractFunctoid[X, Ftoid]] { protected def generateFunctoid[R: Type, Q <: Quotes](paramDefs: List[Expr[LinkedParameter]], originalFun: Expr[AnyRef])(using qctx: Q): Expr[Ftoid[R]] protected final def generateRawFnCall[Q <: Quotes](argsCount: Int, rawFn: Expr[Any], args: Expr[Seq[Any]])(using qctx: Q): Expr[Any] = { diff --git a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala index c4b93d7294..43aafb6f6a 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/AbstractFunctoid.scala @@ -6,9 +6,8 @@ import izumi.fundamentals.platform.language.Quirks.Discarder import izumi.reflect.Tag import scala.annotation.unchecked.uncheckedVariance -import scala.annotation.unused -trait AbstractFunctoid[+A, Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { +trait AbstractFunctoid[+A, Ftoid[+X] <: AbstractFunctoid[X, Ftoid]] { def get: Provider @@ -52,8 +51,8 @@ trait AbstractFunctoid[+A, Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { * this.map2(that)((f, a) => f(a)) * }}} */ - def ap[B, C](that: Ftoid[B])(implicit @unused ev: A <:< (B => C), tag: Tag[C]): Ftoid[C] = { - map2(that)((f, a) => f.asInstanceOf[B => C](a)) + def ap[B, C](that: Ftoid[B])(implicit ev: A <:< (B => C), tag: Tag[C]): Ftoid[C] = { + map2[B, C](that)((f, a) => ev(f)(a))(using tag) } /** Add `B` as an unused dependency of this Functoid */ diff --git a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala index 5e2624a809..be1097e865 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/providers/SimpleFunctoidSyntax.scala @@ -2,12 +2,12 @@ package izumi.distage.model.providers import scala.language.implicitConversions -trait SimpleFunctoidSyntax[Ftoid[+K] <: AbstractFunctoid[K, Ftoid]] { +trait SimpleFunctoidSyntax[Ftoid[+X] <: AbstractFunctoid[X, Ftoid]] { implicit final def syntaxMapSame[A](functoid: Ftoid[A]): SimpleFunctoidSyntax.SyntaxMapSame[A, Ftoid] = new SimpleFunctoidSyntax.SyntaxMapSame[A, Ftoid](functoid) } object SimpleFunctoidSyntax { - final class SyntaxMapSame[A, Ftoid[+K] <: AbstractFunctoid[K, Ftoid]](private val functoid: Ftoid[A]) extends AnyVal { + final class SyntaxMapSame[A, Ftoid[+X] <: AbstractFunctoid[X, Ftoid]](private val functoid: Ftoid[A]) extends AnyVal { def mapSame(f: A => A): Ftoid[A] = functoid.map(f)(functoid.returnTypeTag) } } diff --git a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/SafeType.scala b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/SafeType.scala index cfc4d6148a..81cc581e3b 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/SafeType.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala/izumi/distage/model/reflection/SafeType.scala @@ -36,9 +36,9 @@ final class SafeType(private[distage] val anyTag: AnyTag) { } trait SafeTypeTools { - def get[T: Tag]: SafeType = new SafeType(Tag[T]) - def getK[K[_]: TagK]: SafeType = new SafeType(TagK[K]) - def unsafeGetWeak[T](implicit weakTag: WeakTag[T]): SafeType = new SafeType(WeakTag[T]) + final def get[T: Tag]: SafeType = new SafeType(Tag[T]) + final def getK[K[_]: TagK]: SafeType = new SafeType(TagK[K]) + final def unsafeGetWeak[T](implicit weakTag: WeakTag[T]): SafeType = new SafeType(WeakTag[T]) } object SafeType extends SafeTypeTools { From 7dd03aaf67606ef07d03470e2517c1eb2a2ed2a0 Mon Sep 17 00:00:00 2001 From: Kai <450507+neko-kai@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:41:39 +0200 Subject: [PATCH 59/59] fix 2.12 build --- .../macros/universe/ReflectionProviderDefaultImpl.scala | 4 ++-- .../macros/universe/basicuniverse/PortableNamedArg.scala | 4 +++- .../reflection/macros/universe/FunctoidMacroBase.scala | 2 +- .../macros/universe/basicuniverse/FriendlyAnnoTools.scala | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala index 6cbf03d1ab..f0822c850d 100644 --- a/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala +++ b/distage/distage-core-api/src/main/scala-2/izumi/distage/reflection/macros/universe/ReflectionProviderDefaultImpl.scala @@ -21,7 +21,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { import u.u.Annotation private lazy val idAnnotationFqn = DIAnnotationMeta.idAnnotationFqn(u.u) - private lazy val brp = new BaseReflectionProvider(u.u, idAnnotationFqn) + private lazy val brp = new BaseReflectionProvider[u.u.type](u.u, idAnnotationFqn) private object With { def unapply(ann: Annotation): Option[TypeNative] = { @@ -196,7 +196,7 @@ trait ReflectionProviderDefaultImpl extends ReflectionProvider { } def selectConstructorMethod(tpe: TypeNative): Option[MethodSymbNative] = { - val cs = new ConstructorSelector(u.u) + val cs = new ConstructorSelector[u.u.type](u.u) cs.selectConstructorMethod(tpe).map(s => s.asInstanceOf[MethodSymbNative]) } diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala b/fundamentals/fundamentals-functoid/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala index df141124ce..b49b26b0db 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2.12/izumi/distage/reflection/macros/universe/basicuniverse/PortableNamedArg.scala @@ -1,12 +1,14 @@ package izumi.distage.reflection.macros.universe.basicuniverse -class PortableNamedArg(val u: scala.reflect.api.Universe) { +class PortableNamedArg[U <: scala.reflect.api.Universe & Singleton](val u: U) { import u.* object NArg { def unapply(tree: TreeApi): Option[(String, Any)] = { (tree: @unchecked) match { case AssignOrNamedArg(Ident(TermName(name)), Literal(Constant(c))) => Some((name, c)) + case _ => + None } } } diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala index 940dd62064..198d631c41 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/FunctoidMacroBase.scala @@ -56,7 +56,7 @@ abstract class FunctoidMacroBase[Ftoid[_]](val c: blackbox.Context) { } def generateProvider[R: WeakTypeTag](parameters: List[Parameter], fun: Tree): Tree = { - val tools = new DIUniverseBasicLiftables(c.universe) + val tools = new DIUniverseBasicLiftables[c.universe.type](c.universe) import tools.liftableCompactParameter val seqName = if (parameters.nonEmpty) TermName(c.freshName("seqAny")) else TermName("_") diff --git a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala index 4cb742be74..e58a37d4cd 100644 --- a/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala +++ b/fundamentals/fundamentals-functoid/src/main/scala-2/izumi/distage/reflection/macros/universe/basicuniverse/FriendlyAnnoTools.scala @@ -20,7 +20,7 @@ object FriendlyAnnoTools { def makeFriendly(u: scala.reflect.api.Universe)(anno: u.Annotation): FriendlyAnnotation = { import u.* - val extractor = new PortableNamedArg(u) + val extractor = new PortableNamedArg[u.type](u) val tpe = anno.tree.tpe.finalResultType val annoName = tpe.typeSymbol.fullName @@ -49,7 +49,7 @@ object FriendlyAnnoTools { } } - val rp = new ConstructorSelector(u) + val rp = new ConstructorSelector[u.type](u) val constructor = rp.selectConstructorMethod(tpe) constructor match { case Some(c) =>