Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,242
    • Issues 5,242
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 564
    • Merge requests 564
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #13908
Closed
Open
Issue created Jul 01, 2017 by winter@trac-winter

sameMutableArray equivalent for Array

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 ; )

Edited Mar 10, 2019 by Ben Gamari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking