diff options
author | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2019-07-24 17:17:47 +0300 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-07-26 00:58:15 -0400 |
commit | 00d9d28405a5983ae40a1815a146fb27abca10e8 (patch) | |
tree | f0d77ea51aadd9f27b296e36191de80958a3d380 /compiler | |
parent | aae0457f412aa40dd192ca2cbea565ea60b182ec (diff) | |
download | haskell-00d9d28405a5983ae40a1815a146fb27abca10e8.tar.gz |
TemplateHaskell: reifyType (#16976)
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/typecheck/TcSplice.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/compiler/typecheck/TcSplice.hs b/compiler/typecheck/TcSplice.hs index bcdc503e56..ba4f58752f 100644 --- a/compiler/typecheck/TcSplice.hs +++ b/compiler/typecheck/TcSplice.hs @@ -945,6 +945,7 @@ instance TH.Quasi TcM where qLookupName = lookupName qReify = reify qReifyFixity nm = lookupThName nm >>= reifyFixity + qReifyType = reifyTypeOfThing qReifyInstances = reifyInstances qReifyRoles = reifyRoles qReifyAnnotations = reifyAnnotations @@ -1210,6 +1211,7 @@ handleTHMessage msg = case msg of LookupName b str -> wrapTHResult $ TH.qLookupName b str Reify n -> wrapTHResult $ TH.qReify n ReifyFixity n -> wrapTHResult $ TH.qReifyFixity n + ReifyType n -> wrapTHResult $ TH.qReifyType n ReifyInstances n ts -> wrapTHResult $ TH.qReifyInstances n ts ReifyRoles n -> wrapTHResult $ TH.qReifyRoles n ReifyAnnotations lookup tyrep -> @@ -2015,6 +2017,20 @@ reifyDecidedStrictness HsLazy = TH.DecidedLazy reifyDecidedStrictness HsStrict = TH.DecidedStrict reifyDecidedStrictness HsUnpack{} = TH.DecidedUnpack +reifyTypeOfThing :: TH.Name -> TcM TH.Type +reifyTypeOfThing th_name = do + thing <- getThing th_name + case thing of + AGlobal (AnId id) -> reifyType (idType id) + AGlobal (ATyCon tc) -> reifyKind (tyConKind tc) + AGlobal (AConLike (RealDataCon dc)) -> + reifyType (idType (dataConWrapId dc)) + AGlobal (AConLike (PatSynCon ps)) -> + reifyPatSynType (patSynSig ps) + ATcId{tct_id = id} -> zonkTcType (idType id) >>= reifyType + ATyVar _ tctv -> zonkTcTyVar tctv >>= reifyType + _ -> failWithTc (text "No type or kind associated with" <+> ppr thing) + ------------------------------ lookupThAnnLookup :: TH.AnnLookup -> TcM CoreAnnTarget lookupThAnnLookup (TH.AnnLookupName th_nm) = fmap NamedTarget (lookupThName th_nm) |