File tree 3 files changed +37
-0
lines changed 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -743,6 +743,8 @@ object Symbols {
743
743
def keysIterator : Iterator [Symbol ] = value.keySet().asScala.iterator
744
744
745
745
def toMap : Map [Symbol , T ] = value.asScala.toMap
746
+
747
+ override def toString : String = value.asScala.toString()
746
748
}
747
749
748
750
@ inline def newMutableSymbolMap [T ]: MutableSymbolMap [T ] =
Original file line number Diff line number Diff line change @@ -159,6 +159,12 @@ class Devalify extends Optimisation {
159
159
if (replacements.contains(t.symbol))
160
160
deepReplacer.transform(replacements(t.symbol)).ensureConforms(t.tpe.widen)
161
161
else t
162
+ case t : DefDef if ! t.symbol.owner.isClass =>
163
+ if (timesUsed.getOrElse(t.symbol, 0 ) + timesUsedAsType.getOrElse(t.symbol, 0 ) != 0 ) t
164
+ else {
165
+ simplify.println(s " Dropping definition of ${t.symbol.showFullName} as not used " )
166
+ EmptyTree
167
+ }
162
168
case tree => tree
163
169
}
164
170
Original file line number Diff line number Diff line change @@ -164,6 +164,35 @@ abstract class SimplifyTests(val optimise: Boolean) extends DottyBytecodeTest {
164
164
|print(8)
165
165
""" )
166
166
167
+ @ Test def localDefinitionElimination =
168
+ check(
169
+ """
170
+ |lazy val foo = 1
171
+ |def bar = 2
172
+ |val baz = 3
173
+ """ ,
174
+ """
175
+ """ )
176
+
177
+ @ Test def localDefinitionNoElimination =
178
+ check(
179
+ """
180
+ |val j = 0 // dummy
181
+ |class Foo {
182
+ | lazy val foo = 1
183
+ | def bar = 2
184
+ | val baz = 3
185
+ |}
186
+ """ ,
187
+ """
188
+ |class Foo {
189
+ | lazy val foo = 1
190
+ | def bar = 2
191
+ | val baz = 3
192
+ |}
193
+ """ )
194
+
195
+
167
196
// @Test def listPatmapExample =
168
197
// check(
169
198
// """
You can’t perform that action at this time.
0 commit comments