authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-02 13:39:27-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-02-02 13:39:27-05:00
log3eb8d01f522cf23d484411794ac10777b3de1cfa
treeadcd72ca78f4b72e5bc2e20a2af68c3ce011ee14
parentf95fcb2b1fadb34588f727f22b4d5ed07cd73d5e
parent449554a7307731047fcd9c132386fdf405c3b237
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #10766 from ziglang/yeet-anytype-fields

remove anytype fields from the language

18 files changed, 258 insertions(+), 301 deletions(-)

lib/std/builtin.zig+7-8
...@@ -226,11 +226,10 @@ pub const TypeInfo = union(enum) {...@@ -226,11 +226,10 @@ pub const TypeInfo = union(enum) {
226 child: type,226 child: type,
227 is_allowzero: bool,227 is_allowzero: bool,
228228
229 /// This field is an optional type.
230 /// The type of the sentinel is the element type of the pointer, which is229 /// The type of the sentinel is the element type of the pointer, which is
231 /// the value of the `child` field in this struct. However there is no way230 /// the value of the `child` field in this struct. However there is no way
232 /// to refer to that type here, so we use `anytype`.231 /// to refer to that type here, so we use pointer to `anyopaque`.
233 sentinel: anytype,232 sentinel: ?*const anyopaque,
234233
235 /// This data structure is used by the Zig language code generation and234 /// This data structure is used by the Zig language code generation and
236 /// therefore must be kept in sync with the compiler implementation.235 /// therefore must be kept in sync with the compiler implementation.
...@@ -248,11 +247,10 @@ pub const TypeInfo = union(enum) {...@@ -248,11 +247,10 @@ pub const TypeInfo = union(enum) {
248 len: comptime_int,247 len: comptime_int,
249 child: type,248 child: type,
250249
251 /// This field is an optional type.
252 /// The type of the sentinel is the element type of the array, which is250 /// The type of the sentinel is the element type of the array, which is
253 /// the value of the `child` field in this struct. However there is no way251 /// the value of the `child` field in this struct. However there is no way
254 /// to refer to that type here, so we use `anytype`.252 /// to refer to that type here, so we use pointer to `anyopaque`.
255 sentinel: anytype,253 sentinel: ?*const anyopaque,
256 };254 };
257255
258 /// This data structure is used by the Zig language code generation and256 /// This data structure is used by the Zig language code generation and
...@@ -267,8 +265,9 @@ pub const TypeInfo = union(enum) {...@@ -267,8 +265,9 @@ pub const TypeInfo = union(enum) {
267 /// therefore must be kept in sync with the compiler implementation.265 /// therefore must be kept in sync with the compiler implementation.
268 pub const StructField = struct {266 pub const StructField = struct {
269 name: []const u8,267 name: []const u8,
268 /// TODO rename to `type`
270 field_type: type,269 field_type: type,
271 default_value: anytype,270 default_value: ?*const anyopaque,
272 is_comptime: bool,271 is_comptime: bool,
273 alignment: comptime_int,272 alignment: comptime_int,
274 };273 };
...@@ -369,7 +368,7 @@ pub const TypeInfo = union(enum) {...@@ -369,7 +368,7 @@ pub const TypeInfo = union(enum) {
369 /// This data structure is used by the Zig language code generation and368 /// This data structure is used by the Zig language code generation and
370 /// therefore must be kept in sync with the compiler implementation.369 /// therefore must be kept in sync with the compiler implementation.
371 pub const Frame = struct {370 pub const Frame = struct {
372 function: anytype,371 function: *const anyopaque,
373 };372 };
374373
375 /// This data structure is used by the Zig language code generation and374 /// This data structure is used by the Zig language code generation and
lib/std/crypto/benchmark.zig+2-2
...@@ -297,8 +297,8 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int) !u64 {...@@ -297,8 +297,8 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int) !u64 {
297}297}
298298
299const CryptoPwhash = struct {299const CryptoPwhash = struct {
300 hashFn: anytype,300 hashFn: @compileError("anytype fields are removed from the language"),
301 params: anytype,301 params: @compileError("anytype fields are removed from the language"),
302 name: []const u8,302 name: []const u8,
303};303};
304const bcrypt_params = crypto.pwhash.bcrypt.Params{ .rounds_log = 12 };304const bcrypt_params = crypto.pwhash.bcrypt.Params{ .rounds_log = 12 };
lib/std/enums.zig+1-1
...@@ -16,7 +16,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def...@@ -16,7 +16,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def
16 fields = fields ++ &[_]StructField{.{16 fields = fields ++ &[_]StructField{.{
17 .name = field.name,17 .name = field.name,
18 .field_type = Data,18 .field_type = Data,
19 .default_value = field_default,19 .default_value = if (field_default) |d| &d else null,
20 .is_comptime = false,20 .is_comptime = false,
21 .alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,21 .alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,
22 }};22 }};
lib/std/json.zig+2-1
...@@ -1791,8 +1791,9 @@ fn parseInternal(...@@ -1791,8 +1791,9 @@ fn parseInternal(
1791 }1791 }
1792 inline for (structInfo.fields) |field, i| {1792 inline for (structInfo.fields) |field, i| {
1793 if (!fields_seen[i]) {1793 if (!fields_seen[i]) {
1794 if (field.default_value) |default| {1794 if (field.default_value) |default_ptr| {
1795 if (!field.is_comptime) {1795 if (!field.is_comptime) {
1796 const default = @ptrCast(*const field.field_type, default_ptr).*;
1796 @field(r, field.name) = default;1797 @field(r, field.name) = default;
1797 }1798 }
1798 } else {1799 } else {
lib/std/mem.zig+35-18
...@@ -296,7 +296,8 @@ pub fn zeroes(comptime T: type) T {...@@ -296,7 +296,8 @@ pub fn zeroes(comptime T: type) T {
296 }296 }
297 },297 },
298 .Array => |info| {298 .Array => |info| {
299 if (info.sentinel) |sentinel| {299 if (info.sentinel) |sentinel_ptr| {
300 const sentinel = @ptrCast(*const info.child, sentinel_ptr).*;
300 return [_:sentinel]info.child{zeroes(info.child)} ** info.len;301 return [_:sentinel]info.child{zeroes(info.child)} ** info.len;
301 }302 }
302 return [_]info.child{zeroes(info.child)} ** info.len;303 return [_]info.child{zeroes(info.child)} ** info.len;
...@@ -453,7 +454,8 @@ pub fn zeroInit(comptime T: type, init: anytype) T {...@@ -453,7 +454,8 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
453 @field(value, field.name) = @field(init, field.name);454 @field(value, field.name) = @field(init, field.name);
454 },455 },
455 }456 }
456 } else if (field.default_value) |default_value| {457 } else if (field.default_value) |default_value_ptr| {
458 const default_value = @ptrCast(*const field.field_type, default_value_ptr).*;
457 @field(value, field.name) = default_value;459 @field(value, field.name) = default_value;
458 }460 }
459 }461 }
...@@ -599,7 +601,7 @@ pub fn Span(comptime T: type) type {...@@ -599,7 +601,7 @@ pub fn Span(comptime T: type) type {
599 else => @compileError("invalid type given to std.mem.Span"),601 else => @compileError("invalid type given to std.mem.Span"),
600 },602 },
601 .C => {603 .C => {
602 new_ptr_info.sentinel = 0;604 new_ptr_info.sentinel = &@as(ptr_info.child, 0);
603 new_ptr_info.is_allowzero = false;605 new_ptr_info.is_allowzero = false;
604 },606 },
605 .Many, .Slice => {},607 .Many, .Slice => {},
...@@ -651,7 +653,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {...@@ -651,7 +653,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
651 }653 }
652 const Result = Span(@TypeOf(ptr));654 const Result = Span(@TypeOf(ptr));
653 const l = len(ptr);655 const l = len(ptr);
654 if (@typeInfo(Result).Pointer.sentinel) |s| {656 const ptr_info = @typeInfo(Result).Pointer;
657 if (ptr_info.sentinel) |s_ptr| {
658 const s = @ptrCast(*const ptr_info.child, s_ptr).*;
655 return ptr[0..l :s];659 return ptr[0..l :s];
656 } else {660 } else {
657 return ptr[0..l];661 return ptr[0..l];
...@@ -684,9 +688,10 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {...@@ -684,9 +688,10 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
684 // The return type must only be sentinel terminated if we are guaranteed688 // The return type must only be sentinel terminated if we are guaranteed
685 // to find the value searched for, which is only the case if it matches689 // to find the value searched for, which is only the case if it matches
686 // the sentinel of the type passed.690 // the sentinel of the type passed.
687 if (array_info.sentinel) |sentinel| {691 if (array_info.sentinel) |sentinel_ptr| {
692 const sentinel = @ptrCast(*const array_info.child, sentinel_ptr).*;
688 if (end == sentinel) {693 if (end == sentinel) {
689 new_ptr_info.sentinel = end;694 new_ptr_info.sentinel = &end;
690 } else {695 } else {
691 new_ptr_info.sentinel = null;696 new_ptr_info.sentinel = null;
692 }697 }
...@@ -698,16 +703,17 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {...@@ -698,16 +703,17 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
698 // The return type must only be sentinel terminated if we are guaranteed703 // The return type must only be sentinel terminated if we are guaranteed
699 // to find the value searched for, which is only the case if it matches704 // to find the value searched for, which is only the case if it matches
700 // the sentinel of the type passed.705 // the sentinel of the type passed.
701 if (ptr_info.sentinel) |sentinel| {706 if (ptr_info.sentinel) |sentinel_ptr| {
707 const sentinel = @ptrCast(*const ptr_info.child, sentinel_ptr).*;
702 if (end == sentinel) {708 if (end == sentinel) {
703 new_ptr_info.sentinel = end;709 new_ptr_info.sentinel = &end;
704 } else {710 } else {
705 new_ptr_info.sentinel = null;711 new_ptr_info.sentinel = null;
706 }712 }
707 }713 }
708 },714 },
709 .C => {715 .C => {
710 new_ptr_info.sentinel = end;716 new_ptr_info.sentinel = &end;
711 // C pointers are always allowzero, but we don't want the return type to be.717 // C pointers are always allowzero, but we don't want the return type to be.
712 assert(new_ptr_info.is_allowzero);718 assert(new_ptr_info.is_allowzero);
713 new_ptr_info.is_allowzero = false;719 new_ptr_info.is_allowzero = false;
...@@ -734,7 +740,9 @@ pub fn sliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) SliceTo(@Typ...@@ -734,7 +740,9 @@ pub fn sliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) SliceTo(@Typ
734 }740 }
735 const Result = SliceTo(@TypeOf(ptr), end);741 const Result = SliceTo(@TypeOf(ptr), end);
736 const length = lenSliceTo(ptr, end);742 const length = lenSliceTo(ptr, end);
737 if (@typeInfo(Result).Pointer.sentinel) |s| {743 const ptr_info = @typeInfo(Result).Pointer;
744 if (ptr_info.sentinel) |s_ptr| {
745 const s = @ptrCast(*const ptr_info.child, s_ptr).*;
738 return ptr[0..length :s];746 return ptr[0..length :s];
739 } else {747 } else {
740 return ptr[0..length];748 return ptr[0..length];
...@@ -786,7 +794,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {...@@ -786,7 +794,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
786 .Pointer => |ptr_info| switch (ptr_info.size) {794 .Pointer => |ptr_info| switch (ptr_info.size) {
787 .One => switch (@typeInfo(ptr_info.child)) {795 .One => switch (@typeInfo(ptr_info.child)) {
788 .Array => |array_info| {796 .Array => |array_info| {
789 if (array_info.sentinel) |sentinel| {797 if (array_info.sentinel) |sentinel_ptr| {
798 const sentinel = @ptrCast(*const array_info.child, sentinel_ptr).*;
790 if (sentinel == end) {799 if (sentinel == end) {
791 return indexOfSentinel(array_info.child, end, ptr);800 return indexOfSentinel(array_info.child, end, ptr);
792 }801 }
...@@ -795,7 +804,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {...@@ -795,7 +804,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
795 },804 },
796 else => {},805 else => {},
797 },806 },
798 .Many => if (ptr_info.sentinel) |sentinel| {807 .Many => if (ptr_info.sentinel) |sentinel_ptr| {
808 const sentinel = @ptrCast(*const ptr_info.child, sentinel_ptr).*;
799 // We may be looking for something other than the sentinel,809 // We may be looking for something other than the sentinel,
800 // but iterating past the sentinel would be a bug so we need810 // but iterating past the sentinel would be a bug so we need
801 // to check for both.811 // to check for both.
...@@ -808,7 +818,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {...@@ -808,7 +818,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
808 return indexOfSentinel(ptr_info.child, end, ptr);818 return indexOfSentinel(ptr_info.child, end, ptr);
809 },819 },
810 .Slice => {820 .Slice => {
811 if (ptr_info.sentinel) |sentinel| {821 if (ptr_info.sentinel) |sentinel_ptr| {
822 const sentinel = @ptrCast(*const ptr_info.child, sentinel_ptr).*;
812 if (sentinel == end) {823 if (sentinel == end) {
813 return indexOfSentinel(ptr_info.child, sentinel, ptr);824 return indexOfSentinel(ptr_info.child, sentinel, ptr);
814 }825 }
...@@ -867,10 +878,12 @@ pub fn len(value: anytype) usize {...@@ -867,10 +878,12 @@ pub fn len(value: anytype) usize {
867 .Array => value.len,878 .Array => value.len,
868 else => @compileError("invalid type given to std.mem.len"),879 else => @compileError("invalid type given to std.mem.len"),
869 },880 },
870 .Many => if (info.sentinel) |sentinel|881 .Many => {
871 indexOfSentinel(info.child, sentinel, value)882 const sentinel_ptr = info.sentinel orelse
872 else883 @compileError("length of pointer with no sentinel");
873 @compileError("length of pointer with no sentinel"),884 const sentinel = @ptrCast(*const info.child, sentinel_ptr).*;
885 return indexOfSentinel(info.child, sentinel, value);
886 },
874 .C => {887 .C => {
875 assert(value != null);888 assert(value != null);
876 return indexOfSentinel(info.child, 0, value);889 return indexOfSentinel(info.child, 0, value);
...@@ -2572,7 +2585,11 @@ test "alignPointer" {...@@ -2572,7 +2585,11 @@ test "alignPointer" {
2572 try S.checkAlign([*]u32, math.maxInt(usize) - 3, 8, 0);2585 try S.checkAlign([*]u32, math.maxInt(usize) - 3, 8, 0);
2573}2586}
25742587
2575fn CopyPtrAttrs(comptime source: type, comptime size: std.builtin.TypeInfo.Pointer.Size, comptime child: type) type {2588fn CopyPtrAttrs(
2589 comptime source: type,
2590 comptime size: std.builtin.TypeInfo.Pointer.Size,
2591 comptime child: type,
2592) type {
2576 const info = @typeInfo(source).Pointer;2593 const info = @typeInfo(source).Pointer;
2577 return @Type(.{2594 return @Type(.{
2578 .Pointer = .{2595 .Pointer = .{
lib/std/meta.zig+15-6
...@@ -190,12 +190,21 @@ test "std.meta.Elem" {...@@ -190,12 +190,21 @@ test "std.meta.Elem" {
190/// Types which cannot possibly have a sentinel will be a compile error.190/// Types which cannot possibly have a sentinel will be a compile error.
191pub fn sentinel(comptime T: type) ?Elem(T) {191pub fn sentinel(comptime T: type) ?Elem(T) {
192 switch (@typeInfo(T)) {192 switch (@typeInfo(T)) {
193 .Array => |info| return info.sentinel,193 .Array => |info| {
194 const sentinel_ptr = info.sentinel orelse return null;
195 return @ptrCast(*const info.child, sentinel_ptr).*;
196 },
194 .Pointer => |info| {197 .Pointer => |info| {
195 switch (info.size) {198 switch (info.size) {
196 .Many, .Slice => return info.sentinel,199 .Many, .Slice => {
200 const sentinel_ptr = info.sentinel orelse return null;
201 return @ptrCast(*const info.child, sentinel_ptr).*;
202 },
197 .One => switch (@typeInfo(info.child)) {203 .One => switch (@typeInfo(info.child)) {
198 .Array => |array_info| return array_info.sentinel,204 .Array => |array_info| {
205 const sentinel_ptr = array_info.sentinel orelse return null;
206 return @ptrCast(*const array_info.child, sentinel_ptr).*;
207 },
199 else => {},208 else => {},
200 },209 },
201 else => {},210 else => {},
...@@ -239,7 +248,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -239,7 +248,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
239 .Array = .{248 .Array = .{
240 .len = array_info.len,249 .len = array_info.len,
241 .child = array_info.child,250 .child = array_info.child,
242 .sentinel = sentinel_val,251 .sentinel = &sentinel_val,
243 },252 },
244 }),253 }),
245 .is_allowzero = info.is_allowzero,254 .is_allowzero = info.is_allowzero,
...@@ -257,7 +266,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -257,7 +266,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
257 .address_space = info.address_space,266 .address_space = info.address_space,
258 .child = info.child,267 .child = info.child,
259 .is_allowzero = info.is_allowzero,268 .is_allowzero = info.is_allowzero,
260 .sentinel = sentinel_val,269 .sentinel = &sentinel_val,
261 },270 },
262 }),271 }),
263 else => {},272 else => {},
...@@ -275,7 +284,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -275,7 +284,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
275 .address_space = ptr_info.address_space,284 .address_space = ptr_info.address_space,
276 .child = ptr_info.child,285 .child = ptr_info.child,
277 .is_allowzero = ptr_info.is_allowzero,286 .is_allowzero = ptr_info.is_allowzero,
278 .sentinel = sentinel_val,287 .sentinel = &sentinel_val,
279 },288 },
280 }),289 }),
281 },290 },
lib/std/zig/Ast.zig-5
...@@ -366,7 +366,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -366,7 +366,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex {
366 .builtin_call,366 .builtin_call,
367 .builtin_call_comma,367 .builtin_call_comma,
368 .error_set_decl,368 .error_set_decl,
369 .@"anytype",
370 .@"comptime",369 .@"comptime",
371 .@"nosuspend",370 .@"nosuspend",
372 .asm_simple,371 .asm_simple,
...@@ -729,7 +728,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -729,7 +728,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
729 .error_value,728 .error_value,
730 => return datas[n].rhs + end_offset,729 => return datas[n].rhs + end_offset,
731730
732 .@"anytype",
733 .anyframe_literal,731 .anyframe_literal,
734 .char_literal,732 .char_literal,
735 .integer_literal,733 .integer_literal,
...@@ -2935,9 +2933,6 @@ pub const Node = struct {...@@ -2935,9 +2933,6 @@ pub const Node = struct {
2935 /// main_token is the field name identifier.2933 /// main_token is the field name identifier.
2936 /// lastToken() does not include the possible trailing comma.2934 /// lastToken() does not include the possible trailing comma.
2937 container_field,2935 container_field,
2938 /// `anytype`. both lhs and rhs unused.
2939 /// Used by `ContainerField`.
2940 @"anytype",
2941 /// `comptime lhs`. rhs unused.2936 /// `comptime lhs`. rhs unused.
2942 @"comptime",2937 @"comptime",
2943 /// `nosuspend lhs`. rhs unused.2938 /// `nosuspend lhs`. rhs unused.
lib/std/zig/parse.zig+2-13
...@@ -786,19 +786,8 @@ const Parser = struct {...@@ -786,19 +786,8 @@ const Parser = struct {
786 var align_expr: Node.Index = 0;786 var align_expr: Node.Index = 0;
787 var type_expr: Node.Index = 0;787 var type_expr: Node.Index = 0;
788 if (p.eatToken(.colon)) |_| {788 if (p.eatToken(.colon)) |_| {
789 if (p.eatToken(.keyword_anytype)) |anytype_tok| {789 type_expr = try p.expectTypeExpr();
790 type_expr = try p.addNode(.{790 align_expr = try p.parseByteAlign();
791 .tag = .@"anytype",
792 .main_token = anytype_tok,
793 .data = .{
794 .lhs = undefined,
795 .rhs = undefined,
796 },
797 });
798 } else {
799 type_expr = try p.expectTypeExpr();
800 align_expr = try p.parseByteAlign();
801 }
802 }791 }
803792
804 const value_expr: Node.Index = if (p.eatToken(.equal) == null) 0 else try p.expectExpr();793 const value_expr: Node.Index = if (p.eatToken(.equal) == null) 0 else try p.expectExpr();
lib/std/zig/render.zig-2
...@@ -229,8 +229,6 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index,...@@ -229,8 +229,6 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index,
229 return renderToken(ais, tree, main_tokens[node] + 2, space);229 return renderToken(ais, tree, main_tokens[node] + 2, space);
230 },230 },
231231
232 .@"anytype" => return renderToken(ais, tree, main_tokens[node], space),
233
234 .block_two,232 .block_two,
235 .block_two_semicolon,233 .block_two_semicolon,
236 => {234 => {
src/AstGen.zig+2-18
...@@ -468,7 +468,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins...@@ -468,7 +468,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins
468 .for_simple,468 .for_simple,
469 .@"suspend",469 .@"suspend",
470 .@"continue",470 .@"continue",
471 .@"anytype",
472 .fn_proto_simple,471 .fn_proto_simple,
473 .fn_proto_multi,472 .fn_proto_multi,
474 .fn_proto_one,473 .fn_proto_one,
...@@ -558,8 +557,6 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr...@@ -558,8 +557,6 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr
558 .asm_output => unreachable, // Handled in `asmExpr`.557 .asm_output => unreachable, // Handled in `asmExpr`.
559 .asm_input => unreachable, // Handled in `asmExpr`.558 .asm_input => unreachable, // Handled in `asmExpr`.
560559
561 .@"anytype" => unreachable, // Handled in `containerDecl`.
562
563 .assign => {560 .assign => {
564 try assign(gz, scope, node);561 try assign(gz, scope, node);
565 return rvalue(gz, rl, .void_value, node);562 return rvalue(gz, rl, .void_value, node);
...@@ -3826,7 +3823,6 @@ fn structDeclInner(...@@ -3826,7 +3823,6 @@ fn structDeclInner(
3826 const astgen = gz.astgen;3823 const astgen = gz.astgen;
3827 const gpa = astgen.gpa;3824 const gpa = astgen.gpa;
3828 const tree = astgen.tree;3825 const tree = astgen.tree;
3829 const node_tags = tree.nodes.items(.tag);
38303826
3831 var namespace: Scope.Namespace = .{3827 var namespace: Scope.Namespace = .{
3832 .parent = scope,3828 .parent = scope,
...@@ -3875,10 +3871,7 @@ fn structDeclInner(...@@ -3875,10 +3871,7 @@ fn structDeclInner(
3875 return astgen.failTok(member.ast.name_token, "struct field missing type", .{});3871 return astgen.failTok(member.ast.name_token, "struct field missing type", .{});
3876 }3872 }
38773873
3878 const field_type: Zir.Inst.Ref = if (node_tags[member.ast.type_expr] == .@"anytype")3874 const field_type = try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
3879 .none
3880 else
3881 try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
3882 wip_members.appendToField(@enumToInt(field_type));3875 wip_members.appendToField(@enumToInt(field_type));
38833876
3884 const doc_comment_index = try astgen.docCommentAsString(member.firstToken());3877 const doc_comment_index = try astgen.docCommentAsString(member.firstToken());
...@@ -3951,8 +3944,6 @@ fn unionDeclInner(...@@ -3951,8 +3944,6 @@ fn unionDeclInner(
39513944
3952 const astgen = gz.astgen;3945 const astgen = gz.astgen;
3953 const gpa = astgen.gpa;3946 const gpa = astgen.gpa;
3954 const tree = astgen.tree;
3955 const node_tags = tree.nodes.items(.tag);
39563947
3957 var namespace: Scope.Namespace = .{3948 var namespace: Scope.Namespace = .{
3958 .parent = scope,3949 .parent = scope,
...@@ -4013,10 +4004,7 @@ fn unionDeclInner(...@@ -4013,10 +4004,7 @@ fn unionDeclInner(
4013 wip_members.nextField(bits_per_field, .{ have_type, have_align, have_value, unused });4004 wip_members.nextField(bits_per_field, .{ have_type, have_align, have_value, unused });
40144005
4015 if (have_type) {4006 if (have_type) {
4016 const field_type: Zir.Inst.Ref = if (node_tags[member.ast.type_expr] == .@"anytype")4007 const field_type = try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
4017 .none
4018 else
4019 try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
4020 wip_members.appendToField(@enumToInt(field_type));4008 wip_members.appendToField(@enumToInt(field_type));
4021 } else if (arg_inst == .none and !have_auto_enum) {4009 } else if (arg_inst == .none and !have_auto_enum) {
4022 return astgen.failNode(member_node, "union field missing type", .{});4010 return astgen.failNode(member_node, "union field missing type", .{});
...@@ -7791,7 +7779,6 @@ fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_...@@ -7791,7 +7779,6 @@ fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_
7791 .ptr_type,7779 .ptr_type,
7792 .ptr_type_bit_range,7780 .ptr_type_bit_range,
7793 .@"suspend",7781 .@"suspend",
7794 .@"anytype",
7795 .fn_proto_simple,7782 .fn_proto_simple,
7796 .fn_proto_multi,7783 .fn_proto_multi,
7797 .fn_proto_one,7784 .fn_proto_one,
...@@ -8052,7 +8039,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev...@@ -8052,7 +8039,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev
8052 .ptr_type,8039 .ptr_type,
8053 .ptr_type_bit_range,8040 .ptr_type_bit_range,
8054 .@"suspend",8041 .@"suspend",
8055 .@"anytype",
8056 .fn_proto_simple,8042 .fn_proto_simple,
8057 .fn_proto_multi,8043 .fn_proto_multi,
8058 .fn_proto_one,8044 .fn_proto_one,
...@@ -8232,7 +8218,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In...@@ -8232,7 +8218,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In
8232 .@"resume",8218 .@"resume",
8233 .array_type,8219 .array_type,
8234 .@"suspend",8220 .@"suspend",
8235 .@"anytype",
8236 .fn_decl,8221 .fn_decl,
8237 .anyframe_literal,8222 .anyframe_literal,
8238 .integer_literal,8223 .integer_literal,
...@@ -8474,7 +8459,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {...@@ -8474,7 +8459,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
8474 .@"resume",8459 .@"resume",
8475 .array_type,8460 .array_type,
8476 .@"suspend",8461 .@"suspend",
8477 .@"anytype",
8478 .fn_decl,8462 .fn_decl,
8479 .anyframe_literal,8463 .anyframe_literal,
8480 .integer_literal,8464 .integer_literal,
src/stage1/all_types.hpp+1
...@@ -2108,6 +2108,7 @@ struct CodeGen {...@@ -2108,6 +2108,7 @@ struct CodeGen {
2108 ZigType *entry_global_error_set;2108 ZigType *entry_global_error_set;
2109 ZigType *entry_enum_literal;2109 ZigType *entry_enum_literal;
2110 ZigType *entry_any_frame;2110 ZigType *entry_any_frame;
2111 ZigType *entry_opt_ptr_const_anyopaque;
2111 } builtin_types;2112 } builtin_types;
21122113
2113 struct Intern {2114 struct Intern {
src/stage1/codegen.cpp+6
...@@ -9451,6 +9451,12 @@ static void define_builtin_types(CodeGen *g) {...@@ -9451,6 +9451,12 @@ static void define_builtin_types(CodeGen *g) {
9451 g->primitive_type_table.put(&g->builtin_types.entry_anyopaque->name, g->builtin_types.entry_anyopaque);9451 g->primitive_type_table.put(&g->builtin_types.entry_anyopaque->name, g->builtin_types.entry_anyopaque);
9452 }9452 }
94539453
9454 {
9455 ZigType *ptr_const_anyopaque = get_pointer_to_type(g,
9456 g->builtin_types.entry_anyopaque, true);
9457 g->builtin_types.entry_opt_ptr_const_anyopaque = get_optional_type(g, ptr_const_anyopaque);
9458 }
9459
9454 {9460 {
9455 ZigType *entry = new_type_table_entry(ZigTypeIdErrorSet);9461 ZigType *entry = new_type_table_entry(ZigTypeIdErrorSet);
9456 buf_init_from_str(&entry->name, "anyerror");9462 buf_init_from_str(&entry->name, "anyerror");
src/stage1/ir.cpp+171-170
...@@ -18045,11 +18045,12 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {...@@ -18045,11 +18045,12 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {
18045}18045}
1804618046
18047static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ptr_type_entry) {18047static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ptr_type_entry) {
18048 CodeGen *g = ira->codegen;
18048 ZigType *attrs_type;18049 ZigType *attrs_type;
18049 BuiltinPtrSize size_enum_index;18050 BuiltinPtrSize size_enum_index;
18050 if (is_slice(ptr_type_entry)) {18051 if (is_slice(ptr_type_entry)) {
18051 TypeStructField *ptr_field = ptr_type_entry->data.structure.fields[slice_ptr_index];18052 TypeStructField *ptr_field = ptr_type_entry->data.structure.fields[slice_ptr_index];
18052 attrs_type = resolve_struct_field_type(ira->codegen, ptr_field);18053 attrs_type = resolve_struct_field_type(g, ptr_field);
18053 size_enum_index = BuiltinPtrSizeSlice;18054 size_enum_index = BuiltinPtrSizeSlice;
18054 } else if (ptr_type_entry->id == ZigTypeIdPointer) {18055 } else if (ptr_type_entry->id == ZigTypeIdPointer) {
18055 attrs_type = ptr_type_entry;18056 attrs_type = ptr_type_entry;
...@@ -18059,19 +18060,19 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode...@@ -18059,19 +18060,19 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode
18059 }18060 }
1806018061
18061 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);18062 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
18062 assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown));18063 assertNoError(type_resolve(g, type_info_pointer_type, ResolveStatusSizeKnown));
1806318064
18064 ZigValue *result = ira->codegen->pass1_arena->create<ZigValue>();18065 ZigValue *result = g->pass1_arena->create<ZigValue>();
18065 result->special = ConstValSpecialStatic;18066 result->special = ConstValSpecialStatic;
18066 result->type = type_info_pointer_type;18067 result->type = type_info_pointer_type;
1806718068
18068 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 8);18069 ZigValue **fields = alloc_const_vals_ptrs(g, 8);
18069 result->data.x_struct.fields = fields;18070 result->data.x_struct.fields = fields;
1807018071
18071 // size: Size18072 // size: Size
18072 ensure_field_index(result->type, "size", 0);18073 ensure_field_index(result->type, "size", 0);
18073 ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type);18074 ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type);
18074 assertNoError(type_resolve(ira->codegen, type_info_pointer_size_type, ResolveStatusSizeKnown));18075 assertNoError(type_resolve(g, type_info_pointer_size_type, ResolveStatusSizeKnown));
18075 fields[0]->special = ConstValSpecialStatic;18076 fields[0]->special = ConstValSpecialStatic;
18076 fields[0]->type = type_info_pointer_size_type;18077 fields[0]->type = type_info_pointer_size_type;
18077 bigint_init_unsigned(&fields[0]->data.x_enum_tag, size_enum_index);18078 bigint_init_unsigned(&fields[0]->data.x_enum_tag, size_enum_index);
...@@ -18079,16 +18080,16 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode...@@ -18079,16 +18080,16 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode
18079 // is_const: bool18080 // is_const: bool
18080 ensure_field_index(result->type, "is_const", 1);18081 ensure_field_index(result->type, "is_const", 1);
18081 fields[1]->special = ConstValSpecialStatic;18082 fields[1]->special = ConstValSpecialStatic;
18082 fields[1]->type = ira->codegen->builtin_types.entry_bool;18083 fields[1]->type = g->builtin_types.entry_bool;
18083 fields[1]->data.x_bool = attrs_type->data.pointer.is_const;18084 fields[1]->data.x_bool = attrs_type->data.pointer.is_const;
18084 // is_volatile: bool18085 // is_volatile: bool
18085 ensure_field_index(result->type, "is_volatile", 2);18086 ensure_field_index(result->type, "is_volatile", 2);
18086 fields[2]->special = ConstValSpecialStatic;18087 fields[2]->special = ConstValSpecialStatic;
18087 fields[2]->type = ira->codegen->builtin_types.entry_bool;18088 fields[2]->type = g->builtin_types.entry_bool;
18088 fields[2]->data.x_bool = attrs_type->data.pointer.is_volatile;18089 fields[2]->data.x_bool = attrs_type->data.pointer.is_volatile;
18089 // alignment: comptime_int18090 // alignment: comptime_int
18090 ensure_field_index(result->type, "alignment", 3);18091 ensure_field_index(result->type, "alignment", 3);
18091 fields[3]->type = ira->codegen->builtin_types.entry_num_lit_int;18092 fields[3]->type = g->builtin_types.entry_num_lit_int;
18092 if (attrs_type->data.pointer.explicit_alignment != 0) {18093 if (attrs_type->data.pointer.explicit_alignment != 0) {
18093 fields[3]->special = ConstValSpecialStatic;18094 fields[3]->special = ConstValSpecialStatic;
18094 bigint_init_unsigned(&fields[3]->data.x_bigint, attrs_type->data.pointer.explicit_alignment);18095 bigint_init_unsigned(&fields[3]->data.x_bigint, attrs_type->data.pointer.explicit_alignment);
...@@ -18103,27 +18104,25 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode...@@ -18103,27 +18104,25 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode
18103 // address_space: AddressSpace,18104 // address_space: AddressSpace,
18104 ensure_field_index(result->type, "address_space", 4);18105 ensure_field_index(result->type, "address_space", 4);
18105 fields[4]->special = ConstValSpecialStatic;18106 fields[4]->special = ConstValSpecialStatic;
18106 fields[4]->type = get_builtin_type(ira->codegen, "AddressSpace");18107 fields[4]->type = get_builtin_type(g, "AddressSpace");
18107 bigint_init_unsigned(&fields[4]->data.x_enum_tag, AddressSpaceGeneric);18108 bigint_init_unsigned(&fields[4]->data.x_enum_tag, AddressSpaceGeneric);
18108 // child: type18109 // child: type
18109 ensure_field_index(result->type, "child", 5);18110 ensure_field_index(result->type, "child", 5);
18110 fields[5]->special = ConstValSpecialStatic;18111 fields[5]->special = ConstValSpecialStatic;
18111 fields[5]->type = ira->codegen->builtin_types.entry_type;18112 fields[5]->type = g->builtin_types.entry_type;
18112 fields[5]->data.x_type = attrs_type->data.pointer.child_type;18113 fields[5]->data.x_type = attrs_type->data.pointer.child_type;
18113 // is_allowzero: bool18114 // is_allowzero: bool
18114 ensure_field_index(result->type, "is_allowzero", 6);18115 ensure_field_index(result->type, "is_allowzero", 6);
18115 fields[6]->special = ConstValSpecialStatic;18116 fields[6]->special = ConstValSpecialStatic;
18116 fields[6]->type = ira->codegen->builtin_types.entry_bool;18117 fields[6]->type = g->builtin_types.entry_bool;
18117 fields[6]->data.x_bool = attrs_type->data.pointer.allow_zero;18118 fields[6]->data.x_bool = attrs_type->data.pointer.allow_zero;
18118 // sentinel: anytype18119 // sentinel: ?*const anyopaque
18119 ensure_field_index(result->type, "sentinel", 7);18120 ensure_field_index(result->type, "sentinel", 7);
18120 fields[7]->special = ConstValSpecialStatic;18121 fields[7]->special = ConstValSpecialStatic;
18121 if (attrs_type->data.pointer.sentinel != nullptr) {18122 fields[7]->type = g->builtin_types.entry_opt_ptr_const_anyopaque;
18122 fields[7]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type);18123 ZigValue *ptr_to_sent = (attrs_type->data.pointer.sentinel == nullptr) ? nullptr :
18123 set_optional_payload(fields[7], attrs_type->data.pointer.sentinel);18124 create_const_ptr_ref(g, attrs_type->data.pointer.sentinel, true);
18124 } else {18125 set_optional_payload(fields[7], ptr_to_sent);
18125 fields[7]->type = ira->codegen->builtin_types.entry_null;
18126 }
1812718126
18128 return result;18127 return result;
18129};18128};
...@@ -18153,7 +18152,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18153,7 +18152,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18153 assert(type_entry != nullptr);18152 assert(type_entry != nullptr);
18154 assert(!type_is_invalid(type_entry));18153 assert(!type_is_invalid(type_entry));
1815518154
18156 auto entry = ira->codegen->type_info_cache.maybe_get(type_entry);18155 CodeGen *g = ira->codegen;
18156
18157 auto entry = g->type_info_cache.maybe_get(type_entry);
18157 if (entry != nullptr) {18158 if (entry != nullptr) {
18158 *out = entry->value;18159 *out = entry->value;
18159 return ErrorNone;18160 return ErrorNone;
...@@ -18172,43 +18173,43 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18172,43 +18173,43 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18172 case ZigTypeIdEnumLiteral:18173 case ZigTypeIdEnumLiteral:
18173 case ZigTypeIdUndefined:18174 case ZigTypeIdUndefined:
18174 case ZigTypeIdNull:18175 case ZigTypeIdNull:
18175 result = ira->codegen->intern.for_void();18176 result = g->intern.for_void();
18176 break;18177 break;
18177 case ZigTypeIdInt:18178 case ZigTypeIdInt:
18178 {18179 {
18179 result = ira->codegen->pass1_arena->create<ZigValue>();18180 result = g->pass1_arena->create<ZigValue>();
18180 result->special = ConstValSpecialStatic;18181 result->special = ConstValSpecialStatic;
18181 result->type = ir_type_info_get_type(ira, "Int", nullptr);18182 result->type = ir_type_info_get_type(ira, "Int", nullptr);
1818218183
18183 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);18184 ZigValue **fields = alloc_const_vals_ptrs(g, 2);
18184 result->data.x_struct.fields = fields;18185 result->data.x_struct.fields = fields;
1818518186
18186 // is_signed: Signedness18187 // is_signed: Signedness
18187 ensure_field_index(result->type, "signedness", 0);18188 ensure_field_index(result->type, "signedness", 0);
18188 fields[0]->special = ConstValSpecialStatic;18189 fields[0]->special = ConstValSpecialStatic;
18189 fields[0]->type = get_builtin_type(ira->codegen, "Signedness");18190 fields[0]->type = get_builtin_type(g, "Signedness");
18190 bigint_init_unsigned(&fields[0]->data.x_enum_tag, !type_entry->data.integral.is_signed);18191 bigint_init_unsigned(&fields[0]->data.x_enum_tag, !type_entry->data.integral.is_signed);
18191 // bits: u818192 // bits: u8
18192 ensure_field_index(result->type, "bits", 1);18193 ensure_field_index(result->type, "bits", 1);
18193 fields[1]->special = ConstValSpecialStatic;18194 fields[1]->special = ConstValSpecialStatic;
18194 fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;18195 fields[1]->type = g->builtin_types.entry_num_lit_int;
18195 bigint_init_unsigned(&fields[1]->data.x_bigint, type_entry->data.integral.bit_count);18196 bigint_init_unsigned(&fields[1]->data.x_bigint, type_entry->data.integral.bit_count);
1819618197
18197 break;18198 break;
18198 }18199 }
18199 case ZigTypeIdFloat:18200 case ZigTypeIdFloat:
18200 {18201 {
18201 result = ira->codegen->pass1_arena->create<ZigValue>();18202 result = g->pass1_arena->create<ZigValue>();
18202 result->special = ConstValSpecialStatic;18203 result->special = ConstValSpecialStatic;
18203 result->type = ir_type_info_get_type(ira, "Float", nullptr);18204 result->type = ir_type_info_get_type(ira, "Float", nullptr);
1820418205
18205 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);18206 ZigValue **fields = alloc_const_vals_ptrs(g, 1);
18206 result->data.x_struct.fields = fields;18207 result->data.x_struct.fields = fields;
1820718208
18208 // bits: u818209 // bits: u8
18209 ensure_field_index(result->type, "bits", 0);18210 ensure_field_index(result->type, "bits", 0);
18210 fields[0]->special = ConstValSpecialStatic;18211 fields[0]->special = ConstValSpecialStatic;
18211 fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int;18212 fields[0]->type = g->builtin_types.entry_num_lit_int;
18212 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.floating.bit_count);18213 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.floating.bit_count);
1821318214
18214 break;18215 break;
...@@ -18222,97 +18223,96 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18222,97 +18223,96 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18222 }18223 }
18223 case ZigTypeIdArray:18224 case ZigTypeIdArray:
18224 {18225 {
18225 result = ira->codegen->pass1_arena->create<ZigValue>();18226 result = g->pass1_arena->create<ZigValue>();
18226 result->special = ConstValSpecialStatic;18227 result->special = ConstValSpecialStatic;
18227 result->type = ir_type_info_get_type(ira, "Array", nullptr);18228 result->type = ir_type_info_get_type(ira, "Array", nullptr);
1822818229
18229 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 3);18230 ZigValue **fields = alloc_const_vals_ptrs(g, 3);
18230 result->data.x_struct.fields = fields;18231 result->data.x_struct.fields = fields;
1823118232
18232 // len: usize18233 // len: usize
18233 ensure_field_index(result->type, "len", 0);18234 ensure_field_index(result->type, "len", 0);
18234 fields[0]->special = ConstValSpecialStatic;18235 fields[0]->special = ConstValSpecialStatic;
18235 fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int;18236 fields[0]->type = g->builtin_types.entry_num_lit_int;
18236 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.array.len);18237 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.array.len);
18237 // child: type18238 // child: type
18238 ensure_field_index(result->type, "child", 1);18239 ensure_field_index(result->type, "child", 1);
18239 fields[1]->special = ConstValSpecialStatic;18240 fields[1]->special = ConstValSpecialStatic;
18240 fields[1]->type = ira->codegen->builtin_types.entry_type;18241 fields[1]->type = g->builtin_types.entry_type;
18241 fields[1]->data.x_type = type_entry->data.array.child_type;18242 fields[1]->data.x_type = type_entry->data.array.child_type;
18242 // sentinel: anytype18243 src_assert(type_entry->data.array.child_type != nullptr, source_node);
18244 // sentinel: ?*const anyopaque
18243 fields[2]->special = ConstValSpecialStatic;18245 fields[2]->special = ConstValSpecialStatic;
18244 if (type_entry->data.array.child_type != nullptr) {18246 fields[2]->type = g->builtin_types.entry_opt_ptr_const_anyopaque;
18245 fields[2]->type = get_optional_type(ira->codegen, type_entry->data.array.child_type);18247 ZigValue *ptr_to_sent = (type_entry->data.array.sentinel == nullptr) ? nullptr :
18246 set_optional_payload(fields[2], type_entry->data.array.sentinel);18248 create_const_ptr_ref(g, type_entry->data.array.sentinel, true);
18247 } else {18249 set_optional_payload(fields[2], ptr_to_sent);
18248 fields[2]->type = ira->codegen->builtin_types.entry_null;
18249 }
18250 break;18250 break;
18251 }18251 }
18252 case ZigTypeIdVector: {18252 case ZigTypeIdVector: {
18253 result = ira->codegen->pass1_arena->create<ZigValue>();18253 result = g->pass1_arena->create<ZigValue>();
18254 result->special = ConstValSpecialStatic;18254 result->special = ConstValSpecialStatic;
18255 result->type = ir_type_info_get_type(ira, "Vector", nullptr);18255 result->type = ir_type_info_get_type(ira, "Vector", nullptr);
1825618256
18257 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);18257 ZigValue **fields = alloc_const_vals_ptrs(g, 2);
18258 result->data.x_struct.fields = fields;18258 result->data.x_struct.fields = fields;
1825918259
18260 // len: usize18260 // len: usize
18261 ensure_field_index(result->type, "len", 0);18261 ensure_field_index(result->type, "len", 0);
18262 fields[0]->special = ConstValSpecialStatic;18262 fields[0]->special = ConstValSpecialStatic;
18263 fields[0]->type = ira->codegen->builtin_types.entry_num_lit_int;18263 fields[0]->type = g->builtin_types.entry_num_lit_int;
18264 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.vector.len);18264 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.vector.len);
18265 // child: type18265 // child: type
18266 ensure_field_index(result->type, "child", 1);18266 ensure_field_index(result->type, "child", 1);
18267 fields[1]->special = ConstValSpecialStatic;18267 fields[1]->special = ConstValSpecialStatic;
18268 fields[1]->type = ira->codegen->builtin_types.entry_type;18268 fields[1]->type = g->builtin_types.entry_type;
18269 fields[1]->data.x_type = type_entry->data.vector.elem_type;18269 fields[1]->data.x_type = type_entry->data.vector.elem_type;
1827018270
18271 break;18271 break;
18272 }18272 }
18273 case ZigTypeIdOptional:18273 case ZigTypeIdOptional:
18274 {18274 {
18275 result = ira->codegen->pass1_arena->create<ZigValue>();18275 result = g->pass1_arena->create<ZigValue>();
18276 result->special = ConstValSpecialStatic;18276 result->special = ConstValSpecialStatic;
18277 result->type = ir_type_info_get_type(ira, "Optional", nullptr);18277 result->type = ir_type_info_get_type(ira, "Optional", nullptr);
1827818278
18279 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);18279 ZigValue **fields = alloc_const_vals_ptrs(g, 1);
18280 result->data.x_struct.fields = fields;18280 result->data.x_struct.fields = fields;
1828118281
18282 // child: type18282 // child: type
18283 ensure_field_index(result->type, "child", 0);18283 ensure_field_index(result->type, "child", 0);
18284 fields[0]->special = ConstValSpecialStatic;18284 fields[0]->special = ConstValSpecialStatic;
18285 fields[0]->type = ira->codegen->builtin_types.entry_type;18285 fields[0]->type = g->builtin_types.entry_type;
18286 fields[0]->data.x_type = type_entry->data.maybe.child_type;18286 fields[0]->data.x_type = type_entry->data.maybe.child_type;
1828718287
18288 break;18288 break;
18289 }18289 }
18290 case ZigTypeIdAnyFrame: {18290 case ZigTypeIdAnyFrame: {
18291 result = ira->codegen->pass1_arena->create<ZigValue>();18291 result = g->pass1_arena->create<ZigValue>();
18292 result->special = ConstValSpecialStatic;18292 result->special = ConstValSpecialStatic;
18293 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);18293 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);
1829418294
18295 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);18295 ZigValue **fields = alloc_const_vals_ptrs(g, 1);
18296 result->data.x_struct.fields = fields;18296 result->data.x_struct.fields = fields;
1829718297
18298 // child: ?type18298 // child: ?type
18299 ensure_field_index(result->type, "child", 0);18299 ensure_field_index(result->type, "child", 0);
18300 fields[0]->special = ConstValSpecialStatic;18300 fields[0]->special = ConstValSpecialStatic;
18301 fields[0]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);18301 fields[0]->type = get_optional_type(g, g->builtin_types.entry_type);
18302 fields[0]->data.x_optional = (type_entry->data.any_frame.result_type == nullptr) ? nullptr :18302 fields[0]->data.x_optional = (type_entry->data.any_frame.result_type == nullptr) ? nullptr :
18303 create_const_type(ira->codegen, type_entry->data.any_frame.result_type);18303 create_const_type(g, type_entry->data.any_frame.result_type);
18304 break;18304 break;
18305 }18305 }
18306 case ZigTypeIdEnum:18306 case ZigTypeIdEnum:
18307 {18307 {
18308 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown)))18308 if ((err = type_resolve(g, type_entry, ResolveStatusSizeKnown)))
18309 return err;18309 return err;
1831018310
18311 result = ira->codegen->pass1_arena->create<ZigValue>();18311 result = g->pass1_arena->create<ZigValue>();
18312 result->special = ConstValSpecialStatic;18312 result->special = ConstValSpecialStatic;
18313 result->type = ir_type_info_get_type(ira, "Enum", nullptr);18313 result->type = ir_type_info_get_type(ira, "Enum", nullptr);
1831418314
18315 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 5);18315 ZigValue **fields = alloc_const_vals_ptrs(g, 5);
18316 result->data.x_struct.fields = fields;18316 result->data.x_struct.fields = fields;
1831718317
18318 // layout: ContainerLayout18318 // layout: ContainerLayout
...@@ -18323,24 +18323,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18323,24 +18323,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18323 // tag_type: type18323 // tag_type: type
18324 ensure_field_index(result->type, "tag_type", 1);18324 ensure_field_index(result->type, "tag_type", 1);
18325 fields[1]->special = ConstValSpecialStatic;18325 fields[1]->special = ConstValSpecialStatic;
18326 fields[1]->type = ira->codegen->builtin_types.entry_type;18326 fields[1]->type = g->builtin_types.entry_type;
18327 fields[1]->data.x_type = type_entry->data.enumeration.tag_int_type;18327 fields[1]->data.x_type = type_entry->data.enumeration.tag_int_type;
18328 // fields: []TypeInfo.EnumField18328 // fields: []TypeInfo.EnumField
18329 ensure_field_index(result->type, "fields", 2);18329 ensure_field_index(result->type, "fields", 2);
1833018330
18331 ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);18331 ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
18332 if ((err = type_resolve(ira->codegen, type_info_enum_field_type, ResolveStatusSizeKnown))) {18332 if ((err = type_resolve(g, type_info_enum_field_type, ResolveStatusSizeKnown))) {
18333 zig_unreachable();18333 zig_unreachable();
18334 }18334 }
18335 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;18335 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;
1833618336
18337 ZigValue *enum_field_array = ira->codegen->pass1_arena->create<ZigValue>();18337 ZigValue *enum_field_array = g->pass1_arena->create<ZigValue>();
18338 enum_field_array->special = ConstValSpecialStatic;18338 enum_field_array->special = ConstValSpecialStatic;
18339 enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr);18339 enum_field_array->type = get_array_type(g, type_info_enum_field_type, enum_field_count, nullptr);
18340 enum_field_array->data.x_array.special = ConstArraySpecialNone;18340 enum_field_array->data.x_array.special = ConstArraySpecialNone;
18341 enum_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(enum_field_count);18341 enum_field_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(enum_field_count);
1834218342
18343 init_const_slice(ira->codegen, fields[2], enum_field_array, 0, enum_field_count, false, nullptr);18343 init_const_slice(g, fields[2], enum_field_array, 0, enum_field_count, false, nullptr);
1834418344
18345 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)18345 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)
18346 {18346 {
...@@ -18361,39 +18361,39 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18361,39 +18361,39 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18361 // is_exhaustive: bool18361 // is_exhaustive: bool
18362 ensure_field_index(result->type, "is_exhaustive", 4);18362 ensure_field_index(result->type, "is_exhaustive", 4);
18363 fields[4]->special = ConstValSpecialStatic;18363 fields[4]->special = ConstValSpecialStatic;
18364 fields[4]->type = ira->codegen->builtin_types.entry_bool;18364 fields[4]->type = g->builtin_types.entry_bool;
18365 fields[4]->data.x_bool = !type_entry->data.enumeration.non_exhaustive;18365 fields[4]->data.x_bool = !type_entry->data.enumeration.non_exhaustive;
1836618366
18367 break;18367 break;
18368 }18368 }
18369 case ZigTypeIdErrorSet:18369 case ZigTypeIdErrorSet:
18370 {18370 {
18371 result = ira->codegen->pass1_arena->create<ZigValue>();18371 result = g->pass1_arena->create<ZigValue>();
18372 result->special = ConstValSpecialStatic;18372 result->special = ConstValSpecialStatic;
18373 result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr);18373 result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr);
1837418374
18375 ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);18375 ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
18376 if (!resolve_inferred_error_set(ira->codegen, type_entry, source_node)) {18376 if (!resolve_inferred_error_set(g, type_entry, source_node)) {
18377 return ErrorSemanticAnalyzeFail;18377 return ErrorSemanticAnalyzeFail;
18378 }18378 }
18379 if (type_is_global_error_set(type_entry)) {18379 if (type_is_global_error_set(type_entry)) {
18380 result->data.x_optional = nullptr;18380 result->data.x_optional = nullptr;
18381 break;18381 break;
18382 }18382 }
18383 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {18383 if ((err = type_resolve(g, type_info_error_type, ResolveStatusSizeKnown))) {
18384 zig_unreachable();18384 zig_unreachable();
18385 }18385 }
18386 ZigValue *slice_val = ira->codegen->pass1_arena->create<ZigValue>();18386 ZigValue *slice_val = g->pass1_arena->create<ZigValue>();
18387 result->data.x_optional = slice_val;18387 result->data.x_optional = slice_val;
1838818388
18389 uint32_t error_count = type_entry->data.error_set.err_count;18389 uint32_t error_count = type_entry->data.error_set.err_count;
18390 ZigValue *error_array = ira->codegen->pass1_arena->create<ZigValue>();18390 ZigValue *error_array = g->pass1_arena->create<ZigValue>();
18391 error_array->special = ConstValSpecialStatic;18391 error_array->special = ConstValSpecialStatic;
18392 error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr);18392 error_array->type = get_array_type(g, type_info_error_type, error_count, nullptr);
18393 error_array->data.x_array.special = ConstArraySpecialNone;18393 error_array->data.x_array.special = ConstArraySpecialNone;
18394 error_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(error_count);18394 error_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(error_count);
1839518395
18396 init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false, nullptr);18396 init_const_slice(g, slice_val, error_array, 0, error_count, false, nullptr);
18397 for (uint32_t error_index = 0; error_index < error_count; error_index++) {18397 for (uint32_t error_index = 0; error_index < error_count; error_index++) {
18398 ErrorTableEntry *error = type_entry->data.error_set.errors[error_index];18398 ErrorTableEntry *error = type_entry->data.error_set.errors[error_index];
18399 ZigValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index];18399 ZigValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index];
...@@ -18401,14 +18401,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18401,14 +18401,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18401 error_val->special = ConstValSpecialStatic;18401 error_val->special = ConstValSpecialStatic;
18402 error_val->type = type_info_error_type;18402 error_val->type = type_info_error_type;
1840318403
18404 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 1);18404 ZigValue **inner_fields = alloc_const_vals_ptrs(g, 1);
1840518405
18406 ZigValue *name = nullptr;18406 ZigValue *name = nullptr;
18407 if (error->cached_error_name_val != nullptr)18407 if (error->cached_error_name_val != nullptr)
18408 name = error->cached_error_name_val;18408 name = error->cached_error_name_val;
18409 if (name == nullptr)18409 if (name == nullptr)
18410 name = create_const_str_lit(ira->codegen, &error->name)->data.x_ptr.data.ref.pointee;18410 name = create_const_str_lit(g, &error->name)->data.x_ptr.data.ref.pointee;
18411 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(&error->name), true, nullptr);18411 init_const_slice(g, inner_fields[0], name, 0, buf_len(&error->name), true, nullptr);
1841218412
18413 error_val->data.x_struct.fields = inner_fields;18413 error_val->data.x_struct.fields = inner_fields;
18414 error_val->parent.id = ConstParentIdArray;18414 error_val->parent.id = ConstParentIdArray;
...@@ -18420,37 +18420,37 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18420,37 +18420,37 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18420 }18420 }
18421 case ZigTypeIdErrorUnion:18421 case ZigTypeIdErrorUnion:
18422 {18422 {
18423 result = ira->codegen->pass1_arena->create<ZigValue>();18423 result = g->pass1_arena->create<ZigValue>();
18424 result->special = ConstValSpecialStatic;18424 result->special = ConstValSpecialStatic;
18425 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);18425 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);
1842618426
18427 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);18427 ZigValue **fields = alloc_const_vals_ptrs(g, 2);
18428 result->data.x_struct.fields = fields;18428 result->data.x_struct.fields = fields;
1842918429
18430 // error_set: type18430 // error_set: type
18431 ensure_field_index(result->type, "error_set", 0);18431 ensure_field_index(result->type, "error_set", 0);
18432 fields[0]->special = ConstValSpecialStatic;18432 fields[0]->special = ConstValSpecialStatic;
18433 fields[0]->type = ira->codegen->builtin_types.entry_type;18433 fields[0]->type = g->builtin_types.entry_type;
18434 fields[0]->data.x_type = type_entry->data.error_union.err_set_type;18434 fields[0]->data.x_type = type_entry->data.error_union.err_set_type;
1843518435
18436 // payload: type18436 // payload: type
18437 ensure_field_index(result->type, "payload", 1);18437 ensure_field_index(result->type, "payload", 1);
18438 fields[1]->special = ConstValSpecialStatic;18438 fields[1]->special = ConstValSpecialStatic;
18439 fields[1]->type = ira->codegen->builtin_types.entry_type;18439 fields[1]->type = g->builtin_types.entry_type;
18440 fields[1]->data.x_type = type_entry->data.error_union.payload_type;18440 fields[1]->data.x_type = type_entry->data.error_union.payload_type;
1844118441
18442 break;18442 break;
18443 }18443 }
18444 case ZigTypeIdUnion:18444 case ZigTypeIdUnion:
18445 {18445 {
18446 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown)))18446 if ((err = type_resolve(g, type_entry, ResolveStatusSizeKnown)))
18447 return err;18447 return err;
1844818448
18449 result = ira->codegen->pass1_arena->create<ZigValue>();18449 result = g->pass1_arena->create<ZigValue>();
18450 result->special = ConstValSpecialStatic;18450 result->special = ConstValSpecialStatic;
18451 result->type = ir_type_info_get_type(ira, "Union", nullptr);18451 result->type = ir_type_info_get_type(ira, "Union", nullptr);
1845218452
18453 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 4);18453 ZigValue **fields = alloc_const_vals_ptrs(g, 4);
18454 result->data.x_struct.fields = fields;18454 result->data.x_struct.fields = fields;
1845518455
18456 // layout: ContainerLayout18456 // layout: ContainerLayout
...@@ -18461,15 +18461,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18461,15 +18461,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18461 // tag_type: ?type18461 // tag_type: ?type
18462 ensure_field_index(result->type, "tag_type", 1);18462 ensure_field_index(result->type, "tag_type", 1);
18463 fields[1]->special = ConstValSpecialStatic;18463 fields[1]->special = ConstValSpecialStatic;
18464 fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);18464 fields[1]->type = get_optional_type(g, g->builtin_types.entry_type);
1846518465
18466 AstNode *union_decl_node = type_entry->data.unionation.decl_node;18466 AstNode *union_decl_node = type_entry->data.unionation.decl_node;
18467 if (union_decl_node->data.container_decl.auto_enum ||18467 if (union_decl_node->data.container_decl.auto_enum ||
18468 union_decl_node->data.container_decl.init_arg_expr != nullptr)18468 union_decl_node->data.container_decl.init_arg_expr != nullptr)
18469 {18469 {
18470 ZigValue *tag_type = ira->codegen->pass1_arena->create<ZigValue>();18470 ZigValue *tag_type = g->pass1_arena->create<ZigValue>();
18471 tag_type->special = ConstValSpecialStatic;18471 tag_type->special = ConstValSpecialStatic;
18472 tag_type->type = ira->codegen->builtin_types.entry_type;18472 tag_type->type = g->builtin_types.entry_type;
18473 tag_type->data.x_type = type_entry->data.unionation.tag_type;18473 tag_type->data.x_type = type_entry->data.unionation.tag_type;
18474 fields[1]->data.x_optional = tag_type;18474 fields[1]->data.x_optional = tag_type;
18475 } else {18475 } else {
...@@ -18479,17 +18479,17 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18479,17 +18479,17 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18479 ensure_field_index(result->type, "fields", 2);18479 ensure_field_index(result->type, "fields", 2);
1848018480
18481 ZigType *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr);18481 ZigType *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr);
18482 if ((err = type_resolve(ira->codegen, type_info_union_field_type, ResolveStatusSizeKnown)))18482 if ((err = type_resolve(g, type_info_union_field_type, ResolveStatusSizeKnown)))
18483 zig_unreachable();18483 zig_unreachable();
18484 uint32_t union_field_count = type_entry->data.unionation.src_field_count;18484 uint32_t union_field_count = type_entry->data.unionation.src_field_count;
1848518485
18486 ZigValue *union_field_array = ira->codegen->pass1_arena->create<ZigValue>();18486 ZigValue *union_field_array = g->pass1_arena->create<ZigValue>();
18487 union_field_array->special = ConstValSpecialStatic;18487 union_field_array->special = ConstValSpecialStatic;
18488 union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr);18488 union_field_array->type = get_array_type(g, type_info_union_field_type, union_field_count, nullptr);
18489 union_field_array->data.x_array.special = ConstArraySpecialNone;18489 union_field_array->data.x_array.special = ConstArraySpecialNone;
18490 union_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(union_field_count);18490 union_field_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(union_field_count);
1849118491
18492 init_const_slice(ira->codegen, fields[2], union_field_array, 0, union_field_count, false, nullptr);18492 init_const_slice(g, fields[2], union_field_array, 0, union_field_count, false, nullptr);
1849318493
18494 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {18494 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {
18495 TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index];18495 TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index];
...@@ -18498,19 +18498,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18498,19 +18498,19 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18498 union_field_val->special = ConstValSpecialStatic;18498 union_field_val->special = ConstValSpecialStatic;
18499 union_field_val->type = type_info_union_field_type;18499 union_field_val->type = type_info_union_field_type;
1850018500
18501 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);18501 ZigValue **inner_fields = alloc_const_vals_ptrs(g, 3);
18502 // field_type: type18502 // field_type: type
18503 inner_fields[1]->special = ConstValSpecialStatic;18503 inner_fields[1]->special = ConstValSpecialStatic;
18504 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;18504 inner_fields[1]->type = g->builtin_types.entry_type;
18505 inner_fields[1]->data.x_type = union_field->type_entry;18505 inner_fields[1]->data.x_type = union_field->type_entry;
1850618506
18507 // alignment: comptime_int18507 // alignment: comptime_int
18508 inner_fields[2]->special = ConstValSpecialStatic;18508 inner_fields[2]->special = ConstValSpecialStatic;
18509 inner_fields[2]->type = ira->codegen->builtin_types.entry_num_lit_int;18509 inner_fields[2]->type = g->builtin_types.entry_num_lit_int;
18510 bigint_init_unsigned(&inner_fields[2]->data.x_bigint, union_field->align);18510 bigint_init_unsigned(&inner_fields[2]->data.x_bigint, union_field->align);
1851118511
18512 ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee;18512 ZigValue *name = create_const_str_lit(g, union_field->name)->data.x_ptr.data.ref.pointee;
18513 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true, nullptr);18513 init_const_slice(g, inner_fields[0], name, 0, buf_len(union_field->name), true, nullptr);
1851418514
18515 union_field_val->data.x_struct.fields = inner_fields;18515 union_field_val->data.x_struct.fields = inner_fields;
18516 union_field_val->parent.id = ConstParentIdArray;18516 union_field_val->parent.id = ConstParentIdArray;
...@@ -18536,14 +18536,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18536,14 +18536,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18536 break;18536 break;
18537 }18537 }
1853818538
18539 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown)))18539 if ((err = type_resolve(g, type_entry, ResolveStatusSizeKnown)))
18540 return err;18540 return err;
1854118541
18542 result = ira->codegen->pass1_arena->create<ZigValue>();18542 result = g->pass1_arena->create<ZigValue>();
18543 result->special = ConstValSpecialStatic;18543 result->special = ConstValSpecialStatic;
18544 result->type = ir_type_info_get_type(ira, "Struct", nullptr);18544 result->type = ir_type_info_get_type(ira, "Struct", nullptr);
1854518545
18546 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 4);18546 ZigValue **fields = alloc_const_vals_ptrs(g, 4);
18547 result->data.x_struct.fields = fields;18547 result->data.x_struct.fields = fields;
1854818548
18549 // layout: ContainerLayout18549 // layout: ContainerLayout
...@@ -18555,18 +18555,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18555,18 +18555,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18555 ensure_field_index(result->type, "fields", 1);18555 ensure_field_index(result->type, "fields", 1);
1855618556
18557 ZigType *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr);18557 ZigType *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr);
18558 if ((err = type_resolve(ira->codegen, type_info_struct_field_type, ResolveStatusSizeKnown))) {18558 if ((err = type_resolve(g, type_info_struct_field_type, ResolveStatusSizeKnown))) {
18559 zig_unreachable();18559 zig_unreachable();
18560 }18560 }
18561 uint32_t struct_field_count = type_entry->data.structure.src_field_count;18561 uint32_t struct_field_count = type_entry->data.structure.src_field_count;
1856218562
18563 ZigValue *struct_field_array = ira->codegen->pass1_arena->create<ZigValue>();18563 ZigValue *struct_field_array = g->pass1_arena->create<ZigValue>();
18564 struct_field_array->special = ConstValSpecialStatic;18564 struct_field_array->special = ConstValSpecialStatic;
18565 struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr);18565 struct_field_array->type = get_array_type(g, type_info_struct_field_type, struct_field_count, nullptr);
18566 struct_field_array->data.x_array.special = ConstArraySpecialNone;18566 struct_field_array->data.x_array.special = ConstArraySpecialNone;
18567 struct_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(struct_field_count);18567 struct_field_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(struct_field_count);
1856818568
18569 init_const_slice(ira->codegen, fields[1], struct_field_array, 0, struct_field_count, false, nullptr);18569 init_const_slice(g, fields[1], struct_field_array, 0, struct_field_count, false, nullptr);
1857018570
18571 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {18571 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {
18572 TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index];18572 TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index];
...@@ -18575,34 +18575,37 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18575,34 +18575,37 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18575 struct_field_val->special = ConstValSpecialStatic;18575 struct_field_val->special = ConstValSpecialStatic;
18576 struct_field_val->type = type_info_struct_field_type;18576 struct_field_val->type = type_info_struct_field_type;
1857718577
18578 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 5);18578 ZigValue **inner_fields = alloc_const_vals_ptrs(g, 5);
1857918579
18580 inner_fields[1]->special = ConstValSpecialStatic;18580 inner_fields[1]->special = ConstValSpecialStatic;
18581 inner_fields[1]->type = ira->codegen->builtin_types.entry_type;18581 inner_fields[1]->type = g->builtin_types.entry_type;
18582 inner_fields[1]->data.x_type = struct_field->type_entry;18582 inner_fields[1]->data.x_type = struct_field->type_entry;
1858318583
18584 // default_value: anytype18584 // default_value: ?*const anyopaque
18585 inner_fields[2]->special = ConstValSpecialStatic;18585 inner_fields[2]->special = ConstValSpecialStatic;
18586 inner_fields[2]->type = get_optional_type2(ira->codegen, struct_field->type_entry);18586 inner_fields[2]->type = g->builtin_types.entry_opt_ptr_const_anyopaque;
18587 if (inner_fields[2]->type == nullptr) return ErrorSemanticAnalyzeFail;18587 memoize_field_init_val(g, type_entry, struct_field);
18588 memoize_field_init_val(ira->codegen, type_entry, struct_field);18588 if (struct_field->init_val != nullptr &&
18589 if(struct_field->init_val != nullptr && type_is_invalid(struct_field->init_val->type)){18589 type_is_invalid(struct_field->init_val->type))
18590 {
18590 return ErrorSemanticAnalyzeFail;18591 return ErrorSemanticAnalyzeFail;
18591 }18592 }
18592 set_optional_payload(inner_fields[2], struct_field->init_val);18593 ZigValue *ptr_to_sent = (struct_field->init_val == nullptr) ? nullptr :
18594 create_const_ptr_ref(g, struct_field->init_val, true);
18595 set_optional_payload(inner_fields[2], ptr_to_sent);
1859318596
18594 // is_comptime: bool18597 // is_comptime: bool
18595 inner_fields[3]->special = ConstValSpecialStatic;18598 inner_fields[3]->special = ConstValSpecialStatic;
18596 inner_fields[3]->type = ira->codegen->builtin_types.entry_bool;18599 inner_fields[3]->type = g->builtin_types.entry_bool;
18597 inner_fields[3]->data.x_bool = struct_field->is_comptime;18600 inner_fields[3]->data.x_bool = struct_field->is_comptime;
1859818601
18599 // alignment: comptime_int18602 // alignment: comptime_int
18600 inner_fields[4]->special = ConstValSpecialStatic;18603 inner_fields[4]->special = ConstValSpecialStatic;
18601 inner_fields[4]->type = ira->codegen->builtin_types.entry_num_lit_int;18604 inner_fields[4]->type = g->builtin_types.entry_num_lit_int;
18602 bigint_init_unsigned(&inner_fields[4]->data.x_bigint, struct_field->align);18605 bigint_init_unsigned(&inner_fields[4]->data.x_bigint, struct_field->align);
1860318606
18604 ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee;18607 ZigValue *name = create_const_str_lit(g, struct_field->name)->data.x_ptr.data.ref.pointee;
18605 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true, nullptr);18608 init_const_slice(g, inner_fields[0], name, 0, buf_len(struct_field->name), true, nullptr);
1860618609
18607 struct_field_val->data.x_struct.fields = inner_fields;18610 struct_field_val->data.x_struct.fields = inner_fields;
18608 struct_field_val->parent.id = ConstParentIdArray;18611 struct_field_val->parent.id = ConstParentIdArray;
...@@ -18620,69 +18623,69 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18620,69 +18623,69 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18620 // is_tuple: bool18623 // is_tuple: bool
18621 ensure_field_index(result->type, "is_tuple", 3);18624 ensure_field_index(result->type, "is_tuple", 3);
18622 fields[3]->special = ConstValSpecialStatic;18625 fields[3]->special = ConstValSpecialStatic;
18623 fields[3]->type = ira->codegen->builtin_types.entry_bool;18626 fields[3]->type = g->builtin_types.entry_bool;
18624 fields[3]->data.x_bool = is_tuple(type_entry);18627 fields[3]->data.x_bool = is_tuple(type_entry);
1862518628
18626 break;18629 break;
18627 }18630 }
18628 case ZigTypeIdFn:18631 case ZigTypeIdFn:
18629 {18632 {
18630 result = ira->codegen->pass1_arena->create<ZigValue>();18633 result = g->pass1_arena->create<ZigValue>();
18631 result->special = ConstValSpecialStatic;18634 result->special = ConstValSpecialStatic;
18632 result->type = ir_type_info_get_type(ira, "Fn", nullptr);18635 result->type = ir_type_info_get_type(ira, "Fn", nullptr);
1863318636
18634 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 7);18637 ZigValue **fields = alloc_const_vals_ptrs(g, 7);
18635 result->data.x_struct.fields = fields;18638 result->data.x_struct.fields = fields;
1863618639
18637 // calling_convention: TypeInfo.CallingConvention18640 // calling_convention: TypeInfo.CallingConvention
18638 ensure_field_index(result->type, "calling_convention", 0);18641 ensure_field_index(result->type, "calling_convention", 0);
18639 fields[0]->special = ConstValSpecialStatic;18642 fields[0]->special = ConstValSpecialStatic;
18640 fields[0]->type = get_builtin_type(ira->codegen, "CallingConvention");18643 fields[0]->type = get_builtin_type(g, "CallingConvention");
18641 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc);18644 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc);
18642 // alignment: comptime_int18645 // alignment: comptime_int
18643 ensure_field_index(result->type, "alignment", 1);18646 ensure_field_index(result->type, "alignment", 1);
18644 fields[1]->special = ConstValSpecialStatic;18647 fields[1]->special = ConstValSpecialStatic;
18645 fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;18648 fields[1]->type = g->builtin_types.entry_num_lit_int;
18646 bigint_init_unsigned(&fields[1]->data.x_bigint, get_ptr_align(ira->codegen, type_entry));18649 bigint_init_unsigned(&fields[1]->data.x_bigint, get_ptr_align(g, type_entry));
18647 // is_generic: bool18650 // is_generic: bool
18648 ensure_field_index(result->type, "is_generic", 2);18651 ensure_field_index(result->type, "is_generic", 2);
18649 bool is_generic = type_entry->data.fn.is_generic;18652 bool is_generic = type_entry->data.fn.is_generic;
18650 fields[2]->special = ConstValSpecialStatic;18653 fields[2]->special = ConstValSpecialStatic;
18651 fields[2]->type = ira->codegen->builtin_types.entry_bool;18654 fields[2]->type = g->builtin_types.entry_bool;
18652 fields[2]->data.x_bool = is_generic;18655 fields[2]->data.x_bool = is_generic;
18653 // is_varargs: bool18656 // is_varargs: bool
18654 ensure_field_index(result->type, "is_var_args", 3);18657 ensure_field_index(result->type, "is_var_args", 3);
18655 bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args;18658 bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args;
18656 fields[3]->special = ConstValSpecialStatic;18659 fields[3]->special = ConstValSpecialStatic;
18657 fields[3]->type = ira->codegen->builtin_types.entry_bool;18660 fields[3]->type = g->builtin_types.entry_bool;
18658 fields[3]->data.x_bool = is_varargs;18661 fields[3]->data.x_bool = is_varargs;
18659 // return_type: ?type18662 // return_type: ?type
18660 ensure_field_index(result->type, "return_type", 4);18663 ensure_field_index(result->type, "return_type", 4);
18661 fields[4]->special = ConstValSpecialStatic;18664 fields[4]->special = ConstValSpecialStatic;
18662 fields[4]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);18665 fields[4]->type = get_optional_type(g, g->builtin_types.entry_type);
18663 if (type_entry->data.fn.fn_type_id.return_type == nullptr)18666 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
18664 fields[4]->data.x_optional = nullptr;18667 fields[4]->data.x_optional = nullptr;
18665 else {18668 else {
18666 ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>();18669 ZigValue *return_type = g->pass1_arena->create<ZigValue>();
18667 return_type->special = ConstValSpecialStatic;18670 return_type->special = ConstValSpecialStatic;
18668 return_type->type = ira->codegen->builtin_types.entry_type;18671 return_type->type = g->builtin_types.entry_type;
18669 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;18672 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
18670 fields[4]->data.x_optional = return_type;18673 fields[4]->data.x_optional = return_type;
18671 }18674 }
18672 // args: []TypeInfo.FnArg18675 // args: []TypeInfo.FnArg
18673 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);18676 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
18674 if ((err = type_resolve(ira->codegen, type_info_fn_arg_type, ResolveStatusSizeKnown))) {18677 if ((err = type_resolve(g, type_info_fn_arg_type, ResolveStatusSizeKnown))) {
18675 zig_unreachable();18678 zig_unreachable();
18676 }18679 }
18677 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count;18680 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count;
1867818681
18679 ZigValue *fn_arg_array = ira->codegen->pass1_arena->create<ZigValue>();18682 ZigValue *fn_arg_array = g->pass1_arena->create<ZigValue>();
18680 fn_arg_array->special = ConstValSpecialStatic;18683 fn_arg_array->special = ConstValSpecialStatic;
18681 fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr);18684 fn_arg_array->type = get_array_type(g, type_info_fn_arg_type, fn_arg_count, nullptr);
18682 fn_arg_array->data.x_array.special = ConstArraySpecialNone;18685 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
18683 fn_arg_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count);18686 fn_arg_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(fn_arg_count);
1868418687
18685 init_const_slice(ira->codegen, fields[5], fn_arg_array, 0, fn_arg_count, false, nullptr);18688 init_const_slice(g, fields[5], fn_arg_array, 0, fn_arg_count, false, nullptr);
1868618689
18687 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {18690 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
18688 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];18691 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];
...@@ -18694,22 +18697,22 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18694,22 +18697,22 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18694 bool arg_is_generic = fn_param_info->type == nullptr;18697 bool arg_is_generic = fn_param_info->type == nullptr;
18695 if (arg_is_generic) assert(is_generic);18698 if (arg_is_generic) assert(is_generic);
1869618699
18697 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);18700 ZigValue **inner_fields = alloc_const_vals_ptrs(g, 3);
18698 inner_fields[0]->special = ConstValSpecialStatic;18701 inner_fields[0]->special = ConstValSpecialStatic;
18699 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;18702 inner_fields[0]->type = g->builtin_types.entry_bool;
18700 inner_fields[0]->data.x_bool = arg_is_generic;18703 inner_fields[0]->data.x_bool = arg_is_generic;
18701 inner_fields[1]->special = ConstValSpecialStatic;18704 inner_fields[1]->special = ConstValSpecialStatic;
18702 inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;18705 inner_fields[1]->type = g->builtin_types.entry_bool;
18703 inner_fields[1]->data.x_bool = fn_param_info->is_noalias;18706 inner_fields[1]->data.x_bool = fn_param_info->is_noalias;
18704 inner_fields[2]->special = ConstValSpecialStatic;18707 inner_fields[2]->special = ConstValSpecialStatic;
18705 inner_fields[2]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);18708 inner_fields[2]->type = get_optional_type(g, g->builtin_types.entry_type);
1870618709
18707 if (arg_is_generic)18710 if (arg_is_generic)
18708 inner_fields[2]->data.x_optional = nullptr;18711 inner_fields[2]->data.x_optional = nullptr;
18709 else {18712 else {
18710 ZigValue *arg_type = ira->codegen->pass1_arena->create<ZigValue>();18713 ZigValue *arg_type = g->pass1_arena->create<ZigValue>();
18711 arg_type->special = ConstValSpecialStatic;18714 arg_type->special = ConstValSpecialStatic;
18712 arg_type->type = ira->codegen->builtin_types.entry_type;18715 arg_type->type = g->builtin_types.entry_type;
18713 arg_type->data.x_type = fn_param_info->type;18716 arg_type->data.x_type = fn_param_info->type;
18714 inner_fields[2]->data.x_optional = arg_type;18717 inner_fields[2]->data.x_optional = arg_type;
18715 }18718 }
...@@ -18733,11 +18736,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18733,11 +18736,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18733 }18736 }
18734 case ZigTypeIdOpaque:18737 case ZigTypeIdOpaque:
18735 {18738 {
18736 result = ira->codegen->pass1_arena->create<ZigValue>();18739 result = g->pass1_arena->create<ZigValue>();
18737 result->special = ConstValSpecialStatic;18740 result->special = ConstValSpecialStatic;
18738 result->type = ir_type_info_get_type(ira, "Opaque", nullptr);18741 result->type = ir_type_info_get_type(ira, "Opaque", nullptr);
1873918742
18740 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);18743 ZigValue **fields = alloc_const_vals_ptrs(g, 1);
18741 result->data.x_struct.fields = fields;18744 result->data.x_struct.fields = fields;
1874218745
18743 // decls: []TypeInfo.Declaration18746 // decls: []TypeInfo.Declaration
...@@ -18752,21 +18755,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18752,21 +18755,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18752 }18755 }
18753 case ZigTypeIdFnFrame:18756 case ZigTypeIdFnFrame:
18754 {18757 {
18755 result = ira->codegen->pass1_arena->create<ZigValue>();18758 result = g->pass1_arena->create<ZigValue>();
18756 result->special = ConstValSpecialStatic;18759 result->special = ConstValSpecialStatic;
18757 result->type = ir_type_info_get_type(ira, "Frame", nullptr);18760 result->type = ir_type_info_get_type(ira, "Frame", nullptr);
18758 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);18761 ZigValue **fields = alloc_const_vals_ptrs(g, 1);
18759 result->data.x_struct.fields = fields;18762 result->data.x_struct.fields = fields;
18760 ZigFn *fn = type_entry->data.frame.fn;18763 ZigFn *fn = type_entry->data.frame.fn;
18761 // function: anytype18764 // function: ?*const anyopaque
18762 ensure_field_index(result->type, "function", 0);18765 ensure_field_index(result->type, "function", 0);
18763 fields[0] = create_const_fn(ira->codegen, fn);18766 fields[0]->special = ConstValSpecialStatic;
18767 fields[0]->type = get_pointer_to_type(g, g->builtin_types.entry_anyopaque, true);
18768 fields[0]->data.x_ptr.special = ConstPtrSpecialFunction;
18769 fields[0]->data.x_ptr.data.fn.fn_entry = fn;
18764 break;18770 break;
18765 }18771 }
18766 }18772 }
1876718773
18768 assert(result != nullptr);18774 assert(result != nullptr);
18769 ira->codegen->type_info_cache.put(type_entry, result);18775 g->type_info_cache.put(type_entry, result);
18770 *out = result;18776 *out = result;
18771 return ErrorNone;18777 return ErrorNone;
18772}18778}
...@@ -18810,26 +18816,25 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue...@@ -18810,26 +18816,25 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue
18810 return val;18816 return val;
18811}18817}
1881218818
18813static Error get_const_field_sentinel(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *struct_value,18819static Error get_const_field_sentinel(IrAnalyze *ira, Scope *scope, AstNode *source_node,
18814 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)18820 ZigValue *struct_value, const char *name, size_t field_index, ZigType *elem_type,
18821 ZigValue **result)
18815{18822{
18816 ZigValue *field_val = get_const_field(ira, source_node, struct_value, name, field_index);18823 ZigValue *field_val = get_const_field(ira, source_node, struct_value, name, field_index);
18817 if (field_val == nullptr)18824 if (field_val == nullptr)
18818 return ErrorSemanticAnalyzeFail;18825 return ErrorSemanticAnalyzeFail;
1881918826
18820 Stage1AirInst *field_inst = ir_const_move(ira, scope, source_node, field_val);18827 // type of `field_val` is `?*const anyopaque`.
18821 Stage1AirInst *casted_field_inst = ir_implicit_cast(ira, field_inst,18828 if (field_val->data.x_ptr.special == ConstPtrSpecialNull) {
18822 get_optional_type(ira->codegen, elem_type));
18823 if (type_is_invalid(casted_field_inst->value->type))
18824 return ErrorSemanticAnalyzeFail;
18825
18826 if (optional_value_is_null(casted_field_inst->value)) {
18827 *result = nullptr;18829 *result = nullptr;
18828 } else {18830 return ErrorNone;
18829 assert(type_has_optional_repr(casted_field_inst->value->type));
18830 *result = casted_field_inst->value->data.x_optional;
18831 }18831 }
1883218832
18833 ZigValue *pointee = const_ptr_pointee_unchecked_no_isf(ira->codegen, field_val);
18834 if (pointee == nullptr)
18835 return ErrorSemanticAnalyzeFail;
18836
18837 *result = pointee;
18833 return ErrorNone;18838 return ErrorNone;
18834}18839}
1883518840
...@@ -19043,6 +19048,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_...@@ -19043,6 +19048,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
19043 return ira->codegen->invalid_inst_gen->value->type;19048 return ira->codegen->invalid_inst_gen->value->type;
19044 }19049 }
1904519050
19051 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusAlignmentKnown))) {
19052 return ira->codegen->invalid_inst_gen->value->type;
19053 }
19054
19046 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,19055 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,
19047 elem_type,19056 elem_type,
19048 is_const,19057 is_const,
...@@ -19140,15 +19149,9 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_...@@ -19140,15 +19149,9 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
19140 return get_any_frame_type(ira->codegen, child_type);19149 return get_any_frame_type(ira->codegen, child_type);
19141 }19150 }
19142 case ZigTypeIdFnFrame: {19151 case ZigTypeIdFnFrame: {
19143 assert(payload->special == ConstValSpecialStatic);19152 ir_add_error_node(ira, source_node,
19144 assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr));19153 buf_sprintf("use the @Frame builtin instead of @Type"));
19145 ZigValue *function = get_const_field(ira, source_node, payload, "function", 0);19154 return ira->codegen->invalid_inst_gen->value->type;
19146 if (function == nullptr)
19147 return ira->codegen->invalid_inst_gen->value->type;
19148
19149 assert(function->type->id == ZigTypeIdFn);
19150 ZigFn *fn = function->data.x_ptr.data.fn.fn_entry;
19151 return get_fn_frame_type(ira->codegen, fn);
19152 }19155 }
19153 case ZigTypeIdErrorSet: {19156 case ZigTypeIdErrorSet: {
19154 assert(payload->special == ConstValSpecialStatic);19157 assert(payload->special == ConstValSpecialStatic);
...@@ -19276,19 +19279,17 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_...@@ -19276,19 +19279,17 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
19276 ZigValue *default_value = get_const_field(ira, source_node, field_value, "default_value", 2);19279 ZigValue *default_value = get_const_field(ira, source_node, field_value, "default_value", 2);
19277 if (default_value == nullptr)19280 if (default_value == nullptr)
19278 return ira->codegen->invalid_inst_gen->value->type;19281 return ira->codegen->invalid_inst_gen->value->type;
19279 if (default_value->type->id == ZigTypeIdNull) {19282
19283 // type of `default_value` is `?*const anyopaque`.
19284 if (default_value->data.x_ptr.special == ConstPtrSpecialNull) {
19280 field->init_val = nullptr;19285 field->init_val = nullptr;
19281 } else if (default_value->type->id == ZigTypeIdOptional && default_value->type->data.maybe.child_type == field->type_entry) {
19282 field->init_val = default_value->data.x_optional;
19283 } else if (default_value->type == field->type_entry) {
19284 field->init_val = default_value;
19285 } else {19286 } else {
19286 ir_add_error_node(ira, source_node,19287 ZigValue *pointee = const_ptr_pointee_unchecked_no_isf(ira->codegen, default_value);
19287 buf_sprintf("default_value of field '%s' is of type '%s', expected '%s' or '?%s'",19288 if (pointee == nullptr)
19288 buf_ptr(field->name), buf_ptr(&default_value->type->name),19289 return ira->codegen->invalid_inst_gen->value->type;
19289 buf_ptr(&field->type_entry->name), buf_ptr(&field->type_entry->name)));19290 field->init_val = pointee;
19290 return ira->codegen->invalid_inst_gen->value->type;
19291 }19291 }
19292
19292 if ((err = get_const_field_bool(ira, source_node, field_value, "is_comptime", 3, &field->is_comptime)))19293 if ((err = get_const_field_bool(ira, source_node, field_value, "is_comptime", 3, &field->is_comptime)))
19293 return ira->codegen->invalid_inst_gen->value->type;19294 return ira->codegen->invalid_inst_gen->value->type;
19294 BigInt *alignment = get_const_field_lit_int(ira, source_node, field_value, "alignment", 4);19295 BigInt *alignment = get_const_field_lit_int(ira, source_node, field_value, "alignment", 4);
test/behavior/struct_llvm.zig-15
...@@ -618,21 +618,6 @@ test "anonymous struct literal assigned to variable" {...@@ -618,21 +618,6 @@ test "anonymous struct literal assigned to variable" {
618 try expect(vec.@"2" == 99);618 try expect(vec.@"2" == 99);
619}619}
620620
621test "struct with var field" {
622 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
623
624 const Point = struct {
625 x: anytype,
626 y: anytype,
627 };
628 const pt = Point{
629 .x = 1,
630 .y = 2,
631 };
632 try expect(pt.x == 1);
633 try expect(pt.y == 2);
634}
635
636test "comptime struct field" {621test "comptime struct field" {
637 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO622 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
638623
test/behavior/type_info.zig+6-13
...@@ -119,7 +119,7 @@ fn testNullTerminatedPtr() !void {...@@ -119,7 +119,7 @@ fn testNullTerminatedPtr() !void {
119 try expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);119 try expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
120 try expect(ptr_info.Pointer.is_const == false);120 try expect(ptr_info.Pointer.is_const == false);
121 try expect(ptr_info.Pointer.is_volatile == false);121 try expect(ptr_info.Pointer.is_volatile == false);
122 try expect(ptr_info.Pointer.sentinel.? == 0);122 try expect(@ptrCast(*const u8, ptr_info.Pointer.sentinel.?).* == 0);
123123
124 try expect(@typeInfo([:0]u8).Pointer.sentinel != null);124 try expect(@typeInfo([:0]u8).Pointer.sentinel != null);
125}125}
...@@ -161,7 +161,7 @@ fn testArray() !void {...@@ -161,7 +161,7 @@ fn testArray() !void {
161 const info = @typeInfo([10:0]u8);161 const info = @typeInfo([10:0]u8);
162 try expect(info.Array.len == 10);162 try expect(info.Array.len == 10);
163 try expect(info.Array.child == u8);163 try expect(info.Array.child == u8);
164 try expect(info.Array.sentinel.? == @as(u8, 0));164 try expect(@ptrCast(*const u8, info.Array.sentinel.?).* == @as(u8, 0));
165 try expect(@sizeOf([10:0]u8) == info.Array.len + 1);165 try expect(@sizeOf([10:0]u8) == info.Array.len + 1);
166 }166 }
167}167}
...@@ -271,8 +271,8 @@ fn testStruct() !void {...@@ -271,8 +271,8 @@ fn testStruct() !void {
271 const unpacked_struct_info = @typeInfo(TestUnpackedStruct);271 const unpacked_struct_info = @typeInfo(TestUnpackedStruct);
272 try expect(unpacked_struct_info.Struct.is_tuple == false);272 try expect(unpacked_struct_info.Struct.is_tuple == false);
273 try expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));273 try expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
274 try expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4);274 try expect(@ptrCast(*const u32, unpacked_struct_info.Struct.fields[0].default_value.?).* == 4);
275 try expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?);275 try expectEqualStrings("foobar", @ptrCast(*const *const [6:0]u8, unpacked_struct_info.Struct.fields[1].default_value.?).*);
276276
277 const struct_info = @typeInfo(TestStruct);277 const struct_info = @typeInfo(TestStruct);
278 try expect(struct_info == .Struct);278 try expect(struct_info == .Struct);
...@@ -282,7 +282,7 @@ fn testStruct() !void {...@@ -282,7 +282,7 @@ fn testStruct() !void {
282 try expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));282 try expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
283 try expect(struct_info.Struct.fields[2].field_type == *TestStruct);283 try expect(struct_info.Struct.fields[2].field_type == *TestStruct);
284 try expect(struct_info.Struct.fields[2].default_value == null);284 try expect(struct_info.Struct.fields[2].default_value == null);
285 try expect(struct_info.Struct.fields[3].default_value.? == 4);285 try expect(@ptrCast(*const u32, struct_info.Struct.fields[3].default_value.?).* == 4);
286 try expect(struct_info.Struct.fields[3].alignment == 1);286 try expect(struct_info.Struct.fields[3].alignment == 1);
287 try expect(struct_info.Struct.decls.len == 2);287 try expect(struct_info.Struct.decls.len == 2);
288 try expect(struct_info.Struct.decls[0].is_pub);288 try expect(struct_info.Struct.decls[0].is_pub);
...@@ -436,13 +436,6 @@ test "@typeInfo does not force declarations into existence" {...@@ -436,13 +436,6 @@ test "@typeInfo does not force declarations into existence" {
436 comptime try expect(@typeInfo(S).Struct.fields.len == 1);436 comptime try expect(@typeInfo(S).Struct.fields.len == 1);
437}437}
438438
439test "default value for a anytype field" {
440 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
441
442 const S = struct { x: anytype };
443 try expect(@typeInfo(S).Struct.fields[0].default_value == null);
444}
445
446fn add(a: i32, b: i32) i32 {439fn add(a: i32, b: i32) i32 {
447 return a + b;440 return a + b;
448}441}
...@@ -452,7 +445,7 @@ test "type info for async frames" {...@@ -452,7 +445,7 @@ test "type info for async frames" {
452445
453 switch (@typeInfo(@Frame(add))) {446 switch (@typeInfo(@Frame(add))) {
454 .Frame => |frame| {447 .Frame => |frame| {
455 try expect(frame.function == add);448 try expect(@ptrCast(@TypeOf(add), frame.function) == add);
456 },449 },
457 else => unreachable,450 else => unreachable,
458 }451 }
test/behavior/type_stage1.zig+7-13
...@@ -37,7 +37,7 @@ test "Type.Array" {...@@ -37,7 +37,7 @@ test "Type.Array" {
37 .Array = TypeInfo.Array{37 .Array = TypeInfo.Array{
38 .len = 2,38 .len = 2,
39 .child = u32,39 .child = u32,
40 .sentinel = 0,40 .sentinel = &@as(u32, 0),
41 },41 },
42 }));42 }));
43 try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });43 try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
...@@ -141,12 +141,6 @@ fn add(a: i32, b: i32) i32 {...@@ -141,12 +141,6 @@ fn add(a: i32, b: i32) i32 {
141 return a + b;141 return a + b;
142}142}
143143
144test "Type.Frame" {
145 try testTypes(&[_]type{
146 @Frame(add),
147 });
148}
149
150test "Type.ErrorSet" {144test "Type.ErrorSet" {
151 // error sets don't compare equal so just check if they compile145 // error sets don't compare equal so just check if they compile
152 _ = @Type(@typeInfo(error{}));146 _ = @Type(@typeInfo(error{}));
...@@ -160,10 +154,10 @@ test "Type.Struct" {...@@ -160,10 +154,10 @@ test "Type.Struct" {
160 try testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout);154 try testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout);
161 try testing.expectEqualSlices(u8, "x", infoA.fields[0].name);155 try testing.expectEqualSlices(u8, "x", infoA.fields[0].name);
162 try testing.expectEqual(u8, infoA.fields[0].field_type);156 try testing.expectEqual(u8, infoA.fields[0].field_type);
163 try testing.expectEqual(@as(?u8, null), infoA.fields[0].default_value);157 try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value);
164 try testing.expectEqualSlices(u8, "y", infoA.fields[1].name);158 try testing.expectEqualSlices(u8, "y", infoA.fields[1].name);
165 try testing.expectEqual(u32, infoA.fields[1].field_type);159 try testing.expectEqual(u32, infoA.fields[1].field_type);
166 try testing.expectEqual(@as(?u32, null), infoA.fields[1].default_value);160 try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value);
167 try testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls);161 try testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls);
168 try testing.expectEqual(@as(bool, false), infoA.is_tuple);162 try testing.expectEqual(@as(bool, false), infoA.is_tuple);
169163
...@@ -178,10 +172,10 @@ test "Type.Struct" {...@@ -178,10 +172,10 @@ test "Type.Struct" {
178 try testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout);172 try testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout);
179 try testing.expectEqualSlices(u8, "x", infoB.fields[0].name);173 try testing.expectEqualSlices(u8, "x", infoB.fields[0].name);
180 try testing.expectEqual(u8, infoB.fields[0].field_type);174 try testing.expectEqual(u8, infoB.fields[0].field_type);
181 try testing.expectEqual(@as(?u8, null), infoB.fields[0].default_value);175 try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value);
182 try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);176 try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
183 try testing.expectEqual(u32, infoB.fields[1].field_type);177 try testing.expectEqual(u32, infoB.fields[1].field_type);
184 try testing.expectEqual(@as(?u32, 5), infoB.fields[1].default_value);178 try testing.expectEqual(@as(u32, 5), @ptrCast(*const u32, infoB.fields[1].default_value.?).*);
185 try testing.expectEqual(@as(usize, 0), infoB.decls.len);179 try testing.expectEqual(@as(usize, 0), infoB.decls.len);
186 try testing.expectEqual(@as(bool, false), infoB.is_tuple);180 try testing.expectEqual(@as(bool, false), infoB.is_tuple);
187181
...@@ -190,10 +184,10 @@ test "Type.Struct" {...@@ -190,10 +184,10 @@ test "Type.Struct" {
190 try testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout);184 try testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout);
191 try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);185 try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
192 try testing.expectEqual(u8, infoC.fields[0].field_type);186 try testing.expectEqual(u8, infoC.fields[0].field_type);
193 try testing.expectEqual(@as(?u8, 3), infoC.fields[0].default_value);187 try testing.expectEqual(@as(u8, 3), @ptrCast(*const u8, infoC.fields[0].default_value.?).*);
194 try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);188 try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
195 try testing.expectEqual(u32, infoC.fields[1].field_type);189 try testing.expectEqual(u32, infoC.fields[1].field_type);
196 try testing.expectEqual(@as(?u32, 5), infoC.fields[1].default_value);190 try testing.expectEqual(@as(u32, 5), @ptrCast(*const u32, infoC.fields[1].default_value.?).*);
197 try testing.expectEqual(@as(usize, 0), infoC.decls.len);191 try testing.expectEqual(@as(usize, 0), infoC.decls.len);
198 try testing.expectEqual(@as(bool, false), infoC.is_tuple);192 try testing.expectEqual(@as(bool, false), infoC.is_tuple);
199}193}
test/behavior/union_stage1.zig-5
...@@ -419,8 +419,3 @@ test "union enum type gets a separate scope" {...@@ -419,8 +419,3 @@ test "union enum type gets a separate scope" {
419419
420 try S.doTheTest();420 try S.doTheTest();
421}421}
422
423test "anytype union field: issue #9233" {
424 const Quux = union(enum) { bar: anytype };
425 _ = Quux;
426}
test/compile_errors.zig+1-11
...@@ -744,7 +744,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -744,7 +744,7 @@ pub fn addCases(ctx: *TestContext) !void {
744 \\ .address_space = .generic,744 \\ .address_space = .generic,
745 \\ .child = u8,745 \\ .child = u8,
746 \\ .is_allowzero = false,746 \\ .is_allowzero = false,
747 \\ .sentinel = 0,747 \\ .sentinel = &@as(u8, 0),
748 \\ }});748 \\ }});
749 \\}749 \\}
750 , &[_][]const u8{750 , &[_][]const u8{
...@@ -4207,16 +4207,6 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -4207,16 +4207,6 @@ pub fn addCases(ctx: *TestContext) !void {
4207 "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'",4207 "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'",
4208 });4208 });
42094209
4210 ctx.objErrStage1("var makes structs required to be comptime known",
4211 \\export fn entry() void {
4212 \\ const S = struct{v: anytype};
4213 \\ var s = S{.v=@as(i32, 10)};
4214 \\ _ = s;
4215 \\}
4216 , &[_][]const u8{
4217 "tmp.zig:3:4: error: variable of type 'S' must be const or comptime",
4218 });
4219
4220 ctx.objErrStage1("@ptrCast discards const qualifier",4210 ctx.objErrStage1("@ptrCast discards const qualifier",
4221 \\export fn entry() void {4211 \\export fn entry() void {
4222 \\ const x: i32 = 1234;4212 \\ const x: i32 = 1234;