Skip to content

Commit 491b6b7

Browse files
committed
Maybe just ignore in inline defs
1 parent e013a1b commit 491b6b7

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,28 +173,20 @@ private sealed trait WarningSettings:
173173
choices = List(
174174
ChoiceWithHelp("nowarn", ""),
175175
ChoiceWithHelp("all", ""),
176-
ChoiceWithHelp(
177-
name = "imports",
178-
description = "Warn if an import selector is not referenced.\n" +
179-
"NOTE : overrided by -Wunused:strict-no-implicit-warn"),
176+
ChoiceWithHelp("imports", "Warn if an import selector is not referenced."),
180177
ChoiceWithHelp("privates", "Warn if a private member is unused"),
181178
ChoiceWithHelp("locals", "Warn if a local definition is unused"),
182179
ChoiceWithHelp("explicits", "Warn if an explicit parameter is unused"),
183180
ChoiceWithHelp("implicits", "Warn if an implicit parameter is unused"),
184181
ChoiceWithHelp("params", "Enable -Wunused:explicits,implicits"),
185182
ChoiceWithHelp("patvars","Warn if a variable bound in a pattern is unused"),
183+
ChoiceWithHelp("inlined", "Apply -Wunused to inlined expansions"),
186184
ChoiceWithHelp("linted", "Enable -Wunused:imports,privates,locals,implicits"),
187185
ChoiceWithHelp(
188186
name = "strict-no-implicit-warn",
189187
description = "Same as -Wunused:import, only for imports of explicit named members.\n" +
190188
"NOTE : This overrides -Wunused:imports and NOT set by -Wunused:all"
191189
),
192-
ChoiceWithHelp(
193-
name = "unsafe-warn-patvars",
194-
description = "(UNSAFE) Warn if a variable bound in a pattern is unused.\n" +
195-
"This warning can generate false positive, as warning cannot be\n" +
196-
"suppressed yet."
197-
)
198190
),
199191
default = Nil
200192
)
@@ -206,7 +198,6 @@ private sealed trait WarningSettings:
206198
// Is any choice set for -Wunused?
207199
def any(using Context): Boolean = Wall.value || Wunused.value.nonEmpty
208200

209-
// overrided by strict-no-implicit-warn
210201
def imports(using Context) =
211202
(allOr("imports") || allOr("linted")) && !(strictNoImplicitWarn)
212203
def locals(using Context) =
@@ -220,9 +211,8 @@ private sealed trait WarningSettings:
220211
def params(using Context) = allOr("params")
221212
def privates(using Context) =
222213
allOr("privates") || allOr("linted")
223-
def patvars(using Context) =
224-
allOr("patvars")
225-
//isChoiceSet("unsafe-warn-patvars") // not with "all"
214+
def patvars(using Context) = allOr("patvars")
215+
def inlined(using Context) = isChoiceSet("inlined")
226216
def linted(using Context) =
227217
allOr("linted")
228218
def strictNoImplicitWarn(using Context) =

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
124124
refInfos.inlined.push(tree.call.srcPos)
125125
ctx
126126
override def transformInlined(tree: Inlined)(using Context): tree.type =
127-
val _ = refInfos.inlined.pop()
127+
//val _ = refInfos.inlined.pop()
128+
val prev = refInfos.inlined.pop()
128129
if !tree.call.isEmpty && phaseMode.eq(PhaseMode.Aggregate) then
129130
transformAllDeep(tree.call)
130131
tree
@@ -176,10 +177,15 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
176177
def trivial = tree.symbol.is(Deferred) || isUnconsuming(tree.rhs)
177178
def nontrivial = tree.symbol.isConstructor || tree.symbol.isAnonymousFunction
178179
if !nontrivial && trivial then refInfos.skip.addOne(tree.symbol)
179-
refInfos.register(tree)
180+
if tree.symbol.is(Inline) then
181+
refInfos.inliners += 1
182+
else
183+
refInfos.register(tree)
180184
ctx
181185
override def transformDefDef(tree: DefDef)(using Context): tree.type =
182186
traverseAnnotations(tree.symbol)
187+
if tree.symbol.is(Inline) then
188+
refInfos.inliners -= 1
183189
tree
184190

185191
override def transformTypeDef(tree: TypeDef)(using Context): tree.type =
@@ -427,10 +433,11 @@ object CheckUnused:
427433
val skip = mutable.Set.empty[Symbol] // methods to skip (don't warn about their params)
428434
val imps = new IdentityHashMap[Import, Unit] // imports
429435
val sels = new IdentityHashMap[ImportSelector, Unit] // matched selectors
430-
def register(tree: Tree)(using Context): Unit =
436+
def register(tree: Tree)(using Context): Unit = if inlined.isEmpty then
431437
tree match
432438
case imp: Import =>
433-
if languageImport(imp.expr).isEmpty
439+
if inliners == 0
440+
&& languageImport(imp.expr).isEmpty
434441
&& !imp.isGeneratedByEnum
435442
then
436443
imps.put(imp, ())
@@ -449,6 +456,7 @@ object CheckUnused:
449456

450457
var isRepl = false // have we seen a REPL artifact? avoid import warning, for example
451458
val inlined = Stack.empty[SrcPos] // enclosing call.srcPos of inlined code
459+
var inliners = 0 // depth of inline def
452460
end RefInfos
453461

454462
// Symbols already resolved in the given Context (with name and prefix of lookup)

0 commit comments

Comments
 (0)