-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add a macro to opt into aggressive constprop #38080
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like it!
11fcf8b
to
794883c
Compare
test/core.jl
Outdated
# The first test just makes sure that improvements to the compiler don't | ||
# render the annotation effectless. | ||
@test Base.return_types(f_nonaggressive, Tuple{Int})[1] == Val | ||
@test Base.return_types(f_aggressive, Tuple{Int})[1] == Val{1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move these to test/compiler/inference
@@ -22,7 +22,8 @@ mutable struct Serializer{I<:IO} <: AbstractSerializer | |||
table::IdDict{Any,Any} | |||
pending_refs::Vector{Int} | |||
known_object_data::Dict{UInt64,Any} | |||
Serializer{I}(io::I) where I<:IO = new(io, 0, IdDict(), Int[], Dict{UInt64,Any}()) | |||
version::Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably a good idea, but I still usually try to handle these by making the data fully self-describing, i.e. store the new field in such a way that the type of value you deserialize tells you which version of the object you have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I tried at first, but it just becomes super messy, for what seems to be little benefit. I don't see a realistic way to support non-versioned serialization blobs stably, so we might as well require the version.
794883c
to
ffcbab1
Compare
I've rebased this. @JeffBezanson could I bother you to change the Serialization code to your satisfaction. I'm still not entirely convinced I understand why we can't just do the simple version-based thing - the current tricks in there just seem extremely brittle and non-scalable, but if you'd prefer the other thing, I guess that's ok - I just the feature ;). |
Why is this useful, when it's not inlined, so this code will typically not be what ends up getting run? Do we need instead some degrees of |
Why wouldn't it be useful? Aggressive constprop affects the return type we infer, so even if it's not inlined, sharper type information in the caller can make for a much more efficient function. |
Ok, I think we might as well merge this as-is. |
@@ -716,6 +721,7 @@ function readheader(s::AbstractSerializer) | |||
error("""Cannot read stream serialized with a newer version of Julia. | |||
Got data version $version > current version $ser_version""") | |||
end | |||
s.version = version | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
end | |
nothing | |
end |
test/core.jl
Outdated
@@ -7527,4 +7527,4 @@ const RedefineVarargN{N} = Tuple{Vararg{RedefineVararg, N}} | |||
const RedefineVarargN{N} = Tuple{Vararg{RedefineVararg, N}} | |||
|
|||
# NTuples with non-types | |||
@test NTuple{3, 2} == Tuple{2, 2, 2} | |||
@test NTuple{3, 2} == Tuple{2, 2, 2} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated (and slightly worse)
Does it make any sense to also have a way of blocking constant-prop? I'm thinking #38983. It seems pretty cheap to reinfer for specific constants in many cases, though maybe not all. So 🤷♂️ |
Yes that would make sense. We've seen cases (though it's fairly rare) where it's useful to manually block constant prop. |
We have |
Good point although I'm pretty sure |
I don't want to derail this from its original purpose, so please see #38983 (comment). |
f62c2ef
to
e077e86
Compare
Right now aggressive constprop is essentially tied to the inlining threshold (or to their name being `getproperty` or `setproperty!` respectively, which can be both somewhat brittle if the inlining cost changes and insufficient when you do really know that const prop would be beneficial even if the function is not inlineable. This adds a simple macro that can be used to manually annotate methods to force aggressive constprop on them.
e077e86
to
20ad41c
Compare
Right now aggressive constprop is essentially tied to the inlining threshold (or to their name being `getproperty` or `setproperty!` respectively, which can be both somewhat brittle if the inlining cost changes and insufficient when you do really know that const prop would be beneficial even if the function is not inlineable. This adds a simple macro that can be used to manually annotate methods to force aggressive constprop on them.
Right now aggressive constprop is essentially tied to the inlining threshold (or to their name being `getproperty` or `setproperty!` respectively, which can be both somewhat brittle if the inlining cost changes and insufficient when you do really know that const prop would be beneficial even if the function is not inlineable. This adds a simple macro that can be used to manually annotate methods to force aggressive constprop on them.
Right now aggressive constprop is essentially tied to the inlining
threshold (or to function's name being
getproperty
orsetproperty!
respectively), which can be both somewhat brittle if the inlining cost
changes and insufficient when you do really know that const prop
would be beneficial even if the function is not inlineable. This
adds a simple macro that can be used to manually annotate methods
to force aggressive constprop on them.