Skip to content

Commit

Permalink
See if fakeDynFlags is unnecessary (#378)
Browse files Browse the repository at this point in the history
* See if fakeDynFlags is unnecessary

* Cleanups now fakeDynFlags is gone

* Remove redundant CPP
  • Loading branch information
ndmitchell authored Feb 10, 2020
1 parent b653f59 commit 5a65da1
Showing 1 changed file with 2 additions and 43 deletions.
45 changes: 2 additions & 43 deletions src/Development/IDE/GHC/Util.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

{-# OPTIONS_GHC -Wno-missing-fields #-} -- to enable prettyPrint
{-# LANGUAGE CPP #-}
#include "ghc-api-version.h"

-- | General utility functions, mostly focused around GHC operations.
module Development.IDE.GHC.Util(
-- * HcsEnv and environment
HscEnvEq, hscEnv, newHscEnvEq,
modifyDynFlags,
fakeDynFlags,
runGhcEnv,
-- * GHC wrappers
prettyPrint,
Expand All @@ -25,7 +20,6 @@ module Development.IDE.GHC.Util(
hDuplicateTo',
) where


import Control.Concurrent
import Data.List.Extra
import Data.Maybe
Expand All @@ -47,11 +41,6 @@ import GHC.IO.Encoding
import GHC.IO.Exception
import GHC.IO.Handle.Types
import GHC.IO.Handle.Internals
#if MIN_GHC_API_VERSION(8,10,0)
#else
import Config
import Platform
#endif
import Data.Unique
import Development.Shake.Classes
import qualified Data.Text as T
Expand Down Expand Up @@ -94,9 +83,9 @@ textToStringBuffer :: T.Text -> StringBuffer
textToStringBuffer = stringToStringBuffer . T.unpack


-- | Pretty print a GHC value using 'fakeDynFlags'.
-- | Pretty print a GHC value using 'unsafeGlobalDynFlags '.
prettyPrint :: Outputable a => a -> String
prettyPrint = showSDoc fakeDynFlags . ppr
prettyPrint = showSDoc unsafeGlobalDynFlags . ppr

-- | Run a 'Ghc' monad value using an existing 'HscEnv'. Sets up and tears down all the required
-- pieces, but designed to be more efficient than a standard 'runGhc'.
Expand All @@ -110,36 +99,6 @@ runGhcEnv env act = do
cleanTempFiles dflags
cleanTempDirs dflags

-- | A 'DynFlags' value where most things are undefined. It's sufficient to call pretty printing,
-- but not much else.
fakeDynFlags :: DynFlags
#if MIN_GHC_API_VERSION(8,10,0)
fakeDynFlags = unsafeGlobalDynFlags
#else
fakeDynFlags = defaultDynFlags
settings
mempty
where
settings = Settings
{ sTargetPlatform = platform
, sPlatformConstants = platformConstants
, sProgramName = "ghc"
, sProjectVersion = cProjectVersion
#if MIN_GHC_API_VERSION(8,6,0)
, sOpt_P_fingerprint = fingerprint0
#endif
}
platform = Platform
{ platformWordSize=8
, platformOS=OSUnknown
, platformUnregisterised=True
}
platformConstants = PlatformConstants
{ pc_DYNAMIC_BY_DEFAULT=False
, pc_WORD_SIZE=8
}
#endif

-- | Given a module location, and its parse tree, figure out what is the include directory implied by it.
-- For example, given the file @\/usr\/\Test\/Foo\/Bar.hs@ with the module name @Foo.Bar@ the directory
-- @\/usr\/Test@ should be on the include path to find sibling modules.
Expand Down

0 comments on commit 5a65da1

Please sign in to comment.