-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_occs ++ opt_occs)
- Compulsory -> (non_local_occs ++ comp_occs, opt_occs)
- in
- writeMutVarSST occs_var new_occ_pair
- where
- non_local_occs = [(name, loc) | name <- names, not (isLocallyDefinedName name)]
- necessity = modeToNecessity mode
-
- -- Never look for optional things if we're
- -- ignoring optional input interface information
-not_necessary Compulsory = False
-not_necessary Optional = opt_IgnoreIfacePragmas
-
-popOccurrenceName :: RnSMode -> RnM s d (Maybe Occurrence)
-popOccurrenceName mode (RnDown loc names_var errs_var occs_var) l_down
- = readMutVarSST occs_var `thenSST` \ occs ->
- case (mode, occs) of
- -- Find a compulsory occurrence
- (InterfaceMode 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
- (InterfaceMode Optional, (comps, opt:opts))
- -> ASSERT2( null comps, ppr comps )
- writeMutVarSST occs_var (comps, opts) `thenSST_`
- returnSST (Just opt)
-
- -- No suitable occurrence
- other -> returnSST Nothing
-
--- discardOccurrencesRn does the enclosed thing with a *fresh* occurrences
--- variable, and discards 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.
-
-discardOccurrencesRn :: RnM s d a -> RnM s d a
-discardOccurrencesRn 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