Skip to content

GitLab

  • Menu
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 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 455
    • Merge requests 455
  • 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 Compiler
  • GHCGHC
  • Issues
  • #17901
Closed
Open
Created Mar 05, 2020 by Simon Peyton Jones@simonpjDeveloper

Missed opportunity for combineIdenticalAlts

Consider

fun1 x = case x of
          []    -> length x
          (_:_) -> length x

fun2 x = case x of
          []    -> length x
          (_:_) -> id (length x)

You might think that both would turn into

foo x = length x

because the alternatives are identical. Actually, neither do. Because in the [] branch we replace x with [], thus

fun1 x = case x of
          []    -> length []
          (_:_) -> length x

Doing this is basically a good idea; x is no longer free in the RHS, and any thunks or closures in that RHS will have fewer free vars. But it does make them look different.

It turns out that !2161 (closed) (fixing binder-swapping) makes the right thing happen for fun1, because the combine-identical-alternative stuff happens before the simplifier inlines x. But fun2 defeates it. This sensitivity to exactly when things happen is bad.

The Right Thing is for the equality test in GHC.Core.Utils realise that in the [] branch, [] and x are equal. This should not be hard to do.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking