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(...@@ -13427,7 +13427,7 @@ fn zirBuiltinExtern(
13427}13427}
1342813428
13429fn requireFunctionBlock(sema: *Sema, block: *Block, src: LazySrcLoc) !void {13429fn requireFunctionBlock(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
13430 if (sema.func == null) {13430 if (sema.func == null and !block.is_typeof) {
13431 return sema.fail(block, src, "instruction illegal outside function body", .{});13431 return sema.fail(block, src, "instruction illegal outside function body", .{});
13432 }13432 }
13433}13433}
...@@ -14194,7 +14194,8 @@ fn fieldCallBind(...@@ -14194,7 +14194,8 @@ fn fieldCallBind(
14194 if (first_param_tag == .var_args_param or14194 if (first_param_tag == .var_args_param or
14195 first_param_tag == .generic_poison or (14195 first_param_tag == .generic_poison or (
14196 first_param_type.zigTypeTag() == .Pointer and14196 first_param_type.zigTypeTag() == .Pointer and
14197 first_param_type.ptrSize() == .One and14197 (first_param_type.ptrSize() == .One or
14198 first_param_type.ptrSize() == .C) and
14198 first_param_type.childType().eql(concrete_ty)))14199 first_param_type.childType().eql(concrete_ty)))
14199 {14200 {
14200 // zig fmt: on14201 // zig fmt: on
test/behavior.zig+1-1
...@@ -38,6 +38,7 @@ test {...@@ -38,6 +38,7 @@ test {
38 _ = @import("behavior/bugs/3112.zig");38 _ = @import("behavior/bugs/3112.zig");
39 _ = @import("behavior/bugs/3367.zig");39 _ = @import("behavior/bugs/3367.zig");
40 _ = @import("behavior/bugs/3586.zig");40 _ = @import("behavior/bugs/3586.zig");
41 _ = @import("behavior/bugs/4328.zig");
41 _ = @import("behavior/bugs/4560.zig");42 _ = @import("behavior/bugs/4560.zig");
42 _ = @import("behavior/bugs/4769_a.zig");43 _ = @import("behavior/bugs/4769_a.zig");
43 _ = @import("behavior/bugs/4769_b.zig");44 _ = @import("behavior/bugs/4769_b.zig");
...@@ -150,7 +151,6 @@ test {...@@ -150,7 +151,6 @@ test {
150 _ = @import("behavior/bugs/1851.zig");151 _ = @import("behavior/bugs/1851.zig");
151 _ = @import("behavior/bugs/3384.zig");152 _ = @import("behavior/bugs/3384.zig");
152 _ = @import("behavior/bugs/3779.zig");153 _ = @import("behavior/bugs/3779.zig");
153 _ = @import("behavior/bugs/4328.zig");
154 _ = @import("behavior/bugs/5398.zig");154 _ = @import("behavior/bugs/5398.zig");
155 _ = @import("behavior/bugs/5413.zig");155 _ = @import("behavior/bugs/5413.zig");
156 _ = @import("behavior/bugs/5487.zig");156 _ = @import("behavior/bugs/5487.zig");
test/behavior/bugs/4328.zig+16-7
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const expectEqual = @import("std").testing.expectEqual;1const expect = @import("std").testing.expect;
2const builtin = @import("builtin");
23
3const FILE = extern struct {4const FILE = extern struct {
4 dummy_field: u8,5 dummy_field: u8,
...@@ -16,18 +17,20 @@ const S = extern struct {...@@ -16,18 +17,20 @@ const S = extern struct {
16};17};
1718
18test "Extern function calls in @TypeOf" {19test "Extern function calls in @TypeOf" {
20 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
21
19 const Test = struct {22 const Test = struct {
20 fn test_fn_1(a: anytype, b: anytype) @TypeOf(printf("%d %s\n", a, b)) {23 fn test_fn_1(a: anytype, b: anytype) @TypeOf(printf("%d %s\n", a, b)) {
21 return 0;24 return 0;
22 }25 }
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)) {
25 return 1;28 return 1;
26 }29 }
2730
28 fn doTheTest() !void {31 fn doTheTest() !void {
29 try expectEqual(c_int, @TypeOf(test_fn_1(0, 42)));32 try expect(@TypeOf(test_fn_1(0, 42)) == c_int);
30 try expectEqual(c_short, @TypeOf(test_fn_2(0)));33 try expect(@TypeOf(test_fn_2(&S{ .state = 1 }, 0)) == c_short);
31 }34 }
32 };35 };
3336
...@@ -36,13 +39,15 @@ test "Extern function calls in @TypeOf" {...@@ -36,13 +39,15 @@ test "Extern function calls in @TypeOf" {
36}39}
3740
38test "Peer resolution of extern function calls in @TypeOf" {41test "Peer resolution of extern function calls in @TypeOf" {
42 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
43
39 const Test = struct {44 const Test = struct {
40 fn test_fn() @TypeOf(ftell(null), fputs(null, null)) {45 fn test_fn() @TypeOf(ftell(null), fputs(null, null)) {
41 return 0;46 return 0;
42 }47 }
4348
44 fn doTheTest() !void {49 fn doTheTest() !void {
45 try expectEqual(c_long, @TypeOf(test_fn()));50 try expect(@TypeOf(test_fn()) == c_long);
46 }51 }
47 };52 };
4853
...@@ -51,6 +56,10 @@ test "Peer resolution of extern function calls in @TypeOf" {...@@ -51,6 +56,10 @@ test "Peer resolution of extern function calls in @TypeOf" {
51}56}
5257
53test "Extern function calls, dereferences and field access in @TypeOf" {58test "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
54 const Test = struct {63 const Test = struct {
55 fn test_fn_1(a: c_long) @TypeOf(fopen("test", "r").*) {64 fn test_fn_1(a: c_long) @TypeOf(fopen("test", "r").*) {
56 _ = a;65 _ = a;
...@@ -63,8 +72,8 @@ test "Extern function calls, dereferences and field access in @TypeOf" {...@@ -63,8 +72,8 @@ test "Extern function calls, dereferences and field access in @TypeOf" {
63 }72 }
6473
65 fn doTheTest() !void {74 fn doTheTest() !void {
66 try expectEqual(FILE, @TypeOf(test_fn_1(0)));75 try expect(@TypeOf(test_fn_1(0)) == FILE);
67 try expectEqual(u8, @TypeOf(test_fn_2(0)));76 try expect(@TypeOf(test_fn_2(0)) == u8);
68 }77 }
69 };78 };
7079