@@ -331,9 +331,7 @@ getLocatedImportsRule recorder =
331331 let dflags = hsc_dflags env
332332 opt <- getIdeOptions
333333
334- moduleMaps' <- use_ GetModulesPaths file
335-
336- moduleMaps <- extendModuleMapWithKnownTargets file moduleMaps'
334+ moduleMaps <- extendModuleMapWithKnownTargets file
337335
338336 (diags, imports') <- fmap unzip $ forM imports $ \ (isSource, (mbPkgName, modName)) -> do
339337
@@ -677,10 +675,12 @@ getModulesPathsRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder
677675-- TODO: for now the implementation is O(number_of_known_files *
678676-- number_of_include_path) which is inacceptable and should be addressed.
679677extendModuleMapWithKnownTargets
680- :: NormalizedFilePath -> ( Map. Map ModuleName ( UnitId , NormalizedFilePath ), Map. Map ModuleName ( UnitId , NormalizedFilePath ))
678+ :: NormalizedFilePath
681679 -> Action (Map. Map ModuleName (UnitId , NormalizedFilePath ), Map. Map ModuleName (UnitId , NormalizedFilePath ))
682- extendModuleMapWithKnownTargets file (notSourceModules, sourceModules) = do
680+ extendModuleMapWithKnownTargets file = do
681+ (notSourceModules, sourceModules) <- use_ GetModulesPaths file
683682 KnownTargets targetsMap <- useNoFile_ GetKnownTargets
683+
684684 env_eq <- use_ GhcSession file
685685 let env = hscEnv env_eq
686686 let import_dirs = map (second homeUnitEnv_dflags) $ hugElts $ hsc_HUG env
@@ -701,30 +701,25 @@ extendModuleMapWithKnownTargets file (notSourceModules, sourceModules) = do
701701 -- TODO: the _target may represents something different than the path
702702 -- stored in paths. This need to be investigated.
703703 (_target, paths) <- HM. toList targetsMap
704- -- TODO: I have no idea why there is multiple path here
705- if length paths > 1
706- then error " the pathlength is incorrect"
707- else do
708- guard $ length paths > 0
709- let path = head $ toList paths
710- let pathString = fromNormalizedFilePath path
711- let pathComponents = splitDirectories pathString
712-
713- -- Ensure this file is in the directory
714- guard $ dirComponents `isPrefixOf` pathComponents
715-
716- -- Ensure that this extension is accepted
717- guard $ takeExtension pathString `elem` acceptedExtensions
718- let modName = mkModuleName (intercalate " ." $ drop dir_number_directories (splitDirectories (dropExtension pathString)))
719- let isSourceModule = " -boot" `isSuffixOf` pathString
720- if isSourceModule
721- then
722- pure (Nothing , Just (modName, (u, path)))
723- else
724- pure (Just (modName, (u, path)), Nothing )
725-
726-
727- pure (Map. fromList a <> notSourceModules, Map. fromList b <> sourceModules)
704+ path <- HashSet. toList paths
705+ let pathString = fromNormalizedFilePath path
706+ let pathComponents = splitDirectories pathString
707+
708+ -- Ensure this file is in the directory
709+ guard $ dirComponents `isPrefixOf` pathComponents
710+
711+ -- Ensure that this extension is accepted
712+ guard $ takeExtension pathString `elem` acceptedExtensions
713+ let modName = mkModuleName (intercalate " ." $ drop dir_number_directories (splitDirectories (dropExtension pathString)))
714+ let isSourceModule = " -boot" `isSuffixOf` pathString
715+ if isSourceModule
716+ then
717+ pure (Nothing , Just (modName, (u, path)))
718+ else
719+ pure (Just (modName, (u, path)), Nothing )
720+
721+
722+ pure $ (Map. fromList a <> notSourceModules, Map. fromList b <> sourceModules)
728723
729724
730725dependencyInfoForFiles :: [NormalizedFilePath ] -> Action (BS. ByteString , DependencyInformation )
0 commit comments