| ... | ... | @@ -11174,11 +11174,13 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11174 | 11174 | const mod = sema.mod; |
| 11175 | 11175 | const gpa = sema.gpa; |
| 11176 | 11176 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 11177 | | const src = inst_data.src(); |
| 11178 | | const src_node_offset = inst_data.src_node; |
| 11179 | | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset }; |
| 11180 | | const else_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset }; |
| 11177 | const switch_src = inst_data.src(); |
| 11178 | const switch_src_node_offset = inst_data.src_node; |
| 11179 | const switch_operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_src_node_offset }; |
| 11180 | const else_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = switch_src_node_offset }; |
| 11181 | 11181 | const extra = sema.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index); |
| 11182 | const main_operand_src: LazySrcLoc = .{ .node_offset_if_cond = extra.data.main_src_node_offset }; |
| 11183 | const main_src: LazySrcLoc = .{ .node_offset_main_token = extra.data.main_src_node_offset }; |
| 11182 | 11184 | |
| 11183 | 11185 | const raw_operand_val = try sema.resolveInst(extra.data.operand); |
| 11184 | 11186 | |
| ... | ... | @@ -11295,9 +11297,9 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11295 | 11297 | defer child_block.instructions.deinit(gpa); |
| 11296 | 11298 | defer merges.deinit(gpa); |
| 11297 | 11299 | |
| 11298 | | const resolved_err_set = try sema.resolveInferredErrorSetTy(block, src, operand_err_set_ty.toIntern()); |
| 11300 | const resolved_err_set = try sema.resolveInferredErrorSetTy(block, main_src, operand_err_set_ty.toIntern()); |
| 11299 | 11301 | if (Type.fromInterned(resolved_err_set).errorSetIsEmpty(mod)) { |
| 11300 | | return sema.resolveBlockBody(block, operand_src, &child_block, non_error_case.body, inst, merges); |
| 11302 | return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges); |
| 11301 | 11303 | } |
| 11302 | 11304 | |
| 11303 | 11305 | const else_error_ty: ?Type = try validateErrSetSwitch( |
| ... | ... | @@ -11324,14 +11326,14 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11324 | 11326 | .tag_capture_inst = undefined, |
| 11325 | 11327 | }; |
| 11326 | 11328 | |
| 11327 | | if (try sema.resolveDefinedValue(&child_block, src, raw_operand_val)) |ov| { |
| 11329 | if (try sema.resolveDefinedValue(&child_block, main_src, raw_operand_val)) |ov| { |
| 11328 | 11330 | const operand_val = if (extra.data.bits.payload_is_ref) |
| 11329 | | (try sema.pointerDeref(&child_block, src, ov, operand_ty)).? |
| 11331 | (try sema.pointerDeref(&child_block, main_src, ov, operand_ty)).? |
| 11330 | 11332 | else |
| 11331 | 11333 | ov; |
| 11332 | 11334 | |
| 11333 | 11335 | if (operand_val.errorUnionIsPayload(mod)) { |
| 11334 | | return sema.resolveBlockBody(block, operand_src, &child_block, non_error_case.body, inst, merges); |
| 11336 | return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges); |
| 11335 | 11337 | } else { |
| 11336 | 11338 | const err_val = Value.fromInterned(try mod.intern(.{ |
| 11337 | 11339 | .err = .{ |
| ... | ... | @@ -11340,9 +11342,9 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11340 | 11342 | }, |
| 11341 | 11343 | })); |
| 11342 | 11344 | spa.operand = if (extra.data.bits.payload_is_ref) |
| 11343 | | try sema.analyzeErrUnionCodePtr(block, operand_src, raw_operand_val) |
| 11345 | try sema.analyzeErrUnionCodePtr(block, switch_operand_src, raw_operand_val) |
| 11344 | 11346 | else |
| 11345 | | try sema.analyzeErrUnionCode(block, operand_src, raw_operand_val); |
| 11347 | try sema.analyzeErrUnionCode(block, switch_operand_src, raw_operand_val); |
| 11346 | 11348 | |
| 11347 | 11349 | if (extra.data.bits.any_uses_err_capture) { |
| 11348 | 11350 | sema.inst_map.putAssumeCapacity(err_capture_inst, spa.operand); |
| ... | ... | @@ -11353,7 +11355,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11353 | 11355 | sema, |
| 11354 | 11356 | spa, |
| 11355 | 11357 | &child_block, |
| 11356 | | try sema.switchCond(block, operand_src, spa.operand), |
| 11358 | try sema.switchCond(block, switch_operand_src, spa.operand), |
| 11357 | 11359 | err_val, |
| 11358 | 11360 | operand_err_set_ty, |
| 11359 | 11361 | .{ |
| ... | ... | @@ -11374,12 +11376,12 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11374 | 11376 | |
| 11375 | 11377 | if (scalar_cases_len + multi_cases_len == 0) { |
| 11376 | 11378 | if (else_error_ty) |ty| if (ty.errorSetIsEmpty(mod)) { |
| 11377 | | return sema.resolveBlockBody(block, operand_src, &child_block, non_error_case.body, inst, merges); |
| 11379 | return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges); |
| 11378 | 11380 | }; |
| 11379 | 11381 | } |
| 11380 | 11382 | |
| 11381 | 11383 | if (child_block.is_comptime) { |
| 11382 | | _ = try sema.resolveConstDefinedValue(&child_block, operand_src, raw_operand_val, .{ |
| 11384 | _ = try sema.resolveConstDefinedValue(&child_block, main_operand_src, raw_operand_val, .{ |
| 11383 | 11385 | .needed_comptime_reason = "condition in comptime switch must be comptime-known", |
| 11384 | 11386 | .block_comptime_reason = child_block.comptime_reason, |
| 11385 | 11387 | }); |
| ... | ... | @@ -11387,17 +11389,17 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11387 | 11389 | } |
| 11388 | 11390 | |
| 11389 | 11391 | const cond = if (extra.data.bits.payload_is_ref) blk: { |
| 11390 | | try sema.checkErrorType(block, src, sema.typeOf(raw_operand_val).elemType2(mod)); |
| 11391 | | const loaded = try sema.analyzeLoad(block, src, raw_operand_val, src); |
| 11392 | | break :blk try sema.analyzeIsNonErr(block, src, loaded); |
| 11392 | try sema.checkErrorType(block, main_src, sema.typeOf(raw_operand_val).elemType2(mod)); |
| 11393 | const loaded = try sema.analyzeLoad(block, main_src, raw_operand_val, main_src); |
| 11394 | break :blk try sema.analyzeIsNonErr(block, main_src, loaded); |
| 11393 | 11395 | } else blk: { |
| 11394 | | try sema.checkErrorType(block, src, sema.typeOf(raw_operand_val)); |
| 11395 | | break :blk try sema.analyzeIsNonErr(block, src, raw_operand_val); |
| 11396 | try sema.checkErrorType(block, main_src, sema.typeOf(raw_operand_val)); |
| 11397 | break :blk try sema.analyzeIsNonErr(block, main_src, raw_operand_val); |
| 11396 | 11398 | }; |
| 11397 | 11399 | |
| 11398 | 11400 | var sub_block = child_block.makeSubBlock(); |
| 11399 | 11401 | sub_block.runtime_loop = null; |
| 11400 | | sub_block.runtime_cond = operand_src; |
| 11402 | sub_block.runtime_cond = main_operand_src; |
| 11401 | 11403 | sub_block.runtime_index.increment(); |
| 11402 | 11404 | defer sub_block.instructions.deinit(gpa); |
| 11403 | 11405 | |
| ... | ... | @@ -11406,9 +11408,9 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11406 | 11408 | defer gpa.free(true_instructions); |
| 11407 | 11409 | |
| 11408 | 11410 | spa.operand = if (extra.data.bits.payload_is_ref) |
| 11409 | | try sema.analyzeErrUnionCodePtr(&sub_block, operand_src, raw_operand_val) |
| 11411 | try sema.analyzeErrUnionCodePtr(&sub_block, switch_operand_src, raw_operand_val) |
| 11410 | 11412 | else |
| 11411 | | try sema.analyzeErrUnionCode(&sub_block, operand_src, raw_operand_val); |
| 11413 | try sema.analyzeErrUnionCode(&sub_block, switch_operand_src, raw_operand_val); |
| 11412 | 11414 | |
| 11413 | 11415 | if (extra.data.bits.any_uses_err_capture) { |
| 11414 | 11416 | sema.inst_map.putAssumeCapacity(err_capture_inst, spa.operand); |
| ... | ... | @@ -11417,10 +11419,10 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11417 | 11419 | _ = try sema.analyzeSwitchRuntimeBlock( |
| 11418 | 11420 | spa, |
| 11419 | 11421 | &sub_block, |
| 11420 | | src, |
| 11421 | | try sema.switchCond(block, operand_src, spa.operand), |
| 11422 | switch_src, |
| 11423 | try sema.switchCond(block, switch_operand_src, spa.operand), |
| 11422 | 11424 | operand_err_set_ty, |
| 11423 | | operand_src, |
| 11425 | switch_operand_src, |
| 11424 | 11426 | case_vals, |
| 11425 | 11427 | .{ |
| 11426 | 11428 | .body = else_case.body, |
| ... | ... | @@ -11434,7 +11436,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11434 | 11436 | false, |
| 11435 | 11437 | undefined, |
| 11436 | 11438 | true, |
| 11437 | | src_node_offset, |
| 11439 | switch_src_node_offset, |
| 11438 | 11440 | else_prong_src, |
| 11439 | 11441 | undefined, |
| 11440 | 11442 | seen_errors, |
| ... | ... | @@ -11461,7 +11463,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11461 | 11463 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(true_instructions)); |
| 11462 | 11464 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(sub_block.instructions.items)); |
| 11463 | 11465 | |
| 11464 | | return sema.analyzeBlockBody(block, src, &child_block, merges); |
| 11466 | return sema.analyzeBlockBody(block, main_src, &child_block, merges); |
| 11465 | 11467 | } |
| 11466 | 11468 | |
| 11467 | 11469 | fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_ref: bool) CompileError!Air.Inst.Ref { |