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) {
------------------------------------------------------------------------- */
static inline StgWord
GET_CLOSURE_TAG(StgClosure * p)
GET_CLOSURE_TAG(const StgClosure * p)
{
return (StgWord)p & TAG_MASK;
}
static inline StgClosure *
UNTAG_CLOSURE(StgClosure * p)
UNTAG_CLOSURE(const StgClosure * p)
{
return (StgClosure*)((StgWord)p & ~TAG_MASK);
}
......@@ -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;
}
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);
}
......@@ -337,9 +337,9 @@ EXTERN_INLINE StgWord bco_sizeW ( StgBCO *bco )
*
* (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
closure_sizeW_ (StgClosure *p, StgInfoTable *info)
closure_sizeW_ (const StgClosure *p, StgInfoTable *info)
{
switch (info->type) {
case THUNK_0_1:
......@@ -399,8 +399,8 @@ closure_sizeW_ (StgClosure *p, StgInfoTable *info)
}
// 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 (StgClosure *p)
EXTERN_INLINE uint32_t closure_sizeW (const StgClosure *p);
EXTERN_INLINE uint32_t closure_sizeW (const StgClosure *p)
{
return closure_sizeW_(p, get_itbl(p));
}
......@@ -505,7 +505,7 @@ INLINE_HEADER StgWord8 *mutArrPtrsCard (StgMutArrPtrs *a, W_ n)
#endif
#ifdef PROFILING
void LDV_recordDead (StgClosure *c, uint32_t size);
void LDV_recordDead (const StgClosure *c, uint32_t size);
#endif
EXTERN_INLINE void overwritingClosure (StgClosure *p);
......
......@@ -260,7 +260,7 @@ extern PendingSync * volatile pending_sync;
//
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);
EXTERN_INLINE void recordClosureMutated (Capability *cap, StgClosure *p);
......@@ -354,7 +354,7 @@ INLINE_HEADER rtsBool emptyInbox(Capability *cap);
* -------------------------------------------------------------------------- */
EXTERN_INLINE void
recordMutableCap (StgClosure *p, Capability *cap, uint32_t gen)
recordMutableCap (const StgClosure *p, Capability *cap, uint32_t gen)
{
bdescr *bd;
......
......@@ -28,7 +28,7 @@
* header portion, so that the caller can find the next closure.
* ----------------------------------------------------------------------- */
STATIC_INLINE uint32_t
processHeapClosureForDead( StgClosure *c )
processHeapClosureForDead( const StgClosure *c )
{
uint32_t size;
const StgInfoTable *info;
......
......@@ -96,7 +96,7 @@ static void aggregateCensusInfo( void );
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
......@@ -104,7 +104,7 @@ static rtsBool closureSatisfiesConstraints( StgClosure* p );
* heap profile.
* ------------------------------------------------------------------------- */
static void *
closureIdentity( StgClosure *p )
closureIdentity( const StgClosure *p )
{
switch (RtsFlags.ProfFlags.doHeapProfile) {
......@@ -181,7 +181,7 @@ doingRetainerProfiling( void )
#ifdef PROFILING
void
LDV_recordDead( StgClosure *c, uint32_t size )
LDV_recordDead( const StgClosure *c, uint32_t size )
{
void *id;
uint32_t t;
......@@ -576,7 +576,7 @@ strMatchesSelector( const char* str, const char* sel )
* testing against all the specified constraints.
* -------------------------------------------------------------------------- */
static rtsBool
closureSatisfiesConstraints( StgClosure* p )
closureSatisfiesConstraints( const StgClosure* p )
{
#if !defined(PROFILING)
(void)p; /* keep gcc -Wall happy */
......
......@@ -33,7 +33,7 @@ extern StgWord flip;
((((StgWord)(c)->header.prof.hp.rs & 1) ^ flip) == 0)
static inline RetainerSet *
retainerSetOf( StgClosure *c )
retainerSetOf( const StgClosure *c )
{
ASSERT( isRetainerSetFieldValid(c) );
// StgWord has the same size as pointers, so the following type
......
......@@ -162,10 +162,10 @@ typedef struct {
extern W_ mpc_misses;
StgBool HEAP_ALLOCED_miss(StgWord mblock, void *p);
StgBool HEAP_ALLOCED_miss(StgWord mblock, const void *p);
INLINE_HEADER
StgBool HEAP_ALLOCED(void *p)
StgBool HEAP_ALLOCED(const void *p)
{
StgWord mblock;
uint32_t entry_no;
......
......@@ -359,7 +359,7 @@ uint32_t mblock_map_count = 0;
MbcCacheLine mblock_cache[MBC_ENTRIES];
static MBlockMap *
findMBlockMap(void *p)
findMBlockMap(const void *p)
{
uint32_t i;
StgWord32 hi = (StgWord32) (((StgWord)p) >> 32);
......@@ -373,7 +373,7 @@ findMBlockMap(void *p)
return NULL;
}
StgBool HEAP_ALLOCED_miss(StgWord mblock, void *p)
StgBool HEAP_ALLOCED_miss(StgWord mblock, const void *p)
{
MBlockMap *map;
MBlockMapLine value;
......
......@@ -35,7 +35,7 @@
static void checkSmallBitmap ( StgPtr payload, StgWord bitmap, uint32_t );
static void checkLargeBitmap ( StgPtr payload, StgLargeBitmap*, uint32_t );
static void checkClosureShallow ( StgClosure * );
static void checkClosureShallow ( const StgClosure * );
static void checkSTACK (StgStack *stack);
/* -----------------------------------------------------------------------------
......@@ -79,9 +79,9 @@ checkLargeBitmap( StgPtr payload, StgLargeBitmap* large_bitmap, uint32_t size )
*/
static void
checkClosureShallow( StgClosure* p )
checkClosureShallow( const StgClosure* p )
{
StgClosure *q;
const StgClosure *q;
q = UNTAG_CLOSURE(p);
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