Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
removing fast/slow code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Mar 17, 2014
1 parent 5aa5d3c commit 16e0504
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 78 deletions.
1 change: 0 additions & 1 deletion Language/Haskell/GhcMod/Browse.hs
Expand Up @@ -53,7 +53,6 @@ browse opt cradle mdlName = do
fallback e = throwGhcException e
loadAndFind = do
setTargetFiles [mdlName]
checkSlowAndSet
void $ load LoadAllTargets
findModule mdlname Nothing

Expand Down
1 change: 0 additions & 1 deletion Language/Haskell/GhcMod/Check.hs
Expand Up @@ -39,7 +39,6 @@ check opt cradle fileNames = checkIt `gcatch` handleErrMsg ls
checkIt = do
(readLog,_) <- initializeFlagsWithCradle opt cradle options True
setTargetFiles fileNames
checkSlowAndSet
void $ load LoadAllTargets
liftIO readLog
options
Expand Down
7 changes: 2 additions & 5 deletions Language/Haskell/GhcMod/Debug.hs
Expand Up @@ -32,17 +32,14 @@ debug opt cradle fileName = do
liftIO (fromCabalFile ||> return simpleCompilerOption)
else
return simpleCompilerOption
[fast] <- do
void $ initializeFlagsWithCradle opt cradle gopts True
setTargetFiles [fileName]
pure . canCheckFast <$> depanal [] False
void $ initializeFlagsWithCradle opt cradle gopts True
setTargetFiles [fileName]
return [
"Current directory: " ++ currentDir
, "Cabal file: " ++ cabalFile
, "GHC options: " ++ unwords gopts
, "Include directories: " ++ unwords incDir
, "Dependent packages: " ++ (intercalate ", " $ map fst pkgs)
, "Fast check: " ++ if fast then "Yes" else "No"
]
where
currentDir = cradleCurrentDir cradle
Expand Down
41 changes: 4 additions & 37 deletions Language/Haskell/GhcMod/GHCApi.hs
Expand Up @@ -7,9 +7,6 @@ module Language.Haskell.GhcMod.GHCApi (
, initializeFlagsWithCradle
, setTargetFiles
, getDynamicFlags
, setSlowDynFlags
, checkSlowAndSet
, canCheckFast
) where

import Control.Applicative
Expand Down Expand Up @@ -121,7 +118,10 @@ modifyFlags d0 idirs depPkgs splice build
| otherwise = d4
where
d1 = d0 { importPaths = idirs }
d2 = setFastOrNot d1 Fast
d2 = d1 {
ghcLink = LinkInMemory
, hscTarget = HscInterpreted
}
d3 = Gap.addDevPkgs d2 depPkgs
d4 | build == CabalPkg = Gap.setCabalPkg d3
| otherwise = d3
Expand All @@ -131,31 +131,6 @@ setSplice dflag = dopt_set dflag Opt_D_dump_splices

----------------------------------------------------------------

setFastOrNot :: DynFlags -> CheckSpeed -> DynFlags
setFastOrNot dflags Slow = dflags {
ghcLink = LinkInMemory
, hscTarget = HscInterpreted
}
setFastOrNot dflags Fast = dflags {
ghcLink = NoLink
, hscTarget = HscNothing
}

setSlowDynFlags :: GhcMonad m => m ()
setSlowDynFlags = (flip setFastOrNot Slow <$> getSessionDynFlags)
>>= void . setSessionDynFlags

-- | To check TH, a session module graph is necessary.
-- "load" sets a session module graph using "depanal".
-- But we have to set "-fno-code" to DynFlags before "load".
-- So, this is necessary redundancy.
checkSlowAndSet :: GhcMonad m => m ()
checkSlowAndSet = do
fast <- canCheckFast <$> depanal [] False
unless fast setSlowDynFlags

----------------------------------------------------------------

modifyFlagsWithOpts :: GhcMonad m => DynFlags -> [GHCOption] -> m DynFlags
modifyFlagsWithOpts dflags cmdOpts =
tfst <$> parseDynamicFlags dflags (map noLoc cmdOpts)
Expand All @@ -176,11 +151,3 @@ setTargetFiles files = do
-- | Return the 'DynFlags' currently in use in the GHC session.
getDynamicFlags :: IO DynFlags
getDynamicFlags = runGhc (Just libdir) getSessionDynFlags

-- | Checking if Template Haskell or quasi quotes are used.
-- If not, the process can be faster.
canCheckFast :: ModuleGraph -> Bool
canCheckFast = not . any (hasTHorQQ . ms_hspp_opts)
where
hasTHorQQ :: DynFlags -> Bool
hasTHorQQ dflags = any (`xopt` dflags) [Opt_TemplateHaskell, Opt_QuasiQuotes]
7 changes: 2 additions & 5 deletions Language/Haskell/GhcMod/Info.hs
Expand Up @@ -10,7 +10,7 @@ module Language.Haskell.GhcMod.Info (
) where

import Control.Applicative ((<$>))
import Control.Monad (void, when)
import Control.Monad (void)
import CoreUtils (exprType)
import Data.Function (on)
import Data.Generics hiding (typeOf)
Expand Down Expand Up @@ -135,20 +135,17 @@ pretty dflag = showUnqualifiedOneLine dflag . Gap.typeForUser
----------------------------------------------------------------

inModuleContext :: Cmd -> Options -> Cradle -> FilePath -> ModuleString -> Ghc String -> String -> Ghc String
inModuleContext cmd opt cradle file modstr action errmsg =
inModuleContext _ opt cradle file modstr action errmsg =
valid ||> invalid ||> return errmsg
where
valid = do
void $ initializeFlagsWithCradle opt cradle ["-w:"] False
when (cmd == Info) setSlowDynFlags
setTargetFiles [file]
checkSlowAndSet
void $ load LoadAllTargets
doif setContextFromTarget action
invalid = do
void $ initializeFlagsWithCradle opt cradle ["-w:"] False
setTargetBuffer
checkSlowAndSet
void $ load LoadAllTargets
doif setContextFromTarget action
setTargetBuffer = do
Expand Down
3 changes: 0 additions & 3 deletions Language/Haskell/GhcMod/Internal.hs
Expand Up @@ -14,16 +14,13 @@ module Language.Haskell.GhcMod.Internal (
, cabalDependPackages
, cabalSourceDirs
, cabalAllTargets
-- * GHC API
, canCheckFast
-- * Getting 'DynFlags'
, getDynamicFlags
-- * Initializing 'DynFlags'
, initializeFlags
, initializeFlagsWithCradle
-- * 'GhcMonad'
, setTargetFiles
, checkSlowAndSet
-- * 'Ghc' Choice
, (||>)
, goNext
Expand Down
2 changes: 0 additions & 2 deletions Language/Haskell/GhcMod/Types.hs
Expand Up @@ -113,8 +113,6 @@ type Expression = String
-- | Module name.
type ModuleString = String

data CheckSpeed = Slow | Fast

-- | Option information for GHC
data CompilerOptions = CompilerOptions {
ghcOptions :: [GHCOption] -- ^ Command line options
Expand Down
1 change: 0 additions & 1 deletion ghc-mod.cabal
Expand Up @@ -111,7 +111,6 @@ Test-Suite spec
BrowseSpec
CabalApiSpec
CheckSpec
DebugSpec
FlagSpec
InfoSpec
LangSpec
Expand Down
23 changes: 0 additions & 23 deletions test/DebugSpec.hs

This file was deleted.

9 comments on commit 16e0504

@alanz
Copy link
Collaborator

@alanz alanz commented on 16e0504 Mar 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this in HaRe, and it works fine for template haskell but fails for anything using the FFI

@kazu-yamamoto
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what "fail" means. Would you explain more concretely and give me an example?

@alanz
Copy link
Collaborator

@alanz alanz commented on 16e0504 Mar 31, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazu-yamamoto
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use HscNothing, GHC is fast but does not desugar. So, we cannot get warnings such as warn-unused-do-bind.
That's one of the reasons why I made ghc-modi.

HscInterpreted desugars. But FFI fails as you said.

Replacing HscInterpreted with HscAsm works. But ".o" files are generated. I cannot find a workaround on this.

@kazu-yamamoto
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foreign import works with the current code but foreign export fails, right?

@alanz
Copy link
Collaborator

@alanz alanz commented on 16e0504 Mar 31, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazu-yamamoto
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ghc-modi is shared by a project (package). I don't think hscTarget cannot be changed dynamically. If a HS file without FFI is targed, hscTarget is fixed to HscInterpreted. Then another file with FFI is targeted, we cannot change hscTarget.

@alanz
Copy link
Collaborator

@alanz alanz commented on 16e0504 Apr 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the choice is between speed and full support, maybe have a flag we can pass in we know the project uses FFI exports and want to use ghc-modi with it, which forces the appropriate hscTarget. Or does this break the overall working of ghc-modi?

@kazu-yamamoto
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's continue in #205.

Please sign in to comment.