-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove patter matches on ImplicitMethodType and JavaMethodType #3212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove patter matches on ImplicitMethodType and JavaMethodType #3212
Conversation
test performance please |
performance test scheduled: 1 job(s) in queue, 1 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3212/ to see the changes. Benchmarks is based on merge(s) with master |
@@ -288,6 +288,18 @@ object Types { | |||
/** Is this an alias TypeBounds? */ | |||
final def isAlias: Boolean = this.isInstanceOf[TypeAlias] | |||
|
|||
/** Is this an MethodType which has implicit parameters */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong doc
case _ => false | ||
} | ||
|
||
/** Is this an MethodType which has implicit parameters */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/an/a
5190981
to
ff309b9
Compare
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
ff309b9
to
3c63040
Compare
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3212/ to see the changes. Benchmarks is based on merge(s) with master |
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3212/ to see the changes. Benchmarks is based on merge(s) with master |
It looks like this change makes the compilation of the dotty compiler 8% faster. |
Probably not :). Points are missing for today's PRs, same as #3216 (comment) |
@liufengyun Many recent PRs are missing from https://liufengyun.github.io/bench/, any idea why? |
override def isImplicit = true | ||
override protected def prefixString = "ImplicitMethodType" | ||
} | ||
final class ConcreteMethodType(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type, val kind: MethodKinds.MethodKind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep with naming conventions, it should be CachedMethodType
.
@@ -2788,6 +2784,11 @@ object Types { | |||
tl => tl.integrate(params, resultType)) | |||
} | |||
|
|||
final def apply(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType = { | |||
val mtc = unique(new ConcreteMethodType(paramNames)(paramInfosExp, resultTypeExp, kind)) | |||
if (kind is JavaKind) mtc else checkValid(mtc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the condition. You can always do the checkValid
.
checkValid(unique(new ImplicitMethodType(paramNames)(paramInfosExp, resultTypeExp))) | ||
object MethodType extends MethodTypeCompanion { self => | ||
import MethodKinds._ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since MethodTypes are created very often (~500K for Dotty bootstrap) and there are only a small number of different ones, I would not do the withKind
scaffolding. I would create a finite number of companions instead and use the kind as a parameter.
Actually, I think a simpler scheme is to forgo kinds altogether and only use companions.
Yes, it will get a little bit more complicated once we add unused
, but it's still much easier than defining separate kinds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That design is a lot simpler. The only drawback is that we will have an additional indirection to know is a type is a Java method type or implicit method type as that knowlage is in the companion.
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3212/ to see the changes. Benchmarks is based on merging with master (1dda6e1) |
All requested changes have been made. |
0465c14
to
ff6e675
Compare
Squashed and rebased code |
Code has changed based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the withKind with the two boolean parameters is an improvement. I'd drop that and use the old way of choosing companions.
Otherwise LGTM
@@ -2845,18 +2843,19 @@ object Types { | |||
} | |||
|
|||
object MethodType extends MethodTypeCompanion { | |||
def apply(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType = | |||
checkValid(unique(new CachedMethodType(paramNames)(paramInfosExp, resultTypeExp))) | |||
def withKind(isJava: Boolean = false, isImplicit: Boolean = false): MethodTypeCompanion = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need that method anymore
abstract class MethodTypeCompanion extends TermLambdaCompanion[MethodType] { self => | ||
|
||
def isJava: Boolean = false | ||
def isImplicit: Boolean = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these are needed either?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will become useful if we add more method types. I will remove it and add it back if it is needed in the future.
} | ||
|
||
object JavaMethodType extends MethodTypeCompanion { | ||
def apply(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType = | ||
unique(new JavaMethodType(paramNames)(paramInfosExp, resultTypeExp)) | ||
override def isJava: Boolean = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be dropped
} | ||
|
||
object ImplicitMethodType extends MethodTypeCompanion { | ||
def apply(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType = | ||
checkValid(unique(new ImplicitMethodType(paramNames)(paramInfosExp, resultTypeExp))) | ||
override def isImplicit: Boolean = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be dropped
@@ -774,8 +774,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas | |||
def isImplicit = | |||
tag == IMPLICITMETHODtpe || | |||
params.nonEmpty && (params.head is Implicit) | |||
val maker = if (isImplicit) ImplicitMethodType else MethodType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave as is.
Now we got it to be smaller than before Great! LGTM. |
1efead3
to
4811889
Compare
Rebased |
e07da93
to
4811889
Compare
No description provided.