
#13908: sameMutableArray equivalent for Array -------------------------------------+------------------------------------- Reporter: winter | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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: -------------------------------------+------------------------------------- Sometime it is useful to compare reference equality for immutable arrays, for example when comparing vectors which are slices of arrays, we may want to know if two vectors are slices of the same array. But currently we only have `sameMutableXXXArray` primitives. A workaround may look like this: {{{ sameArray :: Array a -> Array a -> Bool sameArray arr1 arr2 = runST (do marr1 <- unsafeThawArray arr1 marr2 <- unsafeThawArray arr2 return (sameMutableArray marr1 marr2) ) }}} But the problem is for boxed arrays, this code will push an unchanged array to mutable list if it's already on older generations. Next GC will have to scan it(at least will scan its card table). I can see two solutions here, first one is to add `sameXXXArray` for all array types. The second one is somehow more complex: Currently we simply rewrite array's header to `MUT_ARR_PTRS_FROZEN0/SMALL_MUT_ARR_PTRS_FROZEN0` when we do `unsafeFreeze`. But for mutable array with no write happend, e.g. the ones with `MUT_ARR_PTRS_CLEAN/SMALL_MUT_ARR_PTRS_CLEAN` header. we can safely rewrite the header to `MUT_ARR_PTRS_FROZEN/SMALL_MUT_ARR_PTRS_FROZEN`, so that we can keep it from next GC. Then to fix previous code, we can add a freeze before returning. Of course we can do these two solutions all together ; ) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13908 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler