[commit: ghc] wip/erikd/remove-nat: rts: Make function pointer parameters `const` where possible (f97c3f4)

git at git.haskell.org git at git.haskell.org
Thu May 12 03:08:22 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/erikd/remove-nat
Link       : http://ghc.haskell.org/trac/ghc/changeset/f97c3f40df51d434bc47d5d17d1daba2848d3bcb/ghc

>---------------------------------------------------------------

commit f97c3f40df51d434bc47d5d17d1daba2848d3bcb
Author: Erik de Castro Lopo <erikd at mega-nerd.com>
Date:   Mon May 9 21:14:50 2016 +1000

    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.


>---------------------------------------------------------------

f97c3f40df51d434bc47d5d17d1daba2848d3bcb
 includes/rts/storage/ClosureMacros.h | 16 ++++++++--------
 rts/Capability.h                     |  4 ++--
 rts/LdvProfile.c                     |  2 +-
 rts/ProfHeap.c                       |  8 ++++----
 rts/RetainerProfile.h                |  2 +-
 rts/sm/HeapAlloc.h                   |  4 ++--
 rts/sm/MBlock.c                      |  4 ++--
 rts/sm/Sanity.c                      |  6 +++---
 8 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/includes/rts/storage/ClosureMacros.h b/includes/rts/storage/ClosureMacros.h
index d7ae5ea..5ed6928 100644
--- a/includes/rts/storage/ClosureMacros.h
+++ b/includes/rts/storage/ClosureMacros.h
@@ -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);
diff --git a/rts/Capability.h b/rts/Capability.h
index 46ae8b9..22c1d2a 100644
--- a/rts/Capability.h
+++ b/rts/Capability.h
@@ -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;
 
diff --git a/rts/LdvProfile.c b/rts/LdvProfile.c
index 1dfdc56..428078b 100644
--- a/rts/LdvProfile.c
+++ b/rts/LdvProfile.c
@@ -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;
diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c
index def490d..e98704d 100644
--- a/rts/ProfHeap.c
+++ b/rts/ProfHeap.c
@@ -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 */
diff --git a/rts/RetainerProfile.h b/rts/RetainerProfile.h
index d92563f..180c4e2 100644
--- a/rts/RetainerProfile.h
+++ b/rts/RetainerProfile.h
@@ -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
diff --git a/rts/sm/HeapAlloc.h b/rts/sm/HeapAlloc.h
index a867a48..0ec1e6d 100644
--- a/rts/sm/HeapAlloc.h
+++ b/rts/sm/HeapAlloc.h
@@ -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;
diff --git a/rts/sm/MBlock.c b/rts/sm/MBlock.c
index 11b12d1..440b03e 100644
--- a/rts/sm/MBlock.c
+++ b/rts/sm/MBlock.c
@@ -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;
diff --git a/rts/sm/Sanity.c b/rts/sm/Sanity.c
index 794bce7..2abe56b 100644
--- a/rts/sm/Sanity.c
+++ b/rts/sm/Sanity.c
@@ -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));



More information about the ghc-commits mailing list