on master help sign in
Prefer to load imports from the current package
3ad2672Niklas Larsson
src/IRTS/Compiler.hs+1−1
@@ -76,7 +76,7 @@ compile codegen f mtm = do
76 libs <- getLibs codegen
76 libs <- getLibs codegen
77 flags <- getFlags codegen
77 flags <- getFlags codegen
78 hdrs <- getHdrs codegen
78 hdrs <- getHdrs codegen
79− impdirs <- allImportDirs
79+ impdirs <- rankedImportDirs f
80 ttDeclarations <- getDeclarations reachableNames
80 ttDeclarations <- getDeclarations reachableNames
81 defsIn <- mkDecls reachableNames
81 defsIn <- mkDecls reachableNames
82 -- if no 'main term' given, generate interface files
82 -- if no 'main term' given, generate interface files
src/Idris/AbsSyntax.hs+8
@@ -1108,6 +1108,14 @@ allImportDirs = do i <- getIState
1108 let optdirs = opt_importdirs (idris_options i)
1108 let optdirs = opt_importdirs (idris_options i)
1109 return ("." : reverse optdirs)
1109 return ("." : reverse optdirs)
1110
1110
1111+-- Like allImportDirs but the dirs that are a prefix of
1112+-- the files path first. This makes it look in the current
1113+-- package first.
1114+rankedImportDirs :: FilePath -> Idris [FilePath]
1115+rankedImportDirs fp = do ids <- allImportDirs
1116+ let (prefixes, rest) = partition (`isPrefixOf`fp) ids
1117+ return $ prefixes ++ rest
1118+
1111addSourceDir :: FilePath -> Idris ()
1119addSourceDir :: FilePath -> Idris ()
1112addSourceDir fp = do i <- getIState
1120addSourceDir fp = do i <- getIState
1113 let opts = idris_options i
1121 let opts = idris_options i
src/Idris/IBC.hs+15−22
@@ -146,7 +146,7 @@ loadIBC reexport phase fp
146 Right archive -> do
146 Right archive -> do
147 if fullLoad
147 if fullLoad
148 then process reexport phase archive fp
148 then process reexport phase archive fp
149− else unhide phase archive
149+ else unhide phase fp archive
150 addImported reexport fp
150 addImported reexport fp
151
151
152-- | Load an entire package from its index file
152-- | Load an entire package from its index file
@@ -359,9 +359,9 @@ getEntry alt f a = case findEntryByPath f a of
359 Nothing -> return alt
359 Nothing -> return alt
360 Just e -> return $! (force . decode . fromEntry) e
360 Just e -> return $! (force . decode . fromEntry) e
361
361
362−unhide :: IBCPhase -> Archive -> Idris ()
362+unhide :: IBCPhase -> FilePath -> Archive -> Idris ()
363−unhide phase ar = do
363+unhide phase fp ar = do
364− processImports True phase ar
364+ processImports True phase fp ar
365 processAccess True phase ar
365 processAccess True phase ar
366
366
367process :: Bool -- ^ Reexporting
367process :: Bool -- ^ Reexporting
@@ -393,7 +393,7 @@ process reexp phase archive fn = do
393 when srcok $ timestampOlder source fn
393 when srcok $ timestampOlder source fn
394 processImportDirs archive
394 processImportDirs archive
395 processSourceDirs archive
395 processSourceDirs archive
396− processImports reexp phase archive
396+ processImports reexp phase fn archive
397 processImplicits archive
397 processImplicits archive
398 processInfix archive
398 processInfix archive
399 processStatics archive
399 processStatics archive
@@ -405,7 +405,7 @@ process reexp phase archive fn = do
405 processOptimise archive
405 processOptimise archive
406 processSyntax archive
406 processSyntax archive
407 processKeywords archive
407 processKeywords archive
408− processObjectFiles archive
408+ processObjectFiles fn archive
409 processLibs archive
409 processLibs archive
410 processCodegenFlags archive
410 processCodegenFlags archive
411 processDynamicLibs archive
411 processDynamicLibs archive
@@ -509,28 +509,21 @@ processSourceDirs ar = do
509 fs <- getEntry [] "ibc_sourcedirs" ar
509 fs <- getEntry [] "ibc_sourcedirs" ar
510 mapM_ addSourceDir fs
510 mapM_ addSourceDir fs
511
511
512−processImports :: Bool -> IBCPhase -> Archive -> Idris ()
512+processImports :: Bool -> IBCPhase -> FilePath -> Archive -> Idris ()
513−processImports reexp phase ar = do
513+processImports reexp phase fname ar = do
514 fs <- getEntry [] "ibc_imports" ar
514 fs <- getEntry [] "ibc_imports" ar
515 mapM_ (\(re, f) -> do
515 mapM_ (\(re, f) -> do
516 i <- getIState
516 i <- getIState
517 ibcsd <- valIBCSubDir i
517 ibcsd <- valIBCSubDir i
518− ids <- allImportDirs
518+ ids <- rankedImportDirs fname
519− fp <- findImport ids ibcsd f
520−-- if (f `elem` imported i)
521−-- then logLvl 1 $ "Already read " ++ f
522 putIState (i { imported = f : imported i })
519 putIState (i { imported = f : imported i })
523 let phase' = case phase of
520 let phase' = case phase of
524 IBC_REPL _ -> IBC_REPL False
521 IBC_REPL _ -> IBC_REPL False
525 p -> p
522 p -> p
523+ fp <- findIBC ids ibcsd f
526 case fp of
524 case fp of
527− LIDR fn -> do
528− logIBC 2 $ "Failed at " ++ fn
525+ Nothing -> do logIBC 2 $ "Failed to load ibc " ++ f
529− ifail "Must be an ibc"
530− IDR fn -> do
531− logIBC 2 $ "Failed at " ++ fn
532− ifail "Must be an ibc"
533− IBC fn src -> loadIBC (reexp && re) phase' fn) fs
526+ Just fn -> do loadIBC (reexp && re) phase' fn) fs
534
527
535processImplicits :: Archive -> Idris ()
528processImplicits :: Archive -> Idris ()
536processImplicits ar = do
529processImplicits ar = do
@@ -605,11 +598,11 @@ processKeywords ar = do
605 k <- getEntry [] "ibc_keywords" ar
598 k <- getEntry [] "ibc_keywords" ar
606 updateIState (\i -> i { syntax_keywords = k ++ syntax_keywords i })
599 updateIState (\i -> i { syntax_keywords = k ++ syntax_keywords i })
607
600
608−processObjectFiles :: Archive -> Idris ()
601+processObjectFiles :: FilePath -> Archive -> Idris ()
609−processObjectFiles ar = do
602+processObjectFiles fn ar = do
610 os <- getEntry [] "ibc_objs" ar
603 os <- getEntry [] "ibc_objs" ar
611 mapM_ (\ (cg, obj) -> do
604 mapM_ (\ (cg, obj) -> do
612− dirs <- allImportDirs
605+ dirs <- rankedImportDirs fn
613 o <- runIO $ findInPath dirs obj
606 o <- runIO $ findInPath dirs obj
614 addObjectFile cg o) os
607 addObjectFile cg o) os
615
608
src/Idris/Imports.hs+13−1
@@ -6,13 +6,14 @@ License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8module Idris.Imports(
8module Idris.Imports(
9− IFileType(..), findImport, findInPath, findPkgIndex
9+ IFileType(..), findIBC, findImport, findInPath, findPkgIndex
10 , ibcPathNoFallback, installedPackages, pkgIndex
10 , ibcPathNoFallback, installedPackages, pkgIndex
11 ) where
11 ) where
12
12
13import Idris.AbsSyntax
13import Idris.AbsSyntax
14import Idris.Core.TT
14import Idris.Core.TT
15import Idris.Error
15import Idris.Error
16+import Idris.Output
16import IRTS.System (getIdrisLibDir)
17import IRTS.System (getIdrisLibDir)
17
18
18import Control.Applicative ((<$>))
19import Control.Applicative ((<$>))
@@ -77,6 +78,17 @@ findImport (d:ds) ibcsd fp = do let fp_full = d </> fp
77 then return isrc
78 then return isrc
78 else findImport ds ibcsd fp
79 else findImport ds ibcsd fp
79
80
81+-- Only look for IBCs and not source
82+findIBC :: [FilePath] -> FilePath -> FilePath -> Idris (Maybe FilePath)
83+findIBC [] _ fp = return Nothing
84+findIBC (d:ds) ibcsd fp = do let fp_full = d </> fp
85+ ibcp <- runIO $ ibcPathWithFallback ibcsd fp_full
86+ ibc <- runIO $ doesFileExist' ibcp
87+ if ibc
88+ then return $ Just ibcp
89+ else findIBC ds ibcsd fp
90+
91+
80-- find a specific filename somewhere in a path
92-- find a specific filename somewhere in a path
81
93
82findInPath :: [FilePath] -> FilePath -> IO FilePath
94findInPath :: [FilePath] -> FilePath -> IO FilePath
src/Idris/Parser.hs+2−2
@@ -1664,7 +1664,7 @@ loadModule' f phase
1664 = do i <- getIState
1664 = do i <- getIState
1665 let file = takeWhile (/= ' ') f
1665 let file = takeWhile (/= ' ') f
1666 ibcsd <- valIBCSubDir i
1666 ibcsd <- valIBCSubDir i
1667− ids <- allImportDirs
1667+ ids <- rankedImportDirs file
1668 fp <- findImport ids ibcsd file
1668 fp <- findImport ids ibcsd file
1669 if file `elem` imported i
1669 if file `elem` imported i
1670 then do logParser 1 $ "Already read " ++ file
1670 then do logParser 1 $ "Already read " ++ file
@@ -1717,7 +1717,7 @@ loadSource lidr f toline
1717 (mdocs, mname, imports_in, pos) <- parseImports f file
1717 (mdocs, mname, imports_in, pos) <- parseImports f file
1718 ai <- getAutoImports
1718 ai <- getAutoImports
1719 let imports = map (\n -> ImportInfo True n Nothing [] NoFC NoFC) ai ++ imports_in
1719 let imports = map (\n -> ImportInfo True n Nothing [] NoFC NoFC) ai ++ imports_in
1720− ids <- allImportDirs
1720+ ids <- rankedImportDirs f
1721 ibcsd <- valIBCSubDir i
1721 ibcsd <- valIBCSubDir i
1722 mapM_ (\(re, f, ns, nfc) ->
1722 mapM_ (\(re, f, ns, nfc) ->
1723 do fp <- findImport ids ibcsd f
1723 do fp <- findImport ids ibcsd f