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,385
    • Issues 4,385
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 370
    • Merge Requests 370
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #16859

Closed
Open
Opened Jun 23, 2019 by Andreas Klebinger@AndreasKDeveloper

WorkerWrapper: Wrapper takes apart constructor which is then reconstructed in the worker.

We have this function from GHC's Name module as our starting point:


data Name = Name {
                n_sort :: NameSort,     -- What sort of name it is
                n_occ  :: !OccName,     -- Its occurrence name
                n_uniq :: {-# UNPACK #-} !Unique,
                n_loc  :: !SrcSpan      -- Definition site
            }

{-# NOINLINE mkInternalName #-}
mkInternalName :: Unique -> OccName -> SrcSpan -> Name
mkInternalName uniq occ loc = Name { n_uniq = uniq
                                   , n_sort = Internal
                                   , n_occ = occ
                                   , n_loc = loc }

This results in the following worker/wrapper

-- RHS size: {terms: 14, types: 13, coercions: 0, joins: 0/0}
$wmkInternalName
  = \ ww_sl5G ww1_sl5K ww2_sl5L w_sl5D ->
      case w_sl5D of dt_XaRo { __DEFAULT ->
      (# Internal, OccName ww1_sl5K ww2_sl5L, ww_sl5G, dt_XaRo #)
      }

-- RHS size: {terms: 21, types: 21, coercions: 1, joins: 0/0}
mkInternalName
  = \ w_sl5B w1_sl5C w2_sl5D ->
      case w_sl5B `cast` <Co:1> of { I# ww1_sl5G ->
      case w1_sl5C of { OccName ww3_sl5K ww4_sl5L ->
      case $wmkInternalName ww1_sl5G ww3_sl5K ww4_sl5L w2_sl5D of
      { (# ww6_slkS, ww7_slkT, ww8_slkU, ww9_slkV #) ->
      Name ww6_slkS ww7_slkT ww8_slkU ww9_slkV
      }
      }
      }

This code is quite odd. It:

  • Evaluates w1_sl5C to an OccName.
  • Takes the OccName apart and passes it's fields to the worker.
  • The worker constructs a new OccName from the passed fields.
  • The constructed OccName (and other things) are returned.
  • The returned OccName is ultimately returned by the wrapper.

This causes the "old" OccName to become garbage and a new one to be allocated in the heap unless I missed something.

Edited Jun 23, 2019 by Andreas Klebinger
Assignee
Assign to
⊥
Milestone
⊥
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#16859