Skip to content

Commit

Permalink
Fix @isdefined with new optimizer
Browse files Browse the repository at this point in the history
The only values that are special for an `:isdefined` expression are SSAValues
(which are tracked through to phi nodes to see if they are defined), global
variables and static parameters (both of which have support in the interpreter
and codegen).

Fixes #27103.
  • Loading branch information
Keno authored and staticfloat committed May 21, 2018
1 parent f4356d6 commit 3403939
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,11 @@ function type_lift_pass!(ir::IRCode)
# so lift all these nodes that have maybe undef values
processed = IdDict{Int, Union{SSAValue, Bool}}()
if !isa(val, SSAValue)
(isa(val, GlobalRef) || isexpr(val, :static_parameter)) && continue
if stmt.head === :undefcheck
ir.stmts[idx] = nothing
else
ir.stmts[idx] = true
end
continue
end
Expand Down
2 changes: 1 addition & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ isconst(m::Module, s::Symbol) =
Tests whether variable `s` is defined in the current scope.
# Examples
```julia-repl
```jldoctest
julia> function f()
println(@isdefined x)
x = 3
Expand Down
14 changes: 14 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6089,3 +6089,17 @@ let A = [1], B = [], C = DelegateIterator([1]), D = DelegateIterator([]), E = An
@test done(D, start(D))
@test next(E, next(E, start(E))[2])[1] == "abc"
end

# Issue 27103
function f27103()
a = @isdefined x
x = 3
b = @isdefined x
(a, b)
end
@test f27103() == (false, true)

g27103() = @isdefined z27103
@test g27103() == false
z27103 = 1
@test g27103() == true

0 comments on commit 3403939

Please sign in to comment.