Skip to content

Arity: exprArity invariant are not upheld

Invariant (2) of Note [exprArity invariant] says

  (2) exprArity e <= typeArity (exprType e)

And similarly, even after the refactoring and renaming to Note [typeArity invariants] proposed in !5658 (closed) it says

  (1) In any binding x = e,
      idArity f <= typeArity (idType f)

Both invariants are not upheld for the following program:

{-# OPTIONS_GHC -O2 -fforce-recomp #-}

module Lib where

newtype N = N (Int -> Int -> Int)

plusInt :: N
plusInt = N (+)

In -ddump-simpl I see

-- RHS size: {terms: 1, types: 0, coercions: 2, joins: 0/0}                                               
plusInt :: N                   
[GblId,                 
 Arity=2,                                                                                                 
 Str=<1!L><1!L>,                                     
 Cpr=1,                                                                                                   
 Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,                                            
         WorkFree=True, Expandable=True,     
         Guidance=ALWAYS_IF(arity=0,unsat_ok=True,boring_ok=True)}]                                       
plusInt                                                                                                   
  = GHC.Num.$fNumInt_$c+                                                                                  
    `cast` (Sym (Lib.N:N[0]) :: (Int -> Int -> Int) ~R# N)

Note that plusInt gets idArity 2, which is more than 0, the typeArity of N. So the invariant is not upheld.

I think the status quo is fine, but I'm not sure what invariant that is based on. It seems idArity ignores intermittent casts and I'm completely fine with that.

Edited by Sebastian Graf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information