diff --git a/Project.toml b/Project.toml index 703c4871f..aed8f7094 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Compat" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "3.35.0" +version = "3.36.0" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/README.md b/README.md index ddb5fdb1b..6f14b2385 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ changes in `julia`. ## Supported features +* `Compat.@constprop :aggressive ex` and `Compat.@constprop :none ex` allow control over constant-propagation during inference on Julia versions that support this feature, and otherwise just pass back `ex`. ([#42125]) (since Compat 3.36) + * `Returns(value)` returns `value` for any arguments ([#39794]) (since Compat 3.35) * The function `current_exceptions()` has been added to get the current @@ -273,3 +275,4 @@ Note that you should specify the correct minimum version for `Compat` in the [#41076]: https://github.com/JuliaLang/julia/pull/41076 [#34331]: https://github.com/JuliaLang/julia/pull/34331 [#39794]: https://github.com/JuliaLang/julia/pull/39794 +[#42125]: https://github.com/JuliaLang/julia/pull/42125 diff --git a/src/Compat.jl b/src/Compat.jl index 2b401e7ef..b88961e31 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1121,6 +1121,30 @@ if VERSION < v"1.7.0-DEV.793" end end +# https://github.com/JuliaLang/julia/pull/42125 +if !isdefined(Base, Symbol("@constprop")) + if isdefined(Base, Symbol("@aggressive_constprop")) + macro constprop(setting, ex) + if isa(setting, QuoteNode) + setting = setting.value + end + setting === :aggressive && return esc(:(Base.@aggressive_constprop $ex)) + setting === :none && return esc(ex) + throw(ArgumentError("@constprop $setting not supported")) + end + else + macro constprop(setting, ex) + if isa(setting, QuoteNode) + setting = setting.value + end + setting === :aggressive || setting === :none || throw(ArgumentError("@constprop $setting not supported")) + return esc(ex) + end + end +else + using Base: @constprop +end + include("iterators.jl") include("deprecated.jl") diff --git a/test/runtests.jl b/test/runtests.jl index 4363e57f6..00c934bda 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1158,4 +1158,16 @@ end val = [1,2,3] @test Returns(val)(1) === val @test sprint(show, Returns(1.0)) == "Returns{Float64}(1.0)" -end \ No newline at end of file +end + +# https://github.com/JuliaLang/julia/pull/42125 +@testset "@constprop" begin + Compat.@constprop :aggressive aggf(x) = Symbol(x) + Compat.@constprop :none nonef(x) = Symbol(x) + @test_throws Exception Meta.lower(@__MODULE__, + quote + Compat.@constprop :other brokenf(x) = Symbol(x) + end + ) + @test aggf("hi") == nonef("hi") == :hi +end