on master help sign in
More small fixes.
commit7688a12f85dba9d90cfc573268bd384749d7721a authorMatus Tejiscak <ziman@functor.sk> dateMon 17 Feb 2014, 17:58 (13 years ago) parent73d95bb
3 files changed+26−10
src/IRTS/Compiler.hs+10−6 src/Idris/Core/CaseTree.hs+10 src/Idris/Erasure.hs+6−4
src/IRTS/Compiler.hs+10−6
@@ -222,10 +222,9 @@ instance ToIR (TT Name) where
222222
223223 | (P (DCon t a) n _, args) <- unApply tm = do
224224 cg <- idris_callgraph <$> getIState
225− case lookupCtxtExact n cg of
226− Just (CGInfo _ _ _ _ usedpos)
227− -> irCon env t a n [if i `elem` map fst usedpos then a else Erased | (i,a) <- zip [0..] args]
228− Nothing -> return LNothing -- no usage info -> not used at all
225+ let used = maybe [] (map fst . usedpos) $ lookupCtxtExact n cg
226+ args' = [if i `elem` used then a else Erased | (i,a) <- zip [0..] args]
227+ irCon env t a n args'
229228
230229 | (P (TCon t a) n _, args) <- unApply tm
231230 = return LNothing
@@ -238,14 +237,19 @@ instance ToIR (TT Name) where
238237 Just (arity, op) | length args == arity
239238 -> LOp op <$> mapM (ir' env) args
240239
240+ _ -> applyName n ist args
241+
242+{- collapsibility is turned off for now
241243 _
242244 -- if it's collapsible, compile to LNothing
243245 | (collapsible <$> lookupCtxtExact n (idris_optimisation ist)) == Just True
244246 -> return LNothing
245−
247+
246248 -- otherwise, compile normally
247249 | otherwise -> applyName n ist args
248250
251+-}
252+
249253 | (f, args) <- unApply tm
250254 = do f' <- ir' env f
251255 args' <- mapM (ir' env) args
@@ -266,7 +270,7 @@ instance ToIR (TT Name) where
266270 [Operator ty ar op] -> ar
267271 _ -> 0
268272
269− used = fromMaybe [] (map fst . usedpos <$> lookupCtxtExact n (idris_callgraph ist))
273+ used = maybe [] (map fst . usedpos) $ lookupCtxtExact n (idris_callgraph ist)
270274 fst4 (x,_,_,_) = x
271275
272276-- ir' env (P _ (NS (UN "Z") ["Nat", "Prelude"]) _)
src/Idris/Core/CaseTree.hs+10
@@ -587,15 +587,25 @@ prune proj (Case n alts)
587587 | delay == txt "Delay"
588588 -> if proj then mkForce n arg sc
589589 else Case n as
590+
591+ -- Projection transformations prevent us from seeing some uses of ctor fields
592+ -- because they delete information about which ctor is being used.
593+ -- Consider:
594+ -- f (X x) = ... x ...
595+ -- vs.
596+ -- f x = ... x!0 ...
597+ -- There's currently no code to handle this stuff. (TODO)
590598 as@[ConCase cn i args sc] -> if proj && False then mkProj n 0 args sc
591599 else Case n as
592600 as@[SucCase cn sc] -> if proj then mkProj n (-1) [cn] sc
593601 else Case n as
594602 as@[ConstCase _ sc] -> prune proj sc
603+
595604 -- Bit of a hack here! The default case will always be 0, make sure
596605 -- it gets caught first.
597606 [s@(SucCase _ _), DefaultCase dc]
598607 -> Case n [ConstCase (BI 0) dc, s]
608+
599609 as -> Case n as
600610 where pruneAlt (ConCase cn i ns sc) = ConCase cn i ns (prune proj sc)
601611 pruneAlt (FnCase cn ns sc) = FnCase cn ns (prune proj sc)
src/Idris/Erasure.hs+6−4
@@ -174,9 +174,10 @@ buildDepMap ci ctx mainName = addPostulates $ dfs S.empty M.empty [mainName]
174174 [ [(sUN "main" `sNS` ["Main"], Result)]
175175 , [(sUN "run__IO", Result), (sUN "run__IO", Arg 0)]
176176
177− -- MkIO is presumably read by run__IO but this cannot be observed
178− -- in the source code of programs.
177+ -- MkIO is presumably read by run__IO
178+ -- but this cannot be observed in the source code of programs.
179179 , it "MkIO" [1]
180+ , it "prim__IO" [1]
180181
181182 -- these have been discovered as builtins but are not listed
182183 -- among Idris.Primitives.primitives
@@ -360,7 +361,7 @@ buildDepMap ci ctx mainName = addPostulates $ dfs S.empty M.empty [mainName]
360361 `ins` unconditionalDeps args
361362
362363 Proj t i
363− -> error $ "cannot analyse projection !" ++ show i ++ " of " ++ show t
364+ -> error $ "cannot[0] analyse projection !" ++ show i ++ " of " ++ show t
364365
365366 Erased -> M.empty
366367
@@ -377,7 +378,8 @@ buildDepMap ci ctx mainName = addPostulates $ dfs S.empty M.empty [mainName]
377378 getDepsArgs n (Nothing, t) = getDepsTerm vs bs cd t -- unconditional
378379
379380 -- projections (= methods)
380− getDepsTerm vs bs cd (Proj t i) = getDepsTerm vs bs cd t -- TODO?
381+ getDepsTerm vs bs cd (Proj t i) = error $ "cannot[1] analyse projection !" ++ show i ++ " of " ++ show t
382+ -- getDepsTerm vs bs cd t -- TODO?
381383
382384 -- the easy cases
383385 getDepsTerm vs bs cd (Constant _) = M.empty