feat: execute existing hash maps through Honey
This commit is contained in:
@@ -1101,6 +1101,7 @@ collect_block proc(state @mut State, id, return_annotation ast.NodeId, in_loop b
|
||||
try collect_declaration(state, statement)
|
||||
}
|
||||
.expression: try collect_expression(state, ast.statement_expr(tree, statement))
|
||||
.unreachable_stmt: state.cells[usize(statement)].type = Type{ kind = .void }
|
||||
.return_stmt: {
|
||||
state.cells[usize(statement)].role = .return_stmt
|
||||
state.cells[usize(statement)].type = Type{ kind = .void }
|
||||
@@ -2335,6 +2336,7 @@ validate_call proc(state @mut State, id ast.NodeId) void ! (mem.AllocError | dia
|
||||
BlockFlow :: struct {
|
||||
falls bool = true
|
||||
yields bool = false
|
||||
breaks bool = false
|
||||
}
|
||||
|
||||
@hide:file
|
||||
@@ -2367,6 +2369,16 @@ expression_falls_through proc(state @State, id ast.NodeId) bool {
|
||||
}
|
||||
}
|
||||
|
||||
@hide:file
|
||||
expression_breaks proc(state @State, id ast.NodeId) bool {
|
||||
tree :: state.tree
|
||||
if (ast.node_class(tree, id) == .block) return block_flow(state, id).breaks
|
||||
for 0..ast.child_count(tree, id) |i| {
|
||||
if (expression_breaks(state, ast.child(tree, id, i))) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@hide:file
|
||||
block_flow proc(state @State, id ast.NodeId) BlockFlow {
|
||||
tree :: state.tree
|
||||
@@ -2381,30 +2393,62 @@ block_flow proc(state @State, id ast.NodeId) BlockFlow {
|
||||
}
|
||||
match kind {
|
||||
.yield_stmt: {
|
||||
if (ast.yield_stmt(tree, statement).value) |value|
|
||||
result.breaks = result.breaks or expression_breaks(state, value)
|
||||
result.yields = true
|
||||
result.falls = false
|
||||
}
|
||||
.return_stmt, .break_stmt, .continue_stmt, .invalid: result.falls = false
|
||||
.return_stmt: {
|
||||
if (ast.return_stmt(tree, statement).value) |value|
|
||||
result.breaks = result.breaks or expression_breaks(state, value)
|
||||
result.falls = false
|
||||
}
|
||||
.break_stmt: {
|
||||
result.breaks = true
|
||||
result.falls = false
|
||||
}
|
||||
.continue_stmt, .unreachable_stmt, .invalid: result.falls = false
|
||||
.block_stmt: {
|
||||
nested :: block_flow(state, ast.statement_block(tree, statement))
|
||||
result.yields = result.yields or nested.yields
|
||||
result.breaks = result.breaks or nested.breaks
|
||||
result.falls = nested.falls
|
||||
}
|
||||
.if_stmt: {
|
||||
conditional :: ast.if_stmt(tree, statement)
|
||||
then_flow :: block_flow(state, conditional.then_block)
|
||||
result.yields = result.yields or then_flow.yields
|
||||
result.breaks = result.breaks or then_flow.breaks or expression_breaks(state, conditional.condition)
|
||||
if (conditional.else_block) |other| {
|
||||
else_flow :: block_flow(state, other)
|
||||
result.yields = result.yields or else_flow.yields
|
||||
result.breaks = result.breaks or else_flow.breaks
|
||||
result.falls = then_flow.falls or else_flow.falls
|
||||
}
|
||||
}
|
||||
.while_stmt: result.yields = result.yields or block_flow(state, ast.while_stmt(tree, statement).body).yields
|
||||
.for_stmt: result.yields = result.yields or block_flow(state, ast.for_stmt(tree, statement).body).yields
|
||||
.expression: result.falls = expression_falls_through(state, source)
|
||||
.declaration: result.falls = expression_falls_through(state, ast.statement_decl(tree, statement).initializer)
|
||||
.assignment_stmt: result.falls = expression_falls_through(state, ast.assignment_stmt(tree, statement).value)
|
||||
.while_stmt: {
|
||||
loop :: ast.while_stmt(tree, statement)
|
||||
body :: block_flow(state, loop.body)
|
||||
result.yields = result.yields or body.yields
|
||||
result.breaks = result.breaks or expression_breaks(state, loop.condition)
|
||||
if (loop.capture == null and ast.expr_kind(tree, loop.condition) == .literal_bool
|
||||
and mem.eql(ast.literal_text(tree, loop.condition), "true"))
|
||||
result.falls = body.breaks
|
||||
}
|
||||
.for_stmt: {
|
||||
loop :: ast.for_stmt(tree, statement)
|
||||
result.yields = result.yields or block_flow(state, loop.body).yields
|
||||
result.breaks = result.breaks or expression_breaks(state, loop.iterable)
|
||||
}
|
||||
.expression, .declaration, .assignment_stmt: {
|
||||
value :: if (kind == .expression) source
|
||||
else if (kind == .declaration) ast.statement_decl(tree, statement).initializer
|
||||
else ast.assignment_stmt(tree, statement).value
|
||||
result.breaks = result.breaks or expression_breaks(state, value)
|
||||
if (kind == .assignment_stmt)
|
||||
result.breaks = result.breaks or expression_breaks(state, ast.assignment_stmt(tree, statement).target)
|
||||
result.falls = expression_falls_through(state, value)
|
||||
}
|
||||
else: {}
|
||||
}
|
||||
if (!result.falls) return result
|
||||
|
||||
@@ -684,7 +684,7 @@ return_errors_preserve_identity_check_unreachable_code_and_suppress_missing_retu
|
||||
`void_value proc() void { return 1 }
|
||||
`unknown proc() int { return absent }
|
||||
`syntax proc() int { return (1 }
|
||||
`unreachable proc() int {
|
||||
`after_return proc() int {
|
||||
` return 7
|
||||
` -"bad"
|
||||
`}
|
||||
@@ -910,7 +910,7 @@ analyzes_return_paths_after_trap_propagation_without_poisoning_signatures test {
|
||||
`syntax_trap proc() int {
|
||||
` return 1 stray
|
||||
`}
|
||||
`unreachable proc() int {
|
||||
`after_return proc() int {
|
||||
` return 1
|
||||
` -"bad"
|
||||
`}
|
||||
@@ -1198,7 +1198,7 @@ while_checks_nested_bodies_without_claiming_a_zero_iteration_return test {
|
||||
diagnostic_store := diagnostics.init(mem.c_allocator)
|
||||
defer diagnostics.deinit(&diagnostic_store)
|
||||
source ::
|
||||
`missing proc() int { while true { return 1 } }
|
||||
`terminal proc() int { while true { return 1 } }
|
||||
`bad_body proc() int { while false { -"bad" } }
|
||||
`continues proc() int {
|
||||
` while false { -"bad" }
|
||||
@@ -1226,12 +1226,11 @@ while_checks_nested_bodies_without_claiming_a_zero_iteration_return test {
|
||||
result := try check(mem.c_allocator, &tree, &resolution, &diagnostic_store)
|
||||
defer deinit(&result)
|
||||
|
||||
for usize(0)..usize(2) |index| {
|
||||
function :: ast.package_decl(&tree, index)
|
||||
body :: ast.function_decl(&tree, function).body
|
||||
_ = try expect_fallthrough(&result, &diagnostic_store, function, ast.node_span(&tree, body))
|
||||
try expect_kind(&result, ast.block_statement(&tree, body, 0), .void)
|
||||
}
|
||||
terminal :: ast.package_decl(&tree, 0)
|
||||
try testing.expect(fallthrough_diagnostic(&result, terminal) == null)
|
||||
body :: ast.function_decl(&tree, ast.package_decl(&tree, 1)).body
|
||||
_ = try expect_fallthrough(&result, &diagnostic_store, ast.package_decl(&tree, 1), ast.node_span(&tree, body))
|
||||
try expect_kind(&result, ast.block_statement(&tree, body, 0), .void)
|
||||
continues_body :: ast.function_decl(&tree, ast.package_decl(&tree, 2)).body
|
||||
loop_statement :: ast.block_statement(&tree, continues_body, 0)
|
||||
loop :: ast.while_stmt(&tree, loop_statement)
|
||||
@@ -1261,7 +1260,7 @@ while_checks_nested_bodies_without_claiming_a_zero_iteration_return test {
|
||||
try expect_kind(&result, assignment.target, .int)
|
||||
try expect_kind(&result, assignment.value, .int)
|
||||
}
|
||||
try testing.expect_equal(2, code_count(&diagnostic_store, .missing_return))
|
||||
try testing.expect_equal(1, code_count(&diagnostic_store, .missing_return))
|
||||
try testing.expect_equal(1, code_count(&diagnostic_store, .condition_not_bool))
|
||||
try testing.expect_equal(3, code_count(&diagnostic_store, .invalid_operand))
|
||||
}
|
||||
@@ -1518,7 +1517,7 @@ short_circuit_skip_paths_do_not_guarantee_a_return test {
|
||||
`call proc() int { take(true or 1) }
|
||||
`conditional proc() int { if false and missing_condition { return 1 } }
|
||||
`loop proc() int { while true or missing_guard { return 1 } }
|
||||
`loop_body proc() int { while true { true or 1 } }
|
||||
`loop_body proc(flag bool) int { while flag { true or 1 } }
|
||||
`arms proc(flag bool) int {
|
||||
` if flag { false and missing_arm } else { return 1 }
|
||||
`}
|
||||
|
||||
Reference in New Issue
Block a user