-@UfCore@ expressions.
-
-\begin{code}
-rnCoreExpr (UfType ty)
- = rnHsPolyType (text "unfolding type") ty `thenRn` \ (ty', fvs) ->
- returnRn (UfType ty', fvs)
-
-rnCoreExpr (UfVar v)
- = lookupOccRn v `thenRn` \ v' ->
- returnRn (UfVar v', unitFV v')
-
-rnCoreExpr (UfLit l)
- = returnRn (UfLit l, emptyFVs)
-
-rnCoreExpr (UfLitLit l ty)
- = rnHsType (text "litlit") ty `thenRn` \ (ty', fvs) ->
- returnRn (UfLitLit l ty', fvs)
-
-rnCoreExpr (UfCCall cc ty)
- = rnHsPolyType (text "ccall") ty `thenRn` \ (ty', fvs) ->
- returnRn (UfCCall cc ty', fvs)
-
-rnCoreExpr (UfTuple con args)
- = lookupOccRn con `thenRn` \ con' ->
- mapFvRn rnCoreExpr args `thenRn` \ (args', fvs) ->
- returnRn (UfTuple con' args', fvs `addOneFV` con')
-
-rnCoreExpr (UfApp fun arg)
- = rnCoreExpr fun `thenRn` \ (fun', fv1) ->
- rnCoreExpr arg `thenRn` \ (arg', fv2) ->
- returnRn (UfApp fun' arg', fv1 `plusFV` fv2)
-
-rnCoreExpr (UfCase scrut bndr alts)
- = rnCoreExpr scrut `thenRn` \ (scrut', fvs1) ->
- bindCoreLocalFVRn bndr ( \ bndr' ->
- mapFvRn rnCoreAlt alts `thenRn` \ (alts', fvs2) ->
- returnRn (UfCase scrut' bndr' alts', fvs2)
- ) `thenRn` \ (case', fvs3) ->
- returnRn (case', fvs1 `plusFV` fvs3)
-
-rnCoreExpr (UfNote note expr)
- = rnNote note `thenRn` \ (note', fvs1) ->
- rnCoreExpr expr `thenRn` \ (expr', fvs2) ->
- returnRn (UfNote note' expr', fvs1 `plusFV` fvs2)
-
-rnCoreExpr (UfLam bndr body)
- = rnCoreBndr bndr $ \ bndr' ->
- rnCoreExpr body `thenRn` \ (body', fvs) ->
- returnRn (UfLam bndr' body', fvs)
-
-rnCoreExpr (UfLet (UfNonRec bndr rhs) body)
- = rnCoreExpr rhs `thenRn` \ (rhs', fvs1) ->
- rnCoreBndr bndr ( \ bndr' ->
- rnCoreExpr body `thenRn` \ (body', fvs2) ->
- returnRn (UfLet (UfNonRec bndr' rhs') body', fvs2)
- ) `thenRn` \ (result, fvs3) ->
- returnRn (result, fvs1 `plusFV` fvs3)
-
-rnCoreExpr (UfLet (UfRec pairs) body)
- = rnCoreBndrs bndrs $ \ bndrs' ->
- mapFvRn rnCoreExpr rhss `thenRn` \ (rhss', fvs1) ->
- rnCoreExpr body `thenRn` \ (body', fvs2) ->
- returnRn (UfLet (UfRec (bndrs' `zip` rhss')) body', fvs1 `plusFV` fvs2)
- where
- (bndrs, rhss) = unzip pairs
-\end{code}
-
-\begin{code}
-rnCoreBndr (UfValBinder name ty) thing_inside
- = rnHsPolyType doc ty `thenRn` \ (ty', fvs1) ->
- bindCoreLocalFVRn name ( \ name' ->
- thing_inside (UfValBinder name' ty')
- ) `thenRn` \ (result, fvs2) ->
- returnRn (result, fvs1 `plusFV` fvs2)
- where
- doc = text "unfolding id"
-
-rnCoreBndr (UfTyBinder name kind) thing_inside
- = bindCoreLocalFVRn name $ \ name' ->
- thing_inside (UfTyBinder name' kind)
-
-rnCoreBndrs [] thing_inside = thing_inside []
-rnCoreBndrs (b:bs) thing_inside = rnCoreBndr b $ \ name' ->
- rnCoreBndrs bs $ \ names' ->
- thing_inside (name':names')
-\end{code}
-
-\begin{code}
-rnCoreAlt (con, bndrs, rhs)
- = rnUfCon con `thenRn` \ (con', fvs1) ->
- bindCoreLocalsFVRn bndrs ( \ bndrs' ->
- rnCoreExpr rhs `thenRn` \ (rhs', fvs2) ->
- returnRn ((con', bndrs', rhs'), fvs2)
- ) `thenRn` \ (result, fvs3) ->
- returnRn (result, fvs1 `plusFV` fvs3)
-
-rnNote (UfCoerce ty)
- = rnHsPolyType (text "unfolding coerce") ty `thenRn` \ (ty', fvs) ->
- returnRn (UfCoerce ty', fvs)
-
-rnNote (UfSCC cc) = returnRn (UfSCC cc, emptyFVs)
-rnNote UfInlineCall = returnRn (UfInlineCall, emptyFVs)
-rnNote UfInlineMe = returnRn (UfInlineMe, emptyFVs)
-
-
-rnUfCon UfDefault
- = returnRn (UfDefault, emptyFVs)
-
-rnUfCon (UfDataAlt con)
- = lookupOccRn con `thenRn` \ con' ->
- returnRn (UfDataAlt con', unitFV con')
-
-rnUfCon (UfLitAlt lit)
- = returnRn (UfLitAlt lit, emptyFVs)
-
-rnUfCon (UfLitLitAlt lit ty)
- = rnHsPolyType (text "litlit") ty `thenRn` \ (ty', fvs) ->
- returnRn (UfLitLitAlt lit ty', fvs)
-\end{code}
-
-%*********************************************************
-%* *
-\subsection{Rule shapes}
-%* *
-%*********************************************************
-
-Check the shape of a transformation rule LHS. Currently
-we only allow LHSs of the form @(f e1 .. en)@, where @f@ is
-not one of the @forall@'d variables.
-
-\begin{code}
-validRuleLhs foralls lhs
- = check lhs
- where
- check (HsApp e1 e2) = check e1
- check (HsVar v) | v `notElem` foralls = True
- check other = False
-\end{code}
-
-
-%*********************************************************
-%* *
-\subsection{Errors}
-%* *
-%*********************************************************
-
-\begin{code}
-derivingNonStdClassErr clas
- = hsep [ptext SLIT("non-standard class"), ppr clas, ptext SLIT("in deriving clause")]
-
-classTyVarNotInOpTyErr clas_tyvar sig
- = hang (hsep [ptext SLIT("Class type variable"),
- quotes (ppr clas_tyvar),
- ptext SLIT("does not appear in method signature")])
- 4 (ppr sig)
-
-dupClassAssertWarn ctxt (assertion : dups)
- = sep [hsep [ptext SLIT("Duplicate class assertion"),
- quotes (pprHsPred assertion),
- ptext SLIT("in the context:")],
- nest 4 (pprHsContext ctxt <+> ptext SLIT("..."))]
-
-badDataCon name
- = hsep [ptext SLIT("Illegal data constructor name"), quotes (ppr name)]
-
-forAllWarn doc ty tyvar
- | not opt_WarnUnusedMatches = returnRn ()
- | otherwise
- = getModeRn `thenRn` \ mode ->
- case mode of {
-#ifndef DEBUG
- InterfaceMode -> returnRn () ; -- Don't warn of unused tyvars in interface files
- -- unless DEBUG is on, in which case it is slightly
- -- informative. They can arise from mkRhsTyLam,
-#endif -- leading to (say) f :: forall a b. [b] -> [b]
- other ->
-
- addWarnRn (
- sep [ptext SLIT("The universally quantified type variable") <+> quotes (ppr tyvar),
- nest 4 (ptext SLIT("does not appear in the type") <+> quotes (ppr ty))]
- $$
- (ptext SLIT("In") <+> doc))
- }
-
-forAllErr doc ty tyvar
- = addErrRn (
- sep [ptext SLIT("The constrained type variable") <+> quotes (ppr tyvar),
- nest 4 (ptext SLIT("does not appear in the type") <+> quotes (ppr ty))]
- $$
- (ptext SLIT("In") <+> doc))
-
-univErr doc constraint ty
- = sep [ptext SLIT("All of the type variable(s) in the constraint")
- <+> quotes (pprHsPred constraint)
- <+> ptext SLIT("are already in scope"),
- nest 4 (ptext SLIT("At least one must be universally quantified here"))
- ]
- $$
- (ptext SLIT("In") <+> doc)
-
-ambigErr doc constraint ty
- = sep [ptext SLIT("Ambiguous constraint") <+> quotes (pprHsPred constraint),
- nest 4 (ptext SLIT("in the type:") <+> ppr ty),
- nest 4 (ptext SLIT("Each forall-d type variable mentioned by the constraint must appear after the =>."))]
- $$
- (ptext SLIT("In") <+> doc)
-
-unexpectedForAllTy ty
- = ptext SLIT("Unexpected forall type:") <+> ppr ty
-
-badRuleLhsErr name lhs
- = sep [ptext SLIT("Rule") <+> ptext name <> colon,
- nest 4 (ptext SLIT("Illegal left-hand side:") <+> ppr lhs)]
- $$
- ptext SLIT("LHS must be of form (f e1 .. en) where f is not forall'd")
-
-badRuleVar name var
- = sep [ptext SLIT("Rule") <+> ptext name <> colon,
- ptext SLIT("Forall'd variable") <+> quotes (ppr var) <+>
- ptext SLIT("does not appear on left hand side")]
-
-badExtName :: ExtName -> Message
-badExtName ext_nm
- = sep [quotes (ppr ext_nm) <+> ptext SLIT("is not a valid C identifier")]
-\end{code}