Skip to content

Commit 191fc25

Browse files
oscardssmithJeffBezanson
authored andcommitted
improve isdefined precision for 0 field types (#58220)
alternate to #58214. --------- Co-authored-by: Jeff Bezanson <[email protected]>
1 parent 4e7ddaa commit 191fc25

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Compiler/src/tfuncs.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,10 @@ end
449449
return Const(true)
450450
end
451451
end
452+
# datatype_fieldcount is what `fieldcount` uses internally
453+
# and returns nothing (!==0) for non-definite field counts.
454+
elseif datatype_fieldcount(a1) === 0
455+
return Const(false)
452456
end
453457
elseif isa(a1, Union)
454458
# Results can only be `Const` or `Bool`

Compiler/test/inference.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ let isdefined_tfunc(@nospecialize xs...) =
12071207
@test isdefined_tfunc(Union{UnionIsdefinedA,UnionIsdefinedB}, Const(:x)) === Const(true)
12081208
@test isdefined_tfunc(Union{UnionIsdefinedA,UnionIsdefinedB}, Const(:y)) === Const(false)
12091209
@test isdefined_tfunc(Union{UnionIsdefinedA,Nothing}, Const(:x)) === Bool
1210+
@test isdefined_tfunc(Nothing, Any) === Const(false)
12101211
end
12111212

12121213
# https://github.com/aviatesk/JET.jl/issues/379

base/runtime_internals.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ function datatype_fieldcount(t::DataType)
11151115
return length(names)
11161116
end
11171117
if types isa DataType && types <: Tuple
1118-
return fieldcount(types)
1118+
return datatype_fieldcount(types)
11191119
end
11201120
return nothing
11211121
elseif isabstracttype(t)

0 commit comments

Comments
 (0)