Mark jl_world_counter as an inactive integral global (#3208)
Julia's world age counter is an external `i64` global with no
initializer, so Enzyme could neither deduce its inner type nor
create a shadow for it, erroring with
cannot compute with global variable that doesn't have marked
shadow global
@jl_world_counter = external local_unnamed_addr global i64
Seed its type as a pointer to integer data in type analysis, and
list it (along with the `ijl_` variant) among the known inactive
globals in activity analysis.
Claude-Session: https://claude.ai/code/session_01JS9YgwAvq8YuPtRgkauuMu
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
diff --git a/enzyme/Enzyme/ActivityAnalysis.cpp b/enzyme/Enzyme/ActivityAnalysis.cpp
index 0075d27..8299fd6 100644
--- a/enzyme/Enzyme/ActivityAnalysis.cpp
+++ b/enzyme/Enzyme/ActivityAnalysis.cpp
@@ -117,6 +117,8 @@
static const StringSet<> InactiveGlobals = {
"small_typeof",
"jl_small_typeof",
+ "jl_world_counter",
+ "ijl_world_counter",
"ompi_request_null",
"ompi_mpi_double",
"ompi_mpi_comm_world",
diff --git a/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp b/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp
index d9f02f0..c9dee61 100644
--- a/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp
+++ b/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp
@@ -886,6 +886,16 @@
return;
}
+ // from julia code, the world age counter is an integer
+ if (GV->getName() == "jl_world_counter" ||
+ GV->getName() == "ijl_world_counter") {
+ TypeTree T;
+ T.insert({-1}, BaseType::Pointer);
+ T.insert({-1, -1}, BaseType::Integer);
+ analysis[Val] = T;
+ return;
+ }
+
if (startsWith(GV->getName(), getInstrProfCountersVarPrefix())) {
TypeTree T;
T.insert({-1}, BaseType::Pointer);