Commit 995cf0f3 authored by Erik de Castro Lopo's avatar Erik de Castro Lopo Committed by Ben Gamari

rts: Make function pointer parameters `const` where possible

If a function takes a pointer parameter and doesn't update what
the pointer points to, we can add `const` to the parameter
declaration to document that no updates occur.

Test Plan: Validate on Linux, OS X and Windows

Reviewers: austin, Phyx, bgamari, simonmar, hsyl20

Reviewed By: bgamari, simonmar, hsyl20

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2200
parent 69c974fe
...@@ -194,13 +194,13 @@ INLINE_HEADER P_ INTLIKE_CLOSURE(int n) { ...@@ -194,13 +194,13 @@ INLINE_HEADER P_ INTLIKE_CLOSURE(int n) {
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
static inline StgWord static inline StgWord
GET_CLOSURE_TAG(StgClosure * p) GET_CLOSURE_TAG(const StgClosure * p)
{ {
return (StgWord)p & TAG_MASK; return (StgWord)p & TAG_MASK;
} }
static inline StgClosure * static inline StgClosure *
UNTAG_CLOSURE(StgClosure * p) UNTAG_CLOSURE(const StgClosure * p)
{ {
return (StgClosure*)((StgWord)p & ~TAG_MASK); return (StgClosure*)((StgWord)p & ~TAG_MASK);
} }
...@@ -247,7 +247,7 @@ INLINE_HEADER rtsBool LOOKS_LIKE_INFO_PTR (StgWord p) ...@@ -247,7 +247,7 @@ INLINE_HEADER rtsBool LOOKS_LIKE_INFO_PTR (StgWord p)
return (p && (IS_FORWARDING_PTR(p) || LOOKS_LIKE_INFO_PTR_NOT_NULL(p))) ? rtsTrue : rtsFalse; return (p && (IS_FORWARDING_PTR(p) || LOOKS_LIKE_INFO_PTR_NOT_NULL(p))) ? rtsTrue : rtsFalse;
} }
INLINE_HEADER rtsBool LOOKS_LIKE_CLOSURE_PTR (void *p) INLINE_HEADER rtsBool LOOKS_LIKE_CLOSURE_PTR (const void *p)
{ {
return LOOKS_LIKE_INFO_PTR((StgWord)(UNTAG_CLOSURE((StgClosure *)(p)))->header.info); return LOOKS_LIKE_INFO_PTR((StgWord)(UNTAG_CLOSURE((StgClosure *)(p)))->header.info);
} }
...@@ -337,9 +337,9 @@ EXTERN_INLINE StgWord bco_sizeW ( StgBCO *bco ) ...@@ -337,9 +337,9 @@ EXTERN_INLINE StgWord bco_sizeW ( StgBCO *bco )
* *
* (Also for 'closure_sizeW' below) * (Also for 'closure_sizeW' below)
*/ */
EXTERN_INLINE uint32_t closure_sizeW_ (StgClosure *p, StgInfoTable *info); EXTERN_INLINE uint32_t closure_sizeW_ (const StgClosure *p, StgInfoTable *info);
EXTERN_INLINE uint32_t EXTERN_INLINE uint32_t
closure_sizeW_ (StgClosure *p, StgInfoTable *info) closure_sizeW_ (const StgClosure *p, StgInfoTable *info)
{ {
switch (info->type) { switch (info->type) {
case THUNK_0_1: case THUNK_0_1:
...@@ -399,8 +399,8 @@ closure_sizeW_ (StgClosure *p, StgInfoTable *info) ...@@ -399,8 +399,8 @@ closure_sizeW_ (StgClosure *p, StgInfoTable *info)
} }
// The definitive way to find the size, in words, of a heap-allocated closure // The definitive way to find the size, in words, of a heap-allocated closure
EXTERN_INLINE uint32_t closure_sizeW (StgClosure *p); EXTERN_INLINE uint32_t closure_sizeW (const StgClosure *p);
EXTERN_INLINE uint32_t closure_sizeW (StgClosure *p) EXTERN_INLINE uint32_t closure_sizeW (const StgClosure *p)
{ {
return closure_sizeW_(p, get_itbl(p)); return closure_sizeW_(p, get_itbl(p));
} }
...@@ -505,7 +505,7 @@ INLINE_HEADER StgWord8 *mutArrPtrsCard (StgMutArrPtrs *a, W_ n) ...@@ -505,7 +505,7 @@ INLINE_HEADER StgWord8 *mutArrPtrsCard (StgMutArrPtrs *a, W_ n)
#endif #endif
#ifdef PROFILING #ifdef PROFILING
void LDV_recordDead (StgClosure *c, uint32_t size); void LDV_recordDead (const StgClosure *c, uint32_t size);
#endif #endif
EXTERN_INLINE void overwritingClosure (StgClosure *p); EXTERN_INLINE void overwritingClosure (StgClosure *p);
......
...@@ -260,7 +260,7 @@ extern PendingSync * volatile pending_sync; ...@@ -260,7 +260,7 @@ extern PendingSync * volatile pending_sync;
// //
void waitForCapability (Capability **cap/*in/out*/, Task *task); void waitForCapability (Capability **cap/*in/out*/, Task *task);
EXTERN_INLINE void recordMutableCap (StgClosure *p, Capability *cap, EXTERN_INLINE void recordMutableCap (const StgClosure *p, Capability *cap,
uint32_t gen); uint32_t gen);
EXTERN_INLINE void recordClosureMutated (Capability *cap, StgClosure *p); EXTERN_INLINE void recordClosureMutated (Capability *cap, StgClosure *p);
...@@ -354,7 +354,7 @@ INLINE_HEADER rtsBool emptyInbox(Capability *cap); ...@@ -354,7 +354,7 @@ INLINE_HEADER rtsBool emptyInbox(Capability *cap);
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
EXTERN_INLINE void EXTERN_INLINE void
recordMutableCap (StgClosure *p, Capability *cap, uint32_t gen) recordMutableCap (const StgClosure *p, Capability *cap, uint32_t gen)
{ {
bdescr *bd; bdescr *bd;
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* header portion, so that the caller can find the next closure. * header portion, so that the caller can find the next closure.
* ----------------------------------------------------------------------- */ * ----------------------------------------------------------------------- */
STATIC_INLINE uint32_t STATIC_INLINE uint32_t
processHeapClosureForDead( StgClosure *c ) processHeapClosureForDead( const StgClosure *c )
{ {
uint32_t size; uint32_t size;
const StgInfoTable *info; const StgInfoTable *info;
......
...@@ -96,7 +96,7 @@ static void aggregateCensusInfo( void ); ...@@ -96,7 +96,7 @@ static void aggregateCensusInfo( void );
static void dumpCensus( Census *census ); static void dumpCensus( Census *census );
static rtsBool closureSatisfiesConstraints( StgClosure* p ); static rtsBool closureSatisfiesConstraints( const StgClosure* p );
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Find the "closure identity", which is a unique pointer representing * Find the "closure identity", which is a unique pointer representing
...@@ -104,7 +104,7 @@ static rtsBool closureSatisfiesConstraints( StgClosure* p ); ...@@ -104,7 +104,7 @@ static rtsBool closureSatisfiesConstraints( StgClosure* p );
* heap profile. * heap profile.
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
static void * static void *
closureIdentity( StgClosure *p ) closureIdentity( const StgClosure *p )
{ {
switch (RtsFlags.ProfFlags.doHeapProfile) { switch (RtsFlags.ProfFlags.doHeapProfile) {
...@@ -181,7 +181,7 @@ doingRetainerProfiling( void ) ...@@ -181,7 +181,7 @@ doingRetainerProfiling( void )
#ifdef PROFILING #ifdef PROFILING
void void
LDV_recordDead( StgClosure *c, uint32_t size ) LDV_recordDead( const StgClosure *c, uint32_t size )
{ {
void *id; void *id;
uint32_t t; uint32_t t;
...@@ -576,7 +576,7 @@ strMatchesSelector( const char* str, const char* sel ) ...@@ -576,7 +576,7 @@ strMatchesSelector( const char* str, const char* sel )
* testing against all the specified constraints. * testing against all the specified constraints.
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
static rtsBool static rtsBool
closureSatisfiesConstraints( StgClosure* p ) closureSatisfiesConstraints( const StgClosure* p )
{ {
#if !defined(PROFILING) #if !defined(PROFILING)
(void)p; /* keep gcc -Wall happy */ (void)p; /* keep gcc -Wall happy */
......
...@@ -33,7 +33,7 @@ extern StgWord flip; ...@@ -33,7 +33,7 @@ extern StgWord flip;
((((StgWord)(c)->header.prof.hp.rs & 1) ^ flip) == 0) ((((StgWord)(c)->header.prof.hp.rs & 1) ^ flip) == 0)
static inline RetainerSet * static inline RetainerSet *
retainerSetOf( StgClosure *c ) retainerSetOf( const StgClosure *c )
{ {
ASSERT( isRetainerSetFieldValid(c) ); ASSERT( isRetainerSetFieldValid(c) );
// StgWord has the same size as pointers, so the following type // StgWord has the same size as pointers, so the following type
......
...@@ -162,10 +162,10 @@ typedef struct { ...@@ -162,10 +162,10 @@ typedef struct {
extern W_ mpc_misses; extern W_ mpc_misses;
StgBool HEAP_ALLOCED_miss(StgWord mblock, void *p); StgBool HEAP_ALLOCED_miss(StgWord mblock, const void *p);
INLINE_HEADER INLINE_HEADER
StgBool HEAP_ALLOCED(void *p) StgBool HEAP_ALLOCED(const void *p)
{ {
StgWord mblock; StgWord mblock;
uint32_t entry_no; uint32_t entry_no;
......
...@@ -359,7 +359,7 @@ uint32_t mblock_map_count = 0; ...@@ -359,7 +359,7 @@ uint32_t mblock_map_count = 0;
MbcCacheLine mblock_cache[MBC_ENTRIES]; MbcCacheLine mblock_cache[MBC_ENTRIES];
static MBlockMap * static MBlockMap *
findMBlockMap(void *p) findMBlockMap(const void *p)
{ {
uint32_t i; uint32_t i;
StgWord32 hi = (StgWord32) (((StgWord)p) >> 32); StgWord32 hi = (StgWord32) (((StgWord)p) >> 32);
...@@ -373,7 +373,7 @@ findMBlockMap(void *p) ...@@ -373,7 +373,7 @@ findMBlockMap(void *p)
return NULL; return NULL;
} }
StgBool HEAP_ALLOCED_miss(StgWord mblock, void *p) StgBool HEAP_ALLOCED_miss(StgWord mblock, const void *p)
{ {
MBlockMap *map; MBlockMap *map;
MBlockMapLine value; MBlockMapLine value;
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
static void checkSmallBitmap ( StgPtr payload, StgWord bitmap, uint32_t ); static void checkSmallBitmap ( StgPtr payload, StgWord bitmap, uint32_t );
static void checkLargeBitmap ( StgPtr payload, StgLargeBitmap*, uint32_t ); static void checkLargeBitmap ( StgPtr payload, StgLargeBitmap*, uint32_t );
static void checkClosureShallow ( StgClosure * ); static void checkClosureShallow ( const StgClosure * );
static void checkSTACK (StgStack *stack); static void checkSTACK (StgStack *stack);
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
...@@ -79,9 +79,9 @@ checkLargeBitmap( StgPtr payload, StgLargeBitmap* large_bitmap, uint32_t size ) ...@@ -79,9 +79,9 @@ checkLargeBitmap( StgPtr payload, StgLargeBitmap* large_bitmap, uint32_t size )
*/ */
static void static void
checkClosureShallow( StgClosure* p ) checkClosureShallow( const StgClosure* p )
{ {
StgClosure *q; const StgClosure *q;
q = UNTAG_CLOSURE(p); q = UNTAG_CLOSURE(p);
ASSERT(LOOKS_LIKE_CLOSURE_PTR(q)); ASSERT(LOOKS_LIKE_CLOSURE_PTR(q));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment