Skip to content

Commit

Permalink
Merge pull request #23241 from JuliaLang/yyc/fixup
Browse files Browse the repository at this point in the history
Backport of a few test fixes and cleanup
  • Loading branch information
yuyichao authored Aug 14, 2017
2 parents 37655e3 + 8f8c951 commit a62160e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 25 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ CORE_SRCS := $(addprefix $(JULIAHOME)/, \
base/array.jl \
base/bool.jl \
base/associative.jl \
base/codevalidation.jl \
base/error.jl \
base/essentials.jl \
base/generator.jl \
Expand Down
6 changes: 0 additions & 6 deletions base/codevalidation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const VALID_EXPR_HEADS = ObjectIdDict(
:simdloop => 0:0
)

const ASSIGNED_FLAG = 0x02

# @enum isn't defined yet, otherwise I'd use it for this
const INVALID_EXPR_HEAD = "invalid expression head"
const INVALID_EXPR_NARGS = "invalid number of expression args"
Expand All @@ -41,7 +39,6 @@ const SLOTTYPES_MISMATCH = "length(slotnames) != length(slottypes)"
const SLOTTYPES_MISMATCH_UNINFERRED = "uninferred CodeInfo slottypes field is not `nothing`"
const SSAVALUETYPES_MISMATCH = "not all SSAValues in AST have a type in ssavaluetypes"
const SSAVALUETYPES_MISMATCH_UNINFERRED = "uninferred CodeInfo ssavaluetypes field does not equal the number of present SSAValues"
const INVALID_ASSIGNMENT_SLOTFLAG = "slot has wrong assignment slotflag setting (bit flag 2 not set)"
const NON_TOP_LEVEL_METHOD = "encountered `Expr` head `:method` in non-top-level code (i.e. `nargs` > 0)"
const SIGNATURE_NARGS_MISMATCH = "method signature does not match number of method arguments"
const SLOTNAMES_NARGS_MISMATCH = "CodeInfo for method contains fewer slotnames than the number of method arguments"
Expand Down Expand Up @@ -76,9 +73,6 @@ function validate_code!(errors::Vector{>:InvalidCodeError}, c::CodeInfo, is_top_
push!(errors, InvalidCodeError(INVALID_LVALUE, lhs))
elseif isa(lhs, SlotNumber) && !in(lhs.id, lhs_slotnums)
n = lhs.id
if isassigned(c.slotflags, n) && !is_flag_set(c.slotflags[n], ASSIGNED_FLAG)
push!(errors, InvalidCodeError(INVALID_ASSIGNMENT_SLOTFLAG, lhs))
end
push!(lhs_slotnums, n)
end
if !is_valid_rvalue(rhs)
Expand Down
3 changes: 1 addition & 2 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ end
# cond && use(a)

# slot property bit flags
const Slot_Assigned = 2
const Slot_AssignedOnce = 16
const Slot_UsedUndef = 32

Expand Down Expand Up @@ -5110,7 +5109,7 @@ function add_slot!(src::CodeInfo, @nospecialize(typ), is_sa::Bool, name::Symbol=
id = length(src.slotnames) + 1
push!(src.slotnames, name)
push!(src.slottypes, typ)
push!(src.slotflags, Slot_Assigned + is_sa * Slot_AssignedOnce)
push!(src.slotflags, is_sa * Slot_AssignedOnce)
return SlotNumber(id)
end

Expand Down
1 change: 1 addition & 0 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jl_options_t jl_options = { 0, // quiet
NULL, // bind-to
NULL, // output-bc
NULL, // output-unopt-bc
NULL, // output-jit-bc
NULL, // output-o
NULL, // output-ji
0, // incremental
Expand Down
4 changes: 3 additions & 1 deletion src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ static void jl_code_info_set_ast(jl_code_info_t *li, jl_expr_t *ast)
jl_gc_wb(li, li->slotflags);
li->ssavaluetypes = jl_box_long(nssavalue);
jl_gc_wb(li, li->ssavaluetypes);
// Flags that need to be copied to slotflags
const uint8_t vinfo_mask = 16 | 32 | 64;
int i;
for (i = 0; i < nslots; i++) {
jl_value_t *vi = jl_array_ptr_ref(vis, i);
Expand All @@ -187,7 +189,7 @@ static void jl_code_info_set_ast(jl_code_info_t *li, jl_expr_t *ast)
}
}
jl_array_ptr_set(li->slotnames, i, name);
jl_array_uint8_set(li->slotflags, i, jl_unbox_long(jl_array_ptr_ref(vi, 2)));
jl_array_uint8_set(li->slotflags, i, vinfo_mask & jl_unbox_long(jl_array_ptr_ref(vi, 2)));
}
}

Expand Down
7 changes: 0 additions & 7 deletions test/codevalidation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ errors = Core.Inference.validate_code(c)
@test length(errors) == 1
@test errors[1].kind === Core.Inference.SSAVALUETYPES_MISMATCH_UNINFERRED

# INVALID_ASSIGNMENT_SLOTFLAG
c = Core.Inference.copy_code_info(c0)
c.slotflags[8] = 0x00
errors = Core.Inference.validate_code(c)
@test length(errors) == 1
@test errors[1].kind === Core.Inference.INVALID_ASSIGNMENT_SLOTFLAG

# SIGNATURE_NARGS_MISMATCH
old_sig = mi.def.sig
mi.def.sig = Tuple{1,2}
Expand Down
38 changes: 30 additions & 8 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,17 @@ function g15714(array_var15714)
for index_var15714 in eachindex(array_var15714)
array_var15714[index_var15714] += 0
end
for index_var15714 in eachindex(array_var15714)
array_var15714[index_var15714] += 0
let index_var15714
for index_var15714 in eachindex(array_var15714)
array_var15714[index_var15714] += 0
end
index_var15714
end
let index_var15714
for index_var15714 in eachindex(array_var15714)
array_var15714[index_var15714] += 0
end
index_var15714
end
end

Expand All @@ -411,6 +420,10 @@ function test_typed_ast_printing(Base.@nospecialize(f), Base.@nospecialize(types
for name in must_used_vars
@test name in slotnames
end
must_used_checked = Dict{Symbol,Bool}()
for sym in must_used_vars
must_used_checked[sym] = false
end
for str in (sprint(code_warntype, f, types),
stringmime("text/plain", src))
for var in must_used_vars
Expand All @@ -422,31 +435,40 @@ function test_typed_ast_printing(Base.@nospecialize(f), Base.@nospecialize(types
for i in 1:length(src.slotnames)
name = src.slotnames[i]
if name in dupnames
@test contains(str, "_$i")
if name in must_used_vars
if name in must_used_vars && ismatch(Regex("_$i\\b"), str)
must_used_checked[name] = true
global used_dup_var_tested15714 = true
end
else
@test !contains(str, "_$i")
@test !ismatch(Regex("_$i\\b"), str)
if name in must_used_vars
global used_unique_var_tested15714 = true
end
end
end
end
for sym in must_used_vars
if sym in dupnames
@test must_used_checked[sym]
end
must_used_checked[sym] = false
end
# Make sure printing an AST outside CodeInfo still works.
str = sprint(show, src.code)
# Check that we are printing the slot numbers when we don't have the context
# Use the variable names that we know should be present in the optimized AST
for i in 2:length(src.slotnames)
name = src.slotnames[i]
if name in must_used_vars
@test contains(str, "_$i")
if name in must_used_vars && ismatch(Regex("_$i\\b"), str)
must_used_checked[name] = true
end
end
for sym in must_used_vars
@test must_used_checked[sym]
end
end
test_typed_ast_printing(f15714, Tuple{Vector{Float32}},
[:array_var15714, :index_var15714])
[:array_var15714])
test_typed_ast_printing(g15714, Tuple{Vector{Float32}},
[:array_var15714, :index_var15714])
@test used_dup_var_tested15714
Expand Down
2 changes: 1 addition & 1 deletion test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ str = String(take!(io))
# NOTE: This test depends on the code generated by @testset getting compiled,
# to get good backtraces. If it fails, check the implementation of `testset_beginend`.
@test contains(str, "test.jl")
@test !contains(str, "boot.jl")
@test !contains(str, "client.jl")

let io = IOBuffer()
exc = Test.TestSetException(1,2,3,4,Vector{Union{Base.Test.Error, Base.Test.Fail}}())
Expand Down

0 comments on commit a62160e

Please sign in to comment.