| ... | @@ -1323,28 +1323,18 @@ fn analyzeBodyInner( | ... | @@ -1323,28 +1323,18 @@ fn analyzeBodyInner( |
| 1323 | } | 1323 | } |
| 1324 | }, | 1324 | }, |
| 1325 | .@"try" => blk: { | 1325 | .@"try" => blk: { |
| 1326 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst); | 1326 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst, false); |
| 1327 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 1327 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1328 | const src = inst_data.src(); | 1328 | const src = inst_data.src(); |
| 1329 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 1329 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 1330 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 1330 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1331 | const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len]; | 1331 | const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len]; |
| 1332 | const operand = try sema.resolveInst(extra.data.operand); | 1332 | const err_union = try sema.resolveInst(extra.data.operand); |
| 1333 | const operand_ty = sema.typeOf(operand); | | |
| 1334 | const is_ptr = operand_ty.zigTypeTag() == .Pointer; | | |
| 1335 | const err_union = if (is_ptr) | | |
| 1336 | try sema.analyzeLoad(block, src, operand, operand_src) | | |
| 1337 | else | | |
| 1338 | operand; | | |
| 1339 | const is_non_err = try sema.analyzeIsNonErr(block, operand_src, err_union); | 1333 | const is_non_err = try sema.analyzeIsNonErr(block, operand_src, err_union); |
| 1340 | const is_non_err_tv = try sema.resolveInstConst(block, operand_src, is_non_err); | 1334 | const is_non_err_tv = try sema.resolveInstConst(block, operand_src, is_non_err); |
| 1341 | if (is_non_err_tv.val.toBool()) { | 1335 | if (is_non_err_tv.val.toBool()) { |
| 1342 | if (is_ptr) { | 1336 | const err_union_ty = sema.typeOf(err_union); |
| 1343 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); | 1337 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false); |
| 1344 | } else { | | |
| 1345 | const err_union_ty = sema.typeOf(err_union); | | |
| 1346 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false); | | |
| 1347 | } | | |
| 1348 | } | 1338 | } |
| 1349 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse | 1339 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse |
| 1350 | break always_noreturn; | 1340 | break always_noreturn; |
| ... | @@ -1354,28 +1344,50 @@ fn analyzeBodyInner( | ... | @@ -1354,28 +1344,50 @@ fn analyzeBodyInner( |
| 1354 | break break_data.inst; | 1344 | break break_data.inst; |
| 1355 | } | 1345 | } |
| 1356 | }, | 1346 | }, |
| 1357 | .try_inline => blk: { | 1347 | //.try_inline => blk: { |
| | 1348 | // const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| | 1349 | // const src = inst_data.src(); |
| | 1350 | // const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| | 1351 | // const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| | 1352 | // const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len]; |
| | 1353 | // const operand = try sema.resolveInst(extra.data.operand); |
| | 1354 | // const operand_ty = sema.typeOf(operand); |
| | 1355 | // const is_ptr = operand_ty.zigTypeTag() == .Pointer; |
| | 1356 | // const err_union = if (is_ptr) |
| | 1357 | // try sema.analyzeLoad(block, src, operand, operand_src) |
| | 1358 | // else |
| | 1359 | // operand; |
| | 1360 | // const is_non_err = try sema.analyzeIsNonErr(block, operand_src, err_union); |
| | 1361 | // const is_non_err_tv = try sema.resolveInstConst(block, operand_src, is_non_err); |
| | 1362 | // if (is_non_err_tv.val.toBool()) { |
| | 1363 | // if (is_ptr) { |
| | 1364 | // break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); |
| | 1365 | // } else { |
| | 1366 | // const err_union_ty = sema.typeOf(err_union); |
| | 1367 | // break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false); |
| | 1368 | // } |
| | 1369 | // } |
| | 1370 | // const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse |
| | 1371 | // break always_noreturn; |
| | 1372 | // if (inst == break_data.block_inst) { |
| | 1373 | // break :blk try sema.resolveInst(break_data.operand); |
| | 1374 | // } else { |
| | 1375 | // break break_data.inst; |
| | 1376 | // } |
| | 1377 | //}, |
| | 1378 | .try_ptr => blk: { |
| | 1379 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst, true); |
| 1358 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 1380 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1359 | const src = inst_data.src(); | 1381 | const src = inst_data.src(); |
| 1360 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 1382 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 1361 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 1383 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1362 | const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len]; | 1384 | const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len]; |
| 1363 | const operand = try sema.resolveInst(extra.data.operand); | 1385 | const operand = try sema.resolveInst(extra.data.operand); |
| 1364 | const operand_ty = sema.typeOf(operand); | 1386 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); |
| 1365 | const is_ptr = operand_ty.zigTypeTag() == .Pointer; | | |
| 1366 | const err_union = if (is_ptr) | | |
| 1367 | try sema.analyzeLoad(block, src, operand, operand_src) | | |
| 1368 | else | | |
| 1369 | operand; | | |
| 1370 | const is_non_err = try sema.analyzeIsNonErr(block, operand_src, err_union); | 1387 | const is_non_err = try sema.analyzeIsNonErr(block, operand_src, err_union); |
| 1371 | const is_non_err_tv = try sema.resolveInstConst(block, operand_src, is_non_err); | 1388 | const is_non_err_tv = try sema.resolveInstConst(block, operand_src, is_non_err); |
| 1372 | if (is_non_err_tv.val.toBool()) { | 1389 | if (is_non_err_tv.val.toBool()) { |
| 1373 | if (is_ptr) { | 1390 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); |
| 1374 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); | | |
| 1375 | } else { | | |
| 1376 | const err_union_ty = sema.typeOf(err_union); | | |
| 1377 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false); | | |
| 1378 | } | | |
| 1379 | } | 1391 | } |
| 1380 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse | 1392 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse |
| 1381 | break always_noreturn; | 1393 | break always_noreturn; |
| ... | @@ -1385,6 +1397,27 @@ fn analyzeBodyInner( | ... | @@ -1385,6 +1397,27 @@ fn analyzeBodyInner( |
| 1385 | break break_data.inst; | 1397 | break break_data.inst; |
| 1386 | } | 1398 | } |
| 1387 | }, | 1399 | }, |
| | 1400 | //.try_ptr_inline => blk: { |
| | 1401 | // const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| | 1402 | // const src = inst_data.src(); |
| | 1403 | // const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| | 1404 | // const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| | 1405 | // const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len]; |
| | 1406 | // const operand = try sema.resolveInst(extra.data.operand); |
| | 1407 | // const err_union = try sema.analyzeLoad(block, src, operand, operand_src); |
| | 1408 | // const is_non_err = try sema.analyzeIsNonErr(block, operand_src, err_union); |
| | 1409 | // const is_non_err_tv = try sema.resolveInstConst(block, operand_src, is_non_err); |
| | 1410 | // if (is_non_err_tv.val.toBool()) { |
| | 1411 | // break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); |
| | 1412 | // } |
| | 1413 | // const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse |
| | 1414 | // break always_noreturn; |
| | 1415 | // if (inst == break_data.block_inst) { |
| | 1416 | // break :blk try sema.resolveInst(break_data.operand); |
| | 1417 | // } else { |
| | 1418 | // break break_data.inst; |
| | 1419 | // } |
| | 1420 | //}, |
| 1388 | }; | 1421 | }; |
| 1389 | if (sema.typeOf(air_inst).isNoReturn()) | 1422 | if (sema.typeOf(air_inst).isNoReturn()) |
| 1390 | break always_noreturn; | 1423 | break always_noreturn; |
| ... | @@ -13032,15 +13065,18 @@ fn zirCondbr( | ... | @@ -13032,15 +13065,18 @@ fn zirCondbr( |
| 13032 | return always_noreturn; | 13065 | return always_noreturn; |
| 13033 | } | 13066 | } |
| 13034 | | 13067 | |
| 13035 | fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Ref { | 13068 | fn zirTry( |
| | 13069 | sema: *Sema, |
| | 13070 | parent_block: *Block, |
| | 13071 | inst: Zir.Inst.Index, |
| | 13072 | is_ptr: bool, |
| | 13073 | ) CompileError!Zir.Inst.Ref { |
| 13036 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 13074 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 13037 | const src = inst_data.src(); | 13075 | const src = inst_data.src(); |
| 13038 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 13076 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 13039 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 13077 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 13040 | const body = sema.code.extra[extra.end..][0..extra.data.body_len]; | 13078 | const body = sema.code.extra[extra.end..][0..extra.data.body_len]; |
| 13041 | const operand = try sema.resolveInst(extra.data.operand); | 13079 | const operand = try sema.resolveInst(extra.data.operand); |
| 13042 | const operand_ty = sema.typeOf(operand); | | |
| 13043 | const is_ptr = operand_ty.zigTypeTag() == .Pointer; | | |
| 13044 | const err_union = if (is_ptr) | 13080 | const err_union = if (is_ptr) |
| 13045 | try sema.analyzeLoad(parent_block, src, operand, operand_src) | 13081 | try sema.analyzeLoad(parent_block, src, operand, operand_src) |
| 13046 | else | 13082 | else |
| ... | @@ -13073,6 +13109,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -13073,6 +13109,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! |
| 13073 | _ = try sema.analyzeBodyInner(&sub_block, body); | 13109 | _ = try sema.analyzeBodyInner(&sub_block, body); |
| 13074 | | 13110 | |
| 13075 | if (is_ptr) { | 13111 | if (is_ptr) { |
| | 13112 | const operand_ty = sema.typeOf(operand); |
| 13076 | const ptr_info = operand_ty.ptrInfo().data; | 13113 | const ptr_info = operand_ty.ptrInfo().data; |
| 13077 | const res_ty = try Type.ptr(sema.arena, sema.mod, .{ | 13114 | const res_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 13078 | .pointee_type = err_union_ty.errorUnionPayload(), | 13115 | .pointee_type = err_union_ty.errorUnionPayload(), |