Skip to content
Snippets Groups Projects
Commit 35587eba authored by Simon Peyton Jones's avatar Simon Peyton Jones Committed by Marge Bot
Browse files

Fix a bug in tail calls with ticks

See #24078 for the diagnosis.  The change affects only
the Tick case of occurrence analysis.

It's a bit hard to test, so no regression test (yet anyway).
parent e0f35030
No related branches found
No related tags found
No related merge requests found
...@@ -2493,32 +2493,34 @@ But it is not necessary to gather CoVars from the types of other binders. ...@@ -2493,32 +2493,34 @@ But it is not necessary to gather CoVars from the types of other binders.
-} -}
occAnal env (Tick tickish body) occAnal env (Tick tickish body)
| SourceNote{} <- tickish = WUD usage' (Tick tickish body')
= WUD usage (Tick tickish body') where
-- SourceNotes are best-effort; so we just proceed as usual. WUD usage body' = occAnal env body
-- If we drop a tick due to the issues described below it's
-- not the end of the world.
| tickish `tickishScopesLike` SoftScope usage'
= WUD (markAllNonTail usage) (Tick tickish body') | tickish `tickishScopesLike` SoftScope
= usage -- For soft-scoped ticks (including SourceNotes) we don't want
-- to lose join-point-hood, so we don't mess with `usage` (#24078)
| Breakpoint _ _ ids _ <- tickish -- For a non-soft tick scope, we can inline lambdas only, so we
= WUD (addManyOccs usage_lam (mkVarSet ids)) (Tick tickish body') -- abandon tail calls, and do markAllInsideLam too: usage_lam
-- never substitute for any of the Ids in a Breakpoint
| Breakpoint _ _ ids _ <- tickish
= -- Never substitute for any of the Ids in a Breakpoint
addManyOccs usage_lam (mkVarSet ids)
| otherwise
= usage_lam
| otherwise
= WUD usage_lam (Tick tickish body')
where
(WUD usage body') = occAnal env body
-- for a non-soft tick scope, we can inline lambdas only
usage_lam = markAllNonTail (markAllInsideLam usage) usage_lam = markAllNonTail (markAllInsideLam usage)
-- TODO There may be ways to make ticks and join points play
-- nicer together, but right now there are problems: -- TODO There may be ways to make ticks and join points play
-- let j x = ... in tick<t> (j 1) -- nicer together, but right now there are problems:
-- Making j a join point may cause the simplifier to drop t -- let j x = ... in tick<t> (j 1)
-- (if the tick is put into the continuation). So we don't -- Making j a join point may cause the simplifier to drop t
-- count j 1 as a tail call. -- (if the tick is put into the continuation). So we don't
-- See #14242. -- count j 1 as a tail call.
-- See #14242.
occAnal env (Cast expr co) occAnal env (Cast expr co)
= let (WUD usage expr') = occAnal env expr = let (WUD usage expr') = occAnal env expr
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment