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
  • #18377
Closed
Open
Created Jun 23, 2020 by Simon Peyton Jones@simonpjDeveloper

Better combining for identical case alternatives

Sometimes (e.g. here) the user wants to write

f (IfLFCon n)       = unitNameSet n
f (IfLFReEntrant _) = emptyNameSet
f (IfLFThunk _ _)   = emptyNameSet
f (IfLFUnknown _)   = emptyNameSet
f IfLFUnlifted      = emptyNameSet

enumerating all the constructors for the sake of explicitness. But we don't want to do all those tests at runtime! We'd prefer to execute

f (IfLFCon n)       = unitNameSet n
f _                 = emptyNameSet

Some bits of GHC already combine identical alternatives:

  • The Simplifier uses combineIdenticalAlts
  • CSE uses combineAlts, which tries a bit harder

But neither does the full job:

  • CSE doesn't use occurrence analysis to look for dead binders, so it only looks for nullary constructors
  • The Simplifier uses only cheapEqExpr, and only combines the first alternative.

What we want is to

  • Look at alternatives whose binders are all dead
  • Among them pick the most popular RHS
  • Combine them

Not really hard. Probably appropriate to do this in CSE.

Then we could guarantee that we wouldn't make redundant runtime tests.

See also #14684 for an earlier version of the same issue.

Edited Jun 23, 2020 by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking