Skip to content

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

Merged
merged 3 commits into from
Oct 8, 2017

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@nicolasstucki
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 1 running.

@dottybot
Copy link
Member

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 */
Copy link
Contributor

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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/an/a

@nicolasstucki
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3212/ to see the changes.

Benchmarks is based on merge(s) with master

@nicolasstucki
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3212/ to see the changes.

Benchmarks is based on merge(s) with master

@nicolasstucki
Copy link
Contributor Author

It looks like this change makes the compilation of the dotty compiler 8% faster.

@smarter
Copy link
Member

smarter commented Sep 30, 2017

Probably not :). Points are missing for today's PRs, same as #3216 (comment)

@smarter
Copy link
Member

smarter commented Sep 30, 2017

@liufengyun Many recent PRs are missing from https://liufengyun.github.io/bench/, any idea why?

odersky
odersky previously requested changes Oct 1, 2017
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)
Copy link
Contributor

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)
Copy link
Contributor

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._

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@nicolasstucki
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

dottybot commented Oct 2, 2017

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

dottybot commented Oct 2, 2017

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3212/ to see the changes.

Benchmarks is based on merging with master (1dda6e1)

@nicolasstucki
Copy link
Contributor Author

All requested changes have been made.

@nicolasstucki nicolasstucki force-pushed the simplify-method-types branch from 0465c14 to ff6e675 Compare October 4, 2017 16:03
@nicolasstucki
Copy link
Contributor Author

Squashed and rebased code

@nicolasstucki nicolasstucki dismissed odersky’s stale review October 4, 2017 16:04

Code has changed based on this feedback

Copy link
Contributor

@odersky odersky left a 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 = {
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

@odersky
Copy link
Contributor

odersky commented Oct 5, 2017

Now we got it to be smaller than before Great! LGTM.

@nicolasstucki nicolasstucki force-pushed the simplify-method-types branch from 1efead3 to 4811889 Compare October 5, 2017 15:04
@nicolasstucki
Copy link
Contributor Author

Rebased

@nicolasstucki nicolasstucki force-pushed the simplify-method-types branch from e07da93 to 4811889 Compare October 5, 2017 15:20
@odersky odersky assigned nicolasstucki and unassigned odersky Oct 7, 2017
@nicolasstucki nicolasstucki merged commit 70eb2b9 into scala:master Oct 8, 2017
@allanrenucci allanrenucci deleted the simplify-method-types branch December 14, 2017 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants