
#9813: Error when reifying type constructor -------------------------------------+------------------------------------- Reporter: owst | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1899 Wiki Page: | -------------------------------------+------------------------------------- Comment (by owst): A small status update: this is tricky! Replying to [comment:37 goldfire]:
In particular, GHC already does dependency analysis and chunking, and it would be terribly wrong not to have splicy things depend on everything else in the declaration group.
I can't actually see that this is true for ''untyped'' splices! For ''typed'' splices I think it happens in the renamer, here: https://github.com/ghc/ghc/blob/master/compiler/rename/RnSplice.hs#L403 But I haven't found an equivalent for untyped splices.
The only problem, I believe, is that type-checking is held off until the whole group is renamed. (Splice action happens in the renamer.) It may or may not be hard to change that routing.
Yes, this is indeed the case. In particular, renaming of the group happens first, here: https://github.com/ghc/ghc/blob/master/compiler/typecheck/TcRnDriver.hs#L558 before type checking of the group's declarations happens later, here: https://github.com/ghc/ghc/blob/master/compiler/typecheck/TcRnDriver.hs#L596 Since `reify` is called during renaming, it fails since the type environments do not contain the names in question. I'm a bit stuck as to how to proceed! Perhaps the obvious question is: is there a particular reason to run untyped splices in the renamer vs the typechecker? I assume we can't do proper dependency analysis until after renaming, so I'm not sure it's possible to do the dependency sorting 'before' renaming (such that we could rename/typecheck non-splicy declarations before splicy declarations). If we could run untyped splices in the typechecker i.e. after renaming and dependency analysis, I assume we would be able to refer to names earlier in the dependency ordering. Any thoughts/advice that may get me unstuck? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9813#comment:38 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler