on master help sign in
Add method deps.
27fbd56Matus Tejiscak
src/Idris/Erasure.hs+20−13
@@ -240,21 +240,18 @@ buildDepMap ci ctx mainName = addPostulates $ dfs S.empty M.empty [mainName]
240 -- to capture these dependencies as well
240 -- to capture these dependencies as well
241 etaIdx = [length vars .. length tys - 1]
241 etaIdx = [length vars .. length tys - 1]
242 etaVars = [eta i | i <- etaIdx]
242 etaVars = [eta i | i <- etaIdx]
243− etaMap = M.fromList [(eta i, VI
243+ etaMap = M.fromList [varPair (eta i) i | i <- etaIdx]
244− { viDeps = M.singleton (fn, Arg i) S.empty
245− , viFunArg = Just i
246− })
247− | i <- etaIdx]
248 eta i = MN i (pack "eta")
244 eta i = MN i (pack "eta")
249
245
250 -- the variables that arose as function arguments only depend on (n, i)
246 -- the variables that arose as function arguments only depend on (n, i)
251− varMap = M.fromList
247+ varMap = M.fromList [varPair v i | (v,i) <- zip vars [0..]]
252− [(v, VI
248+
249+ varPair n argNo = (n, VI
253− { viDeps = M.singleton (fn, Arg i) S.empty
250+ { viDeps = M.singleton (fn, Arg argNo) S.empty
254− , viFunArg = Just i
251+ , viFunArg = Just argNo
252+ , viMethod = Nothing
255− }
253+ })
256− )
254+
257− | (v,i) <- zip vars [0..]]
258 (vars, sc) = cases_runtime cdefs
255 (vars, sc) = cases_runtime cdefs
259 -- we use cases_runtime in order to have case-blocks
256 -- we use cases_runtime in order to have case-blocks
260 -- resolved to top-level functions before our analysis
257 -- resolved to top-level functions before our analysis
@@ -363,10 +360,20 @@ buildDepMap ci ctx mainName = addPostulates $ dfs S.empty M.empty [mainName]
363 -- a bound variable might draw in additional dependencies,
360 -- a bound variable might draw in additional dependencies,
364 -- think: f x = x 0 <-- here, `x' _is_ used
361 -- think: f x = x 0 <-- here, `x' _is_ used
365 P _ n _
362 P _ n _
363+ -- local name that refers to a method
366 | Just var <- M.lookup n vs
364 | Just var <- M.lookup n vs
365+ , Just (cn, i) <- viMethod var
366+ -> node (SN (WhereN i cn $ sMN i "field")) args
367+
368+ -- local name
369+ | Just var <- M.lookup n vs
370+ -- unconditional use
367 -> viDeps var `ins` unconditionalDeps args
371 -> viDeps var `ins` unconditionalDeps args
372+
373+ -- global name
368 | otherwise
374 | otherwise
369− -> node n args -- depends on whether the referred thing uses its argument
375+ -- depends on whether the referred thing uses its argument
376+ -> node n args
370
377
371 -- TODO: could we somehow infer how bound variables use their arguments?
378 -- TODO: could we somehow infer how bound variables use their arguments?
372 V i -> M.unionWith (M.unionWith S.union) ((bs !! i) cd) (unconditionalDeps args)
379 V i -> M.unionWith (M.unionWith S.union) ((bs !! i) cd) (unconditionalDeps args)