Skip to content

gensym the closure name in @timeit_debug function bodies - #232

Open
KristofferC wants to merge 1 commit into
masterfrom
kc/gensym-inner-closure
Open

gensym the closure name in @timeit_debug function bodies#232
KristofferC wants to merge 1 commit into
masterfrom
kc/gensym-inner-closure

Conversation

@KristofferC

Copy link
Copy Markdown
Owner

The closure @timeit_debug wraps a function body in is literally named inner, and the wrapper is escaped into the user's function, so inner becomes a local binding in their scope:

inner(x) = 2x

@timeit_debug to function f(x)
    return inner(x)      # MethodError: no method matching (::var"#inner#f##0"{Int64})(::Int64)
end

@timeit_debug to function g(inner)
    return inner + 1     # syntax: cannot add method to function argument inner
end

The first fails at run time, the second at definition time. Both happen whether or not debug timings are enabled, since the closure is emitted either way. @gensym the name so it can't clash.

Independent of #230, though that PR is why I noticed — it removes the reason to extend this closure to plain @timeit.

The closure was literally named `inner` and lands in the user's scope, so a
body calling a global `inner` got a MethodError and an argument named `inner`
was a syntax error.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant