| ... | ... | @@ -36,7 +36,7 @@ func: ?*Module.Fn, |
| 36 | 36 | /// > Denormalized data to make `resolveInst` faster. This is 0 if not inside a function, |
| 37 | 37 | /// > otherwise it is the number of parameters of the function. |
| 38 | 38 | /// > param_count: u32 |
| 39 | | param_inst_list: []const Air.Inst.Index, |
| 39 | param_inst_list: []const Air.Inst.Ref, |
| 40 | 40 | branch_quota: u32 = 1000, |
| 41 | 41 | branch_count: u32 = 0, |
| 42 | 42 | /// This field is updated when a new source location becomes active, so that |
| ... | ... | @@ -59,8 +59,6 @@ const TypedValue = @import("TypedValue.zig"); |
| 59 | 59 | const Air = @import("Air.zig"); |
| 60 | 60 | const Zir = @import("Zir.zig"); |
| 61 | 61 | const Module = @import("Module.zig"); |
| 62 | | const Inst = ir.Inst; |
| 63 | | const Body = ir.Body; |
| 64 | 62 | const trace = @import("tracy.zig").trace; |
| 65 | 63 | const Scope = Module.Scope; |
| 66 | 64 | const InnerError = Module.InnerError; |
| ... | ... | @@ -117,7 +115,7 @@ pub fn analyzeFnBody( |
| 117 | 115 | /// Returns only the result from the body that is specified. |
| 118 | 116 | /// Only appropriate to call when it is determined at comptime that this body |
| 119 | 117 | /// has no peers. |
| 120 | | fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 118 | fn resolveBody(sema: *Sema, block: *Scope.Block, body: []const Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 121 | 119 | const break_inst = try sema.analyzeBody(block, body); |
| 122 | 120 | const operand_ref = sema.code.instructions.items(.data)[break_inst].@"break".operand; |
| 123 | 121 | return sema.resolveInst(operand_ref); |
| ... | ... | @@ -513,7 +511,7 @@ pub fn analyzeBody( |
| 513 | 511 | // const break_inst = try sema.analyzeBody(block, inline_body); |
| 514 | 512 | // const break_data = datas[break_inst].@"break"; |
| 515 | 513 | // if (inst == break_data.block_inst) { |
| 516 | | // break :blk try sema.resolveInst(break_data.operand); |
| 514 | // break :blk sema.resolveInst(break_data.operand); |
| 517 | 515 | // } else { |
| 518 | 516 | // return break_inst; |
| 519 | 517 | // } |
| ... | ... | @@ -529,12 +527,12 @@ pub fn analyzeBody( |
| 529 | 527 | // const break_inst = try sema.analyzeBody(block, inline_body); |
| 530 | 528 | // const break_data = datas[break_inst].@"break"; |
| 531 | 529 | // if (inst == break_data.block_inst) { |
| 532 | | // break :blk try sema.resolveInst(break_data.operand); |
| 530 | // break :blk sema.resolveInst(break_data.operand); |
| 533 | 531 | // } else { |
| 534 | 532 | // return break_inst; |
| 535 | 533 | // } |
| 536 | 534 | //}, |
| 537 | | else => @panic("TODO remove else prong"), |
| 535 | else => @panic("TODO finish updating Sema for AIR memory layout changes and then remove this else prong"), |
| 538 | 536 | }; |
| 539 | 537 | if (sema.getAirType(air_inst).isNoReturn()) |
| 540 | 538 | return always_noreturn; |
| ... | ... | @@ -543,7 +541,7 @@ pub fn analyzeBody( |
| 543 | 541 | } |
| 544 | 542 | } |
| 545 | 543 | |
| 546 | | fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 544 | fn zirExtended(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 547 | 545 | const extended = sema.code.instructions.items(.data)[inst].extended; |
| 548 | 546 | switch (extended.opcode) { |
| 549 | 547 | // zig fmt: off |
| ... | ... | @@ -598,7 +596,7 @@ fn resolveConstBool( |
| 598 | 596 | src: LazySrcLoc, |
| 599 | 597 | zir_ref: Zir.Inst.Ref, |
| 600 | 598 | ) !bool { |
| 601 | | const air_inst = try sema.resolveInst(zir_ref); |
| 599 | const air_inst = sema.resolveInst(zir_ref); |
| 602 | 600 | const wanted_type = Type.initTag(.bool); |
| 603 | 601 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 604 | 602 | const val = try sema.resolveConstValue(block, src, coerced_inst); |
| ... | ... | @@ -611,7 +609,7 @@ fn resolveConstString( |
| 611 | 609 | src: LazySrcLoc, |
| 612 | 610 | zir_ref: Zir.Inst.Ref, |
| 613 | 611 | ) ![]u8 { |
| 614 | | const air_inst = try sema.resolveInst(zir_ref); |
| 612 | const air_inst = sema.resolveInst(zir_ref); |
| 615 | 613 | const wanted_type = Type.initTag(.const_slice_u8); |
| 616 | 614 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 617 | 615 | const val = try sema.resolveConstValue(block, src, coerced_inst); |
| ... | ... | @@ -619,24 +617,39 @@ fn resolveConstString( |
| 619 | 617 | } |
| 620 | 618 | |
| 621 | 619 | pub fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { |
| 622 | | const air_inst = try sema.resolveInst(zir_ref); |
| 620 | const air_inst = sema.resolveInst(zir_ref); |
| 623 | 621 | return sema.resolveAirAsType(block, src, air_inst); |
| 624 | 622 | } |
| 625 | 623 | |
| 626 | | fn resolveAirAsType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, air_inst: Air.Inst.Index) !Type { |
| 624 | fn resolveAirAsType( |
| 625 | sema: *Sema, |
| 626 | block: *Scope.Block, |
| 627 | src: LazySrcLoc, |
| 628 | air_inst: Air.Inst.Ref, |
| 629 | ) !Type { |
| 627 | 630 | const wanted_type = Type.initTag(.@"type"); |
| 628 | 631 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 629 | 632 | const val = try sema.resolveConstValue(block, src, coerced_inst); |
| 630 | 633 | return val.toType(sema.arena); |
| 631 | 634 | } |
| 632 | 635 | |
| 633 | | fn resolveConstValue(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, base: Air.Inst.Index) !Value { |
| 634 | | return (try sema.resolveDefinedValue(block, src, base)) orelse |
| 636 | fn resolveConstValue( |
| 637 | sema: *Sema, |
| 638 | block: *Scope.Block, |
| 639 | src: LazySrcLoc, |
| 640 | air_ref: Air.Inst.Ref, |
| 641 | ) !Value { |
| 642 | return (try sema.resolveDefinedValue(block, src, air_ref)) orelse |
| 635 | 643 | return sema.failWithNeededComptime(block, src); |
| 636 | 644 | } |
| 637 | 645 | |
| 638 | | fn resolveDefinedValue(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, base: Air.Inst.Index) !?Value { |
| 639 | | if (try sema.resolvePossiblyUndefinedValue(block, src, base)) |val| { |
| 646 | fn resolveDefinedValue( |
| 647 | sema: *Sema, |
| 648 | block: *Scope.Block, |
| 649 | src: LazySrcLoc, |
| 650 | air_ref: Air.Inst.Ref, |
| 651 | ) !?Value { |
| 652 | if (try sema.resolvePossiblyUndefinedValue(block, src, air_ref)) |val| { |
| 640 | 653 | if (val.isUndef()) { |
| 641 | 654 | return sema.failWithUseOfUndef(block, src); |
| 642 | 655 | } |
| ... | ... | @@ -649,13 +662,29 @@ fn resolvePossiblyUndefinedValue( |
| 649 | 662 | sema: *Sema, |
| 650 | 663 | block: *Scope.Block, |
| 651 | 664 | src: LazySrcLoc, |
| 652 | | base: Air.Inst.Index, |
| 665 | air_ref: Air.Inst.Ref, |
| 653 | 666 | ) !?Value { |
| 654 | | if (try sema.typeHasOnePossibleValue(block, src, base.ty)) |opv| { |
| 667 | const ty = sema.getTypeOfAirRef(air_ref); |
| 668 | if (try sema.typeHasOnePossibleValue(block, src, ty)) |opv| { |
| 655 | 669 | return opv; |
| 656 | 670 | } |
| 657 | | const inst = base.castTag(.constant) orelse return null; |
| 658 | | return inst.val; |
| 671 | // First section of indexes correspond to a set number of constant values. |
| 672 | var i: usize = @enumToInt(air_ref); |
| 673 | if (i < Air.Inst.Ref.typed_value_map.len) { |
| 674 | return Air.Inst.Ref.typed_value_map[i].val; |
| 675 | } |
| 676 | i -= Air.Inst.Ref.typed_value_map.len; |
| 677 | |
| 678 | switch (sema.air_instructions.items(.tag)[i]) { |
| 679 | .constant => { |
| 680 | const ty_pl = sema.air_instructions.items(.data)[i].ty_pl; |
| 681 | return sema.air_values.items[ty_pl.payload]; |
| 682 | }, |
| 683 | .const_ty => { |
| 684 | return sema.air_instructions.items(.data)[i].ty.toValue(undefined) catch unreachable; |
| 685 | }, |
| 686 | else => return null, |
| 687 | } |
| 659 | 688 | } |
| 660 | 689 | |
| 661 | 690 | fn failWithNeededComptime(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) InnerError { |
| ... | ... | @@ -677,7 +706,7 @@ fn resolveAlreadyCoercedInt( |
| 677 | 706 | comptime Int: type, |
| 678 | 707 | ) !Int { |
| 679 | 708 | comptime assert(@typeInfo(Int).Int.bits <= 64); |
| 680 | | const air_inst = try sema.resolveInst(zir_ref); |
| 709 | const air_inst = sema.resolveInst(zir_ref); |
| 681 | 710 | const val = try sema.resolveConstValue(block, src, air_inst); |
| 682 | 711 | switch (@typeInfo(Int).Int.signedness) { |
| 683 | 712 | .signed => return @intCast(Int, val.toSignedInt()), |
| ... | ... | @@ -692,7 +721,7 @@ fn resolveInt( |
| 692 | 721 | zir_ref: Zir.Inst.Ref, |
| 693 | 722 | dest_type: Type, |
| 694 | 723 | ) !u64 { |
| 695 | | const air_inst = try sema.resolveInst(zir_ref); |
| 724 | const air_inst = sema.resolveInst(zir_ref); |
| 696 | 725 | const coerced = try sema.coerce(block, dest_type, air_inst, src); |
| 697 | 726 | const val = try sema.resolveConstValue(block, src, coerced); |
| 698 | 727 | |
| ... | ... | @@ -705,21 +734,21 @@ pub fn resolveInstConst( |
| 705 | 734 | src: LazySrcLoc, |
| 706 | 735 | zir_ref: Zir.Inst.Ref, |
| 707 | 736 | ) InnerError!TypedValue { |
| 708 | | const air_inst = try sema.resolveInst(zir_ref); |
| 709 | | const val = try sema.resolveConstValue(block, src, air_inst); |
| 737 | const air_ref = sema.resolveInst(zir_ref); |
| 738 | const val = try sema.resolveConstValue(block, src, air_ref); |
| 710 | 739 | return TypedValue{ |
| 711 | | .ty = air_inst.ty, |
| 740 | .ty = sema.getTypeOfAirRef(air_ref), |
| 712 | 741 | .val = val, |
| 713 | 742 | }; |
| 714 | 743 | } |
| 715 | 744 | |
| 716 | | fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 745 | fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 717 | 746 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 718 | 747 | const src = inst_data.src(); |
| 719 | 748 | return sema.mod.fail(&block.base, src, "TODO implement zir_sema.zirBitcastResultPtr", .{}); |
| 720 | 749 | } |
| 721 | 750 | |
| 722 | | fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 751 | fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 723 | 752 | _ = inst; |
| 724 | 753 | const tracy = trace(@src()); |
| 725 | 754 | defer tracy.end(); |
| ... | ... | @@ -754,7 +783,7 @@ fn zirStructDecl( |
| 754 | 783 | block: *Scope.Block, |
| 755 | 784 | extended: Zir.Inst.Extended.InstData, |
| 756 | 785 | inst: Zir.Inst.Index, |
| 757 | | ) InnerError!Air.Inst.Index { |
| 786 | ) InnerError!Air.Inst.Ref { |
| 758 | 787 | const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small); |
| 759 | 788 | const src: LazySrcLoc = if (small.has_src_node) blk: { |
| 760 | 789 | const node_offset = @bitCast(i32, sema.code.extra[extended.operand]); |
| ... | ... | @@ -825,7 +854,7 @@ fn zirEnumDecl( |
| 825 | 854 | sema: *Sema, |
| 826 | 855 | block: *Scope.Block, |
| 827 | 856 | extended: Zir.Inst.Extended.InstData, |
| 828 | | ) InnerError!Air.Inst.Index { |
| 857 | ) InnerError!Air.Inst.Ref { |
| 829 | 858 | const tracy = trace(@src()); |
| 830 | 859 | defer tracy.end(); |
| 831 | 860 | |
| ... | ... | @@ -1022,7 +1051,7 @@ fn zirUnionDecl( |
| 1022 | 1051 | block: *Scope.Block, |
| 1023 | 1052 | extended: Zir.Inst.Extended.InstData, |
| 1024 | 1053 | inst: Zir.Inst.Index, |
| 1025 | | ) InnerError!Air.Inst.Index { |
| 1054 | ) InnerError!Air.Inst.Ref { |
| 1026 | 1055 | const tracy = trace(@src()); |
| 1027 | 1056 | defer tracy.end(); |
| 1028 | 1057 | |
| ... | ... | @@ -1086,7 +1115,7 @@ fn zirOpaqueDecl( |
| 1086 | 1115 | block: *Scope.Block, |
| 1087 | 1116 | inst: Zir.Inst.Index, |
| 1088 | 1117 | name_strategy: Zir.Inst.NameStrategy, |
| 1089 | | ) InnerError!Air.Inst.Index { |
| 1118 | ) InnerError!Air.Inst.Ref { |
| 1090 | 1119 | const tracy = trace(@src()); |
| 1091 | 1120 | defer tracy.end(); |
| 1092 | 1121 | |
| ... | ... | @@ -1106,7 +1135,7 @@ fn zirErrorSetDecl( |
| 1106 | 1135 | block: *Scope.Block, |
| 1107 | 1136 | inst: Zir.Inst.Index, |
| 1108 | 1137 | name_strategy: Zir.Inst.NameStrategy, |
| 1109 | | ) InnerError!Air.Inst.Index { |
| 1138 | ) InnerError!Air.Inst.Ref { |
| 1110 | 1139 | const tracy = trace(@src()); |
| 1111 | 1140 | defer tracy.end(); |
| 1112 | 1141 | |
| ... | ... | @@ -1146,7 +1175,7 @@ fn zirRetPtr( |
| 1146 | 1175 | sema: *Sema, |
| 1147 | 1176 | block: *Scope.Block, |
| 1148 | 1177 | extended: Zir.Inst.Extended.InstData, |
| 1149 | | ) InnerError!Air.Inst.Index { |
| 1178 | ) InnerError!Air.Inst.Ref { |
| 1150 | 1179 | const tracy = trace(@src()); |
| 1151 | 1180 | defer tracy.end(); |
| 1152 | 1181 | |
| ... | ... | @@ -1154,16 +1183,16 @@ fn zirRetPtr( |
| 1154 | 1183 | try sema.requireFunctionBlock(block, src); |
| 1155 | 1184 | const fn_ty = sema.func.?.owner_decl.ty; |
| 1156 | 1185 | const ret_type = fn_ty.fnReturnType(); |
| 1157 | | const ptr_type = try sema.mod.simplePtrType(sema.arena, ret_type, true, .One); |
| 1186 | const ptr_type = try Module.simplePtrType(sema.arena, ret_type, true, .One); |
| 1158 | 1187 | return block.addNoOp(src, ptr_type, .alloc); |
| 1159 | 1188 | } |
| 1160 | 1189 | |
| 1161 | | fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1190 | fn zirRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1162 | 1191 | const tracy = trace(@src()); |
| 1163 | 1192 | defer tracy.end(); |
| 1164 | 1193 | |
| 1165 | 1194 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 1166 | | const operand = try sema.resolveInst(inst_data.operand); |
| 1195 | const operand = sema.resolveInst(inst_data.operand); |
| 1167 | 1196 | return sema.analyzeRef(block, inst_data.src(), operand); |
| 1168 | 1197 | } |
| 1169 | 1198 | |
| ... | ... | @@ -1171,7 +1200,7 @@ fn zirRetType( |
| 1171 | 1200 | sema: *Sema, |
| 1172 | 1201 | block: *Scope.Block, |
| 1173 | 1202 | extended: Zir.Inst.Extended.InstData, |
| 1174 | | ) InnerError!Air.Inst.Index { |
| 1203 | ) InnerError!Air.Inst.Ref { |
| 1175 | 1204 | const tracy = trace(@src()); |
| 1176 | 1205 | defer tracy.end(); |
| 1177 | 1206 | |
| ... | ... | @@ -1187,7 +1216,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I |
| 1187 | 1216 | defer tracy.end(); |
| 1188 | 1217 | |
| 1189 | 1218 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 1190 | | const operand = try sema.resolveInst(inst_data.operand); |
| 1219 | const operand = sema.resolveInst(inst_data.operand); |
| 1191 | 1220 | const src = inst_data.src(); |
| 1192 | 1221 | |
| 1193 | 1222 | return sema.ensureResultUsed(block, operand, src); |
| ... | ... | @@ -1196,7 +1225,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I |
| 1196 | 1225 | fn ensureResultUsed( |
| 1197 | 1226 | sema: *Sema, |
| 1198 | 1227 | block: *Scope.Block, |
| 1199 | | operand: Air.Inst.Index, |
| 1228 | operand: Air.Inst.Ref, |
| 1200 | 1229 | src: LazySrcLoc, |
| 1201 | 1230 | ) InnerError!void { |
| 1202 | 1231 | switch (operand.ty.zigTypeTag()) { |
| ... | ... | @@ -1210,7 +1239,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1210 | 1239 | defer tracy.end(); |
| 1211 | 1240 | |
| 1212 | 1241 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 1213 | | const operand = try sema.resolveInst(inst_data.operand); |
| 1242 | const operand = sema.resolveInst(inst_data.operand); |
| 1214 | 1243 | const src = inst_data.src(); |
| 1215 | 1244 | switch (operand.ty.zigTypeTag()) { |
| 1216 | 1245 | .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}), |
| ... | ... | @@ -1218,13 +1247,13 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1218 | 1247 | } |
| 1219 | 1248 | } |
| 1220 | 1249 | |
| 1221 | | fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1250 | fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1222 | 1251 | const tracy = trace(@src()); |
| 1223 | 1252 | defer tracy.end(); |
| 1224 | 1253 | |
| 1225 | 1254 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 1226 | 1255 | const src = inst_data.src(); |
| 1227 | | const array_ptr = try sema.resolveInst(inst_data.operand); |
| 1256 | const array_ptr = sema.resolveInst(inst_data.operand); |
| 1228 | 1257 | |
| 1229 | 1258 | const elem_ty = array_ptr.ty.elemType(); |
| 1230 | 1259 | if (!elem_ty.isIndexable()) { |
| ... | ... | @@ -1267,7 +1296,7 @@ fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air |
| 1267 | 1296 | |
| 1268 | 1297 | // Set the name of the Air.Arg instruction for use by codegen debug info. |
| 1269 | 1298 | const air_arg = sema.param_inst_list[arg_index]; |
| 1270 | | sema.air_instructions.items(.data)[air_arg].ty_str.str = inst_data.start; |
| 1299 | sema.air_instructions.items(.data)[refToIndex(air_arg).?].ty_str.str = inst_data.start; |
| 1271 | 1300 | return air_arg; |
| 1272 | 1301 | } |
| 1273 | 1302 | |
| ... | ... | @@ -1275,13 +1304,13 @@ fn zirAllocExtended( |
| 1275 | 1304 | sema: *Sema, |
| 1276 | 1305 | block: *Scope.Block, |
| 1277 | 1306 | extended: Zir.Inst.Extended.InstData, |
| 1278 | | ) InnerError!Air.Inst.Index { |
| 1307 | ) InnerError!Air.Inst.Ref { |
| 1279 | 1308 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| 1280 | 1309 | const src: LazySrcLoc = .{ .node_offset = extra.data.src_node }; |
| 1281 | 1310 | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended", .{}); |
| 1282 | 1311 | } |
| 1283 | 1312 | |
| 1284 | | fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1313 | fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1285 | 1314 | const tracy = trace(@src()); |
| 1286 | 1315 | defer tracy.end(); |
| 1287 | 1316 | |
| ... | ... | @@ -1289,7 +1318,7 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne |
| 1289 | 1318 | const src = inst_data.src(); |
| 1290 | 1319 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 1291 | 1320 | const var_type = try sema.resolveType(block, ty_src, inst_data.operand); |
| 1292 | | const ptr_type = try sema.mod.simplePtrType(sema.arena, var_type, true, .One); |
| 1321 | const ptr_type = try Module.simplePtrType(sema.arena, var_type, true, .One); |
| 1293 | 1322 | |
| 1294 | 1323 | const val_payload = try sema.arena.create(Value.Payload.ComptimeAlloc); |
| 1295 | 1324 | val_payload.* = .{ |
| ... | ... | @@ -1304,13 +1333,13 @@ fn zirAllocComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne |
| 1304 | 1333 | }); |
| 1305 | 1334 | } |
| 1306 | 1335 | |
| 1307 | | fn zirAllocInferredComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1336 | fn zirAllocInferredComptime(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1308 | 1337 | const src_node = sema.code.instructions.items(.data)[inst].node; |
| 1309 | 1338 | const src: LazySrcLoc = .{ .node_offset = src_node }; |
| 1310 | 1339 | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocInferredComptime", .{}); |
| 1311 | 1340 | } |
| 1312 | 1341 | |
| 1313 | | fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1342 | fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1314 | 1343 | const tracy = trace(@src()); |
| 1315 | 1344 | defer tracy.end(); |
| 1316 | 1345 | |
| ... | ... | @@ -1318,12 +1347,12 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!A |
| 1318 | 1347 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 1319 | 1348 | const var_decl_src = inst_data.src(); |
| 1320 | 1349 | const var_type = try sema.resolveType(block, ty_src, inst_data.operand); |
| 1321 | | const ptr_type = try sema.mod.simplePtrType(sema.arena, var_type, true, .One); |
| 1350 | const ptr_type = try Module.simplePtrType(sema.arena, var_type, true, .One); |
| 1322 | 1351 | try sema.requireRuntimeBlock(block, var_decl_src); |
| 1323 | 1352 | return block.addNoOp(var_decl_src, ptr_type, .alloc); |
| 1324 | 1353 | } |
| 1325 | 1354 | |
| 1326 | | fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1355 | fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1327 | 1356 | const tracy = trace(@src()); |
| 1328 | 1357 | defer tracy.end(); |
| 1329 | 1358 | |
| ... | ... | @@ -1332,7 +1361,7 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 1332 | 1361 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 1333 | 1362 | const var_type = try sema.resolveType(block, ty_src, inst_data.operand); |
| 1334 | 1363 | try sema.validateVarType(block, ty_src, var_type); |
| 1335 | | const ptr_type = try sema.mod.simplePtrType(sema.arena, var_type, true, .One); |
| 1364 | const ptr_type = try Module.simplePtrType(sema.arena, var_type, true, .One); |
| 1336 | 1365 | try sema.requireRuntimeBlock(block, var_decl_src); |
| 1337 | 1366 | return block.addNoOp(var_decl_src, ptr_type, .alloc); |
| 1338 | 1367 | } |
| ... | ... | @@ -1342,7 +1371,7 @@ fn zirAllocInferred( |
| 1342 | 1371 | block: *Scope.Block, |
| 1343 | 1372 | inst: Zir.Inst.Index, |
| 1344 | 1373 | inferred_alloc_ty: Type, |
| 1345 | | ) InnerError!Air.Inst.Index { |
| 1374 | ) InnerError!Air.Inst.Ref { |
| 1346 | 1375 | const tracy = trace(@src()); |
| 1347 | 1376 | defer tracy.end(); |
| 1348 | 1377 | |
| ... | ... | @@ -1372,7 +1401,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1372 | 1401 | |
| 1373 | 1402 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 1374 | 1403 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 1375 | | const ptr = try sema.resolveInst(inst_data.operand); |
| 1404 | const ptr = sema.resolveInst(inst_data.operand); |
| 1376 | 1405 | const ptr_val = ptr.castTag(.constant).?.val; |
| 1377 | 1406 | const inferred_alloc = ptr_val.castTag(.inferred_alloc).?; |
| 1378 | 1407 | const peer_inst_list = inferred_alloc.data.stored_inst_list.items; |
| ... | ... | @@ -1385,7 +1414,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1385 | 1414 | if (var_is_mut) { |
| 1386 | 1415 | try sema.validateVarType(block, ty_src, final_elem_ty); |
| 1387 | 1416 | } |
| 1388 | | const final_ptr_ty = try sema.mod.simplePtrType(sema.arena, final_elem_ty, true, .One); |
| 1417 | const final_ptr_ty = try Module.simplePtrType(sema.arena, final_elem_ty, true, .One); |
| 1389 | 1418 | |
| 1390 | 1419 | // Change it to a normal alloc. |
| 1391 | 1420 | ptr.ty = final_ptr_ty; |
| ... | ... | @@ -1406,7 +1435,7 @@ fn zirValidateStructInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Ind |
| 1406 | 1435 | const struct_obj: *Module.Struct = s: { |
| 1407 | 1436 | const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node; |
| 1408 | 1437 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 1409 | | const object_ptr = try sema.resolveInst(field_ptr_extra.lhs); |
| 1438 | const object_ptr = sema.resolveInst(field_ptr_extra.lhs); |
| 1410 | 1439 | break :s object_ptr.ty.elemType().castTag(.@"struct").?.data; |
| 1411 | 1440 | }; |
| 1412 | 1441 | |
| ... | ... | @@ -1535,9 +1564,9 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In |
| 1535 | 1564 | // to omit it. |
| 1536 | 1565 | return; |
| 1537 | 1566 | } |
| 1538 | | const ptr = try sema.resolveInst(bin_inst.lhs); |
| 1539 | | const value = try sema.resolveInst(bin_inst.rhs); |
| 1540 | | const ptr_ty = try sema.mod.simplePtrType(sema.arena, value.ty, true, .One); |
| 1567 | const ptr = sema.resolveInst(bin_inst.lhs); |
| 1568 | const value = sema.resolveInst(bin_inst.rhs); |
| 1569 | const ptr_ty = try Module.simplePtrType(sema.arena, value.ty, true, .One); |
| 1541 | 1570 | // TODO detect when this store should be done at compile-time. For example, |
| 1542 | 1571 | // if expressions should force it when the condition is compile-time known. |
| 1543 | 1572 | const src: LazySrcLoc = .unneeded; |
| ... | ... | @@ -1552,14 +1581,14 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 1552 | 1581 | |
| 1553 | 1582 | const src: LazySrcLoc = .unneeded; |
| 1554 | 1583 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 1555 | | const ptr = try sema.resolveInst(bin_inst.lhs); |
| 1556 | | const value = try sema.resolveInst(bin_inst.rhs); |
| 1584 | const ptr = sema.resolveInst(bin_inst.lhs); |
| 1585 | const value = sema.resolveInst(bin_inst.rhs); |
| 1557 | 1586 | const inferred_alloc = ptr.castTag(.constant).?.val.castTag(.inferred_alloc).?; |
| 1558 | 1587 | // Add the stored instruction to the set we will use to resolve peer types |
| 1559 | 1588 | // for the inferred allocation. |
| 1560 | 1589 | try inferred_alloc.data.stored_inst_list.append(sema.arena, value); |
| 1561 | 1590 | // Create a runtime bitcast instruction with exactly the type the pointer wants. |
| 1562 | | const ptr_ty = try sema.mod.simplePtrType(sema.arena, value.ty, true, .One); |
| 1591 | const ptr_ty = try Module.simplePtrType(sema.arena, value.ty, true, .One); |
| 1563 | 1592 | try sema.requireRuntimeBlock(block, src); |
| 1564 | 1593 | const bitcasted_ptr = try block.addUnOp(src, ptr_ty, .bitcast, ptr); |
| 1565 | 1594 | return sema.storePtr(block, src, bitcasted_ptr, value); |
| ... | ... | @@ -1578,8 +1607,8 @@ fn zirStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!v |
| 1578 | 1607 | defer tracy.end(); |
| 1579 | 1608 | |
| 1580 | 1609 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 1581 | | const ptr = try sema.resolveInst(bin_inst.lhs); |
| 1582 | | const value = try sema.resolveInst(bin_inst.rhs); |
| 1610 | const ptr = sema.resolveInst(bin_inst.lhs); |
| 1611 | const value = sema.resolveInst(bin_inst.rhs); |
| 1583 | 1612 | return sema.storePtr(block, sema.src, ptr, value); |
| 1584 | 1613 | } |
| 1585 | 1614 | |
| ... | ... | @@ -1590,18 +1619,18 @@ fn zirStoreNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr |
| 1590 | 1619 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1591 | 1620 | const src = inst_data.src(); |
| 1592 | 1621 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 1593 | | const ptr = try sema.resolveInst(extra.lhs); |
| 1594 | | const value = try sema.resolveInst(extra.rhs); |
| 1622 | const ptr = sema.resolveInst(extra.lhs); |
| 1623 | const value = sema.resolveInst(extra.rhs); |
| 1595 | 1624 | return sema.storePtr(block, src, ptr, value); |
| 1596 | 1625 | } |
| 1597 | 1626 | |
| 1598 | | fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1627 | fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1599 | 1628 | const tracy = trace(@src()); |
| 1600 | 1629 | defer tracy.end(); |
| 1601 | 1630 | |
| 1602 | 1631 | const src: LazySrcLoc = .unneeded; |
| 1603 | 1632 | const inst_data = sema.code.instructions.items(.data)[inst].param_type; |
| 1604 | | const fn_inst = try sema.resolveInst(inst_data.callee); |
| 1633 | const fn_inst = sema.resolveInst(inst_data.callee); |
| 1605 | 1634 | const param_index = inst_data.param_index; |
| 1606 | 1635 | |
| 1607 | 1636 | const fn_ty: Type = switch (fn_inst.ty.zigTypeTag()) { |
| ... | ... | @@ -1631,7 +1660,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr |
| 1631 | 1660 | return sema.mod.constType(sema.arena, src, param_type); |
| 1632 | 1661 | } |
| 1633 | 1662 | |
| 1634 | | fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1663 | fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1635 | 1664 | const tracy = trace(@src()); |
| 1636 | 1665 | defer tracy.end(); |
| 1637 | 1666 | |
| ... | ... | @@ -1659,7 +1688,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air |
| 1659 | 1688 | return sema.analyzeDeclRef(block, .unneeded, new_decl); |
| 1660 | 1689 | } |
| 1661 | 1690 | |
| 1662 | | fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1691 | fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1663 | 1692 | _ = block; |
| 1664 | 1693 | const tracy = trace(@src()); |
| 1665 | 1694 | defer tracy.end(); |
| ... | ... | @@ -1668,7 +1697,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air |
| 1668 | 1697 | return sema.mod.constIntUnsigned(sema.arena, .unneeded, Type.initTag(.comptime_int), int); |
| 1669 | 1698 | } |
| 1670 | 1699 | |
| 1671 | | fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1700 | fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1672 | 1701 | _ = block; |
| 1673 | 1702 | const tracy = trace(@src()); |
| 1674 | 1703 | defer tracy.end(); |
| ... | ... | @@ -1686,7 +1715,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError! |
| 1686 | 1715 | }); |
| 1687 | 1716 | } |
| 1688 | 1717 | |
| 1689 | | fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1718 | fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1690 | 1719 | _ = block; |
| 1691 | 1720 | const arena = sema.arena; |
| 1692 | 1721 | const inst_data = sema.code.instructions.items(.data)[inst].float; |
| ... | ... | @@ -1699,7 +1728,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!A |
| 1699 | 1728 | }); |
| 1700 | 1729 | } |
| 1701 | 1730 | |
| 1702 | | fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1731 | fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1703 | 1732 | _ = block; |
| 1704 | 1733 | const arena = sema.arena; |
| 1705 | 1734 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| ... | ... | @@ -1728,7 +1757,7 @@ fn zirCompileLog( |
| 1728 | 1757 | sema: *Sema, |
| 1729 | 1758 | block: *Scope.Block, |
| 1730 | 1759 | extended: Zir.Inst.Extended.InstData, |
| 1731 | | ) InnerError!Air.Inst.Index { |
| 1760 | ) InnerError!Air.Inst.Ref { |
| 1732 | 1761 | var managed = sema.mod.compile_log_text.toManaged(sema.gpa); |
| 1733 | 1762 | defer sema.mod.compile_log_text = managed.moveToUnmanaged(); |
| 1734 | 1763 | const writer = managed.writer(); |
| ... | ... | @@ -1741,7 +1770,7 @@ fn zirCompileLog( |
| 1741 | 1770 | for (args) |arg_ref, i| { |
| 1742 | 1771 | if (i != 0) try writer.print(", ", .{}); |
| 1743 | 1772 | |
| 1744 | | const arg = try sema.resolveInst(arg_ref); |
| 1773 | const arg = sema.resolveInst(arg_ref); |
| 1745 | 1774 | if (try sema.resolvePossiblyUndefinedValue(block, src, arg)) |val| { |
| 1746 | 1775 | try writer.print("@as({}, {})", .{ arg.ty, val }); |
| 1747 | 1776 | } else { |
| ... | ... | @@ -1773,12 +1802,12 @@ fn zirRepeat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError! |
| 1773 | 1802 | fn zirPanic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Zir.Inst.Index { |
| 1774 | 1803 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 1775 | 1804 | const src: LazySrcLoc = inst_data.src(); |
| 1776 | | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 1805 | const msg_inst = sema.resolveInst(inst_data.operand); |
| 1777 | 1806 | |
| 1778 | 1807 | return sema.panicWithMsg(block, src, msg_inst); |
| 1779 | 1808 | } |
| 1780 | 1809 | |
| 1781 | | fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1810 | fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1782 | 1811 | const tracy = trace(@src()); |
| 1783 | 1812 | defer tracy.end(); |
| 1784 | 1813 | |
| ... | ... | @@ -1843,7 +1872,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerE |
| 1843 | 1872 | return sema.analyzeBlockBody(parent_block, src, &child_block, merges); |
| 1844 | 1873 | } |
| 1845 | 1874 | |
| 1846 | | fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1875 | fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1847 | 1876 | const tracy = trace(@src()); |
| 1848 | 1877 | defer tracy.end(); |
| 1849 | 1878 | |
| ... | ... | @@ -1853,13 +1882,13 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Inn |
| 1853 | 1882 | return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirCImport", .{}); |
| 1854 | 1883 | } |
| 1855 | 1884 | |
| 1856 | | fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1885 | fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1857 | 1886 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1858 | 1887 | const src = inst_data.src(); |
| 1859 | 1888 | return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirSuspendBlock", .{}); |
| 1860 | 1889 | } |
| 1861 | 1890 | |
| 1862 | | fn zirBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 1891 | fn zirBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 1863 | 1892 | const tracy = trace(@src()); |
| 1864 | 1893 | defer tracy.end(); |
| 1865 | 1894 | |
| ... | ... | @@ -1917,7 +1946,7 @@ fn resolveBlockBody( |
| 1917 | 1946 | child_block: *Scope.Block, |
| 1918 | 1947 | body: []const Zir.Inst.Index, |
| 1919 | 1948 | merges: *Scope.Block.Merges, |
| 1920 | | ) InnerError!Air.Inst.Index { |
| 1949 | ) InnerError!Air.Inst.Ref { |
| 1921 | 1950 | _ = try sema.analyzeBody(child_block, body); |
| 1922 | 1951 | return sema.analyzeBlockBody(parent_block, src, child_block, merges); |
| 1923 | 1952 | } |
| ... | ... | @@ -1928,7 +1957,7 @@ fn analyzeBlockBody( |
| 1928 | 1957 | src: LazySrcLoc, |
| 1929 | 1958 | child_block: *Scope.Block, |
| 1930 | 1959 | merges: *Scope.Block.Merges, |
| 1931 | | ) InnerError!Air.Inst.Index { |
| 1960 | ) InnerError!Air.Inst.Ref { |
| 1932 | 1961 | const tracy = trace(@src()); |
| 1933 | 1962 | defer tracy.end(); |
| 1934 | 1963 | |
| ... | ... | @@ -2088,7 +2117,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) InnerE |
| 2088 | 2117 | |
| 2089 | 2118 | const inst_data = sema.code.instructions.items(.data)[inst].@"break"; |
| 2090 | 2119 | const src = sema.src; |
| 2091 | | const operand = try sema.resolveInst(inst_data.operand); |
| 2120 | const operand = sema.resolveInst(inst_data.operand); |
| 2092 | 2121 | const zir_block = inst_data.block_inst; |
| 2093 | 2122 | |
| 2094 | 2123 | var block = start_block; |
| ... | ... | @@ -2136,7 +2165,7 @@ fn zirDbgStmt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 2136 | 2165 | _ = try block.addDbgStmt(.unneeded, inst_data.line, inst_data.column); |
| 2137 | 2166 | } |
| 2138 | 2167 | |
| 2139 | | fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2168 | fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2140 | 2169 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 2141 | 2170 | const src = inst_data.src(); |
| 2142 | 2171 | const decl_name = inst_data.get(sema.code); |
| ... | ... | @@ -2144,7 +2173,7 @@ fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 2144 | 2173 | return sema.analyzeDeclRef(block, src, decl); |
| 2145 | 2174 | } |
| 2146 | 2175 | |
| 2147 | | fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2176 | fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2148 | 2177 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 2149 | 2178 | const src = inst_data.src(); |
| 2150 | 2179 | const decl_name = inst_data.get(sema.code); |
| ... | ... | @@ -2198,7 +2227,7 @@ fn zirCall( |
| 2198 | 2227 | inst: Zir.Inst.Index, |
| 2199 | 2228 | modifier: std.builtin.CallOptions.Modifier, |
| 2200 | 2229 | ensure_result_used: bool, |
| 2201 | | ) InnerError!Air.Inst.Index { |
| 2230 | ) InnerError!Air.Inst.Ref { |
| 2202 | 2231 | const tracy = trace(@src()); |
| 2203 | 2232 | defer tracy.end(); |
| 2204 | 2233 | |
| ... | ... | @@ -2208,12 +2237,12 @@ fn zirCall( |
| 2208 | 2237 | const extra = sema.code.extraData(Zir.Inst.Call, inst_data.payload_index); |
| 2209 | 2238 | const args = sema.code.refSlice(extra.end, extra.data.args_len); |
| 2210 | 2239 | |
| 2211 | | const func = try sema.resolveInst(extra.data.callee); |
| 2240 | const func = sema.resolveInst(extra.data.callee); |
| 2212 | 2241 | // TODO handle function calls of generic functions |
| 2213 | | const resolved_args = try sema.arena.alloc(Air.Inst.Index, args.len); |
| 2242 | const resolved_args = try sema.arena.alloc(Air.Inst.Ref, args.len); |
| 2214 | 2243 | for (args) |zir_arg, i| { |
| 2215 | 2244 | // the args are already casted to the result of a param type instruction. |
| 2216 | | resolved_args[i] = try sema.resolveInst(zir_arg); |
| 2245 | resolved_args[i] = sema.resolveInst(zir_arg); |
| 2217 | 2246 | } |
| 2218 | 2247 | |
| 2219 | 2248 | return sema.analyzeCall(block, func, func_src, call_src, modifier, ensure_result_used, resolved_args); |
| ... | ... | @@ -2222,13 +2251,13 @@ fn zirCall( |
| 2222 | 2251 | fn analyzeCall( |
| 2223 | 2252 | sema: *Sema, |
| 2224 | 2253 | block: *Scope.Block, |
| 2225 | | func: Air.Inst.Index, |
| 2254 | func: Air.Inst.Ref, |
| 2226 | 2255 | func_src: LazySrcLoc, |
| 2227 | 2256 | call_src: LazySrcLoc, |
| 2228 | 2257 | modifier: std.builtin.CallOptions.Modifier, |
| 2229 | 2258 | ensure_result_used: bool, |
| 2230 | | args: []const Air.Inst.Index, |
| 2231 | | ) InnerError!Air.Inst.Index { |
| 2259 | args: []const Air.Inst.Ref, |
| 2260 | ) InnerError!Air.Inst.Ref { |
| 2232 | 2261 | if (func.ty.zigTypeTag() != .Fn) |
| 2233 | 2262 | return sema.mod.fail(&block.base, func_src, "type '{}' not a function", .{func.ty}); |
| 2234 | 2263 | |
| ... | ... | @@ -2285,7 +2314,7 @@ fn analyzeCall( |
| 2285 | 2314 | const is_comptime_call = block.is_comptime or modifier == .compile_time; |
| 2286 | 2315 | const is_inline_call = is_comptime_call or modifier == .always_inline or |
| 2287 | 2316 | func.ty.fnCallingConvention() == .Inline; |
| 2288 | | const result: Air.Inst.Index = if (is_inline_call) res: { |
| 2317 | const result: Air.Inst.Ref = if (is_inline_call) res: { |
| 2289 | 2318 | const func_val = try sema.resolveConstValue(block, func_src, func); |
| 2290 | 2319 | const module_fn = switch (func_val.tag()) { |
| 2291 | 2320 | .function => func_val.castTag(.function).?.data, |
| ... | ... | @@ -2383,7 +2412,7 @@ fn analyzeCall( |
| 2383 | 2412 | return result; |
| 2384 | 2413 | } |
| 2385 | 2414 | |
| 2386 | | fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2415 | fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2387 | 2416 | _ = block; |
| 2388 | 2417 | const tracy = trace(@src()); |
| 2389 | 2418 | defer tracy.end(); |
| ... | ... | @@ -2395,7 +2424,7 @@ fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 2395 | 2424 | return sema.mod.constType(sema.arena, src, ty); |
| 2396 | 2425 | } |
| 2397 | 2426 | |
| 2398 | | fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2427 | fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2399 | 2428 | const tracy = trace(@src()); |
| 2400 | 2429 | defer tracy.end(); |
| 2401 | 2430 | |
| ... | ... | @@ -2407,7 +2436,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner |
| 2407 | 2436 | return sema.mod.constType(sema.arena, src, opt_type); |
| 2408 | 2437 | } |
| 2409 | 2438 | |
| 2410 | | fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2439 | fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2411 | 2440 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2412 | 2441 | const src = inst_data.src(); |
| 2413 | 2442 | const array_type = try sema.resolveType(block, src, inst_data.operand); |
| ... | ... | @@ -2415,7 +2444,7 @@ fn zirElemType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 2415 | 2444 | return sema.mod.constType(sema.arena, src, elem_type); |
| 2416 | 2445 | } |
| 2417 | 2446 | |
| 2418 | | fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2447 | fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2419 | 2448 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 2420 | 2449 | const src = inst_data.src(); |
| 2421 | 2450 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | ... | @@ -2430,7 +2459,7 @@ fn zirVectorType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr |
| 2430 | 2459 | return sema.mod.constType(sema.arena, src, vector_type); |
| 2431 | 2460 | } |
| 2432 | 2461 | |
| 2433 | | fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2462 | fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2434 | 2463 | const tracy = trace(@src()); |
| 2435 | 2464 | defer tracy.end(); |
| 2436 | 2465 | |
| ... | ... | @@ -2443,7 +2472,7 @@ fn zirArrayType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr |
| 2443 | 2472 | return sema.mod.constType(sema.arena, .unneeded, array_ty); |
| 2444 | 2473 | } |
| 2445 | 2474 | |
| 2446 | | fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2475 | fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2447 | 2476 | const tracy = trace(@src()); |
| 2448 | 2477 | defer tracy.end(); |
| 2449 | 2478 | |
| ... | ... | @@ -2458,7 +2487,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 2458 | 2487 | return sema.mod.constType(sema.arena, .unneeded, array_ty); |
| 2459 | 2488 | } |
| 2460 | 2489 | |
| 2461 | | fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2490 | fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2462 | 2491 | const tracy = trace(@src()); |
| 2463 | 2492 | defer tracy.end(); |
| 2464 | 2493 | |
| ... | ... | @@ -2471,7 +2500,7 @@ fn zirAnyframeType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner |
| 2471 | 2500 | return sema.mod.constType(sema.arena, src, anyframe_type); |
| 2472 | 2501 | } |
| 2473 | 2502 | |
| 2474 | | fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2503 | fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2475 | 2504 | const tracy = trace(@src()); |
| 2476 | 2505 | defer tracy.end(); |
| 2477 | 2506 | |
| ... | ... | @@ -2492,7 +2521,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn |
| 2492 | 2521 | return sema.mod.constType(sema.arena, src, err_union_ty); |
| 2493 | 2522 | } |
| 2494 | 2523 | |
| 2495 | | fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2524 | fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2496 | 2525 | _ = block; |
| 2497 | 2526 | const tracy = trace(@src()); |
| 2498 | 2527 | defer tracy.end(); |
| ... | ... | @@ -2511,14 +2540,14 @@ fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr |
| 2511 | 2540 | }); |
| 2512 | 2541 | } |
| 2513 | 2542 | |
| 2514 | | fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2543 | fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2515 | 2544 | const tracy = trace(@src()); |
| 2516 | 2545 | defer tracy.end(); |
| 2517 | 2546 | |
| 2518 | 2547 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2519 | 2548 | const src = inst_data.src(); |
| 2520 | 2549 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2521 | | const op = try sema.resolveInst(inst_data.operand); |
| 2550 | const op = sema.resolveInst(inst_data.operand); |
| 2522 | 2551 | const op_coerced = try sema.coerce(block, Type.initTag(.anyerror), op, operand_src); |
| 2523 | 2552 | const result_ty = Type.initTag(.u16); |
| 2524 | 2553 | |
| ... | ... | @@ -2541,7 +2570,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr |
| 2541 | 2570 | return block.addUnOp(src, result_ty, .bitcast, op_coerced); |
| 2542 | 2571 | } |
| 2543 | 2572 | |
| 2544 | | fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2573 | fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2545 | 2574 | const tracy = trace(@src()); |
| 2546 | 2575 | defer tracy.end(); |
| 2547 | 2576 | |
| ... | ... | @@ -2549,7 +2578,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr |
| 2549 | 2578 | const src = inst_data.src(); |
| 2550 | 2579 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2551 | 2580 | |
| 2552 | | const op = try sema.resolveInst(inst_data.operand); |
| 2581 | const op = sema.resolveInst(inst_data.operand); |
| 2553 | 2582 | |
| 2554 | 2583 | if (try sema.resolveDefinedValue(block, operand_src, op)) |value| { |
| 2555 | 2584 | const int = value.toUnsignedInt(); |
| ... | ... | @@ -2574,7 +2603,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr |
| 2574 | 2603 | return block.addUnOp(src, Type.initTag(.anyerror), .bitcast, op); |
| 2575 | 2604 | } |
| 2576 | 2605 | |
| 2577 | | fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2606 | fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2578 | 2607 | const tracy = trace(@src()); |
| 2579 | 2608 | defer tracy.end(); |
| 2580 | 2609 | |
| ... | ... | @@ -2583,8 +2612,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn |
| 2583 | 2612 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 2584 | 2613 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 2585 | 2614 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 2586 | | const lhs = try sema.resolveInst(extra.lhs); |
| 2587 | | const rhs = try sema.resolveInst(extra.rhs); |
| 2615 | const lhs = sema.resolveInst(extra.lhs); |
| 2616 | const rhs = sema.resolveInst(extra.rhs); |
| 2588 | 2617 | if (rhs.ty.zigTypeTag() == .Bool and lhs.ty.zigTypeTag() == .Bool) { |
| 2589 | 2618 | const msg = msg: { |
| 2590 | 2619 | const msg = try sema.mod.errMsg(&block.base, lhs_src, "expected error set type, found 'bool'", .{}); |
| ... | ... | @@ -2664,7 +2693,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn |
| 2664 | 2693 | }); |
| 2665 | 2694 | } |
| 2666 | 2695 | |
| 2667 | | fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2696 | fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2668 | 2697 | _ = block; |
| 2669 | 2698 | const tracy = trace(@src()); |
| 2670 | 2699 | defer tracy.end(); |
| ... | ... | @@ -2678,15 +2707,15 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE |
| 2678 | 2707 | }); |
| 2679 | 2708 | } |
| 2680 | 2709 | |
| 2681 | | fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2710 | fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2682 | 2711 | const mod = sema.mod; |
| 2683 | 2712 | const arena = sema.arena; |
| 2684 | 2713 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2685 | 2714 | const src = inst_data.src(); |
| 2686 | 2715 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2687 | | const operand = try sema.resolveInst(inst_data.operand); |
| 2716 | const operand = sema.resolveInst(inst_data.operand); |
| 2688 | 2717 | |
| 2689 | | const enum_tag: Air.Inst.Index = switch (operand.ty.zigTypeTag()) { |
| 2718 | const enum_tag: Air.Inst.Ref = switch (operand.ty.zigTypeTag()) { |
| 2690 | 2719 | .Enum => operand, |
| 2691 | 2720 | .Union => { |
| 2692 | 2721 | //if (!operand.ty.unionHasTag()) { |
| ... | ... | @@ -2760,7 +2789,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr |
| 2760 | 2789 | return block.addUnOp(src, int_tag_ty, .bitcast, enum_tag); |
| 2761 | 2790 | } |
| 2762 | 2791 | |
| 2763 | | fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 2792 | fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2764 | 2793 | const mod = sema.mod; |
| 2765 | 2794 | const target = mod.getTarget(); |
| 2766 | 2795 | const arena = sema.arena; |
| ... | ... | @@ -2770,7 +2799,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr |
| 2770 | 2799 | const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2771 | 2800 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 2772 | 2801 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 2773 | | const operand = try sema.resolveInst(extra.rhs); |
| 2802 | const operand = sema.resolveInst(extra.rhs); |
| 2774 | 2803 | |
| 2775 | 2804 | if (dest_ty.zigTypeTag() != .Enum) { |
| 2776 | 2805 | return mod.fail(&block.base, dest_ty_src, "expected enum, found {}", .{dest_ty}); |
| ... | ... | @@ -2821,12 +2850,12 @@ fn zirOptionalPayloadPtr( |
| 2821 | 2850 | block: *Scope.Block, |
| 2822 | 2851 | inst: Zir.Inst.Index, |
| 2823 | 2852 | safety_check: bool, |
| 2824 | | ) InnerError!Air.Inst.Index { |
| 2853 | ) InnerError!Air.Inst.Ref { |
| 2825 | 2854 | const tracy = trace(@src()); |
| 2826 | 2855 | defer tracy.end(); |
| 2827 | 2856 | |
| 2828 | 2857 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2829 | | const optional_ptr = try sema.resolveInst(inst_data.operand); |
| 2858 | const optional_ptr = sema.resolveInst(inst_data.operand); |
| 2830 | 2859 | assert(optional_ptr.ty.zigTypeTag() == .Pointer); |
| 2831 | 2860 | const src = inst_data.src(); |
| 2832 | 2861 | |
| ... | ... | @@ -2836,7 +2865,7 @@ fn zirOptionalPayloadPtr( |
| 2836 | 2865 | } |
| 2837 | 2866 | |
| 2838 | 2867 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 2839 | | const child_pointer = try sema.mod.simplePtrType(sema.arena, child_type, !optional_ptr.ty.isConstPtr(), .One); |
| 2868 | const child_pointer = try Module.simplePtrType(sema.arena, child_type, !optional_ptr.ty.isConstPtr(), .One); |
| 2840 | 2869 | |
| 2841 | 2870 | if (optional_ptr.value()) |pointer_val| { |
| 2842 | 2871 | const val = try pointer_val.pointerDeref(sema.arena); |
| ... | ... | @@ -2864,13 +2893,13 @@ fn zirOptionalPayload( |
| 2864 | 2893 | block: *Scope.Block, |
| 2865 | 2894 | inst: Zir.Inst.Index, |
| 2866 | 2895 | safety_check: bool, |
| 2867 | | ) InnerError!Air.Inst.Index { |
| 2896 | ) InnerError!Air.Inst.Ref { |
| 2868 | 2897 | const tracy = trace(@src()); |
| 2869 | 2898 | defer tracy.end(); |
| 2870 | 2899 | |
| 2871 | 2900 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2872 | 2901 | const src = inst_data.src(); |
| 2873 | | const operand = try sema.resolveInst(inst_data.operand); |
| 2902 | const operand = sema.resolveInst(inst_data.operand); |
| 2874 | 2903 | const opt_type = operand.ty; |
| 2875 | 2904 | if (opt_type.zigTypeTag() != .Optional) { |
| 2876 | 2905 | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); |
| ... | ... | @@ -2902,13 +2931,13 @@ fn zirErrUnionPayload( |
| 2902 | 2931 | block: *Scope.Block, |
| 2903 | 2932 | inst: Zir.Inst.Index, |
| 2904 | 2933 | safety_check: bool, |
| 2905 | | ) InnerError!Air.Inst.Index { |
| 2934 | ) InnerError!Air.Inst.Ref { |
| 2906 | 2935 | const tracy = trace(@src()); |
| 2907 | 2936 | defer tracy.end(); |
| 2908 | 2937 | |
| 2909 | 2938 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2910 | 2939 | const src = inst_data.src(); |
| 2911 | | const operand = try sema.resolveInst(inst_data.operand); |
| 2940 | const operand = sema.resolveInst(inst_data.operand); |
| 2912 | 2941 | if (operand.ty.zigTypeTag() != .ErrorUnion) |
| 2913 | 2942 | return sema.mod.fail(&block.base, operand.src, "expected error union type, found '{}'", .{operand.ty}); |
| 2914 | 2943 | |
| ... | ... | @@ -2936,19 +2965,19 @@ fn zirErrUnionPayloadPtr( |
| 2936 | 2965 | block: *Scope.Block, |
| 2937 | 2966 | inst: Zir.Inst.Index, |
| 2938 | 2967 | safety_check: bool, |
| 2939 | | ) InnerError!Air.Inst.Index { |
| 2968 | ) InnerError!Air.Inst.Ref { |
| 2940 | 2969 | const tracy = trace(@src()); |
| 2941 | 2970 | defer tracy.end(); |
| 2942 | 2971 | |
| 2943 | 2972 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2944 | 2973 | const src = inst_data.src(); |
| 2945 | | const operand = try sema.resolveInst(inst_data.operand); |
| 2974 | const operand = sema.resolveInst(inst_data.operand); |
| 2946 | 2975 | assert(operand.ty.zigTypeTag() == .Pointer); |
| 2947 | 2976 | |
| 2948 | 2977 | if (operand.ty.elemType().zigTypeTag() != .ErrorUnion) |
| 2949 | 2978 | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand.ty.elemType()}); |
| 2950 | 2979 | |
| 2951 | | const operand_pointer_ty = try sema.mod.simplePtrType(sema.arena, operand.ty.elemType().castTag(.error_union).?.data.payload, !operand.ty.isConstPtr(), .One); |
| 2980 | const operand_pointer_ty = try Module.simplePtrType(sema.arena, operand.ty.elemType().castTag(.error_union).?.data.payload, !operand.ty.isConstPtr(), .One); |
| 2952 | 2981 | |
| 2953 | 2982 | if (operand.value()) |pointer_val| { |
| 2954 | 2983 | const val = try pointer_val.pointerDeref(sema.arena); |
| ... | ... | @@ -2975,13 +3004,13 @@ fn zirErrUnionPayloadPtr( |
| 2975 | 3004 | } |
| 2976 | 3005 | |
| 2977 | 3006 | /// Value in, value out |
| 2978 | | fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3007 | fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 2979 | 3008 | const tracy = trace(@src()); |
| 2980 | 3009 | defer tracy.end(); |
| 2981 | 3010 | |
| 2982 | 3011 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2983 | 3012 | const src = inst_data.src(); |
| 2984 | | const operand = try sema.resolveInst(inst_data.operand); |
| 3013 | const operand = sema.resolveInst(inst_data.operand); |
| 2985 | 3014 | if (operand.ty.zigTypeTag() != .ErrorUnion) |
| 2986 | 3015 | return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand.ty}); |
| 2987 | 3016 | |
| ... | ... | @@ -3001,13 +3030,13 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner |
| 3001 | 3030 | } |
| 3002 | 3031 | |
| 3003 | 3032 | /// Pointer in, value out |
| 3004 | | fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3033 | fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3005 | 3034 | const tracy = trace(@src()); |
| 3006 | 3035 | defer tracy.end(); |
| 3007 | 3036 | |
| 3008 | 3037 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3009 | 3038 | const src = inst_data.src(); |
| 3010 | | const operand = try sema.resolveInst(inst_data.operand); |
| 3039 | const operand = sema.resolveInst(inst_data.operand); |
| 3011 | 3040 | assert(operand.ty.zigTypeTag() == .Pointer); |
| 3012 | 3041 | |
| 3013 | 3042 | if (operand.ty.elemType().zigTypeTag() != .ErrorUnion) |
| ... | ... | @@ -3035,7 +3064,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 3035 | 3064 | |
| 3036 | 3065 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 3037 | 3066 | const src = inst_data.src(); |
| 3038 | | const operand = try sema.resolveInst(inst_data.operand); |
| 3067 | const operand = sema.resolveInst(inst_data.operand); |
| 3039 | 3068 | if (operand.ty.zigTypeTag() != .ErrorUnion) |
| 3040 | 3069 | return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand.ty}); |
| 3041 | 3070 | if (operand.ty.castTag(.error_union).?.data.payload.zigTypeTag() != .Void) { |
| ... | ... | @@ -3048,7 +3077,7 @@ fn zirFunc( |
| 3048 | 3077 | block: *Scope.Block, |
| 3049 | 3078 | inst: Zir.Inst.Index, |
| 3050 | 3079 | inferred_error_set: bool, |
| 3051 | | ) InnerError!Air.Inst.Index { |
| 3080 | ) InnerError!Air.Inst.Ref { |
| 3052 | 3081 | const tracy = trace(@src()); |
| 3053 | 3082 | defer tracy.end(); |
| 3054 | 3083 | |
| ... | ... | @@ -3099,7 +3128,7 @@ fn funcCommon( |
| 3099 | 3128 | is_extern: bool, |
| 3100 | 3129 | src_locs: Zir.Inst.Func.SrcLocs, |
| 3101 | 3130 | opt_lib_name: ?[]const u8, |
| 3102 | | ) InnerError!Air.Inst.Index { |
| 3131 | ) InnerError!Air.Inst.Ref { |
| 3103 | 3132 | const src: LazySrcLoc = .{ .node_offset = src_node_offset }; |
| 3104 | 3133 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset }; |
| 3105 | 3134 | const bare_return_type = try sema.resolveType(block, ret_ty_src, zir_return_type); |
| ... | ... | @@ -3240,7 +3269,7 @@ fn funcCommon( |
| 3240 | 3269 | return result; |
| 3241 | 3270 | } |
| 3242 | 3271 | |
| 3243 | | fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3272 | fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3244 | 3273 | const tracy = trace(@src()); |
| 3245 | 3274 | defer tracy.end(); |
| 3246 | 3275 | |
| ... | ... | @@ -3248,7 +3277,7 @@ fn zirAs(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air. |
| 3248 | 3277 | return sema.analyzeAs(block, .unneeded, bin_inst.lhs, bin_inst.rhs); |
| 3249 | 3278 | } |
| 3250 | 3279 | |
| 3251 | | fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3280 | fn zirAsNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3252 | 3281 | const tracy = trace(@src()); |
| 3253 | 3282 | defer tracy.end(); |
| 3254 | 3283 | |
| ... | ... | @@ -3264,18 +3293,18 @@ fn analyzeAs( |
| 3264 | 3293 | src: LazySrcLoc, |
| 3265 | 3294 | zir_dest_type: Zir.Inst.Ref, |
| 3266 | 3295 | zir_operand: Zir.Inst.Ref, |
| 3267 | | ) InnerError!Air.Inst.Index { |
| 3296 | ) InnerError!Air.Inst.Ref { |
| 3268 | 3297 | const dest_type = try sema.resolveType(block, src, zir_dest_type); |
| 3269 | | const operand = try sema.resolveInst(zir_operand); |
| 3298 | const operand = sema.resolveInst(zir_operand); |
| 3270 | 3299 | return sema.coerce(block, dest_type, operand, src); |
| 3271 | 3300 | } |
| 3272 | 3301 | |
| 3273 | | fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3302 | fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3274 | 3303 | const tracy = trace(@src()); |
| 3275 | 3304 | defer tracy.end(); |
| 3276 | 3305 | |
| 3277 | 3306 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3278 | | const ptr = try sema.resolveInst(inst_data.operand); |
| 3307 | const ptr = sema.resolveInst(inst_data.operand); |
| 3279 | 3308 | if (ptr.ty.zigTypeTag() != .Pointer) { |
| 3280 | 3309 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 3281 | 3310 | return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr.ty}); |
| ... | ... | @@ -3287,7 +3316,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 3287 | 3316 | return block.addUnOp(src, ty, .ptrtoint, ptr); |
| 3288 | 3317 | } |
| 3289 | 3318 | |
| 3290 | | fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3319 | fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3291 | 3320 | const tracy = trace(@src()); |
| 3292 | 3321 | defer tracy.end(); |
| 3293 | 3322 | |
| ... | ... | @@ -3296,7 +3325,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 3296 | 3325 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 3297 | 3326 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 3298 | 3327 | const field_name = sema.code.nullTerminatedString(extra.field_name_start); |
| 3299 | | const object = try sema.resolveInst(extra.lhs); |
| 3328 | const object = sema.resolveInst(extra.lhs); |
| 3300 | 3329 | const object_ptr = if (object.ty.zigTypeTag() == .Pointer) |
| 3301 | 3330 | object |
| 3302 | 3331 | else |
| ... | ... | @@ -3305,7 +3334,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 3305 | 3334 | return sema.analyzeLoad(block, src, result_ptr, result_ptr.src); |
| 3306 | 3335 | } |
| 3307 | 3336 | |
| 3308 | | fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3337 | fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3309 | 3338 | const tracy = trace(@src()); |
| 3310 | 3339 | defer tracy.end(); |
| 3311 | 3340 | |
| ... | ... | @@ -3314,11 +3343,11 @@ fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 3314 | 3343 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 3315 | 3344 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 3316 | 3345 | const field_name = sema.code.nullTerminatedString(extra.field_name_start); |
| 3317 | | const object_ptr = try sema.resolveInst(extra.lhs); |
| 3346 | const object_ptr = sema.resolveInst(extra.lhs); |
| 3318 | 3347 | return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src); |
| 3319 | 3348 | } |
| 3320 | 3349 | |
| 3321 | | fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3350 | fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3322 | 3351 | const tracy = trace(@src()); |
| 3323 | 3352 | defer tracy.end(); |
| 3324 | 3353 | |
| ... | ... | @@ -3326,14 +3355,14 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne |
| 3326 | 3355 | const src = inst_data.src(); |
| 3327 | 3356 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 3328 | 3357 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 3329 | | const object = try sema.resolveInst(extra.lhs); |
| 3358 | const object = sema.resolveInst(extra.lhs); |
| 3330 | 3359 | const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name); |
| 3331 | 3360 | const object_ptr = try sema.analyzeRef(block, src, object); |
| 3332 | 3361 | const result_ptr = try sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src); |
| 3333 | 3362 | return sema.analyzeLoad(block, src, result_ptr, src); |
| 3334 | 3363 | } |
| 3335 | 3364 | |
| 3336 | | fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3365 | fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3337 | 3366 | const tracy = trace(@src()); |
| 3338 | 3367 | defer tracy.end(); |
| 3339 | 3368 | |
| ... | ... | @@ -3341,12 +3370,12 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne |
| 3341 | 3370 | const src = inst_data.src(); |
| 3342 | 3371 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 3343 | 3372 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 3344 | | const object_ptr = try sema.resolveInst(extra.lhs); |
| 3373 | const object_ptr = sema.resolveInst(extra.lhs); |
| 3345 | 3374 | const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name); |
| 3346 | 3375 | return sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src); |
| 3347 | 3376 | } |
| 3348 | 3377 | |
| 3349 | | fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3378 | fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3350 | 3379 | const tracy = trace(@src()); |
| 3351 | 3380 | defer tracy.end(); |
| 3352 | 3381 | |
| ... | ... | @@ -3357,7 +3386,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 3357 | 3386 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 3358 | 3387 | |
| 3359 | 3388 | const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 3360 | | const operand = try sema.resolveInst(extra.rhs); |
| 3389 | const operand = sema.resolveInst(extra.rhs); |
| 3361 | 3390 | |
| 3362 | 3391 | const dest_is_comptime_int = switch (dest_type.zigTypeTag()) { |
| 3363 | 3392 | .ComptimeInt => true, |
| ... | ... | @@ -3389,20 +3418,21 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 3389 | 3418 | return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten int", .{}); |
| 3390 | 3419 | } |
| 3391 | 3420 | |
| 3392 | | fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3421 | fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3393 | 3422 | const tracy = trace(@src()); |
| 3394 | 3423 | defer tracy.end(); |
| 3395 | 3424 | |
| 3396 | 3425 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 3397 | 3426 | const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 3427 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 3398 | 3428 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 3399 | 3429 | |
| 3400 | 3430 | const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 3401 | | const operand = try sema.resolveInst(extra.rhs); |
| 3402 | | return sema.bitcast(block, dest_type, operand); |
| 3431 | const operand = sema.resolveInst(extra.rhs); |
| 3432 | return sema.bitcast(block, dest_type, operand, operand_src); |
| 3403 | 3433 | } |
| 3404 | 3434 | |
| 3405 | | fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3435 | fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3406 | 3436 | const tracy = trace(@src()); |
| 3407 | 3437 | defer tracy.end(); |
| 3408 | 3438 | |
| ... | ... | @@ -3413,7 +3443,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr |
| 3413 | 3443 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 3414 | 3444 | |
| 3415 | 3445 | const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 3416 | | const operand = try sema.resolveInst(extra.rhs); |
| 3446 | const operand = sema.resolveInst(extra.rhs); |
| 3417 | 3447 | |
| 3418 | 3448 | const dest_is_comptime_float = switch (dest_type.zigTypeTag()) { |
| 3419 | 3449 | .ComptimeFloat => true, |
| ... | ... | @@ -3445,22 +3475,22 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr |
| 3445 | 3475 | return sema.mod.fail(&block.base, src, "TODO implement analyze widen or shorten float", .{}); |
| 3446 | 3476 | } |
| 3447 | 3477 | |
| 3448 | | fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3478 | fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3449 | 3479 | const tracy = trace(@src()); |
| 3450 | 3480 | defer tracy.end(); |
| 3451 | 3481 | |
| 3452 | 3482 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 3453 | | const array = try sema.resolveInst(bin_inst.lhs); |
| 3483 | const array = sema.resolveInst(bin_inst.lhs); |
| 3454 | 3484 | const array_ptr = if (array.ty.zigTypeTag() == .Pointer) |
| 3455 | 3485 | array |
| 3456 | 3486 | else |
| 3457 | 3487 | try sema.analyzeRef(block, sema.src, array); |
| 3458 | | const elem_index = try sema.resolveInst(bin_inst.rhs); |
| 3488 | const elem_index = sema.resolveInst(bin_inst.rhs); |
| 3459 | 3489 | const result_ptr = try sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src); |
| 3460 | 3490 | return sema.analyzeLoad(block, sema.src, result_ptr, sema.src); |
| 3461 | 3491 | } |
| 3462 | 3492 | |
| 3463 | | fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3493 | fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3464 | 3494 | const tracy = trace(@src()); |
| 3465 | 3495 | defer tracy.end(); |
| 3466 | 3496 | |
| ... | ... | @@ -3468,27 +3498,27 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE |
| 3468 | 3498 | const src = inst_data.src(); |
| 3469 | 3499 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; |
| 3470 | 3500 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 3471 | | const array = try sema.resolveInst(extra.lhs); |
| 3501 | const array = sema.resolveInst(extra.lhs); |
| 3472 | 3502 | const array_ptr = if (array.ty.zigTypeTag() == .Pointer) |
| 3473 | 3503 | array |
| 3474 | 3504 | else |
| 3475 | 3505 | try sema.analyzeRef(block, src, array); |
| 3476 | | const elem_index = try sema.resolveInst(extra.rhs); |
| 3506 | const elem_index = sema.resolveInst(extra.rhs); |
| 3477 | 3507 | const result_ptr = try sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src); |
| 3478 | 3508 | return sema.analyzeLoad(block, src, result_ptr, src); |
| 3479 | 3509 | } |
| 3480 | 3510 | |
| 3481 | | fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3511 | fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3482 | 3512 | const tracy = trace(@src()); |
| 3483 | 3513 | defer tracy.end(); |
| 3484 | 3514 | |
| 3485 | 3515 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 3486 | | const array_ptr = try sema.resolveInst(bin_inst.lhs); |
| 3487 | | const elem_index = try sema.resolveInst(bin_inst.rhs); |
| 3516 | const array_ptr = sema.resolveInst(bin_inst.lhs); |
| 3517 | const elem_index = sema.resolveInst(bin_inst.rhs); |
| 3488 | 3518 | return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src); |
| 3489 | 3519 | } |
| 3490 | 3520 | |
| 3491 | | fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3521 | fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3492 | 3522 | const tracy = trace(@src()); |
| 3493 | 3523 | defer tracy.end(); |
| 3494 | 3524 | |
| ... | ... | @@ -3496,39 +3526,39 @@ fn zirElemPtrNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE |
| 3496 | 3526 | const src = inst_data.src(); |
| 3497 | 3527 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; |
| 3498 | 3528 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 3499 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 3500 | | const elem_index = try sema.resolveInst(extra.rhs); |
| 3529 | const array_ptr = sema.resolveInst(extra.lhs); |
| 3530 | const elem_index = sema.resolveInst(extra.rhs); |
| 3501 | 3531 | return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src); |
| 3502 | 3532 | } |
| 3503 | 3533 | |
| 3504 | | fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3534 | fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3505 | 3535 | const tracy = trace(@src()); |
| 3506 | 3536 | defer tracy.end(); |
| 3507 | 3537 | |
| 3508 | 3538 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 3509 | 3539 | const src = inst_data.src(); |
| 3510 | 3540 | const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| 3511 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 3512 | | const start = try sema.resolveInst(extra.start); |
| 3541 | const array_ptr = sema.resolveInst(extra.lhs); |
| 3542 | const start = sema.resolveInst(extra.start); |
| 3513 | 3543 | |
| 3514 | 3544 | return sema.analyzeSlice(block, src, array_ptr, start, null, null, .unneeded); |
| 3515 | 3545 | } |
| 3516 | 3546 | |
| 3517 | | fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3547 | fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3518 | 3548 | const tracy = trace(@src()); |
| 3519 | 3549 | defer tracy.end(); |
| 3520 | 3550 | |
| 3521 | 3551 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 3522 | 3552 | const src = inst_data.src(); |
| 3523 | 3553 | const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; |
| 3524 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 3525 | | const start = try sema.resolveInst(extra.start); |
| 3526 | | const end = try sema.resolveInst(extra.end); |
| 3554 | const array_ptr = sema.resolveInst(extra.lhs); |
| 3555 | const start = sema.resolveInst(extra.start); |
| 3556 | const end = sema.resolveInst(extra.end); |
| 3527 | 3557 | |
| 3528 | 3558 | return sema.analyzeSlice(block, src, array_ptr, start, end, null, .unneeded); |
| 3529 | 3559 | } |
| 3530 | 3560 | |
| 3531 | | fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 3561 | fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 3532 | 3562 | const tracy = trace(@src()); |
| 3533 | 3563 | defer tracy.end(); |
| 3534 | 3564 | |
| ... | ... | @@ -3536,10 +3566,10 @@ fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne |
| 3536 | 3566 | const src = inst_data.src(); |
| 3537 | 3567 | const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node }; |
| 3538 | 3568 | const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; |
| 3539 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 3540 | | const start = try sema.resolveInst(extra.start); |
| 3541 | | const end = try sema.resolveInst(extra.end); |
| 3542 | | const sentinel = try sema.resolveInst(extra.sentinel); |
| 3569 | const array_ptr = sema.resolveInst(extra.lhs); |
| 3570 | const start = sema.resolveInst(extra.start); |
| 3571 | const end = sema.resolveInst(extra.end); |
| 3572 | const sentinel = sema.resolveInst(extra.sentinel); |
| 3543 | 3573 | |
| 3544 | 3574 | return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src); |
| 3545 | 3575 | } |
| ... | ... | @@ -3550,7 +3580,7 @@ fn zirSwitchCapture( |
| 3550 | 3580 | inst: Zir.Inst.Index, |
| 3551 | 3581 | is_multi: bool, |
| 3552 | 3582 | is_ref: bool, |
| 3553 | | ) InnerError!Air.Inst.Index { |
| 3583 | ) InnerError!Air.Inst.Ref { |
| 3554 | 3584 | const tracy = trace(@src()); |
| 3555 | 3585 | defer tracy.end(); |
| 3556 | 3586 | |
| ... | ... | @@ -3569,7 +3599,7 @@ fn zirSwitchCaptureElse( |
| 3569 | 3599 | block: *Scope.Block, |
| 3570 | 3600 | inst: Zir.Inst.Index, |
| 3571 | 3601 | is_ref: bool, |
| 3572 | | ) InnerError!Air.Inst.Index { |
| 3602 | ) InnerError!Air.Inst.Ref { |
| 3573 | 3603 | const tracy = trace(@src()); |
| 3574 | 3604 | defer tracy.end(); |
| 3575 | 3605 | |
| ... | ... | @@ -3588,7 +3618,7 @@ fn zirSwitchBlock( |
| 3588 | 3618 | inst: Zir.Inst.Index, |
| 3589 | 3619 | is_ref: bool, |
| 3590 | 3620 | special_prong: Zir.SpecialProng, |
| 3591 | | ) InnerError!Air.Inst.Index { |
| 3621 | ) InnerError!Air.Inst.Ref { |
| 3592 | 3622 | const tracy = trace(@src()); |
| 3593 | 3623 | defer tracy.end(); |
| 3594 | 3624 | |
| ... | ... | @@ -3597,7 +3627,7 @@ fn zirSwitchBlock( |
| 3597 | 3627 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node }; |
| 3598 | 3628 | const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index); |
| 3599 | 3629 | |
| 3600 | | const operand_ptr = try sema.resolveInst(extra.data.operand); |
| 3630 | const operand_ptr = sema.resolveInst(extra.data.operand); |
| 3601 | 3631 | const operand = if (is_ref) |
| 3602 | 3632 | try sema.analyzeLoad(block, src, operand_ptr, operand_src) |
| 3603 | 3633 | else |
| ... | ... | @@ -3621,7 +3651,7 @@ fn zirSwitchBlockMulti( |
| 3621 | 3651 | inst: Zir.Inst.Index, |
| 3622 | 3652 | is_ref: bool, |
| 3623 | 3653 | special_prong: Zir.SpecialProng, |
| 3624 | | ) InnerError!Air.Inst.Index { |
| 3654 | ) InnerError!Air.Inst.Ref { |
| 3625 | 3655 | const tracy = trace(@src()); |
| 3626 | 3656 | defer tracy.end(); |
| 3627 | 3657 | |
| ... | ... | @@ -3630,7 +3660,7 @@ fn zirSwitchBlockMulti( |
| 3630 | 3660 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = inst_data.src_node }; |
| 3631 | 3661 | const extra = sema.code.extraData(Zir.Inst.SwitchBlockMulti, inst_data.payload_index); |
| 3632 | 3662 | |
| 3633 | | const operand_ptr = try sema.resolveInst(extra.data.operand); |
| 3663 | const operand_ptr = sema.resolveInst(extra.data.operand); |
| 3634 | 3664 | const operand = if (is_ref) |
| 3635 | 3665 | try sema.analyzeLoad(block, src, operand_ptr, operand_src) |
| 3636 | 3666 | else |
| ... | ... | @@ -3651,14 +3681,14 @@ fn zirSwitchBlockMulti( |
| 3651 | 3681 | fn analyzeSwitch( |
| 3652 | 3682 | sema: *Sema, |
| 3653 | 3683 | block: *Scope.Block, |
| 3654 | | operand: Air.Inst.Index, |
| 3684 | operand: Air.Inst.Ref, |
| 3655 | 3685 | extra_end: usize, |
| 3656 | 3686 | special_prong: Zir.SpecialProng, |
| 3657 | 3687 | scalar_cases_len: usize, |
| 3658 | 3688 | multi_cases_len: usize, |
| 3659 | 3689 | switch_inst: Zir.Inst.Index, |
| 3660 | 3690 | src_node_offset: i32, |
| 3661 | | ) InnerError!Air.Inst.Index { |
| 3691 | ) InnerError!Air.Inst.Ref { |
| 3662 | 3692 | const gpa = sema.gpa; |
| 3663 | 3693 | const mod = sema.mod; |
| 3664 | 3694 | |
| ... | ... | @@ -4217,7 +4247,7 @@ fn analyzeSwitch( |
| 4217 | 4247 | const bool_ty = comptime Type.initTag(.bool); |
| 4218 | 4248 | |
| 4219 | 4249 | for (items) |item_ref| { |
| 4220 | | const item = try sema.resolveInst(item_ref); |
| 4250 | const item = sema.resolveInst(item_ref); |
| 4221 | 4251 | _ = try sema.resolveConstValue(&child_block, item.src, item); |
| 4222 | 4252 | |
| 4223 | 4253 | const cmp_ok = try case_block.addBinOp(item.src, bool_ty, .cmp_eq, operand, item); |
| ... | ... | @@ -4235,8 +4265,8 @@ fn analyzeSwitch( |
| 4235 | 4265 | const last_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 4236 | 4266 | extra_index += 1; |
| 4237 | 4267 | |
| 4238 | | const item_first = try sema.resolveInst(first_ref); |
| 4239 | | const item_last = try sema.resolveInst(last_ref); |
| 4268 | const item_first = sema.resolveInst(first_ref); |
| 4269 | const item_last = sema.resolveInst(last_ref); |
| 4240 | 4270 | |
| 4241 | 4271 | _ = try sema.resolveConstValue(&child_block, item_first.src, item_first); |
| 4242 | 4272 | _ = try sema.resolveConstValue(&child_block, item_last.src, item_last); |
| ... | ... | @@ -4334,7 +4364,7 @@ fn resolveSwitchItemVal( |
| 4334 | 4364 | switch_prong_src: Module.SwitchProngSrc, |
| 4335 | 4365 | range_expand: Module.SwitchProngSrc.RangeExpand, |
| 4336 | 4366 | ) InnerError!TypedValue { |
| 4337 | | const item = try sema.resolveInst(item_ref); |
| 4367 | const item = sema.resolveInst(item_ref); |
| 4338 | 4368 | // We have to avoid the other helper functions here because we cannot construct a LazySrcLoc |
| 4339 | 4369 | // because we only have the switch AST node. Only if we know for sure we need to report |
| 4340 | 4370 | // a compile error do we resolve the full source locations. |
| ... | ... | @@ -4513,7 +4543,7 @@ fn validateSwitchNoRange( |
| 4513 | 4543 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 4514 | 4544 | } |
| 4515 | 4545 | |
| 4516 | | fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4546 | fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4517 | 4547 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 4518 | 4548 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 4519 | 4549 | _ = extra; |
| ... | ... | @@ -4522,7 +4552,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 4522 | 4552 | return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{}); |
| 4523 | 4553 | } |
| 4524 | 4554 | |
| 4525 | | fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4555 | fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4526 | 4556 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 4527 | 4557 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 4528 | 4558 | const src = inst_data.src(); |
| ... | ... | @@ -4547,7 +4577,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 4547 | 4577 | return mod.constBool(arena, src, false); |
| 4548 | 4578 | } |
| 4549 | 4579 | |
| 4550 | | fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4580 | fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4551 | 4581 | const tracy = trace(@src()); |
| 4552 | 4582 | defer tracy.end(); |
| 4553 | 4583 | |
| ... | ... | @@ -4572,13 +4602,13 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError! |
| 4572 | 4602 | return mod.constType(sema.arena, src, file_root_decl.ty); |
| 4573 | 4603 | } |
| 4574 | 4604 | |
| 4575 | | fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4605 | fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4576 | 4606 | _ = block; |
| 4577 | 4607 | _ = inst; |
| 4578 | 4608 | return sema.mod.fail(&block.base, sema.src, "TODO implement zirRetErrValueCode", .{}); |
| 4579 | 4609 | } |
| 4580 | 4610 | |
| 4581 | | fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4611 | fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4582 | 4612 | const tracy = trace(@src()); |
| 4583 | 4613 | defer tracy.end(); |
| 4584 | 4614 | |
| ... | ... | @@ -4587,7 +4617,7 @@ fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air |
| 4587 | 4617 | return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{}); |
| 4588 | 4618 | } |
| 4589 | 4619 | |
| 4590 | | fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4620 | fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4591 | 4621 | const tracy = trace(@src()); |
| 4592 | 4622 | defer tracy.end(); |
| 4593 | 4623 | |
| ... | ... | @@ -4599,8 +4629,8 @@ fn zirBitwise( |
| 4599 | 4629 | sema: *Sema, |
| 4600 | 4630 | block: *Scope.Block, |
| 4601 | 4631 | inst: Zir.Inst.Index, |
| 4602 | | ir_tag: ir.Inst.Tag, |
| 4603 | | ) InnerError!Air.Inst.Index { |
| 4632 | air_tag: Air.Inst.Tag, |
| 4633 | ) InnerError!Air.Inst.Ref { |
| 4604 | 4634 | const tracy = trace(@src()); |
| 4605 | 4635 | defer tracy.end(); |
| 4606 | 4636 | |
| ... | ... | @@ -4609,8 +4639,8 @@ fn zirBitwise( |
| 4609 | 4639 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 4610 | 4640 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 4611 | 4641 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 4612 | | const lhs = try sema.resolveInst(extra.lhs); |
| 4613 | | const rhs = try sema.resolveInst(extra.rhs); |
| 4642 | const lhs = sema.resolveInst(extra.lhs); |
| 4643 | const rhs = sema.resolveInst(extra.rhs); |
| 4614 | 4644 | |
| 4615 | 4645 | const instructions = &[_]Air.Inst.Index{ lhs, rhs }; |
| 4616 | 4646 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions); |
| ... | ... | @@ -4655,10 +4685,10 @@ fn zirBitwise( |
| 4655 | 4685 | } |
| 4656 | 4686 | |
| 4657 | 4687 | try sema.requireRuntimeBlock(block, src); |
| 4658 | | return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs); |
| 4688 | return block.addBinOp(src, scalar_type, air_tag, casted_lhs, casted_rhs); |
| 4659 | 4689 | } |
| 4660 | 4690 | |
| 4661 | | fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4691 | fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4662 | 4692 | const tracy = trace(@src()); |
| 4663 | 4693 | defer tracy.end(); |
| 4664 | 4694 | |
| ... | ... | @@ -4666,7 +4696,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError! |
| 4666 | 4696 | return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{}); |
| 4667 | 4697 | } |
| 4668 | 4698 | |
| 4669 | | fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4699 | fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4670 | 4700 | const tracy = trace(@src()); |
| 4671 | 4701 | defer tracy.end(); |
| 4672 | 4702 | |
| ... | ... | @@ -4674,7 +4704,7 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 4674 | 4704 | return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{}); |
| 4675 | 4705 | } |
| 4676 | 4706 | |
| 4677 | | fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4707 | fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4678 | 4708 | const tracy = trace(@src()); |
| 4679 | 4709 | defer tracy.end(); |
| 4680 | 4710 | |
| ... | ... | @@ -4687,7 +4717,7 @@ fn zirNegate( |
| 4687 | 4717 | block: *Scope.Block, |
| 4688 | 4718 | inst: Zir.Inst.Index, |
| 4689 | 4719 | tag_override: Zir.Inst.Tag, |
| 4690 | | ) InnerError!Air.Inst.Index { |
| 4720 | ) InnerError!Air.Inst.Ref { |
| 4691 | 4721 | const tracy = trace(@src()); |
| 4692 | 4722 | defer tracy.end(); |
| 4693 | 4723 | |
| ... | ... | @@ -4695,13 +4725,13 @@ fn zirNegate( |
| 4695 | 4725 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 4696 | 4726 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 4697 | 4727 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 4698 | | const lhs = try sema.resolveInst(.zero); |
| 4699 | | const rhs = try sema.resolveInst(inst_data.operand); |
| 4728 | const lhs = sema.resolveInst(.zero); |
| 4729 | const rhs = sema.resolveInst(inst_data.operand); |
| 4700 | 4730 | |
| 4701 | 4731 | return sema.analyzeArithmetic(block, tag_override, lhs, rhs, src, lhs_src, rhs_src); |
| 4702 | 4732 | } |
| 4703 | 4733 | |
| 4704 | | fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4734 | fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4705 | 4735 | const tracy = trace(@src()); |
| 4706 | 4736 | defer tracy.end(); |
| 4707 | 4737 | |
| ... | ... | @@ -4711,8 +4741,8 @@ fn zirArithmetic(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr |
| 4711 | 4741 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 4712 | 4742 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 4713 | 4743 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 4714 | | const lhs = try sema.resolveInst(extra.lhs); |
| 4715 | | const rhs = try sema.resolveInst(extra.rhs); |
| 4744 | const lhs = sema.resolveInst(extra.lhs); |
| 4745 | const rhs = sema.resolveInst(extra.rhs); |
| 4716 | 4746 | |
| 4717 | 4747 | return sema.analyzeArithmetic(block, tag_override, lhs, rhs, sema.src, lhs_src, rhs_src); |
| 4718 | 4748 | } |
| ... | ... | @@ -4721,7 +4751,7 @@ fn zirOverflowArithmetic( |
| 4721 | 4751 | sema: *Sema, |
| 4722 | 4752 | block: *Scope.Block, |
| 4723 | 4753 | extended: Zir.Inst.Extended.InstData, |
| 4724 | | ) InnerError!Air.Inst.Index { |
| 4754 | ) InnerError!Air.Inst.Ref { |
| 4725 | 4755 | const tracy = trace(@src()); |
| 4726 | 4756 | defer tracy.end(); |
| 4727 | 4757 | |
| ... | ... | @@ -4735,12 +4765,12 @@ fn analyzeArithmetic( |
| 4735 | 4765 | sema: *Sema, |
| 4736 | 4766 | block: *Scope.Block, |
| 4737 | 4767 | zir_tag: Zir.Inst.Tag, |
| 4738 | | lhs: Air.Inst.Index, |
| 4739 | | rhs: Air.Inst.Index, |
| 4768 | lhs: Air.Inst.Ref, |
| 4769 | rhs: Air.Inst.Ref, |
| 4740 | 4770 | src: LazySrcLoc, |
| 4741 | 4771 | lhs_src: LazySrcLoc, |
| 4742 | 4772 | rhs_src: LazySrcLoc, |
| 4743 | | ) InnerError!Air.Inst.Index { |
| 4773 | ) InnerError!Air.Inst.Ref { |
| 4744 | 4774 | const instructions = &[_]Air.Inst.Index{ lhs, rhs }; |
| 4745 | 4775 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions); |
| 4746 | 4776 | const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src); |
| ... | ... | @@ -4850,14 +4880,14 @@ fn analyzeArithmetic( |
| 4850 | 4880 | return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs); |
| 4851 | 4881 | } |
| 4852 | 4882 | |
| 4853 | | fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 4883 | fn zirLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 4854 | 4884 | const tracy = trace(@src()); |
| 4855 | 4885 | defer tracy.end(); |
| 4856 | 4886 | |
| 4857 | 4887 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 4858 | 4888 | const src = inst_data.src(); |
| 4859 | 4889 | const ptr_src: LazySrcLoc = .{ .node_offset_deref_ptr = inst_data.src_node }; |
| 4860 | | const ptr = try sema.resolveInst(inst_data.operand); |
| 4890 | const ptr = sema.resolveInst(inst_data.operand); |
| 4861 | 4891 | return sema.analyzeLoad(block, src, ptr, ptr_src); |
| 4862 | 4892 | } |
| 4863 | 4893 | |
| ... | ... | @@ -4865,7 +4895,7 @@ fn zirAsm( |
| 4865 | 4895 | sema: *Sema, |
| 4866 | 4896 | block: *Scope.Block, |
| 4867 | 4897 | extended: Zir.Inst.Extended.InstData, |
| 4868 | | ) InnerError!Air.Inst.Index { |
| 4898 | ) InnerError!Air.Inst.Ref { |
| 4869 | 4899 | const tracy = trace(@src()); |
| 4870 | 4900 | defer tracy.end(); |
| 4871 | 4901 | |
| ... | ... | @@ -4915,7 +4945,7 @@ fn zirAsm( |
| 4915 | 4945 | const name = sema.code.nullTerminatedString(input.data.name); |
| 4916 | 4946 | _ = name; // TODO: use the name |
| 4917 | 4947 | |
| 4918 | | arg.* = try sema.resolveInst(input.data.operand); |
| 4948 | arg.* = sema.resolveInst(input.data.operand); |
| 4919 | 4949 | inputs[arg_i] = sema.code.nullTerminatedString(input.data.constraint); |
| 4920 | 4950 | } |
| 4921 | 4951 | |
| ... | ... | @@ -4949,7 +4979,7 @@ fn zirCmp( |
| 4949 | 4979 | block: *Scope.Block, |
| 4950 | 4980 | inst: Zir.Inst.Index, |
| 4951 | 4981 | op: std.math.CompareOperator, |
| 4952 | | ) InnerError!Air.Inst.Index { |
| 4982 | ) InnerError!Air.Inst.Ref { |
| 4953 | 4983 | const tracy = trace(@src()); |
| 4954 | 4984 | defer tracy.end(); |
| 4955 | 4985 | |
| ... | ... | @@ -4960,8 +4990,8 @@ fn zirCmp( |
| 4960 | 4990 | const src: LazySrcLoc = inst_data.src(); |
| 4961 | 4991 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 4962 | 4992 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 4963 | | const lhs = try sema.resolveInst(extra.lhs); |
| 4964 | | const rhs = try sema.resolveInst(extra.rhs); |
| 4993 | const lhs = sema.resolveInst(extra.lhs); |
| 4994 | const rhs = sema.resolveInst(extra.rhs); |
| 4965 | 4995 | |
| 4966 | 4996 | const is_equality_cmp = switch (op) { |
| 4967 | 4997 | .eq, .neq => true, |
| ... | ... | @@ -5047,7 +5077,7 @@ fn zirCmp( |
| 5047 | 5077 | return block.addBinOp(src, bool_type, tag, casted_lhs, casted_rhs); |
| 5048 | 5078 | } |
| 5049 | 5079 | |
| 5050 | | fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5080 | fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5051 | 5081 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5052 | 5082 | const src = inst_data.src(); |
| 5053 | 5083 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | ... | @@ -5057,7 +5087,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError! |
| 5057 | 5087 | return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), abi_size); |
| 5058 | 5088 | } |
| 5059 | 5089 | |
| 5060 | | fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5090 | fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5061 | 5091 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5062 | 5092 | const src = inst_data.src(); |
| 5063 | 5093 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | ... | @@ -5071,7 +5101,7 @@ fn zirThis( |
| 5071 | 5101 | sema: *Sema, |
| 5072 | 5102 | block: *Scope.Block, |
| 5073 | 5103 | extended: Zir.Inst.Extended.InstData, |
| 5074 | | ) InnerError!Air.Inst.Index { |
| 5104 | ) InnerError!Air.Inst.Ref { |
| 5075 | 5105 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 5076 | 5106 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirThis", .{}); |
| 5077 | 5107 | } |
| ... | ... | @@ -5080,7 +5110,7 @@ fn zirRetAddr( |
| 5080 | 5110 | sema: *Sema, |
| 5081 | 5111 | block: *Scope.Block, |
| 5082 | 5112 | extended: Zir.Inst.Extended.InstData, |
| 5083 | | ) InnerError!Air.Inst.Index { |
| 5113 | ) InnerError!Air.Inst.Ref { |
| 5084 | 5114 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 5085 | 5115 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{}); |
| 5086 | 5116 | } |
| ... | ... | @@ -5089,12 +5119,12 @@ fn zirBuiltinSrc( |
| 5089 | 5119 | sema: *Sema, |
| 5090 | 5120 | block: *Scope.Block, |
| 5091 | 5121 | extended: Zir.Inst.Extended.InstData, |
| 5092 | | ) InnerError!Air.Inst.Index { |
| 5122 | ) InnerError!Air.Inst.Ref { |
| 5093 | 5123 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 5094 | 5124 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{}); |
| 5095 | 5125 | } |
| 5096 | 5126 | |
| 5097 | | fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5127 | fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5098 | 5128 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5099 | 5129 | const src = inst_data.src(); |
| 5100 | 5130 | const ty = try sema.resolveType(block, src, inst_data.operand); |
| ... | ... | @@ -5137,31 +5167,31 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 5137 | 5167 | } |
| 5138 | 5168 | } |
| 5139 | 5169 | |
| 5140 | | fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5170 | fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5141 | 5171 | _ = block; |
| 5142 | 5172 | const zir_datas = sema.code.instructions.items(.data); |
| 5143 | 5173 | const inst_data = zir_datas[inst].un_node; |
| 5144 | 5174 | const src = inst_data.src(); |
| 5145 | | const operand = try sema.resolveInst(inst_data.operand); |
| 5175 | const operand = sema.resolveInst(inst_data.operand); |
| 5146 | 5176 | return sema.mod.constType(sema.arena, src, operand.ty); |
| 5147 | 5177 | } |
| 5148 | 5178 | |
| 5149 | | fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5179 | fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5150 | 5180 | _ = block; |
| 5151 | 5181 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5152 | 5182 | const src = inst_data.src(); |
| 5153 | | const operand_ptr = try sema.resolveInst(inst_data.operand); |
| 5183 | const operand_ptr = sema.resolveInst(inst_data.operand); |
| 5154 | 5184 | const elem_ty = operand_ptr.ty.elemType(); |
| 5155 | 5185 | return sema.mod.constType(sema.arena, src, elem_ty); |
| 5156 | 5186 | } |
| 5157 | 5187 | |
| 5158 | | fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5188 | fn zirTypeofLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5159 | 5189 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5160 | 5190 | const src = inst_data.src(); |
| 5161 | 5191 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirTypeofLog2IntType", .{}); |
| 5162 | 5192 | } |
| 5163 | 5193 | |
| 5164 | | fn zirLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5194 | fn zirLog2IntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5165 | 5195 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5166 | 5196 | const src = inst_data.src(); |
| 5167 | 5197 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirLog2IntType", .{}); |
| ... | ... | @@ -5171,7 +5201,7 @@ fn zirTypeofPeer( |
| 5171 | 5201 | sema: *Sema, |
| 5172 | 5202 | block: *Scope.Block, |
| 5173 | 5203 | extended: Zir.Inst.Extended.InstData, |
| 5174 | | ) InnerError!Air.Inst.Index { |
| 5204 | ) InnerError!Air.Inst.Ref { |
| 5175 | 5205 | const tracy = trace(@src()); |
| 5176 | 5206 | defer tracy.end(); |
| 5177 | 5207 | |
| ... | ... | @@ -5183,20 +5213,20 @@ fn zirTypeofPeer( |
| 5183 | 5213 | defer sema.gpa.free(inst_list); |
| 5184 | 5214 | |
| 5185 | 5215 | for (args) |arg_ref, i| { |
| 5186 | | inst_list[i] = try sema.resolveInst(arg_ref); |
| 5216 | inst_list[i] = sema.resolveInst(arg_ref); |
| 5187 | 5217 | } |
| 5188 | 5218 | |
| 5189 | 5219 | const result_type = try sema.resolvePeerTypes(block, src, inst_list); |
| 5190 | 5220 | return sema.mod.constType(sema.arena, src, result_type); |
| 5191 | 5221 | } |
| 5192 | 5222 | |
| 5193 | | fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5223 | fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5194 | 5224 | const tracy = trace(@src()); |
| 5195 | 5225 | defer tracy.end(); |
| 5196 | 5226 | |
| 5197 | 5227 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5198 | 5228 | const src = inst_data.src(); |
| 5199 | | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 5229 | const uncasted_operand = sema.resolveInst(inst_data.operand); |
| 5200 | 5230 | |
| 5201 | 5231 | const bool_type = Type.initTag(.bool); |
| 5202 | 5232 | const operand = try sema.coerce(block, bool_type, uncasted_operand, uncasted_operand.src); |
| ... | ... | @@ -5212,16 +5242,16 @@ fn zirBoolOp( |
| 5212 | 5242 | block: *Scope.Block, |
| 5213 | 5243 | inst: Zir.Inst.Index, |
| 5214 | 5244 | comptime is_bool_or: bool, |
| 5215 | | ) InnerError!Air.Inst.Index { |
| 5245 | ) InnerError!Air.Inst.Ref { |
| 5216 | 5246 | const tracy = trace(@src()); |
| 5217 | 5247 | defer tracy.end(); |
| 5218 | 5248 | |
| 5219 | 5249 | const src: LazySrcLoc = .unneeded; |
| 5220 | 5250 | const bool_type = Type.initTag(.bool); |
| 5221 | 5251 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 5222 | | const uncasted_lhs = try sema.resolveInst(bin_inst.lhs); |
| 5252 | const uncasted_lhs = sema.resolveInst(bin_inst.lhs); |
| 5223 | 5253 | const lhs = try sema.coerce(block, bool_type, uncasted_lhs, uncasted_lhs.src); |
| 5224 | | const uncasted_rhs = try sema.resolveInst(bin_inst.rhs); |
| 5254 | const uncasted_rhs = sema.resolveInst(bin_inst.rhs); |
| 5225 | 5255 | const rhs = try sema.coerce(block, bool_type, uncasted_rhs, uncasted_rhs.src); |
| 5226 | 5256 | |
| 5227 | 5257 | if (lhs.value()) |lhs_val| { |
| ... | ... | @@ -5234,7 +5264,7 @@ fn zirBoolOp( |
| 5234 | 5264 | } |
| 5235 | 5265 | } |
| 5236 | 5266 | try sema.requireRuntimeBlock(block, src); |
| 5237 | | const tag: ir.Inst.Tag = if (is_bool_or) .bool_or else .bool_and; |
| 5267 | const tag: Air.Inst.Tag = if (is_bool_or) .bool_or else .bool_and; |
| 5238 | 5268 | return block.addBinOp(src, bool_type, tag, lhs, rhs); |
| 5239 | 5269 | } |
| 5240 | 5270 | |
| ... | ... | @@ -5243,14 +5273,14 @@ fn zirBoolBr( |
| 5243 | 5273 | parent_block: *Scope.Block, |
| 5244 | 5274 | inst: Zir.Inst.Index, |
| 5245 | 5275 | is_bool_or: bool, |
| 5246 | | ) InnerError!Air.Inst.Index { |
| 5276 | ) InnerError!Air.Inst.Ref { |
| 5247 | 5277 | const tracy = trace(@src()); |
| 5248 | 5278 | defer tracy.end(); |
| 5249 | 5279 | |
| 5250 | 5280 | const datas = sema.code.instructions.items(.data); |
| 5251 | 5281 | const inst_data = datas[inst].bool_br; |
| 5252 | 5282 | const src: LazySrcLoc = .unneeded; |
| 5253 | | const lhs = try sema.resolveInst(inst_data.lhs); |
| 5283 | const lhs = sema.resolveInst(inst_data.lhs); |
| 5254 | 5284 | const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index); |
| 5255 | 5285 | const body = sema.code.extra[extra.end..][0..extra.data.body_len]; |
| 5256 | 5286 | |
| ... | ... | @@ -5313,13 +5343,13 @@ fn zirIsNonNull( |
| 5313 | 5343 | sema: *Sema, |
| 5314 | 5344 | block: *Scope.Block, |
| 5315 | 5345 | inst: Zir.Inst.Index, |
| 5316 | | ) InnerError!Air.Inst.Index { |
| 5346 | ) InnerError!Air.Inst.Ref { |
| 5317 | 5347 | const tracy = trace(@src()); |
| 5318 | 5348 | defer tracy.end(); |
| 5319 | 5349 | |
| 5320 | 5350 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5321 | 5351 | const src = inst_data.src(); |
| 5322 | | const operand = try sema.resolveInst(inst_data.operand); |
| 5352 | const operand = sema.resolveInst(inst_data.operand); |
| 5323 | 5353 | return sema.analyzeIsNull(block, src, operand, true); |
| 5324 | 5354 | } |
| 5325 | 5355 | |
| ... | ... | @@ -5327,33 +5357,33 @@ fn zirIsNonNullPtr( |
| 5327 | 5357 | sema: *Sema, |
| 5328 | 5358 | block: *Scope.Block, |
| 5329 | 5359 | inst: Zir.Inst.Index, |
| 5330 | | ) InnerError!Air.Inst.Index { |
| 5360 | ) InnerError!Air.Inst.Ref { |
| 5331 | 5361 | const tracy = trace(@src()); |
| 5332 | 5362 | defer tracy.end(); |
| 5333 | 5363 | |
| 5334 | 5364 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5335 | 5365 | const src = inst_data.src(); |
| 5336 | | const ptr = try sema.resolveInst(inst_data.operand); |
| 5366 | const ptr = sema.resolveInst(inst_data.operand); |
| 5337 | 5367 | const loaded = try sema.analyzeLoad(block, src, ptr, src); |
| 5338 | 5368 | return sema.analyzeIsNull(block, src, loaded, true); |
| 5339 | 5369 | } |
| 5340 | 5370 | |
| 5341 | | fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5371 | fn zirIsNonErr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5342 | 5372 | const tracy = trace(@src()); |
| 5343 | 5373 | defer tracy.end(); |
| 5344 | 5374 | |
| 5345 | 5375 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5346 | | const operand = try sema.resolveInst(inst_data.operand); |
| 5376 | const operand = sema.resolveInst(inst_data.operand); |
| 5347 | 5377 | return sema.analyzeIsNonErr(block, inst_data.src(), operand); |
| 5348 | 5378 | } |
| 5349 | 5379 | |
| 5350 | | fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5380 | fn zirIsNonErrPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5351 | 5381 | const tracy = trace(@src()); |
| 5352 | 5382 | defer tracy.end(); |
| 5353 | 5383 | |
| 5354 | 5384 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5355 | 5385 | const src = inst_data.src(); |
| 5356 | | const ptr = try sema.resolveInst(inst_data.operand); |
| 5386 | const ptr = sema.resolveInst(inst_data.operand); |
| 5357 | 5387 | const loaded = try sema.analyzeLoad(block, src, ptr, src); |
| 5358 | 5388 | return sema.analyzeIsNonErr(block, src, loaded); |
| 5359 | 5389 | } |
| ... | ... | @@ -5374,7 +5404,7 @@ fn zirCondbr( |
| 5374 | 5404 | const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len]; |
| 5375 | 5405 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; |
| 5376 | 5406 | |
| 5377 | | const uncasted_cond = try sema.resolveInst(extra.data.condition); |
| 5407 | const uncasted_cond = sema.resolveInst(extra.data.condition); |
| 5378 | 5408 | const cond = try sema.coerce(parent_block, Type.initTag(.bool), uncasted_cond, cond_src); |
| 5379 | 5409 | |
| 5380 | 5410 | if (try sema.resolveDefinedValue(parent_block, src, cond)) |cond_val| { |
| ... | ... | @@ -5456,7 +5486,7 @@ fn zirRetCoerce( |
| 5456 | 5486 | defer tracy.end(); |
| 5457 | 5487 | |
| 5458 | 5488 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 5459 | | const operand = try sema.resolveInst(inst_data.operand); |
| 5489 | const operand = sema.resolveInst(inst_data.operand); |
| 5460 | 5490 | const src = inst_data.src(); |
| 5461 | 5491 | |
| 5462 | 5492 | return sema.analyzeRet(block, operand, src, need_coercion); |
| ... | ... | @@ -5467,7 +5497,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 5467 | 5497 | defer tracy.end(); |
| 5468 | 5498 | |
| 5469 | 5499 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5470 | | const operand = try sema.resolveInst(inst_data.operand); |
| 5500 | const operand = sema.resolveInst(inst_data.operand); |
| 5471 | 5501 | const src = inst_data.src(); |
| 5472 | 5502 | |
| 5473 | 5503 | return sema.analyzeRet(block, operand, src, false); |
| ... | ... | @@ -5476,7 +5506,7 @@ fn zirRetNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 5476 | 5506 | fn analyzeRet( |
| 5477 | 5507 | sema: *Sema, |
| 5478 | 5508 | block: *Scope.Block, |
| 5479 | | operand: Air.Inst.Index, |
| 5509 | operand: Air.Inst.Ref, |
| 5480 | 5510 | src: LazySrcLoc, |
| 5481 | 5511 | need_coercion: bool, |
| 5482 | 5512 | ) InnerError!Zir.Inst.Index { |
| ... | ... | @@ -5511,7 +5541,7 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool { |
| 5511 | 5541 | }; |
| 5512 | 5542 | } |
| 5513 | 5543 | |
| 5514 | | fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5544 | fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5515 | 5545 | const tracy = trace(@src()); |
| 5516 | 5546 | defer tracy.end(); |
| 5517 | 5547 | |
| ... | ... | @@ -5532,7 +5562,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inne |
| 5532 | 5562 | return sema.mod.constType(sema.arena, .unneeded, ty); |
| 5533 | 5563 | } |
| 5534 | 5564 | |
| 5535 | | fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5565 | fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5536 | 5566 | const tracy = trace(@src()); |
| 5537 | 5567 | defer tracy.end(); |
| 5538 | 5568 | |
| ... | ... | @@ -5586,7 +5616,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 5586 | 5616 | return sema.mod.constType(sema.arena, src, ty); |
| 5587 | 5617 | } |
| 5588 | 5618 | |
| 5589 | | fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5619 | fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5590 | 5620 | const tracy = trace(@src()); |
| 5591 | 5621 | defer tracy.end(); |
| 5592 | 5622 | |
| ... | ... | @@ -5600,13 +5630,13 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In |
| 5600 | 5630 | }); |
| 5601 | 5631 | } |
| 5602 | 5632 | |
| 5603 | | fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5633 | fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5604 | 5634 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5605 | 5635 | const src = inst_data.src(); |
| 5606 | 5636 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnionInitPtr", .{}); |
| 5607 | 5637 | } |
| 5608 | 5638 | |
| 5609 | | fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index { |
| 5639 | fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Ref { |
| 5610 | 5640 | const mod = sema.mod; |
| 5611 | 5641 | const gpa = sema.gpa; |
| 5612 | 5642 | const zir_datas = sema.code.instructions.items(.data); |
| ... | ... | @@ -5657,7 +5687,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 5657 | 5687 | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 5658 | 5688 | } |
| 5659 | 5689 | found_fields[field_index] = item.data.field_type; |
| 5660 | | field_inits[field_index] = try sema.resolveInst(item.data.init); |
| 5690 | field_inits[field_index] = sema.resolveInst(item.data.init); |
| 5661 | 5691 | } |
| 5662 | 5692 | |
| 5663 | 5693 | var root_msg: ?*Module.ErrorMsg = null; |
| ... | ... | @@ -5719,7 +5749,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 5719 | 5749 | return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{}); |
| 5720 | 5750 | } |
| 5721 | 5751 | |
| 5722 | | fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index { |
| 5752 | fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Ref { |
| 5723 | 5753 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5724 | 5754 | const src = inst_data.src(); |
| 5725 | 5755 | |
| ... | ... | @@ -5727,7 +5757,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ |
| 5727 | 5757 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{}); |
| 5728 | 5758 | } |
| 5729 | 5759 | |
| 5730 | | fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index { |
| 5760 | fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Ref { |
| 5731 | 5761 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5732 | 5762 | const src = inst_data.src(); |
| 5733 | 5763 | |
| ... | ... | @@ -5735,7 +5765,7 @@ fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 5735 | 5765 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{}); |
| 5736 | 5766 | } |
| 5737 | 5767 | |
| 5738 | | fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Index { |
| 5768 | fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!Air.Inst.Ref { |
| 5739 | 5769 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5740 | 5770 | const src = inst_data.src(); |
| 5741 | 5771 | |
| ... | ... | @@ -5743,13 +5773,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r |
| 5743 | 5773 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{}); |
| 5744 | 5774 | } |
| 5745 | 5775 | |
| 5746 | | fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5776 | fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5747 | 5777 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5748 | 5778 | const src = inst_data.src(); |
| 5749 | 5779 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldTypeRef", .{}); |
| 5750 | 5780 | } |
| 5751 | 5781 | |
| 5752 | | fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5782 | fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5753 | 5783 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5754 | 5784 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 5755 | 5785 | const src = inst_data.src(); |
| ... | ... | @@ -5771,7 +5801,7 @@ fn zirErrorReturnTrace( |
| 5771 | 5801 | sema: *Sema, |
| 5772 | 5802 | block: *Scope.Block, |
| 5773 | 5803 | extended: Zir.Inst.Extended.InstData, |
| 5774 | | ) InnerError!Air.Inst.Index { |
| 5804 | ) InnerError!Air.Inst.Ref { |
| 5775 | 5805 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 5776 | 5806 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{}); |
| 5777 | 5807 | } |
| ... | ... | @@ -5780,7 +5810,7 @@ fn zirFrame( |
| 5780 | 5810 | sema: *Sema, |
| 5781 | 5811 | block: *Scope.Block, |
| 5782 | 5812 | extended: Zir.Inst.Extended.InstData, |
| 5783 | | ) InnerError!Air.Inst.Index { |
| 5813 | ) InnerError!Air.Inst.Ref { |
| 5784 | 5814 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 5785 | 5815 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{}); |
| 5786 | 5816 | } |
| ... | ... | @@ -5789,91 +5819,91 @@ fn zirFrameAddress( |
| 5789 | 5819 | sema: *Sema, |
| 5790 | 5820 | block: *Scope.Block, |
| 5791 | 5821 | extended: Zir.Inst.Extended.InstData, |
| 5792 | | ) InnerError!Air.Inst.Index { |
| 5822 | ) InnerError!Air.Inst.Ref { |
| 5793 | 5823 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 5794 | 5824 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{}); |
| 5795 | 5825 | } |
| 5796 | 5826 | |
| 5797 | | fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5827 | fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5798 | 5828 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5799 | 5829 | const src = inst_data.src(); |
| 5800 | 5830 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignOf", .{}); |
| 5801 | 5831 | } |
| 5802 | 5832 | |
| 5803 | | fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5833 | fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5804 | 5834 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5805 | 5835 | const src = inst_data.src(); |
| 5806 | 5836 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBoolToInt", .{}); |
| 5807 | 5837 | } |
| 5808 | 5838 | |
| 5809 | | fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5839 | fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5810 | 5840 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5811 | 5841 | const src = inst_data.src(); |
| 5812 | 5842 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirEmbedFile", .{}); |
| 5813 | 5843 | } |
| 5814 | 5844 | |
| 5815 | | fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5845 | fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5816 | 5846 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5817 | 5847 | const src = inst_data.src(); |
| 5818 | 5848 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorName", .{}); |
| 5819 | 5849 | } |
| 5820 | 5850 | |
| 5821 | | fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5851 | fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5822 | 5852 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5823 | 5853 | const src = inst_data.src(); |
| 5824 | 5854 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnaryMath", .{}); |
| 5825 | 5855 | } |
| 5826 | 5856 | |
| 5827 | | fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5857 | fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5828 | 5858 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5829 | 5859 | const src = inst_data.src(); |
| 5830 | 5860 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirTagName", .{}); |
| 5831 | 5861 | } |
| 5832 | 5862 | |
| 5833 | | fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5863 | fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5834 | 5864 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5835 | 5865 | const src = inst_data.src(); |
| 5836 | 5866 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify", .{}); |
| 5837 | 5867 | } |
| 5838 | 5868 | |
| 5839 | | fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5869 | fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5840 | 5870 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5841 | 5871 | const src = inst_data.src(); |
| 5842 | 5872 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirTypeName", .{}); |
| 5843 | 5873 | } |
| 5844 | 5874 | |
| 5845 | | fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5875 | fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5846 | 5876 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5847 | 5877 | const src = inst_data.src(); |
| 5848 | 5878 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameType", .{}); |
| 5849 | 5879 | } |
| 5850 | 5880 | |
| 5851 | | fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5881 | fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5852 | 5882 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5853 | 5883 | const src = inst_data.src(); |
| 5854 | 5884 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameSize", .{}); |
| 5855 | 5885 | } |
| 5856 | 5886 | |
| 5857 | | fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5887 | fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5858 | 5888 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5859 | 5889 | const src = inst_data.src(); |
| 5860 | 5890 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFloatToInt", .{}); |
| 5861 | 5891 | } |
| 5862 | 5892 | |
| 5863 | | fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5893 | fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5864 | 5894 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5865 | 5895 | const src = inst_data.src(); |
| 5866 | 5896 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirIntToFloat", .{}); |
| 5867 | 5897 | } |
| 5868 | 5898 | |
| 5869 | | fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5899 | fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5870 | 5900 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5871 | 5901 | const src = inst_data.src(); |
| 5872 | 5902 | |
| 5873 | 5903 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 5874 | 5904 | |
| 5875 | 5905 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 5876 | | const operand_res = try sema.resolveInst(extra.rhs); |
| 5906 | const operand_res = sema.resolveInst(extra.rhs); |
| 5877 | 5907 | const operand_coerced = try sema.coerce(block, Type.initTag(.usize), operand_res, operand_src); |
| 5878 | 5908 | |
| 5879 | 5909 | const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | ... | @@ -5929,199 +5959,199 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro |
| 5929 | 5959 | return block.addUnOp(src, type_res, .bitcast, operand_coerced); |
| 5930 | 5960 | } |
| 5931 | 5961 | |
| 5932 | | fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5962 | fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5933 | 5963 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5934 | 5964 | const src = inst_data.src(); |
| 5935 | 5965 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrSetCast", .{}); |
| 5936 | 5966 | } |
| 5937 | 5967 | |
| 5938 | | fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5968 | fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5939 | 5969 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5940 | 5970 | const src = inst_data.src(); |
| 5941 | 5971 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirPtrCast", .{}); |
| 5942 | 5972 | } |
| 5943 | 5973 | |
| 5944 | | fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5974 | fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5945 | 5975 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5946 | 5976 | const src = inst_data.src(); |
| 5947 | 5977 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirTruncate", .{}); |
| 5948 | 5978 | } |
| 5949 | 5979 | |
| 5950 | | fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5980 | fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5951 | 5981 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5952 | 5982 | const src = inst_data.src(); |
| 5953 | 5983 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignCast", .{}); |
| 5954 | 5984 | } |
| 5955 | 5985 | |
| 5956 | | fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5986 | fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5957 | 5987 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5958 | 5988 | const src = inst_data.src(); |
| 5959 | 5989 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirClz", .{}); |
| 5960 | 5990 | } |
| 5961 | 5991 | |
| 5962 | | fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5992 | fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5963 | 5993 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5964 | 5994 | const src = inst_data.src(); |
| 5965 | 5995 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirCtz", .{}); |
| 5966 | 5996 | } |
| 5967 | 5997 | |
| 5968 | | fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 5998 | fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5969 | 5999 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5970 | 6000 | const src = inst_data.src(); |
| 5971 | 6001 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirPopCount", .{}); |
| 5972 | 6002 | } |
| 5973 | 6003 | |
| 5974 | | fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6004 | fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5975 | 6005 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5976 | 6006 | const src = inst_data.src(); |
| 5977 | 6007 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteSwap", .{}); |
| 5978 | 6008 | } |
| 5979 | 6009 | |
| 5980 | | fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6010 | fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5981 | 6011 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5982 | 6012 | const src = inst_data.src(); |
| 5983 | 6013 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitReverse", .{}); |
| 5984 | 6014 | } |
| 5985 | 6015 | |
| 5986 | | fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6016 | fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5987 | 6017 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5988 | 6018 | const src = inst_data.src(); |
| 5989 | 6019 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivExact", .{}); |
| 5990 | 6020 | } |
| 5991 | 6021 | |
| 5992 | | fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6022 | fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5993 | 6023 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 5994 | 6024 | const src = inst_data.src(); |
| 5995 | 6025 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivFloor", .{}); |
| 5996 | 6026 | } |
| 5997 | 6027 | |
| 5998 | | fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6028 | fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 5999 | 6029 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6000 | 6030 | const src = inst_data.src(); |
| 6001 | 6031 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivTrunc", .{}); |
| 6002 | 6032 | } |
| 6003 | 6033 | |
| 6004 | | fn zirMod(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6034 | fn zirMod(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6005 | 6035 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6006 | 6036 | const src = inst_data.src(); |
| 6007 | 6037 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMod", .{}); |
| 6008 | 6038 | } |
| 6009 | 6039 | |
| 6010 | | fn zirRem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6040 | fn zirRem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6011 | 6041 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6012 | 6042 | const src = inst_data.src(); |
| 6013 | 6043 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirRem", .{}); |
| 6014 | 6044 | } |
| 6015 | 6045 | |
| 6016 | | fn zirShlExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6046 | fn zirShlExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6017 | 6047 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6018 | 6048 | const src = inst_data.src(); |
| 6019 | 6049 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirShlExact", .{}); |
| 6020 | 6050 | } |
| 6021 | 6051 | |
| 6022 | | fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6052 | fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6023 | 6053 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6024 | 6054 | const src = inst_data.src(); |
| 6025 | 6055 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirShrExact", .{}); |
| 6026 | 6056 | } |
| 6027 | 6057 | |
| 6028 | | fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6058 | fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6029 | 6059 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6030 | 6060 | const src = inst_data.src(); |
| 6031 | 6061 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{}); |
| 6032 | 6062 | } |
| 6033 | 6063 | |
| 6034 | | fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6064 | fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6035 | 6065 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6036 | 6066 | const src = inst_data.src(); |
| 6037 | 6067 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{}); |
| 6038 | 6068 | } |
| 6039 | 6069 | |
| 6040 | | fn zirCmpxchg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6070 | fn zirCmpxchg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6041 | 6071 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6042 | 6072 | const src = inst_data.src(); |
| 6043 | 6073 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirCmpxchg", .{}); |
| 6044 | 6074 | } |
| 6045 | 6075 | |
| 6046 | | fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6076 | fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6047 | 6077 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6048 | 6078 | const src = inst_data.src(); |
| 6049 | 6079 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirSplat", .{}); |
| 6050 | 6080 | } |
| 6051 | 6081 | |
| 6052 | | fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6082 | fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6053 | 6083 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6054 | 6084 | const src = inst_data.src(); |
| 6055 | 6085 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirReduce", .{}); |
| 6056 | 6086 | } |
| 6057 | 6087 | |
| 6058 | | fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6088 | fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6059 | 6089 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6060 | 6090 | const src = inst_data.src(); |
| 6061 | 6091 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirShuffle", .{}); |
| 6062 | 6092 | } |
| 6063 | 6093 | |
| 6064 | | fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6094 | fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6065 | 6095 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6066 | 6096 | const src = inst_data.src(); |
| 6067 | 6097 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicLoad", .{}); |
| 6068 | 6098 | } |
| 6069 | 6099 | |
| 6070 | | fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6100 | fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6071 | 6101 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6072 | 6102 | const src = inst_data.src(); |
| 6073 | 6103 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicRmw", .{}); |
| 6074 | 6104 | } |
| 6075 | 6105 | |
| 6076 | | fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6106 | fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6077 | 6107 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6078 | 6108 | const src = inst_data.src(); |
| 6079 | 6109 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirAtomicStore", .{}); |
| 6080 | 6110 | } |
| 6081 | 6111 | |
| 6082 | | fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6112 | fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6083 | 6113 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6084 | 6114 | const src = inst_data.src(); |
| 6085 | 6115 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMulAdd", .{}); |
| 6086 | 6116 | } |
| 6087 | 6117 | |
| 6088 | | fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6118 | fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6089 | 6119 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6090 | 6120 | const src = inst_data.src(); |
| 6091 | 6121 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinCall", .{}); |
| 6092 | 6122 | } |
| 6093 | 6123 | |
| 6094 | | fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6124 | fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6095 | 6125 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6096 | 6126 | const src = inst_data.src(); |
| 6097 | 6127 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldPtrType", .{}); |
| 6098 | 6128 | } |
| 6099 | 6129 | |
| 6100 | | fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6130 | fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6101 | 6131 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6102 | 6132 | const src = inst_data.src(); |
| 6103 | 6133 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldParentPtr", .{}); |
| 6104 | 6134 | } |
| 6105 | 6135 | |
| 6106 | | fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6136 | fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6107 | 6137 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6108 | 6138 | const src = inst_data.src(); |
| 6109 | 6139 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemcpy", .{}); |
| 6110 | 6140 | } |
| 6111 | 6141 | |
| 6112 | | fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6142 | fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6113 | 6143 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6114 | 6144 | const src = inst_data.src(); |
| 6115 | 6145 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemset", .{}); |
| 6116 | 6146 | } |
| 6117 | 6147 | |
| 6118 | | fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6148 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6119 | 6149 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 6120 | 6150 | const src = inst_data.src(); |
| 6121 | 6151 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{}); |
| 6122 | 6152 | } |
| 6123 | 6153 | |
| 6124 | | fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Index { |
| 6154 | fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!Air.Inst.Ref { |
| 6125 | 6155 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 6126 | 6156 | const src = inst_data.src(); |
| 6127 | 6157 | return sema.mod.fail(&block.base, src, "TODO: Sema.zirResume", .{}); |
| ... | ... | @@ -6132,7 +6162,7 @@ fn zirAwait( |
| 6132 | 6162 | block: *Scope.Block, |
| 6133 | 6163 | inst: Zir.Inst.Index, |
| 6134 | 6164 | is_nosuspend: bool, |
| 6135 | | ) InnerError!Air.Inst.Index { |
| 6165 | ) InnerError!Air.Inst.Ref { |
| 6136 | 6166 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 6137 | 6167 | const src = inst_data.src(); |
| 6138 | 6168 | |
| ... | ... | @@ -6144,7 +6174,7 @@ fn zirVarExtended( |
| 6144 | 6174 | sema: *Sema, |
| 6145 | 6175 | block: *Scope.Block, |
| 6146 | 6176 | extended: Zir.Inst.Extended.InstData, |
| 6147 | | ) InnerError!Air.Inst.Index { |
| 6177 | ) InnerError!Air.Inst.Ref { |
| 6148 | 6178 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); |
| 6149 | 6179 | const src = sema.src; |
| 6150 | 6180 | const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type |
| ... | ... | @@ -6210,7 +6240,7 @@ fn zirFuncExtended( |
| 6210 | 6240 | block: *Scope.Block, |
| 6211 | 6241 | extended: Zir.Inst.Extended.InstData, |
| 6212 | 6242 | inst: Zir.Inst.Index, |
| 6213 | | ) InnerError!Air.Inst.Index { |
| 6243 | ) InnerError!Air.Inst.Ref { |
| 6214 | 6244 | const tracy = trace(@src()); |
| 6215 | 6245 | defer tracy.end(); |
| 6216 | 6246 | |
| ... | ... | @@ -6277,7 +6307,7 @@ fn zirCUndef( |
| 6277 | 6307 | sema: *Sema, |
| 6278 | 6308 | block: *Scope.Block, |
| 6279 | 6309 | extended: Zir.Inst.Extended.InstData, |
| 6280 | | ) InnerError!Air.Inst.Index { |
| 6310 | ) InnerError!Air.Inst.Ref { |
| 6281 | 6311 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6282 | 6312 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 6283 | 6313 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCUndef", .{}); |
| ... | ... | @@ -6287,7 +6317,7 @@ fn zirCInclude( |
| 6287 | 6317 | sema: *Sema, |
| 6288 | 6318 | block: *Scope.Block, |
| 6289 | 6319 | extended: Zir.Inst.Extended.InstData, |
| 6290 | | ) InnerError!Air.Inst.Index { |
| 6320 | ) InnerError!Air.Inst.Ref { |
| 6291 | 6321 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6292 | 6322 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 6293 | 6323 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCInclude", .{}); |
| ... | ... | @@ -6297,7 +6327,7 @@ fn zirCDefine( |
| 6297 | 6327 | sema: *Sema, |
| 6298 | 6328 | block: *Scope.Block, |
| 6299 | 6329 | extended: Zir.Inst.Extended.InstData, |
| 6300 | | ) InnerError!Air.Inst.Index { |
| 6330 | ) InnerError!Air.Inst.Ref { |
| 6301 | 6331 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 6302 | 6332 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 6303 | 6333 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirCDefine", .{}); |
| ... | ... | @@ -6307,7 +6337,7 @@ fn zirWasmMemorySize( |
| 6307 | 6337 | sema: *Sema, |
| 6308 | 6338 | block: *Scope.Block, |
| 6309 | 6339 | extended: Zir.Inst.Extended.InstData, |
| 6310 | | ) InnerError!Air.Inst.Index { |
| 6340 | ) InnerError!Air.Inst.Ref { |
| 6311 | 6341 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6312 | 6342 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 6313 | 6343 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemorySize", .{}); |
| ... | ... | @@ -6317,7 +6347,7 @@ fn zirWasmMemoryGrow( |
| 6317 | 6347 | sema: *Sema, |
| 6318 | 6348 | block: *Scope.Block, |
| 6319 | 6349 | extended: Zir.Inst.Extended.InstData, |
| 6320 | | ) InnerError!Air.Inst.Index { |
| 6350 | ) InnerError!Air.Inst.Ref { |
| 6321 | 6351 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 6322 | 6352 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 6323 | 6353 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{}); |
| ... | ... | @@ -6327,7 +6357,7 @@ fn zirBuiltinExtern( |
| 6327 | 6357 | sema: *Sema, |
| 6328 | 6358 | block: *Scope.Block, |
| 6329 | 6359 | extended: Zir.Inst.Extended.InstData, |
| 6330 | | ) InnerError!Air.Inst.Index { |
| 6360 | ) InnerError!Air.Inst.Ref { |
| 6331 | 6361 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 6332 | 6362 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 6333 | 6363 | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{}); |
| ... | ... | @@ -6361,7 +6391,7 @@ pub const PanicId = enum { |
| 6361 | 6391 | invalid_error_code, |
| 6362 | 6392 | }; |
| 6363 | 6393 | |
| 6364 | | fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: Air.Inst.Index, panic_id: PanicId) !void { |
| 6394 | fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: Air.Inst.Ref, panic_id: PanicId) !void { |
| 6365 | 6395 | const block_inst = try sema.arena.create(Inst.Block); |
| 6366 | 6396 | block_inst.* = .{ |
| 6367 | 6397 | .base = .{ |
| ... | ... | @@ -6423,7 +6453,7 @@ fn panicWithMsg( |
| 6423 | 6453 | sema: *Sema, |
| 6424 | 6454 | block: *Scope.Block, |
| 6425 | 6455 | src: LazySrcLoc, |
| 6426 | | msg_inst: Air.Inst.Index, |
| 6456 | msg_inst: Air.Inst.Ref, |
| 6427 | 6457 | ) !Zir.Inst.Index { |
| 6428 | 6458 | const mod = sema.mod; |
| 6429 | 6459 | const arena = sema.arena; |
| ... | ... | @@ -6439,7 +6469,7 @@ fn panicWithMsg( |
| 6439 | 6469 | const panic_fn = try sema.getBuiltin(block, src, "panic"); |
| 6440 | 6470 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); |
| 6441 | 6471 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 6442 | | const ptr_stack_trace_ty = try mod.simplePtrType(arena, stack_trace_ty, true, .One); |
| 6472 | const ptr_stack_trace_ty = try Module.simplePtrType(arena, stack_trace_ty, true, .One); |
| 6443 | 6473 | const null_stack_trace = try mod.constInst(arena, src, .{ |
| 6444 | 6474 | .ty = try mod.optionalType(arena, ptr_stack_trace_ty), |
| 6445 | 6475 | .val = Value.initTag(.null_value), |
| ... | ... | @@ -6500,10 +6530,10 @@ fn namedFieldPtr( |
| 6500 | 6530 | sema: *Sema, |
| 6501 | 6531 | block: *Scope.Block, |
| 6502 | 6532 | src: LazySrcLoc, |
| 6503 | | object_ptr: Air.Inst.Index, |
| 6533 | object_ptr: Air.Inst.Ref, |
| 6504 | 6534 | field_name: []const u8, |
| 6505 | 6535 | field_name_src: LazySrcLoc, |
| 6506 | | ) InnerError!Air.Inst.Index { |
| 6536 | ) InnerError!Air.Inst.Ref { |
| 6507 | 6537 | const mod = sema.mod; |
| 6508 | 6538 | const arena = sema.arena; |
| 6509 | 6539 | |
| ... | ... | @@ -6579,7 +6609,7 @@ fn namedFieldPtr( |
| 6579 | 6609 | } else (try mod.getErrorValue(field_name)).key; |
| 6580 | 6610 | |
| 6581 | 6611 | return mod.constInst(arena, src, .{ |
| 6582 | | .ty = try mod.simplePtrType(arena, child_type, false, .One), |
| 6612 | .ty = try Module.simplePtrType(arena, child_type, false, .One), |
| 6583 | 6613 | .val = try Value.Tag.ref_val.create( |
| 6584 | 6614 | arena, |
| 6585 | 6615 | try Value.Tag.@"error".create(arena, .{ |
| ... | ... | @@ -6633,7 +6663,7 @@ fn namedFieldPtr( |
| 6633 | 6663 | const field_index_u32 = @intCast(u32, field_index); |
| 6634 | 6664 | const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32); |
| 6635 | 6665 | return mod.constInst(arena, src, .{ |
| 6636 | | .ty = try mod.simplePtrType(arena, child_type, false, .One), |
| 6666 | .ty = try Module.simplePtrType(arena, child_type, false, .One), |
| 6637 | 6667 | .val = try Value.Tag.ref_val.create(arena, enum_val), |
| 6638 | 6668 | }); |
| 6639 | 6669 | }, |
| ... | ... | @@ -6653,7 +6683,7 @@ fn analyzeNamespaceLookup( |
| 6653 | 6683 | src: LazySrcLoc, |
| 6654 | 6684 | namespace: *Scope.Namespace, |
| 6655 | 6685 | decl_name: []const u8, |
| 6656 | | ) InnerError!?Air.Inst.Index { |
| 6686 | ) InnerError!?Air.Inst.Ref { |
| 6657 | 6687 | const mod = sema.mod; |
| 6658 | 6688 | const gpa = sema.gpa; |
| 6659 | 6689 | if (try sema.lookupInNamespace(namespace, decl_name)) |decl| { |
| ... | ... | @@ -6677,11 +6707,11 @@ fn analyzeStructFieldPtr( |
| 6677 | 6707 | sema: *Sema, |
| 6678 | 6708 | block: *Scope.Block, |
| 6679 | 6709 | src: LazySrcLoc, |
| 6680 | | struct_ptr: Air.Inst.Index, |
| 6710 | struct_ptr: Air.Inst.Ref, |
| 6681 | 6711 | field_name: []const u8, |
| 6682 | 6712 | field_name_src: LazySrcLoc, |
| 6683 | 6713 | unresolved_struct_ty: Type, |
| 6684 | | ) InnerError!Air.Inst.Index { |
| 6714 | ) InnerError!Air.Inst.Ref { |
| 6685 | 6715 | const mod = sema.mod; |
| 6686 | 6716 | const arena = sema.arena; |
| 6687 | 6717 | assert(unresolved_struct_ty.zigTypeTag() == .Struct); |
| ... | ... | @@ -6692,7 +6722,7 @@ fn analyzeStructFieldPtr( |
| 6692 | 6722 | const field_index = struct_obj.fields.getIndex(field_name) orelse |
| 6693 | 6723 | return sema.failWithBadFieldAccess(block, struct_obj, field_name_src, field_name); |
| 6694 | 6724 | const field = struct_obj.fields.values()[field_index]; |
| 6695 | | const ptr_field_ty = try mod.simplePtrType(arena, field.ty, true, .One); |
| 6725 | const ptr_field_ty = try Module.simplePtrType(arena, field.ty, true, .One); |
| 6696 | 6726 | |
| 6697 | 6727 | if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| { |
| 6698 | 6728 | return mod.constInst(arena, src, .{ |
| ... | ... | @@ -6712,11 +6742,11 @@ fn analyzeUnionFieldPtr( |
| 6712 | 6742 | sema: *Sema, |
| 6713 | 6743 | block: *Scope.Block, |
| 6714 | 6744 | src: LazySrcLoc, |
| 6715 | | union_ptr: Air.Inst.Index, |
| 6745 | union_ptr: Air.Inst.Ref, |
| 6716 | 6746 | field_name: []const u8, |
| 6717 | 6747 | field_name_src: LazySrcLoc, |
| 6718 | 6748 | unresolved_union_ty: Type, |
| 6719 | | ) InnerError!Air.Inst.Index { |
| 6749 | ) InnerError!Air.Inst.Ref { |
| 6720 | 6750 | const mod = sema.mod; |
| 6721 | 6751 | const arena = sema.arena; |
| 6722 | 6752 | assert(unresolved_union_ty.zigTypeTag() == .Union); |
| ... | ... | @@ -6728,7 +6758,7 @@ fn analyzeUnionFieldPtr( |
| 6728 | 6758 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_name_src, field_name); |
| 6729 | 6759 | |
| 6730 | 6760 | const field = union_obj.fields.values()[field_index]; |
| 6731 | | const ptr_field_ty = try mod.simplePtrType(arena, field.ty, true, .One); |
| 6761 | const ptr_field_ty = try Module.simplePtrType(arena, field.ty, true, .One); |
| 6732 | 6762 | |
| 6733 | 6763 | if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| { |
| 6734 | 6764 | // TODO detect inactive union field and emit compile error |
| ... | ... | @@ -6749,10 +6779,10 @@ fn elemPtr( |
| 6749 | 6779 | sema: *Sema, |
| 6750 | 6780 | block: *Scope.Block, |
| 6751 | 6781 | src: LazySrcLoc, |
| 6752 | | array_ptr: Air.Inst.Index, |
| 6753 | | elem_index: Air.Inst.Index, |
| 6782 | array_ptr: Air.Inst.Ref, |
| 6783 | elem_index: Air.Inst.Ref, |
| 6754 | 6784 | elem_index_src: LazySrcLoc, |
| 6755 | | ) InnerError!Air.Inst.Index { |
| 6785 | ) InnerError!Air.Inst.Ref { |
| 6756 | 6786 | const array_ty = switch (array_ptr.ty.zigTypeTag()) { |
| 6757 | 6787 | .Pointer => array_ptr.ty.elemType(), |
| 6758 | 6788 | else => return sema.mod.fail(&block.base, array_ptr.src, "expected pointer, found '{}'", .{array_ptr.ty}), |
| ... | ... | @@ -6776,10 +6806,10 @@ fn elemPtrArray( |
| 6776 | 6806 | sema: *Sema, |
| 6777 | 6807 | block: *Scope.Block, |
| 6778 | 6808 | src: LazySrcLoc, |
| 6779 | | array_ptr: Air.Inst.Index, |
| 6780 | | elem_index: Air.Inst.Index, |
| 6809 | array_ptr: Air.Inst.Ref, |
| 6810 | elem_index: Air.Inst.Ref, |
| 6781 | 6811 | elem_index_src: LazySrcLoc, |
| 6782 | | ) InnerError!Air.Inst.Index { |
| 6812 | ) InnerError!Air.Inst.Ref { |
| 6783 | 6813 | if (array_ptr.value()) |array_ptr_val| { |
| 6784 | 6814 | if (elem_index.value()) |index_val| { |
| 6785 | 6815 | // Both array pointer and index are compile-time known. |
| ... | ... | @@ -6804,35 +6834,41 @@ fn coerce( |
| 6804 | 6834 | sema: *Sema, |
| 6805 | 6835 | block: *Scope.Block, |
| 6806 | 6836 | dest_type: Type, |
| 6807 | | inst: Air.Inst.Index, |
| 6837 | inst: Air.Inst.Ref, |
| 6808 | 6838 | inst_src: LazySrcLoc, |
| 6809 | | ) InnerError!Air.Inst.Index { |
| 6839 | ) InnerError!Air.Inst.Ref { |
| 6810 | 6840 | if (dest_type.tag() == .var_args_param) { |
| 6811 | | return sema.coerceVarArgParam(block, inst); |
| 6841 | return sema.coerceVarArgParam(block, inst, inst_src); |
| 6812 | 6842 | } |
| 6843 | |
| 6844 | const inst_ty = sema.getTypeOfAirRef(inst); |
| 6813 | 6845 | // If the types are the same, we can return the operand. |
| 6814 | | if (dest_type.eql(inst.ty)) |
| 6846 | if (dest_type.eql(inst_ty)) |
| 6815 | 6847 | return inst; |
| 6816 | 6848 | |
| 6817 | | const in_memory_result = coerceInMemoryAllowed(dest_type, inst.ty); |
| 6849 | const in_memory_result = coerceInMemoryAllowed(dest_type, inst_ty); |
| 6818 | 6850 | if (in_memory_result == .ok) { |
| 6819 | | return sema.bitcast(block, dest_type, inst); |
| 6851 | return sema.bitcast(block, dest_type, inst, inst_src); |
| 6820 | 6852 | } |
| 6821 | 6853 | |
| 6822 | 6854 | const mod = sema.mod; |
| 6823 | 6855 | const arena = sema.arena; |
| 6824 | 6856 | |
| 6825 | 6857 | // undefined to anything |
| 6826 | | if (inst.value()) |val| { |
| 6827 | | if (val.isUndef() or inst.ty.zigTypeTag() == .Undefined) { |
| 6828 | | return mod.constInst(arena, inst_src, .{ .ty = dest_type, .val = val }); |
| 6858 | if (try sema.resolvePossiblyUndefinedValue(block, inst_src, inst)) |val| { |
| 6859 | if (val.isUndef() or inst_ty.zigTypeTag() == .Undefined) { |
| 6860 | return sema.addConstant(dest_type, val); |
| 6829 | 6861 | } |
| 6830 | 6862 | } |
| 6831 | | assert(inst.ty.zigTypeTag() != .Undefined); |
| 6863 | assert(inst_ty.zigTypeTag() != .Undefined); |
| 6864 | |
| 6865 | if (true) { |
| 6866 | @panic("TODO finish AIR memory layout rework"); |
| 6867 | } |
| 6832 | 6868 | |
| 6833 | 6869 | // T to E!T or E to E!T |
| 6834 | 6870 | if (dest_type.tag() == .error_union) { |
| 6835 | | return try sema.wrapErrorUnion(block, dest_type, inst); |
| 6871 | return try sema.wrapErrorUnion(block, dest_type, inst, inst_src); |
| 6836 | 6872 | } |
| 6837 | 6873 | |
| 6838 | 6874 | // comptime known number to other number |
| ... | ... | @@ -6844,14 +6880,14 @@ fn coerce( |
| 6844 | 6880 | switch (dest_type.zigTypeTag()) { |
| 6845 | 6881 | .Optional => { |
| 6846 | 6882 | // null to ?T |
| 6847 | | if (inst.ty.zigTypeTag() == .Null) { |
| 6883 | if (inst_ty.zigTypeTag() == .Null) { |
| 6848 | 6884 | return mod.constInst(arena, inst_src, .{ .ty = dest_type, .val = Value.initTag(.null_value) }); |
| 6849 | 6885 | } |
| 6850 | 6886 | |
| 6851 | 6887 | // T to ?T |
| 6852 | 6888 | var buf: Type.Payload.ElemType = undefined; |
| 6853 | 6889 | const child_type = dest_type.optionalChild(&buf); |
| 6854 | | if (child_type.eql(inst.ty)) { |
| 6890 | if (child_type.eql(inst_ty)) { |
| 6855 | 6891 | return sema.wrapOptional(block, dest_type, inst); |
| 6856 | 6892 | } else if (try sema.coerceNum(block, child_type, inst)) |some| { |
| 6857 | 6893 | return sema.wrapOptional(block, dest_type, some); |
| ... | ... | @@ -6860,12 +6896,12 @@ fn coerce( |
| 6860 | 6896 | .Pointer => { |
| 6861 | 6897 | // Coercions where the source is a single pointer to an array. |
| 6862 | 6898 | src_array_ptr: { |
| 6863 | | if (!inst.ty.isSinglePointer()) break :src_array_ptr; |
| 6864 | | const array_type = inst.ty.elemType(); |
| 6899 | if (!inst_ty.isSinglePointer()) break :src_array_ptr; |
| 6900 | const array_type = inst_ty.elemType(); |
| 6865 | 6901 | if (array_type.zigTypeTag() != .Array) break :src_array_ptr; |
| 6866 | 6902 | const array_elem_type = array_type.elemType(); |
| 6867 | | if (inst.ty.isConstPtr() and !dest_type.isConstPtr()) break :src_array_ptr; |
| 6868 | | if (inst.ty.isVolatilePtr() and !dest_type.isVolatilePtr()) break :src_array_ptr; |
| 6903 | if (inst_ty.isConstPtr() and !dest_type.isConstPtr()) break :src_array_ptr; |
| 6904 | if (inst_ty.isVolatilePtr() and !dest_type.isVolatilePtr()) break :src_array_ptr; |
| 6869 | 6905 | |
| 6870 | 6906 | const dst_elem_type = dest_type.elemType(); |
| 6871 | 6907 | switch (coerceInMemoryAllowed(dst_elem_type, array_elem_type)) { |
| ... | ... | @@ -6904,11 +6940,11 @@ fn coerce( |
| 6904 | 6940 | }, |
| 6905 | 6941 | .Int => { |
| 6906 | 6942 | // integer widening |
| 6907 | | if (inst.ty.zigTypeTag() == .Int) { |
| 6943 | if (inst_ty.zigTypeTag() == .Int) { |
| 6908 | 6944 | assert(inst.value() == null); // handled above |
| 6909 | 6945 | |
| 6910 | 6946 | const dst_info = dest_type.intInfo(target); |
| 6911 | | const src_info = inst.ty.intInfo(target); |
| 6947 | const src_info = inst_ty.intInfo(target); |
| 6912 | 6948 | if ((src_info.signedness == dst_info.signedness and dst_info.bits >= src_info.bits) or |
| 6913 | 6949 | // small enough unsigned ints can get casted to large enough signed ints |
| 6914 | 6950 | (src_info.signedness == .signed and dst_info.signedness == .unsigned and dst_info.bits > src_info.bits)) |
| ... | ... | @@ -6920,10 +6956,10 @@ fn coerce( |
| 6920 | 6956 | }, |
| 6921 | 6957 | .Float => { |
| 6922 | 6958 | // float widening |
| 6923 | | if (inst.ty.zigTypeTag() == .Float) { |
| 6959 | if (inst_ty.zigTypeTag() == .Float) { |
| 6924 | 6960 | assert(inst.value() == null); // handled above |
| 6925 | 6961 | |
| 6926 | | const src_bits = inst.ty.floatBits(target); |
| 6962 | const src_bits = inst_ty.floatBits(target); |
| 6927 | 6963 | const dst_bits = dest_type.floatBits(target); |
| 6928 | 6964 | if (dst_bits >= src_bits) { |
| 6929 | 6965 | try sema.requireRuntimeBlock(block, inst_src); |
| ... | ... | @@ -6933,7 +6969,7 @@ fn coerce( |
| 6933 | 6969 | }, |
| 6934 | 6970 | .Enum => { |
| 6935 | 6971 | // enum literal to enum |
| 6936 | | if (inst.ty.zigTypeTag() == .EnumLiteral) { |
| 6972 | if (inst_ty.zigTypeTag() == .EnumLiteral) { |
| 6937 | 6973 | const val = try sema.resolveConstValue(block, inst_src, inst); |
| 6938 | 6974 | const bytes = val.castTag(.enum_literal).?.data; |
| 6939 | 6975 | const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type); |
| ... | ... | @@ -6965,7 +7001,7 @@ fn coerce( |
| 6965 | 7001 | else => {}, |
| 6966 | 7002 | } |
| 6967 | 7003 | |
| 6968 | | return mod.fail(&block.base, inst_src, "expected {}, found {}", .{ dest_type, inst.ty }); |
| 7004 | return mod.fail(&block.base, inst_src, "expected {}, found {}", .{ dest_type, inst_ty }); |
| 6969 | 7005 | } |
| 6970 | 7006 | |
| 6971 | 7007 | const InMemoryCoercionResult = enum { |
| ... | ... | @@ -6982,7 +7018,7 @@ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type) InMemoryCoercionResult |
| 6982 | 7018 | return .no_match; |
| 6983 | 7019 | } |
| 6984 | 7020 | |
| 6985 | | fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) InnerError!?Air.Inst.Index { |
| 7021 | fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) InnerError!?Air.Inst.Index { |
| 6986 | 7022 | const val = inst.value() orelse return null; |
| 6987 | 7023 | const src_zig_tag = inst.ty.zigTypeTag(); |
| 6988 | 7024 | const dst_zig_tag = dest_type.zigTypeTag(); |
| ... | ... | @@ -7020,9 +7056,15 @@ fn coerceNum(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.I |
| 7020 | 7056 | return null; |
| 7021 | 7057 | } |
| 7022 | 7058 | |
| 7023 | | fn coerceVarArgParam(sema: *Sema, block: *Scope.Block, inst: Air.Inst.Index) !Air.Inst.Index { |
| 7024 | | switch (inst.ty.zigTypeTag()) { |
| 7025 | | .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst.src, "integer and float literals in var args function must be casted", .{}), |
| 7059 | fn coerceVarArgParam( |
| 7060 | sema: *Sema, |
| 7061 | block: *Scope.Block, |
| 7062 | inst: Air.Inst.Ref, |
| 7063 | inst_src: LazySrcLoc, |
| 7064 | ) !Air.Inst.Ref { |
| 7065 | const inst_ty = sema.getTypeOfAirRef(inst); |
| 7066 | switch (inst_ty.zigTypeTag()) { |
| 7067 | .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst_src, "integer and float literals in var args function must be casted", .{}), |
| 7026 | 7068 | else => {}, |
| 7027 | 7069 | } |
| 7028 | 7070 | // TODO implement more of this function. |
| ... | ... | @@ -7033,8 +7075,8 @@ fn storePtr( |
| 7033 | 7075 | sema: *Sema, |
| 7034 | 7076 | block: *Scope.Block, |
| 7035 | 7077 | src: LazySrcLoc, |
| 7036 | | ptr: Air.Inst.Index, |
| 7037 | | uncasted_value: Air.Inst.Index, |
| 7078 | ptr: Air.Inst.Ref, |
| 7079 | uncasted_value: Air.Inst.Ref, |
| 7038 | 7080 | ) !void { |
| 7039 | 7081 | if (ptr.ty.isConstPtr()) |
| 7040 | 7082 | return sema.mod.fail(&block.base, src, "cannot assign to constant", .{}); |
| ... | ... | @@ -7082,17 +7124,23 @@ fn storePtr( |
| 7082 | 7124 | _ = try block.addBinOp(src, Type.initTag(.void), .store, ptr, value); |
| 7083 | 7125 | } |
| 7084 | 7126 | |
| 7085 | | fn bitcast(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index { |
| 7086 | | if (inst.value()) |val| { |
| 7127 | fn bitcast( |
| 7128 | sema: *Sema, |
| 7129 | block: *Scope.Block, |
| 7130 | dest_type: Type, |
| 7131 | inst: Air.Inst.Ref, |
| 7132 | inst_src: LazySrcLoc, |
| 7133 | ) InnerError!Air.Inst.Ref { |
| 7134 | if (try sema.resolvePossiblyUndefinedValue(block, inst_src, inst)) |val| { |
| 7087 | 7135 | // Keep the comptime Value representation; take the new type. |
| 7088 | | return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val }); |
| 7136 | return sema.addConstant(dest_type, val); |
| 7089 | 7137 | } |
| 7090 | 7138 | // TODO validate the type size and other compile errors |
| 7091 | | try sema.requireRuntimeBlock(block, inst.src); |
| 7092 | | return block.addUnOp(inst.src, dest_type, .bitcast, inst); |
| 7139 | try sema.requireRuntimeBlock(block, inst_src); |
| 7140 | return block.addTyOp(.bitcast, dest_type, inst); |
| 7093 | 7141 | } |
| 7094 | 7142 | |
| 7095 | | fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index { |
| 7143 | fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) InnerError!Air.Inst.Ref { |
| 7096 | 7144 | if (inst.value()) |val| { |
| 7097 | 7145 | // The comptime Value representation is compatible with both types. |
| 7098 | 7146 | return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val }); |
| ... | ... | @@ -7100,7 +7148,7 @@ fn coerceArrayPtrToSlice(sema: *Sema, block: *Scope.Block, dest_type: Type, inst |
| 7100 | 7148 | return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToSlice runtime instruction", .{}); |
| 7101 | 7149 | } |
| 7102 | 7150 | |
| 7103 | | fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index { |
| 7151 | fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) !Air.Inst.Ref { |
| 7104 | 7152 | if (inst.value()) |val| { |
| 7105 | 7153 | // The comptime Value representation is compatible with both types. |
| 7106 | 7154 | return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val }); |
| ... | ... | @@ -7108,12 +7156,12 @@ fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: |
| 7108 | 7156 | return sema.mod.fail(&block.base, inst.src, "TODO implement coerceArrayPtrToMany runtime instruction", .{}); |
| 7109 | 7157 | } |
| 7110 | 7158 | |
| 7111 | | fn analyzeDeclVal(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!Air.Inst.Index { |
| 7159 | fn analyzeDeclVal(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!Air.Inst.Ref { |
| 7112 | 7160 | const decl_ref = try sema.analyzeDeclRef(block, src, decl); |
| 7113 | 7161 | return sema.analyzeLoad(block, src, decl_ref, src); |
| 7114 | 7162 | } |
| 7115 | 7163 | |
| 7116 | | fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!Air.Inst.Index { |
| 7164 | fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!Air.Inst.Ref { |
| 7117 | 7165 | try sema.mod.declareDeclDependency(sema.owner_decl, decl); |
| 7118 | 7166 | sema.mod.ensureDeclAnalyzed(decl) catch |err| { |
| 7119 | 7167 | if (sema.func) |func| { |
| ... | ... | @@ -7128,43 +7176,41 @@ fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl |
| 7128 | 7176 | if (decl_tv.val.tag() == .variable) { |
| 7129 | 7177 | return sema.analyzeVarRef(block, src, decl_tv); |
| 7130 | 7178 | } |
| 7131 | | return sema.mod.constInst(sema.arena, src, .{ |
| 7132 | | .ty = try sema.mod.simplePtrType(sema.arena, decl_tv.ty, false, .One), |
| 7133 | | .val = try Value.Tag.decl_ref.create(sema.arena, decl), |
| 7134 | | }); |
| 7179 | return sema.addConstant( |
| 7180 | try Module.simplePtrType(sema.arena, decl_tv.ty, false, .One), |
| 7181 | try Value.Tag.decl_ref.create(sema.arena, decl), |
| 7182 | ); |
| 7135 | 7183 | } |
| 7136 | 7184 | |
| 7137 | | fn analyzeVarRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, tv: TypedValue) InnerError!Air.Inst.Index { |
| 7185 | fn analyzeVarRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, tv: TypedValue) InnerError!Air.Inst.Ref { |
| 7138 | 7186 | const variable = tv.val.castTag(.variable).?.data; |
| 7139 | 7187 | |
| 7140 | | const ty = try sema.mod.simplePtrType(sema.arena, tv.ty, variable.is_mutable, .One); |
| 7188 | const ty = try Module.simplePtrType(sema.arena, tv.ty, variable.is_mutable, .One); |
| 7141 | 7189 | if (!variable.is_mutable and !variable.is_extern) { |
| 7142 | | return sema.mod.constInst(sema.arena, src, .{ |
| 7143 | | .ty = ty, |
| 7144 | | .val = try Value.Tag.ref_val.create(sema.arena, variable.init), |
| 7145 | | }); |
| 7190 | return sema.addConstant(ty, try Value.Tag.ref_val.create(sema.arena, variable.init)); |
| 7146 | 7191 | } |
| 7147 | 7192 | |
| 7193 | const gpa = sema.gpa; |
| 7148 | 7194 | try sema.requireRuntimeBlock(block, src); |
| 7149 | | const inst = try sema.arena.create(Inst.VarPtr); |
| 7150 | | inst.* = .{ |
| 7151 | | .base = .{ |
| 7152 | | .tag = .varptr, |
| 7153 | | .ty = ty, |
| 7154 | | .src = src, |
| 7155 | | }, |
| 7156 | | .variable = variable, |
| 7157 | | }; |
| 7158 | | try block.instructions.append(sema.gpa, &inst.base); |
| 7159 | | return &inst.base; |
| 7195 | try sema.air_variables.append(gpa, variable); |
| 7196 | const result_inst = @intCast(Air.Inst.Index, sema.air_instructions.len); |
| 7197 | try sema.air_instructions.append(gpa, .{ |
| 7198 | .tag = .varptr, |
| 7199 | .data = .{ .ty_pl = .{ |
| 7200 | .ty = try sema.addType(ty), |
| 7201 | .payload = @intCast(u32, sema.air_variables.items.len - 1), |
| 7202 | } }, |
| 7203 | }); |
| 7204 | try block.instructions.append(gpa, result_inst); |
| 7205 | return indexToRef(result_inst); |
| 7160 | 7206 | } |
| 7161 | 7207 | |
| 7162 | 7208 | fn analyzeRef( |
| 7163 | 7209 | sema: *Sema, |
| 7164 | 7210 | block: *Scope.Block, |
| 7165 | 7211 | src: LazySrcLoc, |
| 7166 | | operand: Air.Inst.Index, |
| 7167 | | ) InnerError!Air.Inst.Index { |
| 7212 | operand: Air.Inst.Ref, |
| 7213 | ) InnerError!Air.Inst.Ref { |
| 7168 | 7214 | const ptr_type = try sema.mod.simplePtrType(sema.arena, operand.ty, false, .One); |
| 7169 | 7215 | |
| 7170 | 7216 | if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |val| { |
| ... | ... | @@ -7182,34 +7228,32 @@ fn analyzeLoad( |
| 7182 | 7228 | sema: *Sema, |
| 7183 | 7229 | block: *Scope.Block, |
| 7184 | 7230 | src: LazySrcLoc, |
| 7185 | | ptr: Air.Inst.Index, |
| 7231 | ptr: Air.Inst.Ref, |
| 7186 | 7232 | ptr_src: LazySrcLoc, |
| 7187 | | ) InnerError!Air.Inst.Index { |
| 7188 | | const elem_ty = switch (ptr.ty.zigTypeTag()) { |
| 7189 | | .Pointer => ptr.ty.elemType(), |
| 7190 | | else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr.ty}), |
| 7233 | ) InnerError!Air.Inst.Ref { |
| 7234 | const ptr_ty = sema.getTypeOfAirRef(ptr); |
| 7235 | const elem_ty = switch (ptr_ty.zigTypeTag()) { |
| 7236 | .Pointer => ptr_ty.elemType(), |
| 7237 | else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}), |
| 7191 | 7238 | }; |
| 7192 | 7239 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| blk: { |
| 7193 | 7240 | if (ptr_val.tag() == .int_u64) |
| 7194 | 7241 | break :blk; // do it at runtime |
| 7195 | 7242 | |
| 7196 | | return sema.mod.constInst(sema.arena, src, .{ |
| 7197 | | .ty = elem_ty, |
| 7198 | | .val = try ptr_val.pointerDeref(sema.arena), |
| 7199 | | }); |
| 7243 | return sema.addConstant(elem_ty, try ptr_val.pointerDeref(sema.arena)); |
| 7200 | 7244 | } |
| 7201 | 7245 | |
| 7202 | 7246 | try sema.requireRuntimeBlock(block, src); |
| 7203 | | return block.addUnOp(src, elem_ty, .load, ptr); |
| 7247 | return block.addTyOp(.load, elem_ty, ptr); |
| 7204 | 7248 | } |
| 7205 | 7249 | |
| 7206 | 7250 | fn analyzeIsNull( |
| 7207 | 7251 | sema: *Sema, |
| 7208 | 7252 | block: *Scope.Block, |
| 7209 | 7253 | src: LazySrcLoc, |
| 7210 | | operand: Air.Inst.Index, |
| 7254 | operand: Air.Inst.Ref, |
| 7211 | 7255 | invert_logic: bool, |
| 7212 | | ) InnerError!Air.Inst.Index { |
| 7256 | ) InnerError!Air.Inst.Ref { |
| 7213 | 7257 | const result_ty = Type.initTag(.bool); |
| 7214 | 7258 | if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |opt_val| { |
| 7215 | 7259 | if (opt_val.isUndef()) { |
| ... | ... | @@ -7228,8 +7272,8 @@ fn analyzeIsNonErr( |
| 7228 | 7272 | sema: *Sema, |
| 7229 | 7273 | block: *Scope.Block, |
| 7230 | 7274 | src: LazySrcLoc, |
| 7231 | | operand: Air.Inst.Index, |
| 7232 | | ) InnerError!Air.Inst.Index { |
| 7275 | operand: Air.Inst.Ref, |
| 7276 | ) InnerError!Air.Inst.Ref { |
| 7233 | 7277 | const ot = operand.ty.zigTypeTag(); |
| 7234 | 7278 | if (ot != .ErrorSet and ot != .ErrorUnion) return sema.mod.constBool(sema.arena, src, true); |
| 7235 | 7279 | if (ot == .ErrorSet) return sema.mod.constBool(sema.arena, src, false); |
| ... | ... | @@ -7249,12 +7293,12 @@ fn analyzeSlice( |
| 7249 | 7293 | sema: *Sema, |
| 7250 | 7294 | block: *Scope.Block, |
| 7251 | 7295 | src: LazySrcLoc, |
| 7252 | | array_ptr: Air.Inst.Index, |
| 7253 | | start: Air.Inst.Index, |
| 7296 | array_ptr: Air.Inst.Ref, |
| 7297 | start: Air.Inst.Ref, |
| 7254 | 7298 | end_opt: ?Air.Inst.Index, |
| 7255 | 7299 | sentinel_opt: ?Air.Inst.Index, |
| 7256 | 7300 | sentinel_src: LazySrcLoc, |
| 7257 | | ) InnerError!Air.Inst.Index { |
| 7301 | ) InnerError!Air.Inst.Ref { |
| 7258 | 7302 | const ptr_child = switch (array_ptr.ty.zigTypeTag()) { |
| 7259 | 7303 | .Pointer => array_ptr.ty.elemType(), |
| 7260 | 7304 | else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr.ty}), |
| ... | ... | @@ -7325,10 +7369,10 @@ fn cmpNumeric( |
| 7325 | 7369 | sema: *Sema, |
| 7326 | 7370 | block: *Scope.Block, |
| 7327 | 7371 | src: LazySrcLoc, |
| 7328 | | lhs: Air.Inst.Index, |
| 7329 | | rhs: Air.Inst.Index, |
| 7372 | lhs: Air.Inst.Ref, |
| 7373 | rhs: Air.Inst.Ref, |
| 7330 | 7374 | op: std.math.CompareOperator, |
| 7331 | | ) InnerError!Air.Inst.Index { |
| 7375 | ) InnerError!Air.Inst.Ref { |
| 7332 | 7376 | assert(lhs.ty.isNumeric()); |
| 7333 | 7377 | assert(rhs.ty.isNumeric()); |
| 7334 | 7378 | |
| ... | ... | @@ -7494,7 +7538,7 @@ fn cmpNumeric( |
| 7494 | 7538 | return block.addBinOp(src, Type.initTag(.bool), Inst.Tag.fromCmpOp(op), casted_lhs, casted_rhs); |
| 7495 | 7539 | } |
| 7496 | 7540 | |
| 7497 | | fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index { |
| 7541 | fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Ref) !Air.Inst.Index { |
| 7498 | 7542 | if (inst.value()) |val| { |
| 7499 | 7543 | return sema.mod.constInst(sema.arena, inst.src, .{ .ty = dest_type, .val = val }); |
| 7500 | 7544 | } |
| ... | ... | @@ -7503,9 +7547,15 @@ fn wrapOptional(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Ins |
| 7503 | 7547 | return block.addUnOp(inst.src, dest_type, .wrap_optional, inst); |
| 7504 | 7548 | } |
| 7505 | 7549 | |
| 7506 | | fn wrapErrorUnion(sema: *Sema, block: *Scope.Block, dest_type: Type, inst: Air.Inst.Index) !Air.Inst.Index { |
| 7550 | fn wrapErrorUnion( |
| 7551 | sema: *Sema, |
| 7552 | block: *Scope.Block, |
| 7553 | dest_type: Type, |
| 7554 | inst: Air.Inst.Ref, |
| 7555 | inst_src: LazySrcLoc, |
| 7556 | ) !Air.Inst.Index { |
| 7507 | 7557 | const err_union = dest_type.castTag(.error_union).?; |
| 7508 | | if (inst.value()) |val| { |
| 7558 | if (try sema.resolvePossiblyUndefinedValue(block, inst_src, inst)) |val| { |
| 7509 | 7559 | if (inst.ty.zigTypeTag() != .ErrorSet) { |
| 7510 | 7560 | _ = try sema.coerce(block, err_union.data.payload, inst, inst.src); |
| 7511 | 7561 | } else switch (err_union.data.error_set.tag()) { |
| ... | ... | @@ -7710,7 +7760,7 @@ fn getBuiltin( |
| 7710 | 7760 | block: *Scope.Block, |
| 7711 | 7761 | src: LazySrcLoc, |
| 7712 | 7762 | name: []const u8, |
| 7713 | | ) InnerError!Air.Inst.Index { |
| 7763 | ) InnerError!Air.Inst.Ref { |
| 7714 | 7764 | const mod = sema.mod; |
| 7715 | 7765 | const std_pkg = mod.root_pkg.table.get("std").?; |
| 7716 | 7766 | const std_file = (mod.importPkg(std_pkg) catch unreachable).file; |
| ... | ... | @@ -7938,6 +7988,68 @@ fn enumFieldSrcLoc( |
| 7938 | 7988 | } else unreachable; |
| 7939 | 7989 | } |
| 7940 | 7990 | |
| 7991 | /// Returns the type of the AIR instruction. |
| 7992 | fn getTypeOfAirRef(sema: *Sema, air_ref: Air.Inst.Ref) Type { |
| 7993 | switch (air_ref) { |
| 7994 | .none => unreachable, |
| 7995 | .u8_type => return Type.initTag(.u8), |
| 7996 | .i8_type => return Type.initTag(.i8), |
| 7997 | .u16_type => return Type.initTag(.u16), |
| 7998 | .i16_type => return Type.initTag(.i16), |
| 7999 | .u32_type => return Type.initTag(.u32), |
| 8000 | .i32_type => return Type.initTag(.i32), |
| 8001 | .u64_type => return Type.initTag(.u64), |
| 8002 | .i64_type => return Type.initTag(.i64), |
| 8003 | .u128_type => return Type.initTag(.u128), |
| 8004 | .i128_type => return Type.initTag(.i128), |
| 8005 | .usize_type => return Type.initTag(.usize), |
| 8006 | .isize_type => return Type.initTag(.isize), |
| 8007 | .c_short_type => return Type.initTag(.c_short), |
| 8008 | .c_ushort_type => return Type.initTag(.c_ushort), |
| 8009 | .c_int_type => return Type.initTag(.c_int), |
| 8010 | .c_uint_type => return Type.initTag(.c_uint), |
| 8011 | .c_long_type => return Type.initTag(.c_long), |
| 8012 | .c_ulong_type => return Type.initTag(.c_ulong), |
| 8013 | .c_longlong_type => return Type.initTag(.c_longlong), |
| 8014 | .c_ulonglong_type => return Type.initTag(.c_ulonglong), |
| 8015 | .c_longdouble_type => return Type.initTag(.c_longdouble), |
| 8016 | .f16_type => return Type.initTag(.f16), |
| 8017 | .f32_type => return Type.initTag(.f32), |
| 8018 | .f64_type => return Type.initTag(.f64), |
| 8019 | .f128_type => return Type.initTag(.f128), |
| 8020 | .c_void_type => return Type.initTag(.c_void), |
| 8021 | .bool_type => return Type.initTag(.bool), |
| 8022 | .void_type => return Type.initTag(.void), |
| 8023 | .type_type => return Type.initTag(.type), |
| 8024 | .anyerror_type => return Type.initTag(.anyerror), |
| 8025 | .comptime_int_type => return Type.initTag(.comptime_int), |
| 8026 | .comptime_float_type => return Type.initTag(.comptime_float), |
| 8027 | .noreturn_type => return Type.initTag(.noreturn), |
| 8028 | .anyframe_type => return Type.initTag(.@"anyframe"), |
| 8029 | .null_type => return Type.initTag(.@"null"), |
| 8030 | .undefined_type => return Type.initTag(.@"undefined"), |
| 8031 | .enum_literal_type => return Type.initTag(.enum_literal), |
| 8032 | .atomic_ordering_type => return Type.initTag(.atomic_ordering), |
| 8033 | .atomic_rmw_op_type => return Type.initTag(.atomic_rmw_op), |
| 8034 | .calling_convention_type => return Type.initTag(.calling_convention), |
| 8035 | .float_mode_type => return Type.initTag(.float_mode), |
| 8036 | .reduce_op_type => return Type.initTag(.reduce_op), |
| 8037 | .call_options_type => return Type.initTag(.call_options), |
| 8038 | .export_options_type => return Type.initTag(.export_options), |
| 8039 | .extern_options_type => return Type.initTag(.extern_options), |
| 8040 | .manyptr_u8_type => return Type.initTag(.manyptr_u8), |
| 8041 | .manyptr_const_u8_type => return Type.initTag(.manyptr_const_u8), |
| 8042 | .fn_noreturn_no_args_type => return Type.initTag(.fn_noreturn_no_args), |
| 8043 | .fn_void_no_args_type => return Type.initTag(.fn_void_no_args), |
| 8044 | .fn_naked_noreturn_no_args_type => return Type.initTag(.fn_naked_noreturn_no_args), |
| 8045 | .fn_ccc_void_no_args_type => return Type.initTag(.fn_ccc_void_no_args), |
| 8046 | .single_const_pointer_to_comptime_int_type => return Type.initTag(.single_const_pointer_to_comptime_int), |
| 8047 | .const_slice_u8_type => return Type.initTag(.const_slice_u8), |
| 8048 | else => return sema.getAirType(air_ref), |
| 8049 | } |
| 8050 | } |
| 8051 | |
| 8052 | /// Asserts the AIR instruction is a `const_ty` and returns the type. |
| 7941 | 8053 | fn getAirType(sema: *Sema, air_ref: Air.Inst.Ref) Type { |
| 7942 | 8054 | var i: usize = @enumToInt(air_ref); |
| 7943 | 8055 | if (i < Air.Inst.Ref.typed_value_map.len) { |
| ... | ... | @@ -8014,13 +8126,27 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref { |
| 8014 | 8126 | return indexToRef(@intCast(u32, sema.air_instructions.len - 1)); |
| 8015 | 8127 | } |
| 8016 | 8128 | |
| 8129 | pub fn addConstant(sema: *Sema, ty: Type, val: Value) InnerError!Air.Inst.Ref { |
| 8130 | const gpa = sema.gpa; |
| 8131 | const ty_inst = try sema.addType(ty); |
| 8132 | try sema.air_values.append(gpa, val); |
| 8133 | try sema.air_instructions.append(gpa, .{ |
| 8134 | .tag = .constant, |
| 8135 | .data = .{ .ty_pl = .{ |
| 8136 | .ty = ty_inst, |
| 8137 | .payload = @intCast(u32, sema.air_values.items.len - 1), |
| 8138 | } }, |
| 8139 | }); |
| 8140 | return indexToRef(@intCast(u32, sema.air_instructions.len - 1)); |
| 8141 | } |
| 8142 | |
| 8017 | 8143 | const ref_start_index: u32 = Air.Inst.Ref.typed_value_map.len; |
| 8018 | 8144 | |
| 8019 | | fn indexToRef(inst: Air.Inst.Index) Air.Inst.Ref { |
| 8145 | pub fn indexToRef(inst: Air.Inst.Index) Air.Inst.Ref { |
| 8020 | 8146 | return @intToEnum(Air.Inst.Ref, ref_start_index + inst); |
| 8021 | 8147 | } |
| 8022 | 8148 | |
| 8023 | | fn refToIndex(inst: Air.Inst.Ref) ?Air.Inst.Index { |
| 8149 | pub fn refToIndex(inst: Air.Inst.Ref) ?Air.Inst.Index { |
| 8024 | 8150 | const ref_int = @enumToInt(inst); |
| 8025 | 8151 | if (ref_int >= ref_start_index) { |
| 8026 | 8152 | return ref_int - ref_start_index; |