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