Skip to content

Commit aa17702

Browse files
oscardssmithKeno
andauthored
improve partial opaque inference (JuliaLang#45782)
improve opaqueclosure inference JuliaLang#42831 started calling `tmeet` in abstractinterpretation of `:new` which meant that we now need to be able to infer it. Co-authored-by: Keno Fischer <[email protected]>
1 parent 4873773 commit aa17702

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

base/compiler/typelattice.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,15 @@ function tmeet(@nospecialize(v), @nospecialize(t::Type))
397397
end
398398
end
399399
return tuple_tfunc(new_fields)
400+
elseif isa(v, PartialOpaque)
401+
has_free_typevars(t) && return v
402+
widev = widenconst(v)
403+
if widev <: t
404+
return v
405+
end
406+
ti = typeintersect(widev, t)
407+
valid_as_lattice(ti) || return Bottom
408+
return PartialOpaque(ti, v.env, v.parent, v.source)
400409
elseif isa(v, Conditional)
401410
if !(Bool <: t)
402411
return Bottom

test/compiler/inference.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,3 +4250,9 @@ let # NOTE make sure this toplevel chunk doesn't contain any local binding
42504250
while xcond end
42514251
end
42524252
@test !xcond
4253+
4254+
struct Issue45780
4255+
oc::Core.OpaqueClosure{Tuple{}}
4256+
end
4257+
f45780() = Val{Issue45780(@Base.Experimental.opaque ()->1).oc()}()
4258+
@test (@inferred f45780()) == Val{1}()

0 commit comments

Comments
 (0)