@@ -28,13 +28,9 @@ import Data.IntMap (IntMap)
2828-- UseMap maps names to the set of used (reachable) argument positions.
2929type UseMap = Map Name IntSet
3030
31−-- Deps augmented with cached info.
32−-- fst = deps
33−-- snd = all names that the function depends on
34−type Deps' = (Deps, Set Name)
35−
36−-- DepMap maps functions (only functions) to their Deps'.
37−type DepMap = Map Name Deps'
31+-- DepMap maps functions (only functions) to their Deps.
32+type DepMap = Map Name Deps
33+type FlatMap = Map (Name, Int) (Set (Ctors, Cond))
3834
3935-- Deps of a function is a map from argument index
4036-- to all usages of the argument, including conditions
@@ -58,8 +54,21 @@ type Vars = Map Name Var
5854type PatVar = Ctors -> Var
5955type PatVars = Map Name PatVar
6056
57+{-
58+-- Find the minimal consistent usage by forward chaining.
6159minimalUsage :: DepMap -> UseMap
62−minimalUsage dmap = undefined
60+minimalUsage dmap =
61+ where
62+ flatten :: DepMap -> FlatMap
63+ flatten
64+
65+ trivials :: DepMap
66+ trivials = M.mapMaybeWithKey isTrivial dmap
67+
68+ isTrivial :: Name -> (Deps, Set Name) -> Maybe (Deps, Set Name)
69+ isTrivial n (deps, ns)
70+ where
71+-}
6372
6473-- Build the dependency graph,
6574-- starting the depth-first search from a list of Names.
@@ -73,7 +82,7 @@ buildDepMap ctx ns = dfs M.empty ns
7382 dfs dmap [] = dmap
7483 dfs dmap (n : ns)
7584 | n `M.member` dmap = dfs dmap ns
76− | otherwise = dfs (M.insert n (deps, depn) dmap) ns
85+ | otherwise = dfs (M.insert n deps dmap) ns
7786 where
7887 next = [n | n <- S.toList depn, n `M.notMember` dmap]
7988 depn = S.delete n (depNames deps)