Skip to content

Commit 0680f19

Browse files
authored
fix some t-functions on PartialTuple arguments (#31014)
1 parent 89d64c6 commit 0680f19

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

base/compiler/tfuncs.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ function sizeof_nothrow(@nospecialize(x))
299299
x = x.val
300300
elseif isa(x, Conditional)
301301
return true
302+
else
303+
x = widenconst(x)
302304
end
303305
isconstType(x) && (x = x.parameters[1])
304306
if isa(x, Union)
@@ -325,13 +327,15 @@ function sizeof_tfunc(@nospecialize(x),)
325327
isa(x, Const) && return _const_sizeof(x.val)
326328
isa(x, Conditional) && return _const_sizeof(Bool)
327329
isconstType(x) && return _const_sizeof(x.parameters[1])
330+
x = widenconst(x)
328331
x !== DataType && isconcretetype(x) && return _const_sizeof(x)
329332
return Int
330333
end
331334
add_tfunc(Core.sizeof, 1, 1, sizeof_tfunc, 0)
332335
function nfields_tfunc(@nospecialize(x))
333336
isa(x, Const) && return Const(nfields(x.val))
334337
isa(x, Conditional) && return Const(0)
338+
x = widenconst(x)
335339
if isa(x, DataType) && !x.abstract && !(x.name === Tuple.name && isvatuple(x))
336340
if !(x.name === _NAMEDTUPLE_NAME && !isconcretetype(x))
337341
return Const(length(x.types))
@@ -470,12 +474,14 @@ function isa_tfunc(@nospecialize(v), @nospecialize(tt))
470474
if isexact && isnotbrokensubtype(v, t)
471475
return Const(true)
472476
end
473-
elseif isa(v, Const) || isa(v, Conditional) || isdispatchelem(v)
474-
# this tests for knowledge of a leaftype appearing on the LHS
475-
# (ensuring the isa is precise)
476-
return Const(false)
477477
else
478+
if isa(v, Const) || isa(v, Conditional)
479+
# this and the `isdispatchelem` below test for knowledge of a
480+
# leaftype appearing on the LHS (ensuring the isa is precise)
481+
return Const(false)
482+
end
478483
v = widenconst(v)
484+
isdispatchelem(v) && return Const(false)
479485
if typeintersect(v, t) === Bottom
480486
# similar to `isnotbrokensubtype` check above, `typeintersect(v, t)`
481487
# can't be trusted for kind types so we do an extra check here

test/compiler/inference.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,13 @@ let egal_tfunc
13381338
@test egal_tfunc(Union{Int64, Float64}, AbstractArray) === Const(false)
13391339
end
13401340

1341+
using Core.Compiler: PartialTuple, nfields_tfunc, sizeof_tfunc, sizeof_nothrow
1342+
let PT = PartialTuple(Tuple{Int64,UInt64}, Any[Const(10, false), UInt64])
1343+
@test sizeof_tfunc(PT) === Const(16, false)
1344+
@test nfields_tfunc(PT) === Const(2, false)
1345+
@test sizeof_nothrow(PT) === true
1346+
end
1347+
13411348
function f23024(::Type{T}, ::Int) where T
13421349
1 + 1
13431350
end

0 commit comments

Comments
 (0)