| author | |
| committer | |
| log | 52ec121469d7bf10116fb22c122cbce8ceddd028 |
| tree | dc37b0986aecc60639e4b2e105c4740a14dd8c58 |
| parent | d7bd4f339c90b9ce07283600cb7ef129912ceef3 |
4 files changed, 37 insertions(+), 23 deletions(-)
src/Air.zig+1-1| ... | @@ -1406,7 +1406,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) | ... | @@ -1406,7 +1406,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) |
| 1406 | 1406 | ||
| 1407 | .call, .call_always_tail, .call_never_tail, .call_never_inline => { | 1407 | .call, .call_always_tail, .call_never_tail, .call_never_inline => { |
| 1408 | const callee_ty = air.typeOf(datas[inst].pl_op.operand, ip); | 1408 | const callee_ty = air.typeOf(datas[inst].pl_op.operand, ip); |
| 1409 | return callee_ty.fnReturnTypeIp(ip); | 1409 | return ip.funcReturnType(callee_ty.toIntern()).toType(); |
| 1410 | }, | 1410 | }, |
| 1411 | 1411 | ||
| 1412 | .slice_elem_val, .ptr_elem_val, .array_elem_val => { | 1412 | .slice_elem_val, .ptr_elem_val, .array_elem_val => { |
src/InternPool.zig+17-2| ... | @@ -5694,11 +5694,26 @@ pub fn aggregateTypeLenIncludingSentinel(ip: *const InternPool, ty: Index) u64 { | ... | @@ -5694,11 +5694,26 @@ pub fn aggregateTypeLenIncludingSentinel(ip: *const InternPool, ty: Index) u64 { |
| 5694 | }; | 5694 | }; |
| 5695 | } | 5695 | } |
| 5696 | 5696 | ||
| 5697 | pub fn funcReturnType(ip: *const InternPool, ty: Index) Index { | ||
| 5698 | const item = ip.items.get(@intFromEnum(ty)); | ||
| 5699 | const child_item = switch (item.tag) { | ||
| 5700 | .type_pointer => ip.items.get(ip.extra.items[ | ||
| 5701 | item.data + std.meta.fieldIndex(Tag.TypePointer, "child").? | ||
| 5702 | ]), | ||
| 5703 | .type_function => item, | ||
| 5704 | else => unreachable, | ||
| 5705 | }; | ||
| 5706 | assert(child_item.tag == .type_function); | ||
| 5707 | return @enumFromInt(Index, ip.extra.items[ | ||
| 5708 | child_item.data + std.meta.fieldIndex(TypeFunction, "return_type").? | ||
| 5709 | ]); | ||
| 5710 | } | ||
| 5711 | |||
| 5697 | pub fn isNoReturn(ip: *const InternPool, ty: Index) bool { | 5712 | pub fn isNoReturn(ip: *const InternPool, ty: Index) bool { |
| 5698 | return switch (ty) { | 5713 | return switch (ty) { |
| 5699 | .noreturn_type => true, | 5714 | .noreturn_type => true, |
| 5700 | else => switch (ip.indexToKey(ty)) { | 5715 | else => switch (ip.items.items(.tag)[@intFromEnum(ty)]) { |
| 5701 | .error_set_type => |error_set_type| error_set_type.names.len == 0, | 5716 | .type_error_set => ip.extra.items[ip.items.items(.data)[@intFromEnum(ty)] + std.meta.fieldIndex(ErrorSet, "names_len").?] == 0, |
| 5702 | else => false, | 5717 | else => false, |
| 5703 | }, | 5718 | }, |
| 5704 | }; | 5719 | }; |
src/Sema.zig+18-11| ... | @@ -33817,18 +33817,25 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type { | ... | @@ -33817,18 +33817,25 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type { |
| 33817 | .call_modifier_type => return sema.getBuiltinType("CallModifier"), | 33817 | .call_modifier_type => return sema.getBuiltinType("CallModifier"), |
| 33818 | .prefetch_options_type => return sema.getBuiltinType("PrefetchOptions"), | 33818 | .prefetch_options_type => return sema.getBuiltinType("PrefetchOptions"), |
| 33819 | 33819 | ||
| 33820 | _ => switch (mod.intern_pool.indexToKey(ty.toIntern())) { | 33820 | _ => switch (mod.intern_pool.items.items(.tag)[@intFromEnum(ty.toIntern())]) { |
| 33821 | .struct_type => |struct_type| { | 33821 | .type_struct, |
| 33822 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return ty; | 33822 | .type_struct_ns, |
| 33823 | try sema.resolveTypeFieldsStruct(ty, struct_obj); | 33823 | .type_union_tagged, |
| 33824 | return ty; | 33824 | .type_union_untagged, |
| 33825 | }, | 33825 | .type_union_safety, |
| 33826 | .union_type => |union_type| { | 33826 | => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 33827 | const union_obj = mod.unionPtr(union_type.index); | 33827 | .struct_type => |struct_type| { |
| 33828 | try sema.resolveTypeFieldsUnion(ty, union_obj); | 33828 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return ty; |
| 33829 | return ty; | 33829 | try sema.resolveTypeFieldsStruct(ty, struct_obj); |
| 33830 | return ty; | ||
| 33831 | }, | ||
| 33832 | .union_type => |union_type| { | ||
| 33833 | const union_obj = mod.unionPtr(union_type.index); | ||
| 33834 | try sema.resolveTypeFieldsUnion(ty, union_obj); | ||
| 33835 | return ty; | ||
| 33836 | }, | ||
| 33837 | else => unreachable, | ||
| 33830 | }, | 33838 | }, |
| 33831 | |||
| 33832 | else => return ty, | 33839 | else => return ty, |
| 33833 | }, | 33840 | }, |
| 33834 | } | 33841 | } |
src/type.zig+1-9| ... | @@ -2385,15 +2385,7 @@ pub const Type = struct { | ... | @@ -2385,15 +2385,7 @@ pub const Type = struct { |
| 2385 | 2385 | ||
| 2386 | /// Asserts the type is a function or a function pointer. | 2386 | /// Asserts the type is a function or a function pointer. |
| 2387 | pub fn fnReturnType(ty: Type, mod: *Module) Type { | 2387 | pub fn fnReturnType(ty: Type, mod: *Module) Type { |
| 2388 | return fnReturnTypeIp(ty, &mod.intern_pool); | 2388 | return mod.intern_pool.funcReturnType(ty.toIntern()).toType(); |
| 2389 | } | ||
| 2390 | |||
| 2391 | pub fn fnReturnTypeIp(ty: Type, ip: *const InternPool) Type { | ||
| 2392 | return switch (ip.indexToKey(ty.toIntern())) { | ||
| 2393 | .ptr_type => |ptr_type| ip.indexToKey(ptr_type.child).func_type.return_type, | ||
| 2394 | .func_type => |func_type| func_type.return_type, | ||
| 2395 | else => unreachable, | ||
| 2396 | }.toType(); | ||
| 2397 | } | 2389 | } |
| 2398 | 2390 | ||
| 2399 | /// Asserts the type is a function. | 2391 | /// Asserts the type is a function. |