Skip to content

Commit

Permalink
Never collect entries from the prelude
Browse files Browse the repository at this point in the history
  • Loading branch information
edsko committed Jun 11, 2016
1 parent cc68863 commit caf7b79
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/CBN/Heap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,19 @@ mark roots heap =

-- | Given a set of reachable pointers, remove all unreachable pointers
--
-- Entries from the prelude are never collected (are always considered to
-- be reachable).
--
-- Returns the new heap and the set of removed pointers
sweep :: Show a => Set Ptr -> Heap a -> (Heap a, Set Ptr)
sweep reachable (Heap next hp) = (
Heap next $ Map.filterWithKey isReachable hp
, Map.keysSet hp Set.\\ reachable
Heap next $ Map.filterWithKey (\ptr _a -> isReachable ptr) hp
, Set.filter (not . isReachable) $ Map.keysSet hp
)
where
isReachable :: Ptr -> a -> Bool
isReachable ptr _ = ptr `Set.member` reachable
isReachable :: Ptr -> Bool
isReachable (Ptr Nothing _) = True
isReachable ptr = ptr `Set.member` reachable

-- | Mark-and-sweep garbage collection given a set of roots
--
Expand Down

0 comments on commit caf7b79

Please sign in to comment.