authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-31 15:19:25-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-05-31 15:19:25-04:00
logd09d61be979fc97233bd53d9d082a86e4dcd9779
tree502e0476e43e1a8ea0e0dd9e48e9fb8f76d1dd7c
parentd410693dadfe791e616e78239fa0cec707b95cfa
parent282437c7538e3e70ce06cfee7affe976de28a780
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #11762 from Vexu/stage2

Stage2 fixes

3 files changed, 47 insertions(+), 10 deletions(-)

src/Sema.zig+6-3
...@@ -2976,7 +2976,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -2976,7 +2976,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
29762976
2977 // Even though we reuse the constant instruction, we still remove it from the2977 // Even though we reuse the constant instruction, we still remove it from the
2978 // block so that codegen does not see it.2978 // block so that codegen does not see it.
2979 block.instructions.shrinkRetainingCapacity(block.instructions.items.len - 3);2979 block.instructions.shrinkRetainingCapacity(search_index);
2980 sema.air_values.items[value_index] = try Value.Tag.decl_ref.create(sema.arena, new_decl_index);2980 sema.air_values.items[value_index] = try Value.Tag.decl_ref.create(sema.arena, new_decl_index);
2981 // if bitcast ty ref needs to be made const, make_ptr_const2981 // if bitcast ty ref needs to be made const, make_ptr_const
2982 // ZIR handles it later, so we can just use the ty ref here.2982 // ZIR handles it later, so we can just use the ty ref here.
...@@ -13011,10 +13011,13 @@ fn analyzeRet(...@@ -13011,10 +13011,13 @@ fn analyzeRet(
13011 const backend_supports_error_return_tracing =13011 const backend_supports_error_return_tracing =
13012 sema.mod.comp.bin_file.options.use_llvm;13012 sema.mod.comp.bin_file.options.use_llvm;
1301313013
13014 if ((sema.fn_ret_ty.zigTypeTag() == .ErrorSet or sema.typeOf(uncasted_operand).zigTypeTag() == .ErrorUnion) and13014 if (sema.fn_ret_ty.isError() and
13015 sema.mod.comp.bin_file.options.error_return_tracing and13015 sema.mod.comp.bin_file.options.error_return_tracing and
13016 backend_supports_error_return_tracing)13016 backend_supports_error_return_tracing)
13017 {13017 ret_err: {
13018 if (try sema.resolveMaybeUndefVal(block, src, operand)) |ret_val| {
13019 if (ret_val.tag() != .@"error") break :ret_err;
13020 }
13018 const return_err_fn = try sema.getBuiltin(block, src, "returnError");13021 const return_err_fn = try sema.getBuiltin(block, src, "returnError");
13019 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");13022 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");
13020 const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);13023 const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);
src/type.zig+13-7
...@@ -640,16 +640,16 @@ pub const Type = extern union {...@@ -640,16 +640,16 @@ pub const Type = extern union {
640 if (!eql(a_info.return_type, b_info.return_type, mod))640 if (!eql(a_info.return_type, b_info.return_type, mod))
641 return false;641 return false;
642642
643 if (a_info.cc != b_info.cc)643 if (a_info.is_var_args != b_info.is_var_args)
644 return false;644 return false;
645645
646 if (a_info.alignment != b_info.alignment)646 if (a_info.is_generic != b_info.is_generic)
647 return false;647 return false;
648648
649 if (a_info.is_var_args != b_info.is_var_args)649 if (!a_info.cc_is_generic and a_info.cc != b_info.cc)
650 return false;650 return false;
651651
652 if (a_info.is_generic != b_info.is_generic)652 if (!a_info.align_is_generic and a_info.alignment != b_info.alignment)
653 return false;653 return false;
654654
655 if (a_info.param_types.len != b_info.param_types.len)655 if (a_info.param_types.len != b_info.param_types.len)
...@@ -1036,9 +1036,15 @@ pub const Type = extern union {...@@ -1036,9 +1036,15 @@ pub const Type = extern union {
1036 std.hash.autoHash(hasher, std.builtin.TypeId.Fn);1036 std.hash.autoHash(hasher, std.builtin.TypeId.Fn);
10371037
1038 const fn_info = ty.fnInfo();1038 const fn_info = ty.fnInfo();
1039 hashWithHasher(fn_info.return_type, hasher, mod);1039 if (fn_info.return_type.tag() != .generic_poison) {
1040 std.hash.autoHash(hasher, fn_info.alignment);1040 hashWithHasher(fn_info.return_type, hasher, mod);
1041 std.hash.autoHash(hasher, fn_info.cc);1041 }
1042 if (!fn_info.align_is_generic) {
1043 std.hash.autoHash(hasher, fn_info.alignment);
1044 }
1045 if (!fn_info.cc_is_generic) {
1046 std.hash.autoHash(hasher, fn_info.cc);
1047 }
1042 std.hash.autoHash(hasher, fn_info.is_var_args);1048 std.hash.autoHash(hasher, fn_info.is_var_args);
1043 std.hash.autoHash(hasher, fn_info.is_generic);1049 std.hash.autoHash(hasher, fn_info.is_generic);
10441050
test/behavior/basic.zig+28
...@@ -977,3 +977,31 @@ test "weird array and tuple initializations" {...@@ -977,3 +977,31 @@ test "weird array and tuple initializations" {
977 .b = if (a) .{ .e = .a } else .{ .e = .b },977 .b = if (a) .{ .e = .a } else .{ .e = .b },
978 };978 };
979}979}
980
981test "array type comes from generic function" {
982 const S = struct {
983 fn A() type {
984 return struct { a: u8 = 0 };
985 }
986 };
987 const args = [_]S.A(){.{}};
988 _ = args;
989}
990
991test "generic function uses return type of other generic function" {
992 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
993
994 const S = struct {
995 fn call(
996 f: anytype,
997 args: anytype,
998 ) @TypeOf(@call(.{}, f, @as(@TypeOf(args), undefined))) {
999 return @call(.{}, f, args);
1000 }
1001
1002 fn func(arg: anytype) @TypeOf(arg) {
1003 return arg;
1004 }
1005 };
1006 try std.testing.expect(S.call(S.func, .{@as(u8, 1)}) == 1);
1007}