Skip to content

Commit

Permalink
use the type check modsummary
Browse files Browse the repository at this point in the history
  • Loading branch information
soulomoon committed Jul 3, 2024
1 parent f0ba40b commit 3747ae5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import GHC.Driver.Errors.Types
import GHC.Types.Error (errMsgDiagnostic,
singleMessage)
import GHC.Unit.State
import Debug.Trace (traceM)

data Log
= LogSettingInitialDynFlags
Expand Down Expand Up @@ -530,7 +531,10 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
-- See Note [Avoiding bad interface files]
let hscComponents = sort $ map show uids
cacheDirOpts = hscComponents ++ componentOptions opts
let opts_hash = B.unpack $ B16.encode $ H.finalize $ H.updates H.init (map B.pack cacheDirOpts)
traceM $ "Setting cache dirs for " ++ show rawComponentUnitId ++ " " ++ opts_hash ++ " " ++ show cacheDirOpts

Check failure on line 535 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in loadSessionWithOptions in module Development.IDE.Session: Avoid restricted function ▫︎ Found: "traceM" ▫︎ Note: may break the code
cacheDirs <- liftIO $ getCacheDirs prefix cacheDirOpts

processed_df <- setCacheDirs recorder cacheDirs df2
-- The final component information, mostly the same but the DynFlags don't
-- contain any packages which are also loaded
Expand Down
7 changes: 6 additions & 1 deletion ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import GHC.Driver.Config.CoreToStg.Prep
#if MIN_VERSION_ghc(9,7,0)
import Data.Foldable (toList)
import GHC.Unit.Module.Warnings
import Development.IDE.Core.WorkerThread (awaitRunInThread)
#else
import Development.IDE.Core.FileStore (shareFilePath)
#endif
Expand Down Expand Up @@ -196,6 +197,7 @@ typecheckModule (IdeDefer defer) hsc tc_helpers pm = do
where
demoteIfDefer = if defer then demoteTypeErrorsToWarnings else id


-- | Install hooks to capture the splices as well as the runtime module dependencies
captureSplicesAndDeps :: TypecheckHelpers -> HscEnv -> (HscEnv -> IO a) -> IO (a, Splices, ModuleEnv BS.ByteString)
captureSplicesAndDeps TypecheckHelpers{..} env k = do
Expand Down Expand Up @@ -432,6 +434,7 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
let session = hscSetFlags (ms_hspp_opts ms) session'
ms = pm_mod_summary $ tmrParsed tcm

traceM $ "[TRACE] Generating hi file for " ++ show (moduleName $ ms_mod ms)
(details, guts) <- do
-- write core file
-- give variables unique OccNames
Expand Down Expand Up @@ -724,11 +727,13 @@ addRelativeImport fp modu dflags = dflags
-- | Also resets the interface store
atomicFileWrite :: ShakeExtras -> FilePath -> (FilePath -> IO a) -> IO a
atomicFileWrite se targetPath write = do
-- awaitRunInThread (restartQueue se) $ do
traceM $ "[TRACE] Writing file: " <> targetPath
let dir = takeDirectory targetPath
createDirectoryIfMissing True dir
(tempFilePath, cleanUp) <- newTempFileWithin dir
(write tempFilePath >>= \x -> renameFile tempFilePath targetPath >> atomically (resetInterfaceStore se (toNormalizedFilePath' targetPath)) >> pure x)
`onException` cleanUp
`onException` (cleanUp >> throwIO (userError "atomicFileWrite: write failed"))

generateHieAsts :: HscEnv -> TcModuleResult -> IO ([FileDiagnostic], Maybe (HieASTs Type))
generateHieAsts hscEnv tcm =
Expand Down
6 changes: 5 additions & 1 deletion ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ import System.Info.Extra (isWindows)

import qualified Data.IntMap as IM
import GHC.Fingerprint
import Debug.Trace (traceM)


data Log
Expand Down Expand Up @@ -1039,10 +1040,13 @@ usePropertyByPathAction path plId p = do
getLinkableRule :: Recorder (WithPriority Log) -> Rules ()
getLinkableRule recorder =
defineEarlyCutoff (cmapWithPrio LogShake recorder) $ Rule $ \GetLinkable f -> do
ModSummaryResult{msrModSummary = ms} <- use_ GetModSummary f
-- ModSummaryResult{msrModSummary = ms} <- use_ GetModSummary f
tmr <- use_ TypeCheck f
let ms = tmrModSummary tmr
HiFileResult{hirModIface, hirModDetails, hirCoreFp} <- use_ GetModIface f
let obj_file = ml_obj_file (ms_location ms)
core_file = ml_core_file (ms_location ms)
traceM $ "GetLinkable core_file " ++ show core_file

Check failure on line 1049 in ghcide/src/Development/IDE/Core/Rules.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Error in getLinkableRule in module Development.IDE.Core.Rules: Avoid restricted function ▫︎ Found: "traceM" ▫︎ Note: may break the code
case hirCoreFp of
Nothing -> error $ "called GetLinkable for a file without a linkable: " ++ show f
Just (bin_core, fileHash) -> do
Expand Down

0 comments on commit 3747ae5

Please sign in to comment.