authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-27 16:05:17+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-27 18:33:23+03:00
logd4917957ef5aad5a0f381d21040a81c5afe12718
tree5011a6e0b9bcaf17a10be454ce08c58c7ab9447b
parent509bb82b20e9417d8b0ff604cd87f70fd1fcf4e9

Sema: add better source location for inline prong backwards branch limit


1 files changed, 23 insertions(+), 7 deletions(-)

src/Sema.zig+23-7
...@@ -10042,7 +10042,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10042,7 +10042,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10042 defer gpa.free(prev_then_body);10042 defer gpa.free(prev_then_body);
1004310043
10044 var cases_len = scalar_cases_len;10044 var cases_len = scalar_cases_len;
10045 var multi_i: usize = 0;10045 var multi_i: u32 = 0;
10046 while (multi_i < multi_cases_len) : (multi_i += 1) {10046 while (multi_i < multi_cases_len) : (multi_i += 1) {
10047 const items_len = sema.code.extra[extra_index];10047 const items_len = sema.code.extra[extra_index];
10048 extra_index += 1;10048 extra_index += 1;
...@@ -10062,10 +10062,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10062,10 +10062,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10062 if (is_inline) {10062 if (is_inline) {
10063 const body_start = extra_index + 2 * ranges_len;10063 const body_start = extra_index + 2 * ranges_len;
10064 const body = sema.code.extra[body_start..][0..body_len];10064 const body = sema.code.extra[body_start..][0..body_len];
10065 const case_src = src; // TODO better source location
10066 var emit_bb = false;10065 var emit_bb = false;
1006710066
10068 var range_i: usize = 0;10067 var range_i: u32 = 0;
10069 while (range_i < ranges_len) : (range_i += 1) {10068 while (range_i < ranges_len) : (range_i += 1) {
10070 const first_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);10069 const first_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]);
10071 extra_index += 1;10070 extra_index += 1;
...@@ -10078,7 +10077,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10078,7 +10077,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10078 const item_last = sema.resolveConstValue(block, .unneeded, item_last_ref, undefined) catch unreachable;10077 const item_last = sema.resolveConstValue(block, .unneeded, item_last_ref, undefined) catch unreachable;
1007910078
10080 while (item.compare(.lte, item_last, operand_ty, sema.mod)) : ({10079 while (item.compare(.lte, item_last, operand_ty, sema.mod)) : ({
10081 item = try sema.intAddScalar(block, case_src, item, Value.one);10080 // Previous validation has resolved any possible lazy values.
10081 item = try sema.intAddScalar(block, .unneeded, item, Value.one);
10082 }) {10082 }) {
10083 cases_len += 1;10083 cases_len += 1;
1008410084
...@@ -10088,7 +10088,15 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10088,7 +10088,15 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10088 case_block.instructions.shrinkRetainingCapacity(0);10088 case_block.instructions.shrinkRetainingCapacity(0);
10089 case_block.wip_capture_scope = child_block.wip_capture_scope;10089 case_block.wip_capture_scope = child_block.wip_capture_scope;
1009010090
10091 if (emit_bb) try sema.emitBackwardBranch(block, case_src);10091 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
10092 error.NeededSourceLocation => {
10093 const case_src = Module.SwitchProngSrc{ .range = .{ .prong = multi_i, .item = range_i } };
10094 const decl = sema.mod.declPtr(case_block.src_decl);
10095 try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none));
10096 return error.AnalysisFail;
10097 },
10098 else => return err,
10099 };
10092 emit_bb = true;10100 emit_bb = true;
1009310101
10094 try sema.analyzeBodyRuntimeBreak(&case_block, body);10102 try sema.analyzeBodyRuntimeBreak(&case_block, body);
...@@ -10101,7 +10109,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10101,7 +10109,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10101 }10109 }
10102 }10110 }
1010310111
10104 for (items) |item_ref| {10112 for (items) |item_ref, item_i| {
10105 cases_len += 1;10113 cases_len += 1;
1010610114
10107 const item = try sema.resolveInst(item_ref);10115 const item = try sema.resolveInst(item_ref);
...@@ -10116,7 +10124,15 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10116,7 +10124,15 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10116 break :blk field_ty.zigTypeTag() != .NoReturn;10124 break :blk field_ty.zigTypeTag() != .NoReturn;
10117 } else true;10125 } else true;
1011810126
10119 if (emit_bb) try sema.emitBackwardBranch(block, case_src);10127 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
10128 error.NeededSourceLocation => {
10129 const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } };
10130 const decl = sema.mod.declPtr(case_block.src_decl);
10131 try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none));
10132 return error.AnalysisFail;
10133 },
10134 else => return err,
10135 };
10120 emit_bb = true;10136 emit_bb = true;
1012110137
10122 if (analyze_body) {10138 if (analyze_body) {