authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-26 18:06:06+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-26 18:08:31+02:00
log315d4e84425ddff888de8d464f657981e4c45da7
tree6c5f4bf623b276963cec98ebbf713d2a752e9e01
parentff72b8a8194573bc1d7f95cbf3228b363194c775

stage2: do not require function when evaluating typeOf

We only care about the instructions type; it will never actually be codegen'd.

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

src/Sema.zig+3-2
......@@ -13427,7 +13427,7 @@ fn zirBuiltinExtern(
1342713427}
1342813428
1342913429fn requireFunctionBlock(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
13430 if (sema.func == null) {
13430 if (sema.func == null and !block.is_typeof) {
1343113431 return sema.fail(block, src, "instruction illegal outside function body", .{});
1343213432 }
1343313433}
......@@ -14194,7 +14194,8 @@ fn fieldCallBind(
1419414194 if (first_param_tag == .var_args_param or
1419514195 first_param_tag == .generic_poison or (
1419614196 first_param_type.zigTypeTag() == .Pointer and
14197 first_param_type.ptrSize() == .One and
14197 (first_param_type.ptrSize() == .One or
14198 first_param_type.ptrSize() == .C) and
1419814199 first_param_type.childType().eql(concrete_ty)))
1419914200 {
1420014201 // zig fmt: on
test/behavior.zig+1-1
......@@ -38,6 +38,7 @@ test {
3838 _ = @import("behavior/bugs/3112.zig");
3939 _ = @import("behavior/bugs/3367.zig");
4040 _ = @import("behavior/bugs/3586.zig");
41 _ = @import("behavior/bugs/4328.zig");
4142 _ = @import("behavior/bugs/4560.zig");
4243 _ = @import("behavior/bugs/4769_a.zig");
4344 _ = @import("behavior/bugs/4769_b.zig");
......@@ -150,7 +151,6 @@ test {
150151 _ = @import("behavior/bugs/1851.zig");
151152 _ = @import("behavior/bugs/3384.zig");
152153 _ = @import("behavior/bugs/3779.zig");
153 _ = @import("behavior/bugs/4328.zig");
154154 _ = @import("behavior/bugs/5398.zig");
155155 _ = @import("behavior/bugs/5413.zig");
156156 _ = @import("behavior/bugs/5487.zig");
test/behavior/bugs/4328.zig+16-7
......@@ -1,4 +1,5 @@
1const expectEqual = @import("std").testing.expectEqual;
1const expect = @import("std").testing.expect;
2const builtin = @import("builtin");
23
34const FILE = extern struct {
45 dummy_field: u8,
......@@ -16,18 +17,20 @@ const S = extern struct {
1617};
1718
1819test "Extern function calls in @TypeOf" {
20 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
21
1922 const Test = struct {
2023 fn test_fn_1(a: anytype, b: anytype) @TypeOf(printf("%d %s\n", a, b)) {
2124 return 0;
2225 }
2326
24 fn test_fn_2(a: anytype) @TypeOf((S{ .state = 0 }).s_do_thing(a)) {
27 fn test_fn_2(s: anytype, a: anytype) @TypeOf(s.s_do_thing(a)) {
2528 return 1;
2629 }
2730
2831 fn doTheTest() !void {
29 try expectEqual(c_int, @TypeOf(test_fn_1(0, 42)));
30 try expectEqual(c_short, @TypeOf(test_fn_2(0)));
32 try expect(@TypeOf(test_fn_1(0, 42)) == c_int);
33 try expect(@TypeOf(test_fn_2(&S{ .state = 1 }, 0)) == c_short);
3134 }
3235 };
3336
......@@ -36,13 +39,15 @@ test "Extern function calls in @TypeOf" {
3639}
3740
3841test "Peer resolution of extern function calls in @TypeOf" {
42 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
43
3944 const Test = struct {
4045 fn test_fn() @TypeOf(ftell(null), fputs(null, null)) {
4146 return 0;
4247 }
4348
4449 fn doTheTest() !void {
45 try expectEqual(c_long, @TypeOf(test_fn()));
50 try expect(@TypeOf(test_fn()) == c_long);
4651 }
4752 };
4853
......@@ -51,6 +56,10 @@ test "Peer resolution of extern function calls in @TypeOf" {
5156}
5257
5358test "Extern function calls, dereferences and field access in @TypeOf" {
59 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
60 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
61 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
62
5463 const Test = struct {
5564 fn test_fn_1(a: c_long) @TypeOf(fopen("test", "r").*) {
5665 _ = a;
......@@ -63,8 +72,8 @@ test "Extern function calls, dereferences and field access in @TypeOf" {
6372 }
6473
6574 fn doTheTest() !void {
66 try expectEqual(FILE, @TypeOf(test_fn_1(0)));
67 try expectEqual(u8, @TypeOf(test_fn_2(0)));
75 try expect(@TypeOf(test_fn_1(0)) == FILE);
76 try expect(@TypeOf(test_fn_2(0)) == u8);
6877 }
6978 };
7079