(Failing to) look up names generated by Template Haskell

Hi all, I am stuck on the following problem. Suppose you have two module Lib Client where Client "imports" Lib. Now, while analyzing the Core of `Client` often I need to resolve the name of a `TyThing` defined inside `Lib`. Normally, this is easy enough: I simply use hscTcRcLookupName :: HscEnv https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/ghc-8.2.1/HscTy... -> Name https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/ghc-8.2.1/Name.... -> IO https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/base-4.10.0.0/S... (Maybe https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/base-4.10.0.0/D... TyThing https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/ghc-8.2.1/Type.... ) defined inside HscMain. **THE PROBLEM** However, I find that when the relevant `Name` corresponds to something generated by TemplateHaskell (inside `Lib`) then the above `hscTcRcLookupName` fails to return any result! Even more oddly, suppose the name was BlogPostId If there are TWO `TyThing`s with that name, e.g. a type synonym defined type BlogPostId = ... and also a data constructor for a data family instance, then `hscTcRcLookupName` only returns the type synonym, but refuses to return the data constructor. Does anyone know what may be going on? Thanks! - Ranjit Jhala.

On further inspection, the problem is not with TH but with family instances.
That is, suppose Library.hs is has the constructors defined in the simple
top-level style:
```
data EntityField typ where
BlobXVal :: EntityField Int
BlobYVal :: EntityField Int
```
Then when analyzing Client.hs, the lookup function `hscTcRcLookupName`
WORKS.
However, if instead, Library.hs defines the constructors within an instance:
```
instance PersistEntity Blob where
data EntityField Blob typ where
BlobXVal :: EntityField Blob Int
BlobYVal :: EntityField Blob Int
```
then, when analyzing Client.hs, the `hscTcRcLookupName` function FAILS.
Clearly there is some difference in how `hscTcRcLookupName` works in these
two cases.
Does someone know what it is?
Thanks in advance!
- Ranjit.
On Thu, Jan 25, 2018 at 4:24 PM, Ranjit Jhala
Hi all,
I am stuck on the following problem.
Suppose you have two module
Lib
Client
where Client "imports" Lib. Now, while analyzing the Core of `Client` often I need to resolve the name of a `TyThing` defined inside `Lib`. Normally, this is easy enough: I simply use
hscTcRcLookupName :: HscEnv https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/ghc-8.2.1/HscTy... -> Name https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/ghc-8.2.1/Name.... -> IO https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/base-4.10.0.0/S... (Maybe https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/base-4.10.0.0/D... TyThing https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/ghc-8.2.1/Type.... )
defined inside HscMain.
**THE PROBLEM** However, I find that when the relevant `Name` corresponds to something generated by TemplateHaskell (inside `Lib`) then the above `hscTcRcLookupName` fails to return any result! Even more oddly, suppose the name was
BlogPostId
If there are TWO `TyThing`s with that name, e.g. a type synonym defined
type BlogPostId = ...
and also a data constructor for a data family instance, then `hscTcRcLookupName` only returns the type synonym, but refuses to return the data constructor.
Does anyone know what may be going on?
Thanks!
- Ranjit Jhala.
participants (1)
-
Ranjit Jhala