Skip to content

Commit 3f7acb2

Browse files
committed
Add config for reporting transitively dead things.
This is the normal behaviour: no change. When turned off, only the top dead things, and not the transitive ones, are reported.
1 parent dc355a6 commit 3f7acb2

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

analysis/reanalyze/src/Common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ type decl = {
197197
pos: Lexing.position;
198198
posEnd: Lexing.position;
199199
posStart: Lexing.position;
200-
mutable resolved: bool;
200+
mutable resolvedDead: bool option;
201201
mutable report: bool;
202202
}
203203

analysis/reanalyze/src/DeadCommon.ml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Config = struct
1313
let analyzeTypes = ref true
1414
let analyzeExternals = ref false
1515
let reportUnderscore = false
16+
let reportTransitive = true
1617
let reportTypesDeadOnlyInInterface = false
1718
let recursiveDebug = false
1819
let warnOnCircularDependencies = false
@@ -375,7 +376,7 @@ let addDeclaration_ ?posEnd ?posStart ~declKind ~path ~(loc : Location.t)
375376
pos;
376377
posEnd;
377378
posStart;
378-
resolved = false;
379+
resolvedDead = None;
379380
report = true;
380381
}
381382
in
@@ -536,12 +537,21 @@ module Decl = struct
536537
| VariantCase ->
537538
(WarningDeadType, "is a variant case which is never constructed")
538539
in
540+
let hasRefBelow () =
541+
let refs = ValueReferences.find decl.pos in
542+
let refIsBelow (pos : Lexing.position) =
543+
decl.pos.pos_fname <> pos.pos_fname
544+
|| decl.pos.pos_cnum < pos.pos_cnum
545+
&& decl.posEnd.pos_cnum < pos.pos_cnum
546+
in
547+
refs |> PosSet.exists refIsBelow
548+
in
539549
let shouldEmitWarning =
540550
(not insideReportedValue)
541-
&&
542-
match decl.path with
543-
| name :: _ when name |> Name.isUnderscore -> Config.reportUnderscore
544-
| _ -> true
551+
&& (match decl.path with
552+
| name :: _ when name |> Name.isUnderscore -> Config.reportUnderscore
553+
| _ -> true)
554+
&& (Config.reportTransitive || not (hasRefBelow ()))
545555
in
546556
if shouldEmitWarning then (
547557
decl.path
@@ -563,7 +573,7 @@ let doReportDead pos = not (ProcessDeadAnnotations.isAnnotatedGenTypeOrDead pos)
563573
let rec resolveRecursiveRefs ~checkOptionalArg ~deadDeclarations ~level
564574
~orderedFiles ~refs ~refsBeingResolved decl : bool =
565575
match decl.pos with
566-
| _ when decl.resolved ->
576+
| _ when decl.resolvedDead <> None ->
567577
if Config.recursiveDebug then
568578
Log_.item "recursiveDebug %s [%d] already resolved@."
569579
(decl.path |> Path.toString)
@@ -609,13 +619,13 @@ let rec resolveRecursiveRefs ~checkOptionalArg ~deadDeclarations ~level
609619
~level:(level + 1) ~orderedFiles ~refs:xRefs
610620
~refsBeingResolved
611621
in
612-
if not xDecl.resolved then allDepsResolved := false;
622+
if xDecl.resolvedDead = None then allDepsResolved := false;
613623
not xDeclIsDead)
614624
in
615625
let isDead = decl |> declIsDead ~refs:newRefs in
616626
let isResolved = (not isDead) || !allDepsResolved || level = 0 in
617627
if isResolved then (
618-
decl.resolved <- true;
628+
decl.resolvedDead <- Some isDead;
619629
if isDead then (
620630
decl.path
621631
|> DeadModules.markDead
@@ -691,4 +701,5 @@ let reportDead ~checkOptionalArg =
691701
let sortedDeadDeclarations =
692702
!deadDeclarations |> List.fast_sort Decl.compareForReporting
693703
in
704+
(* XXX *)
694705
sortedDeadDeclarations |> List.iter Decl.report

0 commit comments

Comments
 (0)