Skip to content

Commit 40ed6ae

Browse files
authored
Merge pull request #13930 from r00ster91/renamings
std.builtin: renamings
2 parents e9e804e + 2a5e142 commit 40ed6ae

File tree

76 files changed

+236
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+236
-280
lines changed

doc/langref.html.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,7 +4253,7 @@ fn isFieldOptional(comptime T: type, field_index: usize) !bool {
42534253
return switch (field_index) {
42544254
// This prong is analyzed `fields.len - 1` times with `idx` being an
42554255
// unique comptime-known value each time.
4256-
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].field_type) == .Optional,
4256+
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
42574257
else => return error.IndexOutOfBounds,
42584258
};
42594259
}
@@ -5242,7 +5242,7 @@ const math = std.math;
52425242
const testing = std.testing;
52435243

52445244
test "fn reflection" {
5245-
try testing.expect(@typeInfo(@TypeOf(testing.expect)).Fn.args[0].arg_type.? == bool);
5245+
try testing.expect(@typeInfo(@TypeOf(testing.expect)).Fn.params[0].type.? == bool);
52465246
try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).Fn.return_type.? == testing.TmpDir);
52475247

52485248
try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).Fn.is_generic);

lib/std/array_hash_map.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,13 +2270,13 @@ test "reIndex" {
22702270
test "auto store_hash" {
22712271
const HasCheapEql = AutoArrayHashMap(i32, i32);
22722272
const HasExpensiveEql = AutoArrayHashMap([32]i32, i32);
2273-
try testing.expect(meta.fieldInfo(HasCheapEql.Data, .hash).field_type == void);
2274-
try testing.expect(meta.fieldInfo(HasExpensiveEql.Data, .hash).field_type != void);
2273+
try testing.expect(meta.fieldInfo(HasCheapEql.Data, .hash).type == void);
2274+
try testing.expect(meta.fieldInfo(HasExpensiveEql.Data, .hash).type != void);
22752275

22762276
const HasCheapEqlUn = AutoArrayHashMapUnmanaged(i32, i32);
22772277
const HasExpensiveEqlUn = AutoArrayHashMapUnmanaged([32]i32, i32);
2278-
try testing.expect(meta.fieldInfo(HasCheapEqlUn.Data, .hash).field_type == void);
2279-
try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Data, .hash).field_type != void);
2278+
try testing.expect(meta.fieldInfo(HasCheapEqlUn.Data, .hash).type == void);
2279+
try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Data, .hash).type != void);
22802280
}
22812281

22822282
test "sort" {

lib/std/builtin.zig

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ pub const Type = union(enum) {
280280
/// therefore must be kept in sync with the compiler implementation.
281281
pub const StructField = struct {
282282
name: []const u8,
283-
/// TODO rename to `type`
284-
field_type: type,
283+
type: type,
285284
default_value: ?*const anyopaque,
286285
is_comptime: bool,
287286
alignment: comptime_int,
@@ -331,8 +330,6 @@ pub const Type = union(enum) {
331330
/// This data structure is used by the Zig language code generation and
332331
/// therefore must be kept in sync with the compiler implementation.
333332
pub const Enum = struct {
334-
/// TODO enums should no longer have this field in type info.
335-
layout: ContainerLayout,
336333
tag_type: type,
337334
fields: []const EnumField,
338335
decls: []const Declaration,
@@ -343,7 +340,7 @@ pub const Type = union(enum) {
343340
/// therefore must be kept in sync with the compiler implementation.
344341
pub const UnionField = struct {
345342
name: []const u8,
346-
field_type: type,
343+
type: type,
347344
alignment: comptime_int,
348345
};
349346

@@ -367,14 +364,14 @@ pub const Type = union(enum) {
367364
is_var_args: bool,
368365
/// TODO change the language spec to make this not optional.
369366
return_type: ?type,
370-
args: []const Param,
367+
params: []const Param,
371368

372369
/// This data structure is used by the Zig language code generation and
373370
/// therefore must be kept in sync with the compiler implementation.
374371
pub const Param = struct {
375372
is_generic: bool,
376373
is_noalias: bool,
377-
arg_type: ?type,
374+
type: ?type,
378375
};
379376
};
380377

lib/std/crypto/phc_encoding.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
110110
var found = false;
111111
inline for (comptime meta.fields(HashResult)) |p| {
112112
if (mem.eql(u8, p.name, param.key)) {
113-
switch (@typeInfo(p.field_type)) {
113+
switch (@typeInfo(p.type)) {
114114
.Int => @field(out, p.name) = fmt.parseUnsigned(
115-
p.field_type,
115+
p.type,
116116
param.value,
117117
10,
118118
) catch return Error.InvalidEncoding,
@@ -161,7 +161,7 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
161161
// with default values
162162
var expected_fields: usize = 0;
163163
inline for (comptime meta.fields(HashResult)) |p| {
164-
if (@typeInfo(p.field_type) != .Optional and p.default_value == null) {
164+
if (@typeInfo(p.type) != .Optional and p.default_value == null) {
165165
expected_fields += 1;
166166
}
167167
}
@@ -223,7 +223,7 @@ fn serializeTo(params: anytype, out: anytype) !void {
223223
{
224224
const value = @field(params, p.name);
225225
try out.writeAll(if (has_params) params_delimiter else fields_delimiter);
226-
if (@typeInfo(p.field_type) == .Struct) {
226+
if (@typeInfo(p.type) == .Struct) {
227227
var buf: [@TypeOf(value).max_encoded_length]u8 = undefined;
228228
try out.print("{s}{s}{s}", .{ p.name, kv_delimiter, try value.toB64(&buf) });
229229
} else {

lib/std/enums.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def
1515
for (std.meta.fields(E)) |field| {
1616
fields = fields ++ &[_]StructField{.{
1717
.name = field.name,
18-
.field_type = Data,
18+
.type = Data,
1919
.default_value = if (field_default) |d| @ptrCast(?*const anyopaque, &d) else null,
2020
.is_comptime = false,
2121
.alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,

lib/std/fmt.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ pub const ParseIntError = error{
17241724
/// ) !void;
17251725
///
17261726
pub fn Formatter(comptime format_fn: anytype) type {
1727-
const Data = @typeInfo(@TypeOf(format_fn)).Fn.args[0].arg_type.?;
1727+
const Data = @typeInfo(@TypeOf(format_fn)).Fn.params[0].type.?;
17281728
return struct {
17291729
data: Data,
17301730
pub fn format(

lib/std/hash/auto_hash.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
134134
hash(hasher, tag, strat);
135135
inline for (info.fields) |field| {
136136
if (@field(tag_type, field.name) == tag) {
137-
if (field.field_type != void) {
137+
if (field.type != void) {
138138
hash(hasher, @field(key, field.name), strat);
139139
}
140140
// TODO use a labelled break when it does not crash the compiler. cf #2908
@@ -163,14 +163,14 @@ fn typeContainsSlice(comptime K: type) bool {
163163
}
164164
if (meta.trait.is(.Struct)(K)) {
165165
inline for (@typeInfo(K).Struct.fields) |field| {
166-
if (typeContainsSlice(field.field_type)) {
166+
if (typeContainsSlice(field.type)) {
167167
return true;
168168
}
169169
}
170170
}
171171
if (meta.trait.is(.Union)(K)) {
172172
inline for (@typeInfo(K).Union.fields) |field| {
173-
if (typeContainsSlice(field.field_type)) {
173+
if (typeContainsSlice(field.type)) {
174174
return true;
175175
}
176176
}

lib/std/hash_map.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ pub fn verifyContext(
186186
const info = @typeInfo(@TypeOf(hash));
187187
if (info == .Fn) {
188188
const func = info.Fn;
189-
if (func.args.len != 2) {
189+
if (func.params.len != 2) {
190190
errors = errors ++ lazy.err_invalid_hash_signature;
191191
} else {
192192
var emitted_signature = false;
193-
if (func.args[0].arg_type) |Self| {
193+
if (func.params[0].type) |Self| {
194194
if (Self == Context) {
195195
// pass, this is always fine.
196196
} else if (Self == *const Context) {
@@ -231,12 +231,12 @@ pub fn verifyContext(
231231
errors = errors ++ ", but is " ++ @typeName(Self);
232232
}
233233
}
234-
if (func.args[1].arg_type != null and func.args[1].arg_type.? != PseudoKey) {
234+
if (func.params[1].type != null and func.params[1].type.? != PseudoKey) {
235235
if (!emitted_signature) {
236236
errors = errors ++ lazy.err_invalid_hash_signature;
237237
emitted_signature = true;
238238
}
239-
errors = errors ++ lazy.deep_prefix ++ "Second parameter must be " ++ @typeName(PseudoKey) ++ ", but is " ++ @typeName(func.args[1].arg_type.?);
239+
errors = errors ++ lazy.deep_prefix ++ "Second parameter must be " ++ @typeName(PseudoKey) ++ ", but is " ++ @typeName(func.params[1].type.?);
240240
}
241241
if (func.return_type != null and func.return_type.? != Hash) {
242242
if (!emitted_signature) {
@@ -263,11 +263,11 @@ pub fn verifyContext(
263263
if (info == .Fn) {
264264
const func = info.Fn;
265265
const args_len = if (is_array) 4 else 3;
266-
if (func.args.len != args_len) {
266+
if (func.params.len != args_len) {
267267
errors = errors ++ lazy.err_invalid_eql_signature;
268268
} else {
269269
var emitted_signature = false;
270-
if (func.args[0].arg_type) |Self| {
270+
if (func.params[0].type) |Self| {
271271
if (Self == Context) {
272272
// pass, this is always fine.
273273
} else if (Self == *const Context) {
@@ -308,19 +308,19 @@ pub fn verifyContext(
308308
errors = errors ++ ", but is " ++ @typeName(Self);
309309
}
310310
}
311-
if (func.args[1].arg_type.? != PseudoKey) {
311+
if (func.params[1].type.? != PseudoKey) {
312312
if (!emitted_signature) {
313313
errors = errors ++ lazy.err_invalid_eql_signature;
314314
emitted_signature = true;
315315
}
316-
errors = errors ++ lazy.deep_prefix ++ "Second parameter must be " ++ @typeName(PseudoKey) ++ ", but is " ++ @typeName(func.args[1].arg_type.?);
316+
errors = errors ++ lazy.deep_prefix ++ "Second parameter must be " ++ @typeName(PseudoKey) ++ ", but is " ++ @typeName(func.params[1].type.?);
317317
}
318-
if (func.args[2].arg_type.? != Key) {
318+
if (func.params[2].type.? != Key) {
319319
if (!emitted_signature) {
320320
errors = errors ++ lazy.err_invalid_eql_signature;
321321
emitted_signature = true;
322322
}
323-
errors = errors ++ lazy.deep_prefix ++ "Third parameter must be " ++ @typeName(Key) ++ ", but is " ++ @typeName(func.args[2].arg_type.?);
323+
errors = errors ++ lazy.deep_prefix ++ "Third parameter must be " ++ @typeName(Key) ++ ", but is " ++ @typeName(func.params[2].type.?);
324324
}
325325
if (func.return_type.? != bool) {
326326
if (!emitted_signature) {

lib/std/io/multi_writer.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const testing = std.testing;
66
pub fn MultiWriter(comptime Writers: type) type {
77
comptime var ErrSet = error{};
88
inline for (@typeInfo(Writers).Struct.fields) |field| {
9-
const StreamType = field.field_type;
9+
const StreamType = field.type;
1010
ErrSet = ErrSet || StreamType.Error;
1111
}
1212

lib/std/json.zig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ fn ParseInternalErrorImpl(comptime T: type, comptime inferred_types: []const typ
13621362
if (unionInfo.tag_type) |_| {
13631363
var errors = error{NoUnionMembersMatched};
13641364
for (unionInfo.fields) |u_field| {
1365-
errors = errors || ParseInternalErrorImpl(u_field.field_type, inferred_types ++ [_]type{T});
1365+
errors = errors || ParseInternalErrorImpl(u_field.type, inferred_types ++ [_]type{T});
13661366
}
13671367
return errors;
13681368
} else {
@@ -1379,7 +1379,7 @@ fn ParseInternalErrorImpl(comptime T: type, comptime inferred_types: []const typ
13791379
MissingField,
13801380
} || SkipValueError || TokenStream.Error;
13811381
for (structInfo.fields) |field| {
1382-
errors = errors || ParseInternalErrorImpl(field.field_type, inferred_types ++ [_]type{T});
1382+
errors = errors || ParseInternalErrorImpl(field.type, inferred_types ++ [_]type{T});
13831383
}
13841384
return errors;
13851385
},
@@ -1491,7 +1491,7 @@ fn parseInternal(
14911491
inline for (unionInfo.fields) |u_field| {
14921492
// take a copy of tokens so we can withhold mutations until success
14931493
var tokens_copy = tokens.*;
1494-
if (parseInternal(u_field.field_type, token, &tokens_copy, options)) |value| {
1494+
if (parseInternal(u_field.type, token, &tokens_copy, options)) |value| {
14951495
tokens.* = tokens_copy;
14961496
return @unionInit(T, u_field.name, value);
14971497
} else |err| {
@@ -1519,7 +1519,7 @@ fn parseInternal(
15191519
errdefer {
15201520
inline for (structInfo.fields) |field, i| {
15211521
if (fields_seen[i] and !field.is_comptime) {
1522-
parseFree(field.field_type, @field(r, field.name), options);
1522+
parseFree(field.type, @field(r, field.name), options);
15231523
}
15241524
}
15251525
}
@@ -1547,24 +1547,24 @@ fn parseInternal(
15471547
// }
15481548
if (options.duplicate_field_behavior == .UseFirst) {
15491549
// unconditonally ignore value. for comptime fields, this skips check against default_value
1550-
parseFree(field.field_type, try parse(field.field_type, tokens, child_options), child_options);
1550+
parseFree(field.type, try parse(field.type, tokens, child_options), child_options);
15511551
found = true;
15521552
break;
15531553
} else if (options.duplicate_field_behavior == .Error) {
15541554
return error.DuplicateJSONField;
15551555
} else if (options.duplicate_field_behavior == .UseLast) {
15561556
if (!field.is_comptime) {
1557-
parseFree(field.field_type, @field(r, field.name), child_options);
1557+
parseFree(field.type, @field(r, field.name), child_options);
15581558
}
15591559
fields_seen[i] = false;
15601560
}
15611561
}
15621562
if (field.is_comptime) {
1563-
if (!try parsesTo(field.field_type, @ptrCast(*align(1) const field.field_type, field.default_value.?).*, tokens, child_options)) {
1563+
if (!try parsesTo(field.type, @ptrCast(*align(1) const field.type, field.default_value.?).*, tokens, child_options)) {
15641564
return error.UnexpectedValue;
15651565
}
15661566
} else {
1567-
@field(r, field.name) = try parse(field.field_type, tokens, child_options);
1567+
@field(r, field.name) = try parse(field.type, tokens, child_options);
15681568
}
15691569
fields_seen[i] = true;
15701570
found = true;
@@ -1587,7 +1587,7 @@ fn parseInternal(
15871587
if (!fields_seen[i]) {
15881588
if (field.default_value) |default_ptr| {
15891589
if (!field.is_comptime) {
1590-
const default = @ptrCast(*align(1) const field.field_type, default_ptr).*;
1590+
const default = @ptrCast(*align(1) const field.type, default_ptr).*;
15911591
@field(r, field.name) = default;
15921592
}
15931593
} else {
@@ -1732,7 +1732,7 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {
17321732
if (unionInfo.tag_type) |UnionTagType| {
17331733
inline for (unionInfo.fields) |u_field| {
17341734
if (value == @field(UnionTagType, u_field.name)) {
1735-
parseFree(u_field.field_type, @field(value, u_field.name), options);
1735+
parseFree(u_field.type, @field(value, u_field.name), options);
17361736
break;
17371737
}
17381738
}
@@ -1743,7 +1743,7 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void {
17431743
.Struct => |structInfo| {
17441744
inline for (structInfo.fields) |field| {
17451745
if (!field.is_comptime) {
1746-
parseFree(field.field_type, @field(value, field.name), options);
1746+
parseFree(field.type, @field(value, field.name), options);
17471747
}
17481748
}
17491749
},
@@ -2270,12 +2270,12 @@ pub fn stringify(
22702270
}
22712271
inline for (S.fields) |Field| {
22722272
// don't include void fields
2273-
if (Field.field_type == void) continue;
2273+
if (Field.type == void) continue;
22742274

22752275
var emit_field = true;
22762276

22772277
// don't include optional fields that are null when emit_null_optional_fields is set to false
2278-
if (@typeInfo(Field.field_type) == .Optional) {
2278+
if (@typeInfo(Field.type) == .Optional) {
22792279
if (options.emit_null_optional_fields == false) {
22802280
if (@field(value, Field.name) == null) {
22812281
emit_field = false;

lib/std/mem.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ pub fn zeroes(comptime T: type) T {
300300
if (comptime meta.containerLayout(T) == .Extern) {
301301
// The C language specification states that (global) unions
302302
// should be zero initialized to the first named member.
303-
return @unionInit(T, info.fields[0].name, zeroes(info.fields[0].field_type));
303+
return @unionInit(T, info.fields[0].name, zeroes(info.fields[0].type));
304304
}
305305

306306
@compileError("Can't set a " ++ @typeName(T) ++ " to zero.");
@@ -435,7 +435,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
435435

436436
inline for (struct_info.fields) |field| {
437437
if (field.default_value) |default_value_ptr| {
438-
const default_value = @ptrCast(*align(1) const field.field_type, default_value_ptr).*;
438+
const default_value = @ptrCast(*align(1) const field.type, default_value_ptr).*;
439439
@field(value, field.name) = default_value;
440440
}
441441
}
@@ -452,9 +452,9 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
452452
@compileError("Encountered an initializer for `" ++ field.name ++ "`, but it is not a field of " ++ @typeName(T));
453453
}
454454

455-
switch (@typeInfo(field.field_type)) {
455+
switch (@typeInfo(field.type)) {
456456
.Struct => {
457-
@field(value, field.name) = zeroInit(field.field_type, @field(init, field.name));
457+
@field(value, field.name) = zeroInit(field.type, @field(init, field.name));
458458
},
459459
else => {
460460
@field(value, field.name) = @field(init, field.name);

0 commit comments

Comments
 (0)