|
4 | 4 | {-# LANGUAGE ViewPatterns #-}
|
5 | 5 | {-# LANGUAGE ScopedTypeVariables #-}
|
6 | 6 | {-# LANGUAGE LambdaCase #-}
|
| 7 | +{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} |
| 8 | +{-# HLINT ignore "Use camelCase" #-} |
7 | 9 | module HieDb.Create where
|
8 | 10 |
|
9 | 11 | import Prelude hiding (mod)
|
@@ -37,7 +39,7 @@ import HieDb.Types
|
37 | 39 | import HieDb.Utils
|
38 | 40 |
|
39 | 41 | sCHEMA_VERSION :: Integer
|
40 |
| -sCHEMA_VERSION = 8 |
| 42 | +sCHEMA_VERSION = 9 |
41 | 43 |
|
42 | 44 | dB_VERSION :: Integer
|
43 | 45 | dB_VERSION = read (show sCHEMA_VERSION ++ "999" ++ show hieVersion)
|
@@ -117,6 +119,7 @@ initConn (getConn -> conn) = do
|
117 | 119 | \, sc INTEGER NOT NULL \
|
118 | 120 | \, el INTEGER NOT NULL \
|
119 | 121 | \, ec INTEGER NOT NULL \
|
| 122 | + \, is_generated BOOLEAN NOT NULL \ |
120 | 123 | \, FOREIGN KEY(hieFile) REFERENCES mods(hieFile) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED \
|
121 | 124 | \)"
|
122 | 125 | execute_ conn "CREATE INDEX IF NOT EXISTS refs_mod ON refs(hieFile)"
|
@@ -331,27 +334,39 @@ addRefsFromLoaded_unsafe
|
331 | 334 | mod = moduleName smod
|
332 | 335 | uid = moduleUnit smod
|
333 | 336 | smod = hie_module hf
|
334 |
| - refmap = generateReferencesMap $ getAsts $ hie_asts hf |
| 337 | + asts = getAsts $ hie_asts hf |
| 338 | + refmapAll = generateReferencesMap asts |
| 339 | + refmapSourceOnly = generateReferencesMap $ fmap (dropNodeInfos GeneratedInfo) asts |
| 340 | + refmapGeneratedOnly = generateReferencesMap $ fmap (dropNodeInfos SourceInfo) asts |
335 | 341 | (srcFile, isReal) = case sourceFile of
|
336 | 342 | RealFile f -> (Just f, True)
|
337 | 343 | FakeFile mf -> (mf, False)
|
338 | 344 | modrow = HieModuleRow path (ModuleInfo mod uid isBoot srcFile isReal hash)
|
339 | 345 |
|
| 346 | + -- We want to distinguish between references from source (NodeOrigin is SourceInfo) |
| 347 | + -- vs. generated by compiler (NodeOrigin is GeneratedInfo). |
| 348 | + -- Unfortunately generateReferencesMap throws away the info about NodeOrigin, |
| 349 | + -- so we need to use this to preprocess the ASTs from which the references map is generated. |
| 350 | + dropNodeInfos :: NodeOrigin -> HieAST a -> HieAST a |
| 351 | + dropNodeInfos originToDrop (Node (SourcedNodeInfo sniMap) sp children) = |
| 352 | + let sourceOnlyNodeInfo = SourcedNodeInfo $ M.delete originToDrop sniMap |
| 353 | + in Node sourceOnlyNodeInfo sp (map (dropNodeInfos originToDrop) children) |
| 354 | + |
340 | 355 | execute conn "INSERT INTO mods VALUES (?,?,?,?,?,?,?)" modrow
|
341 | 356 |
|
342 |
| - let AstInfo rows decls imports = genAstInfo path smod refmap |
| 357 | + let AstInfo refsSrc declsSrc importsSrc = genAstInfo path smod SourceInfo refmapSourceOnly |
| 358 | + AstInfo refsGen declsGen importsGen = genAstInfo path smod GeneratedInfo refmapGeneratedOnly |
343 | 359 |
|
344 | 360 | unless (skipRefs skipOptions) $
|
345 |
| - executeMany conn "INSERT INTO refs VALUES (?,?,?,?,?,?,?,?)" rows |
| 361 | + executeMany conn "INSERT INTO refs VALUES (?,?,?,?,?,?,?,?,?)" (refsSrc <> refsGen) |
346 | 362 | unless (skipDecls skipOptions) $
|
347 |
| - executeMany conn "INSERT INTO decls VALUES (?,?,?,?,?,?,?)" decls |
| 363 | + executeMany conn "INSERT INTO decls VALUES (?,?,?,?,?,?,?)" (declsSrc <> declsGen) |
348 | 364 | unless (skipImports skipOptions) $
|
349 |
| - executeMany conn "INSERT INTO imports VALUES (?,?,?,?,?,?)" imports |
| 365 | + executeMany conn "INSERT INTO imports VALUES (?,?,?,?,?,?)" (importsSrc <> importsGen) |
350 | 366 |
|
351 |
| - let defs = genDefRow path smod refmap |
| 367 | + let defs = genDefRow path smod refmapAll |
352 | 368 | unless (skipDefs skipOptions) $
|
353 |
| - forM_ defs $ \def -> |
354 |
| - execute conn "INSERT INTO defs VALUES (?,?,?,?,?,?)" def |
| 369 | + executeMany conn "INSERT INTO defs VALUES (?,?,?,?,?,?)" defs |
355 | 370 |
|
356 | 371 | let exports = generateExports path $ hie_exports hf
|
357 | 372 | unless (skipExports skipOptions) $
|
|
0 commit comments