Skip to content

Commit a2a10e6

Browse files
committed
Drop ElimByName and ByNameClosures phases
1 parent 253b491 commit a2a10e6

14 files changed

+93
-315
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class Compiler {
7474
new ProtectedAccessors, // Add accessors for protected members
7575
new ExtensionMethods, // Expand methods of value classes with extension methods
7676
new UncacheGivenAliases, // Avoid caching RHS of simple parameterless given aliases
77-
new ByNameClosures, // Expand arguments to by-name parameters to closures
7877
new HoistSuperArgs, // Hoist complex arguments of supercalls to enclosing scope
7978
new SpecializeApplyMethods, // Adds specialized methods to FunctionN
8079
new RefChecks, // Various checks mostly related to abstract members and overriding
@@ -84,7 +83,6 @@ class Compiler {
8483
new sjs.ExplicitJSClasses, // Make all JS classes explicit (Scala.js only)
8584
new ExplicitOuter, // Add accessors to outer classes from nested ones.
8685
new ExplicitSelf, // Make references to non-trivial self types explicit as casts
87-
new ElimByName, // Expand by-name parameter references
8886
new StringInterpolatorOpt) :: // Optimizes raw and s string interpolators by rewriting them to string concatenations
8987
List(new PruneErasedDefs, // Drop erased definitions from scopes and simplify erased expressions
9088
new UninitializedDefs, // Replaces `compiletime.uninitialized` by `_`

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,6 @@ class Definitions {
447447
@tu lazy val andType: TypeSymbol = enterBinaryAlias(tpnme.AND, AndType(_, _))
448448
@tu lazy val orType: TypeSymbol = enterBinaryAlias(tpnme.OR, OrType(_, _, soft = false))
449449

450-
/** Marker method to indicate an argument to a call-by-name parameter.
451-
* Created by byNameClosures and elimByName, eliminated by Erasure,
452-
*/
453-
@tu lazy val cbnArg: TermSymbol = enterPolyMethod(OpsPackageClass, nme.cbnArg, 1,
454-
pt => MethodType(List(FunctionOf(Nil, pt.paramRefs(0))), pt.paramRefs(0)))
455-
456450
/** Method representing a throw */
457451
@tu lazy val throwMethod: TermSymbol = enterMethod(OpsPackageClass, nme.THROWkw,
458452
MethodType(List(ThrowableType), NothingType))

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ object StdNames {
446446
val bytes: N = "bytes"
447447
val canEqual_ : N = "canEqual"
448448
val canEqualAny : N = "canEqualAny"
449-
val cbnArg: N = "<cbn-arg>"
450449
val checkInitialized: N = "checkInitialized"
451450
val ClassManifestFactory: N = "ClassManifestFactory"
452451
val classOf: N = "classOf"

compiler/src/dotty/tools/dotc/transform/ByNameClosures.scala

Lines changed: 0 additions & 40 deletions
This file was deleted.

compiler/src/dotty/tools/dotc/transform/ByNameLambda.scala

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,7 @@ import StdNames.nme
1010
import ast.Trees._
1111
import ast.TreeTypeMap
1212

13-
/** Rewrite an application
14-
*
15-
* (((x1, ..., xn) => b): T)(y1, ..., yn)
16-
*
17-
* where
18-
*
19-
* - all yi are pure references without a prefix
20-
* - the closure can also be contextual or erased, but cannot be a SAM type
21-
* _ the type ascription ...: T is optional
22-
*
23-
* to
24-
*
25-
* [xi := yi]b
26-
*
27-
* This is more limited than beta reduction in inlining since it only works for simple variables `yi`.
28-
* It is more general since it also works for type-ascripted closures.
29-
*
30-
* A typical use case is eliminating redundant closures for blackbox macros that
31-
* return context functions. See i6375.scala.
32-
*/
13+
/** Rewrite applications `<byname>(...)` to context closures `() ?=> ...` */
3314
class ByNameLambda extends MiniPhase:
3415
import ast.tpd._
3516

compiler/src/dotty/tools/dotc/transform/CollectNullableFields.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class CollectNullableFields extends MiniPhase {
4343

4444
override def phaseName: String = CollectNullableFields.name
4545

46-
/** Running after `ElimByName` to see by names as nullable types. */
47-
override def runsAfter: Set[String] = Set(ElimByName.name)
46+
/** Running after `ByNameLambda` to see by names as nullable types. */
47+
override def runsAfter: Set[String] = Set(ByNameLambda.name)
4848

4949
private sealed trait FieldInfo
5050
private case object NotNullable extends FieldInfo

compiler/src/dotty/tools/dotc/transform/ElimByName.scala

Lines changed: 0 additions & 80 deletions
This file was deleted.

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -805,49 +805,46 @@ object Erasure {
805805
*/
806806
override def typedApply(tree: untpd.Apply, pt: Type)(using Context): Tree =
807807
val Apply(fun, args) = tree
808-
if fun.symbol == defn.cbnArg then
809-
typedUnadapted(args.head, pt)
810-
else
811-
val origFun = fun.asInstanceOf[tpd.Tree]
812-
val origFunType = origFun.tpe.widen(using preErasureCtx)
813-
val ownArgs = if origFunType.isErasedMethod then Nil else args
814-
val fun1 = typedExpr(fun, AnyFunctionProto)
815-
fun1.tpe.widen match
816-
case mt: MethodType =>
817-
val (xmt, // A method type like `mt` but with bunched arguments expanded to individual ones
818-
bunchArgs, // whether arguments are bunched
819-
outers) = // the outer reference parameter(s)
820-
if fun1.isInstanceOf[Apply] then
821-
(mt, fun1.removeAttachment(BunchedArgs).isDefined, Nil)
822-
else
823-
val xmt = expandedMethodType(mt, origFun)
824-
(xmt, xmt ne mt, outer.args(origFun))
825-
826-
val args0 = outers ::: ownArgs
827-
val args1 = args0.zipWithConserve(xmt.paramInfos)(typedExpr)
828-
.asInstanceOf[List[Tree]]
829-
830-
def mkApply(finalFun: Tree, finalArgs: List[Tree]) =
831-
val app = untpd.cpy.Apply(tree)(finalFun, finalArgs)
832-
.withType(applyResultType(xmt, args1))
833-
if bunchArgs then app.withAttachment(BunchedArgs, ()) else app
834-
835-
def app(fun1: Tree): Tree = fun1 match
836-
case Block(stats, expr) =>
837-
cpy.Block(fun1)(stats, app(expr))
838-
case Apply(fun2, SeqLiteral(prevArgs, argTpt) :: _) if bunchArgs =>
839-
mkApply(fun2, JavaSeqLiteral(prevArgs ++ args1, argTpt) :: Nil)
840-
case Apply(fun2, prevArgs) =>
841-
mkApply(fun2, prevArgs ++ args1)
842-
case _ if bunchArgs =>
843-
mkApply(fun1, JavaSeqLiteral(args1, TypeTree(defn.ObjectType)) :: Nil)
844-
case _ =>
845-
mkApply(fun1, args1)
846-
847-
app(fun1)
848-
case t =>
849-
if ownArgs.isEmpty then fun1
850-
else throw new MatchError(i"tree $tree has unexpected type of function $fun/$fun1: $t, was $origFunType, args = $ownArgs")
808+
val origFun = fun.asInstanceOf[tpd.Tree]
809+
val origFunType = origFun.tpe.widen(using preErasureCtx)
810+
val ownArgs = if origFunType.isErasedMethod then Nil else args
811+
val fun1 = typedExpr(fun, AnyFunctionProto)
812+
fun1.tpe.widen match
813+
case mt: MethodType =>
814+
val (xmt, // A method type like `mt` but with bunched arguments expanded to individual ones
815+
bunchArgs, // whether arguments are bunched
816+
outers) = // the outer reference parameter(s)
817+
if fun1.isInstanceOf[Apply] then
818+
(mt, fun1.removeAttachment(BunchedArgs).isDefined, Nil)
819+
else
820+
val xmt = expandedMethodType(mt, origFun)
821+
(xmt, xmt ne mt, outer.args(origFun))
822+
823+
val args0 = outers ::: ownArgs
824+
val args1 = args0.zipWithConserve(xmt.paramInfos)(typedExpr)
825+
.asInstanceOf[List[Tree]]
826+
827+
def mkApply(finalFun: Tree, finalArgs: List[Tree]) =
828+
val app = untpd.cpy.Apply(tree)(finalFun, finalArgs)
829+
.withType(applyResultType(xmt, args1))
830+
if bunchArgs then app.withAttachment(BunchedArgs, ()) else app
831+
832+
def app(fun1: Tree): Tree = fun1 match
833+
case Block(stats, expr) =>
834+
cpy.Block(fun1)(stats, app(expr))
835+
case Apply(fun2, SeqLiteral(prevArgs, argTpt) :: _) if bunchArgs =>
836+
mkApply(fun2, JavaSeqLiteral(prevArgs ++ args1, argTpt) :: Nil)
837+
case Apply(fun2, prevArgs) =>
838+
mkApply(fun2, prevArgs ++ args1)
839+
case _ if bunchArgs =>
840+
mkApply(fun1, JavaSeqLiteral(args1, TypeTree(defn.ObjectType)) :: Nil)
841+
case _ =>
842+
mkApply(fun1, args1)
843+
844+
app(fun1)
845+
case t =>
846+
if ownArgs.isEmpty then fun1
847+
else throw new MatchError(i"tree $tree has unexpected type of function $fun/$fun1: $t, was $origFunType, args = $ownArgs")
851848
end typedApply
852849

853850
// The following four methods take as the proto-type the erasure of the pre-existing type,

0 commit comments

Comments
 (0)