| ... | ... | @@ -199,65 +199,65 @@ pub fn analyzeBody( |
| 199 | 199 | .cmp_lt => try sema.zirCmp(block, inst, .lt), |
| 200 | 200 | .cmp_lte => try sema.zirCmp(block, inst, .lte), |
| 201 | 201 | .cmp_neq => try sema.zirCmp(block, inst, .neq), |
| 202 | | //.coerce_result_ptr => try sema.zirCoerceResultPtr(block, inst), |
| 203 | | //.decl_ref => try sema.zirDeclRef(block, inst), |
| 204 | | //.decl_val => try sema.zirDeclVal(block, inst), |
| 205 | | //.load => try sema.zirLoad(block, inst), |
| 206 | | //.elem_ptr => try sema.zirElemPtr(block, inst), |
| 207 | | //.elem_ptr_node => try sema.zirElemPtrNode(block, inst), |
| 208 | | //.elem_val => try sema.zirElemVal(block, inst), |
| 209 | | //.elem_val_node => try sema.zirElemValNode(block, inst), |
| 210 | | //.elem_type => try sema.zirElemType(block, inst), |
| 211 | | //.enum_literal => try sema.zirEnumLiteral(block, inst), |
| 212 | | //.enum_to_int => try sema.zirEnumToInt(block, inst), |
| 213 | | //.int_to_enum => try sema.zirIntToEnum(block, inst), |
| 214 | | //.err_union_code => try sema.zirErrUnionCode(block, inst), |
| 215 | | //.err_union_code_ptr => try sema.zirErrUnionCodePtr(block, inst), |
| 216 | | //.err_union_payload_safe => try sema.zirErrUnionPayload(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), |
| 219 | | //.err_union_payload_unsafe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, false), |
| 220 | | //.error_union_type => try sema.zirErrorUnionType(block, inst), |
| 221 | | //.error_value => try sema.zirErrorValue(block, inst), |
| 222 | | //.error_to_int => try sema.zirErrorToInt(block, inst), |
| 223 | | //.int_to_error => try sema.zirIntToError(block, inst), |
| 224 | | //.field_ptr => try sema.zirFieldPtr(block, inst), |
| 225 | | //.field_ptr_named => try sema.zirFieldPtrNamed(block, inst), |
| 226 | | //.field_val => try sema.zirFieldVal(block, inst), |
| 227 | | //.field_val_named => try sema.zirFieldValNamed(block, inst), |
| 228 | | //.func => try sema.zirFunc(block, inst, false), |
| 229 | | //.func_inferred => try sema.zirFunc(block, inst, true), |
| 230 | | //.import => try sema.zirImport(block, inst), |
| 231 | | //.indexable_ptr_len => try sema.zirIndexablePtrLen(block, inst), |
| 232 | | //.int => try sema.zirInt(block, inst), |
| 233 | | //.int_big => try sema.zirIntBig(block, inst), |
| 234 | | //.float => try sema.zirFloat(block, inst), |
| 235 | | //.float128 => try sema.zirFloat128(block, inst), |
| 236 | | //.int_type => try sema.zirIntType(block, inst), |
| 237 | | //.is_non_err => try sema.zirIsNonErr(block, inst), |
| 238 | | //.is_non_err_ptr => try sema.zirIsNonErrPtr(block, inst), |
| 239 | | //.is_non_null => try sema.zirIsNonNull(block, inst), |
| 240 | | //.is_non_null_ptr => try sema.zirIsNonNullPtr(block, inst), |
| 241 | | //.loop => try sema.zirLoop(block, inst), |
| 242 | | //.merge_error_sets => try sema.zirMergeErrorSets(block, inst), |
| 243 | | //.negate => try sema.zirNegate(block, inst, .sub), |
| 244 | | //.negate_wrap => try sema.zirNegate(block, inst, .subwrap), |
| 245 | | //.optional_payload_safe => try sema.zirOptionalPayload(block, inst, true), |
| 246 | | //.optional_payload_safe_ptr => try sema.zirOptionalPayloadPtr(block, inst, true), |
| 247 | | //.optional_payload_unsafe => try sema.zirOptionalPayload(block, inst, false), |
| 248 | | //.optional_payload_unsafe_ptr => try sema.zirOptionalPayloadPtr(block, inst, false), |
| 249 | | //.optional_type => try sema.zirOptionalType(block, inst), |
| 250 | | //.param_type => try sema.zirParamType(block, inst), |
| 251 | | //.ptr_type => try sema.zirPtrType(block, inst), |
| 252 | | //.ptr_type_simple => try sema.zirPtrTypeSimple(block, inst), |
| 253 | | //.ref => try sema.zirRef(block, inst), |
| 254 | | //.ret_err_value_code => try sema.zirRetErrValueCode(block, inst), |
| 255 | | //.shl => try sema.zirShl(block, inst), |
| 256 | | //.shr => try sema.zirShr(block, inst), |
| 257 | | //.slice_end => try sema.zirSliceEnd(block, inst), |
| 258 | | //.slice_sentinel => try sema.zirSliceSentinel(block, inst), |
| 259 | | //.slice_start => try sema.zirSliceStart(block, inst), |
| 260 | | //.str => try sema.zirStr(block, inst), |
| 202 | .coerce_result_ptr => try sema.zirCoerceResultPtr(block, inst), |
| 203 | .decl_ref => try sema.zirDeclRef(block, inst), |
| 204 | .decl_val => try sema.zirDeclVal(block, inst), |
| 205 | .load => try sema.zirLoad(block, inst), |
| 206 | .elem_ptr => try sema.zirElemPtr(block, inst), |
| 207 | .elem_ptr_node => try sema.zirElemPtrNode(block, inst), |
| 208 | .elem_val => try sema.zirElemVal(block, inst), |
| 209 | .elem_val_node => try sema.zirElemValNode(block, inst), |
| 210 | .elem_type => try sema.zirElemType(block, inst), |
| 211 | .enum_literal => try sema.zirEnumLiteral(block, inst), |
| 212 | .enum_to_int => try sema.zirEnumToInt(block, inst), |
| 213 | .int_to_enum => try sema.zirIntToEnum(block, inst), |
| 214 | .err_union_code => try sema.zirErrUnionCode(block, inst), |
| 215 | .err_union_code_ptr => try sema.zirErrUnionCodePtr(block, inst), |
| 216 | .err_union_payload_safe => try sema.zirErrUnionPayload(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), |
| 219 | .err_union_payload_unsafe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, false), |
| 220 | .error_union_type => try sema.zirErrorUnionType(block, inst), |
| 221 | .error_value => try sema.zirErrorValue(block, inst), |
| 222 | .error_to_int => try sema.zirErrorToInt(block, inst), |
| 223 | .int_to_error => try sema.zirIntToError(block, inst), |
| 224 | .field_ptr => try sema.zirFieldPtr(block, inst), |
| 225 | .field_ptr_named => try sema.zirFieldPtrNamed(block, inst), |
| 226 | .field_val => try sema.zirFieldVal(block, inst), |
| 227 | .field_val_named => try sema.zirFieldValNamed(block, inst), |
| 228 | .func => try sema.zirFunc(block, inst, false), |
| 229 | .func_inferred => try sema.zirFunc(block, inst, true), |
| 230 | .import => try sema.zirImport(block, inst), |
| 231 | .indexable_ptr_len => try sema.zirIndexablePtrLen(block, inst), |
| 232 | .int => try sema.zirInt(block, inst), |
| 233 | .int_big => try sema.zirIntBig(block, inst), |
| 234 | .float => try sema.zirFloat(block, inst), |
| 235 | .float128 => try sema.zirFloat128(block, inst), |
| 236 | .int_type => try sema.zirIntType(block, inst), |
| 237 | .is_non_err => try sema.zirIsNonErr(block, inst), |
| 238 | .is_non_err_ptr => try sema.zirIsNonErrPtr(block, inst), |
| 239 | .is_non_null => try sema.zirIsNonNull(block, inst), |
| 240 | .is_non_null_ptr => try sema.zirIsNonNullPtr(block, inst), |
| 241 | .loop => try sema.zirLoop(block, inst), |
| 242 | .merge_error_sets => try sema.zirMergeErrorSets(block, inst), |
| 243 | .negate => try sema.zirNegate(block, inst, .sub), |
| 244 | .negate_wrap => try sema.zirNegate(block, inst, .subwrap), |
| 245 | .optional_payload_safe => try sema.zirOptionalPayload(block, inst, true), |
| 246 | .optional_payload_safe_ptr => try sema.zirOptionalPayloadPtr(block, inst, true), |
| 247 | .optional_payload_unsafe => try sema.zirOptionalPayload(block, inst, false), |
| 248 | .optional_payload_unsafe_ptr => try sema.zirOptionalPayloadPtr(block, inst, false), |
| 249 | .optional_type => try sema.zirOptionalType(block, inst), |
| 250 | .param_type => try sema.zirParamType(block, inst), |
| 251 | .ptr_type => try sema.zirPtrType(block, inst), |
| 252 | .ptr_type_simple => try sema.zirPtrTypeSimple(block, inst), |
| 253 | .ref => try sema.zirRef(block, inst), |
| 254 | .ret_err_value_code => try sema.zirRetErrValueCode(block, inst), |
| 255 | .shl => try sema.zirShl(block, inst), |
| 256 | .shr => try sema.zirShr(block, inst), |
| 257 | .slice_end => try sema.zirSliceEnd(block, inst), |
| 258 | .slice_sentinel => try sema.zirSliceSentinel(block, inst), |
| 259 | .slice_start => try sema.zirSliceStart(block, inst), |
| 260 | .str => try sema.zirStr(block, inst), |
| 261 | 261 | //.switch_block => try sema.zirSwitchBlock(block, inst, false, .none), |
| 262 | 262 | //.switch_block_multi => try sema.zirSwitchBlockMulti(block, inst, false, .none), |
| 263 | 263 | //.switch_block_else => try sema.zirSwitchBlock(block, inst, false, .@"else"), |
| ... | ... | @@ -536,7 +536,7 @@ pub fn analyzeBody( |
| 536 | 536 | }, |
| 537 | 537 | else => |t| @panic(@tagName(t)), |
| 538 | 538 | }; |
| 539 | | if (sema.getTypeOf(air_inst).isNoReturn()) |
| 539 | if (sema.typeOf(air_inst).isNoReturn()) |
| 540 | 540 | return always_noreturn; |
| 541 | 541 | try map.put(sema.gpa, inst, air_inst); |
| 542 | 542 | i += 1; |
| ... | ... | @@ -620,10 +620,10 @@ fn resolveConstString( |
| 620 | 620 | |
| 621 | 621 | pub fn resolveType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !Type { |
| 622 | 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 | } |
| 625 | 625 | |
| 626 | | fn resolveAirAsType( |
| 626 | fn analyzeAsType( |
| 627 | 627 | sema: *Sema, |
| 628 | 628 | block: *Scope.Block, |
| 629 | 629 | src: LazySrcLoc, |
| ... | ... | @@ -664,26 +664,26 @@ fn resolvePossiblyUndefinedValue( |
| 664 | 664 | sema: *Sema, |
| 665 | 665 | block: *Scope.Block, |
| 666 | 666 | src: LazySrcLoc, |
| 667 | | air_ref: Air.Inst.Ref, |
| 667 | inst: Air.Inst.Ref, |
| 668 | 668 | ) CompileError!?Value { |
| 669 | | const ty = sema.getTypeOf(air_ref); |
| 670 | | if (try sema.typeHasOnePossibleValue(block, src, ty)) |opv| { |
| 671 | | return opv; |
| 672 | | } |
| 673 | 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 | 671 | if (i < Air.Inst.Ref.typed_value_map.len) { |
| 676 | 672 | return Air.Inst.Ref.typed_value_map[i].val; |
| 677 | 673 | } |
| 678 | 674 | i -= Air.Inst.Ref.typed_value_map.len; |
| 679 | 675 | |
| 676 | if (try sema.typeHasOnePossibleValue(block, src, sema.typeOf(inst))) |opv| { |
| 677 | return opv; |
| 678 | } |
| 679 | |
| 680 | 680 | switch (sema.air_instructions.items(.tag)[i]) { |
| 681 | 681 | .constant => { |
| 682 | 682 | const ty_pl = sema.air_instructions.items(.data)[i].ty_pl; |
| 683 | 683 | return sema.air_values.items[ty_pl.payload]; |
| 684 | 684 | }, |
| 685 | 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 | 688 | else => return null, |
| 689 | 689 | } |
| ... | ... | @@ -739,7 +739,7 @@ pub fn resolveInstConst( |
| 739 | 739 | const air_ref = sema.resolveInst(zir_ref); |
| 740 | 740 | const val = try sema.resolveConstValue(block, src, air_ref); |
| 741 | 741 | return TypedValue{ |
| 742 | | .ty = sema.getTypeOf(air_ref), |
| 742 | .ty = sema.typeOf(air_ref), |
| 743 | 743 | .val = val, |
| 744 | 744 | }; |
| 745 | 745 | } |
| ... | ... | @@ -1230,7 +1230,7 @@ fn ensureResultUsed( |
| 1230 | 1230 | operand: Air.Inst.Ref, |
| 1231 | 1231 | src: LazySrcLoc, |
| 1232 | 1232 | ) CompileError!void { |
| 1233 | | const operand_ty = sema.getTypeOf(operand); |
| 1233 | const operand_ty = sema.typeOf(operand); |
| 1234 | 1234 | switch (operand_ty.zigTypeTag()) { |
| 1235 | 1235 | .Void, .NoReturn => return, |
| 1236 | 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 | 1244 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 1245 | 1245 | const operand = sema.resolveInst(inst_data.operand); |
| 1246 | 1246 | const src = inst_data.src(); |
| 1247 | | const operand_ty = sema.getTypeOf(operand); |
| 1247 | const operand_ty = sema.typeOf(operand); |
| 1248 | 1248 | switch (operand_ty.zigTypeTag()) { |
| 1249 | 1249 | .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}), |
| 1250 | 1250 | else => return, |
| ... | ... | @@ -1259,7 +1259,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1259 | 1259 | const src = inst_data.src(); |
| 1260 | 1260 | const array_ptr = sema.resolveInst(inst_data.operand); |
| 1261 | 1261 | |
| 1262 | | const elem_ty = sema.getTypeOf(array_ptr).elemType(); |
| 1262 | const elem_ty = sema.typeOf(array_ptr).elemType(); |
| 1263 | 1263 | if (!elem_ty.isIndexable()) { |
| 1264 | 1264 | const cond_src: LazySrcLoc = .{ .node_offset_for_cond = inst_data.src_node }; |
| 1265 | 1265 | const msg = msg: { |
| ... | ... | @@ -1282,7 +1282,8 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1282 | 1282 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 1283 | 1283 | } |
| 1284 | 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 | } |
| 1287 | 1288 | |
| 1288 | 1289 | fn 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 | 1631 | |
| 1631 | 1632 | const inst_data = sema.code.instructions.items(.data)[inst].param_type; |
| 1632 | 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 | 1635 | const param_index = inst_data.param_index; |
| 1635 | 1636 | |
| 1636 | 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 | 1860 | sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity( |
| 1860 | 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 | 1864 | return sema.analyzeBlockBody(parent_block, src, &child_block, merges); |
| 1864 | 1865 | } |
| 1865 | 1866 | |
| ... | ... | @@ -1957,7 +1958,7 @@ fn analyzeBlockBody( |
| 1957 | 1958 | |
| 1958 | 1959 | // Blocks must terminate with noreturn instruction. |
| 1959 | 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()); |
| 1961 | 1962 | |
| 1962 | 1963 | if (merges.results.items.len == 0) { |
| 1963 | 1964 | // No need for a block instruction. We can put the new instructions |
| ... | ... | @@ -1999,7 +2000,7 @@ fn analyzeBlockBody( |
| 1999 | 2000 | for (merges.br_list.items) |br| { |
| 2000 | 2001 | const br_operand = sema.air_instructions.items(.data)[br].br.operand; |
| 2001 | 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 | 2004 | if (br_operand_ty.eql(resolved_ty)) { |
| 2004 | 2005 | // No type coercion needed. |
| 2005 | 2006 | continue; |
| ... | ... | @@ -2252,7 +2253,7 @@ fn analyzeCall( |
| 2252 | 2253 | ensure_result_used: bool, |
| 2253 | 2254 | args: []const Air.Inst.Ref, |
| 2254 | 2255 | ) CompileError!Air.Inst.Ref { |
| 2255 | | const func_ty = sema.getTypeOf(func); |
| 2256 | const func_ty = sema.typeOf(func); |
| 2256 | 2257 | if (func_ty.zigTypeTag() != .Fn) |
| 2257 | 2258 | return sema.mod.fail(&block.base, func_src, "type '{}' not a function", .{func_ty}); |
| 2258 | 2259 | |
| ... | ... | @@ -2606,8 +2607,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2606 | 2607 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 2607 | 2608 | const lhs = sema.resolveInst(extra.lhs); |
| 2608 | 2609 | const rhs = sema.resolveInst(extra.rhs); |
| 2609 | | const lhs_ty = sema.getTypeOf(lhs); |
| 2610 | | const rhs_ty = sema.getTypeOf(rhs); |
| 2610 | const lhs_ty = sema.typeOf(lhs); |
| 2611 | const rhs_ty = sema.typeOf(rhs); |
| 2611 | 2612 | if (rhs_ty.zigTypeTag() == .Bool and lhs_ty.zigTypeTag() == .Bool) { |
| 2612 | 2613 | const msg = msg: { |
| 2613 | 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 | 2700 | const src = inst_data.src(); |
| 2700 | 2701 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2701 | 2702 | const operand = sema.resolveInst(inst_data.operand); |
| 2702 | | const operand_ty = sema.getTypeOf(operand); |
| 2703 | const operand_ty = sema.typeOf(operand); |
| 2703 | 2704 | |
| 2704 | 2705 | const enum_tag: Air.Inst.Ref = switch (operand_ty.zigTypeTag()) { |
| 2705 | 2706 | .Enum => operand, |
| ... | ... | @@ -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); |
| 2724 | 2725 | |
| 2725 | 2726 | var int_tag_type_buffer: Type.Payload.Bits = undefined; |
| 2726 | 2727 | const int_tag_ty = try enum_tag_ty.intTagType(&int_tag_type_buffer).copy(arena); |
| ... | ... | @@ -2821,7 +2822,7 @@ fn zirOptionalPayloadPtr( |
| 2821 | 2822 | |
| 2822 | 2823 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2823 | 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 | 2826 | assert(optional_ptr_ty.zigTypeTag() == .Pointer); |
| 2826 | 2827 | const src = inst_data.src(); |
| 2827 | 2828 | |
| ... | ... | @@ -2863,7 +2864,7 @@ fn zirOptionalPayload( |
| 2863 | 2864 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2864 | 2865 | const src = inst_data.src(); |
| 2865 | 2866 | const operand = sema.resolveInst(inst_data.operand); |
| 2866 | | const operand_ty = sema.getTypeOf(operand); |
| 2867 | const operand_ty = sema.typeOf(operand); |
| 2867 | 2868 | const opt_type = operand_ty; |
| 2868 | 2869 | if (opt_type.zigTypeTag() != .Optional) { |
| 2869 | 2870 | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); |
| ... | ... | @@ -2900,7 +2901,7 @@ fn zirErrUnionPayload( |
| 2900 | 2901 | const src = inst_data.src(); |
| 2901 | 2902 | const operand = sema.resolveInst(inst_data.operand); |
| 2902 | 2903 | const operand_src = src; |
| 2903 | | const operand_ty = sema.getTypeOf(operand); |
| 2904 | const operand_ty = sema.typeOf(operand); |
| 2904 | 2905 | if (operand_ty.zigTypeTag() != .ErrorUnion) |
| 2905 | 2906 | return sema.mod.fail(&block.base, operand_src, "expected error union type, found '{}'", .{operand_ty}); |
| 2906 | 2907 | |
| ... | ... | @@ -2936,7 +2937,7 @@ fn zirErrUnionPayloadPtr( |
| 2936 | 2937 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2937 | 2938 | const src = inst_data.src(); |
| 2938 | 2939 | const operand = sema.resolveInst(inst_data.operand); |
| 2939 | | const operand_ty = sema.getTypeOf(operand); |
| 2940 | const operand_ty = sema.typeOf(operand); |
| 2940 | 2941 | assert(operand_ty.zigTypeTag() == .Pointer); |
| 2941 | 2942 | |
| 2942 | 2943 | if (operand_ty.elemType().zigTypeTag() != .ErrorUnion) |
| ... | ... | @@ -2976,7 +2977,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 2976 | 2977 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2977 | 2978 | const src = inst_data.src(); |
| 2978 | 2979 | const operand = sema.resolveInst(inst_data.operand); |
| 2979 | | const operand_ty = sema.getTypeOf(operand); |
| 2980 | const operand_ty = sema.typeOf(operand); |
| 2980 | 2981 | if (operand_ty.zigTypeTag() != .ErrorUnion) |
| 2981 | 2982 | return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty}); |
| 2982 | 2983 | |
| ... | ... | @@ -3000,7 +3001,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 3000 | 3001 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3001 | 3002 | const src = inst_data.src(); |
| 3002 | 3003 | const operand = sema.resolveInst(inst_data.operand); |
| 3003 | | const operand_ty = sema.getTypeOf(operand); |
| 3004 | const operand_ty = sema.typeOf(operand); |
| 3004 | 3005 | assert(operand_ty.zigTypeTag() == .Pointer); |
| 3005 | 3006 | |
| 3006 | 3007 | if (operand_ty.elemType().zigTypeTag() != .ErrorUnion) |
| ... | ... | @@ -3026,7 +3027,7 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 3026 | 3027 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; |
| 3027 | 3028 | const src = inst_data.src(); |
| 3028 | 3029 | const operand = sema.resolveInst(inst_data.operand); |
| 3029 | | const operand_ty = sema.getTypeOf(operand); |
| 3030 | const operand_ty = sema.typeOf(operand); |
| 3030 | 3031 | if (operand_ty.zigTypeTag() != .ErrorUnion) |
| 3031 | 3032 | return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty}); |
| 3032 | 3033 | if (operand_ty.castTag(.error_union).?.data.payload.zigTypeTag() != .Void) { |
| ... | ... | @@ -3214,7 +3215,6 @@ fn funcCommon( |
| 3214 | 3215 | .state = anal_state, |
| 3215 | 3216 | .zir_body_inst = body_inst, |
| 3216 | 3217 | .owner_decl = sema.owner_decl, |
| 3217 | | .body = undefined, |
| 3218 | 3218 | .lbrace_line = src_locs.lbrace_line, |
| 3219 | 3219 | .rbrace_line = src_locs.rbrace_line, |
| 3220 | 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 | 3283 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 3284 | 3284 | const field_name = sema.code.nullTerminatedString(extra.field_name_start); |
| 3285 | 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 | 3287 | object |
| 3288 | 3288 | else |
| 3289 | 3289 | try sema.analyzeRef(block, src, object); |
| 3290 | 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 | } |
| 3293 | 3294 | |
| 3294 | 3295 | fn 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 | 3357 | ), |
| 3357 | 3358 | }; |
| 3358 | 3359 | |
| 3359 | | const operand_ty = sema.getTypeOf(operand); |
| 3360 | const operand_ty = sema.typeOf(operand); |
| 3360 | 3361 | switch (operand_ty.zigTypeTag()) { |
| 3361 | 3362 | .ComptimeInt, .Int => {}, |
| 3362 | 3363 | else => return sema.mod.fail( |
| ... | ... | @@ -3414,7 +3415,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3414 | 3415 | ), |
| 3415 | 3416 | }; |
| 3416 | 3417 | |
| 3417 | | const operand_ty = sema.getTypeOf(operand); |
| 3418 | const operand_ty = sema.typeOf(operand); |
| 3418 | 3419 | switch (operand_ty.zigTypeTag()) { |
| 3419 | 3420 | .ComptimeFloat, .Float, .ComptimeInt => {}, |
| 3420 | 3421 | else => return sema.mod.fail( |
| ... | ... | @@ -3440,7 +3441,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 3440 | 3441 | |
| 3441 | 3442 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 3442 | 3443 | const array = sema.resolveInst(bin_inst.lhs); |
| 3443 | | const array_ty = sema.getTypeOf(array); |
| 3444 | const array_ty = sema.typeOf(array); |
| 3444 | 3445 | const array_ptr = if (array_ty.zigTypeTag() == .Pointer) |
| 3445 | 3446 | array |
| 3446 | 3447 | else |
| ... | ... | @@ -3459,7 +3460,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 3459 | 3460 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; |
| 3460 | 3461 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 3461 | 3462 | const array = sema.resolveInst(extra.lhs); |
| 3462 | | const array_ty = sema.getTypeOf(array); |
| 3463 | const array_ty = sema.typeOf(array); |
| 3463 | 3464 | const array_ptr = if (array_ty.zigTypeTag() == .Pointer) |
| 3464 | 3465 | array |
| 3465 | 3466 | else |
| ... | ... | @@ -3502,7 +3503,7 @@ fn zirSliceStart(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3502 | 3503 | const array_ptr = sema.resolveInst(extra.lhs); |
| 3503 | 3504 | const start = sema.resolveInst(extra.start); |
| 3504 | 3505 | |
| 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 | } |
| 3507 | 3508 | |
| 3508 | 3509 | fn 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 | 3517 | const start = sema.resolveInst(extra.start); |
| 3517 | 3518 | const end = sema.resolveInst(extra.end); |
| 3518 | 3519 | |
| 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 | } |
| 3521 | 3522 | |
| 3522 | 3523 | fn zirSliceSentinel(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -3668,7 +3669,7 @@ fn analyzeSwitch( |
| 3668 | 3669 | const src: LazySrcLoc = .{ .node_offset = src_node_offset }; |
| 3669 | 3670 | const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset }; |
| 3670 | 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); |
| 3672 | 3673 | |
| 3673 | 3674 | // Validate usage of '_' prongs. |
| 3674 | 3675 | if (special_prong == .under and !operand_ty.isNonexhaustiveEnum()) { |
| ... | ... | @@ -4590,8 +4591,8 @@ fn zirBitwise( |
| 4590 | 4591 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 4591 | 4592 | const lhs = sema.resolveInst(extra.lhs); |
| 4592 | 4593 | const rhs = sema.resolveInst(extra.rhs); |
| 4593 | | const lhs_ty = sema.getTypeOf(lhs); |
| 4594 | | const rhs_ty = sema.getTypeOf(rhs); |
| 4594 | const lhs_ty = sema.typeOf(lhs); |
| 4595 | const rhs_ty = sema.typeOf(rhs); |
| 4595 | 4596 | |
| 4596 | 4597 | const instructions = &[_]Air.Inst.Ref{ lhs, rhs }; |
| 4597 | 4598 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions); |
| ... | ... | @@ -4722,8 +4723,8 @@ fn analyzeArithmetic( |
| 4722 | 4723 | lhs_src: LazySrcLoc, |
| 4723 | 4724 | rhs_src: LazySrcLoc, |
| 4724 | 4725 | ) CompileError!Air.Inst.Ref { |
| 4725 | | const lhs_ty = sema.getTypeOf(lhs); |
| 4726 | | const rhs_ty = sema.getTypeOf(rhs); |
| 4726 | const lhs_ty = sema.typeOf(lhs); |
| 4727 | const rhs_ty = sema.typeOf(rhs); |
| 4727 | 4728 | if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) { |
| 4728 | 4729 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { |
| 4729 | 4730 | return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{ |
| ... | ... | @@ -4944,8 +4945,8 @@ fn zirCmp( |
| 4944 | 4945 | .eq, .neq => true, |
| 4945 | 4946 | else => false, |
| 4946 | 4947 | }; |
| 4947 | | const lhs_ty = sema.getTypeOf(lhs); |
| 4948 | | const rhs_ty = sema.getTypeOf(rhs); |
| 4948 | const lhs_ty = sema.typeOf(lhs); |
| 4949 | const rhs_ty = sema.typeOf(rhs); |
| 4949 | 4950 | const lhs_ty_tag = lhs_ty.zigTypeTag(); |
| 4950 | 4951 | const rhs_ty_tag = rhs_ty.zigTypeTag(); |
| 4951 | 4952 | if (is_equality_cmp and lhs_ty_tag == .Null and rhs_ty_tag == .Null) { |
| ... | ... | @@ -5007,8 +5008,8 @@ fn zirCmp( |
| 5007 | 5008 | if (!is_equality_cmp) { |
| 5008 | 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 rhs_as_type = try sema.resolveAirAsType(block, rhs_src, rhs); |
| 5011 | const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs); |
| 5012 | const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs); |
| 5012 | 5013 | if (lhs_as_type.eql(rhs_as_type) == (op == .eq)) { |
| 5013 | 5014 | return Air.Inst.Ref.bool_true; |
| 5014 | 5015 | } else { |
| ... | ... | @@ -5144,7 +5145,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 5144 | 5145 | const zir_datas = sema.code.instructions.items(.data); |
| 5145 | 5146 | const inst_data = zir_datas[inst].un_node; |
| 5146 | 5147 | const operand = sema.resolveInst(inst_data.operand); |
| 5147 | | const operand_ty = sema.getTypeOf(operand); |
| 5148 | const operand_ty = sema.typeOf(operand); |
| 5148 | 5149 | return sema.addType(operand_ty); |
| 5149 | 5150 | } |
| 5150 | 5151 | |
| ... | ... | @@ -6375,7 +6376,7 @@ fn addSafetyCheck( |
| 6375 | 6376 | const block_inst = @intCast(Air.Inst.Index, sema.air_instructions.len); |
| 6376 | 6377 | const cond_br_inst = block_inst + 1; |
| 6377 | 6378 | const br_inst = cond_br_inst + 1; |
| 6378 | | sema.air_instructions.appendAssumeCapacity(gpa, .{ |
| 6379 | sema.air_instructions.appendAssumeCapacity(.{ |
| 6379 | 6380 | .tag = .block, |
| 6380 | 6381 | .data = .{ .ty_pl = .{ |
| 6381 | 6382 | .ty = .void_type, |
| ... | ... | @@ -6386,7 +6387,7 @@ fn addSafetyCheck( |
| 6386 | 6387 | }); |
| 6387 | 6388 | sema.air_extra.appendAssumeCapacity(cond_br_inst); |
| 6388 | 6389 | |
| 6389 | | sema.air_instructions.appendAssumeCapacity(gpa, .{ |
| 6390 | sema.air_instructions.appendAssumeCapacity(.{ |
| 6390 | 6391 | .tag = .cond_br, |
| 6391 | 6392 | .data = .{ .pl_op = .{ |
| 6392 | 6393 | .operand = ok, |
| ... | ... | @@ -6399,7 +6400,7 @@ fn addSafetyCheck( |
| 6399 | 6400 | sema.air_extra.appendAssumeCapacity(br_inst); |
| 6400 | 6401 | sema.air_extra.appendSliceAssumeCapacity(fail_block.instructions.items); |
| 6401 | 6402 | |
| 6402 | | sema.air_instructions.appendAssumeCapacity(gpa, .{ |
| 6403 | sema.air_instructions.appendAssumeCapacity(.{ |
| 6403 | 6404 | .tag = .br, |
| 6404 | 6405 | .data = .{ .br = .{ |
| 6405 | 6406 | .block_inst = block_inst, |
| ... | ... | @@ -6497,9 +6498,11 @@ fn namedFieldPtr( |
| 6497 | 6498 | const mod = sema.mod; |
| 6498 | 6499 | const arena = sema.arena; |
| 6499 | 6500 | |
| 6500 | | const elem_ty = switch (object_ptr.ty.zigTypeTag()) { |
| 6501 | | .Pointer => object_ptr.ty.elemType(), |
| 6502 | | else => return mod.fail(&block.base, object_ptr.src, "expected pointer, found '{}'", .{object_ptr.ty}), |
| 6501 | const object_ptr_src = src; // TODO better source location |
| 6502 | const object_ptr_ty = sema.typeOf(object_ptr); |
| 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 | 6507 | switch (elem_ty.zigTypeTag()) { |
| 6505 | 6508 | .Array => { |
| ... | ... | @@ -6545,9 +6548,9 @@ fn namedFieldPtr( |
| 6545 | 6548 | } |
| 6546 | 6549 | }, |
| 6547 | 6550 | .Type => { |
| 6548 | | _ = try sema.resolveConstValue(block, object_ptr.src, object_ptr); |
| 6549 | | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr.src); |
| 6550 | | const val = result.value().?; |
| 6551 | _ = try sema.resolveConstValue(block, object_ptr_src, object_ptr); |
| 6552 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); |
| 6553 | const val = (sema.resolveDefinedValue(block, src, result) catch unreachable).?; |
| 6551 | 6554 | const child_type = try val.toType(arena); |
| 6552 | 6555 | switch (child_type.zigTypeTag()) { |
| 6553 | 6556 | .ErrorSet => { |
| ... | ... | @@ -6694,7 +6697,16 @@ fn analyzeStructFieldPtr( |
| 6694 | 6697 | } |
| 6695 | 6698 | |
| 6696 | 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 | } |
| 6699 | 6711 | |
| 6700 | 6712 | fn analyzeUnionFieldPtr( |
| ... | ... | @@ -6742,16 +6754,18 @@ fn elemPtr( |
| 6742 | 6754 | elem_index: Air.Inst.Ref, |
| 6743 | 6755 | elem_index_src: LazySrcLoc, |
| 6744 | 6756 | ) CompileError!Air.Inst.Ref { |
| 6745 | | const array_ty = switch (array_ptr.ty.zigTypeTag()) { |
| 6746 | | .Pointer => array_ptr.ty.elemType(), |
| 6747 | | else => return sema.mod.fail(&block.base, array_ptr.src, "expected pointer, found '{}'", .{array_ptr.ty}), |
| 6757 | const array_ptr_src = src; // TODO better source location |
| 6758 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 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 | 6763 | if (!array_ty.isIndexable()) { |
| 6750 | 6764 | return sema.mod.fail(&block.base, src, "array access of non-array type '{}'", .{array_ty}); |
| 6751 | 6765 | } |
| 6752 | 6766 | if (array_ty.isSinglePointer() and array_ty.elemType().zigTypeTag() == .Array) { |
| 6753 | 6767 | // 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 | 6769 | return sema.elemPtrArray(block, src, array_ptr_deref, elem_index, elem_index_src); |
| 6756 | 6770 | } |
| 6757 | 6771 | if (array_ty.zigTypeTag() == .Array) { |
| ... | ... | @@ -6776,7 +6790,7 @@ fn elemPtrArray( |
| 6776 | 6790 | // @intCast here because it would have been impossible to construct a value that |
| 6777 | 6791 | // required a larger index. |
| 6778 | 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(); |
| 6780 | 6794 | |
| 6781 | 6795 | return sema.addConstant( |
| 6782 | 6796 | try Type.Tag.single_const_pointer.create(sema.arena, pointee_type), |
| ... | ... | @@ -6800,7 +6814,7 @@ fn coerce( |
| 6800 | 6814 | return sema.coerceVarArgParam(block, inst, inst_src); |
| 6801 | 6815 | } |
| 6802 | 6816 | |
| 6803 | | const inst_ty = sema.getTypeOf(inst); |
| 6817 | const inst_ty = sema.typeOf(inst); |
| 6804 | 6818 | // If the types are the same, we can return the operand. |
| 6805 | 6819 | if (dest_type.eql(inst_ty)) |
| 6806 | 6820 | return inst; |
| ... | ... | @@ -7021,7 +7035,7 @@ fn coerceVarArgParam( |
| 7021 | 7035 | inst: Air.Inst.Ref, |
| 7022 | 7036 | inst_src: LazySrcLoc, |
| 7023 | 7037 | ) !Air.Inst.Ref { |
| 7024 | | const inst_ty = sema.getTypeOf(inst); |
| 7038 | const inst_ty = sema.typeOf(inst); |
| 7025 | 7039 | switch (inst_ty.zigTypeTag()) { |
| 7026 | 7040 | .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst_src, "integer and float literals in var args function must be casted", .{}), |
| 7027 | 7041 | else => {}, |
| ... | ... | @@ -7170,8 +7184,8 @@ fn analyzeRef( |
| 7170 | 7184 | src: LazySrcLoc, |
| 7171 | 7185 | operand: Air.Inst.Ref, |
| 7172 | 7186 | ) CompileError!Air.Inst.Ref { |
| 7173 | | const operand_ty = sema.getTypeOf(operand); |
| 7174 | | const ptr_type = try sema.mod.simplePtrType(sema.arena, operand_ty, false, .One); |
| 7187 | const operand_ty = sema.typeOf(operand); |
| 7188 | const ptr_type = try Module.simplePtrType(sema.arena, operand_ty, false, .One); |
| 7175 | 7189 | |
| 7176 | 7190 | if (try sema.resolvePossiblyUndefinedValue(block, src, operand)) |val| { |
| 7177 | 7191 | return sema.addConstant(ptr_type, try Value.Tag.ref_val.create(sema.arena, val)); |
| ... | ... | @@ -7188,7 +7202,7 @@ fn analyzeLoad( |
| 7188 | 7202 | ptr: Air.Inst.Ref, |
| 7189 | 7203 | ptr_src: LazySrcLoc, |
| 7190 | 7204 | ) CompileError!Air.Inst.Ref { |
| 7191 | | const ptr_ty = sema.getTypeOf(ptr); |
| 7205 | const ptr_ty = sema.typeOf(ptr); |
| 7192 | 7206 | const elem_ty = switch (ptr_ty.zigTypeTag()) { |
| 7193 | 7207 | .Pointer => ptr_ty.elemType(), |
| 7194 | 7208 | else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}), |
| ... | ... | @@ -7235,7 +7249,7 @@ fn analyzeIsNonErr( |
| 7235 | 7249 | src: LazySrcLoc, |
| 7236 | 7250 | operand: Air.Inst.Ref, |
| 7237 | 7251 | ) CompileError!Air.Inst.Ref { |
| 7238 | | const operand_ty = sema.getTypeOf(operand); |
| 7252 | const operand_ty = sema.typeOf(operand); |
| 7239 | 7253 | const ot = operand_ty.zigTypeTag(); |
| 7240 | 7254 | if (ot != .ErrorSet and ot != .ErrorUnion) return Air.Inst.Ref.bool_true; |
| 7241 | 7255 | if (ot == .ErrorSet) return Air.Inst.Ref.bool_false; |
| ... | ... | @@ -7261,13 +7275,14 @@ fn analyzeSlice( |
| 7261 | 7275 | src: LazySrcLoc, |
| 7262 | 7276 | array_ptr: Air.Inst.Ref, |
| 7263 | 7277 | start: Air.Inst.Ref, |
| 7264 | | end_opt: ?Air.Inst.Index, |
| 7265 | | sentinel_opt: ?Air.Inst.Index, |
| 7278 | end_opt: Air.Inst.Ref, |
| 7279 | sentinel_opt: Air.Inst.Ref, |
| 7266 | 7280 | sentinel_src: LazySrcLoc, |
| 7267 | 7281 | ) CompileError!Air.Inst.Ref { |
| 7268 | | const ptr_child = switch (array_ptr.ty.zigTypeTag()) { |
| 7269 | | .Pointer => array_ptr.ty.elemType(), |
| 7270 | | else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr.ty}), |
| 7282 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 7283 | const ptr_child = switch (array_ptr_ty.zigTypeTag()) { |
| 7284 | .Pointer => array_ptr_ty.elemType(), |
| 7285 | else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr_ty}), |
| 7271 | 7286 | }; |
| 7272 | 7287 | |
| 7273 | 7288 | var array_type = ptr_child; |
| ... | ... | @@ -7287,15 +7302,15 @@ fn analyzeSlice( |
| 7287 | 7302 | else => return sema.mod.fail(&block.base, src, "slice of non-array type '{}'", .{ptr_child}), |
| 7288 | 7303 | }; |
| 7289 | 7304 | |
| 7290 | | const slice_sentinel = if (sentinel_opt) |sentinel| blk: { |
| 7291 | | const casted = try sema.coerce(block, elem_type, sentinel, sentinel.src); |
| 7305 | const slice_sentinel = if (sentinel_opt != .none) blk: { |
| 7306 | const casted = try sema.coerce(block, elem_type, sentinel_opt, sentinel_src); |
| 7292 | 7307 | break :blk try sema.resolveConstValue(block, sentinel_src, casted); |
| 7293 | 7308 | } else null; |
| 7294 | 7309 | |
| 7295 | 7310 | var return_ptr_size: std.builtin.TypeInfo.Pointer.Size = .Slice; |
| 7296 | 7311 | var return_elem_type = elem_type; |
| 7297 | | if (end_opt) |end| { |
| 7298 | | if (try sema.resolveDefinedValue(block, src, end)) |end_val| { |
| 7312 | if (end_opt != .none) { |
| 7313 | if (try sema.resolveDefinedValue(block, src, end_opt)) |end_val| { |
| 7299 | 7314 | if (try sema.resolveDefinedValue(block, src, start)) |start_val| { |
| 7300 | 7315 | const start_u64 = start_val.toUnsignedInt(); |
| 7301 | 7316 | const end_u64 = end_val.toUnsignedInt(); |
| ... | ... | @@ -7316,7 +7331,7 @@ fn analyzeSlice( |
| 7316 | 7331 | const return_type = try sema.mod.ptrType( |
| 7317 | 7332 | sema.arena, |
| 7318 | 7333 | return_elem_type, |
| 7319 | | if (end_opt == null) slice_sentinel else null, |
| 7334 | if (end_opt == .none) slice_sentinel else null, |
| 7320 | 7335 | 0, // TODO alignment |
| 7321 | 7336 | 0, |
| 7322 | 7337 | 0, |
| ... | ... | @@ -7341,8 +7356,8 @@ fn cmpNumeric( |
| 7341 | 7356 | lhs_src: LazySrcLoc, |
| 7342 | 7357 | rhs_src: LazySrcLoc, |
| 7343 | 7358 | ) CompileError!Air.Inst.Ref { |
| 7344 | | const lhs_ty = sema.getTypeOf(lhs); |
| 7345 | | const rhs_ty = sema.getTypeOf(rhs); |
| 7359 | const lhs_ty = sema.typeOf(lhs); |
| 7360 | const rhs_ty = sema.typeOf(rhs); |
| 7346 | 7361 | |
| 7347 | 7362 | assert(lhs_ty.isNumeric()); |
| 7348 | 7363 | assert(rhs_ty.isNumeric()); |
| ... | ... | @@ -7609,14 +7624,14 @@ fn resolvePeerTypes( |
| 7609 | 7624 | return Type.initTag(.noreturn); |
| 7610 | 7625 | |
| 7611 | 7626 | if (instructions.len == 1) |
| 7612 | | return sema.getTypeOf(instructions[0]); |
| 7627 | return sema.typeOf(instructions[0]); |
| 7613 | 7628 | |
| 7614 | 7629 | const target = sema.mod.getTarget(); |
| 7615 | 7630 | |
| 7616 | 7631 | var chosen = instructions[0]; |
| 7617 | 7632 | for (instructions[1..]) |candidate| { |
| 7618 | | const candidate_ty = sema.getTypeOf(candidate); |
| 7619 | | const chosen_ty = sema.getTypeOf(chosen); |
| 7633 | const candidate_ty = sema.typeOf(candidate); |
| 7634 | const chosen_ty = sema.typeOf(chosen); |
| 7620 | 7635 | if (candidate_ty.eql(chosen_ty)) |
| 7621 | 7636 | continue; |
| 7622 | 7637 | if (candidate_ty.zigTypeTag() == .NoReturn) |
| ... | ... | @@ -7677,7 +7692,7 @@ fn resolvePeerTypes( |
| 7677 | 7692 | return sema.mod.fail(&block.base, src, "incompatible types: '{}' and '{}'", .{ chosen_ty, candidate_ty }); |
| 7678 | 7693 | } |
| 7679 | 7694 | |
| 7680 | | return sema.getTypeOf(chosen); |
| 7695 | return sema.typeOf(chosen); |
| 7681 | 7696 | } |
| 7682 | 7697 | |
| 7683 | 7698 | fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) CompileError!Type { |
| ... | ... | @@ -7753,7 +7768,7 @@ fn getBuiltin( |
| 7753 | 7768 | "builtin", |
| 7754 | 7769 | ); |
| 7755 | 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 | 7772 | const opt_ty_inst = try sema.analyzeNamespaceLookup( |
| 7758 | 7773 | block, |
| 7759 | 7774 | src, |
| ... | ... | @@ -7770,7 +7785,7 @@ fn getBuiltinType( |
| 7770 | 7785 | name: []const u8, |
| 7771 | 7786 | ) CompileError!Type { |
| 7772 | 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 | } |
| 7775 | 7790 | |
| 7776 | 7791 | /// There is another implementation of this in `Type.onePossibleValue`. This one |
| ... | ... | @@ -7970,70 +7985,104 @@ fn enumFieldSrcLoc( |
| 7970 | 7985 | } else unreachable; |
| 7971 | 7986 | } |
| 7972 | 7987 | |
| 7988 | /// This is only meant to be called by `typeOf`. |
| 7989 | fn 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 | 7999 | /// Returns the type of the AIR instruction. |
| 7974 | | fn getTypeOf(sema: *Sema, air_ref: Air.Inst.Ref) Type { |
| 7975 | | switch (air_ref) { |
| 7976 | | .none => unreachable, |
| 7977 | | .u8_type => return Type.initTag(.u8), |
| 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 => {}, |
| 8000 | fn typeOf(sema: *Sema, inst: Air.Inst.Ref) Type { |
| 8001 | var i: usize = @enumToInt(inst); |
| 8002 | if (i < Air.Inst.Ref.typed_value_map.len) { |
| 8003 | return Air.Inst.Ref.typed_value_map[i].ty; |
| 8031 | 8004 | } |
| 8032 | | const air_index = @as(usize, @enumToInt(air_ref)) - Air.Inst.Ref.typed_value_map.len; |
| 8033 | | const air_tags = sema.air_instructions.items(.tag); |
| 8005 | i -= Air.Inst.Ref.typed_value_map.len; |
| 8006 | |
| 8034 | 8007 | const air_datas = sema.air_instructions.items(.data); |
| 8035 | | assert(air_tags[air_index] == .const_ty); |
| 8036 | | return air_datas[air_index].ty; |
| 8008 | switch (sema.air_instructions.items(.tag)[i]) { |
| 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 | } |
| 8038 | 8087 | |
| 8039 | 8088 | pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref { |