aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-10-12 14:18:02 +0200
committerMartin Odersky <odersky@gmail.com>2013-10-12 14:18:02 +0200
commit15a63974d23511a3a879c3354552bed504061617 (patch)
tree1df3952f745970e732d888cdf0298cb19d62e600 /src/dotty/tools/dotc
parent54a1bce87b4682ccfb97504e2daa7c36cbf207b2 (diff)
downloaddotty-15a63974d23511a3a879c3354552bed504061617.tar.gz
dotty-15a63974d23511a3a879c3354552bed504061617.tar.bz2
dotty-15a63974d23511a3a879c3354552bed504061617.zip
New invariant: refined types must have a refined info that's more specific than the previous bounds.
Making use of this to make comparisons of refined types with the same names more efficient. Also, to make findMember on refined type with type refinement more efficient.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala16
-rw-r--r--src/dotty/tools/dotc/core/Types.scala8
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala1
3 files changed, 14 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index cf24743bf..4d6c6a60b 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -234,12 +234,16 @@ class TypeComparer(initctx: Context) extends DotClass {
def thirdTry(tp1: Type, tp2: Type): Boolean = tp2 match {
case tp2: NamedType =>
thirdTryNamed(tp1, tp2)
- case tp2: RefinedType =>
- isSubType(tp1, tp2.parent) && (
- tp2.refinedName == nme.WILDCARD
- || tp1.member(tp2.refinedName).hasAltWith(alt =>
- isSubType(alt.info, tp2.refinedInfo))
- || fourthTry(tp1, tp2))
+ case tp2 @ RefinedType(parent2, name2) =>
+ tp1 match
+ case tp1 @ RefinedType(parent1, name1) if name1 == name2 =>
+ isSubType(parent1, parent2) && isSubType(tp1.refinedInfo, tp2.refinedInfo)
+ case _ =>
+ isSubType(tp1, parent2) && (
+ name2 == nme.WILDCARD
+ || tp1.member(name2).hasAltWith(alt => isSubType(alt.info, tp2.refinedInfo))
+ || fourthTry(tp1, tp2))
+ }
case AndType(tp21, tp22) =>
isSubType(tp1, tp21) && isSubType(tp1, tp22)
case OrType(tp21, tp22) =>
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index a7dadbd0e..f03100323 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -396,11 +396,9 @@ object Types {
val pdenot = tp.parent.findMember(name, pre, excluded)
if (name eq tp.refinedName) {
val rinfo = tp.refinedInfo.substThis(tp, pre)
- if (name.isTypeName) { // simplified case that runs more efficiently
- val info = if (pdenot.symbol is TypeParam) rinfo else pdenot.info & rinfo
- pdenot.asInstanceOf[SingleDenotation].derivedSingleDenotation(
- pdenot.symbol, info)
- } else
+ if (name.isTypeName) // simplified case that runs more efficiently
+ pdenot.asInstanceOf[SingleDenotation].derivedSingleDenotation(pdenot.symbol, rinfo)
+ else
pdenot & (new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId)), pre)
} else pdenot
case tp: ThisType =>
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 0e246480c..1e3049f7e 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -669,6 +669,7 @@ class Typer extends Namer with Applications with Implicits {
val rsym = refinement.symbol
val rinfo = if (rsym is Accessor) rsym.info.resultType else rsym.info
RefinedType(parent, rsym.name, rt => rinfo.substThis(refineCls, RefinedThis(rt)))
+ // todo later: check that refinement is within bounds
}
cpy.RefinedTypeTree(tree, tpt1, refinements1) withType
(tpt1.tpe /: refinements1)(addRefinement)