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,868
    • Issues 4,868
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 456
    • Merge requests 456
  • 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
  • #17759
Closed
Open
Created Jan 28, 2020 by Andreas Klebinger@AndreasKDeveloper

Allow specialization of more functions provided by GHC/base.

Motivation

Many functions and instances provided with GHC are defined in a recursive manner.

Using the Eq [a] instance as example

instance (Eq a) => Eq [a] where
    {-# SPECIALISE instance Eq [[Char]] #-}
    {-# SPECIALISE instance Eq [Char] #-}
    {-# SPECIALISE instance Eq [Int] #-}
    []     == []     = True
    (x:xs) == (y:ys) = x == y && xs == ys
    _xs    == _ys    = False

By default GHC won't provide unfoldings for a function like this. Since it's a loop breaker it won't be inlined so exposing the unfolding is considered wasteful.

However it can still be specialized. This removes the overhead of the overloaded Eq instance improving performance by a lot when it happens.

Proposal

Alternative 1

GHC should retain unfoldings for certain loop breakers.

If a function:

  • Take a dictionary argument
  • Is sufficiently small

Then specializing it has a high chance of being beneficial and the unfolding should be kept.

Alternative 2

Keep eliminating loopbreaker unfoldings.

But add INLINEABLE to GHC provided definitions where it's deemed useful.

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