Skip to content

Commit d6a621a

Browse files
committed
refactor LambdaEncoding
1 parent 395d1c3 commit d6a621a

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

src/compiler/scala/tools/nsc/tasty/bridge/TastyKernel.scala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ trait TastyKernel { self: TastyUniverse =>
7474
def unapply(tpe: Type): Option[(List[Symbol], Type)] = symbolTable.GenPolyType.unapply(tpe)
7575
}
7676

77-
object LambdaEncoding {
78-
def unapply(tpe: Type): Option[PolyType] = tpe match {
79-
case symbolTable.PolyType(args, TypeBounds(nothing, upper)) if nothing =:= defn.NothingTpe =>
80-
Some(mkPolyType(args, upper))
81-
case _ =>
82-
None
83-
}
84-
}
85-
8677
def dropNullaryMethod(tp: Type): Type = symbolTable.definitions.dropNullaryMethod(tp)
8778

8879
def mkSingleType(pre: Type, sym: Symbol): Type = symbolTable.singleType(pre, sym)

src/compiler/scala/tools/nsc/tasty/bridge/TypeOps.scala

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ trait TypeOps extends TastyKernel { self: TastyUniverse =>
2020
import FlagSets._
2121
import SymbolOps._
2222

23-
def isTastyLazyType(rawInfo: Type): Boolean = rawInfo.isInstanceOf[TastyLazyType]
24-
2523
def mergeableParams(t: Type, u: Type): Boolean =
2624
t.typeParams.size == u.typeParams.size
2725

@@ -52,7 +50,7 @@ trait TypeOps extends TastyKernel { self: TastyUniverse =>
5250
mkPolyType(hi.typeParams, TypeBounds.bounded(nuLo, hi.resultType.upperBound))
5351
}
5452
else bounds match {
55-
case TypeBounds(LambdaEncoding(lo), LambdaEncoding(hi)) => TypeBounds.bounded(lo,hi)
53+
case TypeBounds(lo: LambdaEncoding, hi: LambdaEncoding) => TypeBounds.bounded(lo.toNested,hi.toNested)
5654
case _ => bounds
5755
}
5856
}
@@ -66,23 +64,21 @@ trait TypeOps extends TastyKernel { self: TastyUniverse =>
6664

6765
def boundedAppliedType(tycon: Type, args: List[Type])(implicit ctx: Context): Type = {
6866

69-
def typeRefUncurried(tycon: Type, args: List[Type]): Type = {
70-
if (tycon.isInstanceOf[TypeRef] && tycon.typeArgs.nonEmpty) {
67+
def typeRefUncurried(tycon: Type, args: List[Type]): Type = tycon match {
68+
case tycon: TypeRef if tycon.typeArgs.nonEmpty =>
7169
attachCompiletimeOnly(owner =>
7270
s"Unsupported Scala 3 curried type application $tycon[${args.mkString(",")}] in signature of $owner")
7371
errorType
74-
}
75-
else {
72+
case _ =>
7673
mkAppliedType(tycon, args)
77-
}
7874
}
7975

80-
if (args.exists(tpe => tpe.isInstanceOf[TypeBounds] | tpe.isInstanceOf[PolyType])) {
76+
if (args.exists(tpe => tpe.isInstanceOf[TypeBounds] | tpe.isInstanceOf[LambdaEncoding])) {
8177
val syms = mutable.ListBuffer.empty[Symbol]
8278
def bindWildcards(tpe: Type) = tpe match {
83-
case tpe: TypeBounds => ctx.newWildcardSym(tpe).tap(syms += _).pipe(_.ref)
84-
case LambdaEncoding(lambda) => lambda
85-
case tpe => tpe
79+
case tpe: TypeBounds => ctx.newWildcardSym(tpe).tap(syms += _).pipe(_.ref)
80+
case tpe: LambdaEncoding => tpe.toNested
81+
case tpe => tpe
8682
}
8783
val args1 = args.map(bindWildcards)
8884
if (syms.isEmpty) typeRefUncurried(tycon, args1)
@@ -229,6 +225,15 @@ trait TypeOps extends TastyKernel { self: TastyUniverse =>
229225
def apply(paramNames: List[N], paramVariances: List[Variance])(paramInfosExp: LT => List[PInfo], resultTypeExp: LT => Type)(implicit ctx: Context): LT
230226
}
231227

228+
final class LambdaEncoding(override val typeParams: List[Symbol], val resTpe: Type) extends PolyType(typeParams, TypeBounds.addLower(resTpe)) {
229+
def toNested: PolyType = resTpe match {
230+
case _: TypeBounds => this
231+
case _ => mkPolyType(typeParams, resTpe)
232+
}
233+
}
234+
235+
def mkLambdaEncoding(typeParams: List[Symbol], resTpe: Type) = new LambdaEncoding(typeParams, resTpe)
236+
232237
object TypeParamLambda {
233238
def apply(typeParams: List[Symbol], ret: Type): LambdaType = new TypeParamLambda(typeParams, ret)
234239
}
@@ -275,11 +280,11 @@ trait TypeOps extends TastyKernel { self: TastyUniverse =>
275280
*/
276281
final def canonicalForm(implicit ctx: Context): Type = {
277282
val res = resType match {
278-
case LambdaEncoding(lambda) => lambda
279-
case res => res
283+
case res: LambdaEncoding => res.toNested
284+
case res => res
280285
}
281286
lambdaTpe match {
282-
case _: HKTypeLambda => mkPolyType(typeParams, TypeBounds.addLower(res))
287+
case _: HKTypeLambda => mkLambdaEncoding(typeParams, res)
283288
case _: TypeParamLambda => mkPolyType(typeParams, res)
284289
}
285290
}.tap(res => ctx.log(s"""|canonical form of ${lambdaTpe.productPrefix}:

src/tastytest/scala/tools/tastytest/Diff.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ object Diff {
1818
.generateUnifiedDiff(
1919
"check",
2020
"output",
21-
output.asJava,
21+
check.asJava,
2222
diff,
2323
1
2424
)
25-
.asScala
25+
.toArray()
2626
.mkString("\n")
2727
}
2828
}

0 commit comments

Comments
 (0)