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,323
    • Issues 4,323
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 363
    • Merge Requests 363
  • 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
  • #19001

Closed
Open
Opened Nov 27, 2020 by Sebastian Graf@sgraf812Developer

FloatOut discards strict evalution context

Consider

module Lib (h) where

g :: Int -> (Int,Int)
g n = (n, n+1)
{-# NOINLINE g #-}

h :: Int -> Int
h _ = snd (g 2)

we get the simplified Core

$wg_sHs
  = \ w_sHo ->
      (# w_sHo, case w_sHo of { I# x_aGX -> I# (+# x_aGX 1#) } #)

lvl_sHJ = I# 2#
lvl_sH8
  = case $wg_sHs lvl_sHJ of { (# ww_sHt, ww_sHu #) ->
    (ww_sHt, ww_sHu)
    }

h = \ _ -> case lvl_sH8 of { (ds1_aGM, y_aGN) -> y_aGN }

Note how g 2 was floated out and thus separated from its strict snd evaluation context in h.

In this case that inhibits us from seeing (with #18894 (closed)) that every call to g also evaluates the second component of the returned pair (and never looks into the first).

I'd much rather see the whole expression snd (g 2) floated out, so including the surrounding case:

$wg_sHs
  = \ w_sHo ->
      (# w_sHo, case w_sHo of { I# x_aGX -> I# (+# x_aGX 1#) } #)

lvl_sHJ = I# 2#
lvl_sH8
  = case $wg_sHs lvl_sHJ of { (# ww_sHt, ww_sHu #) ->
      ww_sHu
    }

h = \ _ -> lvl_sH8
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#19001