summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-05-06 11:30:57 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-12 21:41:43 -0400
commitf78c25da05849797dab684a221923aeac244c69b (patch)
tree2be99a252aaf70a6848eb1f39ee39e13ae1578df
parenta7473e03e24878c2192958695759f5d3d415215c (diff)
downloadhaskell-f78c25da05849797dab684a221923aeac244c69b.tar.gz
Move GlobalVar macros into GHC.Utils.GlobalVars
That's the only place where they are used and they shouldn't be used elsewhere.
-rw-r--r--compiler/GHC/Data/FastString.hs3
-rw-r--r--compiler/GHC/Utils/GlobalVars.hs35
-rw-r--r--compiler/HsVersions.h29
3 files changed, 32 insertions, 35 deletions
diff --git a/compiler/GHC/Data/FastString.hs b/compiler/GHC/Data/FastString.hs
index 590f043d4b..ac44a68d54 100644
--- a/compiler/GHC/Data/FastString.hs
+++ b/compiler/GHC/Data/FastString.hs
@@ -112,7 +112,8 @@ module GHC.Data.FastString
lengthPS
) where
-#include "HsVersions.h"
+-- For GHC_STAGE
+#include "ghcplatform.h"
import GHC.Prelude as Prelude
diff --git a/compiler/GHC/Utils/GlobalVars.hs b/compiler/GHC/Utils/GlobalVars.hs
index f169d07161..19496d5d82 100644
--- a/compiler/GHC/Utils/GlobalVars.hs
+++ b/compiler/GHC/Utils/GlobalVars.hs
@@ -3,6 +3,9 @@
{-# OPTIONS_GHC -fno-cse #-}
-- -fno-cse is needed for GLOBAL_VAR's to behave properly
+-- | Do not use global variables!
+--
+-- Global variables are a hack. Do not use them if you can help it.
module GHC.Utils.GlobalVars
( v_unsafeHasPprDebug
, v_unsafeHasNoDebugOutput
@@ -19,7 +22,8 @@ module GHC.Utils.GlobalVars
)
where
-#include "HsVersions.h"
+-- For GHC_STAGE
+#include "ghcplatform.h"
import GHC.Prelude
@@ -29,11 +33,32 @@ import System.IO.Unsafe
import Data.IORef
import Foreign (Ptr)
+#define GLOBAL_VAR(name,value,ty) \
+{-# NOINLINE name #-}; \
+name :: IORef (ty); \
+name = global (value);
+
+#define GLOBAL_VAR_M(name,value,ty) \
+{-# NOINLINE name #-}; \
+name :: IORef (ty); \
+name = globalM (value);
+
+
+#define SHARED_GLOBAL_VAR(name,accessor,saccessor,value,ty) \
+{-# NOINLINE name #-}; \
+name :: IORef (ty); \
+name = sharedGlobal (value) (accessor); \
+foreign import ccall unsafe saccessor \
+ accessor :: Ptr (IORef a) -> IO (Ptr (IORef a));
+
+#define SHARED_GLOBAL_VAR_M(name,accessor,saccessor,value,ty) \
+{-# NOINLINE name #-}; \
+name :: IORef (ty); \
+name = sharedGlobalM (value) (accessor); \
+foreign import ccall unsafe saccessor \
+ accessor :: Ptr (IORef a) -> IO (Ptr (IORef a));
+
---------------------------------------------------------------------------
--- Do not use global variables!
---
--- Global variables are a hack. Do not use them if you can help it.
#if GHC_STAGE < 2
diff --git a/compiler/HsVersions.h b/compiler/HsVersions.h
index e472b10002..b71613de97 100644
--- a/compiler/HsVersions.h
+++ b/compiler/HsVersions.h
@@ -1,8 +1,5 @@
#pragma once
--- For GHC_STAGE
-#include "ghcplatform.h"
-
#if 0
IMPORTANT! If you put extra tabs/spaces in these macro definitions,
@@ -12,32 +9,6 @@ you will screw up the layout where they are used in case expressions!
#endif
-#define GLOBAL_VAR(name,value,ty) \
-{-# NOINLINE name #-}; \
-name :: IORef (ty); \
-name = GHC.Utils.GlobalVars.global (value);
-
-#define GLOBAL_VAR_M(name,value,ty) \
-{-# NOINLINE name #-}; \
-name :: IORef (ty); \
-name = GHC.Utils.GlobalVars.globalM (value);
-
-
-#define SHARED_GLOBAL_VAR(name,accessor,saccessor,value,ty) \
-{-# NOINLINE name #-}; \
-name :: IORef (ty); \
-name = GHC.Utils.GlobalVars.sharedGlobal (value) (accessor);\
-foreign import ccall unsafe saccessor \
- accessor :: Ptr (IORef a) -> IO (Ptr (IORef a));
-
-#define SHARED_GLOBAL_VAR_M(name,accessor,saccessor,value,ty) \
-{-# NOINLINE name #-}; \
-name :: IORef (ty); \
-name = GHC.Utils.GlobalVars.sharedGlobalM (value) (accessor); \
-foreign import ccall unsafe saccessor \
- accessor :: Ptr (IORef a) -> IO (Ptr (IORef a));
-
-
#define ASSERT(e) if debugIsOn && not (e) then (assertPanic __FILE__ __LINE__) else
#define ASSERT2(e,msg) if debugIsOn && not (e) then (assertPprPanic __FILE__ __LINE__ (msg)) else
#define WARN( e, msg ) (warnPprTrace (e) __FILE__ __LINE__ (msg)) $