Skip to content

Commit 0298442

Browse files
authored
Merge pull request #10753 from ziglang/nerf-type-info
stage1: remove the `data` field from `TypeInfo.Declaration`
2 parents 44b105a + 4d22fa5 commit 0298442

13 files changed

+113
-268
lines changed

lib/std/builtin.zig

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
174175
pub 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

Lines changed: 83 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -164,31 +164,93 @@ const std = @import("std.zig");
164164

165165
pub const errors = @import("crypto/errors.zig");
166166

167-
test "crypto" {
167+
test {
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

194256
test "CSPRNG" {

lib/std/meta.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
364366
pub fn declarations(comptime T: type) []const TypeInfo.Declaration {
365367
return switch (@typeInfo(T)) {
366368
.Struct => |info| info.decls,

lib/std/target.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ test {
465465
/// Given a type, reference all the declarations inside, so that the semantic analyzer sees them.
466466
pub 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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

1719+
static inline bool fn_is_test(const ZigFn *fn) {
1720+
return fn->proto_node->type == NodeTypeTestDecl;
1721+
}
1722+
17201723
uint32_t fn_table_entry_hash(ZigFn*);
17211724
bool fn_table_entry_eql(ZigFn *a, ZigFn *b);
17221725

src/stage1/analyze.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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);

0 commit comments

Comments
 (0)