Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Fix tracing of macro-expanded functions with gensym names
Browse files Browse the repository at this point in the history
  • Loading branch information
cstjean committed Oct 1, 2017
1 parent 467784e commit d079678
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 3 additions & 4 deletions README.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,15 @@
"@trace (some_function, SomeModule, \"some_interactively_included_file.jl\") bar(1)\n",
"```\n",
"\n",
"This call to `@trace` will execute `bar(1)` while tracing all methods of `some_function`, all methods defined in `SomeModule / \"some_interactively_included_file.jl\"`, and all methods defined with `@traceable` (in this case, `foo()`). Interactively-defined functions have to be defined with `@traceable` to be traceable.\n",
"This call to `@trace` will execute `bar(1)` while tracing all methods of `some_function`, all methods defined in `SomeModule / \"some_interactively_included_file.jl\"`, and all methods defined with `@traceable` (in this case, `foo()`). \n",
"\n",
"Tracing Julia code involves a fair amount of code analysis; TraceCalls.jl will error (when using `@traceable`), warn (when tracing a function), or silently skip (when tracing a module) the following:\n",
"Tracing Julia code involves a fair amount of code analysis; TraceCalls.jl will error, warn, or silently skip (when a tracing module) the following:\n",
"\n",
" - Inner constructors\n",
" - Functions that are defined by `eval`\n",
" - Function definitions inside a macroexpansion (eg. `@inline foo(x) = x+2`), unless `@traceable` is part of the macroexpansion. This should be fixed in the next `TraceCalls` release.\n",
" - Callable objects (eg. `(func::Functor)(x) = ...`)\n",
" \n",
"The `@traceable` macro merely remembers the function definition, it does not modify it in any way. Thus, it has zero impact on the performance of your code.\n",
"The `@traceable` macro (to be used primarily for interactively-defined functions) remembers the function definition without modifying it. It has no impact on the performance of your code.\n",
"\n",
"#### Tracing tips\n",
"\n",
Expand Down
11 changes: 9 additions & 2 deletions src/code_update.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,15 @@ end

""" `get_function(mod::Module, fundef::Expr)::Function` returns the `Function` which this
`fundef` is defining. This code works only when the Function already exists. """
get_function_(mod::Module, fundef::Expr)::Union{Function, Type} =
eval(mod, splitdef(fundef)[:name])
function get_function_(mod::Module, fundef::Expr)::Union{Function, Type, Void}
try
eval(mod, splitdef(fundef)[:name])
catch
# This can happen, for instance, in macro expansions that create functions
# with `gensym` names.
nothing
end
end

""" `get_function(mod, def)` returns the ::Function corresponding to `def` if there is
one (and it's not a callable-object definition), otherwise returns `nothing` """
Expand Down

0 comments on commit d079678

Please sign in to comment.