Skip to content

Commit 0465c14

Browse files
committed
Remove MethodKinds and use companion instead
1 parent ad4282f commit 0465c14

File tree

3 files changed

+20
-41
lines changed

3 files changed

+20
-41
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Definitions {
119119
if (name.firstPart.startsWith(str.ImplicitFunction)) {
120120
val superTrait =
121121
FunctionType(arity).appliedTo(argParams.map(_.typeRef) ::: resParam.typeRef :: Nil)
122-
(MethodType.withKind(isImplicit = true), superTrait :: Nil)
122+
(ImplicitMethodType, superTrait :: Nil)
123123
}
124124
else (MethodType, Nil)
125125
val applyMeth =

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,15 +2684,13 @@ object Types {
26842684
paramInfosExp: MethodType => List[Type],
26852685
resultTypeExp: MethodType => Type)
26862686
extends MethodOrPoly with TermLambda with NarrowCached { thisMethodType =>
2687-
import MethodKinds._
26882687

26892688
type This = MethodType
26902689

2691-
def kind: MethodKind
2692-
final def companion: MethodTypeCompanion = MethodType.withKind(kind)
2690+
def companion: MethodTypeCompanion
26932691

2694-
final override def isJavaMethod: Boolean = kind is JavaKind
2695-
final override def isImplicitMethod: Boolean = kind is ImplicitKind
2692+
final override def isJavaMethod: Boolean = companion.isJava
2693+
final override def isImplicitMethod: Boolean = companion.isImplicit
26962694

26972695
val paramInfos = paramInfosExp(this)
26982696
val resType = resultTypeExp(this)
@@ -2704,7 +2702,7 @@ object Types {
27042702
protected def prefixString = "MethodType"
27052703
}
27062704

2707-
final class CachedMethodType(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type, val kind: MethodKinds.MethodKind)
2705+
final class CachedMethodType(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type, val companion: MethodTypeCompanion)
27082706
extends MethodType(paramNames)(paramInfosExp, resultTypeExp)
27092707

27102708
abstract class LambdaTypeCompanion[N <: Name, PInfo <: Type, LT <: LambdaType] {
@@ -2750,10 +2748,10 @@ object Types {
27502748
def syntheticParamName(n: Int) = tpnme.syntheticTypeParamName(n)
27512749
}
27522750

2753-
abstract class MethodTypeCompanion extends TermLambdaCompanion[MethodType] {
2754-
import MethodKinds._
2751+
abstract class MethodTypeCompanion extends TermLambdaCompanion[MethodType] { self =>
27552752

2756-
def kind: MethodKind
2753+
def isJava: Boolean = false
2754+
def isImplicit: Boolean = false
27572755

27582756
/** Produce method type from parameter symbols, with special mappings for repeated
27592757
* and inline parameters:
@@ -2785,7 +2783,7 @@ object Types {
27852783
}
27862784

27872785
final def apply(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType =
2788-
checkValid(new CachedMethodType(paramNames)(paramInfosExp, resultTypeExp, kind))
2786+
checkValid(new CachedMethodType(paramNames)(paramInfosExp, resultTypeExp, self))
27892787

27902788
def checkValid(mt: MethodType)(implicit ctx: Context): mt.type = {
27912789
if (Config.checkMethodTypes)
@@ -2798,39 +2796,20 @@ object Types {
27982796
}
27992797
}
28002798

2801-
object MethodKinds {
2802-
type MethodKind = Byte
2803-
2804-
val Plain: MethodKind = 0: Byte
2805-
2806-
// Flags
2807-
val JavaKind: MethodKind = 1: Byte
2808-
val ImplicitKind: MethodKind = 2: Byte
2809-
2810-
def makeMethodKind(isJava: Boolean, isImplicit: Boolean): MethodKind = {
2811-
var mk: Int = Plain
2812-
if (isJava) mk |= JavaKind
2813-
if (isImplicit) mk |= ImplicitKind
2814-
mk.toByte
2815-
}
2816-
2817-
implicit class MethodKindsOps(mk: MethodKind) {
2818-
def is(that: MethodKind): Boolean = (mk & that) == that
2799+
object MethodType extends MethodTypeCompanion {
2800+
def withKind(isJava: Boolean = false, isImplicit: Boolean = false): MethodTypeCompanion = {
2801+
if (isJava) JavaMethodType
2802+
else if (isImplicit) ImplicitMethodType
2803+
else MethodType
28192804
}
28202805
}
28212806

2822-
object MethodType extends MethodTypeCompanion { self =>
2823-
import MethodKinds._
2824-
2825-
def kind: MethodKind = Plain
2826-
2827-
private val methodTypeCompanions: mutable.Map[MethodKind, MethodTypeCompanion] = mutable.Map.empty
2828-
def withKind(methodKind: MethodKind): MethodTypeCompanion =
2829-
if (methodKind == Plain) this
2830-
else methodTypeCompanions.getOrElseUpdate(methodKind, new MethodTypeCompanion { def kind = methodKind })
2807+
object JavaMethodType extends MethodTypeCompanion {
2808+
override def isJava: Boolean = true
2809+
}
28312810

2832-
def withKind(isJava: Boolean = false, isImplicit: Boolean = false): MethodTypeCompanion =
2833-
withKind(makeMethodKind(isJava, isImplicit))
2811+
object ImplicitMethodType extends MethodTypeCompanion {
2812+
override def isImplicit: Boolean = true
28342813
}
28352814

28362815
/** A ternary extractor for MethodType */

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class ClassfileParser(
368368
}
369369
index += 1
370370
val restype = sig2type(tparams, skiptvs)
371-
MethodType.withKind(isJava = true)(paramnames.toList, paramtypes.toList, restype)
371+
JavaMethodType(paramnames.toList, paramtypes.toList, restype)
372372
case 'T' =>
373373
val n = subName(';'.==).toTypeName
374374
index += 1

0 commit comments

Comments
 (0)