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
signature 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 @@...@@ -1,6 +1,8 @@
1Scratch pad for stuff to do before merging master1Scratch pad for stuff to do before merging master
2=================================================2=================================================
33
4uncomment all the behavior tests
5
4restore test_runner.zig to master branch6restore test_runner.zig to master branch
5 - also the default panic function and unexpected_error_tracing. see the commit7 - also the default panic function and unexpected_error_tracing. see the commit
6 that adds this text to BRANCH_TODO file.8 that adds this text to BRANCH_TODO file.
...@@ -8,11 +10,21 @@ restore test_runner.zig to master branch...@@ -8,11 +10,21 @@ restore test_runner.zig to master branch
810
9get an empty file compiling successfully (with no panic fn override)11get an empty file compiling successfully (with no panic fn override)
1012
11uncomment all the behavior tests
12
13better behavior for implicit casts. for example these introduce an extra allocation/memcpy:13better behavior for implicit casts. for example these introduce an extra allocation/memcpy:
14 var x: [1]i32 = [_]i32{1};14 var x: [1]i32 = [_]i32{1};
15 var x = ([1]i32)([_]i32{1});15 var x = ([1]i32)([_]i32{1});
16whereas this one does not:16whereas this one does not:
17 var x = [_]i32{1};17 var x = [_]i32{1};
18but all 3 should be semantically identical18but 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 {...@@ -3662,6 +3662,7 @@ struct ResultLocPeerParent {
36623662
3663 bool skipped;3663 bool skipped;
3664 bool done_resuming;3664 bool done_resuming;
3665 IrBasicBlock *end_bb;
3665 ResultLoc *parent;3666 ResultLoc *parent;
3666 ResultLocPeer *peers;3667 ResultLocPeer *peers;
3667 size_t peer_count;3668 size_t peer_count;
src/ir.cpp+4-3
...@@ -3901,6 +3901,7 @@ static ResultLocPeerParent *create_binary_result_peers(IrInstruction *cond_br_in...@@ -3901,6 +3901,7 @@ static ResultLocPeerParent *create_binary_result_peers(IrInstruction *cond_br_in
3901 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);3901 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
3902 peer_parent->base.id = ResultLocIdPeerParent;3902 peer_parent->base.id = ResultLocIdPeerParent;
3903 peer_parent->base.source_instruction = cond_br_inst;3903 peer_parent->base.source_instruction = cond_br_inst;
3904 peer_parent->end_bb = endif_block;
3904 peer_parent->is_comptime = is_comptime;3905 peer_parent->is_comptime = is_comptime;
3905 peer_parent->parent = parent;3906 peer_parent->parent = parent;
3906 peer_parent->peer_count = 2;3907 peer_parent->peer_count = 2;
...@@ -6894,6 +6895,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6894,6 +6895,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
68946895
6895 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);6896 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
6896 peer_parent->base.id = ResultLocIdPeerParent;6897 peer_parent->base.id = ResultLocIdPeerParent;
6898 peer_parent->end_bb = end_block;
6897 peer_parent->is_comptime = is_comptime;6899 peer_parent->is_comptime = is_comptime;
6898 peer_parent->parent = result_loc;6900 peer_parent->parent = result_loc;
6899 peer_parent->peers = allocate<ResultLocPeer>(prong_count);6901 peer_parent->peers = allocate<ResultLocPeer>(prong_count);
...@@ -14923,9 +14925,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -14923,9 +14925,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
14923 }14925 }
1492414926
14925 if (peer_parent->resolved_type == nullptr) {14927 if (peer_parent->resolved_type == nullptr) {
14926 ResultLocPeer *last_peer = &peer_parent->peers[peer_parent->peer_count - 1];14928 if (peer_parent->end_bb->suspend_instruction_ref == nullptr) {
14927 if (last_peer->next_bb->suspend_instruction_ref == nullptr) {14929 peer_parent->end_bb->suspend_instruction_ref = suspend_source_instr;
14928 last_peer->next_bb->suspend_instruction_ref = suspend_source_instr;
14929 }14930 }
14930 return ira_suspend(ira, suspend_source_instr, result_peer->next_bb, &result_peer->suspend_pos);14931 return ira_suspend(ira, suspend_source_instr, result_peer->next_bb, &result_peer->suspend_pos);
14931 }14932 }
test/stage1/behavior.zig+4-4
...@@ -31,7 +31,7 @@ comptime {...@@ -31,7 +31,7 @@ comptime {
31 _ = @import("behavior/bugs/421.zig");31 _ = @import("behavior/bugs/421.zig");
32 _ = @import("behavior/bugs/529.zig");32 _ = @import("behavior/bugs/529.zig");
33 _ = @import("behavior/bugs/655.zig");33 _ = @import("behavior/bugs/655.zig");
34 //_ = @import("behavior/bugs/656.zig");34 _ = @import("behavior/bugs/656.zig");
35 _ = @import("behavior/bugs/679.zig");35 _ = @import("behavior/bugs/679.zig");
36 _ = @import("behavior/bugs/704.zig");36 _ = @import("behavior/bugs/704.zig");
37 _ = @import("behavior/bugs/718.zig");37 _ = @import("behavior/bugs/718.zig");
...@@ -71,7 +71,7 @@ comptime {...@@ -71,7 +71,7 @@ comptime {
71 _ = @import("behavior/popcount.zig");71 _ = @import("behavior/popcount.zig");
72 //_ = @import("behavior/ptrcast.zig");72 //_ = @import("behavior/ptrcast.zig");
73 _ = @import("behavior/pub_enum.zig");73 _ = @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");
75 _ = @import("behavior/reflection.zig");75 _ = @import("behavior/reflection.zig");
76 _ = @import("behavior/sizeof_and_typeof.zig");76 _ = @import("behavior/sizeof_and_typeof.zig");
77 //_ = @import("behavior/slice.zig");77 //_ = @import("behavior/slice.zig");
...@@ -81,7 +81,7 @@ comptime {...@@ -81,7 +81,7 @@ comptime {
81 _ = @import("behavior/struct_contains_slice_of_itself.zig");81 _ = @import("behavior/struct_contains_slice_of_itself.zig");
82 //_ = @import("behavior/switch.zig");82 //_ = @import("behavior/switch.zig");
83 //_ = @import("behavior/switch_prong_err_enum.zig");83 //_ = @import("behavior/switch_prong_err_enum.zig");
84 //_ = @import("behavior/switch_prong_implicit_cast.zig");84 _ = @import("behavior/switch_prong_implicit_cast.zig");
85 _ = @import("behavior/syntax.zig");85 _ = @import("behavior/syntax.zig");
86 _ = @import("behavior/this.zig");86 _ = @import("behavior/this.zig");
87 _ = @import("behavior/truncate.zig");87 _ = @import("behavior/truncate.zig");
...@@ -90,7 +90,7 @@ comptime {...@@ -90,7 +90,7 @@ comptime {
90 //_ = @import("behavior/typename.zig");90 //_ = @import("behavior/typename.zig");
91 _ = @import("behavior/undefined.zig");91 _ = @import("behavior/undefined.zig");
92 _ = @import("behavior/underscore.zig");92 _ = @import("behavior/underscore.zig");
93 //_ = @import("behavior/union.zig");93 _ = @import("behavior/union.zig");
94 _ = @import("behavior/var_args.zig");94 _ = @import("behavior/var_args.zig");
95 _ = @import("behavior/vector.zig");95 _ = @import("behavior/vector.zig");
96 _ = @import("behavior/void.zig");96 _ = @import("behavior/void.zig");