Skip to content

Commit ccd6598

Browse files
simonmarmeta-codesync[bot]
authored andcommitted
Add units for incremental indexing (facebookincubator#627)
Summary: Does what it says on the tin Pull Request resolved: facebookincubator#627 Reviewed By: bochko Differential Revision: D88849453 Pulled By: phlalx fbshipit-source-id: ba443a6e3dc800f5b752602935fa756062bc3527
1 parent ef4cf6f commit ccd6598

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

glean/client/hs/Glean.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ module Glean
154154
, makeFactV
155155
, makeFactV_
156156
, NewFact(..)
157+
, UnitName
157158

158159
-- ** Lower-level write API
159160
, withSender

glean/lang/haskell/HieIndexer/Index.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ mkModule mod unit = do
125125
Glean.makeFact @Hs.Module $
126126
Hs.Module_key modname unitname
127127

128+
-- The Glean unit (used for incremental indexing) is
129+
-- <package>:<module>. We use this rather than the source file path,
130+
-- because you might move the source file while keeping the module
131+
-- name unchanged.
132+
gleanUnit :: GHC.Module -> Glean.UnitName
133+
gleanUnit mod = ghcUnit <> ":" <> moduleName
134+
where
135+
ghcUnit = GHC.bytesFS $ GHC.unitFS $ GHC.moduleUnit mod
136+
moduleName = GHC.bytesFS $ GHC.moduleNameFS $ GHC.moduleName mod
137+
128138
toUnitName :: UnitName -> GHC.Unit -> Text
129139
toUnitName unitName u = case unitName of
130140
UnitKey -> t
@@ -380,7 +390,7 @@ indexHieFile
380390
indexHieFile writer srcPaths srcPrefix unit path hie = do
381391
srcFile <- findSourceFile srcPaths (hie_module hie) (hie_hs_file hie)
382392
logInfo $ "Indexing: " <> path <> " (" <> srcFile <> ")"
383-
Glean.writeFacts writer $ do
393+
Glean.writeFacts writer $ Glean.withUnit (gleanUnit smod) $ do
384394
modfact <- mkModule smod unit
385395

386396
let offs = getLineOffsets (hie_hs_src hie)

0 commit comments

Comments
 (0)