rudymatela / leancheck

enumerative property-based testing for Haskell
https://hackage.haskell.org/package/leancheck
Other
52 stars 8 forks source link

CI: test with GHC 9.2 #20

Closed wolverian closed 2 years ago

wolverian commented 2 years ago

Hi, I'm not sure this is the kind of update you're looking for, but I thought it'd be nice anyway. I'm looking into this because I'm getting the following error with LeanCheck on GHC 9.2.4:

tests/Main.hs:1:1: error:
    Exception when trying to run compile-time code:
      error (typeArity): symbol GHC.Prim.ByteArray# is not a newtype, data or type synonym
CallStack (from HasCallStack):
  error, called at src/Test/LeanCheck/Derive.hs:273:10 in leancheck-0.9.10-3bd55c2110c9808fba2f61d85cd6246868c6e54113deb01678d7aec19341f7e9:Test.LeanCheck.Derive
    Code: deriveListableCascading ''AST.Expr
rudymatela commented 2 years ago

@wolverian Thanks for the addition.

I merged and LeanCheck built and tested fine in GHC 9.2, see:

diagram

log

rudymatela commented 2 years ago

@wolverian The error you copy is on a TH derivation:

tests/Main.hs:1:1: error:
    Exception when trying to run compile-time code:
      error (typeArity): symbol GHC.Prim.ByteArray# is not a newtype, data or type synonym
CallStack (from HasCallStack):
  error, called at src/Test/LeanCheck/Derive.hs:273:10 in leancheck-0.9.10-3bd55c2110c9808fba2f61d85cd6246868c6e54113deb01678d7aec19341f7e9:Test.LeanCheck.Derive
    Code: deriveListableCascading ''AST.Expr

Here is a minimal way to replicate it:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MagicHash #-}
import Test.LeanCheck
import GHC.Prim
import GHC.Exts

data ASTExpr = ASTExpr ByteArray#

deriveListableCascading ''ASTExpr

Compiling:

$ ghc -dynamic issue.hs -o issue
[1 of 1] Compiling Main             ( issue.hs, issue.o )

issue.hs:1:1: error:
    Exception when trying to run compile-time code:
      error (typeArity): symbol GHC.Prim.ByteArray# is not a newtype, data or type synonym
CallStack (from HasCallStack):
  error, called at src/Test/LeanCheck/Derive.hs:273:10 in leancheck-0.9.10-85gqWNPLTz0BWM88m44GNp:Test.LeanCheck.Derive
    Code: deriveListableCascading ''ASTExpr
  |
1 | {-# LANGUAGE TemplateHaskell #-}
  | ^

This was on GHC 9.0.2, so I think this is unrelated to the GHC version:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.0.2

It seems deriveListable... fails for the types exported in GHC.Prim and GHC.Exts.

A (potential) fix would lie in updating Test.LeanCheck.Derive.

rudymatela commented 2 years ago

Let me try again with an explicit instance:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MagicHash #-}
import Test.LeanCheck
import GHC.Prim
import GHC.Exts

data ASTExpr = ASTExpr ByteArray#

instance Listable ByteArray# where list = []

deriveListableCascading ''ASTExpr

This is the error we get:

$ ghc -dynamic issue.hs -o issue
[1 of 1] Compiling Main             ( issue.hs, issue.o )

issue.hs:9:19: error:
    • Expecting a lifted type, but ‘ByteArray#’ is unlifted
    • In the first argument of ‘Listable’, namely ‘ByteArray#’
      In the instance declaration for ‘Listable ByteArray#’
  |
9 | instance Listable ByteArray# where list = []
  |                   ^^^^^^^^^^

I have never used the GHC.Prim Something# types myself... So this error is new to me :sweat_smile:.

rudymatela commented 2 years ago

Expecting a lifted type, but ‘ByteArray#’ is unlifted: I think this means that it is not possible to have typeclass instances for [unlifted types](). So in this case, a possible solution for your derivation of the AST.Expr type is to have explicit listable instances for the types that are "right around" unlifted types. The following compiles successfully:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MagicHash #-}
module Issue where
import Test.LeanCheck
import GHC.Prim
import GHC.Exts

data ASTExpr  =  I IntExpr
              |  B ByteArrayExpr
              |  C CharExpr

data IntExpr        =  IntExpr       Int#
data ByteArrayExpr  =  ByteArrayExpr ByteArray#
data CharExpr       =  CharExpr      Char#

instance Listable IntExpr       where tiers = error "TODO: implement me!"
instance Listable ByteArrayExpr where tiers = error "TODO: implement me!"
instance Listable CharExpr      where tiers = error "TODO: implement me!"

deriveListableCascading ''ASTExpr

@wolverian Hopefully this solves the issue you are having... :thinking: Please let me know your thoughts on this.

rudymatela commented 2 years ago

... and here's one last attempt using GHC.Generics:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE DeriveGeneric #-}
module Issue where
import Test.LeanCheck
import Test.LeanCheck.Generic
import GHC.Prim
import GHC.Exts
import GHC.Generics

data ASTExpr = ASTExpr ByteArray# deriving Generic

instance Listable ASTExpr where tiers = genericTiers

This fails with:

$ ghc -dynamic issue.hs
[1 of 1] Compiling Issue            ( issue.hs, issue.o )

issue.hs:11:44: error:
    • Can't make a derived instance of ‘Generic ASTExpr’:
        ASTExpr must not have exotic unlifted or polymorphic arguments
    • In the data declaration for ‘ASTExpr’
   |
11 | data ASTExpr = ASTExpr ByteArray# deriving Generic
   |                               

Perhaps my previous comment is the only solution for allowing automatic derivations involving unlifted types after all...

wolverian commented 2 years ago

Right… https://github.com/ghc-proposals/ghc-proposals/pull/30 is related.