Skip to content

Commit b4434a6

Browse files
committed
Restructure tmeet based on feedback
1 parent a823309 commit b4434a6

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

base/compiler/typelimits.jl

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -586,21 +586,19 @@ end
586586
# compute typeintersect over the extended inference lattice
587587
# where v is in the extended lattice, and t is a Type
588588
function tmeet(@nospecialize(v), @nospecialize(t))
589-
if isa(v, Const)
590-
if !has_free_typevars(t) && !isa(v.val, t)
591-
return Bottom
592-
end
589+
if isa(v, Type)
590+
return typeintersect(v, t)
591+
end
592+
has_free_typevars(t) && return v
593+
widev = widenconst(v)
594+
if widev <: t
593595
return v
594-
elseif isa(v, PartialStruct)
595-
has_free_typevars(t) && return v
596-
widev = widenconst(v)
597-
if widev <: t
598-
return v
599-
end
600-
ti = typeintersect(widev, t)
601-
if ti === Bottom
602-
return Bottom
603-
end
596+
end
597+
ti = typeintersect(widev, t)
598+
if ti === Bottom
599+
return Bottom
600+
end
601+
if isa(v, PartialStruct)
604602
@assert widev <: Tuple
605603
if isa(ti, DataType) && ti.name === Tuple.name
606604
num_fields = length(ti.parameters)
@@ -612,7 +610,7 @@ function tmeet(@nospecialize(v), @nospecialize(t))
612610
end
613611
new_fields = Vector{Any}(undef, num_fields)
614612
for i = 1:num_fields
615-
new_fields[i] = tmeet(getfield_tfunc(v, Const(i)), widenconst(getfield_tfunc(ti, Const(i))))
613+
new_fields[i] = tmeet(unwrapva(v.fields[min(i, end)]), widenconst(getfield_tfunc(ti, Const(i))))
616614
if new_fields[i] === Bottom
617615
return Bottom
618616
end
@@ -621,11 +619,7 @@ function tmeet(@nospecialize(v), @nospecialize(t))
621619
new_fields[end] = Vararg{new_fields[end]}
622620
end
623621
return tuple_tfunc(new_fields)
624-
elseif isa(v, Conditional)
625-
if !(Bool <: t)
626-
return Bottom
627-
end
628-
return v
629622
end
630-
return typeintersect(widenconst(v), t)
623+
# v is a Const or Conditional and its type is compatible with t
624+
return v
631625
end

0 commit comments

Comments
 (0)