From 1d26139b8d5b842c96df9a18aeaba99b938975cc Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Tue, 2 Sep 2025 19:19:45 +0200 Subject: [PATCH 1/3] `CoreLogging`: prevent some `Annotated*`-related instability Add some concrete `typeassert`s to increase the resistance of the sysimage to invalidation by helping inference within the method body. --- base/logging/ConsoleLogger.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/base/logging/ConsoleLogger.jl b/base/logging/ConsoleLogger.jl index 6521bf49b3e66..1149dabeff1f6 100644 --- a/base/logging/ConsoleLogger.jl +++ b/base/logging/ConsoleLogger.jl @@ -123,9 +123,10 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module # Generate a text representation of the message and all key value pairs, # split into lines. This is specialised to improve type inference, # and reduce the risk of resulting method invalidations. + annotations_type = Vector{@NamedTuple{region::UnitRange{Int}, label::Symbol, value}} message = string(message) - msglines = if Base._isannotated(message) && !isempty(Base.annotations(message)) - message = Base.AnnotatedString(String(message), Base.annotations(message)) + msglines = if Base._isannotated(message) && !isempty(Base.annotations(message)::annotations_type) + message = Base.AnnotatedString(String(message)::String, Base.annotations(message)::annotations_type) @NamedTuple{indent::Int, msg::Union{SubString{Base.AnnotatedString{String}}, SubString{String}}}[ (indent=0, msg=l) for l in split(chomp(message), '\n')] else From 40b1da108da4e024a48d5070fd2fe6f5dfa8c341 Mon Sep 17 00:00:00 2001 From: Neven Sajko <4944410+nsajko@users.noreply.github.com> Date: Thu, 18 Sep 2025 00:56:56 +0200 Subject: [PATCH 2/3] use existing type alias: `Base.RegionAnnotation` Co-authored-by: Cody Tapscott <84105208+topolarity@users.noreply.github.com> --- base/logging/ConsoleLogger.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/logging/ConsoleLogger.jl b/base/logging/ConsoleLogger.jl index 1149dabeff1f6..83a63e9dd2891 100644 --- a/base/logging/ConsoleLogger.jl +++ b/base/logging/ConsoleLogger.jl @@ -125,8 +125,8 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module # and reduce the risk of resulting method invalidations. annotations_type = Vector{@NamedTuple{region::UnitRange{Int}, label::Symbol, value}} message = string(message) - msglines = if Base._isannotated(message) && !isempty(Base.annotations(message)::annotations_type) - message = Base.AnnotatedString(String(message)::String, Base.annotations(message)::annotations_type) + msglines = if Base._isannotated(message) && !isempty(Base.annotations(message)::Vector{Base.RegionAnnotation}) + message = Base.AnnotatedString(String(message)::String, Base.annotations(message)::Vector{Base.RegionAnnotation}) @NamedTuple{indent::Int, msg::Union{SubString{Base.AnnotatedString{String}}, SubString{String}}}[ (indent=0, msg=l) for l in split(chomp(message), '\n')] else From 40647ddfd9f47031c632f50007de43b76b70df29 Mon Sep 17 00:00:00 2001 From: Neven Sajko <4944410+nsajko@users.noreply.github.com> Date: Thu, 18 Sep 2025 00:57:27 +0200 Subject: [PATCH 3/3] delete unused local variable --- base/logging/ConsoleLogger.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/base/logging/ConsoleLogger.jl b/base/logging/ConsoleLogger.jl index 83a63e9dd2891..8666c145da6d7 100644 --- a/base/logging/ConsoleLogger.jl +++ b/base/logging/ConsoleLogger.jl @@ -123,7 +123,6 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module # Generate a text representation of the message and all key value pairs, # split into lines. This is specialised to improve type inference, # and reduce the risk of resulting method invalidations. - annotations_type = Vector{@NamedTuple{region::UnitRange{Int}, label::Symbol, value}} message = string(message) msglines = if Base._isannotated(message) && !isempty(Base.annotations(message)::Vector{Base.RegionAnnotation}) message = Base.AnnotatedString(String(message)::String, Base.annotations(message)::Vector{Base.RegionAnnotation})