From 95b4ac3275c2c6a9aa17081f67a65d2c1291d2c7 Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Wed, 28 Feb 2024 19:12:11 +0000
Subject: [PATCH] rts: expose HeapAlloc.h as public header

This commit exposes HeapAlloc.h as a public header. The intention is
to expose HEAP_ALLOCED/HEAP_ALLOCED_GC, so they can be used in
assertions in other public headers, and they may also be useful for
user code.

(cherry picked from commit dedcf102e5dee3cbb365e5acf8d500581148e6bb)
---
 rts/Sparks.c                                | 2 +-
 rts/{sm => include/rts/storage}/HeapAlloc.h | 4 ----
 rts/posix/OSMem.c                           | 2 +-
 rts/rts.cabal.in                            | 1 +
 rts/sm/CNF.c                                | 2 +-
 rts/sm/GC.h                                 | 2 +-
 rts/sm/NonMoving.h                          | 2 +-
 rts/sm/NonMovingMark.c                      | 2 +-
 rts/sm/Sanity.c                             | 2 +-
 rts/wasm/OSMem.c                            | 2 +-
 rts/win32/OSMem.c                           | 2 +-
 11 files changed, 10 insertions(+), 13 deletions(-)
 rename rts/{sm => include/rts/storage}/HeapAlloc.h (99%)

diff --git a/rts/Sparks.c b/rts/Sparks.c
index 2b4bb22ab3e..8e72e47c30a 100644
--- a/rts/Sparks.c
+++ b/rts/Sparks.c
@@ -16,7 +16,7 @@
 #include "Sparks.h"
 #include "ThreadLabels.h"
 #include "sm/NonMovingMark.h"
-#include "sm/HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 
 #if defined(THREADED_RTS)
 
diff --git a/rts/sm/HeapAlloc.h b/rts/include/rts/storage/HeapAlloc.h
similarity index 99%
rename from rts/sm/HeapAlloc.h
rename to rts/include/rts/storage/HeapAlloc.h
index 32210d12974..e18bdb9c8e9 100644
--- a/rts/sm/HeapAlloc.h
+++ b/rts/include/rts/storage/HeapAlloc.h
@@ -8,8 +8,6 @@
 
 #pragma once
 
-#include "BeginPrivate.h"
-
 #if defined(THREADED_RTS)
 // needed for HEAP_ALLOCED below
 extern SpinLock gc_alloc_block_sync;
@@ -227,5 +225,3 @@ StgBool HEAP_ALLOCED_GC(const void *p)
 #else
 # error HEAP_ALLOCED not defined
 #endif
-
-#include "EndPrivate.h"
diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index e08dfca8b64..d20a656a4bb 100644
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -13,7 +13,7 @@
 
 #include "RtsUtils.h"
 #include "sm/OSMem.h"
-#include "sm/HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 
 #if defined(HAVE_UNISTD_H)
 #include <unistd.h>
diff --git a/rts/rts.cabal.in b/rts/rts.cabal.in
index bd2a5f4261e..c8da60df7a6 100644
--- a/rts/rts.cabal.in
+++ b/rts/rts.cabal.in
@@ -287,6 +287,7 @@ library
                         rts/storage/Closures.h
                         rts/storage/FunTypes.h
                         rts/storage/Heap.h
+                        rts/storage/HeapAlloc.h
                         rts/storage/GC.h
                         rts/storage/InfoTables.h
                         rts/storage/MBlock.h
diff --git a/rts/sm/CNF.c b/rts/sm/CNF.c
index 1f40402c634..17cfdc98ec5 100644
--- a/rts/sm/CNF.c
+++ b/rts/sm/CNF.c
@@ -19,7 +19,7 @@
 #include "Storage.h"
 #include "CNF.h"
 #include "Hash.h"
-#include "HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 #include "BlockAlloc.h"
 #include "Trace.h"
 #include "sm/ShouldCompact.h"
diff --git a/rts/sm/GC.h b/rts/sm/GC.h
index dc7b773e999..0beabc8e6d1 100644
--- a/rts/sm/GC.h
+++ b/rts/sm/GC.h
@@ -13,7 +13,7 @@
 
 #pragma once
 
-#include "HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 
 #include "BeginPrivate.h"
 
diff --git a/rts/sm/NonMoving.h b/rts/sm/NonMoving.h
index 99f2767d4ea..d48f09a9c67 100644
--- a/rts/sm/NonMoving.h
+++ b/rts/sm/NonMoving.h
@@ -11,7 +11,7 @@
 #if !defined(CMINUSMINUS)
 
 #include <string.h>
-#include "HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 #include "NonMovingMark.h"
 
 #include "BeginPrivate.h"
diff --git a/rts/sm/NonMovingMark.c b/rts/sm/NonMovingMark.c
index 2bb1781e2a9..f49ac2dfb0e 100644
--- a/rts/sm/NonMovingMark.c
+++ b/rts/sm/NonMovingMark.c
@@ -14,7 +14,7 @@
 #include "NonMovingShortcut.h"
 #include "NonMoving.h"
 #include "BlockAlloc.h"  /* for countBlocks */
-#include "HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 #include "Task.h"
 #include "Trace.h"
 #include "HeapUtils.h"
diff --git a/rts/sm/Sanity.c b/rts/sm/Sanity.c
index 5f208206b2a..24a3cef4d63 100644
--- a/rts/sm/Sanity.c
+++ b/rts/sm/Sanity.c
@@ -32,7 +32,7 @@
 #include "sm/NonMoving.h"
 #include "sm/NonMovingMark.h"
 #include "Profiling.h" // prof_arena
-#include "HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 
 /* -----------------------------------------------------------------------------
    Forward decls.
diff --git a/rts/wasm/OSMem.c b/rts/wasm/OSMem.c
index 88cbc9c2487..ff4217f413e 100644
--- a/rts/wasm/OSMem.c
+++ b/rts/wasm/OSMem.c
@@ -52,7 +52,7 @@
 
 #include "RtsUtils.h"
 #include "sm/OSMem.h"
-#include "sm/HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 
 #include <__macro_PAGESIZE.h>
 
diff --git a/rts/win32/OSMem.c b/rts/win32/OSMem.c
index 4c643a97c20..6cccc4da83d 100644
--- a/rts/win32/OSMem.c
+++ b/rts/win32/OSMem.c
@@ -8,7 +8,7 @@
 
 #include "Rts.h"
 #include "sm/OSMem.h"
-#include "sm/HeapAlloc.h"
+#include "rts/storage/HeapAlloc.h"
 #include "RtsUtils.h"
 
 #include <windows.h>
-- 
GitLab