authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-01 13:16:00-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-02-01 13:16:00-05:00
log0298442100b2d5707099f09d29af554e8c6ac87e
treec0eefd69483492a922bfcb0ae2bb85db76eed111
parent44b105a38d966a43dcd407b971ea39fe26353eab
parent4d22fa5a2a4afce59b91efc7a6142ec633f0bd4d
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #10753 from ziglang/nerf-type-info

stage1: remove the `data` field from `TypeInfo.Declaration`

13 files changed, 113 insertions(+), 268 deletions(-)

lib/std/builtin.zig+2-22
......@@ -171,6 +171,7 @@ pub const TypeId = std.meta.Tag(TypeInfo);
171171
172172/// This data structure is used by the Zig language code generation and
173173/// therefore must be kept in sync with the compiler implementation.
174/// TODO: rename to `Type` because "info" is redundant.
174175pub const TypeInfo = union(enum) {
175176 Type: void,
176177 Void: void,
......@@ -338,6 +339,7 @@ pub const TypeInfo = union(enum) {
338339
339340 /// This data structure is used by the Zig language code generation and
340341 /// therefore must be kept in sync with the compiler implementation.
342 /// TODO rename to Param and put inside `Fn`.
341343 pub const FnArg = struct {
342344 is_generic: bool,
343345 is_noalias: bool,
......@@ -385,28 +387,6 @@ pub const TypeInfo = union(enum) {
385387 pub const Declaration = struct {
386388 name: []const u8,
387389 is_pub: bool,
388 data: Data,
389
390 /// This data structure is used by the Zig language code generation and
391 /// therefore must be kept in sync with the compiler implementation.
392 pub const Data = union(enum) {
393 Type: type,
394 Var: type,
395 Fn: FnDecl,
396
397 /// This data structure is used by the Zig language code generation and
398 /// therefore must be kept in sync with the compiler implementation.
399 pub const FnDecl = struct {
400 fn_type: type,
401 is_noinline: bool,
402 is_var_args: bool,
403 is_extern: bool,
404 is_export: bool,
405 lib_name: ?[]const u8,
406 return_type: type,
407 arg_names: []const []const u8,
408 };
409 };
410390 };
411391};
412392
lib/std/crypto.zig+83-21
......@@ -164,31 +164,93 @@ const std = @import("std.zig");
164164
165165pub const errors = @import("crypto/errors.zig");
166166
167test "crypto" {
167test {
168168 const please_windows_dont_oom = @import("builtin").os.tag == .windows;
169169 if (please_windows_dont_oom) return error.SkipZigTest;
170170
171 inline for (std.meta.declarations(@This())) |decl| {
172 switch (decl.data) {
173 .Type => |t| {
174 if (@typeInfo(t) != .ErrorSet) {
175 std.testing.refAllDecls(t);
176 }
177 },
178 .Var => |v| {
179 _ = v;
180 },
181 .Fn => |f| {
182 _ = f;
183 },
184 }
185 }
171 _ = aead.aegis.Aegis128L;
172 _ = aead.aegis.Aegis256;
173
174 _ = aead.aes_gcm.Aes128Gcm;
175 _ = aead.aes_gcm.Aes256Gcm;
176
177 _ = aead.aes_ocb.Aes128Ocb;
178 _ = aead.aes_ocb.Aes256Ocb;
179
180 _ = aead.Gimli;
181
182 _ = aead.chacha_poly.ChaCha20Poly1305;
183 _ = aead.chacha_poly.ChaCha12Poly1305;
184 _ = aead.chacha_poly.ChaCha8Poly1305;
185 _ = aead.chacha_poly.XChaCha20Poly1305;
186 _ = aead.chacha_poly.XChaCha12Poly1305;
187 _ = aead.chacha_poly.XChaCha8Poly1305;
188
189 _ = aead.isap;
190 _ = aead.salsa_poly.XSalsa20Poly1305;
191
192 _ = auth.hmac;
193 _ = auth.siphash;
194
195 _ = core.aes;
196 _ = core.Gimli;
197 _ = core.modes;
198
199 _ = dh.X25519;
200
201 _ = ecc.Curve25519;
202 _ = ecc.Edwards25519;
203 _ = ecc.P256;
204 _ = ecc.Ristretto255;
205
206 _ = hash.blake2;
207 _ = hash.Blake3;
208 _ = hash.Gimli;
209 _ = hash.Md5;
210 _ = hash.Sha1;
211 _ = hash.sha2;
212 _ = hash.sha3;
213
214 _ = kdf.hkdf;
215
216 _ = onetimeauth.Ghash;
217 _ = onetimeauth.Poly1305;
218
219 _ = pwhash.Encoding;
220
221 _ = pwhash.Error;
222 _ = pwhash.HasherError;
223 _ = pwhash.KdfError;
224
225 _ = pwhash.argon2;
226 _ = pwhash.bcrypt;
227 _ = pwhash.scrypt;
228 _ = pwhash.pbkdf2;
229
230 _ = pwhash.phc_format;
231
232 _ = sign.Ed25519;
233
234 _ = stream.chacha.ChaCha20IETF;
235 _ = stream.chacha.ChaCha12IETF;
236 _ = stream.chacha.ChaCha8IETF;
237 _ = stream.chacha.ChaCha20With64BitNonce;
238 _ = stream.chacha.ChaCha12With64BitNonce;
239 _ = stream.chacha.ChaCha8With64BitNonce;
240 _ = stream.chacha.XChaCha20IETF;
241 _ = stream.chacha.XChaCha12IETF;
242 _ = stream.chacha.XChaCha8IETF;
243
244 _ = stream.salsa.Salsa20;
245 _ = stream.salsa.XSalsa20;
246
247 _ = nacl.Box;
248 _ = nacl.SecretBox;
249 _ = nacl.SealedBox;
186250
187 _ = @import("crypto/aegis.zig");
188 _ = @import("crypto/aes_gcm.zig");
189 _ = @import("crypto/aes_ocb.zig");
190 _ = @import("crypto/blake2.zig");
191 _ = @import("crypto/chacha20.zig");
251 _ = utils;
252 _ = random;
253 _ = errors;
192254}
193255
194256test "CSPRNG" {
lib/std/meta.zig+2
......@@ -361,6 +361,8 @@ test "std.meta.containerLayout" {
361361 try testing.expect(containerLayout(U3) == .Extern);
362362}
363363
364/// Instead of this function, prefer to use e.g. `@TypeInfo(foo).Struct.decls`
365/// directly when you know what kind of type it is.
364366pub fn declarations(comptime T: type) []const TypeInfo.Declaration {
365367 return switch (@typeInfo(T)) {
366368 .Struct => |info| info.decls,
lib/std/target.zig+1-1
......@@ -1236,7 +1236,7 @@ pub const Target = struct {
12361236 }
12371237
12381238 fn allCpusFromDecls(comptime cpus: type) []const *const Cpu.Model {
1239 const decls = std.meta.declarations(cpus);
1239 const decls = @typeInfo(cpus).Struct.decls;
12401240 var array: [decls.len]*const Cpu.Model = undefined;
12411241 for (decls) |decl, i| {
12421242 array[i] = &@field(cpus, decl.name);
lib/std/testing.zig+1-1
......@@ -465,7 +465,7 @@ test {
465465/// Given a type, reference all the declarations inside, so that the semantic analyzer sees them.
466466pub fn refAllDecls(comptime T: type) void {
467467 if (!builtin.is_test) return;
468 inline for (std.meta.declarations(T)) |decl| {
468 inline for (comptime std.meta.declarations(T)) |decl| {
469469 _ = decl;
470470 }
471471}
src/stage1/all_types.hpp+4-1
......@@ -1713,10 +1713,13 @@ struct ZigFn {
17131713
17141714 bool calls_or_awaits_errorable_fn;
17151715 bool is_cold;
1716 bool is_test;
17171716 bool is_noinline;
17181717};
17191718
1719static inline bool fn_is_test(const ZigFn *fn) {
1720 return fn->proto_node->type == NodeTypeTestDecl;
1721}
1722
17201723uint32_t fn_table_entry_hash(ZigFn*);
17211724bool fn_table_entry_eql(ZigFn *a, ZigFn *b);
17221725
src/stage1/analyze.cpp-1
......@@ -3861,7 +3861,6 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
38613861 fn_table_entry->fndef_scope = create_fndef_scope(g, source_node, tld_fn->base.parent_scope, fn_table_entry);
38623862 fn_table_entry->type_entry = get_test_fn_type(g);
38633863 fn_table_entry->body_node = source_node->data.test_decl.body;
3864 fn_table_entry->is_test = true;
38653864
38663865 g->fn_defs.append(fn_table_entry);
38673866 g->test_fns.append(fn_table_entry);
src/stage1/ir.cpp+16-181
......@@ -17934,7 +17934,6 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, AstNode *source_node, ZigVa
1793417934
1793517935 ensure_field_index(type_info_declaration_type, "name", 0);
1793617936 ensure_field_index(type_info_declaration_type, "is_pub", 1);
17937 ensure_field_index(type_info_declaration_type, "data", 2);
1793817937
1793917938 if (!resolve_types) {
1794017939 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, type_info_declaration_type,
......@@ -17954,61 +17953,27 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, AstNode *source_node, ZigVa
1795417953 return ErrorNone;
1795517954 }
1795617955
17957 ZigType *type_info_declaration_data_type = ir_type_info_get_type(ira, "Data", type_info_declaration_type);
17958 if ((err = type_resolve(ira->codegen, type_info_declaration_data_type, ResolveStatusSizeKnown)))
17959 return err;
17960
17961 ZigType *type_info_fn_decl_type = ir_type_info_get_type(ira, "FnDecl", type_info_declaration_data_type);
17962 if ((err = type_resolve(ira->codegen, type_info_fn_decl_type, ResolveStatusSizeKnown)))
17963 return err;
17964
1796517956 resolve_container_usingnamespace_decls(ira->codegen, decls_scope);
1796617957
17967 // The unresolved declarations are collected in a separate queue to avoid
17968 // modifying decl_table while iterating over it
17969 ZigList<Tld*> resolve_decl_queue{};
17970
17958 // Loop through our declarations once to figure out how many declarations
17959 // we will generate info for.
17960 int declaration_count = 0;
1797117961 auto decl_it = decls_scope->decl_table.entry_iterator();
1797217962 decltype(decls_scope->decl_table)::Entry *curr_entry = nullptr;
17973 while ((curr_entry = decl_it.next()) != nullptr) {
17974 if (curr_entry->value->resolution == TldResolutionInvalid) {
17975 return ErrorSemanticAnalyzeFail;
17976 }
17977
17978 if (curr_entry->value->resolution == TldResolutionResolving) {
17979 ir_error_dependency_loop(ira, source_node);
17980 return ErrorSemanticAnalyzeFail;
17981 }
17982
17983 // If the declaration is unresolved, force it to be resolved again.
17984 if (curr_entry->value->resolution == TldResolutionUnresolved)
17985 resolve_decl_queue.append(curr_entry->value);
17986 }
17987
17988 for (size_t i = 0; i < resolve_decl_queue.length; i++) {
17989 Tld *decl = resolve_decl_queue.at(i);
17990 resolve_top_level_decl(ira->codegen, decl, decl->source_node, false);
17991 if (decl->resolution == TldResolutionInvalid) {
17992 return ErrorSemanticAnalyzeFail;
17993 }
17994 }
17995
17996 resolve_decl_queue.deinit();
17997
17998 // Loop through our declarations once to figure out how many declarations we will generate info for.
17999 int declaration_count = 0;
18000 decl_it = decls_scope->decl_table.entry_iterator();
1800117963 while ((curr_entry = decl_it.next()) != nullptr) {
1800217964 // Skip comptime blocks and test functions.
1800317965 if (curr_entry->value->id == TldIdCompTime)
1800417966 continue;
1800517967
18006 if (curr_entry->value->id == TldIdFn) {
18007 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
18008 if (fn_entry->is_test)
18009 continue;
17968 if (curr_entry->value->id == TldIdFn &&
17969 curr_entry->value->source_node->type == NodeTypeTestDecl)
17970 {
17971 continue;
1801017972 }
1801117973
17974 if (curr_entry->value->resolution == TldResolutionInvalid)
17975 return ErrorSemanticAnalyzeFail;
17976
1801217977 declaration_count += 1;
1801317978 }
1801417979
......@@ -18027,10 +17992,11 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, AstNode *source_node, ZigVa
1802717992 // Skip comptime blocks and test functions.
1802817993 if (curr_entry->value->id == TldIdCompTime) {
1802917994 continue;
18030 } else if (curr_entry->value->id == TldIdFn) {
18031 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
18032 if (fn_entry->is_test)
18033 continue;
17995 }
17996 if (curr_entry->value->id == TldIdFn &&
17997 curr_entry->value->source_node->type == NodeTypeTestDecl)
17998 {
17999 continue;
1803418000 }
1803518001
1803618002 ZigValue *declaration_val = &declaration_array->data.x_array.data.s_none.elements[declaration_index];
......@@ -18038,143 +18004,12 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, AstNode *source_node, ZigVa
1803818004 declaration_val->special = ConstValSpecialStatic;
1803918005 declaration_val->type = type_info_declaration_type;
1804018006
18041 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
18007 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 2);
1804218008 ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;
1804318009 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true, nullptr);
1804418010 inner_fields[1]->special = ConstValSpecialStatic;
1804518011 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;
1804618012 inner_fields[1]->data.x_bool = curr_entry->value->visib_mod == VisibModPub;
18047 inner_fields[2]->special = ConstValSpecialStatic;
18048 inner_fields[2]->type = type_info_declaration_data_type;
18049 inner_fields[2]->parent.id = ConstParentIdStruct;
18050 inner_fields[2]->parent.data.p_struct.struct_val = declaration_val;
18051 inner_fields[2]->parent.data.p_struct.field_index = 1;
18052
18053 switch (curr_entry->value->id) {
18054 case TldIdVar:
18055 {
18056 ZigVar *var = ((TldVar *)curr_entry->value)->var;
18057 assert(var != nullptr);
18058
18059 if ((err = type_resolve(ira->codegen, var->const_value->type, ResolveStatusSizeKnown)))
18060 return ErrorSemanticAnalyzeFail;
18061
18062 if (var->const_value->type->id == ZigTypeIdMetaType) {
18063 // We have a variable of type 'type', so it's actually a type declaration.
18064 // 0: Data.Type: type
18065 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
18066 inner_fields[2]->data.x_union.payload = var->const_value;
18067 } else {
18068 // We have a variable of another type, so we store the type of the variable.
18069 // 1: Data.Var: type
18070 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);
18071
18072 ZigValue *payload = ira->codegen->pass1_arena->create<ZigValue>();
18073 payload->special = ConstValSpecialStatic;
18074 payload->type = ira->codegen->builtin_types.entry_type;
18075 payload->data.x_type = var->const_value->type;
18076
18077 inner_fields[2]->data.x_union.payload = payload;
18078 }
18079
18080 break;
18081 }
18082 case TldIdFn:
18083 {
18084 // 2: Data.Fn: Data.FnDecl
18085 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 2);
18086
18087 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
18088 assert(!fn_entry->is_test);
18089 assert(fn_entry->type_entry != nullptr);
18090
18091 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;
18092
18093 ZigValue *fn_decl_val = ira->codegen->pass1_arena->create<ZigValue>();
18094 fn_decl_val->special = ConstValSpecialStatic;
18095 fn_decl_val->type = type_info_fn_decl_type;
18096 fn_decl_val->parent.id = ConstParentIdUnion;
18097 fn_decl_val->parent.data.p_union.union_val = inner_fields[2];
18098
18099 ZigValue **fn_decl_fields = alloc_const_vals_ptrs(ira->codegen, 9);
18100 fn_decl_val->data.x_struct.fields = fn_decl_fields;
18101
18102 // fn_type: type
18103 ensure_field_index(fn_decl_val->type, "fn_type", 0);
18104 fn_decl_fields[0]->special = ConstValSpecialStatic;
18105 fn_decl_fields[0]->type = ira->codegen->builtin_types.entry_type;
18106 fn_decl_fields[0]->data.x_type = fn_entry->type_entry;
18107 // is_noinline: bool
18108 ensure_field_index(fn_decl_val->type, "is_noinline", 1);
18109 fn_decl_fields[1]->special = ConstValSpecialStatic;
18110 fn_decl_fields[1]->type = ira->codegen->builtin_types.entry_bool;
18111 fn_decl_fields[1]->data.x_bool = fn_entry->is_noinline;
18112 // is_var_args: bool
18113 ensure_field_index(fn_decl_val->type, "is_var_args", 2);
18114 bool is_varargs = fn_node->is_var_args;
18115 fn_decl_fields[2]->special = ConstValSpecialStatic;
18116 fn_decl_fields[2]->type = ira->codegen->builtin_types.entry_bool;
18117 fn_decl_fields[2]->data.x_bool = is_varargs;
18118 // is_extern: bool
18119 ensure_field_index(fn_decl_val->type, "is_extern", 3);
18120 fn_decl_fields[3]->special = ConstValSpecialStatic;
18121 fn_decl_fields[3]->type = ira->codegen->builtin_types.entry_bool;
18122 fn_decl_fields[3]->data.x_bool = fn_node->is_extern;
18123 // is_export: bool
18124 ensure_field_index(fn_decl_val->type, "is_export", 4);
18125 fn_decl_fields[4]->special = ConstValSpecialStatic;
18126 fn_decl_fields[4]->type = ira->codegen->builtin_types.entry_bool;
18127 fn_decl_fields[4]->data.x_bool = fn_node->is_export;
18128 // lib_name: ?[]const u8
18129 ensure_field_index(fn_decl_val->type, "lib_name", 5);
18130 fn_decl_fields[5]->special = ConstValSpecialStatic;
18131 ZigType *u8_ptr = get_pointer_to_type_extra(
18132 ira->codegen, ira->codegen->builtin_types.entry_u8,
18133 true, false, PtrLenUnknown,
18134 0, 0, 0, false);
18135 fn_decl_fields[5]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
18136 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
18137 ZigValue *slice_val = ira->codegen->pass1_arena->create<ZigValue>();
18138 ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;
18139 init_const_slice(ira->codegen, slice_val, lib_name, 0, buf_len(fn_node->lib_name), true, nullptr);
18140 set_optional_payload(fn_decl_fields[5], slice_val);
18141 } else {
18142 set_optional_payload(fn_decl_fields[5], nullptr);
18143 }
18144 // return_type: type
18145 ensure_field_index(fn_decl_val->type, "return_type", 6);
18146 fn_decl_fields[6]->special = ConstValSpecialStatic;
18147 fn_decl_fields[6]->type = ira->codegen->builtin_types.entry_type;
18148 fn_decl_fields[6]->data.x_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
18149 // arg_names: [][] const u8
18150 ensure_field_index(fn_decl_val->type, "arg_names", 7);
18151 size_t fn_arg_count = fn_entry->variable_list.length;
18152 ZigValue *fn_arg_name_array = ira->codegen->pass1_arena->create<ZigValue>();
18153 fn_arg_name_array->special = ConstValSpecialStatic;
18154 fn_arg_name_array->type = get_array_type(ira->codegen,
18155 get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr);
18156 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;
18157 fn_arg_name_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count);
18158
18159 init_const_slice(ira->codegen, fn_decl_fields[7], fn_arg_name_array, 0, fn_arg_count, false, nullptr);
18160
18161 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
18162 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
18163 ZigValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index];
18164 ZigValue *arg_name = create_const_str_lit(ira->codegen,
18165 buf_create_from_str(arg_var->name))->data.x_ptr.data.ref.pointee;
18166 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true, nullptr);
18167 fn_arg_name_val->parent.id = ConstParentIdArray;
18168 fn_arg_name_val->parent.data.p_array.array_val = fn_arg_name_array;
18169 fn_arg_name_val->parent.data.p_array.elem_index = fn_arg_index;
18170 }
18171
18172 inner_fields[2]->data.x_union.payload = fn_decl_val;
18173 break;
18174 }
18175 default:
18176 zig_unreachable();
18177 }
1817818013
1817918014 declaration_val->data.x_struct.fields = inner_fields;
1818018015 declaration_index += 1;
src/translate_c.zig+2-2
......@@ -408,7 +408,7 @@ pub fn translate(
408408 context.pattern_list.deinit(gpa);
409409 }
410410
411 inline for (meta.declarations(std.zig.c_builtins)) |decl| {
411 inline for (@typeInfo(std.zig.c_builtins).Struct.decls) |decl| {
412412 if (decl.is_pub) {
413413 const builtin = try Tag.pub_var_simple.create(context.arena, .{
414414 .name = decl.name,
......@@ -2009,7 +2009,7 @@ fn transImplicitCastExpr(
20092009}
20102010
20112011fn isBuiltinDefined(name: []const u8) bool {
2012 inline for (meta.declarations(std.zig.c_builtins)) |decl| {
2012 inline for (@typeInfo(std.zig.c_builtins).Struct.decls) |decl| {
20132013 if (!decl.is_pub) continue;
20142014 if (std.mem.eql(u8, name, decl.name)) return true;
20152015 }
test/behavior.zig+1
......@@ -149,6 +149,7 @@ test {
149149 _ = @import("behavior/bugs/10147.zig");
150150 _ = @import("behavior/byteswap.zig");
151151 _ = @import("behavior/const_slice_child.zig");
152 _ = @import("behavior/export_self_referential_type_info.zig");
152153 _ = @import("behavior/field_parent_ptr.zig");
153154 _ = @import("behavior/floatop_stage1.zig");
154155 _ = @import("behavior/fn_delegation.zig");
test/behavior/export_self_referential_type_info.zig created+1
......@@ -0,0 +1 @@
1export const foo = @typeInfo(@This()).Struct.decls;
test/behavior/type_info.zig-32
......@@ -286,10 +286,6 @@ fn testStruct() !void {
286286 try expect(struct_info.Struct.fields[3].alignment == 1);
287287 try expect(struct_info.Struct.decls.len == 2);
288288 try expect(struct_info.Struct.decls[0].is_pub);
289 try expect(!struct_info.Struct.decls[0].data.Fn.is_extern);
290 try expect(struct_info.Struct.decls[0].data.Fn.lib_name == null);
291 try expect(struct_info.Struct.decls[0].data.Fn.return_type == void);
292 try expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void);
293289}
294290
295291const TestUnpackedStruct = struct {
......@@ -420,34 +416,6 @@ test "type info: TypeId -> TypeInfo impl cast" {
420416 _ = comptime passTypeInfo(TypeId.Void);
421417}
422418
423test "type info: extern fns with and without lib names" {
424 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
425
426 const S = struct {
427 extern fn bar1() void;
428 extern "cool" fn bar2() void;
429 };
430 const info = @typeInfo(S);
431 comptime {
432 for (info.Struct.decls) |decl| {
433 if (std.mem.eql(u8, decl.name, "bar1")) {
434 try expect(decl.data.Fn.lib_name == null);
435 } else {
436 try expectEqualStrings("cool", decl.data.Fn.lib_name.?);
437 }
438 }
439 }
440}
441
442test "data field is a compile-time value" {
443 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
444
445 const S = struct {
446 const Bar = @as(isize, -1);
447 };
448 comptime try expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
449}
450
451419test "sentinel of opaque pointer type" {
452420 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
453421
test/compile_errors.zig-6
......@@ -1199,12 +1199,6 @@ pub fn addCases(ctx: *TestContext) !void {
11991199 "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'",
12001200 });
12011201
1202 ctx.testErrStage1("dependency loop in top-level decl with @TypeInfo when accessing the decls",
1203 \\export const foo = @typeInfo(@This()).Struct.decls;
1204 , &[_][]const u8{
1205 "tmp.zig:1:20: error: dependency loop detected",
1206 });
1207
12081202 ctx.objErrStage1("function call assigned to incorrect type",
12091203 \\export fn entry() void {
12101204 \\ var arr: [4]f32 = undefined;