From 1a916780732e34416ea445721670edbec8b98261 Mon Sep 17 00:00:00 2001
From: Cody Tapscott <topolarity@tapscott.me>
Date: Wed, 19 Mar 2025 18:23:51 -0400
Subject: [PATCH] precompile_utils: Don't enqueue `macro` methods for
 pre-compilation

Despite disabling the runtime from compiling `macro` functions in
`gf.c`, the pre-compilation code was adding macro code anyway to
the workqueue.
---
 src/precompile_utils.c | 4 ++++
 test/precompile.jl     | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/src/precompile_utils.c b/src/precompile_utils.c
index e0e242836c830..84619b714b624 100644
--- a/src/precompile_utils.c
+++ b/src/precompile_utils.c
@@ -170,6 +170,10 @@ static void jl_compile_all_defs(jl_array_t *mis, int all)
     size_t i, l = jl_array_nrows(allmeths);
     for (i = 0; i < l; i++) {
         jl_method_t *m = (jl_method_t*)jl_array_ptr_ref(allmeths, i);
+        int is_macro_method = jl_symbol_name(m->name)[0] == '@';
+        if (is_macro_method && !all)
+            continue; // Avoid inference / pre-compilation for macros
+
         if (jl_is_datatype(m->sig) && jl_isa_compileable_sig((jl_tupletype_t*)m->sig, jl_emptysvec, m)) {
             // method has a single compilable specialization, e.g. its definition
             // signature is concrete. in this case we can just hint it.
diff --git a/test/precompile.jl b/test/precompile.jl
index 9c5d846280490..07384e66927a4 100644
--- a/test/precompile.jl
+++ b/test/precompile.jl
@@ -2410,4 +2410,9 @@ precompile_test_harness("Package top-level load itself") do load_path
     end
 end
 
+# Verify that inference / caching was not performed for any macros in the sysimage
+let m = only(methods(Base.var"@big_str"))
+    @test m.specializations === Core.svec() || !isdefined(m.specializations, :cache)
+end
+
 finish_precompile_test!()