Skip to content

Commit 7a40ed1

Browse files
committed
Add plain function tests to NameOps and Definitions
1 parent 1801a1f commit 7a40ed1

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Compiler {
6464
new ShortcutImplicits, // Allow implicit functions without creating closures
6565
new CrossCastAnd, // Normalize selections involving intersection types.
6666
new Splitter, // Expand selections involving union types into conditionals
67-
new SpecializeFunction1), // Specialized Function1 by replacing super with specialized super
67+
new SpecializeFunctions), // Specialized Function1 by replacing super with specialized super
6868
List(new VCInlineMethods, // Inlines calls to value class methods
6969
new IsInstanceOfEvaluator, // Issues warnings when unreachable statements are present in match/if expressions
7070
new SeqLiterals, // Express vararg arguments as arrays

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,17 @@ class Definitions {
726726
def isBottomType(tp: Type) =
727727
tp.derivesFrom(NothingClass) || tp.derivesFrom(NullClass)
728728

729-
/** Is a function class.
729+
/** Is any function class that satisfies:
730730
* - FunctionN for N >= 0
731731
* - ImplicitFunctionN for N >= 0
732732
*/
733733
def isFunctionClass(cls: Symbol) = scalaClassName(cls).isFunction
734734

735+
/** Is a function class where
736+
* - FunctionN for N >= 0
737+
*/
738+
def isPlainFunctionClass(cls: Symbol) = scalaClassName(cls).isPlainFunction
739+
735740
/** Is an implicit function class.
736741
* - ImplicitFunctionN for N >= 0
737742
*/

compiler/src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,17 @@ object NameOps {
240240
def functionArity: Int =
241241
functionArityFor(tpnme.Function) max functionArityFor(tpnme.ImplicitFunction)
242242

243-
/** Is a function name
243+
/** Is any function name that satisfies
244244
* - FunctionN for N >= 0
245245
* - ImplicitFunctionN for N >= 0
246-
* - false otherwise
247246
*/
248247
def isFunction: Boolean = functionArity >= 0
249248

249+
/** Is a function name
250+
* - FunctionN for N >= 0
251+
*/
252+
def isPlainFunction: Boolean = functionArityFor(tpnme.Function) >= 0
253+
250254
/** Is a implicit function name
251255
* - ImplicitFunctionN for N >= 0
252256
* - false otherwise

compiler/src/dotty/tools/dotc/transform/SpecializeFunction1.scala renamed to compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Contexts.Context, Types._, Decorators._, Symbols._, DenotTransformers._
88
import Denotations._, SymDenotations._, Scopes._, StdNames._, NameOps._, Names._
99
import ast.tpd
1010

11-
class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
11+
class SpecializeFunctions extends MiniPhaseTransform with DenotTransformer {
1212
import ast.tpd._
1313

1414
val phaseName = "specializeFunction1"
@@ -180,7 +180,7 @@ class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
180180
// Extractors ----------------------------------------------------------------
181181
private object ShouldTransformDenot {
182182
def unapply(cref: ClassDenotation)(implicit ctx: Context): Option[Seq[SpecializationTarget]] =
183-
if (!cref.classParents.map(_.symbol).exists(defn.isFunctionClass)) None
183+
if (!cref.classParents.map(_.symbol).exists(defn.isPlainFunctionClass)) None
184184
else Some(getSpecTargets(cref.typeRef))
185185
}
186186

@@ -207,7 +207,7 @@ class SpecializeFunction1 extends MiniPhaseTransform with DenotTransformer {
207207
val functionParents =
208208
tpe.classSymbols.iterator
209209
.flatMap(_.baseClasses)
210-
.filter(defn.isFunctionClass)
210+
.filter(defn.isPlainFunctionClass)
211211

212212
val tpeCls = tpe.widenDealias
213213
functionParents.map { sym =>

compiler/test/dotty/tools/dotc/transform/SpecializeFunction1Tests.scala renamed to compiler/test/dotty/tools/dotc/transform/SpecializeFunctionsTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.junit.Test
77

88
import dotty.tools.backend.jvm.DottyBytecodeTest
99

10-
class SpecializeFunction1Tests extends DottyBytecodeTest {
10+
class SpecializeFunctionsTests extends DottyBytecodeTest {
1111

1212
import dotty.tools.backend.jvm.ASMConverters._
1313
import dotty.tools.backend.jvm.AsmNode._
@@ -89,6 +89,5 @@ class SpecializeFunction1Tests extends DottyBytecodeTest {
8989
}
9090
.getOrElse(assert(false, "Could not find constructor for object `Test`"))
9191
}
92-
9392
}
9493
}

0 commit comments

Comments
 (0)