-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
inference: remove hacks around type-system incorrectness #21892
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
Conversation
@@ -1397,10 +1395,6 @@ function abstract_call_gf_by_type(f::ANY, atype::ANY, sv::InferenceState) | |||
add_mt_backedge(ftname.mt, argtype, sv) | |||
update_valid_age!(min_valid[1], max_valid[1], sv) | |||
end | |||
if isempty(applicable) | |||
# TODO: this is needed because type intersection is wrong in some cases | |||
return Any |
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.
Are we sure we are ready for this? Admittedly, of the typeintersect
bugs I have seen recently, none was erroneously giving Bottom
, but since proposing this in #20866, I have lost some confidence in typeintersect
... Anyway, we can try, and if there are problems and we can't straighten it out in subype.c
in time, we can just add this back.
@@ -3546,7 +3533,7 @@ function invoke_NF(argexprs, etype::ANY, atypes, sv, atype_unlimited::ANY, | |||
all = false | |||
end | |||
end | |||
if UNION_SPLIT_MISMATCH_ERROR && all |
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.
Just to be sure: This was also about wrongly missing a method due to a wrongly empty type intersection?
@testset "Exactness of cumsum # 21666" begin | ||
# test that cumsum uses more stable algorithm | ||
# for types with unknown/rounding arithmetic | ||
Base.TypeArithmetic(::Type{F21666{T}}) where {T} = T | ||
Base.:+(x::F, y::F) where {F <: F21666} = F(x.x + y.x) | ||
Base.convert(::Type{Float64}, x::F21666) = Float64(x.x) |
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 change is fine, of course, but...
Is everything in a @testset
always happening at the same world age? Somehow, I was under the impression that some method definitions took effect immediately, but I fail to reproduce now, so I was probably wrong. Could you drop a comment at #21769?
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.
Thinking about it again, the +
and convert
definitions must have been available inside the @testset
for the tests to have worked, or am I missing something here?
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.
Inference is willing to get everything wrong if you write method definitions like this. (ref #21570)
Travis on OSX timed out because it was building LLVM. Was that to be expected? |
that can happen if it fails to download the llvm homebrew bottle. hopefully transient. |
@@ -2059,12 +2059,12 @@ struct F21666{T <: Base.TypeArithmetic} | |||
x::Float32 | |||
end | |||
|
|||
Base.TypeArithmetic(::Type{F21666{T}}) where {T} = T() |
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.
Would it make sense to leave a note for the posterity why struct F21666
and these definitions should be outside of @testset
?
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.
Might make more sense to expand the Methods/Redefining Methods manual section a bit to explain how things behave inside let
/try
/... blocks at top level and add a warning note to the Unit Testing/Working with Test Sets section. If we just add a comment here, that won't stop the same mistake from being made elsewhere. (Assuming proper documentation will is pretty optimistic, I know, but still...)
Current thinking: Let's go with this, hoping that we will weed out some more |
@nanosoldier |
Worth a PkgEval run, too? (I haven't set it up here and I'm afraid I don't have the time to do so at the moment, but maybe someone else could run it?) |
|
Hah, I guess we've already found another bug we definitely should fix before merging this. |
I cannot reproduce exactly the crash seen on nanosoldier, but julia> methods(string, Tuple{Char})
# 1 method for generic function "string":
string(a::Union{Char, String}...) in Base at strings/string.jl:351
julia> using LegacyStrings;
julia> methods(string, Tuple{Char})
# 0 methods for generic function "string":
julia> string('0')
"0" Now, julia> methods(string)
# 17 methods for generic function "string":
# ...
string(a::Union{Char, String}...) in Base at strings/string.jl:351
#...
string(a::Union{Char, LegacyStrings.ASCIIString, LegacyStrings.UTF8String}...) in LegacyStrings at LegacyStrings/src/utf8.jl:161
#... So |
Fixing the ambiguity in LegacyStrings lets the benchmarks finish successfully, at least locally. |
infers a missing method (MethodError) as returning `Union{}` and fix tests that were wrong, but not detected previously!
Let's see if it works now: @nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
infers a missing method (MethodError) as returning
Union{}
and fix tests that were wrong, but not detected previously!