You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stack overflow when calling a function named f outside the RGF #146
using RuntimeGeneratedFunctions
RuntimeGeneratedFunctions.init(@__MODULE__)
f(x) = x +1
rgf =@RuntimeGeneratedFunction(:(function(x); f(x); end))
rgf(3)
errors dramatically with
julia>rgf(3) # StackOverflowError: f resolves to the RGF itself, not Main.f
Warning: detected a stack overflow; program state may be corrupted, so further execution might be unreliable.
ERROR: StackOverflowError:
Stacktrace:
[1] generated_callfunc(f::RuntimeGeneratedFunction{…}, __args::Int64)
@ Main ./none:0
[2] (::RuntimeGeneratedFunction{…})(args::Int64)
@ RuntimeGeneratedFunctions ~/jl/RuntimeGeneratedFunctions.jl/src/RuntimeGeneratedFunctions.jl:230
[3] macro expansion
@ ./REPL[4]:1 [inlined]
[4] macro expansion
@ ~/jl/RuntimeGeneratedFunctions.jl/src/RuntimeGeneratedFunctions.jl:243 [inlined]
[5] macro expansion
@ ./none:0 [inlined]
--- the above 5 lines are repeated 39990 more times ---
[199956] generated_callfunc(f::RuntimeGeneratedFunction{…}, __args::Int64)
@ Main ./none:0
Some type information was truncated. Use `show(err)` to see complete types.
If the arity of the RGF and the externally defined f is different, then it segfaults instead of overflowing because of #100.
I think this is because inside the RGF body, f refers to the RGF itself:
Different error if you use __args because of the same root cause:
julia>__args(x) = x +1
__args (generic function with 1 method)
julia> rgf =@RuntimeGeneratedFunction(:(function(x); __args(x); end))
RuntimeGeneratedFunction(#=in Main=#, #=using Main=#, :((x,)->begin#= REPL[4]:1 =##= REPL[4]:1 =#__args(x)
end))
julia>rgf(3)
ERROR: MethodError: objects of type Tuple{Int64} are not callable
The object of type `Tuple{Int64}` exists, but no method is defined for this combination of argument types when trying to treat it as a callable object.
Stacktrace:
[1] macro expansion
@ ./REPL[4]:1 [inlined]
[2] macro expansion
@ ~/jl/RuntimeGeneratedFunctions.jl/src/RuntimeGeneratedFunctions.jl:243 [inlined]
[3] macro expansion
@ ./none:0 [inlined]
[4] generated_callfunc(f::RuntimeGeneratedFunction{…}, __args::Int64)
@ Main ./none:0
[5] (::RuntimeGeneratedFunction{…})(args::Int64)
@ RuntimeGeneratedFunctions ~/jl/RuntimeGeneratedFunctions.jl/src/RuntimeGeneratedFunctions.jl:230
[6] top-level scope
@ REPL[5]:1
[7] top-level scope
@ REPL:1
Some type information was truncated. Use `show(err)` to see complete types.
Activity
penelopeysm commentedon Aug 21, 2026
Different error if you use
__argsbecause of the same root cause: