summaryrefslogtreecommitdiff
path: root/src/continuations
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2011-01-20 09:43:18 +0000
committerAdriaan Moors <adriaan.moors@epfl.ch>2011-01-20 09:43:18 +0000
commitf0bff86d31c0ce9548e595c4b4b7fda8efe038c0 (patch)
treea01a425900de3bca3202bcfca1749099cb74a235 /src/continuations
parentf4f1738fe79193010c328371521ed554e7e8cf6d (diff)
downloadscala-f0bff86d31c0ce9548e595c4b4b7fda8efe038c0.tar.gz
scala-f0bff86d31c0ce9548e595c4b4b7fda8efe038c0.tar.bz2
scala-f0bff86d31c0ce9548e595c4b4b7fda8efe038c0.zip
introduce NullaryMethodType to disambiguate Pol...
introduce NullaryMethodType to disambiguate PolyType motivation: given `def foo[T]: (T, T)` and `type Foo[T] = (T, T)`, `foo.info` and `TypeRef(_, Foo, Nil).normalize` are both `PolyType(List(T), Pair[T, T])` uncurry has been relying on an ugly hack to distinguish these cases based on ad-hoc kind inference without this distinction, the type alias's info (a type function) would be transformed to `PolyType(List(T), MethodType(Nil, Pair[T, T]))` anonymous type functions are being used more often (see #2741, #4017, #4079, #3443, #3106), which makes a proper treatment of PolyTypes more pressing change to type representation: PolyType(Nil, tp) -> NullaryMethodType(tp) PolyType(tps, tp) -> PolyType(tps, NullaryMethodType(tp)) (if the polytype denoted a polymorphic nullary method) PolyType(Nil, tp) is now invalid the kind of a PolyType is * iff its resulttype is a NullaryMethodType or a MethodType (i.e., it's a polymorphic value) in all other cases a PolyType now denotes a type constructor NullaryMethodType is eliminated during uncurry pickling: for backwards compatibility, a NullaryMethodType(tp) is still pickled as a PolyType(Nil, tp), unpickling rewrites pre-2.9-pickled PolyTypes according to the expected kind of the unpickled type (similar to what we used to do in uncurry) a pickled PolyType(Nil, restpe) is unpickled to NullaryMethodType(restpe) a pickled PolyType(tps, restpe) is unpickled to PolyType(tps, NullaryMethodType(restpe)) when the type is expected to have kind * the rewrite probably isn't complete, but was validated by compiling against the old scalacheck jar (which has plenty of polymorphic nullary methods) nevertheless, this commit includes a new scalacheck jar summary of the refactoring: * PolyType(List(), tp) or PolyType(Nil, tp) or PolyType(parms, tp) if params.isEmpty ==> NullaryMethodType(tp) * whenever there was a case PolyType(tps, tp) (irrespective of tps isEmpty), now need to consider the case PolyType(tps, NullaryMethodType(tp)); just add a case NullaryMethodType(tp), since usually: - there already is a PolyType case that recurses on the result type, - the polytype case applied to empty and non-empty type parameter lists alike * tp.resultType, where tp was assumed to be a PolyType that represents a polymorphic nullary method type before, tp == PolyType(tps, res), now tp == PolyType(tps, NullaryMethodType(res)) * got bitten again (last time was dependent-method types refactoring) by a TypeMap not being the identity when dropNonConstraintAnnotations is true (despite having an identity apply method). Since asSeenFrom is skipped when isTrivial, the annotations aren't dropped. The cps plugin relies on asSeenFrom dropping these annotations for trivial types though. Therefore, NullaryMethodType pretends to never be trivial. Better fix(?) in AsSeenFromMap: `if(tp.isTrivial) dropNonContraintAnnotations(tp) else ...` TODO: scalap and eclipse review by odersky, rytz
Diffstat (limited to 'src/continuations')
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala5
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala4
2 files changed, 5 insertions, 4 deletions
diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
index 5151f1eeee..2df538fe85 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
@@ -373,9 +373,10 @@ abstract class CPSAnnotationChecker extends CPSUtils {
transChildrenInOrder(tree, tpe, qual::(transArgList(fun, args).flatten), Nil)
case TypeApply(fun @ Select(qual, name), args) if fun.isTyped =>
+ def stripNullaryMethodType(tp: Type) = tp match { case NullaryMethodType(restpe) => restpe case tp => tp }
vprintln("[checker] checking select apply " + tree + "/" + tpe)
- transChildrenInOrder(tree, tpe, List(qual, fun), Nil)
+ transChildrenInOrder(tree, stripNullaryMethodType(tpe), List(qual, fun), Nil)
case Apply(fun, args) if fun.isTyped =>
@@ -406,7 +407,7 @@ abstract class CPSAnnotationChecker extends CPSUtils {
// we have to do it here so we don't lose the cps information (wouldn't trigger our
// adapt and there is no Apply/TypeApply created)
tpe match {
- case PolyType(List(), restpe) =>
+ case NullaryMethodType(restpe) =>
//println("yep: " + restpe + "," + restpe.getClass)
transChildrenInOrder(tree, restpe, List(qual), Nil)
case _ : PolyType => tpe
diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala
index 07a9e5fed5..78cc8f7ff7 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala
@@ -50,8 +50,8 @@ abstract class SelectiveCPSTransform extends PluginComponent with
def transformCPSType(tp: Type): Type = { // TODO: use a TypeMap? need to handle more cases?
tp match {
case PolyType(params,res) => PolyType(params, transformCPSType(res))
- case MethodType(params,res) =>
- MethodType(params, transformCPSType(res))
+ case NullaryMethodType(res) => NullaryMethodType(transformCPSType(res))
+ case MethodType(params,res) => MethodType(params, transformCPSType(res))
case TypeRef(pre, sym, args) => TypeRef(pre, sym, args.map(transformCPSType(_)))
case _ =>
getExternalAnswerTypeAnn(tp) match {