Skip to content

Commit 12f904f

Browse files
committed
screw up interface :D
(in a good way)
1 parent 08a1339 commit 12f904f

23 files changed

+144
-132
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ set(ZIG_STAGE2_SOURCES
407407
lib/std/c.zig
408408
lib/std/coff.zig
409409
lib/std/crypto.zig
410-
lib/std/comptime_string_map.zig
410+
lib/std/static_string_map.zig
411411
lib/std/crypto/blake3.zig
412412
lib/std/crypto/siphash.zig
413413
lib/std/debug.zig

lib/compiler/aro/aro/LangOpts.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub const Standard = enum {
4747
/// Working Draft for ISO C23 with GNU extensions
4848
gnu23,
4949

50-
const NameMap = std.ComptimeStringMap(Standard, .{
50+
const name_map = std.StaticStringMap(Standard).initComptime(.{
5151
.{ "c89", .c89 }, .{ "c90", .c89 }, .{ "iso9899:1990", .c89 },
5252
.{ "iso9899:199409", .iso9899 }, .{ "gnu89", .gnu89 }, .{ "gnu90", .gnu89 },
5353
.{ "c99", .c99 }, .{ "iso9899:1999", .c99 }, .{ "c9x", .c99 },
@@ -141,7 +141,7 @@ preserve_comments_in_macros: bool = false,
141141
gnuc_version: u32 = 0,
142142

143143
pub fn setStandard(self: *LangOpts, name: []const u8) error{InvalidStandard}!void {
144-
self.standard = Standard.NameMap.get(name) orelse return error.InvalidStandard;
144+
self.standard = Standard.name_map.get(name) orelse return error.InvalidStandard;
145145
}
146146

147147
pub fn enableMSExtensions(self: *LangOpts) void {

lib/compiler/aro/aro/Preprocessor.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ fn expandFuncMacro(
17451745
}
17461746
if (!pp.comp.langopts.standard.atLeast(.c23)) break :res not_found;
17471747

1748-
const Attrs = std.ComptimeStringMap([]const u8, .{
1748+
const attrs = std.StaticStringMap([]const u8).initComptime(.{
17491749
.{ "deprecated", "201904L\n" },
17501750
.{ "fallthrough", "201904L\n" },
17511751
.{ "maybe_unused", "201904L\n" },
@@ -1757,7 +1757,7 @@ fn expandFuncMacro(
17571757
});
17581758

17591759
const attr_str = Attribute.normalize(pp.expandedSlice(attr_ident.?));
1760-
break :res Attrs.get(attr_str) orelse not_found;
1760+
break :res attrs.get(attr_str) orelse not_found;
17611761
};
17621762
const start = pp.comp.generated_buf.items.len;
17631763
try pp.comp.generated_buf.appendSlice(pp.gpa, result);

lib/compiler/aro/aro/Tokenizer.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ pub const Token = struct {
837837
/// belong to the implementation namespace, so we always convert them
838838
/// to keywords.
839839
pub fn getTokenId(langopts: LangOpts, str: []const u8) Token.Id {
840-
const kw = AllKws.get(str) orelse return .identifier;
840+
const kw = all_kws.get(str) orelse return .identifier;
841841
const standard = langopts.standard;
842842
return switch (kw) {
843843
.keyword_inline => if (standard.isGNU() or standard.atLeast(.c99)) kw else .identifier,
@@ -876,7 +876,7 @@ pub const Token = struct {
876876
};
877877
}
878878

879-
const AllKws = std.ComptimeStringMap(Id, .{
879+
const all_kws = std.StaticStringMap(Id).initComptime(.{
880880
.{ "auto", .keyword_auto },
881881
.{ "break", .keyword_break },
882882
.{ "case", .keyword_case },

lib/compiler/resinator/errors.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub const ErrorDetails = struct {
240240
// see https://github.com/ziglang/zig/issues/15395
241241
_: u26 = 0,
242242

243-
pub const Strings = std.ComptimeStringMap([]const u8, .{
243+
pub const strings = std.StaticStringMap([]const u8).initComptime(.{
244244
.{ "number", "number" },
245245
.{ "number_expression", "number expression" },
246246
.{ "string_literal", "quoted string literal" },
@@ -262,7 +262,7 @@ pub const ErrorDetails = struct {
262262
if (field_info.type != bool) continue;
263263
if (i == num_set_bits) return;
264264
if (@field(self, field_info.name)) {
265-
try writer.writeAll(Strings.get(field_info.name).?);
265+
try writer.writeAll(strings.get(field_info.name).?);
266266
i += 1;
267267
if (num_set_bits > 2 and i != num_set_bits) {
268268
try writer.writeAll(", ");

lib/compiler/resinator/rc.zig

+14-14
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub const Resource = enum {
4747
fontdir_num,
4848
manifest_num,
4949

50-
const Map = std.ComptimeStringMapIgnoreCase(Resource, .{
50+
const map = std.StaticStringMapIgnoreCase(Resource).initComptime(.{
5151
.{ "ACCELERATORS", .accelerators },
5252
.{ "BITMAP", .bitmap },
5353
.{ "CURSOR", .cursor },
@@ -75,7 +75,7 @@ pub const Resource = enum {
7575
if (ordinal.ordinal >= 256) return .user_defined;
7676
return fromRT(@enumFromInt(ordinal.ordinal));
7777
}
78-
return Map.get(bytes.slice) orelse .user_defined;
78+
return map.get(bytes.slice) orelse .user_defined;
7979
}
8080

8181
// TODO: Some comptime validation that RT <-> Resource conversion is synced?
@@ -157,13 +157,13 @@ pub const OptionalStatements = enum {
157157
menu,
158158
style,
159159

160-
pub const Map = std.ComptimeStringMapIgnoreCase(OptionalStatements, .{
160+
pub const map = std.StaticStringMapIgnoreCase(OptionalStatements).initComptime(.{
161161
.{ "CHARACTERISTICS", .characteristics },
162162
.{ "LANGUAGE", .language },
163163
.{ "VERSION", .version },
164164
});
165165

166-
pub const DialogMap = std.ComptimeStringMapIgnoreCase(OptionalStatements, .{
166+
pub const dialog_map = std.StaticStringMapIgnoreCase(OptionalStatements).initComptime(.{
167167
.{ "CAPTION", .caption },
168168
.{ "CLASS", .class },
169169
.{ "EXSTYLE", .exstyle },
@@ -197,7 +197,7 @@ pub const Control = enum {
197197
state3,
198198
userbutton,
199199

200-
pub const Map = std.ComptimeStringMapIgnoreCase(Control, .{
200+
pub const map = std.StaticStringMapIgnoreCase(Control).initComptime(.{
201201
.{ "AUTO3STATE", .auto3state },
202202
.{ "AUTOCHECKBOX", .autocheckbox },
203203
.{ "AUTORADIOBUTTON", .autoradiobutton },
@@ -231,7 +231,7 @@ pub const Control = enum {
231231
};
232232

233233
pub const ControlClass = struct {
234-
pub const Map = std.ComptimeStringMapIgnoreCase(res.ControlClass, .{
234+
pub const map = std.StaticStringMapIgnoreCase(res.ControlClass).initComptime(.{
235235
.{ "BUTTON", .button },
236236
.{ "EDIT", .edit },
237237
.{ "STATIC", .static },
@@ -280,7 +280,7 @@ pub const MenuItem = enum {
280280
menuitem,
281281
popup,
282282

283-
pub const Map = std.ComptimeStringMapIgnoreCase(MenuItem, .{
283+
pub const map = std.StaticStringMapIgnoreCase(MenuItem).initComptime(.{
284284
.{ "MENUITEM", .menuitem },
285285
.{ "POPUP", .popup },
286286
});
@@ -297,7 +297,7 @@ pub const MenuItem = enum {
297297
menubarbreak,
298298
menubreak,
299299

300-
pub const Map = std.ComptimeStringMapIgnoreCase(Option, .{
300+
pub const map = std.StaticStringMapIgnoreCase(Option).initComptime(.{
301301
.{ "CHECKED", .checked },
302302
.{ "GRAYED", .grayed },
303303
.{ "HELP", .help },
@@ -312,7 +312,7 @@ pub const ToolbarButton = enum {
312312
button,
313313
separator,
314314

315-
pub const Map = std.ComptimeStringMapIgnoreCase(ToolbarButton, .{
315+
pub const map = std.StaticStringMapIgnoreCase(ToolbarButton).initComptime(.{
316316
.{ "BUTTON", .button },
317317
.{ "SEPARATOR", .separator },
318318
});
@@ -327,7 +327,7 @@ pub const VersionInfo = enum {
327327
file_type,
328328
file_subtype,
329329

330-
pub const Map = std.ComptimeStringMapIgnoreCase(VersionInfo, .{
330+
pub const map = std.StaticStringMapIgnoreCase(VersionInfo).initComptime(.{
331331
.{ "FILEVERSION", .file_version },
332332
.{ "PRODUCTVERSION", .product_version },
333333
.{ "FILEFLAGSMASK", .file_flags_mask },
@@ -342,7 +342,7 @@ pub const VersionBlock = enum {
342342
block,
343343
value,
344344

345-
pub const Map = std.ComptimeStringMapIgnoreCase(VersionBlock, .{
345+
pub const map = std.StaticStringMapIgnoreCase(VersionBlock).initComptime(.{
346346
.{ "BLOCK", .block },
347347
.{ "VALUE", .value },
348348
});
@@ -356,7 +356,7 @@ pub const TopLevelKeywords = enum {
356356
characteristics,
357357
stringtable,
358358

359-
pub const Map = std.ComptimeStringMapIgnoreCase(TopLevelKeywords, .{
359+
pub const map = std.StaticStringMapIgnoreCase(TopLevelKeywords).initComptime(.{
360360
.{ "LANGUAGE", .language },
361361
.{ "VERSION", .version },
362362
.{ "CHARACTERISTICS", .characteristics },
@@ -375,7 +375,7 @@ pub const CommonResourceAttributes = enum {
375375
shared,
376376
nonshared,
377377

378-
pub const Map = std.ComptimeStringMapIgnoreCase(CommonResourceAttributes, .{
378+
pub const map = std.StaticStringMapIgnoreCase(CommonResourceAttributes).initComptime(.{
379379
.{ "PRELOAD", .preload },
380380
.{ "LOADONCALL", .loadoncall },
381381
.{ "FIXED", .fixed },
@@ -396,7 +396,7 @@ pub const AcceleratorTypeAndOptions = enum {
396396
shift,
397397
control,
398398

399-
pub const Map = std.ComptimeStringMapIgnoreCase(AcceleratorTypeAndOptions, .{
399+
pub const map = std.StaticStringMapIgnoreCase(AcceleratorTypeAndOptions).initComptime(.{
400400
.{ "VIRTKEY", .virtkey },
401401
.{ "ASCII", .ascii },
402402
.{ "NOINVERT", .noinvert },

lib/std/crypto/Certificate.zig

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub const Algorithm = enum {
1919
md5WithRSAEncryption,
2020
curveEd25519,
2121

22-
pub const Map = std.ComptimeStringMap(Algorithm, .{
22+
pub const map = std.StaticStringMap(Algorithm).initComptime(.{
2323
.{ &[_]u8{ 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05 }, .sha1WithRSAEncryption },
2424
.{ &[_]u8{ 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B }, .sha256WithRSAEncryption },
2525
.{ &[_]u8{ 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0C }, .sha384WithRSAEncryption },
@@ -52,7 +52,7 @@ pub const AlgorithmCategory = enum {
5252
X9_62_id_ecPublicKey,
5353
curveEd25519,
5454

55-
pub const Map = std.ComptimeStringMap(AlgorithmCategory, .{
55+
pub const map = std.StaticStringMap(AlgorithmCategory).initComptime(.{
5656
.{ &[_]u8{ 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01 }, .rsaEncryption },
5757
.{ &[_]u8{ 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01 }, .X9_62_id_ecPublicKey },
5858
.{ &[_]u8{ 0x2B, 0x65, 0x70 }, .curveEd25519 },
@@ -73,7 +73,7 @@ pub const Attribute = enum {
7373
pkcs9_emailAddress,
7474
domainComponent,
7575

76-
pub const Map = std.ComptimeStringMap(Attribute, .{
76+
pub const map = std.StaticStringMap(Attribute).initComptime(.{
7777
.{ &[_]u8{ 0x55, 0x04, 0x03 }, .commonName },
7878
.{ &[_]u8{ 0x55, 0x04, 0x05 }, .serialNumber },
7979
.{ &[_]u8{ 0x55, 0x04, 0x06 }, .countryName },
@@ -94,7 +94,7 @@ pub const NamedCurve = enum {
9494
secp521r1,
9595
X9_62_prime256v1,
9696

97-
pub const Map = std.ComptimeStringMap(NamedCurve, .{
97+
pub const map = std.StaticStringMap(NamedCurve).initComptime(.{
9898
.{ &[_]u8{ 0x2B, 0x81, 0x04, 0x00, 0x22 }, .secp384r1 },
9999
.{ &[_]u8{ 0x2B, 0x81, 0x04, 0x00, 0x23 }, .secp521r1 },
100100
.{ &[_]u8{ 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07 }, .X9_62_prime256v1 },
@@ -130,7 +130,7 @@ pub const ExtensionId = enum {
130130
netscape_cert_type,
131131
netscape_comment,
132132

133-
pub const Map = std.ComptimeStringMap(ExtensionId, .{
133+
pub const map = std.StaticStringMap(ExtensionId).initComptime(.{
134134
.{ &[_]u8{ 0x55, 0x04, 0x03 }, .commonName },
135135
.{ &[_]u8{ 0x55, 0x1D, 0x01 }, .authority_key_identifier },
136136
.{ &[_]u8{ 0x55, 0x1D, 0x07 }, .subject_alt_name },

lib/std/fs/test.zig

+6-6
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ test "walker" {
16551655

16561656
// iteration order of walker is undefined, so need lookup maps to check against
16571657

1658-
const ExpectedPaths = std.ComptimeStringMap(void, .{
1658+
const expected_paths = std.StaticStringMap(void).initComptime(.{
16591659
.{ "dir1", {} },
16601660
.{ "dir2", {} },
16611661
.{ "dir3", {} },
@@ -1665,7 +1665,7 @@ test "walker" {
16651665
.{ "dir3" ++ fs.path.sep_str ++ "sub2" ++ fs.path.sep_str ++ "subsub1", {} },
16661666
});
16671667

1668-
const ExpectedBasename = std.ComptimeStringMap(void, .{
1668+
const expected_basename = std.StaticStringMap(void).initComptime(.{
16691669
.{ "dir1", {} },
16701670
.{ "dir2", {} },
16711671
.{ "dir3", {} },
@@ -1675,7 +1675,7 @@ test "walker" {
16751675
.{ "subsub1", {} },
16761676
});
16771677

1678-
for (ExpectedPaths.keys()) |key| {
1678+
for (expected_paths.keys()) |key| {
16791679
try tmp.dir.makePath(key);
16801680
}
16811681

@@ -1684,11 +1684,11 @@ test "walker" {
16841684

16851685
var num_walked: usize = 0;
16861686
while (try walker.next()) |entry| {
1687-
testing.expect(ExpectedBasename.has(entry.basename)) catch |err| {
1687+
testing.expect(expected_basename.has(entry.basename)) catch |err| {
16881688
std.debug.print("found unexpected basename: {s}\n", .{std.fmt.fmtSliceEscapeLower(entry.basename)});
16891689
return err;
16901690
};
1691-
testing.expect(ExpectedPaths.has(entry.path)) catch |err| {
1691+
testing.expect(expected_paths.has(entry.path)) catch |err| {
16921692
std.debug.print("found unexpected path: {s}\n", .{std.fmt.fmtSliceEscapeLower(entry.path)});
16931693
return err;
16941694
};
@@ -1697,7 +1697,7 @@ test "walker" {
16971697
defer entry_dir.close();
16981698
num_walked += 1;
16991699
}
1700-
try testing.expectEqual(ExpectedPaths.kvs.len, num_walked);
1700+
try testing.expectEqual(expected_paths.kvs.len, num_walked);
17011701
}
17021702

17031703
test "walker without fully iterating" {

lib/std/http/Client.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -1570,13 +1570,13 @@ pub const RequestOptions = struct {
15701570
};
15711571

15721572
fn validateUri(uri: Uri, arena: Allocator) !struct { Connection.Protocol, Uri } {
1573-
const ProtocolMap = std.ComptimeStringMap(Connection.Protocol, .{
1573+
const protocol_map = std.StaticStringMap(Connection.Protocol).initComptime(.{
15741574
.{ "http", .plain },
15751575
.{ "ws", .plain },
15761576
.{ "https", .tls },
15771577
.{ "wss", .tls },
15781578
});
1579-
const protocol = ProtocolMap.get(uri.scheme) orelse return error.UnsupportedUriScheme;
1579+
const protocol = protocol_map.get(uri.scheme) orelse return error.UnsupportedUriScheme;
15801580
var valid_uri = uri;
15811581
// The host is always going to be needed as a raw string for hostname resolution anyway.
15821582
valid_uri.host = .{

lib/std/meta.zig

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ test {
1515

1616
/// Returns the variant of an enum type, `T`, which is named `str`, or `null` if no such variant exists.
1717
pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
18-
// Using ComptimeStringMap here is more performant, but it will start to take too
18+
// Using StaticStringMap here is more performant, but it will start to take too
1919
// long to compile if the enum is large enough, due to the current limits of comptime
2020
// performance when doing things like constructing lookup maps at comptime.
2121
// TODO The '100' here is arbitrary and should be increased when possible:
2222
// - https://github.com/ziglang/zig/issues/4055
2323
// - https://github.com/ziglang/zig/issues/3863
2424
if (@typeInfo(T).@"enum".fields.len <= 100) {
25-
const Map = comptime build_kvs: {
25+
const map = comptime build_kvs: {
2626
const EnumKV = struct { []const u8, T };
2727
var kvs_array: [@typeInfo(T).@"enum".fields.len]EnumKV = undefined;
2828
for (@typeInfo(T).@"enum".fields, 0..) |enumField, i| {
2929
kvs_array[i] = .{ enumField.name, @field(T, enumField.name) };
3030
}
31-
break :build_kvs std.ComptimeStringMap(T, kvs_array);
31+
break :build_kvs std.StaticStringMap(T).initComptime(kvs_array);
3232
};
33-
return Map.get(str);
33+
return map.get(str);
3434
} else {
3535
inline for (@typeInfo(T).@"enum".fields) |enumField| {
3636
if (mem.eql(u8, str, enumField.name)) {

0 commit comments

Comments
 (0)