| author | |
| committer | |
| log | 3c08fe931a10618950c6af9e89226d1d9b20bbb9 |
| tree | e745ce6e163c0af808adc8322a6c83e5ba426641 |
| parent | 972e70b7941561b10f9b3062dcd7b7a91016c546 |
fixes #10731
Thanks @nektro for previous work in #14878
This change creates a small breaking change:
It removes the `is_pub` field of a decl in `@typeInfo`10 files changed, 64 insertions(+), 52 deletions(-)
lib/std/builtin.zig-1| ... | ... | @@ -437,7 +437,6 @@ pub const Type = union(enum) { |
| 437 | 437 | /// therefore must be kept in sync with the compiler implementation. |
| 438 | 438 | pub const Declaration = struct { |
| 439 | 439 | name: []const u8, |
| 440 | is_pub: bool, | |
| 441 | 440 | }; |
| 442 | 441 | }; |
| 443 | 442 |
lib/std/meta.zig+14-16| ... | ... | @@ -293,18 +293,18 @@ test "std.meta.declarations" { |
| 293 | 293 | const E1 = enum { |
| 294 | 294 | A, |
| 295 | 295 | |
| 296 | fn a() void {} | |
| 296 | pub fn a() void {} | |
| 297 | 297 | }; |
| 298 | 298 | const S1 = struct { |
| 299 | fn a() void {} | |
| 299 | pub fn a() void {} | |
| 300 | 300 | }; |
| 301 | 301 | const U1 = union { |
| 302 | 302 | a: u8, |
| 303 | 303 | |
| 304 | fn a() void {} | |
| 304 | pub fn a() void {} | |
| 305 | 305 | }; |
| 306 | 306 | const O1 = opaque { |
| 307 | fn a() void {} | |
| 307 | pub fn a() void {} | |
| 308 | 308 | }; |
| 309 | 309 | |
| 310 | 310 | const decls = comptime [_][]const Type.Declaration{ |
| ... | ... | @@ -333,15 +333,15 @@ test "std.meta.declarationInfo" { |
| 333 | 333 | const E1 = enum { |
| 334 | 334 | A, |
| 335 | 335 | |
| 336 | fn a() void {} | |
| 336 | pub fn a() void {} | |
| 337 | 337 | }; |
| 338 | 338 | const S1 = struct { |
| 339 | fn a() void {} | |
| 339 | pub fn a() void {} | |
| 340 | 340 | }; |
| 341 | 341 | const U1 = union { |
| 342 | 342 | a: u8, |
| 343 | 343 | |
| 344 | fn a() void {} | |
| 344 | pub fn a() void {} | |
| 345 | 345 | }; |
| 346 | 346 | |
| 347 | 347 | const infos = comptime [_]Type.Declaration{ |
| ... | ... | @@ -352,7 +352,6 @@ test "std.meta.declarationInfo" { |
| 352 | 352 | |
| 353 | 353 | inline for (infos) |info| { |
| 354 | 354 | try testing.expect(comptime mem.eql(u8, info.name, "a")); |
| 355 | try testing.expect(!info.is_pub); | |
| 356 | 355 | } |
| 357 | 356 | } |
| 358 | 357 | pub fn fields(comptime T: type) switch (@typeInfo(T)) { |
| ... | ... | @@ -597,7 +596,6 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { |
| 597 | 596 | if (expected_decls.len != actual_decls.len) return error.FailedTest; |
| 598 | 597 | for (expected_decls, 0..) |expected_decl, i| { |
| 599 | 598 | const actual_decl = actual_decls[i]; |
| 600 | try testing.expectEqual(expected_decl.is_pub, actual_decl.is_pub); | |
| 601 | 599 | try testing.expectEqualStrings(expected_decl.name, actual_decl.name); |
| 602 | 600 | } |
| 603 | 601 | } |
| ... | ... | @@ -644,21 +642,21 @@ pub fn DeclEnum(comptime T: type) type { |
| 644 | 642 | |
| 645 | 643 | test "std.meta.DeclEnum" { |
| 646 | 644 | const A = struct { |
| 647 | const a: u8 = 0; | |
| 645 | pub const a: u8 = 0; | |
| 648 | 646 | }; |
| 649 | 647 | const B = union { |
| 650 | 648 | foo: void, |
| 651 | 649 | |
| 652 | const a: u8 = 0; | |
| 653 | const b: void = {}; | |
| 654 | const c: f32 = 0; | |
| 650 | pub const a: u8 = 0; | |
| 651 | pub const b: void = {}; | |
| 652 | pub const c: f32 = 0; | |
| 655 | 653 | }; |
| 656 | 654 | const C = enum { |
| 657 | 655 | bar, |
| 658 | 656 | |
| 659 | const a: u8 = 0; | |
| 660 | const b: void = {}; | |
| 661 | const c: f32 = 0; | |
| 657 | pub const a: u8 = 0; | |
| 658 | pub const b: void = {}; | |
| 659 | pub const c: f32 = 0; | |
| 662 | 660 | }; |
| 663 | 661 | try expectEqualEnum(enum { a }, DeclEnum(A)); |
| 664 | 662 | try expectEqualEnum(enum { a, b, c }, DeclEnum(B)); |
lib/std/testing.zig+6-8| ... | ... | @@ -1122,7 +1122,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime |
| 1122 | 1122 | pub fn refAllDecls(comptime T: type) void { |
| 1123 | 1123 | if (!builtin.is_test) return; |
| 1124 | 1124 | inline for (comptime std.meta.declarations(T)) |decl| { |
| 1125 | if (decl.is_pub) _ = &@field(T, decl.name); | |
| 1125 | _ = &@field(T, decl.name); | |
| 1126 | 1126 | } |
| 1127 | 1127 | } |
| 1128 | 1128 | |
| ... | ... | @@ -1131,14 +1131,12 @@ pub fn refAllDecls(comptime T: type) void { |
| 1131 | 1131 | pub fn refAllDeclsRecursive(comptime T: type) void { |
| 1132 | 1132 | if (!builtin.is_test) return; |
| 1133 | 1133 | inline for (comptime std.meta.declarations(T)) |decl| { |
| 1134 | if (decl.is_pub) { | |
| 1135 | if (@TypeOf(@field(T, decl.name)) == type) { | |
| 1136 | switch (@typeInfo(@field(T, decl.name))) { | |
| 1137 | .Struct, .Enum, .Union, .Opaque => refAllDeclsRecursive(@field(T, decl.name)), | |
| 1138 | else => {}, | |
| 1139 | } | |
| 1134 | if (@TypeOf(@field(T, decl.name)) == type) { | |
| 1135 | switch (@typeInfo(@field(T, decl.name))) { | |
| 1136 | .Struct, .Enum, .Union, .Opaque => refAllDeclsRecursive(@field(T, decl.name)), | |
| 1137 | else => {}, | |
| 1140 | 1138 | } |
| 1141 | _ = &@field(T, decl.name); | |
| 1142 | 1139 | } |
| 1140 | _ = &@field(T, decl.name); | |
| 1143 | 1141 | } |
| 1144 | 1142 | } |
src/Sema.zig+1-3| ... | ... | @@ -17526,7 +17526,7 @@ fn typeInfoNamespaceDecls( |
| 17526 | 17526 | try sema.typeInfoNamespaceDecls(block, new_ns, declaration_ty, decl_vals, seen_namespaces); |
| 17527 | 17527 | continue; |
| 17528 | 17528 | } |
| 17529 | if (decl.kind != .named) continue; | |
| 17529 | if (decl.kind != .named or !decl.is_pub) continue; | |
| 17530 | 17530 | const name_val = v: { |
| 17531 | 17531 | var anon_decl = try block.startAnonDecl(); |
| 17532 | 17532 | defer anon_decl.deinit(); |
| ... | ... | @@ -17554,8 +17554,6 @@ fn typeInfoNamespaceDecls( |
| 17554 | 17554 | const fields = .{ |
| 17555 | 17555 | //name: []const u8, |
| 17556 | 17556 | name_val, |
| 17557 | //is_pub: bool, | |
| 17558 | Value.makeBool(decl.is_pub).toIntern(), | |
| 17559 | 17557 | }; |
| 17560 | 17558 | try decl_vals.append(try mod.intern(.{ .aggregate = .{ |
| 17561 | 17559 | .ty = declaration_ty.toIntern(), |
src/codegen/llvm/Builder.zig-1| ... | ... | @@ -1159,7 +1159,6 @@ pub const Attribute = union(Kind) { |
| 1159 | 1159 | var any = false; |
| 1160 | 1160 | var remaining: Int = @bitCast(fpclass); |
| 1161 | 1161 | inline for (@typeInfo(FpClass).Struct.decls) |decl| { |
| 1162 | if (!decl.is_pub) continue; | |
| 1163 | 1162 | const pattern: Int = @bitCast(@field(FpClass, decl.name)); |
| 1164 | 1163 | if (remaining & pattern == pattern) { |
| 1165 | 1164 | if (!any) { |
src/translate_c.zig+5-8| ... | ... | @@ -408,13 +408,11 @@ pub fn translate( |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | inline for (@typeInfo(std.zig.c_builtins).Struct.decls) |decl| { |
| 411 | if (decl.is_pub) { | |
| 412 | const builtin = try Tag.pub_var_simple.create(arena, .{ | |
| 413 | .name = decl.name, | |
| 414 | .init = try Tag.import_c_builtin.create(arena, decl.name), | |
| 415 | }); | |
| 416 | try addTopLevelDecl(&context, decl.name, builtin); | |
| 417 | } | |
| 411 | const builtin = try Tag.pub_var_simple.create(arena, .{ | |
| 412 | .name = decl.name, | |
| 413 | .init = try Tag.import_c_builtin.create(arena, decl.name), | |
| 414 | }); | |
| 415 | try addTopLevelDecl(&context, decl.name, builtin); | |
| 418 | 416 | } |
| 419 | 417 | |
| 420 | 418 | try prepopulateGlobalNameTable(ast_unit, &context); |
| ... | ... | @@ -2120,7 +2118,6 @@ fn transImplicitCastExpr( |
| 2120 | 2118 | |
| 2121 | 2119 | fn isBuiltinDefined(name: []const u8) bool { |
| 2122 | 2120 | inline for (@typeInfo(std.zig.c_builtins).Struct.decls) |decl| { |
| 2123 | if (!decl.is_pub) continue; | |
| 2124 | 2121 | if (std.mem.eql(u8, name, decl.name)) return true; |
| 2125 | 2122 | } |
| 2126 | 2123 | return false; |
test/behavior.zig+1| ... | ... | @@ -222,6 +222,7 @@ test { |
| 222 | 222 | _ = @import("behavior/tuple_declarations.zig"); |
| 223 | 223 | _ = @import("behavior/type.zig"); |
| 224 | 224 | _ = @import("behavior/type_info.zig"); |
| 225 | _ = @import("behavior/type_info_only_pub_decls.zig"); | |
| 225 | 226 | _ = @import("behavior/typename.zig"); |
| 226 | 227 | _ = @import("behavior/undefined.zig"); |
| 227 | 228 | _ = @import("behavior/underscore.zig"); |
test/behavior/eval.zig+1-1| ... | ... | @@ -959,7 +959,7 @@ test "debug variable type resolved through indirect zero-bit types" { |
| 959 | 959 | test "const local with comptime init through array init" { |
| 960 | 960 | const E1 = enum { |
| 961 | 961 | A, |
| 962 | fn a() void {} | |
| 962 | pub fn a() void {} | |
| 963 | 963 | }; |
| 964 | 964 | |
| 965 | 965 | const S = struct { |
test/behavior/type_info.zig+13-14| ... | ... | @@ -321,8 +321,7 @@ fn testPackedStruct() !void { |
| 321 | 321 | try expect(struct_info.Struct.fields[2].default_value == null); |
| 322 | 322 | try expect(@as(*align(1) const u32, @ptrCast(struct_info.Struct.fields[3].default_value.?)).* == 4); |
| 323 | 323 | try expect(struct_info.Struct.fields[3].alignment == 0); |
| 324 | try expect(struct_info.Struct.decls.len == 2); | |
| 325 | try expect(struct_info.Struct.decls[0].is_pub); | |
| 324 | try expect(struct_info.Struct.decls.len == 1); | |
| 326 | 325 | } |
| 327 | 326 | |
| 328 | 327 | const TestPackedStruct = packed struct { |
| ... | ... | @@ -344,8 +343,8 @@ test "type info: opaque info" { |
| 344 | 343 | |
| 345 | 344 | fn testOpaque() !void { |
| 346 | 345 | const Foo = opaque { |
| 347 | const A = 1; | |
| 348 | fn b() void {} | |
| 346 | pub const A = 1; | |
| 347 | pub fn b() void {} | |
| 349 | 348 | }; |
| 350 | 349 | |
| 351 | 350 | const foo_info = @typeInfo(Foo); |
| ... | ... | @@ -514,11 +513,11 @@ test "Declarations are returned in declaration order" { |
| 514 | 513 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 515 | 514 | |
| 516 | 515 | const S = struct { |
| 517 | const a = 1; | |
| 518 | const b = 2; | |
| 519 | const c = 3; | |
| 520 | const d = 4; | |
| 521 | const e = 5; | |
| 516 | pub const a = 1; | |
| 517 | pub const b = 2; | |
| 518 | pub const c = 3; | |
| 519 | pub const d = 4; | |
| 520 | pub const e = 5; | |
| 522 | 521 | }; |
| 523 | 522 | const d = @typeInfo(S).Struct.decls; |
| 524 | 523 | try expect(std.mem.eql(u8, d[0].name, "a")); |
| ... | ... | @@ -553,7 +552,7 @@ test "typeInfo resolves usingnamespace declarations" { |
| 553 | 552 | }; |
| 554 | 553 | |
| 555 | 554 | const B = struct { |
| 556 | const f0 = 42; | |
| 555 | pub const f0 = 42; | |
| 557 | 556 | usingnamespace A; |
| 558 | 557 | }; |
| 559 | 558 | |
| ... | ... | @@ -574,14 +573,14 @@ test "@typeInfo decls and usingnamespace" { |
| 574 | 573 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 575 | 574 | |
| 576 | 575 | const A = struct { |
| 577 | const x = 5; | |
| 578 | const y = 34; | |
| 576 | pub const x = 5; | |
| 577 | pub const y = 34; | |
| 579 | 578 | |
| 580 | 579 | comptime {} |
| 581 | 580 | }; |
| 582 | 581 | const B = struct { |
| 583 | 582 | usingnamespace A; |
| 584 | const z = 56; | |
| 583 | pub const z = 56; | |
| 585 | 584 | |
| 586 | 585 | test {} |
| 587 | 586 | }; |
| ... | ... | @@ -594,7 +593,7 @@ test "@typeInfo decls and usingnamespace" { |
| 594 | 593 | |
| 595 | 594 | test "@typeInfo decls ignore dependency loops" { |
| 596 | 595 | const S = struct { |
| 597 | fn Def(comptime T: type) type { | |
| 596 | pub fn Def(comptime T: type) type { | |
| 598 | 597 | std.debug.assert(@typeInfo(T).Struct.decls.len == 1); |
| 599 | 598 | return struct { |
| 600 | 599 | const foo = u32; |
test/behavior/type_info_only_pub_decls.zig created+23| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | const std = @import("std"); | |
| 2 | const other = struct { | |
| 3 | const std = @import("std"); | |
| 4 | ||
| 5 | pub const Enum = enum { | |
| 6 | a, | |
| 7 | b, | |
| 8 | c, | |
| 9 | }; | |
| 10 | ||
| 11 | pub const Struct = struct { | |
| 12 | foo: i32, | |
| 13 | }; | |
| 14 | }; | |
| 15 | ||
| 16 | test { | |
| 17 | const ti = @typeInfo(other); | |
| 18 | const decls = ti.Struct.decls; | |
| 19 | ||
| 20 | try std.testing.expectEqual(2, decls.len); | |
| 21 | try std.testing.expectEqualStrings("Enum", decls[0].name); | |
| 22 | try std.testing.expectEqualStrings("Struct", decls[1].name); | |
| 23 | } |