@@ -29,6 +29,7 @@ import Data.Maybe
29
29
import System.FilePath
30
30
#if MIN_VERSION_ghc(9,3,0)
31
31
import GHC.Types.PkgQual
32
+ import GHC.Unit.State
32
33
#endif
33
34
34
35
data Import
@@ -147,13 +148,32 @@ locateModule env comp_info exts targetFor modName mbPkgName isSource = do
147
148
map snd import_paths
148
149
#endif
149
150
150
- mbFile <- locateModuleFile ((homeUnitId_ dflags, importPaths dflags) : import_paths' ) exts targetFor isSource $ unLoc modName
151
+ mbFile <- locateModuleFile ((homeUnitId_ dflags, importPaths dflags) : other_imports ) exts targetFor isSource $ unLoc modName
151
152
case mbFile of
152
153
Nothing -> lookupInPackageDB env
153
154
Just (uid, file) -> toModLocation uid file
154
155
where
155
156
dflags = hsc_dflags env
156
157
import_paths = mapMaybe (mkImportDirs env) comp_info
158
+ other_imports =
159
+ #if MIN_VERSION_ghc(9,4,0)
160
+ -- On 9.4+ instead of bringing all the units into scope, only bring into scope the units
161
+ -- this one depends on
162
+ -- This way if you have multiple units with the same module names, we won't get confused
163
+ -- For example if unit a imports module M from unit B, when there is also a module M in unit C,
164
+ -- and unit a only depends on unit b, without this logic there is the potential to get confused
165
+ -- about which module unit a imports.
166
+ -- Without multi-component support it is hard to recontruct the dependency environment so
167
+ -- unit a will have both unit b and unit c in scope.
168
+ map (\ uid -> (uid, importPaths (homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue)))) hpt_deps
169
+ ue = hsc_unit_env env
170
+ units = homeUnitEnv_units $ ue_findHomeUnitEnv (homeUnitId_ dflags) ue
171
+ hpt_deps :: [UnitId ]
172
+ hpt_deps = homeUnitDepends units
173
+ #else
174
+ import_paths'
175
+ #endif
176
+
157
177
toModLocation uid file = liftIO $ do
158
178
loc <- mkHomeModLocation dflags (unLoc modName) (fromNormalizedFilePath file)
159
179
#if MIN_VERSION_ghc(9,0,0)
0 commit comments