{-# LANGUAGE CPP #-}
{-# LANGUAGE NondecreasingIndentation #-}
{-# LANGUAGE RecursiveDo #-}
module Agda.Interaction.Imports
( Mode, pattern ScopeCheck, pattern TypeCheck
, CheckResult (CheckResult)
, crModuleInfo
, crInterface
, crWarnings
, crMode
, crSource
, Source(..)
, scopeCheckImport
, parseSource
, typeCheckMain
, readInterface
) where
import Prelude hiding (null)
import Control.Monad ( forM, forM_, void )
import Control.Monad.Except
import Control.Monad.IO.Class ( MonadIO(..) )
import Control.Monad.State
import Control.Monad.Trans.Maybe
import qualified Control.Exception as E
#if __GLASGOW_HASKELL__ < 808
import Control.Monad.Fail (MonadFail)
#endif
import Data.Either
import qualified Data.List as List
import Data.Maybe
import Data.Map (Map)
import qualified Data.Map as Map
import qualified Data.HashMap.Strict as HMap
import qualified Data.HashSet as HSet
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text.Lazy as TL
import System.Directory (doesFileExist, removeFile)
import System.FilePath ((</>), takeDirectory)
import Agda.Benchmarking
import qualified Agda.Syntax.Abstract as A
import qualified Agda.Syntax.Concrete as C
import Agda.Syntax.Concrete.Attribute
import Agda.Syntax.Abstract.Name
import Agda.Syntax.Common
import Agda.Syntax.Parser
import Agda.Syntax.Position
import Agda.Syntax.Scope.Base
import Agda.Syntax.TopLevelModuleName
import Agda.Syntax.Translation.ConcreteToAbstract as CToA
import Agda.TypeChecking.Errors
import Agda.TypeChecking.Warnings hiding (warnings)
import Agda.TypeChecking.Reduce
import Agda.TypeChecking.Rewriting.Confluence ( checkConfluenceOfRules )
import Agda.TypeChecking.MetaVars ( openMetasToPostulates )
import Agda.TypeChecking.Monad
import Agda.TypeChecking.Serialise
import Agda.TypeChecking.Primitive
import Agda.TypeChecking.Pretty as P
import Agda.TypeChecking.DeadCode
import qualified Agda.TypeChecking.Monad.Benchmark as Bench
import Agda.TheTypeChecker
import Agda.Interaction.BasicOps ( getGoals, showGoals )
import Agda.Interaction.FindFile
import Agda.Interaction.Highlighting.Generate
import Agda.Interaction.Highlighting.Precise ( convert )
import Agda.Interaction.Highlighting.Vim
import Agda.Interaction.Library
import Agda.Interaction.Options
import qualified Agda.Interaction.Options.Lenses as Lens
import Agda.Interaction.Options.Warnings (unsolvedWarnings)
import Agda.Interaction.Response
(RemoveTokenBasedHighlighting(KeepHighlighting))
import Agda.Utils.FileName
import Agda.Utils.Lens
import Agda.Utils.Maybe
import qualified Agda.Utils.Maybe.Strict as Strict
import Agda.Utils.Monad
import Agda.Utils.Null
import Agda.Utils.IO.Binary
import Agda.Utils.Pretty hiding (Mode)
import qualified Agda.Utils.ProfileOptions as Profile
import Agda.Utils.Hash
import qualified Agda.Utils.Trie as Trie
import Agda.Utils.WithDefault
import Agda.Utils.Impossible
ignoreInterfaces :: HasOptions m => m Bool
ignoreInterfaces :: forall (m :: * -> *). HasOptions m => m Bool
ignoreInterfaces = CommandLineOptions -> Bool
optIgnoreInterfaces forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m CommandLineOptions
commandLineOptions
ignoreAllInterfaces :: HasOptions m => m Bool
ignoreAllInterfaces :: forall (m :: * -> *). HasOptions m => m Bool
ignoreAllInterfaces = CommandLineOptions -> Bool
optIgnoreAllInterfaces forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m CommandLineOptions
commandLineOptions
data Source = Source
{ Source -> Text
srcText :: TL.Text
, Source -> FileType
srcFileType :: FileType
, Source -> SourceFile
srcOrigin :: SourceFile
, Source -> Module
srcModule :: C.Module
, Source -> TopLevelModuleName
srcModuleName :: TopLevelModuleName
, Source -> [AgdaLibFile]
srcProjectLibs :: [AgdaLibFile]
, Source -> CohesionAttributes
srcCohesion :: !CohesionAttributes
}
parseSource :: SourceFile -> TCM Source
parseSource :: SourceFile -> TCM Source
parseSource sourceFile :: SourceFile
sourceFile@(SourceFile AbsolutePath
f) = forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Parsing] forall a b. (a -> b) -> a -> b
$ do
(Text
source, FileType
fileType, Module
parsedMod, CohesionAttributes
coh, TopLevelModuleName
parsedModName) <- mdo
let rf :: RangeFile
rf = AbsolutePath -> Maybe TopLevelModuleName -> RangeFile
mkRangeFile AbsolutePath
f (forall a. a -> Maybe a
Just TopLevelModuleName
parsedModName)
Text
source <- forall a. PM a -> TCM a
runPM forall a b. (a -> b) -> a -> b
$ RangeFile -> PM Text
readFilePM RangeFile
rf
((Module
parsedMod, CohesionAttributes
coh), FileType
fileType) <- forall a. PM a -> TCM a
runPM forall a b. (a -> b) -> a -> b
$ forall a.
Show a =>
Parser a
-> RangeFile -> [Char] -> PM ((a, CohesionAttributes), FileType)
parseFile Parser Module
moduleParser RangeFile
rf forall a b. (a -> b) -> a -> b
$
Text -> [Char]
TL.unpack Text
source
TopLevelModuleName
parsedModName <- AbsolutePath -> Module -> TCM TopLevelModuleName
moduleName AbsolutePath
f Module
parsedMod
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
source, FileType
fileType, Module
parsedMod, CohesionAttributes
coh, TopLevelModuleName
parsedModName)
[AgdaLibFile]
libs <- AbsolutePath -> TopLevelModuleName -> TCM [AgdaLibFile]
getAgdaLibFiles AbsolutePath
f TopLevelModuleName
parsedModName
forall (m :: * -> *) a. Monad m => a -> m a
return Source
{ srcText :: Text
srcText = Text
source
, srcFileType :: FileType
srcFileType = FileType
fileType
, srcOrigin :: SourceFile
srcOrigin = SourceFile
sourceFile
, srcModule :: Module
srcModule = Module
parsedMod
, srcModuleName :: TopLevelModuleName
srcModuleName = TopLevelModuleName
parsedModName
, srcProjectLibs :: [AgdaLibFile]
srcProjectLibs = [AgdaLibFile]
libs
, srcCohesion :: CohesionAttributes
srcCohesion = CohesionAttributes
coh
}
srcDefaultPragmas :: Source -> [OptionsPragma]
srcDefaultPragmas :: Source -> [[[Char]]]
srcDefaultPragmas Source
src = forall a b. (a -> b) -> [a] -> [b]
map AgdaLibFile -> [[Char]]
_libPragmas (Source -> [AgdaLibFile]
srcProjectLibs Source
src)
srcFilePragmas :: Source -> [OptionsPragma]
srcFilePragmas :: Source -> [[[Char]]]
srcFilePragmas Source
src = [[[Char]]]
pragmas
where
cpragmas :: [Pragma]
cpragmas = Module -> [Pragma]
C.modPragmas (Source -> Module
srcModule Source
src)
pragmas :: [[[Char]]]
pragmas = [ [[Char]]
opts | C.OptionsPragma Range
_ [[Char]]
opts <- [Pragma]
cpragmas ]
srcPragmas :: Source -> [OptionsPragma]
srcPragmas :: Source -> [[[Char]]]
srcPragmas Source
src = Source -> [[[Char]]]
srcDefaultPragmas Source
src forall a. [a] -> [a] -> [a]
++ Source -> [[[Char]]]
srcFilePragmas Source
src
setOptionsFromSourcePragmas :: Source -> TCM ()
setOptionsFromSourcePragmas :: Source -> TCM ()
setOptionsFromSourcePragmas Source
src =
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange (Module -> [Pragma]
C.modPragmas forall b c a. (b -> c) -> (a -> b) -> a -> c
. Source -> Module
srcModule forall a b. (a -> b) -> a -> b
$ Source
src) forall a b. (a -> b) -> a -> b
$
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ [[Char]] -> TCM ()
setOptionsFromPragma (Source -> [[[Char]]]
srcPragmas Source
src)
data Mode
= ScopeCheck
| TypeCheck
deriving (Mode -> Mode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Mode -> Mode -> Bool
$c/= :: Mode -> Mode -> Bool
== :: Mode -> Mode -> Bool
$c== :: Mode -> Mode -> Bool
Eq, Int -> Mode -> ShowS
[Mode] -> ShowS
Mode -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [Mode] -> ShowS
$cshowList :: [Mode] -> ShowS
show :: Mode -> [Char]
$cshow :: Mode -> [Char]
showsPrec :: Int -> Mode -> ShowS
$cshowsPrec :: Int -> Mode -> ShowS
Show)
data MainInterface
= MainInterface Mode
| NotMainInterface
deriving (MainInterface -> MainInterface -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MainInterface -> MainInterface -> Bool
$c/= :: MainInterface -> MainInterface -> Bool
== :: MainInterface -> MainInterface -> Bool
$c== :: MainInterface -> MainInterface -> Bool
Eq, Int -> MainInterface -> ShowS
[MainInterface] -> ShowS
MainInterface -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [MainInterface] -> ShowS
$cshowList :: [MainInterface] -> ShowS
show :: MainInterface -> [Char]
$cshow :: MainInterface -> [Char]
showsPrec :: Int -> MainInterface -> ShowS
$cshowsPrec :: Int -> MainInterface -> ShowS
Show)
includeStateChanges :: MainInterface -> Bool
includeStateChanges :: MainInterface -> Bool
includeStateChanges (MainInterface Mode
_) = Bool
True
includeStateChanges MainInterface
NotMainInterface = Bool
False
moduleCheckMode :: MainInterface -> ModuleCheckMode
moduleCheckMode :: MainInterface -> ModuleCheckMode
moduleCheckMode = \case
MainInterface Mode
TypeCheck -> ModuleCheckMode
ModuleTypeChecked
MainInterface
NotMainInterface -> ModuleCheckMode
ModuleTypeChecked
MainInterface Mode
ScopeCheck -> ModuleCheckMode
ModuleScopeChecked
mergeInterface :: Interface -> TCM ()
mergeInterface :: Interface -> TCM ()
mergeInterface Interface
i = do
let sig :: Signature
sig = Interface -> Signature
iSignature Interface
i
builtin :: [([Char], Builtin ([Char], QName))]
builtin = forall k a. Map k a -> [(k, a)]
Map.toAscList forall a b. (a -> b) -> a -> b
$ Interface -> BuiltinThings ([Char], QName)
iBuiltin Interface
i
primOrBi :: (a, Builtin a) -> Either a (a, Builtin pf)
primOrBi = \case
(a
_, Prim a
x) -> forall a b. a -> Either a b
Left a
x
(a
x, Builtin Term
t) -> forall a b. b -> Either a b
Right (a
x, forall pf. Term -> Builtin pf
Builtin Term
t)
(a
x, BuiltinRewriteRelations Set QName
xs) -> forall a b. b -> Either a b
Right (a
x, forall pf. Set QName -> Builtin pf
BuiltinRewriteRelations Set QName
xs)
([([Char], QName)]
prim, [([Char], Builtin PrimFun)]
bi') = forall a b. [Either a b] -> ([a], [b])
partitionEithers forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall {a} {a} {pf}. (a, Builtin a) -> Either a (a, Builtin pf)
primOrBi [([Char], Builtin ([Char], QName))]
builtin
bi :: Map [Char] (Builtin PrimFun)
bi = forall k a. [(k, a)] -> Map k a
Map.fromDistinctAscList [([Char], Builtin PrimFun)]
bi'
warns :: [TCWarning]
warns = Interface -> [TCWarning]
iWarnings Interface
i
Map [Char] (Builtin PrimFun)
bs <- forall (m :: * -> *) a. ReadTCState m => (TCState -> a) -> m a
getsTC TCState -> Map [Char] (Builtin PrimFun)
stBuiltinThings
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.merge" Int
10 [Char]
"Merging interface"
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.merge" Int
20 forall a b. (a -> b) -> a -> b
$
[Char]
" Current builtins " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (forall k a. Map k a -> [k]
Map.keys Map [Char] (Builtin PrimFun)
bs) forall a. [a] -> [a] -> [a]
++ [Char]
"\n" forall a. [a] -> [a] -> [a]
++
[Char]
" New builtins " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (forall k a. Map k a -> [k]
Map.keys Map [Char] (Builtin PrimFun)
bi)
let check :: [Char] -> Builtin pf -> Builtin pf -> m ()
check [Char]
b (Builtin Term
x) (Builtin Term
y)
| Term
x forall a. Eq a => a -> a -> Bool
== Term
y = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError forall a b. (a -> b) -> a -> b
$ [Char] -> Term -> Term -> TypeError
DuplicateBuiltinBinding [Char]
b Term
x Term
y
check [Char]
_ (BuiltinRewriteRelations Set QName
xs) (BuiltinRewriteRelations Set QName
ys) = forall (m :: * -> *) a. Monad m => a -> m a
return ()
check [Char]
_ Builtin pf
_ Builtin pf
_ = forall a. HasCallStack => a
__IMPOSSIBLE__
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ forall a b. (a -> b) -> a -> b
$ forall k a b c.
Ord k =>
(k -> a -> b -> c) -> Map k a -> Map k b -> Map k c
Map.intersectionWithKey forall {m :: * -> *} {pf} {pf}.
(MonadTCEnv m, ReadTCState m, MonadError TCErr m) =>
[Char] -> Builtin pf -> Builtin pf -> m ()
check Map [Char] (Builtin PrimFun)
bs Map [Char] (Builtin PrimFun)
bi
Signature
-> RemoteMetaStore
-> Map [Char] (Builtin PrimFun)
-> PatternSynDefns
-> DisplayForms
-> Map QName Text
-> Set QName
-> [TCWarning]
-> TCM ()
addImportedThings
Signature
sig
(Interface -> RemoteMetaStore
iMetaBindings Interface
i)
Map [Char] (Builtin PrimFun)
bi
(Interface -> PatternSynDefns
iPatternSyns Interface
i)
(Interface -> DisplayForms
iDisplayForms Interface
i)
(Interface -> Map QName Text
iUserWarnings Interface
i)
(Interface -> Set QName
iPartialDefs Interface
i)
[TCWarning]
warns
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.merge" Int
20 forall a b. (a -> b) -> a -> b
$
[Char]
" Rebinding primitives " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show [([Char], QName)]
prim
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ([Char], QName) -> TCM ()
rebind [([Char], QName)]
prim
forall (m :: * -> *) a.
Monad m =>
m (Maybe a) -> (a -> m ()) -> m ()
whenJustM (PragmaOptions -> Maybe ConfluenceCheck
optConfluenceCheck forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions) forall a b. (a -> b) -> a -> b
$ \ConfluenceCheck
confChk -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.confluence" Int
20 forall a b. (a -> b) -> a -> b
$ [Char]
" Checking confluence of imported rewrite rules"
ConfluenceCheck -> [RewriteRule] -> TCM ()
checkConfluenceOfRules ConfluenceCheck
confChk forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall a b. (a -> b) -> a -> b
$ forall k v. HashMap k v -> [v]
HMap.elems forall a b. (a -> b) -> a -> b
$ Signature
sig forall o i. o -> Lens' i o -> i
^. Lens' (HashMap QName [RewriteRule]) Signature
sigRewriteRules
where
rebind :: ([Char], QName) -> TCM ()
rebind ([Char]
x, QName
q) = do
PrimImpl Type
_ PrimFun
pf <- [Char] -> TCM PrimitiveImpl
lookupPrimitiveFunction [Char]
x
Lens' (Map [Char] (Builtin PrimFun)) TCState
stImportedBuiltins forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert [Char]
x (forall pf. pf -> Builtin pf
Prim PrimFun
pf{ primFunName :: QName
primFunName = QName
q })
addImportedThings
:: Signature
-> RemoteMetaStore
-> BuiltinThings PrimFun
-> A.PatternSynDefns
-> DisplayForms
-> Map A.QName Text
-> Set QName
-> [TCWarning]
-> TCM ()
addImportedThings :: Signature
-> RemoteMetaStore
-> Map [Char] (Builtin PrimFun)
-> PatternSynDefns
-> DisplayForms
-> Map QName Text
-> Set QName
-> [TCWarning]
-> TCM ()
addImportedThings Signature
isig RemoteMetaStore
metas Map [Char] (Builtin PrimFun)
ibuiltin PatternSynDefns
patsyns DisplayForms
display Map QName Text
userwarn
Set QName
partialdefs [TCWarning]
warnings = do
Lens' Signature TCState
stImports forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` \ Signature
imp -> [Signature] -> Signature
unionSignatures [Signature
imp, Signature
isig]
Lens' RemoteMetaStore TCState
stImportedMetaStore forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` forall k v.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k v -> HashMap k v
HMap.union RemoteMetaStore
metas
Lens' (Map [Char] (Builtin PrimFun)) TCState
stImportedBuiltins forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` \ Map [Char] (Builtin PrimFun)
imp -> forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union Map [Char] (Builtin PrimFun)
imp Map [Char] (Builtin PrimFun)
ibuiltin
Lens' (Map QName Text) TCState
stImportedUserWarnings forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` \ Map QName Text
imp -> forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union Map QName Text
imp Map QName Text
userwarn
Lens' (Set QName) TCState
stImportedPartialDefs forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` \ Set QName
imp -> forall a. Ord a => Set a -> Set a -> Set a
Set.union Set QName
imp Set QName
partialdefs
Lens' PatternSynDefns TCState
stPatternSynImports forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` \ PatternSynDefns
imp -> forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union PatternSynDefns
imp PatternSynDefns
patsyns
Lens' DisplayForms TCState
stImportedDisplayForms forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` \ DisplayForms
imp -> forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> HashMap k v -> HashMap k v -> HashMap k v
HMap.unionWith forall a. [a] -> [a] -> [a]
(++) DisplayForms
imp DisplayForms
display
Lens' [TCWarning] TCState
stTCWarnings forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` \ [TCWarning]
imp -> [TCWarning]
imp forall a. Eq a => [a] -> [a] -> [a]
`List.union` [TCWarning]
warnings
Signature -> TCM ()
addImportedInstances Signature
isig
scopeCheckImport ::
TopLevelModuleName -> ModuleName ->
TCM (ModuleName, Map ModuleName Scope)
scopeCheckImport :: TopLevelModuleName
-> ModuleName -> TCM (ModuleName, Map ModuleName Scope)
scopeCheckImport TopLevelModuleName
top ModuleName
x = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.scope" Int
5 forall a b. (a -> b) -> a -> b
$ [Char]
"Scope checking " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow ModuleName
x
forall (m :: * -> *). MonadDebug m => [Char] -> Int -> m () -> m ()
verboseS [Char]
"import.scope" Int
10 forall a b. (a -> b) -> a -> b
$ do
[Char]
visited <- forall a. Pretty a => a -> [Char]
prettyShow forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). ReadTCState m => m Doc
getPrettyVisitedModules
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.scope" Int
10 forall a b. (a -> b) -> a -> b
$ [Char]
" visited: " forall a. [a] -> [a] -> [a]
++ [Char]
visited
Interface
i <- forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [] forall a b. (a -> b) -> a -> b
$ TopLevelModuleName -> Maybe Source -> TCMT IO Interface
getNonMainInterface TopLevelModuleName
top forall a. Maybe a
Nothing
TopLevelModuleName -> TCM ()
addImport TopLevelModuleName
top
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust (Interface -> Maybe Text
iImportWarning Interface
i) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
(HasCallStack, MonadWarning m) =>
Warning -> m ()
warning forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Warning
UserWarning
let s :: Map ModuleName Scope
s = Interface -> Map ModuleName Scope
iScope Interface
i
forall (m :: * -> *) a. Monad m => a -> m a
return (Interface -> ModuleName
iModuleName Interface
i ModuleName -> QName -> ModuleName
`withRangesOfQ` ModuleName -> QName
mnameToConcrete ModuleName
x, Map ModuleName Scope
s)
alreadyVisited :: TopLevelModuleName ->
MainInterface ->
PragmaOptions ->
TCM ModuleInfo ->
TCM ModuleInfo
alreadyVisited :: TopLevelModuleName
-> MainInterface
-> PragmaOptions
-> TCM ModuleInfo
-> TCM ModuleInfo
alreadyVisited TopLevelModuleName
x MainInterface
isMain PragmaOptions
currentOptions TCM ModuleInfo
getModule =
case MainInterface
isMain of
MainInterface Mode
TypeCheck -> ModuleCheckMode -> TCM ModuleInfo
useExistingOrLoadAndRecordVisited ModuleCheckMode
ModuleTypeChecked
MainInterface
NotMainInterface -> ModuleCheckMode -> TCM ModuleInfo
useExistingOrLoadAndRecordVisited ModuleCheckMode
ModuleTypeChecked
MainInterface Mode
ScopeCheck -> ModuleCheckMode -> TCM ModuleInfo
useExistingOrLoadAndRecordVisited ModuleCheckMode
ModuleScopeChecked
where
useExistingOrLoadAndRecordVisited :: ModuleCheckMode -> TCM ModuleInfo
useExistingOrLoadAndRecordVisited :: ModuleCheckMode -> TCM ModuleInfo
useExistingOrLoadAndRecordVisited ModuleCheckMode
mode = forall (m :: * -> *) a. Monad m => m a -> m (Maybe a) -> m a
fromMaybeM TCM ModuleInfo
loadAndRecordVisited (ModuleCheckMode -> TCM (Maybe ModuleInfo)
existingWithoutWarnings ModuleCheckMode
mode)
existingWithoutWarnings :: ModuleCheckMode -> TCM (Maybe ModuleInfo)
existingWithoutWarnings :: ModuleCheckMode -> TCM (Maybe ModuleInfo)
existingWithoutWarnings ModuleCheckMode
mode = forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a. Functor m => ExceptT e m a -> MaybeT m a
exceptToMaybeT forall a b. (a -> b) -> a -> b
$ do
ModuleInfo
mi <- forall (m :: * -> *) e a.
Functor m =>
e -> MaybeT m a -> ExceptT e m a
maybeToExceptT [Char]
"interface has not been visited in this context" forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
ReadTCState m =>
TopLevelModuleName -> m (Maybe ModuleInfo)
getVisitedModule TopLevelModuleName
x
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (ModuleInfo -> ModuleCheckMode
miMode ModuleInfo
mi forall a. Ord a => a -> a -> Bool
< ModuleCheckMode
mode) forall a b. (a -> b) -> a -> b
$
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError [Char]
"previously-visited interface was not sufficiently checked"
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall a. Null a => a -> Bool
null forall a b. (a -> b) -> a -> b
$ ModuleInfo -> [TCWarning]
miWarnings ModuleInfo
mi) forall a b. (a -> b) -> a -> b
$
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError [Char]
"previously-visited interface had warnings"
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.visit" Int
10 forall a b. (a -> b) -> a -> b
$ [Char]
" Already visited " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ ModuleInfo -> TCM ModuleInfo
processResultingModule ModuleInfo
mi
processResultingModule :: ModuleInfo -> TCM ModuleInfo
processResultingModule :: ModuleInfo -> TCM ModuleInfo
processResultingModule ModuleInfo
mi = do
let ModuleInfo { miInterface :: ModuleInfo -> Interface
miInterface = Interface
i, miPrimitive :: ModuleInfo -> Bool
miPrimitive = Bool
isPrim, miWarnings :: ModuleInfo -> [TCWarning]
miWarnings = [TCWarning]
ws } = ModuleInfo
mi
[TCWarning]
wt <- forall a. a -> Maybe a -> a
fromMaybe [TCWarning]
ws forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (MainInterface
-> Bool -> PragmaOptions -> Interface -> TCM (Maybe [TCWarning])
getOptionsCompatibilityWarnings MainInterface
isMain Bool
isPrim PragmaOptions
currentOptions Interface
i)
forall (m :: * -> *) a. Monad m => a -> m a
return ModuleInfo
mi { miWarnings :: [TCWarning]
miWarnings = [TCWarning]
wt }
loadAndRecordVisited :: TCM ModuleInfo
loadAndRecordVisited :: TCM ModuleInfo
loadAndRecordVisited = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.visit" Int
5 forall a b. (a -> b) -> a -> b
$ [Char]
" Getting interface for " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
x
ModuleInfo
mi <- ModuleInfo -> TCM ModuleInfo
processResultingModule forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCM ModuleInfo
getModule
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.visit" Int
5 forall a b. (a -> b) -> a -> b
$ [Char]
" Now we've looked at " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
x
case (MainInterface
isMain, ModuleInfo -> [TCWarning]
miWarnings ModuleInfo
mi) of
(MainInterface Mode
ScopeCheck, [TCWarning]
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
(MainInterface
_, TCWarning
_:[TCWarning]
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
(MainInterface, [TCWarning])
_ -> ModuleInfo -> TCM ()
storeDecodedModule ModuleInfo
mi
forall a (m :: * -> *).
(ReportS a, MonadDebug m) =>
[Char] -> Int -> a -> m ()
reportS [Char]
"warning.import" Int
10
[ [Char]
"module: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (TopLevelModuleName -> TopLevelModuleNameParts
moduleNameParts TopLevelModuleName
x)
, [Char]
"WarningOnImport: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (Interface -> Maybe Text
iImportWarning (ModuleInfo -> Interface
miInterface ModuleInfo
mi))
]
ModuleInfo -> TCM ()
visitModule ModuleInfo
mi
forall (m :: * -> *) a. Monad m => a -> m a
return ModuleInfo
mi
data CheckResult = CheckResult'
{ CheckResult -> ModuleInfo
crModuleInfo :: ModuleInfo
, CheckResult -> Source
crSource' :: Source
}
pattern CheckResult :: Interface -> [TCWarning] -> ModuleCheckMode -> Source -> CheckResult
pattern $mCheckResult :: forall {r}.
CheckResult
-> (Interface -> [TCWarning] -> ModuleCheckMode -> Source -> r)
-> ((# #) -> r)
-> r
CheckResult { CheckResult -> Interface
crInterface, CheckResult -> [TCWarning]
crWarnings, CheckResult -> ModuleCheckMode
crMode, CheckResult -> Source
crSource } <- CheckResult'
{ crModuleInfo = ModuleInfo
{ miInterface = crInterface
, miWarnings = crWarnings
, miMode = crMode
}
, crSource' = crSource
}
typeCheckMain
:: Mode
-> Source
-> TCM CheckResult
typeCheckMain :: Mode -> Source -> TCM CheckResult
typeCheckMain Mode
mode Source
src = do
Source -> TCM ()
setOptionsFromSourcePragmas Source
src
Bool
loadPrims <- PragmaOptions -> Bool
optLoadPrimitives forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
loadPrims forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.main" Int
10 [Char]
"Importing the primitive modules."
[Char]
libdirPrim <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO [Char]
getPrimitiveLibDir
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.main" Int
20 forall a b. (a -> b) -> a -> b
$ [Char]
"Library primitive dir = " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show [Char]
libdirPrim
forall (m :: * -> *) a b.
Monad m =>
m a -> (a -> m ()) -> m b -> m b
bracket_ (forall (m :: * -> *) a. ReadTCState m => (TCState -> a) -> m a
getsTC forall a. LensPersistentVerbosity a => a -> PersistentVerbosity
Lens.getPersistentVerbosity) forall (m :: * -> *). MonadTCState m => PersistentVerbosity -> m ()
Lens.putPersistentVerbosity forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadTCState m =>
(PersistentVerbosity -> PersistentVerbosity) -> m ()
Lens.modifyPersistentVerbosity
(forall a. a -> Maybe a
Strict.Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v. Ord k => [k] -> v -> Trie k v -> Trie k v
Trie.insert [] Int
0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a -> a
Strict.fromMaybe forall a. Null a => a
Trie.empty)
forall a. HighlightingLevel -> TCM a -> TCM a
withHighlightingLevel HighlightingLevel
None forall a b. (a -> b) -> a -> b
$
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map ([Char]
libdirPrim [Char] -> ShowS
</>) Set [Char]
Lens.primitiveModules) forall a b. (a -> b) -> a -> b
$ \[Char]
f -> do
Source
primSource <- SourceFile -> TCM Source
parseSource (AbsolutePath -> SourceFile
SourceFile forall a b. (a -> b) -> a -> b
$ [Char] -> AbsolutePath
mkAbsolute [Char]
f)
TopLevelModuleName -> SourceFile -> TCM ()
checkModuleName' (Source -> TopLevelModuleName
srcModuleName Source
primSource) (Source -> SourceFile
srcOrigin Source
primSource)
forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ TopLevelModuleName -> Maybe Source -> TCMT IO Interface
getNonMainInterface (Source -> TopLevelModuleName
srcModuleName Source
primSource) (forall a. a -> Maybe a
Just Source
primSource)
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.main" Int
10 forall a b. (a -> b) -> a -> b
$ [Char]
"Done importing the primitive modules."
TopLevelModuleName -> SourceFile -> TCM ()
checkModuleName' (Source -> TopLevelModuleName
srcModuleName Source
src) (Source -> SourceFile
srcOrigin Source
src)
ModuleInfo
mi <- TopLevelModuleName
-> MainInterface -> Maybe Source -> TCM ModuleInfo
getInterface (Source -> TopLevelModuleName
srcModuleName Source
src) (Mode -> MainInterface
MainInterface Mode
mode) (forall a. a -> Maybe a
Just Source
src)
Lens' (Maybe (ModuleName, TopLevelModuleName)) TCState
stCurrentModule forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> a -> m ()
`setTCLens'`
forall a. a -> Maybe a
Just ( Interface -> ModuleName
iModuleName (ModuleInfo -> Interface
miInterface ModuleInfo
mi)
, Interface -> TopLevelModuleName
iTopLevelModuleName (ModuleInfo -> Interface
miInterface ModuleInfo
mi)
)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ModuleInfo -> Source -> CheckResult
CheckResult' ModuleInfo
mi Source
src
where
checkModuleName' :: TopLevelModuleName -> SourceFile -> TCM ()
checkModuleName' TopLevelModuleName
m SourceFile
f =
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange TopLevelModuleName
m forall a b. (a -> b) -> a -> b
$ TopLevelModuleName
-> SourceFile -> Maybe TopLevelModuleName -> TCM ()
checkModuleName TopLevelModuleName
m SourceFile
f forall a. Maybe a
Nothing
getNonMainInterface
:: TopLevelModuleName
-> Maybe Source
-> TCM Interface
getNonMainInterface :: TopLevelModuleName -> Maybe Source -> TCMT IO Interface
getNonMainInterface TopLevelModuleName
x Maybe Source
msrc = do
ModuleInfo
mi <- forall (m :: * -> *) a b.
Monad m =>
m a -> (a -> m ()) -> m b -> m b
bracket_ (forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' PragmaOptions TCState
stPragmaOptions) (Lens' PragmaOptions TCState
stPragmaOptions forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> a -> m ()
`setTCLens`) forall a b. (a -> b) -> a -> b
$
TopLevelModuleName
-> MainInterface -> Maybe Source -> TCM ModuleInfo
getInterface TopLevelModuleName
x MainInterface
NotMainInterface Maybe Source
msrc
[TCWarning] -> TCM ()
tcWarningsToError forall a b. (a -> b) -> a -> b
$ ModuleInfo -> [TCWarning]
miWarnings ModuleInfo
mi
forall (m :: * -> *) a. Monad m => a -> m a
return (ModuleInfo -> Interface
miInterface ModuleInfo
mi)
getInterface
:: TopLevelModuleName
-> MainInterface
-> Maybe Source
-> TCM ModuleInfo
getInterface :: TopLevelModuleName
-> MainInterface -> Maybe Source -> TCM ModuleInfo
getInterface TopLevelModuleName
x MainInterface
isMain Maybe Source
msrc =
forall a. TopLevelModuleName -> TCM a -> TCM a
addImportCycleCheck TopLevelModuleName
x forall a b. (a -> b) -> a -> b
$ do
PragmaOptions
currentOptions <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' PragmaOptions TCState
stPragmaOptions
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange (Module -> [Pragma]
C.modPragmas forall b c a. (b -> c) -> (a -> b) -> a -> c
. Source -> Module
srcModule forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Source
msrc) forall a b. (a -> b) -> a -> b
$
CommandLineOptions -> TCM ()
setCommandLineOptions forall b c a. (b -> c) -> (a -> b) -> a -> c
. PersistentTCState -> CommandLineOptions
stPersistentOptions forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCState -> PersistentTCState
stPersistentState forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). MonadTCState m => m TCState
getTC
TopLevelModuleName
-> MainInterface
-> PragmaOptions
-> TCM ModuleInfo
-> TCM ModuleInfo
alreadyVisited TopLevelModuleName
x MainInterface
isMain PragmaOptions
currentOptions forall a b. (a -> b) -> a -> b
$ do
SourceFile
file <- case Maybe Source
msrc of
Maybe Source
Nothing -> TopLevelModuleName -> TCMT IO SourceFile
findFile TopLevelModuleName
x
Just Source
src -> do
let file :: SourceFile
file = Source -> SourceFile
srcOrigin Source
src
forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
modifyTCLens Lens' ModuleToSource TCState
stModuleToSource forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert TopLevelModuleName
x (SourceFile -> AbsolutePath
srcFilePath SourceFile
file)
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceFile
file
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
15 forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [[a]] -> [a]
List.intercalate [Char]
"\n" forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map ([Char]
" " forall a. [a] -> [a] -> [a]
++)
[ [Char]
"module: " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
x
, [Char]
"file: " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow SourceFile
file
]
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
10 forall a b. (a -> b) -> a -> b
$ [Char]
" Check for cycle"
TCM ()
checkForImportCycle
Either [Char] ModuleInfo
stored <- forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Import] forall a b. (a -> b) -> a -> b
$ do
TopLevelModuleName
-> SourceFile
-> Maybe Source
-> ExceptT [Char] (TCMT IO) ModuleInfo
getStoredInterface TopLevelModuleName
x SourceFile
file Maybe Source
msrc
let recheck :: [Char] -> TCM ModuleInfo
recheck = \[Char]
reason -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
5 forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Char]
" ", forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
x, [Char]
" is not up-to-date because ", [Char]
reason, [Char]
"."]
CommandLineOptions -> TCM ()
setCommandLineOptions forall b c a. (b -> c) -> (a -> b) -> a -> c
. PersistentTCState -> CommandLineOptions
stPersistentOptions forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCState -> PersistentTCState
stPersistentState forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). MonadTCState m => m TCState
getTC
case MainInterface
isMain of
MainInterface Mode
_ -> TopLevelModuleName
-> SourceFile -> MainInterface -> Maybe Source -> TCM ModuleInfo
createInterface TopLevelModuleName
x SourceFile
file MainInterface
isMain Maybe Source
msrc
MainInterface
NotMainInterface -> TopLevelModuleName -> SourceFile -> Maybe Source -> TCM ModuleInfo
createInterfaceIsolated TopLevelModuleName
x SourceFile
file Maybe Source
msrc
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [Char] -> TCM ModuleInfo
recheck forall (f :: * -> *) a. Applicative f => a -> f a
pure Either [Char] ModuleInfo
stored
checkOptionsCompatible ::
PragmaOptions -> PragmaOptions -> TopLevelModuleName -> TCM Bool
checkOptionsCompatible :: PragmaOptions
-> PragmaOptions -> TopLevelModuleName -> TCMT IO Bool
checkOptionsCompatible PragmaOptions
current PragmaOptions
imported TopLevelModuleName
importedModule = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m s
execStateT Bool
True forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"import.iface.options" Int
5 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
P.nest Int
2 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"current options =" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
P.<+> forall {m :: * -> *}.
(Applicative m, Semigroup (m Doc), IsString (m Doc)) =>
PragmaOptions -> m Doc
showOptions PragmaOptions
current
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"import.iface.options" Int
5 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
P.nest Int
2 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"imported options =" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
P.<+> forall {m :: * -> *}.
(Applicative m, Semigroup (m Doc), IsString (m Doc)) =>
PragmaOptions -> m Doc
showOptions PragmaOptions
imported
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [InfectiveCoinfectiveOption]
infectiveCoinfectiveOptions forall a b. (a -> b) -> a -> b
$ \InfectiveCoinfectiveOption
opt -> do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (InfectiveCoinfectiveOption
-> PragmaOptions -> PragmaOptions -> Bool
icOptionOK InfectiveCoinfectiveOption
opt PragmaOptions
current PragmaOptions
imported) forall a b. (a -> b) -> a -> b
$ do
forall s (m :: * -> *). MonadState s m => s -> m ()
put Bool
False
forall (m :: * -> *).
(HasCallStack, MonadWarning m) =>
Warning -> m ()
warning forall a b. (a -> b) -> a -> b
$
(case InfectiveCoinfectiveOption -> InfectiveCoinfective
icOptionKind InfectiveCoinfectiveOption
opt of
InfectiveCoinfective
Infective -> Doc -> Warning
InfectiveImport
InfectiveCoinfective
Coinfective -> Doc -> Warning
CoInfectiveImport)
(InfectiveCoinfectiveOption -> TopLevelModuleName -> Doc
icOptionWarning InfectiveCoinfectiveOption
opt TopLevelModuleName
importedModule)
where
showOptions :: PragmaOptions -> m Doc
showOptions PragmaOptions
opts =
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Semigroup (m Doc), Foldable t) =>
t (m Doc) -> m Doc
P.prettyList forall a b. (a -> b) -> a -> b
$
forall a b. (a -> b) -> [a] -> [b]
map (\InfectiveCoinfectiveOption
opt -> (forall (m :: * -> *). Applicative m => [Char] -> m Doc
P.text (InfectiveCoinfectiveOption -> [Char]
icOptionDescription InfectiveCoinfectiveOption
opt) forall a. Semigroup a => a -> a -> a
<> m Doc
": ") forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
P.<+>
forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
P.pretty (InfectiveCoinfectiveOption -> PragmaOptions -> Bool
icOptionActive InfectiveCoinfectiveOption
opt PragmaOptions
opts))
[InfectiveCoinfectiveOption]
infectiveCoinfectiveOptions
getOptionsCompatibilityWarnings :: MainInterface -> Bool -> PragmaOptions -> Interface -> TCM (Maybe [TCWarning])
getOptionsCompatibilityWarnings :: MainInterface
-> Bool -> PragmaOptions -> Interface -> TCM (Maybe [TCWarning])
getOptionsCompatibilityWarnings MainInterface
isMain Bool
isPrim PragmaOptions
currentOptions Interface
i = forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a. Functor m => ExceptT e m a -> MaybeT m a
exceptToMaybeT forall a b. (a -> b) -> a -> b
$ do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isPrim forall a b. (a -> b) -> a -> b
$
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError [Char]
"Options consistency checking disabled for always-available primitive module"
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ PragmaOptions
-> PragmaOptions -> TopLevelModuleName -> TCMT IO Bool
checkOptionsCompatible PragmaOptions
currentOptions (Interface -> PragmaOptions
iOptionsUsed Interface
i)
(Interface -> TopLevelModuleName
iTopLevelModuleName Interface
i)) forall a b. (a -> b) -> a -> b
$
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError [Char]
"No warnings to collect because options were compatible"
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadWarning m) =>
MainInterface -> WhichWarnings -> m [TCWarning]
getAllWarnings' MainInterface
isMain WhichWarnings
ErrorWarnings
getStoredInterface
:: TopLevelModuleName
-> SourceFile
-> Maybe Source
-> ExceptT String TCM ModuleInfo
getStoredInterface :: TopLevelModuleName
-> SourceFile
-> Maybe Source
-> ExceptT [Char] (TCMT IO) ModuleInfo
getStoredInterface TopLevelModuleName
x SourceFile
file Maybe Source
msrc = do
let getIFileHashesET :: ExceptT [Char] (TCMT IO) (InterfaceFile, (Hash, Hash))
getIFileHashesET = do
InterfaceFile
ifile <- forall (m :: * -> *) e a.
Functor m =>
e -> MaybeT m a -> ExceptT e m a
maybeToExceptT [Char]
"the interface file could not be found" forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT forall a b. (a -> b) -> a -> b
$
SourceFile -> TCM (Maybe InterfaceFile)
findInterfaceFile' SourceFile
file
(Hash, Hash)
hashes <- forall (m :: * -> *) e a.
Functor m =>
e -> MaybeT m a -> ExceptT e m a
maybeToExceptT [Char]
"the interface file hash could not be read" forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
InterfaceFile -> IO (Maybe (Hash, Hash))
getInterfaceFileHashes InterfaceFile
ifile
forall (m :: * -> *) a. Monad m => a -> m a
return (InterfaceFile
ifile, (Hash, Hash)
hashes)
let checkSourceHashET :: Hash -> ExceptT [Char] (TCMT IO) ()
checkSourceHashET Hash
ifaceH = do
Hash
sourceH <- case Maybe Source
msrc of
Maybe Source
Nothing -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ AbsolutePath -> IO Hash
hashTextFile (SourceFile -> AbsolutePath
srcFilePath SourceFile
file)
Just Source
src -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Hash
hashText (Source -> Text
srcText Source
src)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Hash
sourceH forall a. Eq a => a -> a -> Bool
== Hash
ifaceH) forall a b. (a -> b) -> a -> b
$
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ [Char]
"the source hash (", forall a. Show a => a -> [Char]
show Hash
sourceH, [Char]
")"
, [Char]
" does not match the source hash for the interface (", forall a. Show a => a -> [Char]
show Hash
ifaceH, [Char]
")"
]
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
5 forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Char]
" ", forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
x, [Char]
" is up-to-date."]
Either [Char] ModuleInfo
cachedE <- forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a.
Functor m =>
e -> MaybeT m a -> ExceptT e m a
maybeToExceptT [Char]
"the interface has not been decoded" forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT forall a b. (a -> b) -> a -> b
$
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ TopLevelModuleName -> TCM (Maybe ModuleInfo)
getDecodedModule TopLevelModuleName
x
case Either [Char] ModuleInfo
cachedE of
Right ModuleInfo
mi -> do
(InterfaceFile
ifile, (Hash, Hash)
hashes) <- ExceptT [Char] (TCMT IO) (InterfaceFile, (Hash, Hash))
getIFileHashesET
let ifp :: [Char]
ifp = AbsolutePath -> [Char]
filePath forall a b. (a -> b) -> a -> b
$ InterfaceFile -> AbsolutePath
intFilePath InterfaceFile
ifile
let i :: Interface
i = ModuleInfo -> Interface
miInterface ModuleInfo
mi
let cachedIfaceHash :: Hash
cachedIfaceHash = Interface -> Hash
iFullHash Interface
i
let fileIfaceHash :: Hash
fileIfaceHash = forall a b. (a, b) -> b
snd (Hash, Hash)
hashes
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Hash
cachedIfaceHash forall a. Eq a => a -> a -> Bool
== Hash
fileIfaceHash) forall a b. (a -> b) -> a -> b
$ do
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ TopLevelModuleName -> TCM ()
dropDecodedModule TopLevelModuleName
x
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
50 forall a b. (a -> b) -> a -> b
$ [Char]
" cached hash = " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Hash
cachedIfaceHash
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
50 forall a b. (a -> b) -> a -> b
$ [Char]
" stored hash = " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Hash
fileIfaceHash
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
5 forall a b. (a -> b) -> a -> b
$ [Char]
" file is newer, re-reading " forall a. [a] -> [a] -> [a]
++ [Char]
ifp
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ [Char]
"the cached interface hash (", forall a. Show a => a -> [Char]
show Hash
cachedIfaceHash, [Char]
")"
, [Char]
" does not match interface file (", forall a. Show a => a -> [Char]
show Hash
fileIfaceHash, [Char]
")"
]
forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Deserialization] forall a b. (a -> b) -> a -> b
$ do
Hash -> ExceptT [Char] (TCMT IO) ()
checkSourceHashET (Interface -> Hash
iSourceHash Interface
i)
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
5 forall a b. (a -> b) -> a -> b
$ [Char]
" using stored version of " forall a. [a] -> [a] -> [a]
++ (AbsolutePath -> [Char]
filePath forall a b. (a -> b) -> a -> b
$ InterfaceFile -> AbsolutePath
intFilePath InterfaceFile
ifile)
SourceFile -> ModuleInfo -> ExceptT [Char] (TCMT IO) ModuleInfo
loadDecodedModule SourceFile
file ModuleInfo
mi
Left [Char]
whyNotCached -> forall (m :: * -> *) e e' a.
Functor m =>
(e -> e') -> ExceptT e m a -> ExceptT e' m a
withExceptT (\[Char]
e -> forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Char]
whyNotCached, [Char]
" and ", [Char]
e]) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM forall (m :: * -> *). HasOptions m => m Bool
ignoreAllInterfaces forall a b. (a -> b) -> a -> b
$
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError [Char]
"we're ignoring all interface files"
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM forall (m :: * -> *). HasOptions m => m Bool
ignoreInterfaces forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
unlessM (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Char] -> m Bool
Lens.isBuiltinModule (AbsolutePath -> [Char]
filePath forall a b. (a -> b) -> a -> b
$ SourceFile -> AbsolutePath
srcFilePath SourceFile
file)) forall a b. (a -> b) -> a -> b
$
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError [Char]
"we're ignoring non-builtin interface files"
(InterfaceFile
ifile, (Hash, Hash)
hashes) <- ExceptT [Char] (TCMT IO) (InterfaceFile, (Hash, Hash))
getIFileHashesET
let ifp :: [Char]
ifp = (AbsolutePath -> [Char]
filePath forall b c a. (b -> c) -> (a -> b) -> a -> c
. InterfaceFile -> AbsolutePath
intFilePath forall a b. (a -> b) -> a -> b
$ InterfaceFile
ifile)
forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Deserialization] forall a b. (a -> b) -> a -> b
$ do
Hash -> ExceptT [Char] (TCMT IO) ()
checkSourceHashET (forall a b. (a, b) -> a
fst (Hash, Hash)
hashes)
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
5 forall a b. (a -> b) -> a -> b
$ [Char]
" no stored version, reading " forall a. [a] -> [a] -> [a]
++ [Char]
ifp
Interface
i <- forall (m :: * -> *) e a.
Functor m =>
e -> MaybeT m a -> ExceptT e m a
maybeToExceptT [Char]
"bad interface, re-type checking" forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT forall a b. (a -> b) -> a -> b
$
InterfaceFile -> TCM (Maybe Interface)
readInterface InterfaceFile
ifile
let topLevelName :: TopLevelModuleName
topLevelName = Interface -> TopLevelModuleName
iTopLevelModuleName Interface
i
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (TopLevelModuleName
topLevelName forall a. Eq a => a -> a -> Bool
== TopLevelModuleName
x) forall a b. (a -> b) -> a -> b
$
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError forall a b. (a -> b) -> a -> b
$ AbsolutePath
-> TopLevelModuleName -> TopLevelModuleName -> TypeError
OverlappingProjects (SourceFile -> AbsolutePath
srcFilePath SourceFile
file) TopLevelModuleName
topLevelName TopLevelModuleName
x
Bool
isPrimitiveModule <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Char] -> m Bool
Lens.isPrimitiveModule (AbsolutePath -> [Char]
filePath forall a b. (a -> b) -> a -> b
$ SourceFile -> AbsolutePath
srcFilePath SourceFile
file)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ [Char] -> TopLevelModuleName -> Maybe [Char] -> TCM ()
chaseMsg [Char]
"Loading " TopLevelModuleName
x forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just [Char]
ifp
let ws :: [TCWarning]
ws = forall a. (a -> Bool) -> [a] -> [a]
filter ((forall a. a -> Maybe a
Strict.Just (forall a. a -> Maybe a
Just TopLevelModuleName
x) forall a. Eq a => a -> a -> Bool
==) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RangeFile -> Maybe TopLevelModuleName
rangeFileName forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCWarning -> SrcFile
tcWarningOrigin) forall a b. (a -> b) -> a -> b
$
Interface -> [TCWarning]
iWarnings Interface
i
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall a. Null a => a -> Bool
null [TCWarning]
ws) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"warning" Int
1 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
P.vcat forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
P.prettyTCM forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TCWarning]
ws
SourceFile -> ModuleInfo -> ExceptT [Char] (TCMT IO) ModuleInfo
loadDecodedModule SourceFile
file forall a b. (a -> b) -> a -> b
$ ModuleInfo
{ miInterface :: Interface
miInterface = Interface
i
, miWarnings :: [TCWarning]
miWarnings = []
, miPrimitive :: Bool
miPrimitive = Bool
isPrimitiveModule
, miMode :: ModuleCheckMode
miMode = ModuleCheckMode
ModuleTypeChecked
}
loadDecodedModule
:: SourceFile
-> ModuleInfo
-> ExceptT String TCM ModuleInfo
loadDecodedModule :: SourceFile -> ModuleInfo -> ExceptT [Char] (TCMT IO) ModuleInfo
loadDecodedModule SourceFile
file ModuleInfo
mi = do
let fp :: [Char]
fp = AbsolutePath -> [Char]
filePath forall a b. (a -> b) -> a -> b
$ SourceFile -> AbsolutePath
srcFilePath SourceFile
file
let i :: Interface
i = ModuleInfo -> Interface
miInterface ModuleInfo
mi
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
5 forall a b. (a -> b) -> a -> b
$ [Char]
" imports: " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow (Interface -> [(TopLevelModuleName, Hash)]
iImportedModules Interface
i)
[[[Char]]]
libOptions <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ AbsolutePath -> TopLevelModuleName -> TCM [[[Char]]]
getLibraryOptions
(SourceFile -> AbsolutePath
srcFilePath SourceFile
file)
(Interface -> TopLevelModuleName
iTopLevelModuleName Interface
i)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ [[Char]] -> TCM ()
setOptionsFromPragma ([[[Char]]]
libOptions forall a. [a] -> [a] -> [a]
++ Interface -> [[[Char]]]
iFilePragmaOptions Interface
i)
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
unlessM (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Char] -> m Bool
Lens.isBuiltinModule [Char]
fp) forall a b. (a -> b) -> a -> b
$ do
PragmaOptions
current <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' PragmaOptions TCState
stPragmaOptions
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (PragmaOptions -> PragmaOptions -> Bool
recheckBecausePragmaOptionsChanged (Interface -> PragmaOptions
iOptionsUsed Interface
i) PragmaOptions
current) forall a b. (a -> b) -> a -> b
$
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError [Char]
"options changed"
[[Char]]
badHashMessages <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. [Either a b] -> [a]
lefts forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM (Interface -> [(TopLevelModuleName, Hash)]
iImportedModules Interface
i) forall a b. (a -> b) -> a -> b
$ \(TopLevelModuleName
impName, Hash
impHash) -> forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
30 forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Char]
"Checking that module hash of import ", forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
impName, [Char]
" matches ", forall a. Pretty a => a -> [Char]
prettyShow Hash
impHash ]
Hash
latestImpHash <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange TopLevelModuleName
impName forall a b. (a -> b) -> a -> b
$ TopLevelModuleName -> TCMT IO Hash
moduleHash TopLevelModuleName
impName
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
30 forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Char]
"Done checking module hash of import ", forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
impName]
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Hash
impHash forall a. Eq a => a -> a -> Bool
/= Hash
latestImpHash) forall a b. (a -> b) -> a -> b
$
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ [Char]
"module hash for imported module ", forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
impName, [Char]
" is out of date"
, [Char]
" (import cached=", forall a. Pretty a => a -> [Char]
prettyShow Hash
impHash, [Char]
", latest=", forall a. Pretty a => a -> [Char]
prettyShow Hash
latestImpHash, [Char]
")"
]
forall (m :: * -> *) a.
(Monad m, Null a) =>
a -> (a -> m ()) -> m ()
unlessNull [[Char]]
badHashMessages (forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> [Char]
unlines)
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
5 [Char]
" New module. Let's check it out."
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ Interface -> TCM ()
mergeInterface Interface
i
forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Highlighting] forall a b. (a -> b) -> a -> b
$
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (tcm :: * -> *).
MonadTCEnv tcm =>
HighlightingLevel -> tcm () -> tcm ()
ifTopLevelAndHighlightingLevelIs HighlightingLevel
NonInteractive forall a b. (a -> b) -> a -> b
$
Interface -> SourceFile -> TCM ()
highlightFromInterface Interface
i SourceFile
file
forall (m :: * -> *) a. Monad m => a -> m a
return ModuleInfo
mi
createInterfaceIsolated
:: TopLevelModuleName
-> SourceFile
-> Maybe Source
-> TCM ModuleInfo
createInterfaceIsolated :: TopLevelModuleName -> SourceFile -> Maybe Source -> TCM ModuleInfo
createInterfaceIsolated TopLevelModuleName
x SourceFile
file Maybe Source
msrc = do
forall (m :: * -> *). (MonadDebug m, MonadTCState m) => m ()
cleanCachedLog
[TopLevelModuleName]
ms <- TCM [TopLevelModuleName]
getImportPath
Range
range <- forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> Range
envRange
Maybe (Closure Call)
call <- forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> Maybe (Closure Call)
envCall
ModuleToSource
mf <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' ModuleToSource TCState
stModuleToSource
VisitedModules
vs <- forall (m :: * -> *). ReadTCState m => m VisitedModules
getVisitedModules
VisitedModules
ds <- TCM VisitedModules
getDecodedModules
CommandLineOptions
opts <- PersistentTCState -> CommandLineOptions
stPersistentOptions forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCState -> PersistentTCState
stPersistentState forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). MonadTCState m => m TCState
getTC
Signature
isig <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' Signature TCState
stImports
RemoteMetaStore
metas <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' RemoteMetaStore TCState
stImportedMetaStore
Map [Char] (Builtin PrimFun)
ibuiltin <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Map [Char] (Builtin PrimFun)) TCState
stImportedBuiltins
DisplayForms
display <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' DisplayForms TCState
stImportsDisplayForms
Map QName Text
userwarn <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Map QName Text) TCState
stImportedUserWarnings
Set QName
partialdefs <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Set QName) TCState
stImportedPartialDefs
PatternSynDefns
ipatsyns <- forall (m :: * -> *). ReadTCState m => m PatternSynDefns
getPatternSynImports
InteractionOutputCallback
ho <- forall (m :: * -> *). ReadTCState m => m InteractionOutputCallback
getInteractionOutputCallback
(ModuleInfo
mi, ModuleToSource
newModToSource, VisitedModules
newDecodedModules) <- (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a.
(MonadTCState m, ReadTCState m) =>
m a -> m a
withoutCache forall a b. (a -> b) -> a -> b
$
forall a. TCM a -> TCM (Either TCErr a)
freshTCM forall a b. (a -> b) -> a -> b
$
forall a. [TopLevelModuleName] -> TCM a -> TCM a
withImportPath [TopLevelModuleName]
ms forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a.
MonadTCEnv m =>
(TCEnv -> TCEnv) -> m a -> m a
localTC (\TCEnv
e -> TCEnv
e
{ envRange :: Range
envRange = Range
range
, envCall :: Maybe (Closure Call)
envCall = Maybe (Closure Call)
call
}) forall a b. (a -> b) -> a -> b
$ do
VisitedModules -> TCM ()
setDecodedModules VisitedModules
ds
CommandLineOptions -> TCM ()
setCommandLineOptions CommandLineOptions
opts
InteractionOutputCallback -> TCM ()
setInteractionOutputCallback InteractionOutputCallback
ho
Lens' ModuleToSource TCState
stModuleToSource forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> a -> m ()
`setTCLens` ModuleToSource
mf
VisitedModules -> TCM ()
setVisitedModules VisitedModules
vs
Signature
-> RemoteMetaStore
-> Map [Char] (Builtin PrimFun)
-> PatternSynDefns
-> DisplayForms
-> Map QName Text
-> Set QName
-> [TCWarning]
-> TCM ()
addImportedThings Signature
isig RemoteMetaStore
metas Map [Char] (Builtin PrimFun)
ibuiltin PatternSynDefns
ipatsyns DisplayForms
display
Map QName Text
userwarn Set QName
partialdefs []
ModuleInfo
r <- TopLevelModuleName
-> SourceFile -> MainInterface -> Maybe Source -> TCM ModuleInfo
createInterface TopLevelModuleName
x SourceFile
file MainInterface
NotMainInterface Maybe Source
msrc
ModuleToSource
mf' <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' ModuleToSource TCState
stModuleToSource
VisitedModules
ds' <- TCM VisitedModules
getDecodedModules
forall (m :: * -> *) a. Monad m => a -> m a
return (ModuleInfo
r, ModuleToSource
mf', VisitedModules
ds')
Lens' ModuleToSource TCState
stModuleToSource forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> a -> m ()
`setTCLens` ModuleToSource
newModToSource
VisitedModules -> TCM ()
setDecodedModules VisitedModules
newDecodedModules
Either [Char] ModuleInfo
validated <- forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT forall a b. (a -> b) -> a -> b
$ SourceFile -> ModuleInfo -> ExceptT [Char] (TCMT IO) ModuleInfo
loadDecodedModule SourceFile
file ModuleInfo
mi
let recheckOnError :: [Char] -> TCM ModuleInfo
recheckOnError = \[Char]
msg -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
1 forall a b. (a -> b) -> a -> b
$ [Char]
"Failed to validate just-loaded interface: " forall a. [a] -> [a] -> [a]
++ [Char]
msg
TopLevelModuleName -> SourceFile -> Maybe Source -> TCM ModuleInfo
createInterfaceIsolated TopLevelModuleName
x SourceFile
file Maybe Source
msrc
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [Char] -> TCM ModuleInfo
recheckOnError forall (f :: * -> *) a. Applicative f => a -> f a
pure Either [Char] ModuleInfo
validated
chaseMsg
:: String
-> TopLevelModuleName
-> Maybe String
-> TCM ()
chaseMsg :: [Char] -> TopLevelModuleName -> Maybe [Char] -> TCM ()
chaseMsg [Char]
kind TopLevelModuleName
x Maybe [Char]
file = do
[Char]
indentation <- (forall a. Int -> a -> [a]
`replicate` Char
' ') forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC (forall a. Enum a => a -> a
pred forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Int
length forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCEnv -> [TopLevelModuleName]
envImportPath)
let maybeFile :: [Char]
maybeFile = forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe [Char]
file [Char]
"." forall a b. (a -> b) -> a -> b
$ \ [Char]
f -> [Char]
" (" forall a. [a] -> [a] -> [a]
++ [Char]
f forall a. [a] -> [a] -> [a]
++ [Char]
")."
vLvl :: Int
vLvl | [Char]
kind forall a. Eq a => a -> a -> Bool
== [Char]
"Checking" = Int
1
| Bool
otherwise = Int
2
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.chase" Int
vLvl forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ [Char]
indentation, [Char]
kind, [Char]
" ", forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
x, [Char]
maybeFile ]
highlightFromInterface
:: Interface
-> SourceFile
-> TCM ()
highlightFromInterface :: Interface -> SourceFile -> TCM ()
highlightFromInterface Interface
i SourceFile
file = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
5 forall a b. (a -> b) -> a -> b
$
[Char]
"Generating syntax info for " forall a. [a] -> [a] -> [a]
++ AbsolutePath -> [Char]
filePath (SourceFile -> AbsolutePath
srcFilePath SourceFile
file) forall a. [a] -> [a] -> [a]
++
[Char]
" (read from interface)."
forall (m :: * -> *).
MonadTrace m =>
RemoveTokenBasedHighlighting -> HighlightingInfo -> m ()
printHighlightingInfo RemoveTokenBasedHighlighting
KeepHighlighting (Interface -> HighlightingInfo
iHighlighting Interface
i)
readInterface :: InterfaceFile -> TCM (Maybe Interface)
readInterface :: InterfaceFile -> TCM (Maybe Interface)
readInterface InterfaceFile
file = do
let ifp :: [Char]
ifp = AbsolutePath -> [Char]
filePath forall a b. (a -> b) -> a -> b
$ InterfaceFile -> AbsolutePath
intFilePath InterfaceFile
file
(ByteString
s, IO ()
close) <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ [Char] -> IO (ByteString, IO ())
readBinaryFile' [Char]
ifp
do Maybe Interface
mi <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> IO a
E.evaluate forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ByteString -> TCM (Maybe Interface)
decodeInterface ByteString
s
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ()
close
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Interface -> Interface
constructIScope forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Interface
mi
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \TCErr
e -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ()
close forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall {a}. TCErr -> TCMT IO (Maybe a)
handler TCErr
e
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` forall {a}. TCErr -> TCMT IO (Maybe a)
handler
where
handler :: TCErr -> TCMT IO (Maybe a)
handler = \case
IOException TCState
_ Range
_ IOException
e -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"" Int
0 forall a b. (a -> b) -> a -> b
$ [Char]
"IO exception: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show IOException
e
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
TCErr
e -> forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError TCErr
e
writeInterface :: AbsolutePath -> Interface -> TCM Interface
writeInterface :: AbsolutePath -> Interface -> TCMT IO Interface
writeInterface AbsolutePath
file Interface
i = let fp :: [Char]
fp = AbsolutePath -> [Char]
filePath AbsolutePath
file in do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.write" Int
5 forall a b. (a -> b) -> a -> b
$
[Char]
"Writing interface file " forall a. [a] -> [a] -> [a]
++ [Char]
fp forall a. [a] -> [a] -> [a]
++ [Char]
"."
let filteredIface :: Interface
filteredIface = Interface
i { iInsideScope :: ScopeInfo
iInsideScope = ScopeInfo -> ScopeInfo
withoutPrivates forall a b. (a -> b) -> a -> b
$ Interface -> ScopeInfo
iInsideScope Interface
i }
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.write" Int
50 forall a b. (a -> b) -> a -> b
$
[Char]
"Writing interface file with hash " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (Interface -> Hash
iFullHash Interface
filteredIface) forall a. [a] -> [a] -> [a]
++ [Char]
"."
ByteString
encodedIface <- [Char] -> Interface -> TCM ByteString
encodeFile [Char]
fp Interface
filteredIface
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.write" Int
5 [Char]
"Wrote interface file."
#if __GLASGOW_HASKELL__ >= 804
forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Deserialization] (forall a. EmbPrj a => ByteString -> TCM (Maybe a)
decode ByteString
encodedIface))
#else
return filteredIface
#endif
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \TCErr
e -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"" Int
1 forall a b. (a -> b) -> a -> b
$
[Char]
"Failed to write interface " forall a. [a] -> [a] -> [a]
++ [Char]
fp forall a. [a] -> [a] -> [a]
++ [Char]
"."
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM ([Char] -> IO Bool
doesFileExist [Char]
fp) forall a b. (a -> b) -> a -> b
$ [Char] -> IO ()
removeFile [Char]
fp
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError TCErr
e
createInterface
:: TopLevelModuleName
-> SourceFile
-> MainInterface
-> Maybe Source
-> TCM ModuleInfo
createInterface :: TopLevelModuleName
-> SourceFile -> MainInterface -> Maybe Source -> TCM ModuleInfo
createInterface TopLevelModuleName
mname SourceFile
file MainInterface
isMain Maybe Source
msrc = do
let x :: TopLevelModuleName
x = TopLevelModuleName
mname
let fp :: [Char]
fp = AbsolutePath -> [Char]
filePath forall a b. (a -> b) -> a -> b
$ SourceFile -> AbsolutePath
srcFilePath SourceFile
file
let checkMsg :: [Char]
checkMsg = case MainInterface
isMain of
MainInterface Mode
ScopeCheck -> [Char]
"Reading "
MainInterface
_ -> [Char]
"Checking"
withMsgs :: TCM ModuleInfo -> TCM ModuleInfo
withMsgs = forall (m :: * -> *) a b.
Monad m =>
m a -> (a -> m ()) -> m b -> m b
bracket_
([Char] -> TopLevelModuleName -> Maybe [Char] -> TCM ()
chaseMsg [Char]
checkMsg TopLevelModuleName
x forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just [Char]
fp)
(forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ do [TCWarning]
ws <- forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadWarning m) =>
WhichWarnings -> m [TCWarning]
getAllWarnings WhichWarnings
AllWarnings
let classified :: WarningsAndNonFatalErrors
classified = [TCWarning] -> WarningsAndNonFatalErrors
classifyWarnings [TCWarning]
ws
let wa' :: [TCWarning]
wa' = forall a. (a -> Bool) -> [a] -> [a]
filter ((forall a. a -> Maybe a
Strict.Just (forall a. a -> Maybe a
Just TopLevelModuleName
mname) forall a. Eq a => a -> a -> Bool
==) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RangeFile -> Maybe TopLevelModuleName
rangeFileName forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCWarning -> SrcFile
tcWarningOrigin) forall a b. (a -> b) -> a -> b
$
WarningsAndNonFatalErrors -> [TCWarning]
tcWarnings WarningsAndNonFatalErrors
classified
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall a. Null a => a -> Bool
null [TCWarning]
wa') forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"warning" Int
1 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
P.vcat forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
P.prettyTCM forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TCWarning]
wa'
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall a. Null a => a -> Bool
null (WarningsAndNonFatalErrors -> [TCWarning]
nonFatalErrors WarningsAndNonFatalErrors
classified)) forall a b. (a -> b) -> a -> b
$ [Char] -> TopLevelModuleName -> Maybe [Char] -> TCM ()
chaseMsg [Char]
"Finished" TopLevelModuleName
x forall a. Maybe a
Nothing)
TCM ModuleInfo -> TCM ModuleInfo
withMsgs forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [TopLevelModuleName -> Phase
Bench.TopModule TopLevelModuleName
mname] forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a.
MonadTCEnv m =>
(TCEnv -> TCEnv) -> m a -> m a
localTC (\TCEnv
e -> TCEnv
e { envCurrentPath :: Maybe AbsolutePath
envCurrentPath = forall a. a -> Maybe a
Just (SourceFile -> AbsolutePath
srcFilePath SourceFile
file) }) forall a b. (a -> b) -> a -> b
$ do
let onlyScope :: Bool
onlyScope = MainInterface
isMain forall a. Eq a => a -> a -> Bool
== Mode -> MainInterface
MainInterface Mode
ScopeCheck
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
5 forall a b. (a -> b) -> a -> b
$
[Char]
"Creating interface for " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow TopLevelModuleName
mname forall a. [a] -> [a] -> [a]
++ [Char]
"."
forall (m :: * -> *). MonadDebug m => [Char] -> Int -> m () -> m ()
verboseS [Char]
"import.iface.create" Int
10 forall a b. (a -> b) -> a -> b
$ do
[Char]
visited <- forall a. Pretty a => a -> [Char]
prettyShow forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). ReadTCState m => m Doc
getPrettyVisitedModules
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
10 forall a b. (a -> b) -> a -> b
$ [Char]
" visited: " forall a. [a] -> [a] -> [a]
++ [Char]
visited
Source
src <- forall b a. b -> (a -> b) -> Maybe a -> b
maybe (SourceFile -> TCM Source
parseSource SourceFile
file) forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Source
msrc
let srcPath :: AbsolutePath
srcPath = SourceFile -> AbsolutePath
srcFilePath forall a b. (a -> b) -> a -> b
$ Source -> SourceFile
srcOrigin Source
src
HighlightingInfo
fileTokenInfo <- forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Highlighting] forall a b. (a -> b) -> a -> b
$
RangeFile -> [Char] -> TCMT IO HighlightingInfo
generateTokenInfoFromSource
(let !top :: TopLevelModuleName
top = Source -> TopLevelModuleName
srcModuleName Source
src in
AbsolutePath -> Maybe TopLevelModuleName -> RangeFile
mkRangeFile AbsolutePath
srcPath (forall a. a -> Maybe a
Just TopLevelModuleName
top))
(Text -> [Char]
TL.unpack forall a b. (a -> b) -> a -> b
$ Source -> Text
srcText Source
src)
Lens' HighlightingInfo TCState
stTokens forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` (HighlightingInfo
fileTokenInfo forall a. Semigroup a => a -> a -> a
<>)
Source -> TCM ()
setOptionsFromSourcePragmas Source
src
CohesionAttributes -> TCM ()
checkCohesionAttributes (Source -> CohesionAttributes
srcCohesion Source
src)
Maybe Int
syntactic <- PragmaOptions -> Maybe Int
optSyntacticEquality forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions
forall (m :: * -> *) a.
MonadTCEnv m =>
(TCEnv -> TCEnv) -> m a -> m a
localTC (\TCEnv
env -> TCEnv
env { envSyntacticEqualityFuel :: Maybe Int
envSyntacticEqualityFuel = Maybe Int
syntactic }) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). MonadDebug m => [Char] -> Int -> m () -> m ()
verboseS [Char]
"import.iface.create" Int
15 forall a b. (a -> b) -> a -> b
$ do
Int
nestingLevel <- forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC (forall a. Enum a => a -> a
pred forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Int
length forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCEnv -> [TopLevelModuleName]
envImportPath)
HighlightingLevel
highlightingLevel <- forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> HighlightingLevel
envHighlightingLevel
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
15 forall a b. (a -> b) -> a -> b
$ [[Char]] -> [Char]
unlines
[ [Char]
" nesting level: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Int
nestingLevel
, [Char]
" highlighting level: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show HighlightingLevel
highlightingLevel
]
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Starting scope checking."
TopLevelInfo
topLevel <- forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Scoping] forall a b. (a -> b) -> a -> b
$ do
let topDecls :: [Declaration]
topDecls = Module -> [Declaration]
C.modDecls forall a b. (a -> b) -> a -> b
$ Source -> Module
srcModule Source
src
forall c. ToAbstract c => c -> ScopeM (AbsOfCon c)
concreteToAbstract_ (forall a. AbsolutePath -> TopLevelModuleName -> a -> TopLevel a
TopLevel AbsolutePath
srcPath TopLevelModuleName
mname [Declaration]
topDecls)
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Finished scope checking."
let ds :: [Declaration]
ds = TopLevelInfo -> [Declaration]
topLevelDecls TopLevelInfo
topLevel
scope :: ScopeInfo
scope = TopLevelInfo -> ScopeInfo
topLevelScope TopLevelInfo
topLevel
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Starting highlighting from scope."
forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Highlighting] forall a b. (a -> b) -> a -> b
$ do
forall (tcm :: * -> *).
MonadTCEnv tcm =>
HighlightingLevel -> tcm () -> tcm ()
ifTopLevelAndHighlightingLevelIs HighlightingLevel
NonInteractive forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
MonadTrace m =>
RemoveTokenBasedHighlighting -> HighlightingInfo -> m ()
printHighlightingInfo RemoveTokenBasedHighlighting
KeepHighlighting HighlightingInfo
fileTokenInfo
forall (tcm :: * -> *).
MonadTCEnv tcm =>
HighlightingLevel -> Bool -> tcm () -> tcm ()
ifTopLevelAndHighlightingLevelIsOr HighlightingLevel
NonInteractive Bool
onlyScope forall a b. (a -> b) -> a -> b
$
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (\ Declaration
d -> Declaration -> Level -> Bool -> TCM ()
generateAndPrintSyntaxInfo Declaration
d Level
Partial Bool
onlyScope) [Declaration]
ds
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Finished highlighting from scope."
forall (m :: * -> *).
(HasOptions m, MonadDebug m, MonadTCState m) =>
m ()
activateLoadedFileCache
forall (m :: * -> *).
(MonadDebug m, MonadTCState m, ReadTCState m) =>
m ()
cachingStarts
PragmaOptions
opts <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' PragmaOptions TCState
stPragmaOptions
Maybe (TypeCheckAction, PostScopeState)
me <- forall (m :: * -> *).
(MonadDebug m, MonadTCState m, ReadTCState m) =>
m (Maybe (TypeCheckAction, PostScopeState))
readFromCachedLog
case Maybe (TypeCheckAction, PostScopeState)
me of
Just (Pragmas PragmaOptions
opts', PostScopeState
_) | PragmaOptions
opts forall a. Eq a => a -> a -> Bool
== PragmaOptions
opts'
-> forall (m :: * -> *) a. Monad m => a -> m a
return ()
Maybe (TypeCheckAction, PostScopeState)
_ -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"cache" Int
10 forall a b. (a -> b) -> a -> b
$ [Char]
"pragma changed: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (forall a. Maybe a -> Bool
isJust Maybe (TypeCheckAction, PostScopeState)
me)
forall (m :: * -> *). (MonadDebug m, MonadTCState m) => m ()
cleanCachedLog
forall (m :: * -> *).
(MonadDebug m, MonadTCState m, ReadTCState m) =>
TypeCheckAction -> m ()
writeToCurrentLog forall a b. (a -> b) -> a -> b
$ PragmaOptions -> TypeCheckAction
Pragmas PragmaOptions
opts
if Bool
onlyScope
then do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Skipping type checking."
forall (m :: * -> *). (MonadDebug m, MonadTCState m) => m ()
cacheCurrentLog
else do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Starting type checking."
forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Typing] forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Declaration -> TCM ()
checkDeclCached [Declaration]
ds forall a b. TCM a -> TCM b -> TCM a
`finally_` forall (m :: * -> *). (MonadDebug m, MonadTCState m) => m ()
cacheCurrentLog
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Finished type checking."
TCM ()
unfreezeMetas
forall (m :: * -> *). MonadDebug m => ProfileOption -> m () -> m ()
whenProfile ProfileOption
Profile.Metas forall a b. (a -> b) -> a -> b
$ do
MetaId
m <- forall i (m :: * -> *). MonadFresh i m => m i
fresh
forall (m :: * -> *).
MonadStatistics m =>
[Char] -> Integer -> m ()
tickN [Char]
"metas" (forall a b. (Integral a, Num b) => a -> b
fromIntegral (MetaId -> Hash
metaId MetaId
m))
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Starting highlighting from type info."
forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Highlighting] forall a b. (a -> b) -> a -> b
$ do
HighlightingInfo
toks <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' HighlightingInfo TCState
stTokens
forall (tcm :: * -> *).
MonadTCEnv tcm =>
HighlightingLevel -> tcm () -> tcm ()
ifTopLevelAndHighlightingLevelIs HighlightingLevel
NonInteractive forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
MonadTrace m =>
RemoveTokenBasedHighlighting -> HighlightingInfo -> m ()
printHighlightingInfo RemoveTokenBasedHighlighting
KeepHighlighting HighlightingInfo
toks
Lens' HighlightingInfo TCState
stTokens forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> a -> m ()
`setTCLens` forall a. Monoid a => a
mempty
[TCWarning]
warnings <- forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadWarning m) =>
WhichWarnings -> m [TCWarning]
getAllWarnings WhichWarnings
AllWarnings
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall a. Null a => a -> Bool
null [TCWarning]
warnings) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"import.iface.create" Int
20 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"collected warnings: " forall a. Semigroup a => a -> a -> a
<> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM [TCWarning]
warnings
[TCWarning]
unsolved <- forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadWarning m) =>
m [TCWarning]
getAllUnsolvedWarnings
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall a. Null a => a -> Bool
null [TCWarning]
unsolved) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"import.iface.create" Int
20 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"collected unsolved: " forall a. Semigroup a => a -> a -> a
<> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM [TCWarning]
unsolved
let warningInfo :: HighlightingInfo
warningInfo =
forall a b. Convert a b => a -> b
convert forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap TCWarning -> HighlightingInfoBuilder
warningHighlighting forall a b. (a -> b) -> a -> b
$ [TCWarning]
unsolved forall a. [a] -> [a] -> [a]
++ [TCWarning]
warnings
Lens' HighlightingInfo TCState
stSyntaxInfo forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` \HighlightingInfo
inf -> (HighlightingInfo
inf forall a. Monoid a => a -> a -> a
`mappend` HighlightingInfo
toks) forall a. Monoid a => a -> a -> a
`mappend` HighlightingInfo
warningInfo
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (CommandLineOptions -> Bool
optGenerateVimFile forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m CommandLineOptions
commandLineOptions) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) a. ReadTCState m => ScopeInfo -> m a -> m a
withScope_ ScopeInfo
scope forall a b. (a -> b) -> a -> b
$ [Char] -> TCM ()
generateVimFile forall a b. (a -> b) -> a -> b
$ AbsolutePath -> [Char]
filePath forall a b. (a -> b) -> a -> b
$ AbsolutePath
srcPath
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Finished highlighting from type info."
ScopeInfo -> TCM ()
setScope ScopeInfo
scope
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"scope.top" Int
50 forall a b. (a -> b) -> a -> b
$ [Char]
"SCOPE " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show ScopeInfo
scope
[MetaId]
openMetas <- forall (m :: * -> *). ReadTCState m => m [MetaId]
getOpenMetas
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall a. Null a => a -> Bool
null [MetaId]
openMetas) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.metas" Int
10 [Char]
"We have unsolved metas."
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.metas" Int
10 forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Goals -> TCMT IO [Char]
showGoals forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCM Goals
getGoals
forall (tcm :: * -> *).
MonadTCEnv tcm =>
HighlightingLevel -> tcm () -> tcm ()
ifTopLevelAndHighlightingLevelIs HighlightingLevel
NonInteractive TCM ()
printUnsolvedInfo
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (MainInterface -> Bool
includeStateChanges MainInterface
isMain) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (PragmaOptions -> Bool
optAllowUnsolved forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Turning unsolved metas (if any) into postulates."
forall (m :: * -> *) a. MonadTCEnv m => ModuleName -> m a -> m a
withCurrentModule (ScopeInfo
scope forall o i. o -> Lens' i o -> i
^. Lens' ModuleName ScopeInfo
scopeCurrent) TCM ()
openMetasToPostulates
Lens' Constraints TCState
stAwakeConstraints forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> a -> m ()
`setTCLens` []
Lens' Constraints TCState
stSleepingConstraints forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> a -> m ()
`setTCLens` []
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Starting serialization."
Interface
i <- forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Serialization, Phase
Bench.BuildInterface] forall a b. (a -> b) -> a -> b
$
Source -> TopLevelInfo -> TCMT IO Interface
buildInterface Source
src TopLevelInfo
topLevel
forall a (m :: * -> *).
(ReportS a, MonadDebug m) =>
[Char] -> Int -> a -> m ()
reportS [Char]
"tc.top" Int
101 forall a b. (a -> b) -> a -> b
$
[Char]
"Signature:" forall a. a -> [a] -> [a]
:
[ [[Char]] -> [Char]
unlines
[ forall a. Pretty a => a -> [Char]
prettyShow QName
q
, [Char]
" type: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (Definition -> Type
defType Definition
def)
, [Char]
" def: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Maybe CompiledClauses
cc
]
| (QName
q, Definition
def) <- forall k v. HashMap k v -> [(k, v)]
HMap.toList forall a b. (a -> b) -> a -> b
$ Interface -> Signature
iSignature Interface
i forall o i. o -> Lens' i o -> i
^. Lens' (HashMap QName Definition) Signature
sigDefinitions,
Function{ funCompiled :: Defn -> Maybe CompiledClauses
funCompiled = Maybe CompiledClauses
cc } <- [Definition -> Defn
theDef Definition
def]
]
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Finished serialization."
[TCWarning]
mallWarnings <- forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadWarning m) =>
MainInterface -> WhichWarnings -> m [TCWarning]
getAllWarnings' MainInterface
isMain WhichWarnings
ErrorWarnings
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Considering writing to interface file."
Interface
finalIface <- Interface -> Interface
constructIScope forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case ([TCWarning]
mallWarnings, MainInterface
isMain) of
(TCWarning
_:[TCWarning]
_, MainInterface
_) -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"We have warnings, skipping writing interface file."
forall (m :: * -> *) a. Monad m => a -> m a
return Interface
i
([], MainInterface Mode
ScopeCheck) -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"We are just scope-checking, skipping writing interface file."
forall (m :: * -> *) a. Monad m => a -> m a
return Interface
i
([], MainInterface
_) -> forall (m :: * -> *) c.
MonadBench m =>
Account (BenchPhase m) -> m c -> m c
Bench.billTo [Phase
Bench.Serialization] forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Actually calling writeInterface."
AbsolutePath
ifile <- SourceFile -> TCM AbsolutePath
toIFile SourceFile
file
Interface
serializedIface <- AbsolutePath -> Interface -> TCMT IO Interface
writeInterface AbsolutePath
ifile Interface
i
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface.create" Int
7 [Char]
"Finished writing to interface file."
forall (m :: * -> *) a. Monad m => a -> m a
return Interface
serializedIface
forall (m :: * -> *).
(MonadDebug m, MonadTCEnv m, HasOptions m) =>
Maybe TopLevelModuleName -> Statistics -> m ()
printStatistics (forall a. a -> Maybe a
Just TopLevelModuleName
mname) forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). ReadTCState m => m Statistics
getStatistics
Statistics
localStatistics <- forall (m :: * -> *). ReadTCState m => m Statistics
getStatistics
Lens' Statistics TCState
lensAccumStatistics forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith forall a. Num a => a -> a -> a
(+) Statistics
localStatistics
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
5 [Char]
"Accumulated statistics."
Bool
isPrimitiveModule <- forall (m :: * -> *). MonadIO m => [Char] -> m Bool
Lens.isPrimitiveModule (AbsolutePath -> [Char]
filePath AbsolutePath
srcPath)
forall (m :: * -> *) a. Monad m => a -> m a
return ModuleInfo
{ miInterface :: Interface
miInterface = Interface
finalIface
, miWarnings :: [TCWarning]
miWarnings = [TCWarning]
mallWarnings
, miPrimitive :: Bool
miPrimitive = Bool
isPrimitiveModule
, miMode :: ModuleCheckMode
miMode = MainInterface -> ModuleCheckMode
moduleCheckMode MainInterface
isMain
}
getAllWarnings' :: (MonadFail m, ReadTCState m, MonadWarning m) => MainInterface -> WhichWarnings -> m [TCWarning]
getAllWarnings' :: forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadWarning m) =>
MainInterface -> WhichWarnings -> m [TCWarning]
getAllWarnings' (MainInterface Mode
_) = forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadWarning m) =>
Set WarningName -> WhichWarnings -> m [TCWarning]
getAllWarningsPreserving Set WarningName
unsolvedWarnings
getAllWarnings' MainInterface
NotMainInterface = forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadWarning m) =>
Set WarningName -> WhichWarnings -> m [TCWarning]
getAllWarningsPreserving forall a. Set a
Set.empty
constructIScope :: Interface -> Interface
constructIScope :: Interface -> Interface
constructIScope Interface
i = forall a. Account -> a -> a
billToPure [ Phase
Deserialization ] forall a b. (a -> b) -> a -> b
$
Interface
i{ iScope :: Map ModuleName Scope
iScope = ScopeInfo -> Map ModuleName Scope
publicModules forall a b. (a -> b) -> a -> b
$ Interface -> ScopeInfo
iInsideScope Interface
i }
buildInterface
:: Source
-> TopLevelInfo
-> TCM Interface
buildInterface :: Source -> TopLevelInfo -> TCMT IO Interface
buildInterface Source
src TopLevelInfo
topLevel = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
5 [Char]
"Building interface..."
let mname :: ModuleName
mname = TopLevelInfo -> ModuleName
CToA.topLevelModuleName TopLevelInfo
topLevel
source :: Text
source = Source -> Text
srcText Source
src
fileType :: FileType
fileType = Source -> FileType
srcFileType Source
src
defPragmas :: [[[Char]]]
defPragmas = Source -> [[[Char]]]
srcDefaultPragmas Source
src
filePragmas :: [[[Char]]]
filePragmas = Source -> [[[Char]]]
srcFilePragmas Source
src
Map [Char] (Builtin PrimFun)
builtin <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Map [Char] (Builtin PrimFun)) TCState
stLocalBuiltins
[(TopLevelModuleName, Hash)]
mhs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\TopLevelModuleName
top -> (TopLevelModuleName
top,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TopLevelModuleName -> TCMT IO Hash
moduleHash TopLevelModuleName
top) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. HashSet a -> [a]
HSet.toList forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useR Lens' (HashSet TopLevelModuleName) TCState
stImportedModules
Map [Char] [ForeignCode]
foreignCode <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Map [Char] [ForeignCode]) TCState
stForeignCode
DisplayForms
origDisplayForms <- forall v k. (v -> Bool) -> HashMap k v -> HashMap k v
HMap.filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Null a => a -> Bool
null) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall v1 v2 k. (v1 -> v2) -> HashMap k v1 -> HashMap k v2
HMap.map (forall a. (a -> Bool) -> [a] -> [a]
filter forall a. Open a -> Bool
isClosed) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' DisplayForms TCState
stImportsDisplayForms
(DisplayForms
display, Signature
sig, RemoteMetaStore
solvedMetas) <-
Map [Char] (Builtin PrimFun)
-> DisplayForms
-> Signature
-> LocalMetaStore
-> TCMT IO (DisplayForms, Signature, RemoteMetaStore)
eliminateDeadCode Map [Char] (Builtin PrimFun)
builtin DisplayForms
origDisplayForms forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> (m a, m b) -> m c
==<<
(forall (m :: * -> *). ReadTCState m => m Signature
getSignature, forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useR Lens' LocalMetaStore TCState
stSolvedMetaStore)
Map QName Text
userwarns <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Map QName Text) TCState
stLocalUserWarnings
Maybe Text
importwarn <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Maybe Text) TCState
stWarningOnImport
HighlightingInfo
syntaxInfo <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' HighlightingInfo TCState
stSyntaxInfo
PragmaOptions
optionsUsed <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' PragmaOptions TCState
stPragmaOptions
Set QName
partialDefs <- forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Set QName) TCState
stLocalPartialDefs
PatternSynDefns
patsyns <- forall a. KillRange a => KillRangeT a
killRange forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). ReadTCState m => m PatternSynDefns
getPatternSyns
let builtin' :: BuiltinThings ([Char], QName)
builtin' = forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey (\ [Char]
x Builtin PrimFun
b -> ([Char]
x,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimFun -> QName
primFunName forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Builtin PrimFun
b) Map [Char] (Builtin PrimFun)
builtin
[TCWarning]
warnings <- forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadWarning m) =>
WhichWarnings -> m [TCWarning]
getAllWarnings WhichWarnings
AllWarnings
let i :: Interface
i = Interface
{ iSourceHash :: Hash
iSourceHash = Text -> Hash
hashText Text
source
, iSource :: Text
iSource = Text
source
, iFileType :: FileType
iFileType = FileType
fileType
, iImportedModules :: [(TopLevelModuleName, Hash)]
iImportedModules = [(TopLevelModuleName, Hash)]
mhs
, iModuleName :: ModuleName
iModuleName = ModuleName
mname
, iTopLevelModuleName :: TopLevelModuleName
iTopLevelModuleName = Source -> TopLevelModuleName
srcModuleName Source
src
, iScope :: Map ModuleName Scope
iScope = forall a. Null a => a
empty
, iInsideScope :: ScopeInfo
iInsideScope = TopLevelInfo -> ScopeInfo
topLevelScope TopLevelInfo
topLevel
, iSignature :: Signature
iSignature = Signature
sig
, iMetaBindings :: RemoteMetaStore
iMetaBindings = RemoteMetaStore
solvedMetas
, iDisplayForms :: DisplayForms
iDisplayForms = DisplayForms
display
, iUserWarnings :: Map QName Text
iUserWarnings = Map QName Text
userwarns
, iImportWarning :: Maybe Text
iImportWarning = Maybe Text
importwarn
, iBuiltin :: BuiltinThings ([Char], QName)
iBuiltin = BuiltinThings ([Char], QName)
builtin'
, iForeignCode :: Map [Char] [ForeignCode]
iForeignCode = Map [Char] [ForeignCode]
foreignCode
, iHighlighting :: HighlightingInfo
iHighlighting = HighlightingInfo
syntaxInfo
, iDefaultPragmaOptions :: [[[Char]]]
iDefaultPragmaOptions = [[[Char]]]
defPragmas
, iFilePragmaOptions :: [[[Char]]]
iFilePragmaOptions = [[[Char]]]
filePragmas
, iOptionsUsed :: PragmaOptions
iOptionsUsed = PragmaOptions
optionsUsed
, iPatternSyns :: PatternSynDefns
iPatternSyns = PatternSynDefns
patsyns
, iWarnings :: [TCWarning]
iWarnings = [TCWarning]
warnings
, iPartialDefs :: Set QName
iPartialDefs = Set QName
partialDefs
}
Interface
i <-
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (forall (b :: Bool). KnownBool b => WithDefault b -> Bool
collapseDefault forall b c a. (b -> c) -> (a -> b) -> a -> c
. PragmaOptions -> WithDefault 'False
optSaveMetas forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions)
(forall (m :: * -> *) a. Monad m => a -> m a
return Interface
i)
(do forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
7
[Char]
" instantiating all meta variables"
forall (m :: * -> *). MonadReduce m => Interface -> m Interface
instantiateFullExceptForDefinitions Interface
i)
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"import.iface" Int
7 [Char]
" interface complete"
forall (m :: * -> *) a. Monad m => a -> m a
return Interface
i
getInterfaceFileHashes :: InterfaceFile -> IO (Maybe (Hash, Hash))
getInterfaceFileHashes :: InterfaceFile -> IO (Maybe (Hash, Hash))
getInterfaceFileHashes InterfaceFile
fp = do
let ifile :: [Char]
ifile = AbsolutePath -> [Char]
filePath forall a b. (a -> b) -> a -> b
$ InterfaceFile -> AbsolutePath
intFilePath InterfaceFile
fp
(ByteString
s, IO ()
close) <- [Char] -> IO (ByteString, IO ())
readBinaryFile' [Char]
ifile
let hs :: Maybe (Hash, Hash)
hs = ByteString -> Maybe (Hash, Hash)
decodeHashes ByteString
s
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Hash
0 (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. Num a => a -> a -> a
(+)) Maybe (Hash, Hash)
hs seq :: forall a b. a -> b -> b
`seq` IO ()
close
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Hash, Hash)
hs
moduleHash :: TopLevelModuleName -> TCM Hash
moduleHash :: TopLevelModuleName -> TCMT IO Hash
moduleHash TopLevelModuleName
m = Interface -> Hash
iFullHash forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TopLevelModuleName -> Maybe Source -> TCMT IO Interface
getNonMainInterface TopLevelModuleName
m forall a. Maybe a
Nothing