Repository: 7mind/izumi
Pull request #833 (2020-01-16 21:21:17)

Rename `aliasTo` to `aliased`


Patch:
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 ac6b32dde..6945348ac 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
@@ -102,11 +102,11 @@ object LocatorDef {
     protected[this] def mutableState: SingletonRef
     protected[this] def key: DIKey
 
-    def aliasTo[T1 >: T: Tag](implicit pos: CodePositionMaterializer): BindDSLAfterFrom[T] = {
+    def aliased[T1 >: T: Tag](implicit pos: CodePositionMaterializer): BindDSLAfterFrom[T] = {
       addOp(AliasTo(DIKey.get[T1], pos.get.position))(new BindDSLAfterFrom[T](_, key))
     }
 
-    def aliasTo[T1 >: T: Tag](name: String)(implicit pos: CodePositionMaterializer): BindDSLAfterFrom[T] = {
+    def aliased[T1 >: T: Tag](name: String)(implicit pos: CodePositionMaterializer): BindDSLAfterFrom[T] = {
       addOp(AliasTo(DIKey.get[T1].named(name), pos.get.position))(new BindDSLAfterFrom[T](_, key))
     }
 
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 217a1a65e..056da94e3 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
@@ -439,7 +439,7 @@ object ModuleDefDSL {
     *
     * Please update this when adding new methods to [[MakeDSL]]!
     */
-  private[distage] final lazy val MakeDSLNoOpMethodsWhitelist = Set("named", "namedByImpl", "tagged", "aliasTo")
+  private[distage] final lazy val MakeDSLNoOpMethodsWhitelist = Set("named", "namedByImpl", "tagged", "aliased")
 
   final class MakeDSL[T]
   (
@@ -497,11 +497,11 @@ object ModuleDefDSL {
     protected[this] def mutableState: SingletonRef
     protected[this] def key: DIKey
 
-    def aliasTo[T1 >: T: Tag](implicit pos: CodePositionMaterializer): MakeDSLAfterFrom[T] = {
+    def aliased[T1 >: T: Tag](implicit pos: CodePositionMaterializer): MakeDSLAfterFrom[T] = {
       addOp(AliasTo(DIKey.get[T1], pos.get.position))(new MakeDSLAfterFrom[T](_, key))
     }
 
-    def aliasTo[T1 >: T: Tag](name: String)(implicit pos: CodePositionMaterializer): MakeDSLAfterFrom[T] = {
+    def aliased[T1 >: T: Tag](name: String)(implicit pos: CodePositionMaterializer): MakeDSLAfterFrom[T] = {
       addOp(AliasTo(DIKey.get[T1].named(name), pos.get.position))(new MakeDSLAfterFrom[T](_, key))
     }
 
diff --git a/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/load/PluginLoader.scala b/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/load/PluginLoader.scala
index 8149d2a2b..0f13cf99a 100644
--- a/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/load/PluginLoader.scala
+++ b/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/load/PluginLoader.scala
@@ -1,7 +1,6 @@
 package izumi.distage.plugins.load
 
-import distage.plugins.PluginConfig
-import izumi.distage.plugins.PluginBase
+import izumi.distage.plugins.{PluginBase, PluginConfig}
 
 trait PluginLoader {
   def load(): Seq[PluginBase]
diff --git a/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/load/PluginLoaderDefaultImpl.scala b/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/load/PluginLoaderDefaultImpl.scala
index 259b24bc5..7f0a710ad 100644
--- a/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/load/PluginLoaderDefaultImpl.scala
+++ b/distage/distage-extension-plugins/src/main/scala/izumi/distage/plugins/load/PluginLoaderDefaultImpl.scala
@@ -42,8 +42,6 @@ class PluginLoaderDefaultImpl
 object PluginLoaderDefaultImpl {
   private lazy val cache = new SyncCache[String, Seq[PluginBase]]()
 
-
-
   def doLoad[T](base: String, whitelistClasses: Seq[String], enabledPackages: Seq[String], disabledPackages: Seq[String], debug: Boolean): Seq[T] = {
     val scanResult = Value(new ClassGraph())
       .map(_.whitelistPackages(enabledPackages: _*))
diff --git a/distage/distage-framework/src/main/scala/izumi/distage/effect/modules/CatsDIEffectModule.scala b/distage/distage-framework/src/main/scala/izumi/distage/effect/modules/CatsDIEffectModule.scala
index ce33e6477..ed28b557c 100644
--- a/distage/distage-framework/src/main/scala/izumi/distage/effect/modules/CatsDIEffectModule.scala
+++ b/distage/distage-framework/src/main/scala/izumi/distage/effect/modules/CatsDIEffectModule.scala
@@ -30,7 +30,7 @@ trait CatsDIEffectModule extends ModuleDef {
   make[Parallel[IO]].from(IO.ioParallel(_: ContextShift[IO]))
   make[ConcurrentEffect[IO]]
     .from(IO.ioConcurrentEffect(_: ContextShift[IO]))
-    .aliasTo[Concurrent[IO]]
+    .aliased[Concurrent[IO]]
 
   make[ContextShift[IO]].from((_: PublicIOApp).contextShift)
   make[Timer[IO]].from((_: PublicIOApp).timer)
diff --git a/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppLauncherImpl.scala b/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppLauncherImpl.scala
index 19fa38092..dee1a4685 100644
--- a/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppLauncherImpl.scala
+++ b/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppLauncherImpl.scala
@@ -129,14 +129,16 @@ abstract class RoleAppLauncherImpl[F[_]: TagK: DIEffect] extends RoleAppLauncher
   }
 
   protected def loadRoles(parameters: RawAppArgs, logger: IzLogger, plugins: AllLoadedPlugins): RolesInfo = {
-    val activeRoleNames = parameters.roles.map(_.role).toSet
-    val roleProvider: RoleProvider[F] = new RoleProvider.Impl(logger, activeRoleNames)
     val bindings = plugins.app.flatMap(_.bindings)
-    val bsBindings = plugins.app.flatMap(_.bindings)
-    logger.info(s"Available ${plugins.app.size -> "app plugins"} with ${bindings.size -> "app bindings"} and ${plugins.bootstrap.size -> "bootstrap plugins"} with ${bsBindings.size -> "bootstrap bindings"} ...")
-    val roles = roleProvider.getInfo(bindings)
+    val bsBindings = plugins.bootstrap.flatMap(_.bindings)
+    logger.info(s"Available ${plugins.app.size -> "app plugins"} with ${bindings.size -> "app bindings"} and ${
+      plugins.bootstrap.size -> "bootstrap plugins"} with ${bsBindings.size -> "bootstrap bindings"} ...")
 
+    val activeRoleNames = parameters.roles.map(_.role).toSet
+    val roleProvider = new RoleProvider.Impl(logger, activeRoleNames)
+    val roles = roleProvider.getInfo(bindings)
     printRoleInfo(logger, roles)
+
     val missing = parameters.roles.map(_.role).toSet.diff(roles.availableRoleBindings.map(_.descriptor.id).toSet)
     if (missing.nonEmpty) {
       logger.crit(s"Missing ${missing.niceList() -> "roles"}")
diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/TagMacro.scala b/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/TagMacro.scala
index 3ca266cce..83abb0ff7 100644
--- a/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/TagMacro.scala
+++ b/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/TagMacro.scala
@@ -98,7 +98,7 @@ class TagMacro(val c: blackbox.Context) {
 
     val res = {
       if (isSimplePartialApplication) {
-        // FIXME: unused in complex tl ???
+        // FIXME: unused in complex type lambda ???
         val argTags = {
           // FIXME: fast-path optimize if typeArg is Strong
           val args = embeddedMaybeNonParamTypeArgs.map(_.map(t => ReflectionUtil.norm(c.universe: c.universe.type)(t.dealias)))
diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/macrortti/LightTypeTag.scala b/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/macrortti/LightTypeTag.scala
index 686a64ed1..74106cf05 100644
--- a/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/macrortti/LightTypeTag.scala
+++ b/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/macrortti/LightTypeTag.scala
@@ -144,7 +144,7 @@ abstract class LightTypeTag
 
   override def hashCode(): Int = hashcode
 
-  private lazy val hashcode: Int = {
+  private[this] lazy val hashcode: Int = {
     ref.hashCode() * 31
   }
 }
@@ -173,15 +173,16 @@ object LightTypeTag {
     LightTypeTag(ref, mergedBasesDB, mergedInheritanceDb)
   }
 
-  def parse[T](refString: String, basesString: String): LightTypeTag = {
+  def parse[T](hashCode: Int, refString: String, basesString: String): LightTypeTag = {
     lazy val shared = {
       subtypeDBsSerializer.unpickle(ByteBuffer.wrap(basesString.getBytes("ISO-8859-1")))
     }
 
-    new ParsedLightTypeTag(refString, () => shared.bases, () => shared.idb)
+    new ParsedLightTypeTag(hashCode, refString, () => shared.bases, () => shared.idb)
   }
 
   final class ParsedLightTypeTag(
+                                  override val hashCode: Int,
                                   private val refString: String,
                                   bases: () => Map[AbstractReference, Set[AbstractReference]],
                                   db: () => Map[NameReference, Set[NameReference]],
diff --git a/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/macrortti/LightTypeTagMacro.scala b/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/macrortti/LightTypeTagMacro.scala
index f6c114646..0fde1a034 100644
--- a/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/macrortti/LightTypeTagMacro.scala
+++ b/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/macrortti/LightTypeTagMacro.scala
@@ -18,16 +18,16 @@ private[reflection] class LightTypeTagMacro0[C <: blackbox.Context](val c: C)(lo
   protected final val impl = new LightTypeTagImpl[c.universe.type](c.universe, withCache = cacheEnabled, logger)
 
   final def makeStrongHKTag[ArgStruct: c.WeakTypeTag]: c.Expr[LTag.StrongHK[ArgStruct]] = {
-    val tpe = weakTypeOf[ArgStruct]
-    if (ReflectionUtil.allPartsStrong(tpe.dealias)) {
-      c.Expr[LTag.StrongHK[ArgStruct]](q"new ${weakTypeOf[LTag.StrongHK[ArgStruct]]}(${makeParsedHKTagLightTypeTagImpl(tpe)})")
+    val tpe = unpackArgStruct(weakTypeOf[ArgStruct])
+    if (ReflectionUtil.allPartsStrong(tpe)) {
+      c.Expr[LTag.StrongHK[ArgStruct]](q"new ${weakTypeOf[LTag.StrongHK[ArgStruct]]}(${makeParsedLightTypeTagImpl(tpe)})")
     } else {
       c.abort(c.enclosingPosition, s"Can't materialize LTag.StrongHKTag[$tpe]: found unresolved type parameters in $tpe")
     }
   }
 
   final def makeWeakHKTag[ArgStruct: c.WeakTypeTag]: c.Expr[LTag.WeakHK[ArgStruct]] = {
-    c.Expr[LTag.WeakHK[ArgStruct]](q"new ${weakTypeOf[LTag.WeakHK[ArgStruct]]}(${makeParsedHKTagLightTypeTagImpl(weakTypeOf[ArgStruct])})")
+    c.Expr[LTag.WeakHK[ArgStruct]](q"new ${weakTypeOf[LTag.WeakHK[ArgStruct]]}(${makeParsedLightTypeTagImpl(unpackArgStruct(weakTypeOf[ArgStruct]))})")
   }
 
   final def makeStrongTag[T: c.WeakTypeTag]: c.Expr[LTag[T]] = {
@@ -49,34 +49,6 @@ private[reflection] class LightTypeTagMacro0[C <: blackbox.Context](val c: C)(lo
     makeParsedLightTypeTagImpl(weakTypeOf[T])
   }
 
-  final def makeParsedHKTagLightTypeTagImpl(argStruct: Type): c.Expr[LightTypeTag] = {
-    def badShapeError(t: TypeApi) = {
-      c.abort(c.enclosingPosition, s"Expected type shape RefinedType `{ type Arg[A] = X[A] }` for summoning `LTag.StrongHK/WeakHK[X]`, but got $t (raw: ${showRaw(t)} ${t.getClass})")
-    }
-
-    argStruct match {
-      case r: RefinedTypeApi =>
-        r.decl(TypeName("Arg")) match {
-          case sym: TypeSymbolApi =>
-            makeParsedLightTypeTagImpl(sym.info.typeConstructor)
-          case _ => badShapeError(r)
-        }
-      case other => badShapeError(other)
-    }
-  }
-
-  @inline final def unpackArgStruct(t: Type): Type = {
-    def badShapeError() = c.abort(c.enclosingPosition, s"Expected type shape RefinedType `{ type Arg[A] = X[A] }` for summoning `LTag.StrongHK/WeakHK[X]`, but got $t (raw: ${showRaw(t)} ${t.getClass})")
-    t match {
-      case r: RefinedTypeApi =>
-        r.decl(TypeName("Arg")) match {
-          case sym: TypeSymbolApi => sym.info.typeConstructor
-          case _ => badShapeError()
-        }
-      case _ => badShapeError()
-    }
-  }
-
   final def makeParsedLightTypeTagImpl(tpe: Type): c.Expr[LightTypeTag] = {
     val res = impl.makeFullTagImpl(tpe)
 
@@ -87,10 +59,28 @@ private[reflection] class LightTypeTagMacro0[C <: blackbox.Context](val c: C)(lo
       new String(bytes, 0, bytes.length, "ISO-8859-1")
     }
 
+    val hashCodeRef = res.hashCode()
     val strRef = serialize(res.ref)(LightTypeTag.lttRefSerializer)
     val strDBs = serialize(SubtypeDBs(res.basesdb, res.idb))(LightTypeTag.subtypeDBsSerializer)
 
-    c.Expr[LightTypeTag](q"_root_.izumi.fundamentals.reflection.macrortti.LightTypeTag.parse($strRef : _root_.java.lang.String, $strDBs : _root_.java.lang.String)")
+    c.Expr[LightTypeTag](q"_root_.izumi.fundamentals.reflection.macrortti.LightTypeTag.parse($hashCodeRef: _root_.scala.Int, $strRef : _root_.java.lang.String, $strDBs : _root_.java.lang.String)")
+  }
+
+  @inline final def unpackArgStruct(t: Type): Type = {
+    def badShapeError() = {
+      c.abort(c.enclosingPosition,
+        s"Expected type shape RefinedType `{ type Arg[A] = X[A] }` for summoning `LTag.StrongHK/WeakHK[X]`, but got $t (raw: ${showRaw(t)} ${t.getClass})"
+      )
+    }
+    t match {
+      case r: RefinedTypeApi =>
+        r.decl(TypeName("Arg")) match {
+          case sym: TypeSymbolApi =>
+            sym.info.typeConstructor
+          case _ => badShapeError()
+        }
+      case _ => badShapeError()
+    }
   }
 
 }


Test patch:
diff --git a/distage/distage-core/src/test/scala/izumi/distage/dsl/DSLTest.scala b/distage/distage-core/src/test/scala/izumi/distage/dsl/DSLTest.scala
index b9969ad1e..ccfb36447 100644
--- a/distage/distage-core/src/test/scala/izumi/distage/dsl/DSLTest.scala
+++ b/distage/distage-core/src/test/scala/izumi/distage/dsl/DSLTest.scala
@@ -334,9 +334,9 @@ class DSLTest extends AnyWordSpec with MkInjector {
 
       val definition = new ModuleDef {
         make[ImplXYZ]
-          .aliasTo[TraitX]
-          .aliasTo[TraitY]
-          .aliasTo[TraitZ]
+          .aliased[TraitX]
+          .aliased[TraitY]
+          .aliased[TraitZ]
       }
 
       assert(definition == Module.make(
@@ -350,9 +350,9 @@ class DSLTest extends AnyWordSpec with MkInjector {
 
       val definitionEffect = new ModuleDef {
         make[ImplXYZ].fromEffect(implXYZ)
-          .aliasTo[TraitX]
-          .aliasTo[TraitY]
-          .aliasTo[TraitZ]
+          .aliased[TraitX]
+          .aliased[TraitY]
+          .aliased[TraitZ]
       }
 
       assert(definitionEffect == Module.make(
@@ -372,9 +372,9 @@ class DSLTest extends AnyWordSpec with MkInjector {
 
       val definitionResource = new ModuleDef {
         make[ImplXYZ].fromResource[X]
-          .aliasTo[TraitX]
-          .aliasTo[TraitY]
-          .aliasTo[TraitZ]
+          .aliased[TraitX]
+          .aliased[TraitY]
+          .aliased[TraitZ]
       }
       val expectedResource = Module.make(
         Set(
@@ -396,9 +396,9 @@ class DSLTest extends AnyWordSpec with MkInjector {
 
       val definitionResourceFn = new ModuleDef {
         make[ImplXYZ].fromResource(implXYZResource)
-          .aliasTo[TraitX]
-          .aliasTo[TraitY]
-          .aliasTo[TraitZ]
+          .aliased[TraitX]
+          .aliased[TraitY]
+          .aliased[TraitZ]
       }
 
       assert(definitionResourceFn == Module.make(
@@ -419,8 +419,8 @@ class DSLTest extends AnyWordSpec with MkInjector {
 
       val definition = PlannerInput.noGc(new ModuleDef {
         make[ImplXYZ].named("my-impl")
-          .aliasTo[TraitX]
-          .aliasTo[TraitY]("Y")
+          .aliased[TraitX]
+          .aliased[TraitY]("Y")
       })
 
       val defWithoutSugar = PlannerInput.noGc(new ModuleDef {
@@ -431,8 +431,8 @@ class DSLTest extends AnyWordSpec with MkInjector {
 
       val defWithTags = PlannerInput.noGc(new ModuleDef {
         make[ImplXYZ].named("my-impl").tagged("tag1")
-          .aliasTo[TraitX]
-          .aliasTo[TraitY]
+          .aliased[TraitX]
+          .aliased[TraitY]
       })
 
       val defWithTagsWithoutSugar = PlannerInput.noGc(new ModuleDef {
diff --git a/distage/distage-testkit-legacy/src/test/scala/izumi/distage/testkit/scalatest/TestkitTest.scala b/distage/distage-testkit-legacy/src/test/scala/izumi/distage/testkit/scalatest/TestkitTest.scala
index 247993f3d..f219479aa 100644
--- a/distage/distage-testkit-legacy/src/test/scala/izumi/distage/testkit/scalatest/TestkitTest.scala
+++ b/distage/distage-testkit-legacy/src/test/scala/izumi/distage/testkit/scalatest/TestkitTest.scala
@@ -65,7 +65,7 @@ abstract class TestkitTest[F[_]: TagK] extends TestkitSelftest[F] {
 
   override protected def appOverride: ModuleBase = super.appOverride overridenBy new ConfigModuleDef {
     // FIXME: implement Provider mutators ???
-    makeConfig[TestConf]("test").aliasTo[TestConf]("test1")
+    makeConfig[TestConf]("test").aliased[TestConf]("test1")
     make[TestConf].named("test").from((_: TestConf @Id("test1")).copy(overriden = 3))
   }
 
diff --git a/fundamentals/fundamentals-reflection/src/test/scala/izumi.fundamentals.reflection.test/LightTypeTagTest.scala b/fundamentals/fundamentals-reflection/src/test/scala/izumi.fundamentals.reflection.test/LightTypeTagTest.scala
index de2b0bf33..42f179c71 100644
--- a/fundamentals/fundamentals-reflection/src/test/scala/izumi.fundamentals.reflection.test/LightTypeTagTest.scala
+++ b/fundamentals/fundamentals-reflection/src/test/scala/izumi.fundamentals.reflection.test/LightTypeTagTest.scala
@@ -362,7 +362,10 @@ class LightTypeTagTest extends AnyWordSpec {
     }
 
     "support TagK* family summoners" in {
-      assertSame(LTagK[List].tag, `LTT[_]`[List])
+      val tag = LTagK[List].tag
+      val tag1 = LTagKK[Either].tag
+      assertSame(tag, `LTT[_]`[List])
+      assertSame(tag1, `LTT[_,_]`[Either])
     }
 
     "support intersection type equality" in {