Skip to content

Commit

Permalink
add LambdaParamNameMaker
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivoyaa committed Feb 15, 2023
1 parent e68a045 commit 4a1e30a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import izumi.reflect.internal.fundamentals.platform.assertions.IzAssert
import izumi.reflect.internal.fundamentals.platform.console.TrivialLogger
import izumi.reflect.internal.fundamentals.platform.console.TrivialLogger.Config
import izumi.reflect.internal.fundamentals.platform.strings.IzString._
import izumi.reflect.macrortti.LightTypeTag.LambdaParamNameMaker
import izumi.reflect.macrortti.LightTypeTagImpl.{Broken, globalCache}
import izumi.reflect.macrortti.LightTypeTagRef.RefinementDecl.TypeMember
import izumi.reflect.macrortti.LightTypeTagRef.SymName.{SymLiteral, SymTermName, SymTypeName}
Expand Down Expand Up @@ -548,12 +549,7 @@ final class LightTypeTagImpl[U <: Universe with Singleton](val u: U, withCache:
tparams.zipWithIndex.map {
case (tparamSym, idx) =>
val fullName = tparamSym.fullName
val idxStr = ctxIdx match {
case Some(ctx) =>
s"$ctx:$idx"
case None =>
idx.toString
}
val idxStr = LambdaParamNameMaker.makeParamName(ctxIdx, idx)
fullName -> LambdaParameter(idxStr)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package izumi.reflect.macrortti

import izumi.reflect.internal.fundamentals.functional.{Renderable, WithRenderableSyntax}
import izumi.reflect.internal.fundamentals.platform.language.unused
import izumi.reflect.macrortti.LightTypeTag.LambdaParamNameMaker
import izumi.reflect.macrortti.LightTypeTagRef.SymName.SymLiteral
import izumi.reflect.macrortti.LightTypeTagRef._

Expand Down Expand Up @@ -213,7 +214,9 @@ object LTTRenderables {
Long.r_SymName(sym, hasPrefix)
}

override implicit lazy val r_Lambda: Renderable[Lambda] = new Renderable[Lambda] {
override def prefixSplitter: String = "."

override implicit lazy val r_Lambda: Renderable[Lambda] = new Renderable[Lambda] {
override def render(value: Lambda): String = {
s"${value.output.render()}"
}
Expand All @@ -225,10 +228,28 @@ object LTTRenderables {
}
}

override implicit lazy val r_Variance: Renderable[Variance] = new Renderable[Variance] {
override def render(value: Variance): String = value match {
case Variance.Invariant => ""
case Variance.Contravariant => "-"
case Variance.Covariant => "+"
}
}

override implicit lazy val r_Boundaries: Renderable[Boundaries] = new Renderable[Boundaries] {
override def render(value: Boundaries): String = value match {
case Boundaries.Defined(bottom, top) =>
s"_ >:${bottom.render()} <: ${top.render()}"

case Boundaries.Empty =>
""
}
}

override implicit lazy val r_TypeParam: Renderable[TypeParam] = new Renderable[TypeParam] {
override def render(value: TypeParam): String =
value.ref match {
case n: NameReference if n.symName.name.forall(_.isDigit) =>
case n: NameReference if LambdaParamNameMaker.isParamName(n.symName.name) =>
s"${value.variance.render()}_"
case other =>
other.render()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,21 @@ object LightTypeTag {
(tagref, dbsSerializer)
}

private[reflect] object LambdaParamNameMaker {
def makeParamName(ctxIdx: Option[Int], idx: Int): String = ctxIdx match {
case Some(ctx) =>
s"$ctx:$idx"
case None =>
idx.toString
}

def isParamName(paramName: String): Boolean = paramName.toIntOption.map(idx => makeParamName(None, idx) == paramName)
.getOrElse(paramName.split(":").toList.flatMap(_.toIntOption) match {
case ctx :: idx :: Nil => makeParamName(Some(ctx), idx) == paramName
case _ => false
})
}

private[macrortti] def mergeIDBs[T](self: Map[T, Set[T]], other: Map[T, Set[T]]): Map[T, Set[T]] = {
import izumi.reflect.internal.fundamentals.collections.IzCollections._

Expand Down

0 comments on commit 4a1e30a

Please sign in to comment.