- occ_fs = mkFastString (TH.occString occ)
- bogus_ns = OccName.varName -- Not yet recorded in the TH name
- -- but only the unique matters
-
-mk_uniq :: Int# -> Unique
-mk_uniq u = mkUniqueGrimily (I# u)
+ -- guessed_ns is the name space guessed from looking at the TH name
+ guessed_ns | isLexCon (mkFastString occ_str) = OccName.dataName
+ | otherwise = OccName.varName
+ occ_str = TH.occString occ
+
+tcLookupTh :: Name -> TcM TcTyThing
+-- This is a specialised version of TcEnv.tcLookup; specialised mainly in that
+-- it gives a reify-related error message on failure, whereas in the normal
+-- tcLookup, failure is a bug.
+tcLookupTh name
+ = do { (gbl_env, lcl_env) <- getEnvs
+ ; case lookupNameEnv (tcl_env lcl_env) name of {
+ Just thing -> returnM thing;
+ Nothing -> do
+ { if nameIsLocalOrFrom (tcg_mod gbl_env) name
+ then -- It's defined in this module
+ case lookupNameEnv (tcg_type_env gbl_env) name of
+ Just thing -> return (AGlobal thing)
+ Nothing -> failWithTc (notInEnv name)
+
+ else do -- It's imported
+ { (eps,hpt) <- getEpsAndHpt
+ ; case lookupType hpt (eps_PTE eps) name of
+ Just thing -> return (AGlobal thing)
+ Nothing -> do { thing <- tcImportDecl name
+ ; return (AGlobal thing) }
+ -- Imported names should always be findable;
+ -- if not, we fail hard in tcImportDecl
+ }}}}