From ee812fc6d50e5bf57137bb7ab121cea4c56af253 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 2 May 2025 17:19:33 +0000 Subject: [PATCH] only warn about Vararg wrapping once This quiets down the long message in #38136 to be once-per-process when running with `--depwarn=yes` instead of spamming log files continually. We probably should have considered doing this a long time ago, but hopefully better now than never. --- src/jltypes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/jltypes.c b/src/jltypes.c index e5341c2621df3..64d22958dfc38 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -910,7 +910,9 @@ JL_DLLEXPORT jl_value_t *jl_type_unionall(jl_tvar_t *v, jl_value_t *body) if (jl_options.depwarn) { if (jl_options.depwarn == JL_OPTIONS_DEPWARN_ERROR) jl_error("Wrapping `Vararg` directly in UnionAll is deprecated (wrap the tuple instead).\nYou may need to write `f(x::Vararg{T})` rather than `f(x::Vararg{<:T})` or `f(x::Vararg{T}) where T` instead of `f(x::Vararg{T} where T)`."); - jl_printf(JL_STDERR, "WARNING: Wrapping `Vararg` directly in UnionAll is deprecated (wrap the tuple instead).\nYou may need to write `f(x::Vararg{T})` rather than `f(x::Vararg{<:T})` or `f(x::Vararg{T}) where T` instead of `f(x::Vararg{T} where T)`.\nTo make this warning an error, and hence obtain a stack trace, use `julia --depwarn=error`.\n"); + static _Atomic(int) warnedonce; + if (jl_atomic_load_relaxed(&warnedonce) == 0 && jl_atomic_exchange_relaxed(&warnedonce, 1) == 0) + jl_printf(JL_STDERR, "WARNING: Wrapping `Vararg` directly in UnionAll is deprecated (wrap the tuple instead).\nYou may need to write `f(x::Vararg{T})` rather than `f(x::Vararg{<:T})` or `f(x::Vararg{T}) where T` instead of `f(x::Vararg{T} where T)`.\nTo make this warning an error, and hence obtain a stack trace, use `julia --depwarn=error`.\n"); } jl_vararg_t *vm = (jl_vararg_t*)body; int T_has_tv = vm->T && jl_has_typevar(vm->T, v);