-addOccurrenceName :: Name -> RnMS s Name -- Same name returned as passed
-addOccurrenceName name (RnDown loc names_var errs_var occs_var)
- (SDown rn_env local_env mod_name mode)
- | isLocallyDefinedName name ||
- not_necessary necessity
- = returnSST name
-
- | otherwise
- = readMutVarSST occs_var `thenSST` \ (comp_occs, opt_occs) ->
- let
- new_occ_pair = case necessity of
- Optional -> (comp_occs, name:opt_occs)
- Compulsory -> (name:comp_occs, opt_occs)
- in
- writeMutVarSST occs_var new_occ_pair `thenSST_`
- returnSST name
- where
- necessity = case mode of
- SourceMode -> Compulsory
- InterfaceMode necessity -> necessity
-
-
-addOccurrenceNames :: [Name] -> RnMS s ()
-addOccurrenceNames names (RnDown loc names_var errs_var occs_var)
- (SDown rn_env local_env mod_name mode)
- | not_necessary necessity
- = returnSST ()
-
- | otherwise
- = readMutVarSST occs_var `thenSST` \ (comp_occs, opt_occs) ->
- let
- new_occ_pair = case necessity of
- Optional -> (comp_occs, non_local_names ++ opt_occs)
- Compulsory -> (non_local_names ++ comp_occs, opt_occs)
- in
- writeMutVarSST occs_var new_occ_pair
- where
- non_local_names = filter (not . isLocallyDefinedName) names
- necessity = case mode of
- SourceMode -> Compulsory
- InterfaceMode necessity -> necessity
-
- -- Never look for optional things if we're
- -- ignoring optional input interface information
-not_necessary Compulsory = False
-not_necessary Optional = opt_IgnoreIfacePragmas
-
-popOccurrenceName :: Necessity -> RnM s d (Maybe Name)
-popOccurrenceName necessity (RnDown loc names_var errs_var occs_var) l_down
- = readMutVarSST occs_var `thenSST` \ occs ->
- case (necessity, occs) of
- -- Find a compulsory occurrence
- (Compulsory, (comp:comps, opts)) -> writeMutVarSST occs_var (comps, opts) `thenSST_`
- returnSST (Just comp)
-
- -- Find an optional occurrence
- -- We shouldn't be looking unless we've done all the compulsories
- (Optional, (comps, opt:opts)) -> ASSERT( null comps )
- writeMutVarSST occs_var (comps, opts) `thenSST_`
- returnSST (Just opt)
-
- -- No suitable occurrence
- other -> returnSST Nothing
-
--- findOccurrencesRn does the enclosed thing with a *fresh* occurrences
--- variable, and returns the list of occurrences thus found. It's useful
--- when loading instance decls and specialisation signatures, when we want to
--- know the names of the things in the types, but we don't want to treat them
--- as occurrences.
-
-findOccurrencesRn :: RnM s d a -> RnM s d [Name]
-findOccurrencesRn enclosed_thing (RnDown loc names_var errs_var occs_var) l_down
- = newMutVarSST ([],[]) `thenSST` \ new_occs_var ->
- enclosed_thing (RnDown loc names_var errs_var new_occs_var) l_down `thenSST_`
- readMutVarSST new_occs_var `thenSST` \ (occs,_) ->
- returnSST occs