Skip to content

Safe logging macros don't work in generated functions due to with_logger closure #685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danielwe opened this issue Apr 1, 2025 · 0 comments · Fixed by #686
Closed

Safe logging macros don't work in generated functions due to with_logger closure #685

danielwe opened this issue Apr 1, 2025 · 0 comments · Fixed by #686

Comments

@danielwe
Copy link
Contributor

danielwe commented Apr 1, 2025

This is my fault, ref #622

MWE:

julia> using GPUCompiler

julia> @generated function trywarn()
           return :(GPUCompiler.@safe_warn "watch out!")
       end
trywarn (generic function with 1 method)

julia> trywarn()
ERROR: The function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

The problem is there's no public closure-free API to change the current logger. The non-public way is to reassign current_task().logstate, which is what with_logger does under the hood.

So I guess the choices are

  • Copy the internals of with_logger, i.e., reassign the non-public current_task().logstate
  • Revert to mutating the global logger and hope that @safe_* is never used in a task that's attached to a non-global logger
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 a pull request may close this issue.

1 participant