Skip to content

Commit c00974c

Browse files
committed
Elim ElimWildcardIdents
Instead of cleaning up, generate sensical code in the first place. This is shorter and (I would argue) clearer, and also has the advantage that some initializing assignments are not generated at all.
1 parent 55c6d08 commit c00974c

File tree

6 files changed

+12
-46
lines changed

6 files changed

+12
-46
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class Compiler {
7171
List(new LambdaLift, // in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
7272
new Flatten,
7373
new ElimStaticThis,
74-
new ElimWildcardIdents,
7574
new RestoreScopes),
7675
List(/*new PrivateToStatic,*/
7776
new ExpandPrivate,

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
723723
def ensureConforms(tp: Type)(implicit ctx: Context): Tree =
724724
if (tree.tpe <:< tp) tree else asInstance(tp)
725725

726+
/** If inititializer tree is `_', the default value of its type,
727+
* otherwise the tree itself.
728+
*/
729+
def wildcardToDefault(implicit ctx: Context) =
730+
if (isWildcardArg(tree)) defaultValue(tree.tpe) else tree
731+
726732
/** `this && that`, for boolean trees `this`, `that` */
727733
def and(that: Tree)(implicit ctx: Context): Tree =
728734
tree.select(defn.Boolean_&&).appliedTo(that)

src/dotty/tools/dotc/transform/ElimWildcardIdents.scala

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

src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
146146

147147
def mkNonThreadSafeDef(target: Tree, flag: Tree, rhs: Tree)(implicit ctx: Context) = {
148148
val setFlag = flag.becomes(Literal(Constants.Constant(true)))
149-
val setTarget = target.becomes(rhs)
150-
val init = Block(List(setFlag, setTarget), target.ensureApplied)
149+
val setTargets = if (isWildcardArg(rhs)) Nil else target.becomes(rhs) :: Nil
150+
val init = Block(setFlag :: setTargets, target.ensureApplied)
151151
If(flag.ensureApplied, target.ensureApplied, init)
152152
}
153153

src/dotty/tools/dotc/transform/Memoize.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ import Decorators._
5555
lazy val field = sym.field.orElse(newField).asTerm
5656
if (sym.is(Accessor, butNot = NoFieldNeeded))
5757
if (sym.isGetter) {
58-
tree.rhs.changeOwnerAfter(sym, field, thisTransform)
59-
val fieldDef = transformFollowing(ValDef(field, tree.rhs))
58+
var rhs = tree.rhs.changeOwnerAfter(sym, field, thisTransform)
59+
if (isWildcardArg(rhs)) rhs = EmptyTree
60+
val fieldDef = transformFollowing(ValDef(field, rhs))
6061
val getterDef = cpy.DefDef(tree)(rhs = transformFollowingDeep(ref(field)))
6162
Thicket(fieldDef, getterDef)
6263
}

src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
118118
val isym = initializer(vsym)
119119
val rhs = Block(
120120
initBuf.toList.map(_.changeOwner(impl.symbol, isym)),
121-
stat.rhs.changeOwner(vsym, isym))
121+
stat.rhs.changeOwner(vsym, isym).wildcardToDefault)
122122
initBuf.clear()
123123
cpy.DefDef(stat)(rhs = EmptyTree) :: DefDef(isym, rhs) :: Nil
124124
case stat: DefDef if stat.symbol.isSetter =>

0 commit comments

Comments
 (0)