Commit a2a67cd5 authored by Simon Marlow's avatar Simon Marlow

RTS tidyup sweep, first phase

The first phase of this tidyup is focussed on the header files, and in
particular making sure we are exposinng publicly exactly what we need
to, and no more.

 - Rts.h now includes everything that the RTS exposes publicly,
   rather than a random subset of it.

 - Most of the public header files have moved into subdirectories, and
   many of them have been renamed.  But clients should not need to
   include any of the other headers directly, just #include the main
   public headers: Rts.h, HsFFI.h, RtsAPI.h.

 - All the headers needed for via-C compilation have moved into the
   stg subdirectory, which is self-contained.  Most of the headers for
   the rest of the RTS APIs have moved into the rts subdirectory.

 - I left MachDeps.h where it is, because it is so widely used in
   Haskell code.
 
 - I left a deprecated stub for RtsFlags.h in place.  The flag
   structures are now exposed by Rts.h.

 - Various internal APIs are no longer exposed by public header files.

 - Various bits of dead code and declarations have been removed

 - More gcc warnings are turned on, and the RTS code is more
   warning-clean.

 - More source files #include "PosixSource.h", and hence only use
   standard POSIX (1003.1c-1995) interfaces.

There is a lot more tidying up still to do, this is just the first
pass.  I also intend to standardise the names for external RTS APIs
(e.g use the rts_ prefix consistently), and declare the internal APIs
as hidden for shared libraries.
parent 5d379cbe
......@@ -58,7 +58,7 @@ cmmToRawCmm cmm = do
-- <normal forward rest of StgInfoTable>
-- <forward variable part>
--
-- See includes/InfoTables.h
-- See includes/rts/storage/InfoTables.h
--
-- For return-points these are as follows
--
......
......@@ -56,7 +56,7 @@ import Data.Maybe
-- Temp Jan08
import SMRep
import ClosureInfo
#include "../includes/StgFun.h"
#include "../includes/rts/storage/FunTypes.h"
pprCmms :: (Outputable info, Outputable g) => [GenCmm CmmStatic info g] -> SDoc
......
......@@ -64,7 +64,7 @@ import Data.Bits
-------------------------------------------------------------------------
-- bring in ARG_P, ARG_N, etc.
#include "../includes/StgFun.h"
#include "../includes/rts/storage/FunTypes.h"
-------------------------
argDescrType :: ArgDescr -> StgHalfWord
......
......@@ -24,9 +24,9 @@ module CgProf (
) where
#include "HsVersions.h"
#include "MachDeps.h"
#include "../includes/MachDeps.h"
-- For WORD_SIZE_IN_BITS only.
#include "../includes/Constants.h"
#include "../includes/rts/Constants.h"
-- For LDV_CREATE_MASK, LDV_STATE_USE
-- which are StgWords
#include "../includes/DerivedConstants.h"
......
......@@ -50,7 +50,7 @@ module CgUtils (
) where
#include "HsVersions.h"
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
import BlockId
import CgMonad
......
......@@ -246,7 +246,7 @@ data SMRep
| BlackHoleRep
data ClosureType -- Corresponds 1-1 with the varieties of closures
-- implemented by the RTS. Compare with ghc/includes/ClosureTypes.h
-- implemented by the RTS. Compare with includes/rts/storage/ClosureTypes.h
= Constr
| ConstrNoCaf
| Fun
......@@ -284,7 +284,7 @@ isStaticRep BlackHoleRep = False
\end{code}
\begin{code}
#include "../includes/ClosureTypes.h"
#include "../includes/rts/storage/ClosureTypes.h"
-- Defines CONSTR, CONSTR_1_0 etc
-- krc: only called by tickyDynAlloc in CgTicky; return
......
......@@ -313,7 +313,7 @@ mkVirtHeapOffsets is_thunk things
-------------------------------------------------------------------------
-- bring in ARG_P, ARG_N, etc.
#include "../includes/StgFun.h"
#include "../includes/rts/storage/FunTypes.h"
-------------------------
-- argDescrType :: ArgDescr -> StgHalfWord
......
......@@ -25,9 +25,9 @@ module StgCmmProf (
) where
#include "HsVersions.h"
#include "MachDeps.h"
#include "../includes/MachDeps.h"
-- For WORD_SIZE_IN_BITS only.
#include "../includes/Constants.h"
#include "../includes/rts/Constants.h"
-- For LDV_CREATE_MASK, LDV_STATE_USE
-- which are StgWords
#include "../includes/DerivedConstants.h"
......
......@@ -44,7 +44,7 @@ module StgCmmUtils (
) where
#include "HsVersions.h"
#include "MachRegs.h"
#include "../includes/stg/MachRegs.h"
import StgCmmMonad
import StgCmmClosure
......
......@@ -208,7 +208,7 @@ sizeSS16 :: SizedSeq a -> Word16
sizeSS16 (SizedSeq n _) = fromIntegral n
-- Bring in all the bci_ bytecode constants.
#include "Bytecodes.h"
#include "rts/Bytecodes.h"
largeArgInstr :: Word16 -> Word16
largeArgInstr bci = bci_FLAG_LARGE_ARGS .|. bci
......
......@@ -84,7 +84,7 @@ mkITbl tc
dcs = tyConDataCons tc
n = tyConFamilySize tc
#include "../includes/ClosureTypes.h"
#include "../includes/rts/storage/ClosureTypes.h"
cONSTR :: Int -- Defined in ClosureTypes.h
cONSTR = CONSTR
......@@ -151,7 +151,7 @@ ptrToInt (Ptr a#) = I# (addr2Int# a#)
#if sparc_TARGET_ARCH
-- After some consideration, we'll try this, where
-- 0x55555555 stands in for the address to jump to.
-- According to ghc/includes/MachRegs.h, %g3 is very
-- According to includes/rts/MachRegs.h, %g3 is very
-- likely indeed to be baggable.
--
-- 0000 07155555 sethi %hi(0x55555555), %g3
......
......@@ -165,7 +165,7 @@ data Closure = Closure { tipe :: ClosureType
instance Outputable ClosureType where
ppr = text . show
#include "../includes/ClosureTypes.h"
#include "../includes/rts/storage/ClosureTypes.h"
aP_CODE, pAP_CODE :: Int
aP_CODE = AP
......
......@@ -206,7 +206,7 @@ initBinMemSize :: Int
initBinMemSize = 1024 * 1024
-- The *host* architecture version:
#include "MachDeps.h"
#include "../includes/MachDeps.h"
binaryInterfaceMagic :: Word32
#if WORD_SIZE_IN_BITS == 32
......
......@@ -14,8 +14,8 @@ import Data.Bits (shiftL)
-- be in trouble.
#include "HsVersions.h"
#include "../includes/MachRegs.h"
#include "../includes/Constants.h"
#include "../includes/stg/MachRegs.h"
#include "../includes/rts/Constants.h"
#include "../includes/MachDeps.h"
#include "../includes/DerivedConstants.h"
......
......@@ -275,7 +275,7 @@ opt_Unregisterised = lookUp (fsLit "-funregisterised")
-- Derived, not a real option. Determines whether we will be compiling
-- info tables that reside just before the entry code, or with an
-- indirection to the entry code. See TABLES_NEXT_TO_CODE in
-- includes/InfoTables.h.
-- includes/rts/storage/InfoTables.h.
tablesNextToCode :: Bool
tablesNextToCode = not opt_Unregisterised
&& cGhcEnableTablesNextToCode == "YES"
......
......@@ -21,7 +21,7 @@ where
{-
#include "nativeGen/NCG.h"
#include "HsVersions.h"
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
import RegsBase
......
......@@ -22,7 +22,7 @@ where
#include "HsVersions.h"
#include "nativeGen/NCG.h"
#include "MachDeps.h"
#include "../includes/MachDeps.h"
-- NCG stuff:
import PPC.Instr
......
......@@ -49,7 +49,7 @@ where
#include "nativeGen/NCG.h"
#include "HsVersions.h"
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
import Reg
import RegClass
......
......@@ -43,7 +43,7 @@ import FastTypes
-- There is an allocatableRegsInClass :: RegClass -> Int, but doing the unboxing
-- is too slow for us here.
--
-- Look at includes/MachRegs.h to get these numbers.
-- Look at includes/stg/MachRegs.h to get these numbers.
--
#if i386_TARGET_ARCH
......
......@@ -115,7 +115,7 @@ import Data.Maybe
import Data.List
import Control.Monad
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
-- -----------------------------------------------------------------------------
......
......@@ -15,7 +15,7 @@ where
#include "HsVersions.h"
#include "nativeGen/NCG.h"
#include "MachDeps.h"
#include "../includes/MachDeps.h"
-- NCG stuff:
import SPARC.CodeGen.Sanity
......
......@@ -93,7 +93,7 @@ import FastBool
#define f31 63
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
-- | Check whether a machine register is free for allocation.
freeReg :: RegNo -> FastBool
......
......@@ -54,7 +54,7 @@ import FastBool
prepared for any eventuality.
The whole fp-register pairing thing on sparcs is a huge nuisance. See
fptools/ghc/includes/MachRegs.h for a description of what's going on
includes/stg/MachRegs.h for a description of what's going on
here.
-}
......@@ -290,11 +290,13 @@ regDotColor reg
-- Hard coded freeReg / globalRegMaybe -----------------------------------------
-- This isn't being used at the moment because we're generating
-- these functions from the information in includes/MachRegs.hs via RegPlate.hs
-- these functions from the information in
-- includes/stg/MachRegs.hs via RegPlate.hs
-- | Check whether a machine register is free for allocation.
-- This needs to match the info in includes/MachRegs.h otherwise modules
-- compiled with the NCG won't be compatible with via-C ones.
-- This needs to match the info in includes/stg/MachRegs.h
-- otherwise modules compiled with the NCG won't be compatible
-- with via-C ones.
--
{-
freeReg :: RegNo -> FastBool
......
......@@ -27,7 +27,7 @@ where
#include "HsVersions.h"
#include "nativeGen/NCG.h"
#include "MachDeps.h"
#include "../includes/MachDeps.h"
-- NCG stuff:
import X86.Instr
......
......@@ -466,7 +466,7 @@ pprDataItem lit
-- all such offsets will fit into 32 bits, so we have to stick
-- to 32-bit offset fields and modify the RTS appropriately
--
-- See Note [x86-64-relative] in includes/InfoTables.h
-- See Note [x86-64-relative] in includes/rts/storage/InfoTables.h
--
ppr_item II64 x
| isRelativeReloc x =
......
......@@ -54,7 +54,7 @@ where
-- HACK: go for the max
#endif
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
import Reg
import RegClass
......
......@@ -4,7 +4,9 @@ places in the GHC library.
*/
#include "Rts.h"
#if __GLASGOW_HASKELL__ <= 610
#include "RtsFlags.h"
#endif
#include "HsFFI.h"
......@@ -20,19 +22,19 @@ and causes gcc to require too many registers on x84
*/
HsInt
ghc_strlen( HsAddr a )
ghc_strlen( HsPtr a )
{
return (strlen((char *)a));
}
HsInt
ghc_memcmp( HsAddr a1, HsAddr a2, HsInt len )
ghc_memcmp( HsPtr a1, HsPtr a2, HsInt len )
{
return (memcmp((char *)a1, a2, len));
}
HsInt
ghc_memcmp_off( HsAddr a1, HsInt i, HsAddr a2, HsInt len )
ghc_memcmp_off( HsPtr a1, HsInt i, HsPtr a2, HsInt len )
{
return (memcmp((char *)a1 + i, a2, len));
}
......
......@@ -59,7 +59,7 @@ module Binary
#include "HsVersions.h"
-- The *host* architecture version:
#include "MachDeps.h"
#include "../includes/MachDeps.h"
import {-# SOURCE #-} Name (Name)
import FastString
......
......@@ -19,7 +19,7 @@ module FastMutInt(
#ifdef __GLASGOW_HASKELL__
#include "MachDeps.h"
#include "../includes/MachDeps.h"
#ifndef SIZEOF_HSINT
#define SIZEOF_HSINT INT_SIZE_IN_BYTES
#endif
......
......@@ -66,7 +66,6 @@
#define CMINUSMINUS 1
#include "ghcconfig.h"
#include "RtsConfig.h"
/* -----------------------------------------------------------------------------
Types
......@@ -144,6 +143,18 @@
name : bits8[] str; \
} \
#ifdef TABLES_NEXT_TO_CODE
#define RET_LBL(f) f##_info
#else
#define RET_LBL(f) f##_ret
#endif
#ifdef TABLES_NEXT_TO_CODE
#define ENTRY_LBL(f) f##_info
#else
#define ENTRY_LBL(f) f##_entry
#endif
/* -----------------------------------------------------------------------------
Byte/word macros
......@@ -320,26 +331,26 @@
Constants.
-------------------------------------------------------------------------- */
#include "Constants.h"
#include "rts/Constants.h"
#include "DerivedConstants.h"
#include "ClosureTypes.h"
#include "StgFun.h"
#include "OSThreads.h"
#include "SMPClosureOps.h"
#include "rts/storage/ClosureTypes.h"
#include "rts/storage/FunTypes.h"
#include "rts/storage/SMPClosureOps.h"
#include "rts/OSThreads.h"
/*
* Need MachRegs, because some of the RTS code is conditionally
* compiled based on REG_R1, REG_R2, etc.
*/
#define STOLEN_X86_REGS 4
#include "MachRegs.h"
#include "stg/MachRegs.h"
#include "Liveness.h"
#include "StgLdvProf.h"
#include "rts/storage/Liveness.h"
#include "rts/prof/LDV.h"
#undef BLOCK_SIZE
#undef MBLOCK_SIZE
#include "Block.h" /* For Bdescr() */
#include "rts/storage/Block.h" /* For Bdescr() */
#define MyCapability() (BaseReg - OFFSET_Capability_r)
......
This diff is collapsed.
......@@ -18,8 +18,7 @@ extern "C" {
/* get types from GHC's runtime system */
#include "ghcconfig.h"
#include "RtsConfig.h"
#include "StgTypes.h"
#include "stg/Types.h"
/* get limits for integral types */
#ifdef HAVE_STDINT_H
......@@ -84,10 +83,7 @@ typedef StgDouble HsDouble;
typedef StgInt HsBool;
typedef void* HsPtr; /* this should better match StgAddr */
typedef void (*HsFunPtr)(void); /* this should better match StgAddr */
typedef void* HsForeignPtr; /* ... and this StgForeignPtr */
typedef void* HsStablePtr;
typedef void* HsAddr; /* DEPRECATED */
typedef void* HsForeignObj; /* DEPRECATED */
/* this should correspond to the type of StgChar in StgTypes.h */
#define HS_CHAR_MIN 0
......
......@@ -58,9 +58,6 @@
#define SIZEOF_HSFUNPTR SIZEOF_VOID_P
#define ALIGNMENT_HSFUNPTR ALIGNMENT_VOID_P
#define SIZEOF_HSFOREIGNPTR SIZEOF_VOID_P
#define ALIGNMENT_HSFOREIGNPTR ALIGNMENT_VOID_P
#define SIZEOF_HSSTABLEPTR SIZEOF_VOID_P
#define ALIGNMENT_HSSTABLEPTR ALIGNMENT_VOID_P
......
This diff is collapsed.
......@@ -83,17 +83,14 @@ Rts.h
SpinLock.h
TSO.h
Updates.h /* macros for performing updates */
GranSim.h
Parallel.h
Block.h
Stable.h
Hooks.h
Signals.h
DNInvoke.h
Dotnet.h
RtsExternal.h /* decls for RTS things required by .hc code */
(RtsAPI.h)
(HsFFI.h)
Adjustor.h /* foreign import "wrapper", aka adjustors */
StgPrimFloat.h /* primitive floating-point operations */
Hpc.h
Cmm.h /* included into .cmm source only */
DerivedConstants.h /* generated by mkDerivedConstants.c from other */
......
/* -----------------------------------------------------------------------------
*
* (c) The GHC Team, 1998-2004
* (c) The GHC Team, 1998-2009
*
* Top-level include file for the RTS itself
* RTS external APIs. This file declares everything that the GHC RTS
* exposes externally.
*
* ---------------------------------------------------------------------------*/
......@@ -18,8 +19,8 @@ extern "C" {
#endif
#include "Stg.h"
// ToDo: move RtsExternal stuff elsewhere
#include "RtsExternal.h"
#include "HsFFI.h"
#include "RtsAPI.h"
// Turn off inlining when debugging - it obfuscates things
#ifdef DEBUG
......@@ -27,7 +28,7 @@ extern "C" {
# define STATIC_INLINE static
#endif
#include "RtsTypes.h"
#include "rts/Types.h"
#if __GNUC__ >= 3
/* Assume that a flexible array member at the end of a struct
......@@ -63,11 +64,6 @@ extern "C" {
#define sizeofW(t) ROUNDUP_BYTES_TO_WDS(sizeof(t))
/*
* It's nice to be able to grep for casts
*/
#define stgCast(ty,e) ((ty)(e))
/* -----------------------------------------------------------------------------
Assertions and Debuggery
......@@ -75,7 +71,8 @@ extern "C" {
ASSERT(p) like CHECK(p) if DEBUG is on, otherwise a no-op
-------------------------------------------------------------------------- */
extern void _assertFail (const char *, unsigned int);
void _assertFail(const char *filename, unsigned int linenum)
GNUC3_ATTRIBUTE(__noreturn__);
#define CHECK(predicate) \
if (predicate) \
......@@ -124,29 +121,6 @@ extern void _assertFail (const char *, unsigned int);
#define FMT_Int64 "lld"
#endif
/*
* Macros for untagging and retagging closure pointers
* For more information look at the comments in Cmm.h
*/
static inline StgWord
GET_CLOSURE_TAG(StgClosure * p)
{
return (StgWord)p & TAG_MASK;
}
static inline StgClosure *
UNTAG_CLOSURE(StgClosure * p)
{
return (StgClosure*)((StgWord)p & ~TAG_MASK);
}
static inline StgClosure *
TAG_CLOSURE(StgWord tag,StgClosure * p)
{
return (StgClosure*)((StgWord)p | tag);
}
/* -----------------------------------------------------------------------------
Include everything STG-ish
-------------------------------------------------------------------------- */
......@@ -158,59 +132,62 @@ TAG_CLOSURE(StgWord tag,StgClosure * p)
*/
#include <stdlib.h>
#include "rts/Config.h"
/* Global constaints */
#include "Constants.h"
#include "rts/Constants.h"
/* Profiling information */
#include "StgProf.h"
#include "StgLdvProf.h"
/* Storage format definitions */
#include "StgFun.h"
#include "Closures.h"
#include "Liveness.h"
#include "ClosureTypes.h"
#include "InfoTables.h"
#include "TSO.h"
/* Info tables, closures & code fragments defined in the RTS */
#include "StgMiscClosures.h"
#include "rts/prof/CCS.h"
#include "rts/prof/LDV.h"
/* Parallel information */
#include "OSThreads.h"
#include "SMPClosureOps.h"
#include "SpinLock.h"
/* Macros for STG/C code */
#include "Block.h"
#include "ClosureMacros.h"
/* Runtime-system hooks */
#include "Hooks.h"
#include "RtsMessages.h"
#include "rts/OSThreads.h"
#include "rts/SpinLock.h"
/* for StablePtr/getStablePtr/deRefStablePtr */
#include "Storage.h"
#include "Stable.h"
#include "rts/Messages.h"
#include "ieee-flpt.h"
#include "Signals.h"
/* Storage format definitions */
#include "rts/storage/FunTypes.h"
#include "rts/storage/InfoTables.h"
#include "rts/storage/Closures.h"
#include "rts/storage/Liveness.h"
#include "rts/storage/ClosureTypes.h"
#include "rts/storage/TSO.h"
#include "stg/MiscClosures.h" /* InfoTables, closures etc. defined in the RTS */
#include "rts/storage/SMPClosureOps.h"
#include "rts/storage/Block.h"
#include "rts/storage/ClosureMacros.h"
#include "rts/storage/MBlock.h"
#include "rts/storage/GC.h"
/* Other RTS external APIs */
#include "rts/Parallel.h"
#include "rts/Hooks.h"
#include "rts/Signals.h"
#include "rts/Hpc.h"
#include "rts/Flags.h"
#include "rts/Adjustor.h"
#include "rts/FileLock.h"
#include "rts/Globals.h"
#include "rts/IOManager.h"
#include "rts/Linker.h"
#include "rts/Threads.h"
#include "rts/Timer.h"
#include "rts/Stable.h"
/* Misc stuff without a home */
DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
DLL_IMPORT_RTS extern int prog_argc;
DLL_IMPORT_RTS extern char *prog_name;
extern void stackOverflow(void);
extern void __decodeDouble_2Int (I_ *man_sign, W_ *man_high, W_ *man_low, I_ *exp, StgDouble dbl);
extern void __decodeFloat_Int (I_ *man, I_ *exp, StgFloat flt);
void stackOverflow(void);
/* Initialising the whole adjustor thunk machinery. */
extern void initAdjustor(void);
void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
#ifndef mingw32_HOST_OS
int stg_sig_install (int, int, void *);
#endif
/* -----------------------------------------------------------------------------
RTS Exit codes
......@@ -236,11 +213,6 @@ extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
extern StgInt RIGHT_ARITY_##arity; \
extern StgInt TAGGED_PTR_##arity;
#define TICK_VAR_INI(arity) \
StgInt SLOW_CALLS_##arity = 1; \
StgInt RIGHT_ARITY_##arity = 1; \
StgInt TAGGED_PTR_##arity = 0;
extern StgInt TOTAL_CALLS;
TICK_VAR(1)
......@@ -253,10 +225,6 @@ TICK_VAR(2)
#define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
/* -----------------------------------------------------------------------------
Assertions and Debuggery
-------------------------------------------------------------------------- */
#ifdef DEBUG
#if IN_STG_CODE
#define IF_DEBUG(c,s) if (RtsFlags[0].DebugFlags.c) { s; }
......
......@@ -26,7 +26,7 @@ typedef enum {
HeapExhausted /* out of memory */
} SchedulerStatus;
typedef StgClosure *HaskellObj;
typedef struct StgClosure_ *HaskellObj;
/*
* An abstract type representing the token returned by rts_lock() and
......