diff options
author | Martin Odersky <odersky@gmail.com> | 2016-06-29 19:57:02 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-07-11 13:35:02 +0200 |
commit | e749d832e9adebc502c961d743b3b29072f8116a (patch) | |
tree | 4c9bdc83925a118ce4cfe37f9d2deea2c6ee7613 /src/dotty/tools/dotc/core/TypeApplications.scala | |
parent | 6414f3bccf5319d273e8f5eb5461b111e9270b34 (diff) | |
download | dotty-e749d832e9adebc502c961d743b3b29072f8116a.tar.gz dotty-e749d832e9adebc502c961d743b3b29072f8116a.tar.bz2 dotty-e749d832e9adebc502c961d743b3b29072f8116a.zip |
Various tweaks
- Swap order of subtype tests
The theory is that if two refined types have the same refined name, then
they are likely to be of related classes. So it seems more fruitful to
check the argument before the typeconstructor because that way we test
the part that's more likely to fail first. Rough observations seem to
indicate a 3% improvement in the junit test time.
- Cleanups
Drop some unnecessary cases; improve comments.
- Smarter handling of LazyRefs in betaReduce
Try to combine type constructor and arguments under a
common LazyRef.
- Optimize RecType/RecType comparisons
- Fix compareHkLambda, make it check variances.
Diffstat (limited to 'src/dotty/tools/dotc/core/TypeApplications.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/TypeApplications.scala | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index c0728a8fb..0edc598dd 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -38,14 +38,23 @@ object TypeApplications { case _ => tp } - /** Does the variance of `sym1` conform to the variance of `sym2`? + /** Does variance `v1` conform to variance `v2`? * This is the case if the variances are the same or `sym` is nonvariant. */ - def varianceConforms(sym1: MemberBinding, sym2: MemberBinding)(implicit ctx: Context) = - sym1.memberVariance == sym2.memberVariance || sym2.memberVariance == 0 + def varianceConforms(v1: Int, v2: Int)(implicit ctx: Context): Boolean = + v1 == v2 || v2 == 0 - def variancesConform(syms1: List[MemberBinding], syms2: List[MemberBinding])(implicit ctx: Context) = - syms1.corresponds(syms2)(varianceConforms) + /** Does the variance of type parameter `tparam1` conform to the variance of type parameter `tparam2`? + */ + def varianceConforms(tparam1: MemberBinding, tparam2: MemberBinding)(implicit ctx: Context): Boolean = + varianceConforms(tparam1.memberVariance, tparam2.memberVariance) + + /** Doe the variances of type parameters `tparams1` conform to the variances + * of corresponding type parameters `tparams2`? + * This is only the case of `tparams1` and `tparams2` have the same length. + */ + def variancesConform(tparams1: List[MemberBinding], tparams2: List[MemberBinding])(implicit ctx: Context): Boolean = + tparams1.corresponds(tparams2)(varianceConforms) def fallbackTypeParams(variances: List[Int])(implicit ctx: Context): List[MemberBinding] = { def memberBindings(vs: List[Int]): Type = vs match { @@ -102,7 +111,7 @@ object TypeApplications { def unapply(tp: Type)(implicit ctx: Context): Option[(/*List[Int], */List[TypeBounds], Type)] = if (Config.newHK) { def decompose(t: Type, acc: List[TypeBounds]): (List[TypeBounds], Type) = t match { - case t @ RefinedType(p, rname, rinfo: TypeBounds) if rname.isHkArgName && rinfo.isBinding => + case t @ RefinedType(p, rname, rinfo: TypeBounds) if t.isTypeParam => decompose(p, rinfo.bounds :: acc) case t: RecType => decompose(t.parent, acc) |