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,859
    • Issues 4,859
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 454
    • Merge requests 454
  • 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
  • #20058
Closed
Open
Created Jun 28, 2021 by Krzysztof Gogolewski@monoidalDeveloper

Linear types: restrict transformations around empty case

This program

{-# LANGUAGE LinearTypes, EmptyCase #-}
module M where

{-# NOINLINE f #-}
f :: a %1-> ()
f x = case () of {}

fails Linear Lint with -dlinear-core-lint -O. There are three problems.

  1. castBottomExpr converts (case x :: T of {}) :: T to x. Commenting this line:
--- a/compiler/GHC/Core/Make.hs
+++ b/compiler/GHC/Core/Make.hs
@@ -239,7 +239,7 @@ castBottomExpr :: CoreExpr -> Type -> CoreExpr
 -- return an expression of type 'ty'
 -- See Note [Empty case alternatives] in GHC.Core
 castBottomExpr e res_ty
-  | e_ty `eqType` res_ty = e
+  -- | e_ty `eqType` res_ty = e
   | otherwise            = Case e (mkWildValBinder One e_ty) res_ty []
   where
     e_ty = exprType e

works around the problem, but the correct fix is to do this transformation only if the usage environment of the case is completely unrestricted. This needs #18768.

  1. Worker/wrapper moves the empty case to a separate binding:
f = \ (@a_sCY) (w_sCZ [Dmd=B] :: a_sCY) -> $wf_sD1 @a_sCY void#

where $wf_sD1 contains the empty case. This fails Lint, can be worked around with -fno-worker-wrapper.

  1. CorePrep eliminates empty case, just like point 1.
-- Eliminate empty case
-- See Note [Unsafe coercions]
cpeRhsE env (Case scrut _ ty [])
  = ...

This ticket is blocked on #18768.

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