@@ -27,7 +27,7 @@ import qualified GHC
27
27
import GHC.Iface.Ext.Utils (generateReferencesMap )
28
28
import GHC.Iface.Ext.Types (
29
29
getAsts , ContextInfo (.. ), IdentifierDetails (.. ), RecFieldContext (.. ),
30
- BindType (.. ), DeclType (.. ))
30
+ BindType (.. ), DeclType (.. ), IEType ( .. ) )
31
31
import qualified GHC.Types.Name.Occurrence as GHC
32
32
import qualified GHC.Types.Name as GHC (isSystemName )
33
33
import GHC.Unit.Types (unitFS )
@@ -45,6 +45,7 @@ import Glean.Util.Range
45
45
{- TODO
46
46
47
47
- issues with record fields
48
+ - DuplicateRecordFields generates names like $sel:field:Rec
48
49
- weird references to the record constructor from field decls
49
50
- why do we get a ref for the field decl?
50
51
- span of record field in pattern match is wrong
@@ -196,16 +197,16 @@ indexHieFile writer hie = do
196
197
Glean. makeFact_ @ Hs. ModuleDeclarations $ Hs. ModuleDeclarations_key
197
198
modfact (map snd names)
198
199
199
- let refs = Map. fromListWith (++ )
200
- [ (n, [span ])
200
+ let refs = Map. fromListWith (Map. unionWith (++) )
201
+ [ (n, Map. singleton kind [span ])
201
202
| (n, (span , dets)) <- allIds,
202
- any isRef (identInfo dets),
203
+ Just kind <- map isRef (Set. toList ( identInfo dets) ),
203
204
not (GHC. isSystemName n),
204
205
-- TODO: we should exclude generated names in a cleaner way
205
206
not (GHC. isDerivedOccName (nameOccName n))
206
207
]
207
208
208
- refs <- fmap catMaybes $ forM (Map. toList refs) $ \ (name, spans ) -> do
209
+ refs <- fmap catMaybes $ forM (Map. toList refs) $ \ (name, kindspans ) -> do
209
210
maybe_namefact <-
210
211
case Map. lookup name nameMap of
211
212
Just fact -> return $ Just fact
@@ -218,9 +219,11 @@ indexHieFile writer hie = do
218
219
namemod <- mkModule mod
219
220
Just <$> mkName name namemod (Hs. NameSort_external def)
220
221
forM maybe_namefact $ \ namefact -> do
221
- let gleanspans = map (toByteSpan . srcSpanToSrcRange filefact) spans
222
+ refspans <- forM (Map. toList kindspans) $ \ (kind, spans) -> do
223
+ let gleanspans = map (toByteSpan . srcSpanToSrcRange filefact) spans
224
+ return $ map (Hs. RefSpan kind) gleanspans
222
225
Glean. makeFact @ Hs. Reference $
223
- Hs. Reference_key namefact gleanspans
226
+ Hs. Reference_key namefact ( concat refspans)
224
227
225
228
Glean. makeFact_ @ Hs. FileXRefs $ Hs. FileXRefs_key filefact refs
226
229
@@ -236,12 +239,14 @@ indexHieFile writer hie = do
236
239
| otherwise -> False
237
240
238
241
-- returns True if this ContextInfo is a reference
239
- isRef Use = True
240
- isRef (RecField r _) = isRecFieldRef r
241
- isRef (ValBind InstanceBind _ _) = True -- treat these as refs, not binds
242
- isRef TyDecl {} = True
243
- isRef IEThing {} = True
244
- isRef _ = False
242
+ isRef Use = Just Hs. RefKind_coderef
243
+ isRef (RecField r _) | isRecFieldRef r = Just Hs. RefKind_coderef
244
+ isRef (ValBind InstanceBind _ _) = Just Hs. RefKind_coderef
245
+ -- treat these as refs, not binds
246
+ isRef TyDecl {} = Just Hs. RefKind_coderef
247
+ isRef (IEThing Export ) = Just Hs. RefKind_exportref
248
+ isRef (IEThing _) = Just Hs. RefKind_importref
249
+ isRef _ = Nothing
245
250
246
251
isRecFieldRef RecFieldAssign = True
247
252
isRecFieldRef RecFieldMatch = True
@@ -258,4 +263,3 @@ indexHieFile writer hie = do
258
263
goDecl TyVarBind {} = Just defaultSpan
259
264
goDecl (ClassTyDecl sp) = sp
260
265
goDecl _ = Nothing
261
-
0 commit comments