| ... |
... |
@@ -1555,13 +1555,13 @@ rep_splice splice_name |
|
1555
|
1555
|
-- Expressions
|
|
1556
|
1556
|
-----------------------------------------------------------------------------
|
|
1557
|
1557
|
|
|
1558
|
|
-repLEs :: [LHsExpr GhcRn] -> MetaM (Core [(M TH.Exp)])
|
|
|
1558
|
+repLEs :: forall p. (IsPass p) => [LHsExpr (GhcPass p)] -> MetaM (Core [(M TH.Exp)])
|
|
1559
|
1559
|
repLEs es = repListM expTyConName repLE es
|
|
1560
|
1560
|
|
|
1561
|
1561
|
-- FIXME: some of these panics should be converted into proper error messages
|
|
1562
|
1562
|
-- unless we can make sure that constructs, which are plainly not
|
|
1563
|
1563
|
-- supported in TH already lead to error messages at an earlier stage
|
|
1564
|
|
-repLE :: LHsExpr GhcRn -> MetaM (Core (M TH.Exp))
|
|
|
1564
|
+repLE :: forall p. (IsPass p) => LHsExpr (GhcPass p) -> MetaM (Core (M TH.Exp))
|
|
1565
|
1565
|
repLE (L loc e) = mapReaderT (putSrcSpanDs (locA loc)) (repE e)
|
|
1566
|
1566
|
|
|
1567
|
1567
|
repE :: forall p. (IsPass p) => HsExpr (GhcPass p) -> MetaM (Core (M TH.Exp))
|
| ... |
... |
@@ -1671,7 +1671,7 @@ repE e@(HsDo _ ctxt (L _ sts)) |
|
1671
|
1671
|
|
|
1672
|
1672
|
repE (ExplicitList _ es) = do { xs <- repLEs es; repListExp xs }
|
|
1673
|
1673
|
repE (ExplicitTuple _ es boxity) =
|
|
1674
|
|
- let tupArgToCoreExp :: HsTupArg GhcRn -> MetaM (Core (Maybe (M TH.Exp)))
|
|
|
1674
|
+ let tupArgToCoreExp :: forall p. (IsPass p) => HsTupArg (GhcPass p) -> MetaM (Core (Maybe (M TH.Exp)))
|
|
1675
|
1675
|
tupArgToCoreExp a
|
|
1676
|
1676
|
| (Present _ e) <- a = do { e' <- repLE e
|
|
1677
|
1677
|
; coreJustM expTyConName e' }
|
| ... |
... |
@@ -1749,7 +1749,7 @@ repE (HsForAll _ tele body) = |
|
1749
|
1749
|
HsForAllVis _ tvs -> mk_forall forallVisEName tvs
|
|
1750
|
1750
|
HsForAllInvis _ tvs -> mk_forall forallEName tvs
|
|
1751
|
1751
|
where
|
|
1752
|
|
- mk_forall :: RepTV flag flag' => Name -> [LHsTyVarBndr flag GhcRn] -> MetaM (Core (M TH.Exp))
|
|
|
1752
|
+ mk_forall :: forall flag flag' p. (IsPass p, RepTV flag flag') => Name -> [LHsTyVarBndr flag (GhcPass p)] -> MetaM (Core (M TH.Exp))
|
|
1753
|
1753
|
mk_forall forall_name tvs =
|
|
1754
|
1754
|
addHsTyVarBinds FreshNamesOnly tvs $ \bndrs -> do
|
|
1755
|
1755
|
body' <- repLE body
|
| ... |
... |
@@ -1774,7 +1774,9 @@ repE e@(HsUntypedBracket{}) = notHandled (ThExpressionForm e) |
|
1774
|
1774
|
repE e@(HsProc{}) = notHandled (ThExpressionForm e)
|
|
1775
|
1775
|
repE e@(HsStar{}) = notHandled (ThExpressionForm e)
|
|
1776
|
1776
|
|
|
1777
|
|
-repFunArrMult :: HsModifiedFunArrOf (LocatedA (HsExpr GhcRn)) GhcRn -> MetaM (Core (M TH.Exp))
|
|
|
1777
|
+repFunArrMult :: forall p. (IsPass p)
|
|
|
1778
|
+ => HsModifiedFunArrOf (LocatedA (HsExpr (GhcPass p))) (GhcPass p)
|
|
|
1779
|
+ -> MetaM (Core (M TH.Exp))
|
|
1778
|
1780
|
repFunArrMult (HsModifiedFunArr _ mods arr) = case (arr, mods) of
|
|
1779
|
1781
|
(HsStandardArr _, []) -> repConName unrestrictedFunTyConName
|
|
1780
|
1782
|
(HsStandardArr _, [L _ (HsModifier _ m)]) -> do
|
| ... |
... |
@@ -1819,7 +1821,7 @@ the choice in ExpandedThingRn, but it seems simpler to consult the flag (again). |
|
1819
|
1821
|
-----------------------------------------------------------------------------
|
|
1820
|
1822
|
-- Building representations of auxiliary structures like Match, Clause, Stmt,
|
|
1821
|
1823
|
|
|
1822
|
|
-repMatchTup :: LMatch GhcRn (LHsExpr GhcRn) -> MetaM (Core (M TH.Match))
|
|
|
1824
|
+repMatchTup :: forall p. IsPass p => LMatch (GhcPass p) (LHsExpr (GhcPass p)) -> MetaM (Core (M TH.Match))
|
|
1823
|
1825
|
repMatchTup (L _ (Match { m_pats = L _ [p]
|
|
1824
|
1826
|
, m_grhss = GRHSs _ guards wheres })) =
|
|
1825
|
1827
|
do { ss1 <- mkGenSyms (collectPatBinders CollNoDictBinders p)
|
| ... |
... |
@@ -1832,7 +1834,7 @@ repMatchTup (L _ (Match { m_pats = L _ [p] |
|
1832
|
1834
|
; wrapGenSyms (ss1++ss2) match }}}
|
|
1833
|
1835
|
repMatchTup _ = panic "repMatchTup: case alt with more than one arg or with invisible pattern"
|
|
1834
|
1836
|
|
|
1835
|
|
-repClauseTup :: LMatch GhcRn (LHsExpr GhcRn) -> MetaM (Core (M TH.Clause))
|
|
|
1837
|
+repClauseTup :: forall p. IsPass p => LMatch (GhcPass p) (LHsExpr (GhcPass p)) -> MetaM (Core (M TH.Clause))
|
|
1836
|
1838
|
repClauseTup (L _ (Match { m_pats = L _ ps
|
|
1837
|
1839
|
, m_grhss = GRHSs _ guards wheres })) =
|
|
1838
|
1840
|
do { ss1 <- mkGenSyms (collectPatsBinders CollNoDictBinders ps)
|
| ... |
... |
@@ -1844,7 +1846,7 @@ repClauseTup (L _ (Match { m_pats = L _ ps |
|
1844
|
1846
|
; clause <- repClause ps1 gs ds
|
|
1845
|
1847
|
; wrapGenSyms (ss1++ss2) clause }}}
|
|
1846
|
1848
|
|
|
1847
|
|
-repGuards :: NonEmpty (LGRHS GhcRn (LHsExpr GhcRn)) -> MetaM (Core (M TH.Body))
|
|
|
1849
|
+repGuards :: forall p. IsPass p => NonEmpty (LGRHS (GhcPass p) (LHsExpr (GhcPass p))) -> MetaM (Core (M TH.Body))
|
|
1848
|
1850
|
repGuards (L _ (GRHS _ [] e) :| [])
|
|
1849
|
1851
|
= do {a <- repLE e; repNormal a }
|
|
1850
|
1852
|
repGuards other
|
| ... |
... |
@@ -1853,7 +1855,7 @@ repGuards other |
|
1853
|
1855
|
; gd <- repGuarded (nonEmptyCoreList' ys)
|
|
1854
|
1856
|
; wrapGenSyms (concat xs) gd }
|
|
1855
|
1857
|
|
|
1856
|
|
-repLGRHS :: LGRHS GhcRn (LHsExpr GhcRn)
|
|
|
1858
|
+repLGRHS :: forall p. IsPass p => LGRHS (GhcPass p) (LHsExpr (GhcPass p))
|
|
1857
|
1859
|
-> MetaM ([GenSymBind], (Core (M (TH.Guard, TH.Exp))))
|
|
1858
|
1860
|
repLGRHS (L _ (GRHS _ [L _ (BodyStmt _ e1 _ _)] e2))
|
|
1859
|
1861
|
= do { guarded <- repLNormalGE e1 e2
|
| ... |
... |
@@ -1864,20 +1866,20 @@ repLGRHS (L _ (GRHS _ ss rhs)) |
|
1864
|
1866
|
; guarded <- repPatGE (nonEmptyCoreList ss') rhs'
|
|
1865
|
1867
|
; return (gs, guarded) }
|
|
1866
|
1868
|
|
|
1867
|
|
-repFields :: HsRecordBinds GhcRn -> MetaM (Core [M TH.FieldExp])
|
|
|
1869
|
+repFields :: forall p. IsPass p => HsRecordBinds (GhcPass p) -> MetaM (Core [M TH.FieldExp])
|
|
1868
|
1870
|
repFields (HsRecFields { rec_flds = flds })
|
|
1869
|
1871
|
= repListM fieldExpTyConName rep_fld flds
|
|
1870
|
1872
|
where
|
|
1871
|
|
- rep_fld :: LHsRecField GhcRn (LHsExpr GhcRn)
|
|
|
1873
|
+ rep_fld :: forall p. (IsPass p) => LHsRecField (GhcPass p) (LHsExpr (GhcPass p))
|
|
1872
|
1874
|
-> MetaM (Core (M TH.FieldExp))
|
|
1873
|
1875
|
rep_fld (L _ fld) = do { fn <- lookupOcc (hsRecFieldSel fld)
|
|
1874
|
1876
|
; e <- repLE (hfbRHS fld)
|
|
1875
|
1877
|
; repFieldExp fn e }
|
|
1876
|
1878
|
|
|
1877
|
|
-repUpdFields :: [LHsRecUpdField GhcRn GhcRn] -> MetaM (Core [M TH.FieldExp])
|
|
|
1879
|
+repUpdFields :: forall p. IsPass p => [LHsRecUpdField (GhcPass p) (GhcPass p)] -> MetaM (Core [M TH.FieldExp])
|
|
1878
|
1880
|
repUpdFields = repListM fieldExpTyConName rep_fld
|
|
1879
|
1881
|
where
|
|
1880
|
|
- rep_fld :: LHsRecUpdField GhcRn GhcRn -> MetaM (Core (M TH.FieldExp))
|
|
|
1882
|
+ rep_fld :: forall p. IsPass p => LHsRecUpdField (GhcPass p) (GhcPass p) -> MetaM (Core (M TH.FieldExp))
|
|
1881
|
1883
|
rep_fld (L l fld) =
|
|
1882
|
1884
|
let (FieldOcc _ (L _ sel_name)) = unLoc (hfbLHS fld)
|
|
1883
|
1885
|
-- If we have an unbountName in the sel_name, that means we failed to
|
| ... |
... |
@@ -1920,10 +1922,10 @@ repUpdFields = repListM fieldExpTyConName rep_fld |
|
1920
|
1922
|
-- The helper function repSts computes the translation of each sub expression
|
|
1921
|
1923
|
-- and a bunch of prefix bindings denoting the dynamic renaming.
|
|
1922
|
1924
|
|
|
1923
|
|
-repLSts :: [LStmt GhcRn (LHsExpr GhcRn)] -> MetaM ([GenSymBind], [Core (M TH.Stmt)])
|
|
|
1925
|
+repLSts :: forall p. IsPass p => [LStmt (GhcPass p) (LHsExpr (GhcPass p))] -> MetaM ([GenSymBind], [Core (M TH.Stmt)])
|
|
1924
|
1926
|
repLSts stmts = repSts (map unLoc stmts)
|
|
1925
|
1927
|
|
|
1926
|
|
-repSts :: [Stmt GhcRn (LHsExpr GhcRn)] -> MetaM ([GenSymBind], [Core (M TH.Stmt)])
|
|
|
1928
|
+repSts :: forall p. IsPass p => [Stmt (GhcPass p) (LHsExpr (GhcPass p))] -> MetaM ([GenSymBind], [Core (M TH.Stmt)])
|
|
1927
|
1929
|
repSts (BindStmt _ p e : ss) =
|
|
1928
|
1930
|
do { e2 <- repLE e
|
|
1929
|
1931
|
; ss1 <- mkGenSyms (collectPatBinders CollNoDictBinders p)
|
| ... |
... |
@@ -1950,7 +1952,7 @@ repSts (ParStmt _ stmt_blocks _ _ : ss) = |
|
1950
|
1952
|
; (ss2, zs) <- addBinds ss1 (repSts ss)
|
|
1951
|
1953
|
; return (ss1++ss2, z : zs) }
|
|
1952
|
1954
|
where
|
|
1953
|
|
- rep_stmt_block :: ParStmtBlock GhcRn GhcRn
|
|
|
1955
|
+ rep_stmt_block :: forall p. IsPass p => ParStmtBlock (GhcPass p) (GhcPass p)
|
|
1954
|
1956
|
-> MetaM ([GenSymBind], Core [(M TH.Stmt)])
|
|
1955
|
1957
|
rep_stmt_block (ParStmtBlock _ stmts _ _) =
|
|
1956
|
1958
|
do { (ss1, zs) <- repSts (map unLoc stmts)
|
| ... |
... |
@@ -1978,7 +1980,7 @@ repSts other = notHandled (ThExoticStatement other) |
|
1978
|
1980
|
-- Bindings
|
|
1979
|
1981
|
-----------------------------------------------------------
|
|
1980
|
1982
|
|
|
1981
|
|
-repBinds :: HsLocalBinds GhcRn -> MetaM ([GenSymBind], Core [(M TH.Dec)])
|
|
|
1983
|
+repBinds :: forall p. IsPass p => HsLocalBinds (GhcPass p) -> MetaM ([GenSymBind], Core [(M TH.Dec)])
|
|
1982
|
1984
|
repBinds (EmptyLocalBinds _)
|
|
1983
|
1985
|
= do { core_list <- coreListM decTyConName []
|
|
1984
|
1986
|
; return ([], core_list) }
|
| ... |
... |
@@ -2003,7 +2005,7 @@ repBinds (HsValBinds _ decs) |
|
2003
|
2005
|
(de_loc (sort_by_loc prs))
|
|
2004
|
2006
|
; return (ss, core_list) }
|
|
2005
|
2007
|
|
|
2006
|
|
-rep_implicit_param_bind :: LIPBind GhcRn -> MetaM (SrcSpan, Core (M TH.Dec))
|
|
|
2008
|
+rep_implicit_param_bind :: forall p. IsPass p => LIPBind (GhcPass p) -> MetaM (SrcSpan, Core (M TH.Dec))
|
|
2007
|
2009
|
rep_implicit_param_bind (L loc (IPBind _ (L _ n) (L _ rhs)))
|
|
2008
|
2010
|
= do { name <- rep_implicit_param_name n
|
|
2009
|
2011
|
; rhs' <- repE rhs
|
| ... |
... |
@@ -2013,7 +2015,7 @@ rep_implicit_param_bind (L loc (IPBind _ (L _ n) (L _ rhs))) |
|
2013
|
2015
|
rep_implicit_param_name :: HsIPName -> MetaM (Core String)
|
|
2014
|
2016
|
rep_implicit_param_name (HsIPName name) = coreStringLit name
|
|
2015
|
2017
|
|
|
2016
|
|
-rep_val_binds :: HsValBinds GhcRn -> MetaM [(SrcSpan, Core (M TH.Dec))]
|
|
|
2018
|
+rep_val_binds :: forall p. IsPass p => HsValBinds (GhcPass p) -> MetaM [(SrcSpan, Core (M TH.Dec))]
|
|
2017
|
2019
|
-- Assumes: all the binders of the binding are already in the meta-env
|
|
2018
|
2020
|
rep_val_binds (XValBindsLR (HsVBG binds sigs))
|
|
2019
|
2021
|
= do { core1 <- rep_binds (concatMap snd binds)
|
| ... |
... |
@@ -2022,10 +2024,10 @@ rep_val_binds (XValBindsLR (HsVBG binds sigs)) |
|
2022
|
2024
|
rep_val_binds (ValBinds _ _ _)
|
|
2023
|
2025
|
= panic "rep_val_binds: ValBinds"
|
|
2024
|
2026
|
|
|
2025
|
|
-rep_binds :: LHsBinds GhcRn -> MetaM [(SrcSpan, Core (M TH.Dec))]
|
|
|
2027
|
+rep_binds :: forall p. IsPass p => LHsBinds (GhcPass p) -> MetaM [(SrcSpan, Core (M TH.Dec))]
|
|
2026
|
2028
|
rep_binds = mapM rep_bind
|
|
2027
|
2029
|
|
|
2028
|
|
-rep_bind :: LHsBind GhcRn -> MetaM (SrcSpan, Core (M TH.Dec))
|
|
|
2030
|
+rep_bind :: forall p. IsPass p => LHsBind (GhcPass p) -> MetaM (SrcSpan, Core (M TH.Dec))
|
|
2029
|
2031
|
-- Assumes: all the binders of the binding are already in the meta-env
|
|
2030
|
2032
|
|
|
2031
|
2033
|
-- Note GHC treats declarations of a variable (not a pattern)
|
| ... |
... |
@@ -2082,7 +2084,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn |
|
2082
|
2084
|
; patSynD'' <- wrapGenArgSyms args ss patSynD'
|
|
2083
|
2085
|
; return (locA loc, patSynD'') }
|
|
2084
|
2086
|
where
|
|
2085
|
|
- mkGenArgSyms :: HsPatSynDetails GhcRn -> MetaM [GenSymBind]
|
|
|
2087
|
+ mkGenArgSyms :: forall p. IsPass p => HsPatSynDetails (GhcPass p) -> MetaM [GenSymBind]
|
|
2086
|
2088
|
-- for Record Pattern Synonyms we want to conflate the selector
|
|
2087
|
2089
|
-- and the pattern-only names in order to provide a nicer TH
|
|
2088
|
2090
|
-- API. Whereas inside GHC, record pattern synonym selectors and
|
| ... |
... |
@@ -2101,7 +2103,7 @@ rep_bind (L loc (PatSynBind _ (PSB { psb_id = syn |
|
2101
|
2103
|
= [ (pat, id) | (sel, id) <- genSyms, (sel', pat) <- selsPats
|
|
2102
|
2104
|
, sel == sel' ]
|
|
2103
|
2105
|
|
|
2104
|
|
- wrapGenArgSyms :: HsPatSynDetails GhcRn
|
|
|
2106
|
+ wrapGenArgSyms :: forall p. IsPass p => HsPatSynDetails (GhcPass p)
|
|
2105
|
2107
|
-> [GenSymBind] -> Core (M TH.Dec) -> MetaM (Core (M TH.Dec))
|
|
2106
|
2108
|
wrapGenArgSyms (RecCon _) _ dec = return dec
|
|
2107
|
2109
|
wrapGenArgSyms _ ss dec = wrapGenSyms ss dec
|
| ... |
... |
@@ -2139,7 +2141,7 @@ repRecordPatSynArgs :: Core [TH.Name] |
|
2139
|
2141
|
-> MetaM (Core (M TH.PatSynArgs))
|
|
2140
|
2142
|
repRecordPatSynArgs (MkC sels) = rep2 recordPatSynName [sels]
|
|
2141
|
2143
|
|
|
2142
|
|
-repPatSynDir :: HsPatSynDir GhcRn -> MetaM (Core (M TH.PatSynDir))
|
|
|
2144
|
+repPatSynDir :: forall p. IsPass p => HsPatSynDir (GhcPass p) -> MetaM (Core (M TH.PatSynDir))
|
|
2143
|
2145
|
repPatSynDir Unidirectional = rep2 unidirPatSynName []
|
|
2144
|
2146
|
repPatSynDir ImplicitBidirectional = rep2 implBidirPatSynName []
|
|
2145
|
2147
|
repPatSynDir (ExplicitBidirectional (MG { mg_alts = (L _ clauses) }))
|
| ... |
... |
@@ -2195,10 +2197,10 @@ repLambda (L _ m) = notHandled (ThGuardedLambdas m) |
|
2195
|
2197
|
-- variable should already appear in the environment.
|
|
2196
|
2198
|
|
|
2197
|
2199
|
-- Process a list of patterns
|
|
2198
|
|
-repLPs :: [LPat GhcRn] -> MetaM (Core [(M TH.Pat)])
|
|
|
2200
|
+repLPs :: forall p. IsPass p => [LPat (GhcPass p)] -> MetaM (Core [(M TH.Pat)])
|
|
2199
|
2201
|
repLPs ps = repListM patTyConName repLP ps
|
|
2200
|
2202
|
|
|
2201
|
|
-repLPs1 :: NonEmpty (LPat GhcRn) -> MetaM (Core (NonEmpty (M TH.Pat)))
|
|
|
2203
|
+repLPs1 :: forall p. IsPass p => NonEmpty (LPat (GhcPass p)) -> MetaM (Core (NonEmpty (M TH.Pat)))
|
|
2202
|
2204
|
repLPs1 ps = repNonEmptyM patTyConName repLP ps
|
|
2203
|
2205
|
|
|
2204
|
2206
|
repLP :: forall p. IsPass p => LPat (GhcPass p) -> MetaM (Core (M TH.Pat))
|