authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-14 11:41:53-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-14 11:41:53-04:00
log7c074b85165c6aff6bdaccd0fecea59489a2de58
tree753126cea46836fb7af4060e2e92ca6b2471ad85
parent2ba29a1907264d6466f187cd89552a63160d3922
signaturelock-open Commit is signed but in an unrecognized format.

fix peer result locs with switch


4 files changed, 23 insertions(+), 9 deletions(-)

BRANCH_TODO+14-2
......@@ -1,6 +1,8 @@
11Scratch pad for stuff to do before merging master
22=================================================
33
4uncomment all the behavior tests
5
46restore test_runner.zig to master branch
57 - also the default panic function and unexpected_error_tracing. see the commit
68 that adds this text to BRANCH_TODO file.
......@@ -8,11 +10,21 @@ restore test_runner.zig to master branch
810
911get an empty file compiling successfully (with no panic fn override)
1012
11uncomment all the behavior tests
12
1313better behavior for implicit casts. for example these introduce an extra allocation/memcpy:
1414 var x: [1]i32 = [_]i32{1};
1515 var x = ([1]i32)([_]i32{1});
1616whereas this one does not:
1717 var x = [_]i32{1};
1818but all 3 should be semantically identical
19
20
21This example has less than ideal LLVM IR:
22```zig
23export fn entry() void {
24 _ = mul(true, 1) catch undefined;
25}
26pub fn mul(c: bool, answer: i32) error{Overflow}!i32 {
27 return if (c) error.Overflow else answer;
28}
29```
30It creates an unnecessary stack variable.
src/all_types.hpp+1
......@@ -3662,6 +3662,7 @@ struct ResultLocPeerParent {
36623662
36633663 bool skipped;
36643664 bool done_resuming;
3665 IrBasicBlock *end_bb;
36653666 ResultLoc *parent;
36663667 ResultLocPeer *peers;
36673668 size_t peer_count;
src/ir.cpp+4-3
......@@ -3901,6 +3901,7 @@ static ResultLocPeerParent *create_binary_result_peers(IrInstruction *cond_br_in
39013901 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
39023902 peer_parent->base.id = ResultLocIdPeerParent;
39033903 peer_parent->base.source_instruction = cond_br_inst;
3904 peer_parent->end_bb = endif_block;
39043905 peer_parent->is_comptime = is_comptime;
39053906 peer_parent->parent = parent;
39063907 peer_parent->peer_count = 2;
......@@ -6894,6 +6895,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
68946895
68956896 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
68966897 peer_parent->base.id = ResultLocIdPeerParent;
6898 peer_parent->end_bb = end_block;
68976899 peer_parent->is_comptime = is_comptime;
68986900 peer_parent->parent = result_loc;
68996901 peer_parent->peers = allocate<ResultLocPeer>(prong_count);
......@@ -14923,9 +14925,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1492314925 }
1492414926
1492514927 if (peer_parent->resolved_type == nullptr) {
14926 ResultLocPeer *last_peer = &peer_parent->peers[peer_parent->peer_count - 1];
14927 if (last_peer->next_bb->suspend_instruction_ref == nullptr) {
14928 last_peer->next_bb->suspend_instruction_ref = suspend_source_instr;
14928 if (peer_parent->end_bb->suspend_instruction_ref == nullptr) {
14929 peer_parent->end_bb->suspend_instruction_ref = suspend_source_instr;
1492914930 }
1493014931 return ira_suspend(ira, suspend_source_instr, result_peer->next_bb, &result_peer->suspend_pos);
1493114932 }
test/stage1/behavior.zig+4-4
......@@ -31,7 +31,7 @@ comptime {
3131 _ = @import("behavior/bugs/421.zig");
3232 _ = @import("behavior/bugs/529.zig");
3333 _ = @import("behavior/bugs/655.zig");
34 //_ = @import("behavior/bugs/656.zig");
34 _ = @import("behavior/bugs/656.zig");
3535 _ = @import("behavior/bugs/679.zig");
3636 _ = @import("behavior/bugs/704.zig");
3737 _ = @import("behavior/bugs/718.zig");
......@@ -71,7 +71,7 @@ comptime {
7171 _ = @import("behavior/popcount.zig");
7272 //_ = @import("behavior/ptrcast.zig");
7373 _ = @import("behavior/pub_enum.zig");
74 //_ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
74 _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
7575 _ = @import("behavior/reflection.zig");
7676 _ = @import("behavior/sizeof_and_typeof.zig");
7777 //_ = @import("behavior/slice.zig");
......@@ -81,7 +81,7 @@ comptime {
8181 _ = @import("behavior/struct_contains_slice_of_itself.zig");
8282 //_ = @import("behavior/switch.zig");
8383 //_ = @import("behavior/switch_prong_err_enum.zig");
84 //_ = @import("behavior/switch_prong_implicit_cast.zig");
84 _ = @import("behavior/switch_prong_implicit_cast.zig");
8585 _ = @import("behavior/syntax.zig");
8686 _ = @import("behavior/this.zig");
8787 _ = @import("behavior/truncate.zig");
......@@ -90,7 +90,7 @@ comptime {
9090 //_ = @import("behavior/typename.zig");
9191 _ = @import("behavior/undefined.zig");
9292 _ = @import("behavior/underscore.zig");
93 //_ = @import("behavior/union.zig");
93 _ = @import("behavior/union.zig");
9494 _ = @import("behavior/var_args.zig");
9595 _ = @import("behavior/vector.zig");
9696 _ = @import("behavior/void.zig");