how does a CAF become unreachable?

I spent the afternoon spelunking through some code and the Commentary, and I'm wondering how a CAF becomes unreachable. I gather it might have to do with GHC floating a static expression out of a context until it becomes a CAF, but I'm still not seeing how a CAF could at one point be reachable, then dynamically become unreachable. Can anyone show an example? Norman

| Can anyone show an example?
Sure
xs = [1..1000] :: [Int]
ys = [2..2000] :: [Float]
main = do { print xs; print ys }
After printing xs, the CAF for xs is unreachable and can be GC'd. No point in keeping it around. Indeed this applies from the moment (print xs) begins work. But it was
main = do { print xs; print xs }
then the CAF for xs remains reachable until the second (print xs) starts.
Simon
PS: I am leaving Microsoft at the end of November 2021, at which point simonpj@microsoft.com will cease to work. Use simon.peytonjones@gmail.com instead. (For now, it just forwards to simonpj@microsoft.com.)
| -----Original Message-----
| From: ghc-devs
participants (2)
-
Norman Ramsey
-
Simon Peyton Jones