aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Doeraene <sjrdoeraene@gmail.com>2016-03-05 01:08:18 +0100
committerSébastien Doeraene <sjrdoeraene@gmail.com>2016-03-07 14:41:36 +0100
commitc14c9c096d09d9e21f1fd4ec27e6b416db01512f (patch)
tree628838c31d6d2ca6c46bb5591882501cdb608030 /src
parenta50926701ef5171779aa025d2d307751d166cabe (diff)
downloaddotty-c14c9c096d09d9e21f1fd4ec27e6b416db01512f.tar.gz
dotty-c14c9c096d09d9e21f1fd4ec27e6b416db01512f.tar.bz2
dotty-c14c9c096d09d9e21f1fd4ec27e6b416db01512f.zip
Move the logic of ExpandSAMs.isJvmSam to Platform.isSam.
Whether a language SAM type is also a valid SAM type for the back-end is a platform-specific thing. On Scala.js, for example, the rules are completely different than for the JVM. This commit therefore moves the logic of the predicate used by ExpandSAMs to decide whether to expand a SAM as an anonymous class to the Platform.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/config/JavaPlatform.scala9
-rw-r--r--src/dotty/tools/dotc/config/Platform.scala3
-rw-r--r--src/dotty/tools/dotc/transform/ExpandSAMs.scala12
3 files changed, 16 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/config/JavaPlatform.scala b/src/dotty/tools/dotc/config/JavaPlatform.scala
index 432a9a0b7..433b5b3f0 100644
--- a/src/dotty/tools/dotc/config/JavaPlatform.scala
+++ b/src/dotty/tools/dotc/config/JavaPlatform.scala
@@ -7,6 +7,7 @@ import ClassPath.{ JavaContext, DefaultJavaContext }
import core._
import Symbols._, Types._, Contexts._, Denotations._, SymDenotations._, StdNames._, Names._
import Flags._, Scopes._, Decorators._, NameOps._, util.Positions._
+import transform.ExplicitOuter, transform.SymUtils._
class JavaPlatform extends Platform {
@@ -38,6 +39,14 @@ class JavaPlatform extends Platform {
def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = new ctx.base.loaders.PackageLoader(root, classPath)
+ /** Is the SAMType `cls` also a SAM under the rules of the JVM? */
+ def isSam(cls: ClassSymbol)(implicit ctx: Context): Boolean =
+ cls.is(NoInitsTrait) &&
+ cls.superClass == defn.ObjectClass &&
+ cls.directlyInheritedTraits.forall(_.is(NoInits)) &&
+ !ExplicitOuter.needsOuterIfReferenced(cls) &&
+ cls.typeRef.fields.isEmpty // Superaccessors already show up as abstract methods here, so no test necessary
+
/** We could get away with excluding BoxedBooleanClass for the
* purpose of equality testing since it need not compare equal
* to anything but other booleans, but it should be present in
diff --git a/src/dotty/tools/dotc/config/Platform.scala b/src/dotty/tools/dotc/config/Platform.scala
index 972892d12..062d9002d 100644
--- a/src/dotty/tools/dotc/config/Platform.scala
+++ b/src/dotty/tools/dotc/config/Platform.scala
@@ -27,6 +27,9 @@ abstract class Platform {
/** Any platform-specific phases. */
//def platformPhases: List[SubComponent]
+ /** Is the SAMType `cls` also a SAM under the rules of the platform? */
+ def isSam(cls: ClassSymbol)(implicit ctx: Context): Boolean
+
/** The various ways a boxed primitive might materialize at runtime. */
def isMaybeBoxed(sym: ClassSymbol)(implicit ctx: Context): Boolean
diff --git a/src/dotty/tools/dotc/transform/ExpandSAMs.scala b/src/dotty/tools/dotc/transform/ExpandSAMs.scala
index 5de778fab..58771734a 100644
--- a/src/dotty/tools/dotc/transform/ExpandSAMs.scala
+++ b/src/dotty/tools/dotc/transform/ExpandSAMs.scala
@@ -25,13 +25,9 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer =>
import ast.tpd._
- /** Is SAMType `cls` also a SAM under the rules of the JVM? */
- def isJvmSam(cls: ClassSymbol)(implicit ctx: Context): Boolean =
- cls.is(NoInitsTrait) &&
- cls.superClass == defn.ObjectClass &&
- cls.directlyInheritedTraits.forall(_.is(NoInits)) &&
- !ExplicitOuter.needsOuterIfReferenced(cls) &&
- cls.typeRef.fields.isEmpty // Superaccessors already show up as abstract methods here, so no test necessary
+ /** Is the SAMType `cls` also a SAM under the rules of the platform? */
+ def isPlatformSam(cls: ClassSymbol)(implicit ctx: Context): Boolean =
+ ctx.platform.isSam(cls)
override def transformBlock(tree: Block)(implicit ctx: Context, info: TransformerInfo): Tree = tree match {
case Block(stats @ (fn: DefDef) :: Nil, Closure(_, fnRef, tpt)) if fnRef.symbol == fn.symbol =>
@@ -39,7 +35,7 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer =>
case NoType => tree // it's a plain function
case tpe @ SAMType(_) if tpe.isRef(defn.PartialFunctionClass) =>
toPartialFunction(tree)
- case tpe @ SAMType(_) if isJvmSam(tpe.classSymbol.asClass) =>
+ case tpe @ SAMType(_) if isPlatformSam(tpe.classSymbol.asClass) =>
tree
case tpe =>
cpy.Block(tree)(stats,