Skip to content

Commit ace5c19

Browse files
committed
test: more coverage of EvalOptions branches
1 parent a87016e commit ace5c19

File tree

3 files changed

+66
-34
lines changed

3 files changed

+66
-34
lines changed

src/Evaluate.jl

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module EvaluateModule
22

3-
using DispatchDoctor: @unstable
3+
using DispatchDoctor: @stable, @unstable
44

55
import ..NodeModule: AbstractExpressionNode, constructorof
66
import ..StringsModule: string_tree
@@ -51,39 +51,53 @@ struct EvalOptions{T,B,E}
5151
early_exit::Val{E}
5252
end
5353

54-
@inline _to_bool_val(x::Bool) = x ? Val(true) : Val(false)
55-
@inline _to_bool_val(x::Val{T}) where {T} = Val(T::Bool)
56-
57-
function EvalOptions(;
58-
turbo::Union{Bool,Val}=Val(false),
59-
bumper::Union{Bool,Val}=Val(false),
60-
early_exit::Union{Bool,Val}=Val(true),
54+
@stable(
55+
default_mode = "disable",
56+
default_union_limit = 2,
57+
@inline _to_bool_val(x::Bool) = x ? Val(true) : Val(false)
6158
)
62-
return EvalOptions(_to_bool_val(turbo), _to_bool_val(bumper), _to_bool_val(early_exit))
63-
end
64-
65-
function _process_deprecated_kws(eval_options, deprecated_kws)
66-
turbo = get(deprecated_kws, :turbo, nothing)
67-
bumper = get(deprecated_kws, :bumper, nothing)
68-
if any(Base.Fix2(, (:turbo, :bumper)), keys(deprecated_kws))
69-
throw(ArgumentError("Invalid keyword argument(s): $(keys(deprecated_kws))"))
70-
end
71-
if !isempty(deprecated_kws)
72-
@assert eval_options === nothing "Cannot use both `eval_options` and deprecated flags `turbo` and `bumper`."
73-
Base.depwarn(
74-
"The `turbo` and `bumper` keyword arguments are deprecated. Please use `eval_options` instead.",
75-
:eval_tree_array,
76-
)
77-
end
78-
if eval_options !== nothing
79-
return eval_options
80-
else
81-
return EvalOptions(;
82-
turbo=turbo === nothing ? Val(false) : turbo,
83-
bumper=bumper === nothing ? Val(false) : bumper,
59+
@stable(default_mode = "disable", @inline _to_bool_val(x::Val{T}) where {T} = Val(T::Bool))
60+
61+
@stable(
62+
default_mode = "disable",
63+
default_union_limit = 4,
64+
begin
65+
function EvalOptions(;
66+
turbo::Union{Bool,Val}=Val(false),
67+
bumper::Union{Bool,Val}=Val(false),
68+
early_exit::Union{Bool,Val}=Val(true),
8469
)
70+
return EvalOptions(
71+
_to_bool_val(turbo), _to_bool_val(bumper), _to_bool_val(early_exit)
72+
)
73+
end
74+
75+
function _process_deprecated_kws(eval_options, deprecated_kws)
76+
turbo = get(deprecated_kws, :turbo, nothing)
77+
bumper = get(deprecated_kws, :bumper, nothing)
78+
if any(Base.Fix2(, (:turbo, :bumper)), keys(deprecated_kws))
79+
throw(
80+
ArgumentError("Invalid keyword argument(s): $(keys(deprecated_kws))")
81+
)
82+
end
83+
if !isempty(deprecated_kws)
84+
@assert eval_options === nothing "Cannot use both `eval_options` and deprecated flags `turbo` and `bumper`."
85+
Base.depwarn(
86+
"The `turbo` and `bumper` keyword arguments are deprecated. Please use `eval_options` instead.",
87+
:eval_tree_array,
88+
)
89+
end
90+
if eval_options !== nothing
91+
return eval_options
92+
else
93+
return EvalOptions(;
94+
turbo=turbo === nothing ? Val(false) : turbo,
95+
bumper=bumper === nothing ? Val(false) : bumper,
96+
)
97+
end
98+
end
8599
end
86-
end
100+
)
87101

88102
"""
89103
eval_tree_array(

test/test_deprecations.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using DynamicExpressions
2-
using Test
3-
using Zygote
1+
using Test, DynamicExpressions, Zygote, LoopVectorization
42
using Suppressor: @capture_err
53
using DispatchDoctor: allow_unstable
64

@@ -47,6 +45,14 @@ if VERSION >= v"1.9"
4745
)
4846
end
4947

48+
# Old usage of evaluation options
49+
if VERSION >= v"1.9-"
50+
ex = Expression(Node{Float64}(; feature=1))
51+
@test_logs (:warn, r"The `turbo` and `bumper` keyword arguments are deprecated.*") (ex(
52+
randn(Float64, 1, 10), OperatorEnum(); turbo=true
53+
))
54+
end
55+
5056
# Test deprecated modules
5157
logs = @capture_err begin
5258
@eval using DynamicExpressions.EquationModule

test/test_evaluation.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,15 @@ end
271271
@test !isfinite(y[2])
272272
end
273273
end
274+
275+
@testitem "Test EvalOptions constructor" begin
276+
using DynamicExpressions, LoopVectorization
277+
278+
@test EvalOptions(; turbo=true) isa EvalOptions{true}
279+
@test EvalOptions(; turbo=Val(true)) isa EvalOptions{true}
280+
@test EvalOptions(; turbo=false) isa EvalOptions{false}
281+
@test EvalOptions(; turbo=Val(false)) isa EvalOptions{false}
282+
283+
ex = Expression(Node{Float64}(; feature=1))
284+
@test_throws ArgumentError ex(randn(1, 5), OperatorEnum(); bad_arg=1)
285+
end

0 commit comments

Comments
 (0)