Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,262
    • Issues 4,262
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 403
    • Merge Requests 403
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #5298

Closed
Open
Opened Jul 04, 2011 by reinerp@trac-reinerp

Inlined functions aren't fully specialised

When a function is inlined, it can expose other functions as candidates for specialisation, but GHC doesn't specialise them.

For instance, given the two modules

module A where

{-# INLINABLE fac #-}
fac :: Num a => a -> a
fac 0 = 1
fac n = n * fac (n-1)

{-# INLINE f #-}
f :: Num a => a -> a
f a = fac a
module B where

import A

g :: Int -> Int
g x = f x

we see that f is inlined, but fac isn't specialised for Ints:

B.g :: Int -> Int
[GblId,
 Arity=1,

 Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=1, Value=True,
         ConLike=True, Cheap=True, Expandable=True,
         Guidance=IF_ARGS [0] 30 0}]
B.g =
  \ (x_ary :: Int) ->
    A.fac @ Int $fNumInt x_ary

Removing the INLINE pragma on f doesn't help.

Either of the following changes will cause fac to be specialised:

  • adding # SPECIALISE f :: Int -> Int # to module B
  • defining "g x = fac x" instead

This happens with both GHC 7.0.3 and GHC HEAD

Trac metadata
Trac field Value
Version 7.0.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
8.0.1
Milestone
8.0.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#5298