Skip to content

Commit 6d543bc

Browse files
authored
Merge pull request #23733 from alichraghi/bp
replace @type with individual type-creating builtins
2 parents 0a9f666 + dec1163 commit 6d543bc

File tree

122 files changed

+2665
-3322
lines changed

Some content is hidden

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

122 files changed

+2665
-3322
lines changed

doc/langref.html.in

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@
638638
{#syntax#}i7{#endsyntax#} refers to a signed 7-bit integer. The maximum allowed bit-width of an
639639
integer type is {#syntax#}65535{#endsyntax#}.
640640
</p>
641-
{#see_also|Integers|Floats|void|Errors|@Type#}
641+
{#see_also|Integers|Floats|void|Errors|@Int#}
642642
{#header_close#}
643643
{#header_open|Primitive Values#}
644644
<div class="table-wrapper">
@@ -3723,9 +3723,9 @@ void do_a_thing(struct Foo *foo) {
37233723
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}@FieldType(T, "a"){#endsyntax#}</td>
37243724
</tr>
37253725
<tr>
3726-
<th scope="row">{#syntax#}@Type(x){#endsyntax#}</th>
3726+
<th scope="row">{#syntax#}@Int(x, y){#endsyntax#}</th>
37273727
<td>-</td>
3728-
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}std.builtin.Type{#endsyntax#}</td>
3728+
<td>{#syntax#}x{#endsyntax#} is a {#syntax#}std.builtin.Signedness{#endsyntax#}, {#syntax#}y{#endsyntax#} is a {#syntax#}u16{#endsyntax#}</td>
37293729
</tr>
37303730
<tr>
37313731
<th scope="row">{#syntax#}@typeInfo(x){#endsyntax#}</th>
@@ -3839,9 +3839,9 @@ void do_a_thing(struct Foo *foo) {
38393839
<td>{#syntax#}x{#endsyntax#} has no result location (typed initializers do not propagate result locations)</td>
38403840
</tr>
38413841
<tr>
3842-
<th scope="row">{#syntax#}@Type(x){#endsyntax#}</th>
3843-
<td>{#syntax#}ptr{#endsyntax#}</td>
3844-
<td>{#syntax#}x{#endsyntax#} has no result location</td>
3842+
<th scope="row">{#syntax#}@Int(x, y){#endsyntax#}</th>
3843+
<td>-</td>
3844+
<td>{#syntax#}x{#endsyntax#} and {#syntax#}y{#endsyntax#} do not have result locations</td>
38453845
</tr>
38463846
<tr>
38473847
<th scope="row">{#syntax#}@typeInfo(x){#endsyntax#}</th>
@@ -5755,41 +5755,75 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
57555755
</p>
57565756
{#header_close#}
57575757

5758-
{#header_open|@Type#}
5759-
<pre>{#syntax#}@Type(comptime info: std.builtin.Type) type{#endsyntax#}</pre>
5760-
<p>
5761-
This function is the inverse of {#link|@typeInfo#}. It reifies type information
5762-
into a {#syntax#}type{#endsyntax#}.
5763-
</p>
5764-
<p>
5765-
It is available for the following types:
5766-
</p>
5767-
<ul>
5768-
<li>{#syntax#}type{#endsyntax#}</li>
5769-
<li>{#syntax#}noreturn{#endsyntax#}</li>
5770-
<li>{#syntax#}void{#endsyntax#}</li>
5771-
<li>{#syntax#}bool{#endsyntax#}</li>
5772-
<li>{#link|Integers#} - The maximum bit count for an integer type is {#syntax#}65535{#endsyntax#}.</li>
5773-
<li>{#link|Floats#}</li>
5774-
<li>{#link|Pointers#}</li>
5775-
<li>{#syntax#}comptime_int{#endsyntax#}</li>
5776-
<li>{#syntax#}comptime_float{#endsyntax#}</li>
5777-
<li>{#syntax#}@TypeOf(undefined){#endsyntax#}</li>
5778-
<li>{#syntax#}@TypeOf(null){#endsyntax#}</li>
5779-
<li>{#link|Arrays#}</li>
5780-
<li>{#link|Optionals#}</li>
5781-
<li>{#link|Error Set Type#}</li>
5782-
<li>{#link|Error Union Type#}</li>
5783-
<li>{#link|Vectors#}</li>
5784-
<li>{#link|opaque#}</li>
5785-
<li>{#syntax#}anyframe{#endsyntax#}</li>
5786-
<li>{#link|struct#}</li>
5787-
<li>{#link|enum#}</li>
5788-
<li>{#link|Enum Literals#}</li>
5789-
<li>{#link|union#}</li>
5790-
<li>{#link|Functions#}</li>
5791-
</ul>
5758+
{#header_open|@EnumLiteral#}
5759+
<pre>{#syntax#}@EnumLiteral() type{#endsyntax#}</pre>
5760+
<p>Returns the comptime-only "enum literal" type. This is the type of uncoerced {#link|Enum Literals#}. Values of this type can coerce to any {#link|enum#} with a matching field.</p>
5761+
{#header_close#}
5762+
5763+
{#header_open|@Int#}
5764+
<pre>{#syntax#}@Int(comptime signedness: std.builtin.Signedness, comptime bits: u16) type{#endsyntax#}</pre>
5765+
<p>Returns an integer type with the given signedness and bit width.</p>
5766+
<p>For instance, {#syntax#}@Int(.unsigned, 18){#endsyntax#} returns the type {#syntax#}u18{#endsyntax#}.</p>
57925767
{#header_close#}
5768+
5769+
{#header_open|@Tuple#}
5770+
<pre>{#syntax#}@Tuple(comptime field_types: []const type) type{#endsyntax#}</pre>
5771+
<p>Returns a {#link|tuple|Tuples#} type with the given field types.</p>
5772+
{#header_close#}
5773+
5774+
{#header_open|@Pointer#}
5775+
<pre>{#syntax#}@Pointer(
5776+
comptime size: std.builtin.Type.Pointer.Size,
5777+
comptime attrs: std.builtin.Type.Pointer.Attributes,
5778+
comptime Element: type,
5779+
comptime sentinel: ?Element,
5780+
) type{#endsyntax#}</pre>
5781+
<p>Returns a {#link|pointer|Pointers#} type with the properties specified by the arguments.</p>
5782+
{#header_close#}
5783+
5784+
{#header_open|@Fn#}
5785+
<pre>{#syntax#}@Fn(
5786+
comptime param_types: []const type,
5787+
comptime param_attrs: *const [param_types.len]std.builtin.Type.Fn.Param.Attributes,
5788+
comptime ReturnType: type,
5789+
comptime attrs: std.builtin.Type.Fn.Attributes,
5790+
) type{#endsyntax#}</pre>
5791+
<p>Returns a {#link|function|Functions#} type with the properties specified by the arguments.</p>
5792+
{#header_close#}
5793+
5794+
{#header_open|@Struct#}
5795+
<pre>{#syntax#}@Struct(
5796+
comptime layout: std.builtin.Type.ContainerLayout,
5797+
comptime BackingInt: ?type,
5798+
comptime field_names: []const []const u8,
5799+
comptime field_types: *const [field_names.len]type,
5800+
comptime field_attrs: *const [field_names.len]std.builtin.Type.StructField.Attributes,
5801+
) type{#endsyntax#}</pre>
5802+
<p>Returns a {#link|struct#} type with the properties specified by the arguments.</p>
5803+
{#header_close#}
5804+
5805+
{#header_open|@Union#}
5806+
<pre>{#syntax#}@Union(
5807+
comptime layout: std.builtin.Type.ContainerLayout,
5808+
/// Either the integer tag type, or the integer backing type, depending on `layout`.
5809+
comptime ArgType: ?type,
5810+
comptime field_names: []const []const u8,
5811+
comptime field_types: *const [field_names.len]type,
5812+
comptime field_attrs: *const [field_names.len]std.builtin.Type.UnionField.Attributes,
5813+
) type{#endsyntax#}</pre>
5814+
<p>Returns a {#link|union#} type with the properties specified by the arguments.</p>
5815+
{#header_close#}
5816+
5817+
{#header_open|@Enum#}
5818+
<pre>{#syntax#}@Enum(
5819+
comptime TagInt: type,
5820+
comptime mode: std.builtin.Type.Enum.Mode,
5821+
comptime field_names: []const []const u8,
5822+
comptime field_values: *const [field_names.len]TagInt,
5823+
) type{#endsyntax#}</pre>
5824+
<p>Returns an {#link|enum#} type with the properties specified by the arguments.</p>
5825+
{#header_close#}
5826+
57935827
{#header_open|@typeInfo#}
57945828
<pre>{#syntax#}@typeInfo(comptime T: type) std.builtin.Type{#endsyntax#}</pre>
57955829
<p>

doc/langref/std_options.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub const std_options: std.Options = .{
1111

1212
fn myLogFn(
1313
comptime level: std.log.Level,
14-
comptime scope: @Type(.enum_literal),
14+
comptime scope: @EnumLiteral(),
1515
comptime format: []const u8,
1616
args: anytype,
1717
) void {

doc/langref/test_coerce_unions_enums.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test "coercion between unions and enums" {
4141
try expect(u_4.tag() == 1);
4242

4343
// The following example is invalid.
44-
// error: coercion from enum '@TypeOf(.enum_literal)' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b'
44+
// error: coercion from enum '@EnumLiteral()' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b'
4545
//var u_5: U2 = .b;
4646
//try expect(u_5.tag() == 2);
4747
}

lib/build-web/main.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace, addr: ?usize) noretu
4949

5050
fn logFn(
5151
comptime message_level: log.Level,
52-
comptime scope: @TypeOf(.enum_literal),
52+
comptime scope: @EnumLiteral(),
5353
comptime format: []const u8,
5454
args: anytype,
5555
) void {

lib/compiler/aro/aro/Attribute.zig

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -717,23 +717,13 @@ pub const Tag = std.meta.DeclEnum(attributes);
717717

718718
pub const Arguments = blk: {
719719
const decls = @typeInfo(attributes).@"struct".decls;
720-
var union_fields: [decls.len]ZigType.UnionField = undefined;
721-
for (decls, &union_fields) |decl, *field| {
722-
field.* = .{
723-
.name = decl.name,
724-
.type = @field(attributes, decl.name),
725-
.alignment = @alignOf(@field(attributes, decl.name)),
726-
};
720+
var names: [decls.len][]const u8 = undefined;
721+
var types: [decls.len]type = undefined;
722+
for (decls, &names, &types) |decl, *name, *T| {
723+
name.* = decl.name;
724+
T.* = @field(attributes, decl.name);
727725
}
728-
729-
break :blk @Type(.{
730-
.@"union" = .{
731-
.layout = .auto,
732-
.tag_type = null,
733-
.fields = &union_fields,
734-
.decls = &.{},
735-
},
736-
});
726+
break :blk @Union(.auto, null, &names, &types, &@splat(.{}));
737727
};
738728

739729
pub fn ArgumentsForTag(comptime tag: Tag) type {

lib/compiler/aro/assembly_backend/x86_64.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn serializeFloat(comptime T: type, value: T, w: *std.Io.Writer) !void {
5959
else => {
6060
const size = @bitSizeOf(T);
6161
const storage_unit = std.meta.intToEnum(StorageUnit, size) catch unreachable;
62-
const IntTy = @Type(.{ .int = .{ .signedness = .unsigned, .bits = size } });
62+
const IntTy = @Int(.unsigned, size);
6363
const int_val: IntTy = @bitCast(value);
6464
return serializeInt(int_val, storage_unit, w);
6565
},

lib/compiler/resinator/code_pages.zig

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,13 @@ pub const UnsupportedCodePage = enum(u16) {
179179

180180
pub const CodePage = blk: {
181181
const fields = @typeInfo(SupportedCodePage).@"enum".fields ++ @typeInfo(UnsupportedCodePage).@"enum".fields;
182-
break :blk @Type(.{ .@"enum" = .{
183-
.tag_type = u16,
184-
.decls = &.{},
185-
.fields = fields,
186-
.is_exhaustive = true,
187-
} });
182+
var field_names: [fields.len][]const u8 = undefined;
183+
var field_values: [fields.len]u16 = undefined;
184+
for (fields, &field_names, &field_values) |field, *name, *val| {
185+
name.* = field.name;
186+
val.* = field.value;
187+
}
188+
break :blk @Enum(u16, .exhaustive, &field_names, &field_values);
188189
};
189190

190191
pub fn isSupported(code_page: CodePage) bool {

lib/compiler/resinator/errors.zig

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -862,20 +862,23 @@ pub const ErrorDetails = struct {
862862
pub const ErrorDetailsWithoutCodePage = blk: {
863863
const details_info = @typeInfo(ErrorDetails);
864864
const fields = details_info.@"struct".fields;
865-
var fields_without_codepage: [fields.len - 1]std.builtin.Type.StructField = undefined;
865+
var field_names: [fields.len - 1][]const u8 = undefined;
866+
var field_types: [fields.len - 1]type = undefined;
867+
var field_attrs: [fields.len - 1]std.builtin.Type.StructField.Attributes = undefined;
866868
var i: usize = 0;
867869
for (fields) |field| {
868870
if (std.mem.eql(u8, field.name, "code_page")) continue;
869-
fields_without_codepage[i] = field;
871+
field_names[i] = field.name;
872+
field_types[i] = field.type;
873+
field_attrs[i] = .{
874+
.@"comptime" = field.is_comptime,
875+
.@"align" = field.alignment,
876+
.default_value_ptr = field.default_value_ptr,
877+
};
870878
i += 1;
871879
}
872-
std.debug.assert(i == fields_without_codepage.len);
873-
break :blk @Type(.{ .@"struct" = .{
874-
.layout = .auto,
875-
.fields = &fields_without_codepage,
876-
.decls = &.{},
877-
.is_tuple = false,
878-
} });
880+
std.debug.assert(i == fields.len - 1);
881+
break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs);
879882
};
880883

881884
fn cellCount(code_page: SupportedCodePage, source: []const u8, start_index: usize, end_index: usize) usize {

lib/compiler/test_runner.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ fn mainTerminal() void {
298298

299299
pub fn log(
300300
comptime message_level: std.log.Level,
301-
comptime scope: @Type(.enum_literal),
301+
comptime scope: @EnumLiteral(),
302302
comptime format: []const u8,
303303
args: anytype,
304304
) void {

lib/compiler_rt/common.zig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,7 @@ pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeIn
290290
pub inline fn fneg(a: anytype) @TypeOf(a) {
291291
const F = @TypeOf(a);
292292
const bits = @typeInfo(F).float.bits;
293-
const U = @Type(.{ .int = .{
294-
.signedness = .unsigned,
295-
.bits = bits,
296-
} });
293+
const U = @Int(.unsigned, bits);
297294
const sign_bit_mask = @as(U, 1) << (bits - 1);
298295
const negated = @as(U, @bitCast(a)) ^ sign_bit_mask;
299296
return @bitCast(negated);

0 commit comments

Comments
 (0)