aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-08-29 11:30:05 +0200
committerMartin Odersky <odersky@gmail.com>2014-08-29 11:30:05 +0200
commit9a49deff8a1905b9dc111e79638541ea5ba927c9 (patch)
tree6fd3340071ec9c09527fe7635242bc77cda7a167 /src/dotty/tools/dotc/core/Types.scala
parent8b9bdfe5f0c8c084b2db90ddcc0b5bbc25347034 (diff)
downloaddotty-9a49deff8a1905b9dc111e79638541ea5ba927c9.tar.gz
dotty-9a49deff8a1905b9dc111e79638541ea5ba927c9.tar.bz2
dotty-9a49deff8a1905b9dc111e79638541ea5ba927c9.zip
Shorten "if denotation is current the symbol" to "currentSymbol".
And make its usage more systematic on all substitutions where it makes sense.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index c2d465f7f..42ff62f4d 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -1102,9 +1102,24 @@ object Types {
// (1) checkedPeriod != Nowhere => lastDenotation != null
// (2) lastDenotation != null => lastSymbol != null
+ /** There is a denotation computed which is valid (somewhere in) the
+ * current run.
+ */
def denotationIsCurrent(implicit ctx: Context) =
lastDenotation != null && lastDenotation.validFor.runId == ctx.runId
+ /** The the denotation is current, its symbol, otherwise NoDenotation.
+ *
+ * Note: This operation does not force the denotation, and is therefore
+ * timing dependent. It should only be used if the outcome of the
+ * essential computation does not depend on the symbol being present or not.
+ * It's currently used to take an optimized path in substituters and
+ * type accumulators, as well as to be safe in diagnostiic printing.
+ * Normally, it's better to use `symbol`, not `currentSymbol`.
+ */
+ def currentSymbol(implicit ctx: Context) =
+ if (denotationIsCurrent) symbol else NoSymbol
+
/** The denotation currently denoted by this type */
final def denot(implicit ctx: Context): Denotation = {
val now = ctx.period
@@ -2659,7 +2674,7 @@ object Types {
this(x, if (tp1.exists) tp1 else tp.prefix)
}
case tp: TermRef =>
- if (stopAtStatic && tp.denotationIsCurrent && tp.symbol.isStatic) x
+ if (stopAtStatic && tp.currentSymbol.isStatic) x
else this(x, tp.prefix)
case _: ThisType