Skip to content

Add config for reporting transitively dead things. #601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
cristianoc committed Oct 21, 2022
commit cb3f31877cd26ca42d6cc8757486788624ef1d89
2 changes: 1 addition & 1 deletion analysis/reanalyze/src/Common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ type decl = {
pos: Lexing.position;
posEnd: Lexing.position;
posStart: Lexing.position;
mutable resolved: bool;
mutable resolvedDead: bool option;
mutable report: bool;
}

Expand Down
27 changes: 19 additions & 8 deletions analysis/reanalyze/src/DeadCommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Config = struct
let analyzeTypes = ref true
let analyzeExternals = ref false
let reportUnderscore = false
let reportTransitive = true
let reportTypesDeadOnlyInInterface = false
let recursiveDebug = false
let warnOnCircularDependencies = false
Expand Down Expand Up @@ -375,7 +376,7 @@ let addDeclaration_ ?posEnd ?posStart ~declKind ~path ~(loc : Location.t)
pos;
posEnd;
posStart;
resolved = false;
resolvedDead = None;
report = true;
}
in
Expand Down Expand Up @@ -536,12 +537,21 @@ module Decl = struct
| VariantCase ->
(WarningDeadType, "is a variant case which is never constructed")
in
let hasRefBelow () =
let refs = ValueReferences.find decl.pos in
let refIsBelow (pos : Lexing.position) =
decl.pos.pos_fname <> pos.pos_fname
|| decl.pos.pos_cnum < pos.pos_cnum
&& decl.posEnd.pos_cnum < pos.pos_cnum
in
refs |> PosSet.exists refIsBelow
in
let shouldEmitWarning =
(not insideReportedValue)
&&
match decl.path with
| name :: _ when name |> Name.isUnderscore -> Config.reportUnderscore
| _ -> true
&& (match decl.path with
| name :: _ when name |> Name.isUnderscore -> Config.reportUnderscore
| _ -> true)
&& (Config.reportTransitive || not (hasRefBelow ()))
in
if shouldEmitWarning then (
decl.path
Expand All @@ -563,7 +573,7 @@ let doReportDead pos = not (ProcessDeadAnnotations.isAnnotatedGenTypeOrDead pos)
let rec resolveRecursiveRefs ~checkOptionalArg ~deadDeclarations ~level
~orderedFiles ~refs ~refsBeingResolved decl : bool =
match decl.pos with
| _ when decl.resolved ->
| _ when decl.resolvedDead <> None ->
if Config.recursiveDebug then
Log_.item "recursiveDebug %s [%d] already resolved@."
(decl.path |> Path.toString)
Expand Down Expand Up @@ -609,13 +619,13 @@ let rec resolveRecursiveRefs ~checkOptionalArg ~deadDeclarations ~level
~level:(level + 1) ~orderedFiles ~refs:xRefs
~refsBeingResolved
in
if not xDecl.resolved then allDepsResolved := false;
if xDecl.resolvedDead = None then allDepsResolved := false;
not xDeclIsDead)
in
let isDead = decl |> declIsDead ~refs:newRefs in
let isResolved = (not isDead) || !allDepsResolved || level = 0 in
if isResolved then (
decl.resolved <- true;
decl.resolvedDead <- Some isDead;
if isDead then (
decl.path
|> DeadModules.markDead
Expand Down Expand Up @@ -691,4 +701,5 @@ let reportDead ~checkOptionalArg =
let sortedDeadDeclarations =
!deadDeclarations |> List.fast_sort Decl.compareForReporting
in
(* XXX *)
sortedDeadDeclarations |> List.iter Decl.report