@@ -80,10 +80,16 @@ instance Pretty Log where
8080 " New component cache HscEnvEq:" <+> viaShow componentCache
8181 LogDLLLoadError errorString ->
8282 " Error dynamically loading libm.so.6:" <+> pretty errorString
83-
83+ -- | Configuration info for a particular home unit.
8484data HomeUnitConfig = HomeUnitConfig
85- { homeUnitDynFlags :: DynFlags
85+ {
86+ -- | The dynamic flags to compile this specific unit.
87+ homeUnitDynFlags :: DynFlags
88+ -- | All the targets for this unit.
8689 , homeUnitTargets :: [GHC. Target ]
90+ -- | Optional hash seed to differentiate home units
91+ -- with same `-this-unit-id`. Used when `-this-unit-id` is "main"
92+ -- , common when loading a single target.
8793 , homeUnitHash :: Maybe B. ByteString
8894 }
8995-- This is pristine information about a component
@@ -101,7 +107,7 @@ data RawComponentInfo = RawComponentInfo
101107 -- | Maps cradle dependencies, such as `stack.yaml`, or `.cabal` file
102108 -- to last modification time. See Note [Multi Cradle Dependency Info].
103109 , rawComponentDependencyInfo :: DependencyInfo
104- -- | The raw ByteString for the hash generated in setoptions for the uid "main"
110+ -- | An optional hash seed generated in 'setOptions' for the unit id "main".
105111 , rawComponentHash :: Maybe B. ByteString
106112 }
107113
@@ -431,13 +437,23 @@ setCacheDirs recorder CacheDirs{..} dflags = do
431437 & maybe id setHieDir hieCacheDir
432438 & maybe id setODir oCacheDir
433439
440+ -- | Append the hash to the unit id to create unique cache folders.
441+ --
442+ -- This function generates a single, unified hash.
443+ -- If an optional base hash (@mFirstHash@) is provided—which
444+ -- is common for a single target with `-this-unit-id` as "main"-
445+ -- we set the prefix to "main", extract the context generated
446+ -- from the @mFirstHash@, and update the @opts@ into the same hash.
447+ --
448+ -- This guarantees a unique cache folder for different GHC
449+ -- options(avoiding incompatible interface files) while
450+ -- keeping the path short and clean.
434451getCacheDirsDefault :: String -> Maybe B. ByteString -> [String ] -> IO CacheDirs
435452getCacheDirsDefault prefix mFirstHash opts = do
436453 dir <- Just <$> getXdgDirectory XdgCache (cacheDir </> prefix' ++ " -" ++ opts_hash)
437454 return $ CacheDirs dir dir dir
438455 where
439- -- Create a unique folder per set of different GHC options, assuming that each different set of
440- -- GHC options will create incompatible interface files.
456+ -- Create a unique folder per set of different GHC options.
441457 prefix' = if isJust mFirstHash then " main" else prefix
442458 basectx = case mFirstHash of
443459 Just h -> H. updates H. init [h]
0 commit comments