Skip to content

Commit d09d61b

Browse files
authored
Merge pull request #11762 from Vexu/stage2
Stage2 fixes
2 parents d410693 + 282437c commit d09d61b

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

src/Sema.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
29762976

29772977
// Even though we reuse the constant instruction, we still remove it from the
29782978
// block so that codegen does not see it.
2979-
block.instructions.shrinkRetainingCapacity(block.instructions.items.len - 3);
2979+
block.instructions.shrinkRetainingCapacity(search_index);
29802980
sema.air_values.items[value_index] = try Value.Tag.decl_ref.create(sema.arena, new_decl_index);
29812981
// if bitcast ty ref needs to be made const, make_ptr_const
29822982
// ZIR handles it later, so we can just use the ty ref here.
@@ -13011,10 +13011,13 @@ fn analyzeRet(
1301113011
const backend_supports_error_return_tracing =
1301213012
sema.mod.comp.bin_file.options.use_llvm;
1301313013

13014-
if ((sema.fn_ret_ty.zigTypeTag() == .ErrorSet or sema.typeOf(uncasted_operand).zigTypeTag() == .ErrorUnion) and
13014+
if (sema.fn_ret_ty.isError() and
1301513015
sema.mod.comp.bin_file.options.error_return_tracing and
1301613016
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+
}
1301813021
const return_err_fn = try sema.getBuiltin(block, src, "returnError");
1301913022
const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");
1302013023
const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);

src/type.zig

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -640,16 +640,16 @@ pub const Type = extern union {
640640
if (!eql(a_info.return_type, b_info.return_type, mod))
641641
return false;
642642

643-
if (a_info.cc != b_info.cc)
643+
if (a_info.is_var_args != b_info.is_var_args)
644644
return false;
645645

646-
if (a_info.alignment != b_info.alignment)
646+
if (a_info.is_generic != b_info.is_generic)
647647
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)
650650
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)
653653
return false;
654654

655655
if (a_info.param_types.len != b_info.param_types.len)
@@ -1036,9 +1036,15 @@ pub const Type = extern union {
10361036
std.hash.autoHash(hasher, std.builtin.TypeId.Fn);
10371037

10381038
const fn_info = ty.fnInfo();
1039-
hashWithHasher(fn_info.return_type, hasher, mod);
1040-
std.hash.autoHash(hasher, fn_info.alignment);
1041-
std.hash.autoHash(hasher, fn_info.cc);
1039+
if (fn_info.return_type.tag() != .generic_poison) {
1040+
hashWithHasher(fn_info.return_type, hasher, mod);
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+
}
10421048
std.hash.autoHash(hasher, fn_info.is_var_args);
10431049
std.hash.autoHash(hasher, fn_info.is_generic);
10441050

test/behavior/basic.zig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,3 +977,31 @@ test "weird array and tuple initializations" {
977977
.b = if (a) .{ .e = .a } else .{ .e = .b },
978978
};
979979
}
980+
981+
test "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+
991+
test "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+
}

0 commit comments

Comments
 (0)