From c7325c27c0f6aa79051d2cc7c1ab7522048a60e4 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Wed, 8 Oct 2025 11:21:40 +0100 Subject: [PATCH] Revert "RAI: Don't use macros inside `logmsg_code` (#250)" This reverts commit 9a42d18b2074eb067bbe1fe15eecacf34e40856d. --- base/logging/logging.jl | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/base/logging/logging.jl b/base/logging/logging.jl index 3f90996fbd5c2..c44e74ffa627b 100644 --- a/base/logging/logging.jl +++ b/base/logging/logging.jl @@ -347,13 +347,11 @@ end # Generate code for logging macros function logmsg_code(_module, file, line, level, message, exs...) @nospecialize - msg = gensym(:msg) - kwargs = gensym(:kwargs) log_data = process_logmsg_exs(_module, file, line, level, message, exs...) if !isa(message, Symbol) && issimple(message) && isempty(log_data.kwargs) logrecord = quote - $(msg) = $(message) - $(kwargs) = (;) + msg = $(message) + kwargs = (;) true end elseif issimple(message) && all(issimplekw, log_data.kwargs) @@ -372,8 +370,8 @@ function logmsg_code(_module, file, line, level, message, exs...) logrecord = quote let err = $checkerrors if err === nothing - $(msg) = $(message) - $(kwargs) = (;$(log_data.kwargs...)) + msg = $(message) + kwargs = (;$(log_data.kwargs...)) true else @invokelatest $(logging_error)(logger, level, _module, group, id, file, line, err, false) @@ -384,8 +382,8 @@ function logmsg_code(_module, file, line, level, message, exs...) else logrecord = quote try - $(msg) = $(esc(message)) - $(kwargs) = (;$(log_data.kwargs...)) + msg = $(esc(message)) + kwargs = (;$(log_data.kwargs...)) true catch err @invokelatest $(logging_error)(logger, level, _module, group, id, file, line, err, true) @@ -412,13 +410,13 @@ function logmsg_code(_module, file, line, level, message, exs...) file = Base.fixup_stdlib_path(file) end line = $(log_data._line) - local $(msg), $(kwargs) + local msg, kwargs if $(logrecord) - $(Expr(:isdefined, msg)) || throw(AssertionError("Assertion to tell the compiler about the definedness of this variable")) - $(Expr(:isdefined, kwargs)) || throw(AssertionError("Assertion to tell the compiler about the definedness of this variable")) + @assert @isdefined(msg) "Assertion to tell the compiler about the definedness of this variable" + @assert @isdefined(kwargs) "Assertion to tell the compiler about the definedness of this variable" $handle_message_nothrow( - logger, level, $(msg), _module, group, id, file, line; - $(kwargs)...) + logger, level, msg, _module, group, id, file, line; + kwargs...) end end end