Skip to content

Commit

Permalink
fix some t-functions on PartialTuple arguments (#31014)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 9, 2019
1 parent 89d64c6 commit 0680f19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 10 additions & 4 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ function sizeof_nothrow(@nospecialize(x))
x = x.val
elseif isa(x, Conditional)
return true
else
x = widenconst(x)
end
isconstType(x) && (x = x.parameters[1])
if isa(x, Union)
Expand All @@ -325,13 +327,15 @@ function sizeof_tfunc(@nospecialize(x),)
isa(x, Const) && return _const_sizeof(x.val)
isa(x, Conditional) && return _const_sizeof(Bool)
isconstType(x) && return _const_sizeof(x.parameters[1])
x = widenconst(x)
x !== DataType && isconcretetype(x) && return _const_sizeof(x)
return Int
end
add_tfunc(Core.sizeof, 1, 1, sizeof_tfunc, 0)
function nfields_tfunc(@nospecialize(x))
isa(x, Const) && return Const(nfields(x.val))
isa(x, Conditional) && return Const(0)
x = widenconst(x)
if isa(x, DataType) && !x.abstract && !(x.name === Tuple.name && isvatuple(x))
if !(x.name === _NAMEDTUPLE_NAME && !isconcretetype(x))
return Const(length(x.types))
Expand Down Expand Up @@ -470,12 +474,14 @@ function isa_tfunc(@nospecialize(v), @nospecialize(tt))
if isexact && isnotbrokensubtype(v, t)
return Const(true)
end
elseif isa(v, Const) || isa(v, Conditional) || isdispatchelem(v)
# this tests for knowledge of a leaftype appearing on the LHS
# (ensuring the isa is precise)
return Const(false)
else
if isa(v, Const) || isa(v, Conditional)
# this and the `isdispatchelem` below test for knowledge of a
# leaftype appearing on the LHS (ensuring the isa is precise)
return Const(false)
end
v = widenconst(v)
isdispatchelem(v) && return Const(false)
if typeintersect(v, t) === Bottom
# similar to `isnotbrokensubtype` check above, `typeintersect(v, t)`
# can't be trusted for kind types so we do an extra check here
Expand Down
7 changes: 7 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,13 @@ let egal_tfunc
@test egal_tfunc(Union{Int64, Float64}, AbstractArray) === Const(false)
end

using Core.Compiler: PartialTuple, nfields_tfunc, sizeof_tfunc, sizeof_nothrow
let PT = PartialTuple(Tuple{Int64,UInt64}, Any[Const(10, false), UInt64])
@test sizeof_tfunc(PT) === Const(16, false)
@test nfields_tfunc(PT) === Const(2, false)
@test sizeof_nothrow(PT) === true
end

function f23024(::Type{T}, ::Int) where T
1 + 1
end
Expand Down

2 comments on commit 0680f19

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.