File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -743,6 +743,8 @@ object Symbols {
743743 def keysIterator : Iterator [Symbol ] = value.keySet().asScala.iterator
744744
745745 def toMap : Map [Symbol , T ] = value.asScala.toMap
746+
747+ override def toString : String = value.asScala.toString()
746748 }
747749
748750 @ inline def newMutableSymbolMap [T ]: MutableSymbolMap [T ] =
Original file line number Diff line number Diff line change @@ -159,6 +159,12 @@ class Devalify extends Optimisation {
159159 if (replacements.contains(t.symbol))
160160 deepReplacer.transform(replacements(t.symbol)).ensureConforms(t.tpe.widen)
161161 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+ }
162168 case tree => tree
163169 }
164170
Original file line number Diff line number Diff line change @@ -164,6 +164,35 @@ abstract class SimplifyTests(val optimise: Boolean) extends DottyBytecodeTest {
164164 |print(8)
165165 """ )
166166
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+
167196 // @Test def listPatmapExample =
168197 // check(
169198 // """
You can’t perform that action at this time.
0 commit comments