[GHC] #15403: Compact Regions with Lazy Evaluation

#15403: Compact Regions with Lazy Evaluation -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Currently, adding a value to a compact region evaluates it to normal form. I'm wondering if it's possible to have another compacting primitive that can add unevaluated thunks to a compact region. These thunks would be evaluated as they were demanded, and the resulting values would be added to the compact region. I actually have a use case for this in mind involving very large map-like data structures whose size exceeds system memory when in normal form but that are largely unevaluated, giving them a memory footprint that is a fraction of what it would be. One problem would be that a compaction failure (from someone trying to stick a function or a `MutableArray#` into a compact region) would happen after the call to `compactLazy`, so you end up with all the usual lazy IO problems. Another problem would be that the thunks wouldn't get GCed, since they would live in a compact region (and also because you could not update the references to the thunk, since compact regions are not scanned during GC). Neither of these are absolute deal-breakers though. Are there other problems that make this fundamentally impossible to do? Or is this something that could conceivably be added? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15403 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15403: Compact Regions with Lazy Evaluation -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): Another problem is that we'd need to teach mutators to allocate in a compact region. Currently mutators only allocate in nurseries (with the exception that some primops can allocate large or pinned blocks etc.) and code generator generates code accordingly. I think a simple trick like "update Hp to point to the compact region, revert it back afterwards" would not work as because of lazy evaluation we'd have to update Hp when evaluating objects referenced by the thunk in the compact region and update again for any other object (not sure if this is possible to do). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15403#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15403: Compact Regions with Lazy Evaluation -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by andrewthad): That's a good point. It may not be possible to teach mutators to allocate in a compact region. Even if it is, the extra branch need to do this might slow down all programs (even ones that don't need this feature). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15403#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15403: Compact Regions with Lazy Evaluation -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Right, I've thought a fair bit about how you might be able to use compact regions as an arena-style allocator for subcomputations. Of course, this involves teaching mutators to allocate directly into the compact. It turns out this is quite tricky to do for the reasons that Omer mentions. Our implementation of laziness is such that it's very hard to regain control over allocation behavior. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15403#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC