Declarations processed in unexpected order in the presence of TH declaration splices
In ghc-7.8 reify returns only first data type that have an instance, here is a code:
Test.hs
```
{-# LANGUAGE TemplateHaskell #-}
module Test where
import Language.Haskell.TH
class C a
inner :: ExpQ
inner = do
ClassI _ instances <- reify ''C
let sh = show instances
[| sh |]
def :: String -> DecsQ
def x =
let dn = mkName x
in do dt <- dataD (cxt []) dn [] [] []
i <- instanceD (cxt []) (appT (conT ''C) (conT dn)) [] -- [d| instance C $(cn) |]
return [dt,i]
test :: ExpQ
test = [| print $inner |]
```
test.hs
```
{-# LANGUAGE TemplateHaskell #-}
import Test
def "A"
def "B"
main = $(test)
```
running test returns:
"\[InstanceD \[\] (AppT (ConT Test.C) (ConT Main.A)) \[\]\]"
under 7.6 test returns:
"\[InstanceD \[\] (AppT (ConT Test.C) (ContT Main.B) \[\], InstanceD \[\] (AppT (ConT Test.C) (ConT Main.A) \[\]\]"
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 7.8.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"reify returns only first instance of class","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.8.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"In ghc-7.8 reify returns only first data type that have an instance, here is a code:\r\n\r\nTest.hs\r\n\r\n{{{\r\n{-# LANGUAGE TemplateHaskell #-}\r\nmodule Test where\r\n\r\nimport Language.Haskell.TH\r\n\r\nclass C a\r\n\r\ninner :: ExpQ\r\ninner = do\r\n ClassI _ instances <- reify ''C\r\n let sh = show instances\r\n [| sh |]\r\n\r\ndef :: String -> DecsQ\r\ndef x =\r\n let dn = mkName x\r\n in do dt <- dataD (cxt []) dn [] [] [] \r\n i <- instanceD (cxt []) (appT (conT ''C) (conT dn)) [] -- [d| instance C $(cn) |]\r\n return [dt,i]\r\n\r\ntest :: ExpQ\r\ntest = [| print $inner |]\r\n}}}\r\n\r\ntest.hs\r\n{{{\r\n{-# LANGUAGE TemplateHaskell #-}\r\n\r\nimport Test\r\n\r\ndef \"A\"\r\ndef \"B\"\r\n\r\nmain = $(test)\r\n}}}\r\n\r\nrunning test returns:\r\n\r\n\"[InstanceD [] (AppT (ConT Test.C) (ConT Main.A)) []]\"\r\n\r\n\r\nunder 7.6 test returns:\r\n\r\n\"[InstanceD [] (AppT (ConT Test.C) (ContT Main.B) [], InstanceD [] (AppT (ConT Test.C) (ConT Main.A) []]\"","type_of_failure":"OtherFailure","blocking":[]} -->
issue