diff --git a/Project.toml b/Project.toml index 14f5852f..46ef8ba6 100644 --- a/Project.toml +++ b/Project.toml @@ -32,6 +32,7 @@ DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" MarkdownAST = "d0879d2d-cac2-40c8-9cee-1863dc0c7391" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" @@ -46,6 +47,7 @@ test = [ "Documenter", "ForwardDiff", "JET", + "Logging", "Markdown", "MarkdownAST", "Plots", @@ -62,6 +64,7 @@ DocStringExtensions = "0.9" Documenter = "1" ForwardDiff = "0.10, 1" JET = "0.11" +Logging = "1" Markdown = "1" MarkdownAST = "0.1" Plots = "1" diff --git a/test/suite/meta/test_code_quality.jl b/test/suite/meta/test_code_quality.jl index eba33725..9281c799 100644 --- a/test/suite/meta/test_code_quality.jl +++ b/test/suite/meta/test_code_quality.jl @@ -4,10 +4,57 @@ using Test: Test using Aqua: Aqua using JET: JET using CTBase: CTBase +using Logging: Logging const VERBOSE = isdefined(Main, :TestData) ? Main.TestData.VERBOSE : true const SHOWTIMING = isdefined(Main, :TestData) ? Main.TestData.SHOWTIMING : true +# ============================================================================== +# Filter LoweredCodeUtils' benign "skipping callee ... UndefRefError()" warnings +# ============================================================================== +# +# JET.test_package collects method signatures via Revise/LoweredCodeUtils without +# calling anything. For keyword-argument functor methods (a callable struct with a +# `; kwarg=default` in its call signature), Julia compiles a hidden body function +# named `var"#_#N"`; LoweredCodeUtils cannot statically attribute that hidden body +# to its parent method and emits a `@warn "skipping callee ..." ` before moving on. +# It is a collector limitation, not a JET finding — the flagged body is simply +# excluded from the static scan; everything else (including its runtime behavior, +# covered by the normal test suite) is unaffected. +# +# Filtered precisely by message prefix + emitting module, so any other, unrelated +# warning from LoweredCodeUtils still surfaces normally. +struct _SkipBenignLoweredCodeUtilsWarnings <: Logging.AbstractLogger + logger::Logging.AbstractLogger +end + +Logging.min_enabled_level(l::_SkipBenignLoweredCodeUtilsWarnings) = + Logging.min_enabled_level(l.logger) + +Logging.shouldlog(l::_SkipBenignLoweredCodeUtilsWarnings, level, _module, group, id) = + Logging.shouldlog(l.logger, level, _module, group, id) + +function Logging.handle_message( + l::_SkipBenignLoweredCodeUtilsWarnings, + level, + message, + _module, + group, + id, + file, + line; + kwargs..., +) + if level == Logging.Warn && + nameof(_module) === :LoweredCodeUtils && + startswith(string(message), "skipping callee") + return nothing + end + return Logging.handle_message( + l.logger, level, message, _module, group, id, file, line; kwargs... + ) +end + function test_code_quality() Test.@testset verbose = VERBOSE showtiming = SHOWTIMING "Code quality" begin Test.@testset verbose = VERBOSE showtiming = SHOWTIMING "Aqua" begin @@ -23,7 +70,11 @@ function test_code_quality() end Test.@testset "JET" begin - JET.test_package(CTBase; target_modules=(CTBase,)) + Logging.with_logger( + _SkipBenignLoweredCodeUtilsWarnings(Logging.current_logger()) + ) do + JET.test_package(CTBase; target_modules=(CTBase,)) + end end # Test.@testset "JuliaFormatter" begin