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,261
    • Issues 4,261
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 419
    • Merge Requests 419
  • 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
  • #15358

Closed
Open
Opened Jul 10, 2018 by chessai@chessaiDeveloper

no way to talk about unpacking sum types / unpacking tuples

Suppose I have the following Haskell module:

{-# LANGUAGE BangPatterns #-}

-- strict 'Maybe'
data StrictMaybe a = SNothing | SJust !a

-- lazy 'Maybe'
data Maybe a = Nothing | Just a

data BoxedInner = BoxedInner
  !Int
  !(Maybe Int)

data StillBoxedInner = StillBoxedInner
  !Int
  !(StrictMaybe Int)

mBoxed :: BoxedInner
mBoxed = BoxedInner 0 (Just 0)

mWantThisToUnbox :: StillBoxedInner
mWantThisToUnbox = StillBoxedInner 1 (Just 1)

the 'StrictMaybe' can unbox the first 'Int' into 1#, but the 1 inside of the just cannot unbox. When compiled to core with -O2 what I'd want to see is something like:

mWantThisToUnbox = StillBoxedInner 0# (# | 1# #)

(where (# (# #) | a #) is an unboxed sum type with two constructors, one nullary and one unary)

but instead the Int inside 'SJust' remains boxed.

Even with something like the following:

{-# LANGUAGE UnboxedSums #-}
data UMaybe a = (# (# #) | a #)

something like 'UMaybe Int' would still result in 'Int' being boxed.

This same thing occurs with unpacked tuples, consider something like:

data StrictTuple = StrictTuple
  !Int
  !(Int, Int)

Anything inside the (Int, Int) tuple will not unbox, despite having a bang pattern there.

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