From 0f8266bf6d00f757dbcc0609a6bb13f181e38ab3 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Mon, 25 Aug 2025 14:40:48 +0200 Subject: [PATCH 1/2] `_register_kinds!`: prevent unintentional closure capture, boxing The variable `i` was unintentionally shared between the generator closure in `_register_kinds!` and another part of the body of `_register_kinds!`. Thus `i` was boxed, causing trouble for inference. Fix this by moving the part of `_register_kinds!` with `i` to a new function. Fixing this should make the sysimage more resistant to invalidation, once the change propagates to Julia itself. --- src/julia/kinds.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/julia/kinds.jl b/src/julia/kinds.jl index 96d78ad7..32d1f0e2 100644 --- a/src/julia/kinds.jl +++ b/src/julia/kinds.jl @@ -102,6 +102,10 @@ function _register_kinds!(kind_modules, int_to_kindstr, kind_str_to_int, mod, mo error("Kind module ID $module_id already claimed by module $m") end end + _register_kinds_names!(int_to_kindstr, kind_str_to_int, module_id, names) +end + +function _register_kinds_names!(int_to_kindstr, kind_str_to_int, module_id, names) # Process names to conflate category BEGIN/END markers with the first/last # in the category. i = 0 From 0b8583342630f1c8cce0a481dace92e198c9bfc5 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Tue, 26 Aug 2025 08:59:38 +0200 Subject: [PATCH 2/2] add comment on the motivation as suggested by aviatesk --- src/julia/kinds.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/julia/kinds.jl b/src/julia/kinds.jl index 32d1f0e2..c659f667 100644 --- a/src/julia/kinds.jl +++ b/src/julia/kinds.jl @@ -105,6 +105,8 @@ function _register_kinds!(kind_modules, int_to_kindstr, kind_str_to_int, mod, mo _register_kinds_names!(int_to_kindstr, kind_str_to_int, module_id, names) end +# This function is separated from `_register_kinds!` to prevent sharing of the variable `i` +# here and in the closure in `_register_kinds!`, which causes boxing and bad inference. function _register_kinds_names!(int_to_kindstr, kind_str_to_int, module_id, names) # Process names to conflate category BEGIN/END markers with the first/last # in the category.