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) {
226226 child: type,
227227 is_allowzero: bool,
228228
229 /// This field is an optional type.
230229 /// The type of the sentinel is the element type of the pointer, which is
231230 /// 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`.
233 sentinel: anytype,
231 /// to refer to that type here, so we use pointer to `anyopaque`.
232 sentinel: ?*const anyopaque,
234233
235234 /// This data structure is used by the Zig language code generation and
236235 /// therefore must be kept in sync with the compiler implementation.
......@@ -248,11 +247,10 @@ pub const TypeInfo = union(enum) {
248247 len: comptime_int,
249248 child: type,
250249
251 /// This field is an optional type.
252250 /// The type of the sentinel is the element type of the array, which is
253251 /// 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`.
255 sentinel: anytype,
252 /// to refer to that type here, so we use pointer to `anyopaque`.
253 sentinel: ?*const anyopaque,
256254 };
257255
258256 /// This data structure is used by the Zig language code generation and
......@@ -267,8 +265,9 @@ pub const TypeInfo = union(enum) {
267265 /// therefore must be kept in sync with the compiler implementation.
268266 pub const StructField = struct {
269267 name: []const u8,
268 /// TODO rename to `type`
270269 field_type: type,
271 default_value: anytype,
270 default_value: ?*const anyopaque,
272271 is_comptime: bool,
273272 alignment: comptime_int,
274273 };
......@@ -369,7 +368,7 @@ pub const TypeInfo = union(enum) {
369368 /// This data structure is used by the Zig language code generation and
370369 /// therefore must be kept in sync with the compiler implementation.
371370 pub const Frame = struct {
372 function: anytype,
371 function: *const anyopaque,
373372 };
374373
375374 /// 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 {
297297}
298298
299299const CryptoPwhash = struct {
300 hashFn: anytype,
301 params: anytype,
300 hashFn: @compileError("anytype fields are removed from the language"),
301 params: @compileError("anytype fields are removed from the language"),
302302 name: []const u8,
303303};
304304const 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
1616 fields = fields ++ &[_]StructField{.{
1717 .name = field.name,
1818 .field_type = Data,
19 .default_value = field_default,
19 .default_value = if (field_default) |d| &d else null,
2020 .is_comptime = false,
2121 .alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,
2222 }};
lib/std/json.zig+2-1
......@@ -1791,8 +1791,9 @@ fn parseInternal(
17911791 }
17921792 inline for (structInfo.fields) |field, i| {
17931793 if (!fields_seen[i]) {
1794 if (field.default_value) |default| {
1794 if (field.default_value) |default_ptr| {
17951795 if (!field.is_comptime) {
1796 const default = @ptrCast(*const field.field_type, default_ptr).*;
17961797 @field(r, field.name) = default;
17971798 }
17981799 } else {
lib/std/mem.zig+35-18
......@@ -296,7 +296,8 @@ pub fn zeroes(comptime T: type) T {
296296 }
297297 },
298298 .Array => |info| {
299 if (info.sentinel) |sentinel| {
299 if (info.sentinel) |sentinel_ptr| {
300 const sentinel = @ptrCast(*const info.child, sentinel_ptr).*;
300301 return [_:sentinel]info.child{zeroes(info.child)} ** info.len;
301302 }
302303 return [_]info.child{zeroes(info.child)} ** info.len;
......@@ -453,7 +454,8 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
453454 @field(value, field.name) = @field(init, field.name);
454455 },
455456 }
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).*;
457459 @field(value, field.name) = default_value;
458460 }
459461 }
......@@ -599,7 +601,7 @@ pub fn Span(comptime T: type) type {
599601 else => @compileError("invalid type given to std.mem.Span"),
600602 },
601603 .C => {
602 new_ptr_info.sentinel = 0;
604 new_ptr_info.sentinel = &@as(ptr_info.child, 0);
603605 new_ptr_info.is_allowzero = false;
604606 },
605607 .Many, .Slice => {},
......@@ -651,7 +653,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
651653 }
652654 const Result = Span(@TypeOf(ptr));
653655 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).*;
655659 return ptr[0..l :s];
656660 } else {
657661 return ptr[0..l];
......@@ -684,9 +688,10 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
684688 // The return type must only be sentinel terminated if we are guaranteed
685689 // to find the value searched for, which is only the case if it matches
686690 // 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).*;
688693 if (end == sentinel) {
689 new_ptr_info.sentinel = end;
694 new_ptr_info.sentinel = &end;
690695 } else {
691696 new_ptr_info.sentinel = null;
692697 }
......@@ -698,16 +703,17 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
698703 // The return type must only be sentinel terminated if we are guaranteed
699704 // to find the value searched for, which is only the case if it matches
700705 // 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).*;
702708 if (end == sentinel) {
703 new_ptr_info.sentinel = end;
709 new_ptr_info.sentinel = &end;
704710 } else {
705711 new_ptr_info.sentinel = null;
706712 }
707713 }
708714 },
709715 .C => {
710 new_ptr_info.sentinel = end;
716 new_ptr_info.sentinel = &end;
711717 // C pointers are always allowzero, but we don't want the return type to be.
712718 assert(new_ptr_info.is_allowzero);
713719 new_ptr_info.is_allowzero = false;
......@@ -734,7 +740,9 @@ pub fn sliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) SliceTo(@Typ
734740 }
735741 const Result = SliceTo(@TypeOf(ptr), end);
736742 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).*;
738746 return ptr[0..length :s];
739747 } else {
740748 return ptr[0..length];
......@@ -786,7 +794,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
786794 .Pointer => |ptr_info| switch (ptr_info.size) {
787795 .One => switch (@typeInfo(ptr_info.child)) {
788796 .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).*;
790799 if (sentinel == end) {
791800 return indexOfSentinel(array_info.child, end, ptr);
792801 }
......@@ -795,7 +804,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
795804 },
796805 else => {},
797806 },
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).*;
799809 // We may be looking for something other than the sentinel,
800810 // but iterating past the sentinel would be a bug so we need
801811 // to check for both.
......@@ -808,7 +818,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
808818 return indexOfSentinel(ptr_info.child, end, ptr);
809819 },
810820 .Slice => {
811 if (ptr_info.sentinel) |sentinel| {
821 if (ptr_info.sentinel) |sentinel_ptr| {
822 const sentinel = @ptrCast(*const ptr_info.child, sentinel_ptr).*;
812823 if (sentinel == end) {
813824 return indexOfSentinel(ptr_info.child, sentinel, ptr);
814825 }
......@@ -867,10 +878,12 @@ pub fn len(value: anytype) usize {
867878 .Array => value.len,
868879 else => @compileError("invalid type given to std.mem.len"),
869880 },
870 .Many => if (info.sentinel) |sentinel|
871 indexOfSentinel(info.child, sentinel, value)
872 else
873 @compileError("length of pointer with no sentinel"),
881 .Many => {
882 const sentinel_ptr = info.sentinel orelse
883 @compileError("length of pointer with no sentinel");
884 const sentinel = @ptrCast(*const info.child, sentinel_ptr).*;
885 return indexOfSentinel(info.child, sentinel, value);
886 },
874887 .C => {
875888 assert(value != null);
876889 return indexOfSentinel(info.child, 0, value);
......@@ -2572,7 +2585,11 @@ test "alignPointer" {
25722585 try S.checkAlign([*]u32, math.maxInt(usize) - 3, 8, 0);
25732586}
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 {
25762593 const info = @typeInfo(source).Pointer;
25772594 return @Type(.{
25782595 .Pointer = .{
lib/std/meta.zig+15-6
......@@ -190,12 +190,21 @@ test "std.meta.Elem" {
190190/// Types which cannot possibly have a sentinel will be a compile error.
191191pub fn sentinel(comptime T: type) ?Elem(T) {
192192 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 },
194197 .Pointer => |info| {
195198 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 },
197203 .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 },
199208 else => {},
200209 },
201210 else => {},
......@@ -239,7 +248,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
239248 .Array = .{
240249 .len = array_info.len,
241250 .child = array_info.child,
242 .sentinel = sentinel_val,
251 .sentinel = &sentinel_val,
243252 },
244253 }),
245254 .is_allowzero = info.is_allowzero,
......@@ -257,7 +266,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
257266 .address_space = info.address_space,
258267 .child = info.child,
259268 .is_allowzero = info.is_allowzero,
260 .sentinel = sentinel_val,
269 .sentinel = &sentinel_val,
261270 },
262271 }),
263272 else => {},
......@@ -275,7 +284,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
275284 .address_space = ptr_info.address_space,
276285 .child = ptr_info.child,
277286 .is_allowzero = ptr_info.is_allowzero,
278 .sentinel = sentinel_val,
287 .sentinel = &sentinel_val,
279288 },
280289 }),
281290 },
lib/std/zig/Ast.zig-5
......@@ -366,7 +366,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex {
366366 .builtin_call,
367367 .builtin_call_comma,
368368 .error_set_decl,
369 .@"anytype",
370369 .@"comptime",
371370 .@"nosuspend",
372371 .asm_simple,
......@@ -729,7 +728,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
729728 .error_value,
730729 => return datas[n].rhs + end_offset,
731730
732 .@"anytype",
733731 .anyframe_literal,
734732 .char_literal,
735733 .integer_literal,
......@@ -2935,9 +2933,6 @@ pub const Node = struct {
29352933 /// main_token is the field name identifier.
29362934 /// lastToken() does not include the possible trailing comma.
29372935 container_field,
2938 /// `anytype`. both lhs and rhs unused.
2939 /// Used by `ContainerField`.
2940 @"anytype",
29412936 /// `comptime lhs`. rhs unused.
29422937 @"comptime",
29432938 /// `nosuspend lhs`. rhs unused.
lib/std/zig/parse.zig+2-13
......@@ -786,19 +786,8 @@ const Parser = struct {
786786 var align_expr: Node.Index = 0;
787787 var type_expr: Node.Index = 0;
788788 if (p.eatToken(.colon)) |_| {
789 if (p.eatToken(.keyword_anytype)) |anytype_tok| {
790 type_expr = try p.addNode(.{
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 }
789 type_expr = try p.expectTypeExpr();
790 align_expr = try p.parseByteAlign();
802791 }
803792
804793 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,
229229 return renderToken(ais, tree, main_tokens[node] + 2, space);
230230 },
231231
232 .@"anytype" => return renderToken(ais, tree, main_tokens[node], space),
233
234232 .block_two,
235233 .block_two_semicolon,
236234 => {
src/AstGen.zig+2-18
......@@ -468,7 +468,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins
468468 .for_simple,
469469 .@"suspend",
470470 .@"continue",
471 .@"anytype",
472471 .fn_proto_simple,
473472 .fn_proto_multi,
474473 .fn_proto_one,
......@@ -558,8 +557,6 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr
558557 .asm_output => unreachable, // Handled in `asmExpr`.
559558 .asm_input => unreachable, // Handled in `asmExpr`.
560559
561 .@"anytype" => unreachable, // Handled in `containerDecl`.
562
563560 .assign => {
564561 try assign(gz, scope, node);
565562 return rvalue(gz, rl, .void_value, node);
......@@ -3826,7 +3823,6 @@ fn structDeclInner(
38263823 const astgen = gz.astgen;
38273824 const gpa = astgen.gpa;
38283825 const tree = astgen.tree;
3829 const node_tags = tree.nodes.items(.tag);
38303826
38313827 var namespace: Scope.Namespace = .{
38323828 .parent = scope,
......@@ -3875,10 +3871,7 @@ fn structDeclInner(
38753871 return astgen.failTok(member.ast.name_token, "struct field missing type", .{});
38763872 }
38773873
3878 const field_type: Zir.Inst.Ref = if (node_tags[member.ast.type_expr] == .@"anytype")
3879 .none
3880 else
3881 try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
3874 const field_type = try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
38823875 wip_members.appendToField(@enumToInt(field_type));
38833876
38843877 const doc_comment_index = try astgen.docCommentAsString(member.firstToken());
......@@ -3951,8 +3944,6 @@ fn unionDeclInner(
39513944
39523945 const astgen = gz.astgen;
39533946 const gpa = astgen.gpa;
3954 const tree = astgen.tree;
3955 const node_tags = tree.nodes.items(.tag);
39563947
39573948 var namespace: Scope.Namespace = .{
39583949 .parent = scope,
......@@ -4013,10 +4004,7 @@ fn unionDeclInner(
40134004 wip_members.nextField(bits_per_field, .{ have_type, have_align, have_value, unused });
40144005
40154006 if (have_type) {
4016 const field_type: Zir.Inst.Ref = if (node_tags[member.ast.type_expr] == .@"anytype")
4017 .none
4018 else
4019 try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
4007 const field_type = try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
40204008 wip_members.appendToField(@enumToInt(field_type));
40214009 } else if (arg_inst == .none and !have_auto_enum) {
40224010 return astgen.failNode(member_node, "union field missing type", .{});
......@@ -7791,7 +7779,6 @@ fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_
77917779 .ptr_type,
77927780 .ptr_type_bit_range,
77937781 .@"suspend",
7794 .@"anytype",
77957782 .fn_proto_simple,
77967783 .fn_proto_multi,
77977784 .fn_proto_one,
......@@ -8052,7 +8039,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev
80528039 .ptr_type,
80538040 .ptr_type_bit_range,
80548041 .@"suspend",
8055 .@"anytype",
80568042 .fn_proto_simple,
80578043 .fn_proto_multi,
80588044 .fn_proto_one,
......@@ -8232,7 +8218,6 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In
82328218 .@"resume",
82338219 .array_type,
82348220 .@"suspend",
8235 .@"anytype",
82368221 .fn_decl,
82378222 .anyframe_literal,
82388223 .integer_literal,
......@@ -8474,7 +8459,6 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
84748459 .@"resume",
84758460 .array_type,
84768461 .@"suspend",
8477 .@"anytype",
84788462 .fn_decl,
84798463 .anyframe_literal,
84808464 .integer_literal,
src/stage1/all_types.hpp+1
......@@ -2108,6 +2108,7 @@ struct CodeGen {
21082108 ZigType *entry_global_error_set;
21092109 ZigType *entry_enum_literal;
21102110 ZigType *entry_any_frame;
2111 ZigType *entry_opt_ptr_const_anyopaque;
21112112 } builtin_types;
21122113
21132114 struct Intern {
src/stage1/codegen.cpp+6
......@@ -9451,6 +9451,12 @@ static void define_builtin_types(CodeGen *g) {
94519451 g->primitive_type_table.put(&g->builtin_types.entry_anyopaque->name, g->builtin_types.entry_anyopaque);
94529452 }
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
94549460 {
94559461 ZigType *entry = new_type_table_entry(ZigTypeIdErrorSet);
94569462 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) {
1804518045}
1804618046
1804718047static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ptr_type_entry) {
18048 CodeGen *g = ira->codegen;
1804818049 ZigType *attrs_type;
1804918050 BuiltinPtrSize size_enum_index;
1805018051 if (is_slice(ptr_type_entry)) {
1805118052 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);
1805318054 size_enum_index = BuiltinPtrSizeSlice;
1805418055 } else if (ptr_type_entry->id == ZigTypeIdPointer) {
1805518056 attrs_type = ptr_type_entry;
......@@ -18059,19 +18060,19 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode
1805918060 }
1806018061
1806118062 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>();
1806518066 result->special = ConstValSpecialStatic;
1806618067 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);
1806918070 result->data.x_struct.fields = fields;
1807018071
1807118072 // size: Size
1807218073 ensure_field_index(result->type, "size", 0);
1807318074 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));
1807518076 fields[0]->special = ConstValSpecialStatic;
1807618077 fields[0]->type = type_info_pointer_size_type;
1807718078 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
1807918080 // is_const: bool
1808018081 ensure_field_index(result->type, "is_const", 1);
1808118082 fields[1]->special = ConstValSpecialStatic;
18082 fields[1]->type = ira->codegen->builtin_types.entry_bool;
18083 fields[1]->type = g->builtin_types.entry_bool;
1808318084 fields[1]->data.x_bool = attrs_type->data.pointer.is_const;
1808418085 // is_volatile: bool
1808518086 ensure_field_index(result->type, "is_volatile", 2);
1808618087 fields[2]->special = ConstValSpecialStatic;
18087 fields[2]->type = ira->codegen->builtin_types.entry_bool;
18088 fields[2]->type = g->builtin_types.entry_bool;
1808818089 fields[2]->data.x_bool = attrs_type->data.pointer.is_volatile;
1808918090 // alignment: comptime_int
1809018091 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;
1809218093 if (attrs_type->data.pointer.explicit_alignment != 0) {
1809318094 fields[3]->special = ConstValSpecialStatic;
1809418095 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
1810318104 // address_space: AddressSpace,
1810418105 ensure_field_index(result->type, "address_space", 4);
1810518106 fields[4]->special = ConstValSpecialStatic;
18106 fields[4]->type = get_builtin_type(ira->codegen, "AddressSpace");
18107 fields[4]->type = get_builtin_type(g, "AddressSpace");
1810718108 bigint_init_unsigned(&fields[4]->data.x_enum_tag, AddressSpaceGeneric);
1810818109 // child: type
1810918110 ensure_field_index(result->type, "child", 5);
1811018111 fields[5]->special = ConstValSpecialStatic;
18111 fields[5]->type = ira->codegen->builtin_types.entry_type;
18112 fields[5]->type = g->builtin_types.entry_type;
1811218113 fields[5]->data.x_type = attrs_type->data.pointer.child_type;
1811318114 // is_allowzero: bool
1811418115 ensure_field_index(result->type, "is_allowzero", 6);
1811518116 fields[6]->special = ConstValSpecialStatic;
18116 fields[6]->type = ira->codegen->builtin_types.entry_bool;
18117 fields[6]->type = g->builtin_types.entry_bool;
1811718118 fields[6]->data.x_bool = attrs_type->data.pointer.allow_zero;
18118 // sentinel: anytype
18119 // sentinel: ?*const anyopaque
1811918120 ensure_field_index(result->type, "sentinel", 7);
1812018121 fields[7]->special = ConstValSpecialStatic;
18121 if (attrs_type->data.pointer.sentinel != nullptr) {
18122 fields[7]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type);
18123 set_optional_payload(fields[7], attrs_type->data.pointer.sentinel);
18124 } else {
18125 fields[7]->type = ira->codegen->builtin_types.entry_null;
18126 }
18122 fields[7]->type = g->builtin_types.entry_opt_ptr_const_anyopaque;
18123 ZigValue *ptr_to_sent = (attrs_type->data.pointer.sentinel == nullptr) ? nullptr :
18124 create_const_ptr_ref(g, attrs_type->data.pointer.sentinel, true);
18125 set_optional_payload(fields[7], ptr_to_sent);
1812718126
1812818127 return result;
1812918128};
......@@ -18153,7 +18152,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1815318152 assert(type_entry != nullptr);
1815418153 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);
1815718158 if (entry != nullptr) {
1815818159 *out = entry->value;
1815918160 return ErrorNone;
......@@ -18172,43 +18173,43 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1817218173 case ZigTypeIdEnumLiteral:
1817318174 case ZigTypeIdUndefined:
1817418175 case ZigTypeIdNull:
18175 result = ira->codegen->intern.for_void();
18176 result = g->intern.for_void();
1817618177 break;
1817718178 case ZigTypeIdInt:
1817818179 {
18179 result = ira->codegen->pass1_arena->create<ZigValue>();
18180 result = g->pass1_arena->create<ZigValue>();
1818018181 result->special = ConstValSpecialStatic;
1818118182 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);
1818418185 result->data.x_struct.fields = fields;
1818518186
1818618187 // is_signed: Signedness
1818718188 ensure_field_index(result->type, "signedness", 0);
1818818189 fields[0]->special = ConstValSpecialStatic;
18189 fields[0]->type = get_builtin_type(ira->codegen, "Signedness");
18190 fields[0]->type = get_builtin_type(g, "Signedness");
1819018191 bigint_init_unsigned(&fields[0]->data.x_enum_tag, !type_entry->data.integral.is_signed);
1819118192 // bits: u8
1819218193 ensure_field_index(result->type, "bits", 1);
1819318194 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;
1819518196 bigint_init_unsigned(&fields[1]->data.x_bigint, type_entry->data.integral.bit_count);
1819618197
1819718198 break;
1819818199 }
1819918200 case ZigTypeIdFloat:
1820018201 {
18201 result = ira->codegen->pass1_arena->create<ZigValue>();
18202 result = g->pass1_arena->create<ZigValue>();
1820218203 result->special = ConstValSpecialStatic;
1820318204 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);
1820618207 result->data.x_struct.fields = fields;
1820718208
1820818209 // bits: u8
1820918210 ensure_field_index(result->type, "bits", 0);
1821018211 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;
1821218213 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.floating.bit_count);
1821318214
1821418215 break;
......@@ -18222,97 +18223,96 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1822218223 }
1822318224 case ZigTypeIdArray:
1822418225 {
18225 result = ira->codegen->pass1_arena->create<ZigValue>();
18226 result = g->pass1_arena->create<ZigValue>();
1822618227 result->special = ConstValSpecialStatic;
1822718228 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);
1823018231 result->data.x_struct.fields = fields;
1823118232
1823218233 // len: usize
1823318234 ensure_field_index(result->type, "len", 0);
1823418235 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;
1823618237 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.array.len);
1823718238 // child: type
1823818239 ensure_field_index(result->type, "child", 1);
1823918240 fields[1]->special = ConstValSpecialStatic;
18240 fields[1]->type = ira->codegen->builtin_types.entry_type;
18241 fields[1]->type = g->builtin_types.entry_type;
1824118242 fields[1]->data.x_type = type_entry->data.array.child_type;
18242 // sentinel: anytype
18243 src_assert(type_entry->data.array.child_type != nullptr, source_node);
18244 // sentinel: ?*const anyopaque
1824318245 fields[2]->special = ConstValSpecialStatic;
18244 if (type_entry->data.array.child_type != nullptr) {
18245 fields[2]->type = get_optional_type(ira->codegen, type_entry->data.array.child_type);
18246 set_optional_payload(fields[2], type_entry->data.array.sentinel);
18247 } else {
18248 fields[2]->type = ira->codegen->builtin_types.entry_null;
18249 }
18246 fields[2]->type = g->builtin_types.entry_opt_ptr_const_anyopaque;
18247 ZigValue *ptr_to_sent = (type_entry->data.array.sentinel == nullptr) ? nullptr :
18248 create_const_ptr_ref(g, type_entry->data.array.sentinel, true);
18249 set_optional_payload(fields[2], ptr_to_sent);
1825018250 break;
1825118251 }
1825218252 case ZigTypeIdVector: {
18253 result = ira->codegen->pass1_arena->create<ZigValue>();
18253 result = g->pass1_arena->create<ZigValue>();
1825418254 result->special = ConstValSpecialStatic;
1825518255 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);
1825818258 result->data.x_struct.fields = fields;
1825918259
1826018260 // len: usize
1826118261 ensure_field_index(result->type, "len", 0);
1826218262 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;
1826418264 bigint_init_unsigned(&fields[0]->data.x_bigint, type_entry->data.vector.len);
1826518265 // child: type
1826618266 ensure_field_index(result->type, "child", 1);
1826718267 fields[1]->special = ConstValSpecialStatic;
18268 fields[1]->type = ira->codegen->builtin_types.entry_type;
18268 fields[1]->type = g->builtin_types.entry_type;
1826918269 fields[1]->data.x_type = type_entry->data.vector.elem_type;
1827018270
1827118271 break;
1827218272 }
1827318273 case ZigTypeIdOptional:
1827418274 {
18275 result = ira->codegen->pass1_arena->create<ZigValue>();
18275 result = g->pass1_arena->create<ZigValue>();
1827618276 result->special = ConstValSpecialStatic;
1827718277 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);
1828018280 result->data.x_struct.fields = fields;
1828118281
1828218282 // child: type
1828318283 ensure_field_index(result->type, "child", 0);
1828418284 fields[0]->special = ConstValSpecialStatic;
18285 fields[0]->type = ira->codegen->builtin_types.entry_type;
18285 fields[0]->type = g->builtin_types.entry_type;
1828618286 fields[0]->data.x_type = type_entry->data.maybe.child_type;
1828718287
1828818288 break;
1828918289 }
1829018290 case ZigTypeIdAnyFrame: {
18291 result = ira->codegen->pass1_arena->create<ZigValue>();
18291 result = g->pass1_arena->create<ZigValue>();
1829218292 result->special = ConstValSpecialStatic;
1829318293 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);
1829618296 result->data.x_struct.fields = fields;
1829718297
1829818298 // child: ?type
1829918299 ensure_field_index(result->type, "child", 0);
1830018300 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);
1830218302 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);
1830418304 break;
1830518305 }
1830618306 case ZigTypeIdEnum:
1830718307 {
18308 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown)))
18308 if ((err = type_resolve(g, type_entry, ResolveStatusSizeKnown)))
1830918309 return err;
1831018310
18311 result = ira->codegen->pass1_arena->create<ZigValue>();
18311 result = g->pass1_arena->create<ZigValue>();
1831218312 result->special = ConstValSpecialStatic;
1831318313 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);
1831618316 result->data.x_struct.fields = fields;
1831718317
1831818318 // layout: ContainerLayout
......@@ -18323,24 +18323,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1832318323 // tag_type: type
1832418324 ensure_field_index(result->type, "tag_type", 1);
1832518325 fields[1]->special = ConstValSpecialStatic;
18326 fields[1]->type = ira->codegen->builtin_types.entry_type;
18326 fields[1]->type = g->builtin_types.entry_type;
1832718327 fields[1]->data.x_type = type_entry->data.enumeration.tag_int_type;
1832818328 // fields: []TypeInfo.EnumField
1832918329 ensure_field_index(result->type, "fields", 2);
1833018330
1833118331 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))) {
1833318333 zig_unreachable();
1833418334 }
1833518335 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>();
1833818338 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);
1834018340 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
1834518345 for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++)
1834618346 {
......@@ -18361,39 +18361,39 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1836118361 // is_exhaustive: bool
1836218362 ensure_field_index(result->type, "is_exhaustive", 4);
1836318363 fields[4]->special = ConstValSpecialStatic;
18364 fields[4]->type = ira->codegen->builtin_types.entry_bool;
18364 fields[4]->type = g->builtin_types.entry_bool;
1836518365 fields[4]->data.x_bool = !type_entry->data.enumeration.non_exhaustive;
1836618366
1836718367 break;
1836818368 }
1836918369 case ZigTypeIdErrorSet:
1837018370 {
18371 result = ira->codegen->pass1_arena->create<ZigValue>();
18371 result = g->pass1_arena->create<ZigValue>();
1837218372 result->special = ConstValSpecialStatic;
1837318373 result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr);
1837418374
1837518375 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)) {
1837718377 return ErrorSemanticAnalyzeFail;
1837818378 }
1837918379 if (type_is_global_error_set(type_entry)) {
1838018380 result->data.x_optional = nullptr;
1838118381 break;
1838218382 }
18383 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {
18383 if ((err = type_resolve(g, type_info_error_type, ResolveStatusSizeKnown))) {
1838418384 zig_unreachable();
1838518385 }
18386 ZigValue *slice_val = ira->codegen->pass1_arena->create<ZigValue>();
18386 ZigValue *slice_val = g->pass1_arena->create<ZigValue>();
1838718387 result->data.x_optional = slice_val;
1838818388
1838918389 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>();
1839118391 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);
1839318393 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);
1839718397 for (uint32_t error_index = 0; error_index < error_count; error_index++) {
1839818398 ErrorTableEntry *error = type_entry->data.error_set.errors[error_index];
1839918399 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
1840118401 error_val->special = ConstValSpecialStatic;
1840218402 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
1840618406 ZigValue *name = nullptr;
1840718407 if (error->cached_error_name_val != nullptr)
1840818408 name = error->cached_error_name_val;
1840918409 if (name == nullptr)
18410 name = create_const_str_lit(ira->codegen, &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);
18410 name = create_const_str_lit(g, &error->name)->data.x_ptr.data.ref.pointee;
18411 init_const_slice(g, inner_fields[0], name, 0, buf_len(&error->name), true, nullptr);
1841218412
1841318413 error_val->data.x_struct.fields = inner_fields;
1841418414 error_val->parent.id = ConstParentIdArray;
......@@ -18420,37 +18420,37 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1842018420 }
1842118421 case ZigTypeIdErrorUnion:
1842218422 {
18423 result = ira->codegen->pass1_arena->create<ZigValue>();
18423 result = g->pass1_arena->create<ZigValue>();
1842418424 result->special = ConstValSpecialStatic;
1842518425 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);
1842818428 result->data.x_struct.fields = fields;
1842918429
1843018430 // error_set: type
1843118431 ensure_field_index(result->type, "error_set", 0);
1843218432 fields[0]->special = ConstValSpecialStatic;
18433 fields[0]->type = ira->codegen->builtin_types.entry_type;
18433 fields[0]->type = g->builtin_types.entry_type;
1843418434 fields[0]->data.x_type = type_entry->data.error_union.err_set_type;
1843518435
1843618436 // payload: type
1843718437 ensure_field_index(result->type, "payload", 1);
1843818438 fields[1]->special = ConstValSpecialStatic;
18439 fields[1]->type = ira->codegen->builtin_types.entry_type;
18439 fields[1]->type = g->builtin_types.entry_type;
1844018440 fields[1]->data.x_type = type_entry->data.error_union.payload_type;
1844118441
1844218442 break;
1844318443 }
1844418444 case ZigTypeIdUnion:
1844518445 {
18446 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown)))
18446 if ((err = type_resolve(g, type_entry, ResolveStatusSizeKnown)))
1844718447 return err;
1844818448
18449 result = ira->codegen->pass1_arena->create<ZigValue>();
18449 result = g->pass1_arena->create<ZigValue>();
1845018450 result->special = ConstValSpecialStatic;
1845118451 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);
1845418454 result->data.x_struct.fields = fields;
1845518455
1845618456 // layout: ContainerLayout
......@@ -18461,15 +18461,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1846118461 // tag_type: ?type
1846218462 ensure_field_index(result->type, "tag_type", 1);
1846318463 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
1846618466 AstNode *union_decl_node = type_entry->data.unionation.decl_node;
1846718467 if (union_decl_node->data.container_decl.auto_enum ||
1846818468 union_decl_node->data.container_decl.init_arg_expr != nullptr)
1846918469 {
18470 ZigValue *tag_type = ira->codegen->pass1_arena->create<ZigValue>();
18470 ZigValue *tag_type = g->pass1_arena->create<ZigValue>();
1847118471 tag_type->special = ConstValSpecialStatic;
18472 tag_type->type = ira->codegen->builtin_types.entry_type;
18472 tag_type->type = g->builtin_types.entry_type;
1847318473 tag_type->data.x_type = type_entry->data.unionation.tag_type;
1847418474 fields[1]->data.x_optional = tag_type;
1847518475 } else {
......@@ -18479,17 +18479,17 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1847918479 ensure_field_index(result->type, "fields", 2);
1848018480
1848118481 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)))
1848318483 zig_unreachable();
1848418484 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>();
1848718487 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);
1848918489 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
1849418494 for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {
1849518495 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
1849818498 union_field_val->special = ConstValSpecialStatic;
1849918499 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);
1850218502 // field_type: type
1850318503 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;
1850518505 inner_fields[1]->data.x_type = union_field->type_entry;
1850618506
1850718507 // alignment: comptime_int
1850818508 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;
1851018510 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;
18513 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true, nullptr);
18512 ZigValue *name = create_const_str_lit(g, union_field->name)->data.x_ptr.data.ref.pointee;
18513 init_const_slice(g, inner_fields[0], name, 0, buf_len(union_field->name), true, nullptr);
1851418514
1851518515 union_field_val->data.x_struct.fields = inner_fields;
1851618516 union_field_val->parent.id = ConstParentIdArray;
......@@ -18536,14 +18536,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1853618536 break;
1853718537 }
1853818538
18539 if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusSizeKnown)))
18539 if ((err = type_resolve(g, type_entry, ResolveStatusSizeKnown)))
1854018540 return err;
1854118541
18542 result = ira->codegen->pass1_arena->create<ZigValue>();
18542 result = g->pass1_arena->create<ZigValue>();
1854318543 result->special = ConstValSpecialStatic;
1854418544 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);
1854718547 result->data.x_struct.fields = fields;
1854818548
1854918549 // layout: ContainerLayout
......@@ -18555,18 +18555,18 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1855518555 ensure_field_index(result->type, "fields", 1);
1855618556
1855718557 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))) {
1855918559 zig_unreachable();
1856018560 }
1856118561 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>();
1856418564 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);
1856618566 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
1857118571 for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) {
1857218572 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
1857518575 struct_field_val->special = ConstValSpecialStatic;
1857618576 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
1858018580 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;
1858218582 inner_fields[1]->data.x_type = struct_field->type_entry;
1858318583
18584 // default_value: anytype
18584 // default_value: ?*const anyopaque
1858518585 inner_fields[2]->special = ConstValSpecialStatic;
18586 inner_fields[2]->type = get_optional_type2(ira->codegen, struct_field->type_entry);
18587 if (inner_fields[2]->type == nullptr) return ErrorSemanticAnalyzeFail;
18588 memoize_field_init_val(ira->codegen, type_entry, struct_field);
18589 if(struct_field->init_val != nullptr && type_is_invalid(struct_field->init_val->type)){
18586 inner_fields[2]->type = g->builtin_types.entry_opt_ptr_const_anyopaque;
18587 memoize_field_init_val(g, type_entry, struct_field);
18588 if (struct_field->init_val != nullptr &&
18589 type_is_invalid(struct_field->init_val->type))
18590 {
1859018591 return ErrorSemanticAnalyzeFail;
1859118592 }
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
1859418597 // is_comptime: bool
1859518598 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;
1859718600 inner_fields[3]->data.x_bool = struct_field->is_comptime;
1859818601
1859918602 // alignment: comptime_int
1860018603 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;
1860218605 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;
18605 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true, nullptr);
18607 ZigValue *name = create_const_str_lit(g, struct_field->name)->data.x_ptr.data.ref.pointee;
18608 init_const_slice(g, inner_fields[0], name, 0, buf_len(struct_field->name), true, nullptr);
1860618609
1860718610 struct_field_val->data.x_struct.fields = inner_fields;
1860818611 struct_field_val->parent.id = ConstParentIdArray;
......@@ -18620,69 +18623,69 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1862018623 // is_tuple: bool
1862118624 ensure_field_index(result->type, "is_tuple", 3);
1862218625 fields[3]->special = ConstValSpecialStatic;
18623 fields[3]->type = ira->codegen->builtin_types.entry_bool;
18626 fields[3]->type = g->builtin_types.entry_bool;
1862418627 fields[3]->data.x_bool = is_tuple(type_entry);
1862518628
1862618629 break;
1862718630 }
1862818631 case ZigTypeIdFn:
1862918632 {
18630 result = ira->codegen->pass1_arena->create<ZigValue>();
18633 result = g->pass1_arena->create<ZigValue>();
1863118634 result->special = ConstValSpecialStatic;
1863218635 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);
1863518638 result->data.x_struct.fields = fields;
1863618639
1863718640 // calling_convention: TypeInfo.CallingConvention
1863818641 ensure_field_index(result->type, "calling_convention", 0);
1863918642 fields[0]->special = ConstValSpecialStatic;
18640 fields[0]->type = get_builtin_type(ira->codegen, "CallingConvention");
18643 fields[0]->type = get_builtin_type(g, "CallingConvention");
1864118644 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc);
1864218645 // alignment: comptime_int
1864318646 ensure_field_index(result->type, "alignment", 1);
1864418647 fields[1]->special = ConstValSpecialStatic;
18645 fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
18646 bigint_init_unsigned(&fields[1]->data.x_bigint, get_ptr_align(ira->codegen, type_entry));
18648 fields[1]->type = g->builtin_types.entry_num_lit_int;
18649 bigint_init_unsigned(&fields[1]->data.x_bigint, get_ptr_align(g, type_entry));
1864718650 // is_generic: bool
1864818651 ensure_field_index(result->type, "is_generic", 2);
1864918652 bool is_generic = type_entry->data.fn.is_generic;
1865018653 fields[2]->special = ConstValSpecialStatic;
18651 fields[2]->type = ira->codegen->builtin_types.entry_bool;
18654 fields[2]->type = g->builtin_types.entry_bool;
1865218655 fields[2]->data.x_bool = is_generic;
1865318656 // is_varargs: bool
1865418657 ensure_field_index(result->type, "is_var_args", 3);
1865518658 bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args;
1865618659 fields[3]->special = ConstValSpecialStatic;
18657 fields[3]->type = ira->codegen->builtin_types.entry_bool;
18660 fields[3]->type = g->builtin_types.entry_bool;
1865818661 fields[3]->data.x_bool = is_varargs;
1865918662 // return_type: ?type
1866018663 ensure_field_index(result->type, "return_type", 4);
1866118664 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);
1866318666 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
1866418667 fields[4]->data.x_optional = nullptr;
1866518668 else {
18666 ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>();
18669 ZigValue *return_type = g->pass1_arena->create<ZigValue>();
1866718670 return_type->special = ConstValSpecialStatic;
18668 return_type->type = ira->codegen->builtin_types.entry_type;
18671 return_type->type = g->builtin_types.entry_type;
1866918672 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
1867018673 fields[4]->data.x_optional = return_type;
1867118674 }
1867218675 // args: []TypeInfo.FnArg
1867318676 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))) {
1867518678 zig_unreachable();
1867618679 }
1867718680 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>();
1868018683 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);
1868218685 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
1868718690 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
1868818691 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
1869418697 bool arg_is_generic = fn_param_info->type == nullptr;
1869518698 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);
1869818701 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;
1870018703 inner_fields[0]->data.x_bool = arg_is_generic;
1870118704 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;
1870318706 inner_fields[1]->data.x_bool = fn_param_info->is_noalias;
1870418707 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
1870718710 if (arg_is_generic)
1870818711 inner_fields[2]->data.x_optional = nullptr;
1870918712 else {
18710 ZigValue *arg_type = ira->codegen->pass1_arena->create<ZigValue>();
18713 ZigValue *arg_type = g->pass1_arena->create<ZigValue>();
1871118714 arg_type->special = ConstValSpecialStatic;
18712 arg_type->type = ira->codegen->builtin_types.entry_type;
18715 arg_type->type = g->builtin_types.entry_type;
1871318716 arg_type->data.x_type = fn_param_info->type;
1871418717 inner_fields[2]->data.x_optional = arg_type;
1871518718 }
......@@ -18733,11 +18736,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1873318736 }
1873418737 case ZigTypeIdOpaque:
1873518738 {
18736 result = ira->codegen->pass1_arena->create<ZigValue>();
18739 result = g->pass1_arena->create<ZigValue>();
1873718740 result->special = ConstValSpecialStatic;
1873818741 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);
1874118744 result->data.x_struct.fields = fields;
1874218745
1874318746 // decls: []TypeInfo.Declaration
......@@ -18752,21 +18755,24 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
1875218755 }
1875318756 case ZigTypeIdFnFrame:
1875418757 {
18755 result = ira->codegen->pass1_arena->create<ZigValue>();
18758 result = g->pass1_arena->create<ZigValue>();
1875618759 result->special = ConstValSpecialStatic;
1875718760 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);
1875918762 result->data.x_struct.fields = fields;
1876018763 ZigFn *fn = type_entry->data.frame.fn;
18761 // function: anytype
18764 // function: ?*const anyopaque
1876218765 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;
1876418770 break;
1876518771 }
1876618772 }
1876718773
1876818774 assert(result != nullptr);
18769 ira->codegen->type_info_cache.put(type_entry, result);
18775 g->type_info_cache.put(type_entry, result);
1877018776 *out = result;
1877118777 return ErrorNone;
1877218778}
......@@ -18810,26 +18816,25 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue
1881018816 return val;
1881118817}
1881218818
18813static Error get_const_field_sentinel(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *struct_value,
18814 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
18819static Error get_const_field_sentinel(IrAnalyze *ira, Scope *scope, AstNode *source_node,
18820 ZigValue *struct_value, const char *name, size_t field_index, ZigType *elem_type,
18821 ZigValue **result)
1881518822{
1881618823 ZigValue *field_val = get_const_field(ira, source_node, struct_value, name, field_index);
1881718824 if (field_val == nullptr)
1881818825 return ErrorSemanticAnalyzeFail;
1881918826
18820 Stage1AirInst *field_inst = ir_const_move(ira, scope, source_node, field_val);
18821 Stage1AirInst *casted_field_inst = ir_implicit_cast(ira, field_inst,
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 // type of `field_val` is `?*const anyopaque`.
18828 if (field_val->data.x_ptr.special == ConstPtrSpecialNull) {
1882718829 *result = nullptr;
18828 } else {
18829 assert(type_has_optional_repr(casted_field_inst->value->type));
18830 *result = casted_field_inst->value->data.x_optional;
18830 return ErrorNone;
1883118831 }
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;
1883318838 return ErrorNone;
1883418839}
1883518840
......@@ -19043,6 +19048,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
1904319048 return ira->codegen->invalid_inst_gen->value->type;
1904419049 }
1904519050
19051 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusAlignmentKnown))) {
19052 return ira->codegen->invalid_inst_gen->value->type;
19053 }
19054
1904619055 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,
1904719056 elem_type,
1904819057 is_const,
......@@ -19140,15 +19149,9 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
1914019149 return get_any_frame_type(ira->codegen, child_type);
1914119150 }
1914219151 case ZigTypeIdFnFrame: {
19143 assert(payload->special == ConstValSpecialStatic);
19144 assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr));
19145 ZigValue *function = get_const_field(ira, source_node, payload, "function", 0);
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 ir_add_error_node(ira, source_node,
19153 buf_sprintf("use the @Frame builtin instead of @Type"));
19154 return ira->codegen->invalid_inst_gen->value->type;
1915219155 }
1915319156 case ZigTypeIdErrorSet: {
1915419157 assert(payload->special == ConstValSpecialStatic);
......@@ -19276,19 +19279,17 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
1927619279 ZigValue *default_value = get_const_field(ira, source_node, field_value, "default_value", 2);
1927719280 if (default_value == nullptr)
1927819281 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) {
1928019285 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;
1928519286 } else {
19286 ir_add_error_node(ira, source_node,
19287 buf_sprintf("default_value of field '%s' is of type '%s', expected '%s' or '?%s'",
19288 buf_ptr(field->name), buf_ptr(&default_value->type->name),
19289 buf_ptr(&field->type_entry->name), buf_ptr(&field->type_entry->name)));
19290 return ira->codegen->invalid_inst_gen->value->type;
19287 ZigValue *pointee = const_ptr_pointee_unchecked_no_isf(ira->codegen, default_value);
19288 if (pointee == nullptr)
19289 return ira->codegen->invalid_inst_gen->value->type;
19290 field->init_val = pointee;
1929119291 }
19292
1929219293 if ((err = get_const_field_bool(ira, source_node, field_value, "is_comptime", 3, &field->is_comptime)))
1929319294 return ira->codegen->invalid_inst_gen->value->type;
1929419295 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" {
618618 try expect(vec.@"2" == 99);
619619}
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
636621test "comptime struct field" {
637622 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
638623
test/behavior/type_info.zig+6-13
......@@ -119,7 +119,7 @@ fn testNullTerminatedPtr() !void {
119119 try expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many);
120120 try expect(ptr_info.Pointer.is_const == false);
121121 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
124124 try expect(@typeInfo([:0]u8).Pointer.sentinel != null);
125125}
......@@ -161,7 +161,7 @@ fn testArray() !void {
161161 const info = @typeInfo([10:0]u8);
162162 try expect(info.Array.len == 10);
163163 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));
165165 try expect(@sizeOf([10:0]u8) == info.Array.len + 1);
166166 }
167167}
......@@ -271,8 +271,8 @@ fn testStruct() !void {
271271 const unpacked_struct_info = @typeInfo(TestUnpackedStruct);
272272 try expect(unpacked_struct_info.Struct.is_tuple == false);
273273 try expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
274 try expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4);
275 try expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?);
274 try expect(@ptrCast(*const u32, unpacked_struct_info.Struct.fields[0].default_value.?).* == 4);
275 try expectEqualStrings("foobar", @ptrCast(*const *const [6:0]u8, unpacked_struct_info.Struct.fields[1].default_value.?).*);
276276
277277 const struct_info = @typeInfo(TestStruct);
278278 try expect(struct_info == .Struct);
......@@ -282,7 +282,7 @@ fn testStruct() !void {
282282 try expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
283283 try expect(struct_info.Struct.fields[2].field_type == *TestStruct);
284284 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);
286286 try expect(struct_info.Struct.fields[3].alignment == 1);
287287 try expect(struct_info.Struct.decls.len == 2);
288288 try expect(struct_info.Struct.decls[0].is_pub);
......@@ -436,13 +436,6 @@ test "@typeInfo does not force declarations into existence" {
436436 comptime try expect(@typeInfo(S).Struct.fields.len == 1);
437437}
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
446439fn add(a: i32, b: i32) i32 {
447440 return a + b;
448441}
......@@ -452,7 +445,7 @@ test "type info for async frames" {
452445
453446 switch (@typeInfo(@Frame(add))) {
454447 .Frame => |frame| {
455 try expect(frame.function == add);
448 try expect(@ptrCast(@TypeOf(add), frame.function) == add);
456449 },
457450 else => unreachable,
458451 }
test/behavior/type_stage1.zig+7-13
......@@ -37,7 +37,7 @@ test "Type.Array" {
3737 .Array = TypeInfo.Array{
3838 .len = 2,
3939 .child = u32,
40 .sentinel = 0,
40 .sentinel = &@as(u32, 0),
4141 },
4242 }));
4343 try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
......@@ -141,12 +141,6 @@ fn add(a: i32, b: i32) i32 {
141141 return a + b;
142142}
143143
144test "Type.Frame" {
145 try testTypes(&[_]type{
146 @Frame(add),
147 });
148}
149
150144test "Type.ErrorSet" {
151145 // error sets don't compare equal so just check if they compile
152146 _ = @Type(@typeInfo(error{}));
......@@ -160,10 +154,10 @@ test "Type.Struct" {
160154 try testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout);
161155 try testing.expectEqualSlices(u8, "x", infoA.fields[0].name);
162156 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);
164158 try testing.expectEqualSlices(u8, "y", infoA.fields[1].name);
165159 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);
167161 try testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls);
168162 try testing.expectEqual(@as(bool, false), infoA.is_tuple);
169163
......@@ -178,10 +172,10 @@ test "Type.Struct" {
178172 try testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout);
179173 try testing.expectEqualSlices(u8, "x", infoB.fields[0].name);
180174 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);
182176 try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
183177 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.?).*);
185179 try testing.expectEqual(@as(usize, 0), infoB.decls.len);
186180 try testing.expectEqual(@as(bool, false), infoB.is_tuple);
187181
......@@ -190,10 +184,10 @@ test "Type.Struct" {
190184 try testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout);
191185 try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
192186 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.?).*);
194188 try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
195189 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.?).*);
197191 try testing.expectEqual(@as(usize, 0), infoC.decls.len);
198192 try testing.expectEqual(@as(bool, false), infoC.is_tuple);
199193}
test/behavior/union_stage1.zig-5
......@@ -419,8 +419,3 @@ test "union enum type gets a separate scope" {
419419
420420 try S.doTheTest();
421421}
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 {
744744 \\ .address_space = .generic,
745745 \\ .child = u8,
746746 \\ .is_allowzero = false,
747 \\ .sentinel = 0,
747 \\ .sentinel = &@as(u8, 0),
748748 \\ }});
749749 \\}
750750 , &[_][]const u8{
......@@ -4207,16 +4207,6 @@ pub fn addCases(ctx: *TestContext) !void {
42074207 "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'",
42084208 });
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
42204210 ctx.objErrStage1("@ptrCast discards const qualifier",
42214211 \\export fn entry() void {
42224212 \\ const x: i32 = 1234;