#12901 closed bug (fixed)

Levity polymorphic expressions mustn't be floated out

Reported by: hsyl20 Owned by: hsyl20
Priority: normal Milestone: 8.2.1
Component: Compiler Version: 8.1
Keywords: LevityPolymorphism Cc: simonpj
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash or panic Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D2769
Wiki Page:

Description

I have been trying to add the following code into GHC:

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
pattern AppOp1  :: PrimOp -> Arg CoreBndr -> CoreExpr
pattern OpVal   :: PrimOp -> Arg CoreBndr

pattern AppOp1  op x   =  App (OpVal op) x
pattern OpVal   op     <- Var (isPrimOpId_maybe -> Just op) where
   OpVal op = Var (mkPrimOpId op)

It triggers the following CoreLint error:

<no location info>: warning:
    [RHS of lvl_spfb :: r]
    RuntimeRep-polymorphic binder: lvl_spfb :: (r :: TYPE rep)

Indeed:

$mAppOp1
  :: forall (r :: TYPE rep).
     CoreExpr -> (PrimOp -> Arg CoreBndr -> r) -> (Void# -> r) -> r
[LclIdX, Arity=3]
$mAppOp1 =
  \ (@ (rep_agRe :: RuntimeRep))
    (@ (r_agRf :: TYPE rep))
    (scrut_agRh :: CoreExpr)
    (cont_agRi :: PrimOp -> Arg CoreBndr -> r)
    (fail_agRj :: Void# -> r) ->
    let {
      fail_spbW :: Void# -> r
      [LclId, Arity=1]
      fail_spbW = \ _ [Occ=Dead, OS=OneShot] -> fail_agRj void# } in
    let {
      lvl_spfb :: r
      [LclId]
      lvl_spfb = fail_spbW void# } in
    case scrut_agRh of {
      __DEFAULT -> fail_spbW void#;
      App ds_dj2u x_afoV ->
        $mOpVal
          @ rep
          @ r
          ds_dj2u
          (\ (op_afoU :: PrimOp) -> cont_agRi op_afoU x_afoV)
          (\ _ [Occ=Dead] -> lvl_spfb)

According to the levity polymorphism paper lvl_spfb shouldn't have been floated out in a let-binding.

Change History (3)

comment:1 Changed 12 months ago by hsyl20

Differential Rev(s): Phab:D2769
Status: newpatch

comment:2 Changed 12 months ago by Ben Gamari <ben@…>

In 514c01ee/ghc:

Levity polymorphic expressions mustn't be floated-out in let-bindings.

Reviewers: simonpj, austin, bgamari

Reviewed By: simonpj, bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2769

GHC Trac Issues: #12901

comment:3 Changed 12 months ago by bgamari

Milestone: 8.2.1
Resolution: fixed
Status: patchclosed
Note: See TracTickets for help on using tickets.