summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorschinz <schinz@epfl.ch>2005-04-20 06:39:49 +0000
committerschinz <schinz@epfl.ch>2005-04-20 06:39:49 +0000
commitb0876f8e3527ad574471c94ef0978c1b76227434 (patch)
tree60e1f1ca8c63e904aad5429dc8af7b8a1e0e8df6 /sources
parent956b9aa3fc0d0d76602def9e016824c55e885cb4 (diff)
downloadscala-b0876f8e3527ad574471c94ef0978c1b76227434.tar.gz
scala-b0876f8e3527ad574471c94ef0978c1b76227434.tar.bz2
scala-b0876f8e3527ad574471c94ef0978c1b76227434.zip
- renamed weak* methods in ScalaClassType to is...
- renamed weak* methods in ScalaClassType to isNonTrivial*, which better reflects what they do, - moved these methods to ClassType, - made getScalaType return a ClassType, to enable the forthcoming optimisation making strongly trivial classes return a JavaClassType instead of a ScalaClassType
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/ScalaObject.java4
-rw-r--r--sources/scala/runtime/types/ClassType.java10
-rw-r--r--sources/scala/runtime/types/ScalaClassType.java10
-rw-r--r--sources/scalac/symtab/Definitions.java12
-rw-r--r--sources/scalac/transformer/TypesAsValuesPhase.java4
-rw-r--r--sources/scalac/util/Names.java2
6 files changed, 26 insertions, 16 deletions
diff --git a/sources/scala/ScalaObject.java b/sources/scala/ScalaObject.java
index c9ebecd4be..c958960a02 100644
--- a/sources/scala/ScalaObject.java
+++ b/sources/scala/ScalaObject.java
@@ -10,7 +10,7 @@
package scala;
-import scala.runtime.types.ScalaClassType;
+import scala.runtime.types.ClassType;
/** @meta class extends scala.AnyRef;
*/
@@ -18,7 +18,7 @@ public interface ScalaObject {
/**
* Return the Scala type of the object.
*/
- public ScalaClassType getScalaType();
+ public ClassType getScalaType();
/** This method is needed for optimizing pattern matching expressions
* which match on constructors of case classes.
diff --git a/sources/scala/runtime/types/ClassType.java b/sources/scala/runtime/types/ClassType.java
index 79d964712f..b0fb83b79e 100644
--- a/sources/scala/runtime/types/ClassType.java
+++ b/sources/scala/runtime/types/ClassType.java
@@ -38,6 +38,11 @@ public abstract class ClassType extends Type {
return clazz.isInstance(o);
}
+ public boolean isNonTrivialInstance(Object o) {
+ assert isTrivial; // must be overridden for non-trivial types
+ return true;
+ }
+
public boolean isSubType(Type that) {
return (that == Type.Any)
|| (that instanceof ClassType
@@ -50,6 +55,11 @@ public abstract class ClassType extends Type {
return that.clazz.isAssignableFrom(this.clazz);
}
+ public boolean isNonTrivialSubClassType(ClassType that) {
+ assert isTrivial; // must be overridden for non-trivial types
+ return true;
+ }
+
protected final boolean isSubCompoundType(CompoundType that) {
// TODO? check refinement
for (int i = 0; i < that.components.length; ++i) {
diff --git a/sources/scala/runtime/types/ScalaClassType.java b/sources/scala/runtime/types/ScalaClassType.java
index 794fc4e12a..13da109579 100644
--- a/sources/scala/runtime/types/ScalaClassType.java
+++ b/sources/scala/runtime/types/ScalaClassType.java
@@ -54,22 +54,22 @@ public class ScalaClassType extends ClassType {
public boolean isInstance(Object o) {
return super.isInstance(o)
&& (isTrivial
- || ((ScalaObject)o).getScalaType().weakIsSubScalaClassType(this));
+ || ((ScalaObject)o).getScalaType().isNonTrivialSubClassType(this));
}
- public boolean weakIsInstance(Object o) {
+ public boolean isNonTrivialInstance(Object o) {
assert Statistics.incWeakInstanceOf();
- return ((ScalaObject)o).getScalaType().weakIsSubScalaClassType(this);
+ return ((ScalaObject)o).getScalaType().isNonTrivialSubClassType(this);
}
protected boolean isSubClassType(ClassType that) {
return (this == that)
|| (super.isSubClassType(that)
&& (that.isTrivial
- || weakIsSubScalaClassType((ScalaClassType)that)));
+ || isNonTrivialSubClassType((ScalaClassType)that)));
}
- private boolean weakIsSubScalaClassType(ScalaClassType that) {
+ public boolean isNonTrivialSubClassType(ScalaClassType that) {
ScalaClassType parentCT = myInstantiationFor(that);
// At this stage, if parentCT is null, it means that the
diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java
index cedd8703cd..32c472e90b 100644
--- a/sources/scalac/symtab/Definitions.java
+++ b/sources/scalac/symtab/Definitions.java
@@ -680,12 +680,12 @@ public class Definitions {
return TYPECONSTRUCTOR_FUNCTIONOUTER;
}
- private Symbol SCALACLASSTYPE_WEAKISINSTANCE;
- public Symbol SCALACLASSTYPE_WEAKISINSTANCE() {
- if (SCALACLASSTYPE_WEAKISINSTANCE == null)
- SCALACLASSTYPE_WEAKISINSTANCE =
- loadTerm(SCALACLASSTYPE_CLASS, Names.weakIsInstance);
- return SCALACLASSTYPE_WEAKISINSTANCE;
+ private Symbol CLASSTYPE_ISNONTRIVIALINSTANCE;
+ public Symbol CLASSTYPE_ISNONTRIVIALINSTANCE() {
+ if (CLASSTYPE_ISNONTRIVIALINSTANCE == null)
+ CLASSTYPE_ISNONTRIVIALINSTANCE =
+ loadTerm(CLASSTYPE_CLASS, Names.isNonTrivialInstance);
+ return CLASSTYPE_ISNONTRIVIALINSTANCE;
}
private Symbol SCALACLASSTYPE_SETPARENTS;
diff --git a/sources/scalac/transformer/TypesAsValuesPhase.java b/sources/scalac/transformer/TypesAsValuesPhase.java
index b18afe9525..74161c356e 100644
--- a/sources/scalac/transformer/TypesAsValuesPhase.java
+++ b/sources/scalac/transformer/TypesAsValuesPhase.java
@@ -761,14 +761,14 @@ public class TypesAsValuesPhase extends Phase {
Tree cheapTest =
gen.mkIsInstanceOf(pos, gen.mkLocalRef(pos, val), tp, true);
- Symbol weakIsInst = defs.SCALACLASSTYPE_WEAKISINSTANCE();
+ Symbol isNonTrivialInst = defs.CLASSTYPE_ISNONTRIVIALINSTANCE();
Tree scalaTpVal = gen.mkAsInstanceOf(pos,
tpVal,
defs.SCALACLASSTYPE_TYPE(),
true);
Tree expensiveTest =
gen.mkApply_V(pos,
- gen.Select(pos, scalaTpVal, weakIsInst),
+ gen.Select(pos, scalaTpVal, isNonTrivialInst),
new Tree[] { gen.mkLocalRef(pos, val) });
Tree bothTests =
diff --git a/sources/scalac/util/Names.java b/sources/scalac/util/Names.java
index 9875857bdd..4ed8c69336 100644
--- a/sources/scalac/util/Names.java
+++ b/sources/scalac/util/Names.java
@@ -226,7 +226,7 @@ public class Names {
public static final Name update = Name.fromString("update");
public static final Name view = Name.fromString("view");
public static final Name wait = Name.fromString("wait");
- public static final Name weakIsInstance = Name.fromString("weakIsInstance");
+ public static final Name isNonTrivialInstance = Name.fromString("isNonTrivialInstance");
public static final Name xml = Name.fromString("xml");