authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-14 23:59:29-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-20 12:19:16-07:00
log0da66339096c21d9ca524ff7a0c11a5707b60041
treee5c530e4c42e7ae4a6b65040da9e7ac7e3bae264
parent1294ebe1f5eaca1f11d68284d1b96419d53253be

Sema: fix implementation of getTypeOf

and rename it to typeOf

1 files changed, 258 insertions(+), 209 deletions(-)

src/Sema.zig+258-209
...@@ -199,65 +199,65 @@ pub fn analyzeBody(...@@ -199,65 +199,65 @@ pub fn analyzeBody(
199 .cmp_lt => try sema.zirCmp(block, inst, .lt),199 .cmp_lt => try sema.zirCmp(block, inst, .lt),
200 .cmp_lte => try sema.zirCmp(block, inst, .lte),200 .cmp_lte => try sema.zirCmp(block, inst, .lte),
201 .cmp_neq => try sema.zirCmp(block, inst, .neq),201 .cmp_neq => try sema.zirCmp(block, inst, .neq),
202 //.coerce_result_ptr => try sema.zirCoerceResultPtr(block, inst),202 .coerce_result_ptr => try sema.zirCoerceResultPtr(block, inst),
203 //.decl_ref => try sema.zirDeclRef(block, inst),203 .decl_ref => try sema.zirDeclRef(block, inst),
204 //.decl_val => try sema.zirDeclVal(block, inst),204 .decl_val => try sema.zirDeclVal(block, inst),
205 //.load => try sema.zirLoad(block, inst),205 .load => try sema.zirLoad(block, inst),
206 //.elem_ptr => try sema.zirElemPtr(block, inst),206 .elem_ptr => try sema.zirElemPtr(block, inst),
207 //.elem_ptr_node => try sema.zirElemPtrNode(block, inst),207 .elem_ptr_node => try sema.zirElemPtrNode(block, inst),
208 //.elem_val => try sema.zirElemVal(block, inst),208 .elem_val => try sema.zirElemVal(block, inst),
209 //.elem_val_node => try sema.zirElemValNode(block, inst),209 .elem_val_node => try sema.zirElemValNode(block, inst),
210 //.elem_type => try sema.zirElemType(block, inst),210 .elem_type => try sema.zirElemType(block, inst),
211 //.enum_literal => try sema.zirEnumLiteral(block, inst),211 .enum_literal => try sema.zirEnumLiteral(block, inst),
212 //.enum_to_int => try sema.zirEnumToInt(block, inst),212 .enum_to_int => try sema.zirEnumToInt(block, inst),
213 //.int_to_enum => try sema.zirIntToEnum(block, inst),213 .int_to_enum => try sema.zirIntToEnum(block, inst),
214 //.err_union_code => try sema.zirErrUnionCode(block, inst),214 .err_union_code => try sema.zirErrUnionCode(block, inst),
215 //.err_union_code_ptr => try sema.zirErrUnionCodePtr(block, inst),215 .err_union_code_ptr => try sema.zirErrUnionCodePtr(block, inst),
216 //.err_union_payload_safe => try sema.zirErrUnionPayload(block, inst, true),216 .err_union_payload_safe => try sema.zirErrUnionPayload(block, inst, true),
217 //.err_union_payload_safe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, true),217 .err_union_payload_safe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, true),
218 //.err_union_payload_unsafe => try sema.zirErrUnionPayload(block, inst, false),218 .err_union_payload_unsafe => try sema.zirErrUnionPayload(block, inst, false),
219 //.err_union_payload_unsafe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, false),219 .err_union_payload_unsafe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, false),
220 //.error_union_type => try sema.zirErrorUnionType(block, inst),220 .error_union_type => try sema.zirErrorUnionType(block, inst),
221 //.error_value => try sema.zirErrorValue(block, inst),221 .error_value => try sema.zirErrorValue(block, inst),
222 //.error_to_int => try sema.zirErrorToInt(block, inst),222 .error_to_int => try sema.zirErrorToInt(block, inst),
223 //.int_to_error => try sema.zirIntToError(block, inst),223 .int_to_error => try sema.zirIntToError(block, inst),
224 //.field_ptr => try sema.zirFieldPtr(block, inst),224 .field_ptr => try sema.zirFieldPtr(block, inst),
225 //.field_ptr_named => try sema.zirFieldPtrNamed(block, inst),225 .field_ptr_named => try sema.zirFieldPtrNamed(block, inst),
226 //.field_val => try sema.zirFieldVal(block, inst),226 .field_val => try sema.zirFieldVal(block, inst),
227 //.field_val_named => try sema.zirFieldValNamed(block, inst),227 .field_val_named => try sema.zirFieldValNamed(block, inst),
228 //.func => try sema.zirFunc(block, inst, false),228 .func => try sema.zirFunc(block, inst, false),
229 //.func_inferred => try sema.zirFunc(block, inst, true),229 .func_inferred => try sema.zirFunc(block, inst, true),
230 //.import => try sema.zirImport(block, inst),230 .import => try sema.zirImport(block, inst),
231 //.indexable_ptr_len => try sema.zirIndexablePtrLen(block, inst),231 .indexable_ptr_len => try sema.zirIndexablePtrLen(block, inst),
232 //.int => try sema.zirInt(block, inst),232 .int => try sema.zirInt(block, inst),
233 //.int_big => try sema.zirIntBig(block, inst),233 .int_big => try sema.zirIntBig(block, inst),
234 //.float => try sema.zirFloat(block, inst),234 .float => try sema.zirFloat(block, inst),
235 //.float128 => try sema.zirFloat128(block, inst),235 .float128 => try sema.zirFloat128(block, inst),
236 //.int_type => try sema.zirIntType(block, inst),236 .int_type => try sema.zirIntType(block, inst),
237 //.is_non_err => try sema.zirIsNonErr(block, inst),237 .is_non_err => try sema.zirIsNonErr(block, inst),
238 //.is_non_err_ptr => try sema.zirIsNonErrPtr(block, inst),238 .is_non_err_ptr => try sema.zirIsNonErrPtr(block, inst),
239 //.is_non_null => try sema.zirIsNonNull(block, inst),239 .is_non_null => try sema.zirIsNonNull(block, inst),
240 //.is_non_null_ptr => try sema.zirIsNonNullPtr(block, inst),240 .is_non_null_ptr => try sema.zirIsNonNullPtr(block, inst),
241 //.loop => try sema.zirLoop(block, inst),241 .loop => try sema.zirLoop(block, inst),
242 //.merge_error_sets => try sema.zirMergeErrorSets(block, inst),242 .merge_error_sets => try sema.zirMergeErrorSets(block, inst),
243 //.negate => try sema.zirNegate(block, inst, .sub),243 .negate => try sema.zirNegate(block, inst, .sub),
244 //.negate_wrap => try sema.zirNegate(block, inst, .subwrap),244 .negate_wrap => try sema.zirNegate(block, inst, .subwrap),
245 //.optional_payload_safe => try sema.zirOptionalPayload(block, inst, true),245 .optional_payload_safe => try sema.zirOptionalPayload(block, inst, true),
246 //.optional_payload_safe_ptr => try sema.zirOptionalPayloadPtr(block, inst, true),246 .optional_payload_safe_ptr => try sema.zirOptionalPayloadPtr(block, inst, true),
247 //.optional_payload_unsafe => try sema.zirOptionalPayload(block, inst, false),247 .optional_payload_unsafe => try sema.zirOptionalPayload(block, inst, false),
248 //.optional_payload_unsafe_ptr => try sema.zirOptionalPayloadPtr(block, inst, false),248 .optional_payload_unsafe_ptr => try sema.zirOptionalPayloadPtr(block, inst, false),
249 //.optional_type => try sema.zirOptionalType(block, inst),249 .optional_type => try sema.zirOptionalType(block, inst),
250 //.param_type => try sema.zirParamType(block, inst),250 .param_type => try sema.zirParamType(block, inst),
251 //.ptr_type => try sema.zirPtrType(block, inst),251 .ptr_type => try sema.zirPtrType(block, inst),
252 //.ptr_type_simple => try sema.zirPtrTypeSimple(block, inst),252 .ptr_type_simple => try sema.zirPtrTypeSimple(block, inst),
253 //.ref => try sema.zirRef(block, inst),253 .ref => try sema.zirRef(block, inst),
254 //.ret_err_value_code => try sema.zirRetErrValueCode(block, inst),254 .ret_err_value_code => try sema.zirRetErrValueCode(block, inst),
255 //.shl => try sema.zirShl(block, inst),255 .shl => try sema.zirShl(block, inst),
256 //.shr => try sema.zirShr(block, inst),256 .shr => try sema.zirShr(block, inst),
257 //.slice_end => try sema.zirSliceEnd(block, inst),257 .slice_end => try sema.zirSliceEnd(block, inst),
258 //.slice_sentinel => try sema.zirSliceSentinel(block, inst),258 .slice_sentinel => try sema.zirSliceSentinel(block, inst),
259 //.slice_start => try sema.zirSliceStart(block, inst),259 .slice_start => try sema.zirSliceStart(block, inst),
260 //.str => try sema.zirStr(block, inst),260 .str => try sema.zirStr(block, inst),
261 //.switch_block => try sema.zirSwitchBlock(block, inst, false, .none),261 //.switch_block => try sema.zirSwitchBlock(block, inst, false, .none),
262 //.switch_block_multi => try sema.zirSwitchBlockMulti(block, inst, false, .none),262 //.switch_block_multi => try sema.zirSwitchBlockMulti(block, inst, false, .none),
263 //.switch_block_else => try sema.zirSwitchBlock(block, inst, false, .@"else"),263 //.switch_block_else => try sema.zirSwitchBlock(block, inst, false, .@"else"),
...@@ -536,7 +536,7 @@ pub fn analyzeBody(...@@ -536,7 +536,7 @@ pub fn analyzeBody(
536 },536 },
537 else => |t| @panic(@tagName(t)),537 else => |t| @panic(@tagName(t)),
538 };538 };
539 if (sema.getTypeOf(air_inst).isNoReturn())539 if (sema.typeOf(air_inst).isNoReturn())
540 return always_noreturn;540 return always_noreturn;
541 try map.put(sema.gpa, inst, air_inst);541 try map.put(sema.gpa, inst, air_inst);
542 i += 1;542 i += 1;
...@@ -620,10 +620,10 @@ fn resolveConstString(...@@ -620,10 +620,10 @@ fn resolveConstString(
620620
621pub fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type {621pub fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type {
622 const air_inst = sema.resolveInst(zir_ref);622 const air_inst = sema.resolveInst(zir_ref);
623 return sema.resolveAirAsType(block, src, air_inst);623 return sema.analyzeAsType(block, src, air_inst);
624}624}
625625
626fn resolveAirAsType(626fn analyzeAsType(
627 sema: *Sema,627 sema: *Sema,
628 block: *Scope.Block,628 block: *Scope.Block,
629 src: LazySrcLoc,629 src: LazySrcLoc,
...@@ -664,26 +664,26 @@ fn resolvePossiblyUndefinedValue(...@@ -664,26 +664,26 @@ fn resolvePossiblyUndefinedValue(
664 sema: *Sema,664 sema: *Sema,
665 block: *Scope.Block,665 block: *Scope.Block,
666 src: LazySrcLoc,666 src: LazySrcLoc,
667 air_ref: Air.Inst.Ref,667 inst: Air.Inst.Ref,
668) CompileError!?Value {668) CompileError!?Value {
669 const ty = sema.getTypeOf(air_ref);
670 if (try sema.typeHasOnePossibleValue(block, src, ty)) |opv| {
671 return opv;
672 }
673 // First section of indexes correspond to a set number of constant values.669 // First section of indexes correspond to a set number of constant values.
674 var i: usize = @enumToInt(air_ref);670 var i: usize = @enumToInt(inst);
675 if (i < Air.Inst.Ref.typed_value_map.len) {671 if (i < Air.Inst.Ref.typed_value_map.len) {
676 return Air.Inst.Ref.typed_value_map[i].val;672 return Air.Inst.Ref.typed_value_map[i].val;
677 }673 }
678 i -= Air.Inst.Ref.typed_value_map.len;674 i -= Air.Inst.Ref.typed_value_map.len;
679675
676 if (try sema.typeHasOnePossibleValue(block, src, sema.typeOf(inst))) |opv| {
677 return opv;
678 }
679
680 switch (sema.air_instructions.items(.tag)[i]) {680 switch (sema.air_instructions.items(.tag)[i]) {
681 .constant => {681 .constant => {
682 const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;682 const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
683 return sema.air_values.items[ty_pl.payload];683 return sema.air_values.items[ty_pl.payload];
684 },684 },
685 .const_ty => {685 .const_ty => {
686 return sema.air_instructions.items(.data)[i].ty.toValue(undefined) catch unreachable;686 return try sema.air_instructions.items(.data)[i].ty.toValue(sema.arena);
687 },687 },
688 else => return null,688 else => return null,
689 }689 }
...@@ -739,7 +739,7 @@ pub fn resolveInstConst(...@@ -739,7 +739,7 @@ pub fn resolveInstConst(
739 const air_ref = sema.resolveInst(zir_ref);739 const air_ref = sema.resolveInst(zir_ref);
740 const val = try sema.resolveConstValue(block, src, air_ref);740 const val = try sema.resolveConstValue(block, src, air_ref);
741 return TypedValue{741 return TypedValue{
742 .ty = sema.getTypeOf(air_ref),742 .ty = sema.typeOf(air_ref),
743 .val = val,743 .val = val,
744 };744 };
745}745}
...@@ -1230,7 +1230,7 @@ fn ensureResultUsed(...@@ -1230,7 +1230,7 @@ fn ensureResultUsed(
1230 operand: Air.Inst.Ref,1230 operand: Air.Inst.Ref,
1231 src: LazySrcLoc,1231 src: LazySrcLoc,
1232) CompileError!void {1232) CompileError!void {
1233 const operand_ty = sema.getTypeOf(operand);1233 const operand_ty = sema.typeOf(operand);
1234 switch (operand_ty.zigTypeTag()) {1234 switch (operand_ty.zigTypeTag()) {
1235 .Void, .NoReturn => return,1235 .Void, .NoReturn => return,
1236 else => return sema.mod.fail(&block.base, src, "expression value is ignored", .{}),1236 else => return sema.mod.fail(&block.base, src, "expression value is ignored", .{}),
...@@ -1244,7 +1244,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -1244,7 +1244,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
1244 const inst_data = sema.code.instructions.items(.data)[inst].un_node;1244 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1245 const operand = sema.resolveInst(inst_data.operand);1245 const operand = sema.resolveInst(inst_data.operand);
1246 const src = inst_data.src();1246 const src = inst_data.src();
1247 const operand_ty = sema.getTypeOf(operand);1247 const operand_ty = sema.typeOf(operand);
1248 switch (operand_ty.zigTypeTag()) {1248 switch (operand_ty.zigTypeTag()) {
1249 .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}),1249 .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}),
1250 else => return,1250 else => return,
...@@ -1259,7 +1259,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co...@@ -1259,7 +1259,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
1259 const src = inst_data.src();1259 const src = inst_data.src();
1260 const array_ptr = sema.resolveInst(inst_data.operand);1260 const array_ptr = sema.resolveInst(inst_data.operand);
12611261
1262 const elem_ty = sema.getTypeOf(array_ptr).elemType();1262 const elem_ty = sema.typeOf(array_ptr).elemType();
1263 if (!elem_ty.isIndexable()) {1263 if (!elem_ty.isIndexable()) {
1264 const cond_src: LazySrcLoc = .{ .node_offset_for_cond = inst_data.src_node };1264 const cond_src: LazySrcLoc = .{ .node_offset_for_cond = inst_data.src_node };
1265 const msg = msg: {1265 const msg = msg: {
...@@ -1282,7 +1282,8 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co...@@ -1282,7 +1282,8 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
1282 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);1282 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
1283 }1283 }
1284 const result_ptr = try sema.namedFieldPtr(block, src, array_ptr, "len", src);1284 const result_ptr = try sema.namedFieldPtr(block, src, array_ptr, "len", src);
1285 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);1285 const result_ptr_src = src;
1286 return sema.analyzeLoad(block, src, result_ptr, result_ptr_src);
1286}1287}
12871288
1288fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {1289fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -1630,7 +1631,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -1630,7 +1631,7 @@ fn zirParamType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
16301631
1631 const inst_data = sema.code.instructions.items(.data)[inst].param_type;1632 const inst_data = sema.code.instructions.items(.data)[inst].param_type;
1632 const fn_inst = sema.resolveInst(inst_data.callee);1633 const fn_inst = sema.resolveInst(inst_data.callee);
1633 const fn_inst_ty = sema.getTypeOf(fn_inst);1634 const fn_inst_ty = sema.typeOf(fn_inst);
1634 const param_index = inst_data.param_index;1635 const param_index = inst_data.param_index;
16351636
1636 const fn_ty: Type = switch (fn_inst_ty.zigTypeTag()) {1637 const fn_ty: Type = switch (fn_inst_ty.zigTypeTag()) {
...@@ -1859,7 +1860,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -1859,7 +1860,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Compil
1859 sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity(1860 sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity(
1860 Air.Block{ .body_len = @intCast(u32, loop_block.instructions.items.len) },1861 Air.Block{ .body_len = @intCast(u32, loop_block.instructions.items.len) },
1861 );1862 );
1862 sema.air_extra.appendAssumeCapacity(loop_block.instructions.items);1863 sema.air_extra.appendSliceAssumeCapacity(loop_block.instructions.items);
1863 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);1864 return sema.analyzeBlockBody(parent_block, src, &child_block, merges);
1864}1865}
18651866
...@@ -1957,7 +1958,7 @@ fn analyzeBlockBody(...@@ -1957,7 +1958,7 @@ fn analyzeBlockBody(
19571958
1958 // Blocks must terminate with noreturn instruction.1959 // Blocks must terminate with noreturn instruction.
1959 assert(child_block.instructions.items.len != 0);1960 assert(child_block.instructions.items.len != 0);
1960 assert(sema.getTypeOf(indexToRef(child_block.instructions.items[child_block.instructions.items.len - 1])).isNoReturn());1961 assert(sema.typeOf(indexToRef(child_block.instructions.items[child_block.instructions.items.len - 1])).isNoReturn());
19611962
1962 if (merges.results.items.len == 0) {1963 if (merges.results.items.len == 0) {
1963 // No need for a block instruction. We can put the new instructions1964 // No need for a block instruction. We can put the new instructions
...@@ -1999,7 +2000,7 @@ fn analyzeBlockBody(...@@ -1999,7 +2000,7 @@ fn analyzeBlockBody(
1999 for (merges.br_list.items) |br| {2000 for (merges.br_list.items) |br| {
2000 const br_operand = sema.air_instructions.items(.data)[br].br.operand;2001 const br_operand = sema.air_instructions.items(.data)[br].br.operand;
2001 const br_operand_src = src;2002 const br_operand_src = src;
2002 const br_operand_ty = sema.getTypeOf(br_operand);2003 const br_operand_ty = sema.typeOf(br_operand);
2003 if (br_operand_ty.eql(resolved_ty)) {2004 if (br_operand_ty.eql(resolved_ty)) {
2004 // No type coercion needed.2005 // No type coercion needed.
2005 continue;2006 continue;
...@@ -2252,7 +2253,7 @@ fn analyzeCall(...@@ -2252,7 +2253,7 @@ fn analyzeCall(
2252 ensure_result_used: bool,2253 ensure_result_used: bool,
2253 args: []const Air.Inst.Ref,2254 args: []const Air.Inst.Ref,
2254) CompileError!Air.Inst.Ref {2255) CompileError!Air.Inst.Ref {
2255 const func_ty = sema.getTypeOf(func);2256 const func_ty = sema.typeOf(func);
2256 if (func_ty.zigTypeTag() != .Fn)2257 if (func_ty.zigTypeTag() != .Fn)
2257 return sema.mod.fail(&block.base, func_src, "type '{}' not a function", .{func_ty});2258 return sema.mod.fail(&block.base, func_src, "type '{}' not a function", .{func_ty});
22582259
...@@ -2606,8 +2607,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com...@@ -2606,8 +2607,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com
2606 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };2607 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
2607 const lhs = sema.resolveInst(extra.lhs);2608 const lhs = sema.resolveInst(extra.lhs);
2608 const rhs = sema.resolveInst(extra.rhs);2609 const rhs = sema.resolveInst(extra.rhs);
2609 const lhs_ty = sema.getTypeOf(lhs);2610 const lhs_ty = sema.typeOf(lhs);
2610 const rhs_ty = sema.getTypeOf(rhs);2611 const rhs_ty = sema.typeOf(rhs);
2611 if (rhs_ty.zigTypeTag() == .Bool and lhs_ty.zigTypeTag() == .Bool) {2612 if (rhs_ty.zigTypeTag() == .Bool and lhs_ty.zigTypeTag() == .Bool) {
2612 const msg = msg: {2613 const msg = msg: {
2613 const msg = try sema.mod.errMsg(&block.base, lhs_src, "expected error set type, found 'bool'", .{});2614 const msg = try sema.mod.errMsg(&block.base, lhs_src, "expected error set type, found 'bool'", .{});
...@@ -2699,7 +2700,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -2699,7 +2700,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
2699 const src = inst_data.src();2700 const src = inst_data.src();
2700 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };2701 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2701 const operand = sema.resolveInst(inst_data.operand);2702 const operand = sema.resolveInst(inst_data.operand);
2702 const operand_ty = sema.getTypeOf(operand);2703 const operand_ty = sema.typeOf(operand);
27032704
2704 const enum_tag: Air.Inst.Ref = switch (operand_ty.zigTypeTag()) {2705 const enum_tag: Air.Inst.Ref = switch (operand_ty.zigTypeTag()) {
2705 .Enum => operand,2706 .Enum => operand,
...@@ -2720,7 +2721,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -2720,7 +2721,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
2720 });2721 });
2721 },2722 },
2722 };2723 };
2723 const enum_tag_ty = sema.getTypeOf(enum_tag);2724 const enum_tag_ty = sema.typeOf(enum_tag);
27242725
2725 var int_tag_type_buffer: Type.Payload.Bits = undefined;2726 var int_tag_type_buffer: Type.Payload.Bits = undefined;
2726 const int_tag_ty = try enum_tag_ty.intTagType(&int_tag_type_buffer).copy(arena);2727 const int_tag_ty = try enum_tag_ty.intTagType(&int_tag_type_buffer).copy(arena);
...@@ -2821,7 +2822,7 @@ fn zirOptionalPayloadPtr(...@@ -2821,7 +2822,7 @@ fn zirOptionalPayloadPtr(
28212822
2822 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2823 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2823 const optional_ptr = sema.resolveInst(inst_data.operand);2824 const optional_ptr = sema.resolveInst(inst_data.operand);
2824 const optional_ptr_ty = sema.getTypeOf(optional_ptr);2825 const optional_ptr_ty = sema.typeOf(optional_ptr);
2825 assert(optional_ptr_ty.zigTypeTag() == .Pointer);2826 assert(optional_ptr_ty.zigTypeTag() == .Pointer);
2826 const src = inst_data.src();2827 const src = inst_data.src();
28272828
...@@ -2863,7 +2864,7 @@ fn zirOptionalPayload(...@@ -2863,7 +2864,7 @@ fn zirOptionalPayload(
2863 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2864 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2864 const src = inst_data.src();2865 const src = inst_data.src();
2865 const operand = sema.resolveInst(inst_data.operand);2866 const operand = sema.resolveInst(inst_data.operand);
2866 const operand_ty = sema.getTypeOf(operand);2867 const operand_ty = sema.typeOf(operand);
2867 const opt_type = operand_ty;2868 const opt_type = operand_ty;
2868 if (opt_type.zigTypeTag() != .Optional) {2869 if (opt_type.zigTypeTag() != .Optional) {
2869 return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type});2870 return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type});
...@@ -2900,7 +2901,7 @@ fn zirErrUnionPayload(...@@ -2900,7 +2901,7 @@ fn zirErrUnionPayload(
2900 const src = inst_data.src();2901 const src = inst_data.src();
2901 const operand = sema.resolveInst(inst_data.operand);2902 const operand = sema.resolveInst(inst_data.operand);
2902 const operand_src = src;2903 const operand_src = src;
2903 const operand_ty = sema.getTypeOf(operand);2904 const operand_ty = sema.typeOf(operand);
2904 if (operand_ty.zigTypeTag() != .ErrorUnion)2905 if (operand_ty.zigTypeTag() != .ErrorUnion)
2905 return sema.mod.fail(&block.base, operand_src, "expected error union type, found '{}'", .{operand_ty});2906 return sema.mod.fail(&block.base, operand_src, "expected error union type, found '{}'", .{operand_ty});
29062907
...@@ -2936,7 +2937,7 @@ fn zirErrUnionPayloadPtr(...@@ -2936,7 +2937,7 @@ fn zirErrUnionPayloadPtr(
2936 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2937 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2937 const src = inst_data.src();2938 const src = inst_data.src();
2938 const operand = sema.resolveInst(inst_data.operand);2939 const operand = sema.resolveInst(inst_data.operand);
2939 const operand_ty = sema.getTypeOf(operand);2940 const operand_ty = sema.typeOf(operand);
2940 assert(operand_ty.zigTypeTag() == .Pointer);2941 assert(operand_ty.zigTypeTag() == .Pointer);
29412942
2942 if (operand_ty.elemType().zigTypeTag() != .ErrorUnion)2943 if (operand_ty.elemType().zigTypeTag() != .ErrorUnion)
...@@ -2976,7 +2977,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi...@@ -2976,7 +2977,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi
2976 const inst_data = sema.code.instructions.items(.data)[inst].un_node;2977 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
2977 const src = inst_data.src();2978 const src = inst_data.src();
2978 const operand = sema.resolveInst(inst_data.operand);2979 const operand = sema.resolveInst(inst_data.operand);
2979 const operand_ty = sema.getTypeOf(operand);2980 const operand_ty = sema.typeOf(operand);
2980 if (operand_ty.zigTypeTag() != .ErrorUnion)2981 if (operand_ty.zigTypeTag() != .ErrorUnion)
2981 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty});2982 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty});
29822983
...@@ -3000,7 +3001,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co...@@ -3000,7 +3001,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
3000 const inst_data = sema.code.instructions.items(.data)[inst].un_node;3001 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3001 const src = inst_data.src();3002 const src = inst_data.src();
3002 const operand = sema.resolveInst(inst_data.operand);3003 const operand = sema.resolveInst(inst_data.operand);
3003 const operand_ty = sema.getTypeOf(operand);3004 const operand_ty = sema.typeOf(operand);
3004 assert(operand_ty.zigTypeTag() == .Pointer);3005 assert(operand_ty.zigTypeTag() == .Pointer);
30053006
3006 if (operand_ty.elemType().zigTypeTag() != .ErrorUnion)3007 if (operand_ty.elemType().zigTypeTag() != .ErrorUnion)
...@@ -3026,7 +3027,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde...@@ -3026,7 +3027,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
3026 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;3027 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
3027 const src = inst_data.src();3028 const src = inst_data.src();
3028 const operand = sema.resolveInst(inst_data.operand);3029 const operand = sema.resolveInst(inst_data.operand);
3029 const operand_ty = sema.getTypeOf(operand);3030 const operand_ty = sema.typeOf(operand);
3030 if (operand_ty.zigTypeTag() != .ErrorUnion)3031 if (operand_ty.zigTypeTag() != .ErrorUnion)
3031 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty});3032 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty});
3032 if (operand_ty.castTag(.error_union).?.data.payload.zigTypeTag() != .Void) {3033 if (operand_ty.castTag(.error_union).?.data.payload.zigTypeTag() != .Void) {
...@@ -3214,7 +3215,6 @@ fn funcCommon(...@@ -3214,7 +3215,6 @@ fn funcCommon(
3214 .state = anal_state,3215 .state = anal_state,
3215 .zir_body_inst = body_inst,3216 .zir_body_inst = body_inst,
3216 .owner_decl = sema.owner_decl,3217 .owner_decl = sema.owner_decl,
3217 .body = undefined,
3218 .lbrace_line = src_locs.lbrace_line,3218 .lbrace_line = src_locs.lbrace_line,
3219 .rbrace_line = src_locs.rbrace_line,3219 .rbrace_line = src_locs.rbrace_line,
3220 .lbrace_column = @truncate(u16, src_locs.columns),3220 .lbrace_column = @truncate(u16, src_locs.columns),
...@@ -3283,12 +3283,13 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -3283,12 +3283,13 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
3283 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;3283 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
3284 const field_name = sema.code.nullTerminatedString(extra.field_name_start);3284 const field_name = sema.code.nullTerminatedString(extra.field_name_start);
3285 const object = sema.resolveInst(extra.lhs);3285 const object = sema.resolveInst(extra.lhs);
3286 const object_ptr = if (sema.getTypeOf(object).zigTypeTag() == .Pointer)3286 const object_ptr = if (sema.typeOf(object).zigTypeTag() == .Pointer)
3287 object3287 object
3288 else3288 else
3289 try sema.analyzeRef(block, src, object);3289 try sema.analyzeRef(block, src, object);
3290 const result_ptr = try sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);3290 const result_ptr = try sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
3291 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);3291 const result_ptr_src = src;
3292 return sema.analyzeLoad(block, src, result_ptr, result_ptr_src);
3292}3293}
32933294
3294fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3295fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -3356,7 +3357,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -3356,7 +3357,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
3356 ),3357 ),
3357 };3358 };
33583359
3359 const operand_ty = sema.getTypeOf(operand);3360 const operand_ty = sema.typeOf(operand);
3360 switch (operand_ty.zigTypeTag()) {3361 switch (operand_ty.zigTypeTag()) {
3361 .ComptimeInt, .Int => {},3362 .ComptimeInt, .Int => {},
3362 else => return sema.mod.fail(3363 else => return sema.mod.fail(
...@@ -3414,7 +3415,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE...@@ -3414,7 +3415,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
3414 ),3415 ),
3415 };3416 };
34163417
3417 const operand_ty = sema.getTypeOf(operand);3418 const operand_ty = sema.typeOf(operand);
3418 switch (operand_ty.zigTypeTag()) {3419 switch (operand_ty.zigTypeTag()) {
3419 .ComptimeFloat, .Float, .ComptimeInt => {},3420 .ComptimeFloat, .Float, .ComptimeInt => {},
3420 else => return sema.mod.fail(3421 else => return sema.mod.fail(
...@@ -3440,7 +3441,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr...@@ -3440,7 +3441,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
34403441
3441 const bin_inst = sema.code.instructions.items(.data)[inst].bin;3442 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
3442 const array = sema.resolveInst(bin_inst.lhs);3443 const array = sema.resolveInst(bin_inst.lhs);
3443 const array_ty = sema.getTypeOf(array);3444 const array_ty = sema.typeOf(array);
3444 const array_ptr = if (array_ty.zigTypeTag() == .Pointer)3445 const array_ptr = if (array_ty.zigTypeTag() == .Pointer)
3445 array3446 array
3446 else3447 else
...@@ -3459,7 +3460,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil...@@ -3459,7 +3460,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
3459 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };3460 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
3460 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;3461 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
3461 const array = sema.resolveInst(extra.lhs);3462 const array = sema.resolveInst(extra.lhs);
3462 const array_ty = sema.getTypeOf(array);3463 const array_ty = sema.typeOf(array);
3463 const array_ptr = if (array_ty.zigTypeTag() == .Pointer)3464 const array_ptr = if (array_ty.zigTypeTag() == .Pointer)
3464 array3465 array
3465 else3466 else
...@@ -3502,7 +3503,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile...@@ -3502,7 +3503,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
3502 const array_ptr = sema.resolveInst(extra.lhs);3503 const array_ptr = sema.resolveInst(extra.lhs);
3503 const start = sema.resolveInst(extra.start);3504 const start = sema.resolveInst(extra.start);
35043505
3505 return sema.analyzeSlice(block, src, array_ptr, start, null, null, .unneeded);3506 return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded);
3506}3507}
35073508
3508fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3509fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -3516,7 +3517,7 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -3516,7 +3517,7 @@ fn zirSliceEnd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
3516 const start = sema.resolveInst(extra.start);3517 const start = sema.resolveInst(extra.start);
3517 const end = sema.resolveInst(extra.end);3518 const end = sema.resolveInst(extra.end);
35183519
3519 return sema.analyzeSlice(block, src, array_ptr, start, end, null, .unneeded);3520 return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded);
3520}3521}
35213522
3522fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3523fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -3668,7 +3669,7 @@ fn analyzeSwitch(...@@ -3668,7 +3669,7 @@ fn analyzeSwitch(
3668 const src: LazySrcLoc = .{ .node_offset = src_node_offset };3669 const src: LazySrcLoc = .{ .node_offset = src_node_offset };
3669 const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset };3670 const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset };
3670 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };3671 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };
3671 const operand_ty = sema.getTypeOf(operand);3672 const operand_ty = sema.typeOf(operand);
36723673
3673 // Validate usage of '_' prongs.3674 // Validate usage of '_' prongs.
3674 if (special_prong == .under and !operand_ty.isNonexhaustiveEnum()) {3675 if (special_prong == .under and !operand_ty.isNonexhaustiveEnum()) {
...@@ -4590,8 +4591,8 @@ fn zirBitwise(...@@ -4590,8 +4591,8 @@ fn zirBitwise(
4590 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;4591 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4591 const lhs = sema.resolveInst(extra.lhs);4592 const lhs = sema.resolveInst(extra.lhs);
4592 const rhs = sema.resolveInst(extra.rhs);4593 const rhs = sema.resolveInst(extra.rhs);
4593 const lhs_ty = sema.getTypeOf(lhs);4594 const lhs_ty = sema.typeOf(lhs);
4594 const rhs_ty = sema.getTypeOf(rhs);4595 const rhs_ty = sema.typeOf(rhs);
45954596
4596 const instructions = &[_]Air.Inst.Ref{ lhs, rhs };4597 const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
4597 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);4598 const resolved_type = try sema.resolvePeerTypes(block, src, instructions);
...@@ -4722,8 +4723,8 @@ fn analyzeArithmetic(...@@ -4722,8 +4723,8 @@ fn analyzeArithmetic(
4722 lhs_src: LazySrcLoc,4723 lhs_src: LazySrcLoc,
4723 rhs_src: LazySrcLoc,4724 rhs_src: LazySrcLoc,
4724) CompileError!Air.Inst.Ref {4725) CompileError!Air.Inst.Ref {
4725 const lhs_ty = sema.getTypeOf(lhs);4726 const lhs_ty = sema.typeOf(lhs);
4726 const rhs_ty = sema.getTypeOf(rhs);4727 const rhs_ty = sema.typeOf(rhs);
4727 if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) {4728 if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) {
4728 if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) {4729 if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) {
4729 return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{4730 return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{
...@@ -4944,8 +4945,8 @@ fn zirCmp(...@@ -4944,8 +4945,8 @@ fn zirCmp(
4944 .eq, .neq => true,4945 .eq, .neq => true,
4945 else => false,4946 else => false,
4946 };4947 };
4947 const lhs_ty = sema.getTypeOf(lhs);4948 const lhs_ty = sema.typeOf(lhs);
4948 const rhs_ty = sema.getTypeOf(rhs);4949 const rhs_ty = sema.typeOf(rhs);
4949 const lhs_ty_tag = lhs_ty.zigTypeTag();4950 const lhs_ty_tag = lhs_ty.zigTypeTag();
4950 const rhs_ty_tag = rhs_ty.zigTypeTag();4951 const rhs_ty_tag = rhs_ty.zigTypeTag();
4951 if (is_equality_cmp and lhs_ty_tag == .Null and rhs_ty_tag == .Null) {4952 if (is_equality_cmp and lhs_ty_tag == .Null and rhs_ty_tag == .Null) {
...@@ -5007,8 +5008,8 @@ fn zirCmp(...@@ -5007,8 +5008,8 @@ fn zirCmp(
5007 if (!is_equality_cmp) {5008 if (!is_equality_cmp) {
5008 return mod.fail(&block.base, src, "{s} operator not allowed for types", .{@tagName(op)});5009 return mod.fail(&block.base, src, "{s} operator not allowed for types", .{@tagName(op)});
5009 }5010 }
5010 const lhs_as_type = try sema.resolveAirAsType(block, lhs_src, lhs);5011 const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs);
5011 const rhs_as_type = try sema.resolveAirAsType(block, rhs_src, rhs);5012 const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs);
5012 if (lhs_as_type.eql(rhs_as_type) == (op == .eq)) {5013 if (lhs_as_type.eql(rhs_as_type) == (op == .eq)) {
5013 return Air.Inst.Ref.bool_true;5014 return Air.Inst.Ref.bool_true;
5014 } else {5015 } else {
...@@ -5144,7 +5145,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro...@@ -5144,7 +5145,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
5144 const zir_datas = sema.code.instructions.items(.data);5145 const zir_datas = sema.code.instructions.items(.data);
5145 const inst_data = zir_datas[inst].un_node;5146 const inst_data = zir_datas[inst].un_node;
5146 const operand = sema.resolveInst(inst_data.operand);5147 const operand = sema.resolveInst(inst_data.operand);
5147 const operand_ty = sema.getTypeOf(operand);5148 const operand_ty = sema.typeOf(operand);
5148 return sema.addType(operand_ty);5149 return sema.addType(operand_ty);
5149}5150}
51505151
...@@ -6375,7 +6376,7 @@ fn addSafetyCheck(...@@ -6375,7 +6376,7 @@ fn addSafetyCheck(
6375 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);6376 const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len);
6376 const cond_br_inst = block_inst + 1;6377 const cond_br_inst = block_inst + 1;
6377 const br_inst = cond_br_inst + 1;6378 const br_inst = cond_br_inst + 1;
6378 sema.air_instructions.appendAssumeCapacity(gpa, .{6379 sema.air_instructions.appendAssumeCapacity(.{
6379 .tag = .block,6380 .tag = .block,
6380 .data = .{ .ty_pl = .{6381 .data = .{ .ty_pl = .{
6381 .ty = .void_type,6382 .ty = .void_type,
...@@ -6386,7 +6387,7 @@ fn addSafetyCheck(...@@ -6386,7 +6387,7 @@ fn addSafetyCheck(
6386 });6387 });
6387 sema.air_extra.appendAssumeCapacity(cond_br_inst);6388 sema.air_extra.appendAssumeCapacity(cond_br_inst);
63886389
6389 sema.air_instructions.appendAssumeCapacity(gpa, .{6390 sema.air_instructions.appendAssumeCapacity(.{
6390 .tag = .cond_br,6391 .tag = .cond_br,
6391 .data = .{ .pl_op = .{6392 .data = .{ .pl_op = .{
6392 .operand = ok,6393 .operand = ok,
...@@ -6399,7 +6400,7 @@ fn addSafetyCheck(...@@ -6399,7 +6400,7 @@ fn addSafetyCheck(
6399 sema.air_extra.appendAssumeCapacity(br_inst);6400 sema.air_extra.appendAssumeCapacity(br_inst);
6400 sema.air_extra.appendSliceAssumeCapacity(fail_block.instructions.items);6401 sema.air_extra.appendSliceAssumeCapacity(fail_block.instructions.items);
64016402
6402 sema.air_instructions.appendAssumeCapacity(gpa, .{6403 sema.air_instructions.appendAssumeCapacity(.{
6403 .tag = .br,6404 .tag = .br,
6404 .data = .{ .br = .{6405 .data = .{ .br = .{
6405 .block_inst = block_inst,6406 .block_inst = block_inst,
...@@ -6497,9 +6498,11 @@ fn namedFieldPtr(...@@ -6497,9 +6498,11 @@ fn namedFieldPtr(
6497 const mod = sema.mod;6498 const mod = sema.mod;
6498 const arena = sema.arena;6499 const arena = sema.arena;
64996500
6500 const elem_ty = switch (object_ptr.ty.zigTypeTag()) {6501 const object_ptr_src = src; // TODO better source location
6501 .Pointer => object_ptr.ty.elemType(),6502 const object_ptr_ty = sema.typeOf(object_ptr);
6502 else => return mod.fail(&block.base, object_ptr.src, "expected pointer, found '{}'", .{object_ptr.ty}),6503 const elem_ty = switch (object_ptr_ty.zigTypeTag()) {
6504 .Pointer => object_ptr_ty.elemType(),
6505 else => return mod.fail(&block.base, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty}),
6503 };6506 };
6504 switch (elem_ty.zigTypeTag()) {6507 switch (elem_ty.zigTypeTag()) {
6505 .Array => {6508 .Array => {
...@@ -6545,9 +6548,9 @@ fn namedFieldPtr(...@@ -6545,9 +6548,9 @@ fn namedFieldPtr(
6545 }6548 }
6546 },6549 },
6547 .Type => {6550 .Type => {
6548 _ = try sema.resolveConstValue(block, object_ptr.src, object_ptr);6551 _ = try sema.resolveConstValue(block, object_ptr_src, object_ptr);
6549 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr.src);6552 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);
6550 const val = result.value().?;6553 const val = (sema.resolveDefinedValue(block, src, result) catch unreachable).?;
6551 const child_type = try val.toType(arena);6554 const child_type = try val.toType(arena);
6552 switch (child_type.zigTypeTag()) {6555 switch (child_type.zigTypeTag()) {
6553 .ErrorSet => {6556 .ErrorSet => {
...@@ -6694,7 +6697,16 @@ fn analyzeStructFieldPtr(...@@ -6694,7 +6697,16 @@ fn analyzeStructFieldPtr(
6694 }6697 }
66956698
6696 try sema.requireRuntimeBlock(block, src);6699 try sema.requireRuntimeBlock(block, src);
6697 return block.addStructFieldPtr(src, ptr_field_ty, struct_ptr, @intCast(u32, field_index));6700 return block.addInst(.{
6701 .tag = .struct_field_ptr,
6702 .data = .{ .ty_pl = .{
6703 .ty = try sema.addType(ptr_field_ty),
6704 .payload = try sema.addExtra(Air.StructField{
6705 .struct_ptr = struct_ptr,
6706 .field_index = @intCast(u32, field_index),
6707 }),
6708 } },
6709 });
6698}6710}
66996711
6700fn analyzeUnionFieldPtr(6712fn analyzeUnionFieldPtr(
...@@ -6742,16 +6754,18 @@ fn elemPtr(...@@ -6742,16 +6754,18 @@ fn elemPtr(
6742 elem_index: Air.Inst.Ref,6754 elem_index: Air.Inst.Ref,
6743 elem_index_src: LazySrcLoc,6755 elem_index_src: LazySrcLoc,
6744) CompileError!Air.Inst.Ref {6756) CompileError!Air.Inst.Ref {
6745 const array_ty = switch (array_ptr.ty.zigTypeTag()) {6757 const array_ptr_src = src; // TODO better source location
6746 .Pointer => array_ptr.ty.elemType(),6758 const array_ptr_ty = sema.typeOf(array_ptr);
6747 else => return sema.mod.fail(&block.base, array_ptr.src, "expected pointer, found '{}'", .{array_ptr.ty}),6759 const array_ty = switch (array_ptr_ty.zigTypeTag()) {
6760 .Pointer => array_ptr_ty.elemType(),
6761 else => return sema.mod.fail(&block.base, array_ptr_src, "expected pointer, found '{}'", .{array_ptr_ty}),
6748 };6762 };
6749 if (!array_ty.isIndexable()) {6763 if (!array_ty.isIndexable()) {
6750 return sema.mod.fail(&block.base, src, "array access of non-array type '{}'", .{array_ty});6764 return sema.mod.fail(&block.base, src, "array access of non-array type '{}'", .{array_ty});
6751 }6765 }
6752 if (array_ty.isSinglePointer() and array_ty.elemType().zigTypeTag() == .Array) {6766 if (array_ty.isSinglePointer() and array_ty.elemType().zigTypeTag() == .Array) {
6753 // we have to deref the ptr operand to get the actual array pointer6767 // we have to deref the ptr operand to get the actual array pointer
6754 const array_ptr_deref = try sema.analyzeLoad(block, src, array_ptr, array_ptr.src);6768 const array_ptr_deref = try sema.analyzeLoad(block, src, array_ptr, array_ptr_src);
6755 return sema.elemPtrArray(block, src, array_ptr_deref, elem_index, elem_index_src);6769 return sema.elemPtrArray(block, src, array_ptr_deref, elem_index, elem_index_src);
6756 }6770 }
6757 if (array_ty.zigTypeTag() == .Array) {6771 if (array_ty.zigTypeTag() == .Array) {
...@@ -6776,7 +6790,7 @@ fn elemPtrArray(...@@ -6776,7 +6790,7 @@ fn elemPtrArray(
6776 // @intCast here because it would have been impossible to construct a value that6790 // @intCast here because it would have been impossible to construct a value that
6777 // required a larger index.6791 // required a larger index.
6778 const elem_ptr = try array_ptr_val.elemPtr(sema.arena, @intCast(usize, index_u64));6792 const elem_ptr = try array_ptr_val.elemPtr(sema.arena, @intCast(usize, index_u64));
6779 const pointee_type = array_ptr.ty.elemType().elemType();6793 const pointee_type = sema.typeOf(array_ptr).elemType().elemType();
67806794
6781 return sema.addConstant(6795 return sema.addConstant(
6782 try Type.Tag.single_const_pointer.create(sema.arena, pointee_type),6796 try Type.Tag.single_const_pointer.create(sema.arena, pointee_type),
...@@ -6800,7 +6814,7 @@ fn coerce(...@@ -6800,7 +6814,7 @@ fn coerce(
6800 return sema.coerceVarArgParam(block, inst, inst_src);6814 return sema.coerceVarArgParam(block, inst, inst_src);
6801 }6815 }
68026816
6803 const inst_ty = sema.getTypeOf(inst);6817 const inst_ty = sema.typeOf(inst);
6804 // If the types are the same, we can return the operand.6818 // If the types are the same, we can return the operand.
6805 if (dest_type.eql(inst_ty))6819 if (dest_type.eql(inst_ty))
6806 return inst;6820 return inst;
...@@ -7021,7 +7035,7 @@ fn coerceVarArgParam(...@@ -7021,7 +7035,7 @@ fn coerceVarArgParam(
7021 inst: Air.Inst.Ref,7035 inst: Air.Inst.Ref,
7022 inst_src: LazySrcLoc,7036 inst_src: LazySrcLoc,
7023) !Air.Inst.Ref {7037) !Air.Inst.Ref {
7024 const inst_ty = sema.getTypeOf(inst);7038 const inst_ty = sema.typeOf(inst);
7025 switch (inst_ty.zigTypeTag()) {7039 switch (inst_ty.zigTypeTag()) {
7026 .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst_src, "integer and float literals in var args function must be casted", .{}),7040 .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst_src, "integer and float literals in var args function must be casted", .{}),
7027 else => {},7041 else => {},
...@@ -7170,8 +7184,8 @@ fn analyzeRef(...@@ -7170,8 +7184,8 @@ fn analyzeRef(
7170 src: LazySrcLoc,7184 src: LazySrcLoc,
7171 operand: Air.Inst.Ref,7185 operand: Air.Inst.Ref,
7172) CompileError!Air.Inst.Ref {7186) CompileError!Air.Inst.Ref {
7173 const operand_ty = sema.getTypeOf(operand);7187 const operand_ty = sema.typeOf(operand);
7174 const ptr_type = try sema.mod.simplePtrType(sema.arena, operand_ty, false, .One);7188 const ptr_type = try Module.simplePtrType(sema.arena, operand_ty, false, .One);
71757189
7176 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |val| {7190 if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |val| {
7177 return sema.addConstant(ptr_type, try Value.Tag.ref_val.create(sema.arena, val));7191 return sema.addConstant(ptr_type, try Value.Tag.ref_val.create(sema.arena, val));
...@@ -7188,7 +7202,7 @@ fn analyzeLoad(...@@ -7188,7 +7202,7 @@ fn analyzeLoad(
7188 ptr: Air.Inst.Ref,7202 ptr: Air.Inst.Ref,
7189 ptr_src: LazySrcLoc,7203 ptr_src: LazySrcLoc,
7190) CompileError!Air.Inst.Ref {7204) CompileError!Air.Inst.Ref {
7191 const ptr_ty = sema.getTypeOf(ptr);7205 const ptr_ty = sema.typeOf(ptr);
7192 const elem_ty = switch (ptr_ty.zigTypeTag()) {7206 const elem_ty = switch (ptr_ty.zigTypeTag()) {
7193 .Pointer => ptr_ty.elemType(),7207 .Pointer => ptr_ty.elemType(),
7194 else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}),7208 else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}),
...@@ -7235,7 +7249,7 @@ fn analyzeIsNonErr(...@@ -7235,7 +7249,7 @@ fn analyzeIsNonErr(
7235 src: LazySrcLoc,7249 src: LazySrcLoc,
7236 operand: Air.Inst.Ref,7250 operand: Air.Inst.Ref,
7237) CompileError!Air.Inst.Ref {7251) CompileError!Air.Inst.Ref {
7238 const operand_ty = sema.getTypeOf(operand);7252 const operand_ty = sema.typeOf(operand);
7239 const ot = operand_ty.zigTypeTag();7253 const ot = operand_ty.zigTypeTag();
7240 if (ot != .ErrorSet and ot != .ErrorUnion) return Air.Inst.Ref.bool_true;7254 if (ot != .ErrorSet and ot != .ErrorUnion) return Air.Inst.Ref.bool_true;
7241 if (ot == .ErrorSet) return Air.Inst.Ref.bool_false;7255 if (ot == .ErrorSet) return Air.Inst.Ref.bool_false;
...@@ -7261,13 +7275,14 @@ fn analyzeSlice(...@@ -7261,13 +7275,14 @@ fn analyzeSlice(
7261 src: LazySrcLoc,7275 src: LazySrcLoc,
7262 array_ptr: Air.Inst.Ref,7276 array_ptr: Air.Inst.Ref,
7263 start: Air.Inst.Ref,7277 start: Air.Inst.Ref,
7264 end_opt: ?Air.Inst.Index,7278 end_opt: Air.Inst.Ref,
7265 sentinel_opt: ?Air.Inst.Index,7279 sentinel_opt: Air.Inst.Ref,
7266 sentinel_src: LazySrcLoc,7280 sentinel_src: LazySrcLoc,
7267) CompileError!Air.Inst.Ref {7281) CompileError!Air.Inst.Ref {
7268 const ptr_child = switch (array_ptr.ty.zigTypeTag()) {7282 const array_ptr_ty = sema.typeOf(array_ptr);
7269 .Pointer => array_ptr.ty.elemType(),7283 const ptr_child = switch (array_ptr_ty.zigTypeTag()) {
7270 else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr.ty}),7284 .Pointer => array_ptr_ty.elemType(),
7285 else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr_ty}),
7271 };7286 };
72727287
7273 var array_type = ptr_child;7288 var array_type = ptr_child;
...@@ -7287,15 +7302,15 @@ fn analyzeSlice(...@@ -7287,15 +7302,15 @@ fn analyzeSlice(
7287 else => return sema.mod.fail(&block.base, src, "slice of non-array type '{}'", .{ptr_child}),7302 else => return sema.mod.fail(&block.base, src, "slice of non-array type '{}'", .{ptr_child}),
7288 };7303 };
72897304
7290 const slice_sentinel = if (sentinel_opt) |sentinel| blk: {7305 const slice_sentinel = if (sentinel_opt != .none) blk: {
7291 const casted = try sema.coerce(block, elem_type, sentinel, sentinel.src);7306 const casted = try sema.coerce(block, elem_type, sentinel_opt, sentinel_src);
7292 break :blk try sema.resolveConstValue(block, sentinel_src, casted);7307 break :blk try sema.resolveConstValue(block, sentinel_src, casted);
7293 } else null;7308 } else null;
72947309
7295 var return_ptr_size: std.builtin.TypeInfo.Pointer.Size = .Slice;7310 var return_ptr_size: std.builtin.TypeInfo.Pointer.Size = .Slice;
7296 var return_elem_type = elem_type;7311 var return_elem_type = elem_type;
7297 if (end_opt) |end| {7312 if (end_opt != .none) {
7298 if (try sema.resolveDefinedValue(block, src, end)) |end_val| {7313 if (try sema.resolveDefinedValue(block, src, end_opt)) |end_val| {
7299 if (try sema.resolveDefinedValue(block, src, start)) |start_val| {7314 if (try sema.resolveDefinedValue(block, src, start)) |start_val| {
7300 const start_u64 = start_val.toUnsignedInt();7315 const start_u64 = start_val.toUnsignedInt();
7301 const end_u64 = end_val.toUnsignedInt();7316 const end_u64 = end_val.toUnsignedInt();
...@@ -7316,7 +7331,7 @@ fn analyzeSlice(...@@ -7316,7 +7331,7 @@ fn analyzeSlice(
7316 const return_type = try sema.mod.ptrType(7331 const return_type = try sema.mod.ptrType(
7317 sema.arena,7332 sema.arena,
7318 return_elem_type,7333 return_elem_type,
7319 if (end_opt == null) slice_sentinel else null,7334 if (end_opt == .none) slice_sentinel else null,
7320 0, // TODO alignment7335 0, // TODO alignment
7321 0,7336 0,
7322 0,7337 0,
...@@ -7341,8 +7356,8 @@ fn cmpNumeric(...@@ -7341,8 +7356,8 @@ fn cmpNumeric(
7341 lhs_src: LazySrcLoc,7356 lhs_src: LazySrcLoc,
7342 rhs_src: LazySrcLoc,7357 rhs_src: LazySrcLoc,
7343) CompileError!Air.Inst.Ref {7358) CompileError!Air.Inst.Ref {
7344 const lhs_ty = sema.getTypeOf(lhs);7359 const lhs_ty = sema.typeOf(lhs);
7345 const rhs_ty = sema.getTypeOf(rhs);7360 const rhs_ty = sema.typeOf(rhs);
73467361
7347 assert(lhs_ty.isNumeric());7362 assert(lhs_ty.isNumeric());
7348 assert(rhs_ty.isNumeric());7363 assert(rhs_ty.isNumeric());
...@@ -7609,14 +7624,14 @@ fn resolvePeerTypes(...@@ -7609,14 +7624,14 @@ fn resolvePeerTypes(
7609 return Type.initTag(.noreturn);7624 return Type.initTag(.noreturn);
76107625
7611 if (instructions.len == 1)7626 if (instructions.len == 1)
7612 return sema.getTypeOf(instructions[0]);7627 return sema.typeOf(instructions[0]);
76137628
7614 const target = sema.mod.getTarget();7629 const target = sema.mod.getTarget();
76157630
7616 var chosen = instructions[0];7631 var chosen = instructions[0];
7617 for (instructions[1..]) |candidate| {7632 for (instructions[1..]) |candidate| {
7618 const candidate_ty = sema.getTypeOf(candidate);7633 const candidate_ty = sema.typeOf(candidate);
7619 const chosen_ty = sema.getTypeOf(chosen);7634 const chosen_ty = sema.typeOf(chosen);
7620 if (candidate_ty.eql(chosen_ty))7635 if (candidate_ty.eql(chosen_ty))
7621 continue;7636 continue;
7622 if (candidate_ty.zigTypeTag() == .NoReturn)7637 if (candidate_ty.zigTypeTag() == .NoReturn)
...@@ -7677,7 +7692,7 @@ fn resolvePeerTypes(...@@ -7677,7 +7692,7 @@ fn resolvePeerTypes(
7677 return sema.mod.fail(&block.base, src, "incompatible types: '{}' and '{}'", .{ chosen_ty, candidate_ty });7692 return sema.mod.fail(&block.base, src, "incompatible types: '{}' and '{}'", .{ chosen_ty, candidate_ty });
7678 }7693 }
76797694
7680 return sema.getTypeOf(chosen);7695 return sema.typeOf(chosen);
7681}7696}
76827697
7683fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!Type {7698fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!Type {
...@@ -7753,7 +7768,7 @@ fn getBuiltin(...@@ -7753,7 +7768,7 @@ fn getBuiltin(
7753 "builtin",7768 "builtin",
7754 );7769 );
7755 const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst.?, src);7770 const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst.?, src);
7756 const builtin_ty = try sema.resolveAirAsType(block, src, builtin_inst);7771 const builtin_ty = try sema.analyzeAsType(block, src, builtin_inst);
7757 const opt_ty_inst = try sema.analyzeNamespaceLookup(7772 const opt_ty_inst = try sema.analyzeNamespaceLookup(
7758 block,7773 block,
7759 src,7774 src,
...@@ -7770,7 +7785,7 @@ fn getBuiltinType(...@@ -7770,7 +7785,7 @@ fn getBuiltinType(
7770 name: []const u8,7785 name: []const u8,
7771) CompileError!Type {7786) CompileError!Type {
7772 const ty_inst = try sema.getBuiltin(block, src, name);7787 const ty_inst = try sema.getBuiltin(block, src, name);
7773 return sema.resolveAirAsType(block, src, ty_inst);7788 return sema.analyzeAsType(block, src, ty_inst);
7774}7789}
77757790
7776/// There is another implementation of this in `Type.onePossibleValue`. This one7791/// There is another implementation of this in `Type.onePossibleValue`. This one
...@@ -7970,70 +7985,104 @@ fn enumFieldSrcLoc(...@@ -7970,70 +7985,104 @@ fn enumFieldSrcLoc(
7970 } else unreachable;7985 } else unreachable;
7971}7986}
79727987
7988/// This is only meant to be called by `typeOf`.
7989fn analyzeAsTypeInfallible(sema: *Sema, inst: Air.Inst.Ref) Type {
7990 var i: usize = @enumToInt(inst);
7991 if (i < Air.Inst.Ref.typed_value_map.len) {
7992 return Air.Inst.Ref.typed_value_map[i].val.toType(undefined) catch unreachable;
7993 }
7994 i -= Air.Inst.Ref.typed_value_map.len;
7995 assert(sema.air_instructions.items(.tag)[i] == .const_ty);
7996 return sema.air_instructions.items(.data)[i].ty;
7997}
7998
7973/// Returns the type of the AIR instruction.7999/// Returns the type of the AIR instruction.
7974fn getTypeOf(sema: *Sema, air_ref: Air.Inst.Ref) Type {8000fn typeOf(sema: *Sema, inst: Air.Inst.Ref) Type {
7975 switch (air_ref) {8001 var i: usize = @enumToInt(inst);
7976 .none => unreachable,8002 if (i < Air.Inst.Ref.typed_value_map.len) {
7977 .u8_type => return Type.initTag(.u8),8003 return Air.Inst.Ref.typed_value_map[i].ty;
7978 .i8_type => return Type.initTag(.i8),
7979 .u16_type => return Type.initTag(.u16),
7980 .i16_type => return Type.initTag(.i16),
7981 .u32_type => return Type.initTag(.u32),
7982 .i32_type => return Type.initTag(.i32),
7983 .u64_type => return Type.initTag(.u64),
7984 .i64_type => return Type.initTag(.i64),
7985 .u128_type => return Type.initTag(.u128),
7986 .i128_type => return Type.initTag(.i128),
7987 .usize_type => return Type.initTag(.usize),
7988 .isize_type => return Type.initTag(.isize),
7989 .c_short_type => return Type.initTag(.c_short),
7990 .c_ushort_type => return Type.initTag(.c_ushort),
7991 .c_int_type => return Type.initTag(.c_int),
7992 .c_uint_type => return Type.initTag(.c_uint),
7993 .c_long_type => return Type.initTag(.c_long),
7994 .c_ulong_type => return Type.initTag(.c_ulong),
7995 .c_longlong_type => return Type.initTag(.c_longlong),
7996 .c_ulonglong_type => return Type.initTag(.c_ulonglong),
7997 .c_longdouble_type => return Type.initTag(.c_longdouble),
7998 .f16_type => return Type.initTag(.f16),
7999 .f32_type => return Type.initTag(.f32),
8000 .f64_type => return Type.initTag(.f64),
8001 .f128_type => return Type.initTag(.f128),
8002 .c_void_type => return Type.initTag(.c_void),
8003 .bool_type => return Type.initTag(.bool),
8004 .void_type => return Type.initTag(.void),
8005 .type_type => return Type.initTag(.type),
8006 .anyerror_type => return Type.initTag(.anyerror),
8007 .comptime_int_type => return Type.initTag(.comptime_int),
8008 .comptime_float_type => return Type.initTag(.comptime_float),
8009 .noreturn_type => return Type.initTag(.noreturn),
8010 .anyframe_type => return Type.initTag(.@"anyframe"),
8011 .null_type => return Type.initTag(.@"null"),
8012 .undefined_type => return Type.initTag(.@"undefined"),
8013 .enum_literal_type => return Type.initTag(.enum_literal),
8014 .atomic_ordering_type => return Type.initTag(.atomic_ordering),
8015 .atomic_rmw_op_type => return Type.initTag(.atomic_rmw_op),
8016 .calling_convention_type => return Type.initTag(.calling_convention),
8017 .float_mode_type => return Type.initTag(.float_mode),
8018 .reduce_op_type => return Type.initTag(.reduce_op),
8019 .call_options_type => return Type.initTag(.call_options),
8020 .export_options_type => return Type.initTag(.export_options),
8021 .extern_options_type => return Type.initTag(.extern_options),
8022 .manyptr_u8_type => return Type.initTag(.manyptr_u8),
8023 .manyptr_const_u8_type => return Type.initTag(.manyptr_const_u8),
8024 .fn_noreturn_no_args_type => return Type.initTag(.fn_noreturn_no_args),
8025 .fn_void_no_args_type => return Type.initTag(.fn_void_no_args),
8026 .fn_naked_noreturn_no_args_type => return Type.initTag(.fn_naked_noreturn_no_args),
8027 .fn_ccc_void_no_args_type => return Type.initTag(.fn_ccc_void_no_args),
8028 .single_const_pointer_to_comptime_int_type => return Type.initTag(.single_const_pointer_to_comptime_int),
8029 .const_slice_u8_type => return Type.initTag(.const_slice_u8),
8030 else => {},
8031 }8004 }
8032 const air_index = @as(usize, @enumToInt(air_ref)) - Air.Inst.Ref.typed_value_map.len;8005 i -= Air.Inst.Ref.typed_value_map.len;
8033 const air_tags = sema.air_instructions.items(.tag);8006
8034 const air_datas = sema.air_instructions.items(.data);8007 const air_datas = sema.air_instructions.items(.data);
8035 assert(air_tags[air_index] == .const_ty);8008 switch (sema.air_instructions.items(.tag)[i]) {
8036 return air_datas[air_index].ty;8009 .arg => return sema.analyzeAsTypeInfallible(air_datas[i].ty_str.ty),
8010
8011 .add,
8012 .addwrap,
8013 .sub,
8014 .subwrap,
8015 .mul,
8016 .mulwrap,
8017 .div,
8018 .bit_and,
8019 .bit_or,
8020 .xor,
8021 => return sema.typeOf(air_datas[i].bin_op.lhs),
8022
8023 .cmp_lt,
8024 .cmp_lte,
8025 .cmp_eq,
8026 .cmp_gte,
8027 .cmp_gt,
8028 .cmp_neq,
8029 .is_null,
8030 .is_non_null,
8031 .is_null_ptr,
8032 .is_non_null_ptr,
8033 .is_err,
8034 .is_non_err,
8035 .is_err_ptr,
8036 .is_non_err_ptr,
8037 .bool_and,
8038 .bool_or,
8039 => return Type.initTag(.bool),
8040
8041 .const_ty => return Type.initTag(.type),
8042
8043 .alloc => return air_datas[i].ty,
8044
8045 .assembly,
8046 .block,
8047 .constant,
8048 .varptr,
8049 .struct_field_ptr,
8050 => return sema.analyzeAsTypeInfallible(air_datas[i].ty_pl.ty),
8051
8052 .not,
8053 .bitcast,
8054 .load,
8055 .ref,
8056 .floatcast,
8057 .intcast,
8058 .optional_payload,
8059 .optional_payload_ptr,
8060 .wrap_optional,
8061 .unwrap_errunion_payload,
8062 .unwrap_errunion_err,
8063 .unwrap_errunion_payload_ptr,
8064 .unwrap_errunion_err_ptr,
8065 .wrap_errunion_payload,
8066 .wrap_errunion_err,
8067 => return sema.analyzeAsTypeInfallible(air_datas[i].ty_op.ty),
8068
8069 .loop,
8070 .br,
8071 .cond_br,
8072 .switch_br,
8073 .ret,
8074 .unreach,
8075 => return Type.initTag(.noreturn),
8076
8077 .breakpoint,
8078 .dbg_stmt,
8079 .store,
8080 => return Type.initTag(.void),
8081
8082 .ptrtoint => return Type.initTag(.usize),
8083
8084 .call => @panic("TODO Sema.typeOf call"),
8085 }
8037}8086}
80388087
8039pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {8088pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {