From 9d5a27ffe64068302c5b862280a6740f1431994b Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Wed, 1 Apr 2026 18:28:44 +0000 Subject: [PATCH 1/2] Fix JET resumable name collisions --- src/macro.jl | 4 ++-- src/utils.jl | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/macro.jl b/src/macro.jl index 5400045..d860bea 100755 --- a/src/macro.jl +++ b/src/macro.jl @@ -115,7 +115,7 @@ macro resumable(ex::Expr...) pushfirst!(args, functional) # The finite state machine structure definition - type_name = gensym(Symbol(func_def[:name], :_FSMI)) + type_name = fresh_binding_name(Symbol(func_def[:name], :_FSMI)) constr_def = copy(func_def) slot_T = [gensym(s) for s in keys(slots)] slot_T_sub = [:($k <: $v) for (k, v) in zip(slot_T, values(slots))] @@ -152,7 +152,7 @@ macro resumable(ex::Expr...) bareconst_expr = nothing end constr_expr = combinedef(constr_def) |> flatten - typed_fsmi = VERSION >= v"1.10.0-DEV.873" ? gensym(:typed_fsmi) : typed_fsmi_fallback + typed_fsmi = VERSION >= v"1.10.0-DEV.873" ? fresh_binding_name(:typed_fsmi) : typed_fsmi_fallback type_expr = quote mutable struct $struct_name _state :: UInt8 diff --git a/src/utils.jl b/src/utils.jl index 25284bc..127c6de 100755 --- a/src/utils.jl +++ b/src/utils.jl @@ -59,6 +59,14 @@ function forward_args(func_def) end const unused = (Symbol("#temp#"), Symbol("_"), Symbol(""), Symbol("#unused#"), Symbol("#self#")) +const fresh_binding_counter = Base.Threads.Atomic{UInt}(0) + +# JET/Revise can replay macro expansion in a way that makes plain `gensym()` +# collide for top-level bindings. Use an explicit module-global counter there. +function fresh_binding_name(prefix=:resumable) + id = Base.Threads.atomic_add!(fresh_binding_counter, UInt(1)) + UInt(1) + return Symbol("##", prefix, "#", Base.get_world_counter(), "#", id) +end function strip_defaults(arg_exprs::Vector{Any}) return Any[@capture(arg_expr, arg_expr2_ = default_) ? arg_expr2 : arg_expr @@ -70,7 +78,7 @@ Function returning the slots of a function definition """ function get_slots(func_def::Dict, args::Dict{Symbol, Any}, mod::Module) slots = Dict{Symbol, Any}() - func_def[:name] = gensym() + func_def[:name] = fresh_binding_name(:inferfn) func_def[:args] = Any[strip_defaults(func_def[:args])..., strip_defaults(func_def[:kwargs])...] func_def[:kwargs] = [] # replace yield with inference barrier From d8fef7706cef13670c7a4a6f39ce4245830eec59 Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Thu, 23 Apr 2026 08:44:56 -0400 Subject: [PATCH 2/2] bump and changelog --- CHANGELOG.md | 4 ++++ Project.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00c344d..e523744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # News +## v1.0.6 - 2026-04-23 + +- (internal) switch to a reimplementation of `gensym` that is not replayable by JET.jl (see https://github.com/aviatesk/JET.jl/issues/814) + ## v1.0.5 - 2026-03-20 - Some general cleanup of the code diff --git a/Project.toml b/Project.toml index d9438d1..d7de49c 100644 --- a/Project.toml +++ b/Project.toml @@ -5,7 +5,7 @@ license = "MIT" desc = "C# sharp style generators a.k.a. semi-coroutines for Julia." authors = ["Ben Lauwens and volunteer maintainers"] repo = "https://github.com/JuliaDynamics/ResumableFunctions.jl.git" -version = "1.0.5" +version = "1.0.6" [deps] Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"