on 1238607 help sign in
87 lines 2.8 kB history raw
1module Nitpick.Debug
2 ( hasDebugUses
3 )
4 where
7import qualified Data.Map.Utils as Map
9import qualified AST.Optimized as Opt
13-- HAS DEBUG USES
16hasDebugUses :: Opt.LocalGraph -> Bool
17hasDebugUses (Opt.LocalGraph _ graph _) =
18 Map.any nodeHasDebug graph
21nodeHasDebug :: Opt.Node -> Bool
22nodeHasDebug node =
23 case node of
24 Opt.Define expr _ -> hasDebug expr
25 Opt.DefineTailFunc _ expr _ -> hasDebug expr
26 Opt.Ctor _ _ -> False
27 Opt.Enum _ -> False
28 Opt.Box -> False
29 Opt.Link _ -> False
30 Opt.Cycle _ vs fs _ -> any (hasDebug . snd) vs || any defHasDebug fs
31 Opt.Manager _ -> False
32 Opt.Kernel _ _ -> False
33 Opt.PortIncoming expr _ -> hasDebug expr
34 Opt.PortOutgoing expr _ -> hasDebug expr
37hasDebug :: Opt.Expr -> Bool
38hasDebug expression =
39 case expression of
40 Opt.Bool _ -> False
41 Opt.Chr _ -> False
42 Opt.Str _ -> False
43 Opt.Int _ -> False
44 Opt.Float _ -> False
45 Opt.VarLocal _ -> False
46 Opt.VarGlobal _ -> False
47 Opt.VarEnum _ _ -> False
48 Opt.VarBox _ -> False
49 Opt.VarCycle _ _ -> False
50 Opt.VarDebug _ _ _ _ -> True
51 Opt.VarKernel _ _ -> False
52 Opt.List exprs -> any hasDebug exprs
53 Opt.Function _ expr -> hasDebug expr
54 Opt.Call e es -> hasDebug e || any hasDebug es
55 Opt.TailCall _ args -> any (hasDebug . snd) args
56 Opt.If conds finally -> any (\(c,e) -> hasDebug c || hasDebug e) conds || hasDebug finally
57 Opt.Let def body -> defHasDebug def || hasDebug body
58 Opt.Destruct _ expr -> hasDebug expr
59 Opt.Case _ _ d jumps -> deciderHasDebug d || any (hasDebug . snd) jumps
60 Opt.Accessor _ -> False
61 Opt.Access r _ -> hasDebug r
62 Opt.Update r fs -> hasDebug r || any hasDebug fs
63 Opt.Record fs -> any hasDebug fs
64 Opt.Unit -> False
65 Opt.Tuple a b c -> hasDebug a || hasDebug b || maybe False hasDebug c
66 Opt.Shader _ _ _ -> False
69defHasDebug :: Opt.Def -> Bool
70defHasDebug def =
71 case def of
72 Opt.Def _ expr -> hasDebug expr
73 Opt.TailDef _ _ expr -> hasDebug expr
76deciderHasDebug :: Opt.Decider Opt.Choice -> Bool
77deciderHasDebug decider =
78 case decider of
79 Opt.Leaf (Opt.Inline expr) -> hasDebug expr
80 Opt.Leaf (Opt.Jump _) -> False
81 Opt.Chain _ success failure -> deciderHasDebug success || deciderHasDebug failure
82 Opt.FanOut _ tests fallback -> any (deciderHasDebug . snd) tests || deciderHasDebug fallback
86-- TODO: FIND GLOBALLY UNUSED DEFINITIONS?
87-- TODO: FIND PACKAGE USAGE STATS? (e.g. elm/core = 142, author/project = 2, etc.)