The Backpack patch.
[ghc.git] / compiler / backpack / RnModIface.hs
1 {-# LANGUAGE CPP #-}
2 {-# LANGUAGE LambdaCase #-}
3
4 -- | This module implements interface renaming, which is
5 -- used to rewrite interface files on the fly when we
6 -- are doing indefinite typechecking and need instantiations
7 -- of modules which do not necessarily exist yet.
8
9 module RnModIface(
10 rnModIface,
11 rnModExports,
12 ) where
13
14 #include "HsVersions.h"
15
16 import Outputable
17 import HscTypes
18 import Module
19 import UniqFM
20 import Avail
21 import IfaceSyn
22 import FieldLabel
23 import Var
24
25 import Name
26 import TcRnMonad
27 import Util
28 import Fingerprint
29 import BasicTypes
30
31 -- a bit vexing
32 import {-# SOURCE #-} LoadIface
33 import DynFlags
34
35 import qualified Data.Traversable as T
36
37 import NameShape
38 import IfaceEnv
39
40 -- | What we have a generalized ModIface, which corresponds to
41 -- a module that looks like p[A=<A>]:B. We need a *specific* ModIface, e.g.
42 -- p[A=q():A]:B (or maybe even p[A=<B>]:B) which we load
43 -- up (either to merge it, or to just use during typechecking).
44 --
45 -- Suppose we have:
46 --
47 -- p[A=<A>]:M ==> p[A=q():A]:M
48 --
49 -- Substitute all occurrences of <A> with q():A (renameHoleModule).
50 -- Then, for any Name of form {A.T}, replace the Name with
51 -- the Name according to the exports of the implementing module.
52 -- This works even for p[A=<B>]:M, since we just read in the
53 -- exports of B.hi, which is assumed to be ready now.
54 --
55 -- This function takes an optional 'NameShape', which can be used
56 -- to further refine the identities in this interface: suppose
57 -- we read a declaration for {H.T} but we actually know that this
58 -- should be Foo.T; then we'll also rename this (this is used
59 -- when loading an interface to merge it into a requirement.)
60 rnModIface :: HscEnv -> [(ModuleName, Module)] -> Maybe NameShape
61 -> ModIface -> IO ModIface
62 rnModIface hsc_env insts nsubst iface = do
63 initRnIface hsc_env iface insts nsubst $ do
64 mod <- rnModule (mi_module iface)
65 sig_of <- case mi_sig_of iface of
66 Nothing -> return Nothing
67 Just x -> fmap Just (rnModule x)
68 exports <- mapM rnAvailInfo (mi_exports iface)
69 decls <- mapM rnIfaceDecl' (mi_decls iface)
70 insts <- mapM rnIfaceClsInst (mi_insts iface)
71 fams <- mapM rnIfaceFamInst (mi_fam_insts iface)
72 -- TODO:
73 -- mi_rules
74 -- mi_vect_info (LOW PRIORITY)
75 return iface { mi_module = mod
76 , mi_sig_of = sig_of
77 , mi_insts = insts
78 , mi_fam_insts = fams
79 , mi_exports = exports
80 , mi_decls = decls }
81
82 -- | Rename just the exports of a 'ModIface'. Useful when we're doing
83 -- shaping prior to signature merging.
84 rnModExports :: HscEnv -> [(ModuleName, Module)] -> ModIface -> IO [AvailInfo]
85 rnModExports hsc_env insts iface
86 = initRnIface hsc_env iface insts Nothing
87 $ mapM rnAvailInfo (mi_exports iface)
88
89 {-
90 ************************************************************************
91 * *
92 ModIface substitution
93 * *
94 ************************************************************************
95 -}
96
97 -- | Initialize the 'ShIfM' monad.
98 initRnIface :: HscEnv -> ModIface -> [(ModuleName, Module)] -> Maybe NameShape
99 -> ShIfM a -> IO a
100 initRnIface hsc_env iface insts nsubst do_this =
101 let hsubst = listToUFM insts
102 rn_mod = renameHoleModule (hsc_dflags hsc_env) hsubst
103 env = ShIfEnv {
104 sh_if_module = rn_mod (mi_module iface),
105 sh_if_semantic_module = rn_mod (mi_semantic_module iface),
106 sh_if_hole_subst = listToUFM insts,
107 sh_if_shape = nsubst
108 }
109 in initTcRnIf 'c' hsc_env env () do_this
110
111 -- | Environment for 'ShIfM' monads.
112 data ShIfEnv = ShIfEnv {
113 -- What we are renaming the ModIface to. It assumed that
114 -- the original mi_module of the ModIface is
115 -- @generalizeModule (mi_module iface)@.
116 sh_if_module :: Module,
117 -- The semantic module that we are renaming to
118 sh_if_semantic_module :: Module,
119 -- Cached hole substitution, e.g.
120 -- @sh_if_hole_subst == listToUFM . unitIdInsts . moduleUnitId . sh_if_module@
121 sh_if_hole_subst :: ShHoleSubst,
122 -- An optional name substitution to be applied when renaming
123 -- the names in the interface. If this is 'Nothing', then
124 -- we just load the target interface and look at the export
125 -- list to determine the renaming.
126 sh_if_shape :: Maybe NameShape
127 }
128
129 getHoleSubst :: ShIfM ShHoleSubst
130 getHoleSubst = fmap sh_if_hole_subst getGblEnv
131
132 type ShIfM = TcRnIf ShIfEnv ()
133 type Rename a = a -> ShIfM a
134
135
136 rnModule :: Rename Module
137 rnModule mod = do
138 hmap <- getHoleSubst
139 dflags <- getDynFlags
140 return (renameHoleModule dflags hmap mod)
141
142 rnAvailInfo :: Rename AvailInfo
143 rnAvailInfo (Avail p n) = Avail p <$> rnIfaceGlobal n
144 rnAvailInfo (AvailTC n ns fs) = do
145 -- Why don't we rnIfaceGlobal the availName itself? It may not
146 -- actually be exported by the module it putatively is from, in
147 -- which case we won't be able to tell what the name actually
148 -- is. But for the availNames they MUST be exported, so they
149 -- will rename fine.
150 ns' <- mapM rnIfaceGlobal ns
151 fs' <- mapM rnFieldLabel fs
152 case ns' ++ map flSelector fs' of
153 [] -> panic "rnAvailInfoEmpty AvailInfo"
154 (rep:rest) -> ASSERT2( all ((== nameModule rep) . nameModule) rest, ppr rep $$ hcat (map ppr rest) ) do
155 n' <- setNameModule (Just (nameModule rep)) n
156 return (AvailTC n' ns' fs')
157
158 rnFieldLabel :: Rename FieldLabel
159 rnFieldLabel (FieldLabel l b sel) = do
160 sel' <- rnIfaceGlobal sel
161 return (FieldLabel l b sel')
162
163
164
165
166 -- | The key function. This gets called on every Name embedded
167 -- inside a ModIface. Our job is to take a Name from some
168 -- generalized unit ID p[A=<A>, B=<B>], and change
169 -- it to the correct name for a (partially) instantiated unit
170 -- ID, e.g. p[A=q[]:A, B=<B>].
171 --
172 -- There are two important things to do:
173 --
174 -- If a hole is substituted with a real module implementation,
175 -- we need to look at that actual implementation to determine what
176 -- the true identity of this name should be. We'll do this by
177 -- loading that module's interface and looking at the mi_exports.
178 --
179 -- However, there is one special exception: when we are loading
180 -- the interface of a requirement. In this case, we may not have
181 -- the "implementing" interface, because we are reading this
182 -- interface precisely to "merge it in".
183 --
184 -- External case:
185 -- p[A=<B>]:A (and thisUnitId is something else)
186 -- We are loading this in order to determine B.hi! So
187 -- don't load B.hi to find the exports.
188 --
189 -- Local case:
190 -- p[A=<A>]:A (and thisUnitId is p[A=<A>])
191 -- This should not happen, because the rename is not necessary
192 -- in this case, but if it does we shouldn't load A.hi!
193 --
194 -- Compare me with 'tcIfaceGlobal'!
195
196 -- In effect, this function needs compute the name substitution on the
197 -- fly. What it has is the name that we would like to substitute.
198 -- If the name is not a hole name {M.x} (e.g. isHoleModule) then
199 -- no renaming can take place (although the inner hole structure must
200 -- be updated to account for the hole module renaming.)
201 rnIfaceGlobal :: Name -> ShIfM Name
202 rnIfaceGlobal n = do
203 hsc_env <- getTopEnv
204 let dflags = hsc_dflags hsc_env
205 iface_semantic_mod <- fmap sh_if_semantic_module getGblEnv
206 mb_nsubst <- fmap sh_if_shape getGblEnv
207 hmap <- getHoleSubst
208 let m = nameModule n
209 m' = renameHoleModule dflags hmap m
210 case () of
211 -- Did we encounter {A.T} while renaming p[A=<B>]:A? If so,
212 -- do NOT assume B.hi is available.
213 -- In this case, rename {A.T} to {B.T} but don't look up exports.
214 _ | m' == iface_semantic_mod
215 , isHoleModule m'
216 -- NB: this could be Nothing for computeExports, we have
217 -- nothing to say.
218 -> do fmap (case mb_nsubst of
219 Nothing -> id
220 Just nsubst -> substNameShape nsubst)
221 $ setNameModule (Just m') n
222 -- Fastpath: we are renaming p[H=<H>]:A.T, in which case the
223 -- export list is irrelevant.
224 | not (isHoleModule m)
225 -> setNameModule (Just m') n
226 -- The substitution was from <A> to p[]:A.
227 -- But this does not mean {A.T} goes to p[]:A.T:
228 -- p[]:A may reexport T from somewhere else. Do the name
229 -- substitution. Furthermore, we need
230 -- to make sure we pick the accurate name NOW,
231 -- or we might accidentally reject a merge.
232 | otherwise
233 -> do -- Make sure we look up the local interface if substitution
234 -- went from <A> to <B>.
235 let m'' = if isHoleModule m'
236 -- Pull out the local guy!!
237 then mkModule (thisPackage dflags) (moduleName m')
238 else m'
239 iface <- liftIO . initIfaceCheck (text "rnIfaceGlobal") hsc_env
240 $ loadSysInterface (text "rnIfaceGlobal") m''
241 let nsubst = mkNameShape (moduleName m) (mi_exports iface)
242 return (substNameShape nsubst n)
243
244 -- PILES AND PILES OF BOILERPLATE
245
246 -- | Rename an 'IfaceClsInst', with special handling for an associated
247 -- dictionary function.
248 rnIfaceClsInst :: Rename IfaceClsInst
249 rnIfaceClsInst cls_inst = do
250 n <- rnIfaceGlobal (ifInstCls cls_inst)
251 tys <- mapM rnMaybeIfaceTyCon (ifInstTys cls_inst)
252
253 hmap <- getHoleSubst
254 dflags <- getDynFlags
255
256 -- Note [Bogus DFun renamings]
257 -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
258 -- Every 'IfaceClsInst' is associated with a DFun; in fact, when
259 -- we are typechecking only, it is the ONLY place a DFun Id
260 -- can appear. This DFun must refer to a DFun that is defined
261 -- elsewhere in the 'ModIface'.
262 --
263 -- Unfortunately, DFuns are not exported (don't appear in
264 -- mi_exports), so we can't look at the exports (as we do in
265 -- rnIfaceGlobal) to rename it.
266 --
267 -- We have to rename it to *something*. So what we do depends
268 -- on the situation:
269 --
270 -- * If the instance wasn't defined in a signature, the DFun
271 -- have a name like p[A=<A>]:B.$fShowFoo. This is the
272 -- easy case: just apply the module substitution to the
273 -- unit id and go our merry way.
274 --
275 -- * If the instance was defined in a signature, we are in
276 -- an interesting situation. Suppose we are instantiating
277 -- the signature:
278 --
279 -- signature H where
280 -- instance F T -- {H.$fxFT}
281 -- module H where
282 -- instance F T where ... -- p[]:H.$fFT
283 --
284 -- In an ideal world, we would map {H.$fxFT} to p[]:H.$fFT.
285 -- But we have no idea what the correct DFun is: the OccNames
286 -- don't match up. Nor do we really want to wire up {H.$fxFT}
287 -- to p[]:H.$fFT: we'd rather have it point at the DFun
288 -- from the *signature's* interface, and use that type to
289 -- find the actual instance we want to compare against.
290 --
291 -- So, to handle this case, we have to do several things:
292 --
293 -- * In 'rnIfaceClsInst', we just blindly rename the
294 -- the identifier to something that looks vaguely plausible.
295 -- In the instantiating case, we just map {H.$fxFT}
296 -- to p[]:H.$fxFT. In the merging case, we map
297 -- {H.$fxFT} to {H2.$fxFT}.
298 --
299 -- * In 'lookupIfaceTop', we arrange for the top-level DFun
300 -- to be assigned the very same identifier we picked
301 -- during renaming (p[]:H.$fxFT)
302 --
303 -- * Finally, in 'tcIfaceInstWithDFunTypeEnv', we make sure
304 -- to grab the correct 'TyThing' for the DFun directly
305 -- from the local type environment (which was constructed
306 -- using 'Name's from 'lookupIfaceTop').
307 --
308 -- It's all a bit of a giant Rube Goldberg machine, but it
309 -- seems to work! Note that the name we pick here doesn't
310 -- really matter, since we throw it out shortly after
311 -- (for merging, we rename all of the DFuns so that they
312 -- are unique; for instantiation, the final interface never
313 -- mentions DFuns since they are implicitly exported.) The
314 -- important thing is that it's consistent everywhere.
315
316 iface_semantic_mod <- fmap sh_if_semantic_module getGblEnv
317 let m = renameHoleModule dflags hmap $ nameModule (ifDFun cls_inst)
318 -- Doublecheck that this DFun was, indeed, locally defined.
319 MASSERT2( iface_semantic_mod == m, ppr iface_semantic_mod <+> ppr m )
320 dfun <- setNameModule (Just m) (ifDFun cls_inst)
321 return cls_inst { ifInstCls = n
322 , ifInstTys = tys
323 , ifDFun = dfun
324 }
325
326 rnMaybeIfaceTyCon :: Rename (Maybe IfaceTyCon)
327 rnMaybeIfaceTyCon Nothing = return Nothing
328 rnMaybeIfaceTyCon (Just tc) = Just <$> rnIfaceTyCon tc
329
330 rnIfaceFamInst :: Rename IfaceFamInst
331 rnIfaceFamInst d = do
332 fam <- rnIfaceGlobal (ifFamInstFam d)
333 tys <- mapM rnMaybeIfaceTyCon (ifFamInstTys d)
334 axiom <- rnIfaceGlobal (ifFamInstAxiom d)
335 return d { ifFamInstFam = fam, ifFamInstTys = tys, ifFamInstAxiom = axiom }
336
337 rnIfaceDecl' :: Rename (Fingerprint, IfaceDecl)
338 rnIfaceDecl' (fp, decl) = (,) fp <$> rnIfaceDecl decl
339
340 rnIfaceDecl :: Rename IfaceDecl
341 rnIfaceDecl d@IfaceId{} = do
342 ty <- rnIfaceType (ifType d)
343 details <- rnIfaceIdDetails (ifIdDetails d)
344 info <- rnIfaceIdInfo (ifIdInfo d)
345 return d { ifType = ty
346 , ifIdDetails = details
347 , ifIdInfo = info
348 }
349 rnIfaceDecl d@IfaceData{} = do
350 binders <- mapM rnIfaceTyConBinder (ifBinders d)
351 ctxt <- mapM rnIfaceType (ifCtxt d)
352 cons <- rnIfaceConDecls (ifCons d)
353 parent <- rnIfaceTyConParent (ifParent d)
354 return d { ifBinders = binders
355 , ifCtxt = ctxt
356 , ifCons = cons
357 , ifParent = parent
358 }
359 rnIfaceDecl d@IfaceSynonym{} = do
360 binders <- mapM rnIfaceTyConBinder (ifBinders d)
361 syn_kind <- rnIfaceType (ifResKind d)
362 syn_rhs <- rnIfaceType (ifSynRhs d)
363 return d { ifBinders = binders
364 , ifResKind = syn_kind
365 , ifSynRhs = syn_rhs
366 }
367 rnIfaceDecl d@IfaceFamily{} = do
368 binders <- mapM rnIfaceTyConBinder (ifBinders d)
369 fam_kind <- rnIfaceType (ifResKind d)
370 fam_flav <- rnIfaceFamTyConFlav (ifFamFlav d)
371 return d { ifBinders = binders
372 , ifResKind = fam_kind
373 , ifFamFlav = fam_flav
374 }
375 rnIfaceDecl d@IfaceClass{} = do
376 ctxt <- mapM rnIfaceType (ifCtxt d)
377 binders <- mapM rnIfaceTyConBinder (ifBinders d)
378 ats <- mapM rnIfaceAT (ifATs d)
379 sigs <- mapM rnIfaceClassOp (ifSigs d)
380 return d { ifCtxt = ctxt
381 , ifBinders = binders
382 , ifATs = ats
383 , ifSigs = sigs
384 }
385 rnIfaceDecl d@IfaceAxiom{} = do
386 tycon <- rnIfaceTyCon (ifTyCon d)
387 ax_branches <- mapM rnIfaceAxBranch (ifAxBranches d)
388 return d { ifTyCon = tycon
389 , ifAxBranches = ax_branches
390 }
391 rnIfaceDecl d@IfacePatSyn{} = do
392 let rnPat (n, b) = (,) <$> rnIfaceGlobal n <*> pure b
393 pat_matcher <- rnPat (ifPatMatcher d)
394 pat_builder <- T.traverse rnPat (ifPatBuilder d)
395 pat_univ_bndrs <- mapM rnIfaceForAllBndr (ifPatUnivBndrs d)
396 pat_ex_bndrs <- mapM rnIfaceForAllBndr (ifPatExBndrs d)
397 pat_prov_ctxt <- mapM rnIfaceType (ifPatProvCtxt d)
398 pat_req_ctxt <- mapM rnIfaceType (ifPatReqCtxt d)
399 pat_args <- mapM rnIfaceType (ifPatArgs d)
400 pat_ty <- rnIfaceType (ifPatTy d)
401 return d { ifPatMatcher = pat_matcher
402 , ifPatBuilder = pat_builder
403 , ifPatUnivBndrs = pat_univ_bndrs
404 , ifPatExBndrs = pat_ex_bndrs
405 , ifPatProvCtxt = pat_prov_ctxt
406 , ifPatReqCtxt = pat_req_ctxt
407 , ifPatArgs = pat_args
408 , ifPatTy = pat_ty
409 }
410
411 rnIfaceFamTyConFlav :: Rename IfaceFamTyConFlav
412 rnIfaceFamTyConFlav (IfaceClosedSynFamilyTyCon (Just (n, axs)))
413 = IfaceClosedSynFamilyTyCon . Just <$> ((,) <$> rnIfaceGlobal n
414 <*> mapM rnIfaceAxBranch axs)
415 rnIfaceFamTyConFlav flav = pure flav
416
417 rnIfaceAT :: Rename IfaceAT
418 rnIfaceAT (IfaceAT decl mb_ty)
419 = IfaceAT <$> rnIfaceDecl decl <*> T.traverse rnIfaceType mb_ty
420
421 rnIfaceTyConParent :: Rename IfaceTyConParent
422 rnIfaceTyConParent (IfDataInstance n tc args)
423 = IfDataInstance <$> rnIfaceGlobal n
424 <*> rnIfaceTyCon tc
425 <*> rnIfaceTcArgs args
426 rnIfaceTyConParent IfNoParent = pure IfNoParent
427
428 rnIfaceConDecls :: Rename IfaceConDecls
429 rnIfaceConDecls (IfDataTyCon ds b fs)
430 = IfDataTyCon <$> mapM rnIfaceConDecl ds
431 <*> return b
432 <*> return fs
433 rnIfaceConDecls (IfNewTyCon d b fs) = IfNewTyCon <$> rnIfaceConDecl d <*> return b <*> return fs
434 rnIfaceConDecls (IfAbstractTyCon b) = pure (IfAbstractTyCon b)
435
436 rnIfaceConDecl :: Rename IfaceConDecl
437 rnIfaceConDecl d = do
438 con_ex_tvs <- mapM rnIfaceForAllBndr (ifConExTvs d)
439 let rnIfConEqSpec (n,t) = (,) n <$> rnIfaceType t
440 con_eq_spec <- mapM rnIfConEqSpec (ifConEqSpec d)
441 con_ctxt <- mapM rnIfaceType (ifConCtxt d)
442 con_arg_tys <- mapM rnIfaceType (ifConArgTys d)
443 let rnIfaceBang (IfUnpackCo co) = IfUnpackCo <$> rnIfaceCo co
444 rnIfaceBang bang = pure bang
445 con_stricts <- mapM rnIfaceBang (ifConStricts d)
446 return d { ifConExTvs = con_ex_tvs
447 , ifConEqSpec = con_eq_spec
448 , ifConCtxt = con_ctxt
449 , ifConArgTys = con_arg_tys
450 , ifConStricts = con_stricts
451 }
452
453 rnIfaceClassOp :: Rename IfaceClassOp
454 rnIfaceClassOp (IfaceClassOp n ty dm) = IfaceClassOp n <$> rnIfaceType ty <*> rnMaybeDefMethSpec dm
455
456 rnMaybeDefMethSpec :: Rename (Maybe (DefMethSpec IfaceType))
457 rnMaybeDefMethSpec (Just (GenericDM ty)) = Just . GenericDM <$> rnIfaceType ty
458 rnMaybeDefMethSpec mb = return mb
459
460 rnIfaceAxBranch :: Rename IfaceAxBranch
461 rnIfaceAxBranch d = do
462 ty_vars <- mapM rnIfaceTvBndr (ifaxbTyVars d)
463 lhs <- rnIfaceTcArgs (ifaxbLHS d)
464 rhs <- rnIfaceType (ifaxbRHS d)
465 return d { ifaxbTyVars = ty_vars
466 , ifaxbLHS = lhs
467 , ifaxbRHS = rhs }
468
469 rnIfaceIdInfo :: Rename IfaceIdInfo
470 rnIfaceIdInfo NoInfo = pure NoInfo
471 rnIfaceIdInfo (HasInfo is) = HasInfo <$> mapM rnIfaceInfoItem is
472
473 rnIfaceInfoItem :: Rename IfaceInfoItem
474 rnIfaceInfoItem (HsUnfold lb if_unf)
475 = HsUnfold lb <$> rnIfaceUnfolding if_unf
476 rnIfaceInfoItem i
477 = pure i
478
479 rnIfaceUnfolding :: Rename IfaceUnfolding
480 rnIfaceUnfolding (IfCoreUnfold stable if_expr)
481 = IfCoreUnfold stable <$> rnIfaceExpr if_expr
482 rnIfaceUnfolding (IfCompulsory if_expr)
483 = IfCompulsory <$> rnIfaceExpr if_expr
484 rnIfaceUnfolding (IfInlineRule arity unsat_ok boring_ok if_expr)
485 = IfInlineRule arity unsat_ok boring_ok <$> rnIfaceExpr if_expr
486 rnIfaceUnfolding (IfDFunUnfold bs ops)
487 = IfDFunUnfold <$> rnIfaceBndrs bs <*> mapM rnIfaceExpr ops
488
489 rnIfaceExpr :: Rename IfaceExpr
490 rnIfaceExpr (IfaceLcl name) = pure (IfaceLcl name)
491 rnIfaceExpr (IfaceExt gbl) = IfaceExt <$> rnIfaceGlobal gbl
492 rnIfaceExpr (IfaceType ty) = IfaceType <$> rnIfaceType ty
493 rnIfaceExpr (IfaceCo co) = IfaceCo <$> rnIfaceCo co
494 rnIfaceExpr (IfaceTuple sort args) = IfaceTuple sort <$> rnIfaceExprs args
495 rnIfaceExpr (IfaceLam lam_bndr expr)
496 = IfaceLam <$> rnIfaceLamBndr lam_bndr <*> rnIfaceExpr expr
497 rnIfaceExpr (IfaceApp fun arg)
498 = IfaceApp <$> rnIfaceExpr fun <*> rnIfaceExpr arg
499 rnIfaceExpr (IfaceCase scrut case_bndr alts)
500 = IfaceCase <$> rnIfaceExpr scrut
501 <*> pure case_bndr
502 <*> mapM rnIfaceAlt alts
503 rnIfaceExpr (IfaceECase scrut ty)
504 = IfaceECase <$> rnIfaceExpr scrut <*> rnIfaceType ty
505 rnIfaceExpr (IfaceLet (IfaceNonRec bndr rhs) body)
506 = IfaceLet <$> (IfaceNonRec <$> rnIfaceLetBndr bndr <*> rnIfaceExpr rhs)
507 <*> rnIfaceExpr body
508 rnIfaceExpr (IfaceLet (IfaceRec pairs) body)
509 = IfaceLet <$> (IfaceRec <$> mapM (\(bndr, rhs) ->
510 (,) <$> rnIfaceLetBndr bndr
511 <*> rnIfaceExpr rhs) pairs)
512 <*> rnIfaceExpr body
513 rnIfaceExpr (IfaceCast expr co)
514 = IfaceCast <$> rnIfaceExpr expr <*> rnIfaceCo co
515 rnIfaceExpr (IfaceLit lit) = pure (IfaceLit lit)
516 rnIfaceExpr (IfaceFCall cc ty) = IfaceFCall cc <$> rnIfaceType ty
517 rnIfaceExpr (IfaceTick tickish expr) = IfaceTick tickish <$> rnIfaceExpr expr
518
519 rnIfaceBndrs :: Rename [IfaceBndr]
520 rnIfaceBndrs = mapM rnIfaceBndr
521
522 rnIfaceBndr :: Rename IfaceBndr
523 rnIfaceBndr (IfaceIdBndr (fs, ty)) = IfaceIdBndr <$> ((,) fs <$> rnIfaceType ty)
524 rnIfaceBndr (IfaceTvBndr tv_bndr) = IfaceIdBndr <$> rnIfaceTvBndr tv_bndr
525
526 rnIfaceTvBndr :: Rename IfaceTvBndr
527 rnIfaceTvBndr (fs, kind) = (,) fs <$> rnIfaceType kind
528
529 rnIfaceTyConBinder :: Rename IfaceTyConBinder
530 rnIfaceTyConBinder (TvBndr tv vis) = TvBndr <$> rnIfaceTvBndr tv <*> pure vis
531
532 rnIfaceAlt :: Rename IfaceAlt
533 rnIfaceAlt (conalt, names, rhs)
534 = (,,) <$> rnIfaceConAlt conalt <*> pure names <*> rnIfaceExpr rhs
535
536 rnIfaceConAlt :: Rename IfaceConAlt
537 rnIfaceConAlt (IfaceDataAlt data_occ) = IfaceDataAlt <$> rnIfaceGlobal data_occ
538 rnIfaceConAlt alt = pure alt
539
540 rnIfaceLetBndr :: Rename IfaceLetBndr
541 rnIfaceLetBndr (IfLetBndr fs ty info)
542 = IfLetBndr fs <$> rnIfaceType ty <*> rnIfaceIdInfo info
543
544 rnIfaceLamBndr :: Rename IfaceLamBndr
545 rnIfaceLamBndr (bndr, oneshot) = (,) <$> rnIfaceBndr bndr <*> pure oneshot
546
547 rnIfaceCo :: Rename IfaceCoercion
548 rnIfaceCo (IfaceReflCo role ty) = IfaceReflCo role <$> rnIfaceType ty
549 rnIfaceCo (IfaceFunCo role co1 co2)
550 = IfaceFunCo role <$> rnIfaceCo co1 <*> rnIfaceCo co2
551 rnIfaceCo (IfaceTyConAppCo role tc cos)
552 = IfaceTyConAppCo role <$> rnIfaceTyCon tc <*> mapM rnIfaceCo cos
553 rnIfaceCo (IfaceAppCo co1 co2)
554 = IfaceAppCo <$> rnIfaceCo co1 <*> rnIfaceCo co2
555 rnIfaceCo (IfaceForAllCo bndr co1 co2)
556 = IfaceForAllCo <$> rnIfaceTvBndr bndr <*> rnIfaceCo co1 <*> rnIfaceCo co2
557 rnIfaceCo (IfaceCoVarCo lcl) = IfaceCoVarCo <$> pure lcl
558 rnIfaceCo (IfaceAxiomInstCo n i cs)
559 = IfaceAxiomInstCo <$> rnIfaceGlobal n <*> pure i <*> mapM rnIfaceCo cs
560 rnIfaceCo (IfaceUnivCo s r t1 t2)
561 = IfaceUnivCo s r <$> rnIfaceType t1 <*> rnIfaceType t2
562 rnIfaceCo (IfaceSymCo c)
563 = IfaceSymCo <$> rnIfaceCo c
564 rnIfaceCo (IfaceTransCo c1 c2)
565 = IfaceTransCo <$> rnIfaceCo c1 <*> rnIfaceCo c2
566 rnIfaceCo (IfaceInstCo c1 c2)
567 = IfaceInstCo <$> rnIfaceCo c1 <*> rnIfaceCo c2
568 rnIfaceCo (IfaceNthCo d c) = IfaceNthCo d <$> rnIfaceCo c
569 rnIfaceCo (IfaceLRCo lr c) = IfaceLRCo lr <$> rnIfaceCo c
570 rnIfaceCo (IfaceSubCo c) = IfaceSubCo <$> rnIfaceCo c
571 rnIfaceCo (IfaceAxiomRuleCo ax cos)
572 = IfaceAxiomRuleCo ax <$> mapM rnIfaceCo cos
573 rnIfaceCo (IfaceKindCo c) = IfaceKindCo <$> rnIfaceCo c
574 rnIfaceCo (IfaceCoherenceCo c1 c2) = IfaceCoherenceCo <$> rnIfaceCo c1 <*> rnIfaceCo c2
575
576 rnIfaceTyCon :: Rename IfaceTyCon
577 rnIfaceTyCon (IfaceTyCon n info)
578 = IfaceTyCon <$> rnIfaceGlobal n <*> pure info
579
580 rnIfaceExprs :: Rename [IfaceExpr]
581 rnIfaceExprs = mapM rnIfaceExpr
582
583 rnIfaceIdDetails :: Rename IfaceIdDetails
584 rnIfaceIdDetails (IfRecSelId (Left tc) b) = IfRecSelId <$> fmap Left (rnIfaceTyCon tc) <*> pure b
585 rnIfaceIdDetails (IfRecSelId (Right decl) b) = IfRecSelId <$> fmap Right (rnIfaceDecl decl) <*> pure b
586 rnIfaceIdDetails details = pure details
587
588 rnIfaceType :: Rename IfaceType
589 rnIfaceType (IfaceTyVar n) = pure (IfaceTyVar n)
590 rnIfaceType (IfaceAppTy t1 t2)
591 = IfaceAppTy <$> rnIfaceType t1 <*> rnIfaceType t2
592 rnIfaceType (IfaceLitTy l) = return (IfaceLitTy l)
593 rnIfaceType (IfaceFunTy t1 t2)
594 = IfaceFunTy <$> rnIfaceType t1 <*> rnIfaceType t2
595 rnIfaceType (IfaceDFunTy t1 t2)
596 = IfaceDFunTy <$> rnIfaceType t1 <*> rnIfaceType t2
597 rnIfaceType (IfaceTupleTy s i tks)
598 = IfaceTupleTy s i <$> rnIfaceTcArgs tks
599 rnIfaceType (IfaceTyConApp tc tks)
600 = IfaceTyConApp <$> rnIfaceTyCon tc <*> rnIfaceTcArgs tks
601 rnIfaceType (IfaceForAllTy tv t)
602 = IfaceForAllTy <$> rnIfaceForAllBndr tv <*> rnIfaceType t
603 rnIfaceType (IfaceCoercionTy co)
604 = IfaceCoercionTy <$> rnIfaceCo co
605 rnIfaceType (IfaceCastTy ty co)
606 = IfaceCastTy <$> rnIfaceType ty <*> rnIfaceCo co
607
608 rnIfaceForAllBndr :: Rename IfaceForAllBndr
609 rnIfaceForAllBndr (TvBndr tv vis) = TvBndr <$> rnIfaceTvBndr tv <*> pure vis
610
611 rnIfaceTcArgs :: Rename IfaceTcArgs
612 rnIfaceTcArgs (ITC_Invis t ts) = ITC_Invis <$> rnIfaceType t <*> rnIfaceTcArgs ts
613 rnIfaceTcArgs (ITC_Vis t ts) = ITC_Vis <$> rnIfaceType t <*> rnIfaceTcArgs ts
614 rnIfaceTcArgs ITC_Nil = pure ITC_Nil