11package dotty .tools .dotc .transform
22
3- import scala .annotation .tailrec
3+ import scala .annotation .*
44
55import dotty .tools .uncheckedNN
66import dotty .tools .dotc .ast .tpd .*
@@ -301,7 +301,7 @@ object CheckUnused:
301301 *
302302 * For other contexts, which symbols defined here have been referenced?
303303 */
304- private class UnusedData :
304+ private class UnusedData ( using Context @ constructorOnly) :
305305 import collection .mutable as mut , mut .Stack , mut .ListBuffer
306306 import UnusedData .*
307307
@@ -330,8 +330,13 @@ object CheckUnused:
330330
331331 /** All used symbols */
332332 private val usedDef = mut.Set .empty[Symbol ]
333- /** Do not register as used */
334- private val doNotRegister = mut.Set .empty[Symbol ]
333+
334+ /** Do not register as used.
335+ *
336+ * Seed with common symbols that are never warnable, as an optimization.
337+ */
338+ private val doNotRegister = mut.Set [Symbol ](defn.SourceFileAnnot , defn.ModuleSerializationProxyClass )
339+ private val doNotRegisterPrefix = mut.Set [Symbol ](defn.ScalaRuntimePackageClass )
335340
336341 /** Trivial definitions, avoid registering params */
337342 private val trivialDefs = mut.Set .empty[Symbol ]
@@ -355,7 +360,7 @@ object CheckUnused:
355360 * as the same element can be imported with different renaming.
356361 */
357362 def registerUsed (sym : Symbol , name : Option [Name ], prefix : Type = NoType , includeForImport : Boolean = true )(using Context ): Unit =
358- if sym.exists && ! isConstructorOfSynth(sym) && ! doNotRegister(sym) then
363+ if sym.exists && ! isConstructorOfSynth(sym) && ! doNotRegister(sym) && ! doNotRegisterPrefix(prefix.typeSymbol) then
359364 if sym.isConstructor then
360365 // constructors are "implicitly" imported with the class
361366 registerUsed(sym.owner, name = None , prefix, includeForImport = includeForImport)
0 commit comments