\begin{code}
dsRule :: Module -> IdSet -> LRuleDecl Id -> DsM (Maybe CoreRule)
-dsRule mod in_scope (L loc (HsRule name act vars lhs rhs))
+dsRule mod in_scope (L loc (HsRule name act vars lhs tv_lhs rhs fv_rhs))
= putSrcSpanDs loc $
do { let bndrs = [var | RuleBndr (L _ var) <- vars]
; lhs' <- dsLExpr lhs
-- or a 'where' clause
= HsValBinds (HsValBinds id)
| HsIPBinds (HsIPBinds id)
+
| EmptyLocalBinds
data HsValBinds id -- Value bindings (not implicit parameters)
import HsPat ( HsConDetails(..), hsConArgs )
import HsImpExp ( pprHsVar )
import HsTypes
+import NameSet ( NameSet )
import HscTypes ( DeprecTxt )
import CoreSyn ( RuleName )
import Kind ( Kind, pprKind )
Activation
[RuleBndr name] -- Forall'd vars; after typechecking this includes tyvars
(Located (HsExpr name)) -- LHS
+ NameSet -- Free-vars from the LHS
(Located (HsExpr name)) -- RHS
+ NameSet -- Free-vars from the RHS
data RuleBndr name
= RuleBndr (Located name)
collectRuleBndrSigTys bndrs = [ty | RuleBndrSig _ ty <- bndrs]
instance OutputableBndr name => Outputable (RuleDecl name) where
- ppr (HsRule name act ns lhs rhs)
+ ppr (HsRule name act ns lhs fv_lhs rhs fv_rhs)
= sep [text "{-# RULES" <+> doubleQuotes (ftext name) <+> ppr act,
nest 4 (pp_forall <+> pprExpr (unLoc lhs)),
nest 4 (equals <+> pprExpr (unLoc rhs) <+> text "#-}") ]
: STRING activation rule_forall infixexp '=' exp
{ LL $ RuleD (HsRule (getSTRING $1)
($2 `orElse` AlwaysActive)
- $3 $4 $6) }
+ $3 $4 placeHolderNames $6 placeHolderNames) }
activation :: { Maybe Activation }
: {- empty -} { Nothing }
%*********************************************************
\begin{code}
-rnHsRuleDecl (HsRule rule_name act vars lhs rhs)
+rnHsRuleDecl (HsRule rule_name act vars lhs fv_lhs rhs fv_rhs)
= bindPatSigTyVarsFV (collectRuleBndrSigTys vars) $
bindLocatedLocalsFV doc (map get_var vars) $ \ ids ->
mapFvRn rn_var (vars `zip` ids) `thenM` \ (vars', fv_vars) ->
- rnLExpr lhs `thenM` \ (lhs', fv_lhs) ->
- rnLExpr rhs `thenM` \ (rhs', fv_rhs) ->
+ rnLExpr lhs `thenM` \ (lhs', fv_lhs') ->
+ rnLExpr rhs `thenM` \ (rhs', fv_rhs') ->
let
mb_bad = validRuleLhs ids lhs'
in
checkErr (isNothing mb_bad)
(badRuleLhsErr rule_name lhs' mb_bad) `thenM_`
let
- bad_vars = [var | var <- ids, not (var `elemNameSet` fv_lhs)]
+ bad_vars = [var | var <- ids, not (var `elemNameSet` fv_lhs')]
in
mappM (addErr . badRuleVar rule_name) bad_vars `thenM_`
- returnM (HsRule rule_name act vars' lhs' rhs',
- fv_vars `plusFV` fv_lhs `plusFV` fv_rhs)
+ returnM (HsRule rule_name act vars' lhs' fv_lhs' rhs' fv_rhs',
+ fv_vars `plusFV` fv_lhs' `plusFV` fv_rhs')
where
doc = text "In the transformation rule" <+> ftext rule_name
zonkRules env rs = mappM (wrapLocM (zonkRule env)) rs
zonkRule :: ZonkEnv -> RuleDecl TcId -> TcM (RuleDecl Id)
-zonkRule env (HsRule name act (vars::[RuleBndr TcId]) lhs rhs)
+zonkRule env (HsRule name act (vars::[RuleBndr TcId]) lhs fv_lhs rhs fv_rhs)
= mappM zonk_bndr vars `thenM` \ new_bndrs ->
newMutVar emptyVarSet `thenM` \ unbound_tv_set ->
let
final_bndrs :: [Located Var]
final_bndrs = map noLoc (varSetElems unbound_tvs) ++ new_bndrs
in
- returnM (HsRule name act (map RuleBndr final_bndrs) new_lhs new_rhs)
+ returnM (HsRule name act (map RuleBndr final_bndrs) new_lhs fv_lhs new_rhs fv_rhs)
-- I hate this map RuleBndr stuff
where
zonk_bndr (RuleBndr v)
tcRules decls = mappM (wrapLocM tcRule) decls
tcRule :: RuleDecl Name -> TcM (RuleDecl TcId)
-tcRule (HsRule name act vars lhs rhs)
+tcRule (HsRule name act vars lhs fv_lhs rhs fv_rhs)
= addErrCtxt (ruleCtxt name) $
traceTc (ptext SLIT("---- Rule ------")
<+> ppr name) `thenM_`
returnM (HsRule name act
(map (RuleBndr . noLoc) (forall_tvs2 ++ tpl_ids)) -- yuk
- (mkHsDictLet lhs_binds lhs')
- (mkHsDictLet rhs_binds rhs'))
+ (mkHsDictLet lhs_binds lhs') fv_lhs
+ (mkHsDictLet rhs_binds rhs') fv_rhs)
where
tcRuleBndrs [] thing_inside = thing_inside []