Skip to content

Commit 1237a9c

Browse files
improve isdefined precision for 0 field types (#58220)
alternate to #58214. --------- Co-authored-by: Jeff Bezanson <[email protected]>
1 parent 9fccbda commit 1237a9c

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
@@ -450,6 +450,10 @@ end
450450
return Const(true)
451451
end
452452
end
453+
# datatype_fieldcount is what `fieldcount` uses internally
454+
# and returns nothing (!==0) for non-definite field counts.
455+
elseif datatype_fieldcount(a1) === 0
456+
return Const(false)
453457
end
454458
elseif isa(a1, Union)
455459
# 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
@@ -1210,6 +1210,7 @@ let isdefined_tfunc(@nospecialize xs...) =
12101210
@test isdefined_tfunc(Union{UnionIsdefinedA,UnionIsdefinedB}, Const(:x)) === Const(true)
12111211
@test isdefined_tfunc(Union{UnionIsdefinedA,UnionIsdefinedB}, Const(:y)) === Const(false)
12121212
@test isdefined_tfunc(Union{UnionIsdefinedA,Nothing}, Const(:x)) === Bool
1213+
@test isdefined_tfunc(Nothing, Any) === Const(false)
12131214
end
12141215

12151216
# 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
@@ -1141,7 +1141,7 @@ function datatype_fieldcount(t::DataType)
11411141
return length(names)
11421142
end
11431143
if types isa DataType && types <: Tuple
1144-
return fieldcount(types)
1144+
return datatype_fieldcount(types)
11451145
end
11461146
return nothing
11471147
elseif isabstracttype(t)

0 commit comments

Comments
 (0)