ndmitchell / derive

A Haskell program and library to derive instances for data types
BSD 3-Clause "New" or "Revised" License
25 stars 17 forks source link

Convert to haskell-src-exts-1.18 #19

Closed ndmitchell closed 7 years ago

ndmitchell commented 8 years ago

I started work on this but it is not yet complete. I expect there are a few more hours work required.

src.zip

ndmitchell commented 8 years ago

There is a branch here: https://github.com/ndmitchell/derive/tree/hse-1.18

It doesn't work, but I certainly did a lot of the conversion.

lemmih commented 8 years ago

I finished the conversion but I'm not completely sure it's 100% correct. Do you have regression tests?

ndmitchell commented 8 years ago

In .ghci if you type :test it will run:

:main --generate
:reload
:main --test

That's the regression tests.

lemmih commented 8 years ago

I get:

*Main> :test
[20 of 25] Compiling Data.Derive.All  ( src/Data/Derive/All.hs, interpreted )

src/Data/Derive/All.hs:9:16:
    Not in scope: ‘make’
    Perhaps you meant ‘take’ (imported from Prelude)
lemmih commented 8 years ago

Did I accidentally mess up the tests? I don't understand how the tests are supposed to work.

ndmitchell commented 8 years ago

Can you try running the tests with the HEAD version, or the last released version, so you can see how they are meant to work? That should give us a clue as to whether you are running the test wrong, or in the conversion something has broken which was not yet visible due to other changes.

lemmih commented 8 years ago

Can't even successfully run the tests for 2.5.26 with hse-1.17.1

*Main> :test
Generating Arbitrary
[snip]
Testing Arbitrary
[snip]
Type checking examples

src/Language/Haskell.hs:288:31:
    Ambiguous occurrence ‘FieldDecl’
    It could refer to either ‘Language.Haskell.FieldDecl’,
                             defined at src/Language/Haskell.hs:210:1
                          or ‘Language.Haskell.Exts.FieldDecl’,
                             imported from ‘Language.Haskell.Exts’ at src/Language/Haskell.hs:4:1-57
                             (and originally defined in ‘Language.Haskell.Exts.Syntax’)
*** Exception: Failed to typecheck results
lemmih commented 8 years ago

Ah, I see something weird. In this patch, "#19, start moving to haskell-src-exts", you add takeBaseName x == "Data" to the test filter. That expression is always false and no tests should be generated. That's then combined with a bug that generates invalid code when there are no tests.

lemmih commented 8 years ago

I fixed the test generator code and each test checks out OK. I hope that means it works. :)

flip111 commented 8 years ago

Thank you @Lemmih :)

domenkozar commented 7 years ago

This is now a blocker for using GHC 8.0.2 / LTS 8

peti commented 7 years ago

The lack of support for haskell-src-exts 1.18.x also blocks openSUSE from distributing this package since we're following LTS 8.x, too. Right now, the build fails (https://build.opensuse.org/package/show/devel:languages:haskell/derive), but at some point we'll have to remove derive from the package set.

ndmitchell commented 7 years ago

Sorry for the radio silence for some time. I'll endeavour to take a look at this over the weekend and see what I can do.

domenkozar commented 7 years ago

So much appreciated @ndmitchell

ndmitchell commented 7 years ago

I've uploaded Derive 2.6, mainly thanks to the work of @Lemmih. Can people check it works - the whole package is in a bit of a state (it needs a lot of love applying to it), so I'm no longer as confident the tests mirror real-world usage as I used to be.

ndmitchell commented 7 years ago

I noticed that the bounds were too tight to allow HSE 1.19 so have relaxed them. Can someone confirm it works? And let me know if it needs re-adding to Stackage? Ideally if it were readded it would be by someone other than me :)

domenkozar commented 7 years ago

@ndmitchell in following line I get

Pos/Data/Attributes.hs:1:1: error:
    Exception when trying to run compile-time code:
      Could not convert Decl () to Dec
InstDecl () Nothing (IRule () Nothing (Just (CxTuple () [ClassA () (UnQual () (Ident () "NFData")) [TyVar () (Ident () "h_6989586621679297913")]])) (IHApp () (IHCon () (UnQual () (Ident () "NFData"))) (TyParen () (TyApp () (TyCon () (UnQual () (Ident () "Attributes"))) (TyVar () (Ident () "h_6989586621679297913")))))) (Just [InsDecl () (FunBind () [Match () (Ident () "rnf") [PParen () (PApp () (UnQual () (Ident () "Attributes")) [PVar () (Ident () "x1"),PVar () (Ident () "x2")])] (UnGuardedRhs () (InfixApp () (App () (Var () (UnQual () (Ident () "rnf"))) (Var () (UnQual () (Ident () "x1")))) (QVarOp () (UnQual () (Ident () "seq"))) (InfixApp () (App () (Var () (UnQual () (Ident () "rnf"))) (Var () (UnQual () (Ident () "x2")))) (QVarOp () (UnQual () (Ident () "seq"))) (Con () (Special () (UnitCon ())))))) Nothing])])
src/Language/Haskell/Convert.hs:(124,5)-(132,57): Non-exhaustive patterns in function conv

CallStack (from HasCallStack):
  error, called at src/Language/Haskell/Convert.hs:21:87 in derive-2.6.1-Fni1nm1Ws9IAIfnzevXAvI:Language.Haskell.Convert
    Code: derive makeNFData ''Attributes
ndmitchell commented 7 years ago

@domenkozar I've released 2.6.2 which hopefully fixes that issue.

domenkozar commented 7 years ago

@ndmitchell thanks, that works :)

ndmitchell commented 7 years ago

OK, happy for someone to submit this to Stackage, but in doing so, they are taking over at least co-maintainership!