summaryrefslogtreecommitdiff
path: root/src/continuations/plugin
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-05-11 13:02:53 -0700
committerPaul Phillips <paulp@improving.org>2013-05-11 13:02:53 -0700
commit1850ddf380789e364813111282af5ff11e65b52c (patch)
tree38ae4b5f4f56cf5e24b7ac639b4fb297c171f070 /src/continuations/plugin
parentc85a507ba815643faacd8e07270efbd83b700846 (diff)
downloadscala-1850ddf380789e364813111282af5ff11e65b52c.tar.gz
scala-1850ddf380789e364813111282af5ff11e65b52c.tar.bz2
scala-1850ddf380789e364813111282af5ff11e65b52c.zip
Corralling Modes into a smaller pen.
Attempting to reduce the frequency of low-level operations with modes. I mean stuff like this: if ((mode & (EXPRmode | LHSmode)) == EXPRmode) THey don't make those ten line boolean guards any easier to understand. Hopefully this will lead us toward eliminating some of the modes entirely, or at least better isolating their logic rather than having it interspersed at arbitrary points throughout the typer. Modes are in their entirety a leaked implementation detail. Typing a tree requires a tree and optionally an expected type. It shouldn't require a bucket of state bits. In subsequent commits I will start eliminating them. This commit also breaks adapt down into more digestible chunks.
Diffstat (limited to 'src/continuations/plugin')
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
index beab271a3b..519b90f0c6 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
@@ -138,7 +138,7 @@ abstract class CPSAnnotationChecker extends CPSUtils {
/*
// not precise enough -- still relying on addAnnotations to remove things from ValDef symbols
- if ((mode & TYPEmode) != 0 && (mode & BYVALmode) != 0) {
+ if (mode.inAllModes(TYPEmode | BYVALmode)) {
if (!annots1.isEmpty) {
return true
}
@@ -147,7 +147,7 @@ abstract class CPSAnnotationChecker extends CPSUtils {
/*
this interferes with overloading resolution
- if ((mode & BYVALmode) != 0 && tree.tpe <:< pt) {
+ if (mode.inByValMode && tree.tpe <:< pt) {
vprintln("already compatible, can't adapt further")
return false
}
@@ -193,19 +193,15 @@ abstract class CPSAnnotationChecker extends CPSUtils {
vprintln("adapt annotations " + tree + " / " + tree.tpe + " / " + mode + " / " + pt)
- val patMode = mode.inPatternMode
- val exprMode = mode.inExprMode
- val byValMode = mode.inByValMode
- val retMode = mode.inRetMode
-
- val annotsTree = cpsParamAnnotation(tree.tpe)
- val annotsExpected = cpsParamAnnotation(pt)
+ val annotsTree = cpsParamAnnotation(tree.tpe)
+ val annotsExpected = cpsParamAnnotation(pt)
+ def isMissingExpectedAnnots = annotsTree.isEmpty && annotsExpected.nonEmpty
// not sure I rephrased this comment correctly:
- // replacing `patMode` in the condition below by `patMode || ((mode & TYPEmode) != 0 && (mode & BYVALmode))`
+ // replacing `mode.inPatternMode` in the condition below by `mode.inPatternMode || mode.inAllModes(TYPEmode | BYVALmode)`
// doesn't work correctly -- still relying on addAnnotations to remove things from ValDef symbols
- if (patMode && !annotsTree.isEmpty) tree modifyType removeAllCPSAnnotations
- else if (exprMode && !byValMode && !hasPlusMarker(tree.tpe) && annotsTree.isEmpty && annotsExpected.nonEmpty) { // shiftUnit
+ if (mode.inPatternMode && annotsTree.nonEmpty) tree modifyType removeAllCPSAnnotations
+ else if (mode.typingExprNotValue && !hasPlusMarker(tree.tpe) && isMissingExpectedAnnots) { // shiftUnit
// add a marker annotation that will make tree.tpe behave as pt, subtyping wise
// tree will look like having any possible annotation
//println("adapt annotations " + tree + " / " + tree.tpe + " / " + Integer.toHexString(mode) + " / " + pt)
@@ -217,13 +213,13 @@ abstract class CPSAnnotationChecker extends CPSUtils {
val res = tree modifyType (_ withAnnotations newPlusMarker() :: annotsExpected) // needed for #1807
vprintln("adapted annotations (not by val) of " + tree + " to " + res.tpe)
res
- } else if (exprMode && byValMode && !hasMinusMarker(tree.tpe) && annotsTree.nonEmpty) { // dropping annotation
+ } else if (mode.typingExprByValue && !hasMinusMarker(tree.tpe) && annotsTree.nonEmpty) { // dropping annotation
// add a marker annotation that will make tree.tpe behave as pt, subtyping wise
// tree will look like having no annotation
val res = tree modifyType addMinusMarker
vprintln("adapted annotations (by val) of " + tree + " to " + res.tpe)
res
- } else if (retMode && !hasPlusMarker(tree.tpe) && annotsTree.isEmpty && annotsExpected.nonEmpty) {
+ } else if (mode.inRetMode && !hasPlusMarker(tree.tpe) && isMissingExpectedAnnots) {
// add a marker annotation that will make tree.tpe behave as pt, subtyping wise
// tree will look like having any possible annotation
@@ -231,7 +227,7 @@ abstract class CPSAnnotationChecker extends CPSUtils {
// (annotsExpected.nonEmpty == cpsParamAnnotation(pt).nonEmpty)
// note 2: we are not adding the expected cps annotations, since they will be added
// by adaptTypeOfReturn (see below).
- val res = tree modifyType (_ withAnnotations List(newPlusMarker()))
+ val res = tree modifyType (_ withAnnotation newPlusMarker())
vprintln("adapted annotations (return) of " + tree + " to " + res.tpe)
res
} else tree