Skip to content

Commit

Permalink
Hide/remove unused slot flags after lowering
Browse files Browse the repository at this point in the history
This gives us more freedom to pick slot flags in inference.
Also remove the corresponding code validation tests.
  • Loading branch information
yuyichao committed Aug 13, 2017
1 parent cfe3fa7 commit 34a606f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 16 deletions.
6 changes: 0 additions & 6 deletions base/codevalidation.jl
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
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
4 changes: 3 additions & 1 deletion src/method.c
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
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

0 comments on commit 34a606f

Please sign in to comment.