import {-# SOURCE #-} RnSource ( rnHsSigType )
import HsSyn
-import HsBinds ( sigsForMe, cmpHsSig, sigName, hsSigDoc )
+import HsBinds ( eqHsSig, sigName, hsSigDoc )
import RdrHsSyn
import RnHsSyn
import RnMonad
import RnExpr ( rnMatch, rnGRHSs, rnPat, checkPrecMatch )
-import RnEnv ( bindLocatedLocalsRn, lookupBndrRn, lookupGlobalOccRn, lookupOccRn,
+import RnEnv ( bindLocatedLocalsRn, lookupBndrRn,
+ lookupGlobalOccRn, lookupOccRn, lookupSigOccRn,
warnUnusedLocalBinds, mapFvRn,
FreeVars, emptyFVs, plusFV, plusFVs, unitFV, addOneFV,
unknownNameErr
import NameSet
import RdrName ( RdrName, rdrNameOcc )
import BasicTypes ( RecFlag(..), TopLevelFlag(..) )
-import Util ( thenCmp, removeDups )
import List ( partition )
-import ListSetOps ( minusList )
import Bag ( bagToList )
-import FiniteMap ( lookupFM, listToFM )
-import Maybe ( isJust )
import Outputable
\end{code}
-- The parser doesn't produce other forms
-rnTopMonoBinds EmptyMonoBinds sigs
- = returnRn (EmptyBinds, emptyFVs)
-
rnTopMonoBinds mbinds sigs
- = mapRn lookupBndrRn binder_rdr_names `thenRn` \ binder_names ->
- renameSigs (okBindSig (mkNameSet binder_names)) sigs `thenRn` \ (siglist, sig_fvs) ->
+ = mapRn lookupBndrRn binder_rdr_names `thenRn` \ binder_names ->
+ let
+ bndr_name_set = mkNameSet binder_names
+ in
+ renameSigs (okBindSig bndr_name_set) sigs `thenRn` \ (siglist, sig_fvs) ->
let
type_sig_vars = [n | Sig n _ _ <- siglist]
- un_sigd_binders | opt_WarnMissingSigs = binder_names `minusList` type_sig_vars
+ un_sigd_binders | opt_WarnMissingSigs = nameSetToList (delListFromNameSet bndr_name_set type_sig_vars)
| otherwise = []
in
mapRn_ (addWarnRn.missingSigWarn) un_sigd_binders `thenRn_`
-> (RenamedHsBinds -> RnMS (result, FreeVars))
-> RnMS (result, FreeVars)
-rnMonoBinds EmptyMonoBinds sigs thing_inside = thing_inside EmptyBinds
-
rnMonoBinds mbinds sigs thing_inside -- Non-empty monobinds
= -- Extract all the binders in this group,
-- and extend current scope, inventing new names for the new binders
-- This also checks that the names form a set
- bindLocatedLocalsRn (text "a binding group") mbinders_w_srclocs
- $ \ new_mbinders ->
+ bindLocatedLocalsRn (text "a binding group")
+ mbinders_w_srclocs $ \ new_mbinders ->
let
binder_set = mkNameSet new_mbinders
in
let
edges = mkEdges (mbinds_info `zip` [(0::Int)..])
scc_result = stronglyConnComp edges
- final_binds = foldr1 ThenBinds (map reconstructCycle scc_result)
+ final_binds = foldr (ThenBinds . reconstructCycle) EmptyBinds scc_result
-- Deal with bound and free-var calculation
rhs_fvs = plusFVs [fvs | (_,fvs,_,_) <- mbinds_info]
-- Find which things are bound in this group
let
names_bound_here = mkNameSet (collectPatBinders pat')
- sigs_for_me = sigsForMe (`elemNameSet` names_bound_here) sigs
in
+ sigsForMe names_bound_here sigs `thenRn` \ sigs_for_me ->
rnGRHSs grhss `thenRn` \ (grhss', fvs) ->
returnRn
[(names_bound_here,
= pushSrcLocRn locn $
lookupBndrRn name `thenRn` \ new_name ->
let
- sigs_for_me = sigsForMe (new_name ==) sigs
+ names_bound_here = unitNameSet new_name
in
+ sigsForMe names_bound_here sigs `thenRn` \ sigs_for_me ->
mapFvRn rnMatch matches `thenRn` \ (new_matches, fvs) ->
mapRn_ (checkPrecMatch inf new_name) new_matches `thenRn_`
returnRn
FunMonoBind new_name inf new_matches locn,
sigs_for_me
)]
+
+
+sigsForMe names_bound_here sigs
+ = foldlRn check [] (filter (sigForThisGroup names_bound_here) sigs)
+ where
+ check sigs sig = case filter (eqHsSig sig) sigs of
+ [] -> returnRn (sig:sigs)
+ other -> dupSigDeclErr sig `thenRn_`
+ returnRn sigs
\end{code}
is_in_scope sig = case sigName sig of
Just n -> not (isUnboundName n)
Nothing -> True
- (not_dups, dups) = removeDups cmpHsSig in_scope
- (goods, bads) = partition ok_sig not_dups
+ (goods, bads) = partition ok_sig in_scope
in
mapRn_ unknownSigErr bads `thenRn_`
- mapRn_ dupSigDeclErr dups `thenRn_`
returnRn (goods, fvs)
--- We use lookupOccRn in the signatures, which is a little bit unsatisfactory
+-- We use lookupSigOccRn in the signatures, which is a little bit unsatisfactory
-- because this won't work for:
-- instance Foo T where
-- {-# INLINE op #-}
renameSig (Sig v ty src_loc)
= pushSrcLocRn src_loc $
- lookupOccRn v `thenRn` \ new_v ->
+ lookupSigOccRn v `thenRn` \ new_v ->
rnHsSigType (quotes (ppr v)) ty `thenRn` \ (new_ty,fvs) ->
returnRn (Sig new_v new_ty src_loc, fvs `addOneFV` new_v)
renameSig (SpecSig v ty src_loc)
= pushSrcLocRn src_loc $
- lookupOccRn v `thenRn` \ new_v ->
+ lookupSigOccRn v `thenRn` \ new_v ->
rnHsSigType (quotes (ppr v)) ty `thenRn` \ (new_ty,fvs) ->
returnRn (SpecSig new_v new_ty src_loc, fvs `addOneFV` new_v)
renameSig (FixSig (FixitySig v fix src_loc))
= pushSrcLocRn src_loc $
- lookupOccRn v `thenRn` \ new_v ->
+ lookupSigOccRn v `thenRn` \ new_v ->
returnRn (FixSig (FixitySig new_v fix src_loc), unitFV new_v)
-renameSig (DeprecSig (Deprecation ie txt) src_loc)
- = pushSrcLocRn src_loc $
- renameIE lookupOccRn ie `thenRn` \ (new_ie, fvs) ->
- returnRn (DeprecSig (Deprecation new_ie txt) src_loc, fvs)
-
renameSig (InlineSig v p src_loc)
= pushSrcLocRn src_loc $
- lookupOccRn v `thenRn` \ new_v ->
+ lookupSigOccRn v `thenRn` \ new_v ->
returnRn (InlineSig new_v p src_loc, unitFV new_v)
renameSig (NoInlineSig v p src_loc)
= pushSrcLocRn src_loc $
- lookupOccRn v `thenRn` \ new_v ->
+ lookupSigOccRn v `thenRn` \ new_v ->
returnRn (NoInlineSig new_v p src_loc, unitFV new_v)
\end{code}
%************************************************************************
\begin{code}
-dupSigDeclErr (sig:sigs)
+dupSigDeclErr sig
= pushSrcLocRn loc $
addErrRn (sep [ptext SLIT("Duplicate") <+> ptext what_it_is <> colon,
ppr sig])