Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support @constprop #752

Merged
merged 5 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
24 changes: 24 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
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