authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-08-20 12:20:24+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-20 16:42:48-07:00
logebfe723f3cdbb40d2f2280e223b710418abde777
treec5cdc3061e3b8b7c84f34a14866871a7216c730b
parenteef111fe78d7b246b634a07561082a6fcf947e09

stage2: implement rest of simple pointer types


6 files changed, 230 insertions(+), 51 deletions(-)

src-self-hosted/Module.zig+18-8
...@@ -2429,7 +2429,7 @@ pub fn analyzeDeclRef(self: *Module, scope: *Scope, src: usize, decl: *Decl) Inn...@@ -2429,7 +2429,7 @@ pub fn analyzeDeclRef(self: *Module, scope: *Scope, src: usize, decl: *Decl) Inn
2429 if (decl_tv.val.tag() == .variable) {2429 if (decl_tv.val.tag() == .variable) {
2430 return self.analyzeVarRef(scope, src, decl_tv);2430 return self.analyzeVarRef(scope, src, decl_tv);
2431 }2431 }
2432 const ty = try self.singlePtrType(scope, src, false, decl_tv.ty);2432 const ty = try self.simplePtrType(scope, src, decl_tv.ty, false, .One);
2433 const val_payload = try scope.arena().create(Value.Payload.DeclRef);2433 const val_payload = try scope.arena().create(Value.Payload.DeclRef);
2434 val_payload.* = .{ .decl = decl };2434 val_payload.* = .{ .decl = decl };
24352435
...@@ -2442,7 +2442,7 @@ pub fn analyzeDeclRef(self: *Module, scope: *Scope, src: usize, decl: *Decl) Inn...@@ -2442,7 +2442,7 @@ pub fn analyzeDeclRef(self: *Module, scope: *Scope, src: usize, decl: *Decl) Inn
2442fn analyzeVarRef(self: *Module, scope: *Scope, src: usize, tv: TypedValue) InnerError!*Inst {2442fn analyzeVarRef(self: *Module, scope: *Scope, src: usize, tv: TypedValue) InnerError!*Inst {
2443 const variable = tv.val.cast(Value.Payload.Variable).?.variable;2443 const variable = tv.val.cast(Value.Payload.Variable).?.variable;
24442444
2445 const ty = try self.singlePtrType(scope, src, variable.is_mutable, tv.ty);2445 const ty = try self.singlePtrType(scope, src, variable.is_mutable, tv.ty, .One);
2446 if (!variable.is_mutable and !variable.is_extern) {2446 if (!variable.is_mutable and !variable.is_extern) {
2447 const val_payload = try scope.arena().create(Value.Payload.RefVal);2447 const val_payload = try scope.arena().create(Value.Payload.RefVal);
2448 val_payload.* = .{ .val = variable.init };2448 val_payload.* = .{ .val = variable.init };
...@@ -2766,7 +2766,7 @@ pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst...@@ -2766,7 +2766,7 @@ pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst
27662766
2767 // T to ?T2767 // T to ?T
2768 if (dest_type.zigTypeTag() == .Optional) {2768 if (dest_type.zigTypeTag() == .Optional) {
2769 var buf: Type.Payload.Pointer = undefined;2769 var buf: Type.Payload.PointerSimple = undefined;
2770 const child_type = dest_type.optionalChild(&buf);2770 const child_type = dest_type.optionalChild(&buf);
2771 if (child_type.eql(inst.ty)) {2771 if (child_type.eql(inst.ty)) {
2772 return self.wrapOptional(scope, dest_type, inst);2772 return self.wrapOptional(scope, dest_type, inst);
...@@ -3145,10 +3145,20 @@ pub fn floatSub(self: *Module, scope: *Scope, float_type: Type, src: usize, lhs:...@@ -3145,10 +3145,20 @@ pub fn floatSub(self: *Module, scope: *Scope, float_type: Type, src: usize, lhs:
3145 return Value.initPayload(val_payload);3145 return Value.initPayload(val_payload);
3146}3146}
31473147
3148pub fn singlePtrType(self: *Module, scope: *Scope, src: usize, mutable: bool, elem_ty: Type) Allocator.Error!Type {3148pub fn simplePtrType(self: *Module, scope: *Scope, src: usize, elem_ty: Type, mutable: bool, size: std.builtin.TypeInfo.Pointer.Size) Allocator.Error!Type {
3149 const type_payload = try scope.arena().create(Type.Payload.Pointer);3149 // TODO stage1 type inference bug
3150 const T = Type.Tag;
3151
3152 const type_payload = try scope.arena().create(Type.Payload.PointerSimple);
3150 type_payload.* = .{3153 type_payload.* = .{
3151 .base = .{ .tag = if (mutable) .single_mut_pointer else .single_const_pointer },3154 .base = .{
3155 .tag = switch (size) {
3156 .One => if (mutable) .single_mut_pointer else T.many_const_pointer,
3157 .Many => if (mutable) T.many_mut_pointer else T.many_const_pointer,
3158 .C => if (mutable) T.c_mut_pointer else T.c_const_pointer,
3159 else => unreachable,
3160 },
3161 },
3152 .pointee_type = elem_ty,3162 .pointee_type = elem_ty,
3153 };3163 };
3154 return Type.initPayload(&type_payload.base);3164 return Type.initPayload(&type_payload.base);
...@@ -3157,7 +3167,7 @@ pub fn singlePtrType(self: *Module, scope: *Scope, src: usize, mutable: bool, el...@@ -3157,7 +3167,7 @@ pub fn singlePtrType(self: *Module, scope: *Scope, src: usize, mutable: bool, el
3157pub fn optionalType(self: *Module, scope: *Scope, child_type: Type) Allocator.Error!Type {3167pub fn optionalType(self: *Module, scope: *Scope, child_type: Type) Allocator.Error!Type {
3158 return Type.initPayload(switch (child_type.tag()) {3168 return Type.initPayload(switch (child_type.tag()) {
3159 .single_const_pointer => blk: {3169 .single_const_pointer => blk: {
3160 const payload = try scope.arena().create(Type.Payload.Pointer);3170 const payload = try scope.arena().create(Type.Payload.PointerSimple);
3161 payload.* = .{3171 payload.* = .{
3162 .base = .{ .tag = .optional_single_const_pointer },3172 .base = .{ .tag = .optional_single_const_pointer },
3163 .pointee_type = child_type.elemType(),3173 .pointee_type = child_type.elemType(),
...@@ -3165,7 +3175,7 @@ pub fn optionalType(self: *Module, scope: *Scope, child_type: Type) Allocator.Er...@@ -3165,7 +3175,7 @@ pub fn optionalType(self: *Module, scope: *Scope, child_type: Type) Allocator.Er
3165 break :blk &payload.base;3175 break :blk &payload.base;
3166 },3176 },
3167 .single_mut_pointer => blk: {3177 .single_mut_pointer => blk: {
3168 const payload = try scope.arena().create(Type.Payload.Pointer);3178 const payload = try scope.arena().create(Type.Payload.PointerSimple);
3169 payload.* = .{3179 payload.* = .{
3170 .base = .{ .tag = .optional_single_mut_pointer },3180 .base = .{ .tag = .optional_single_mut_pointer },
3171 .pointee_type = child_type.elemType(),3181 .pointee_type = child_type.elemType(),
src-self-hosted/astgen.zig+22-5
...@@ -577,6 +577,17 @@ fn ptrType(mod: *Module, scope: *Scope, node: *ast.Node.PtrType) InnerError!*zir...@@ -577,6 +577,17 @@ fn ptrType(mod: *Module, scope: *Scope, node: *ast.Node.PtrType) InnerError!*zir
577 .val = Value.initTag(.type_type),577 .val = Value.initTag(.type_type),
578 });578 });
579579
580 const size: std.builtin.TypeInfo.Pointer.Size = switch (tree.token_ids[node.op_token]) {
581 .Asterisk, .AsteriskAsterisk => .One,
582 // TODO stage1 type inference bug
583 .LBracket => @as(std.builtin.TypeInfo.Pointer.Size, switch (tree.token_ids[node.op_token + 2]) {
584 .Identifier => .C,
585 .RBracket => .Many,
586 else => unreachable,
587 }),
588 else => unreachable,
589 };
590
580 const simple = node.ptr_info.allowzero_token == null and591 const simple = node.ptr_info.allowzero_token == null and
581 node.ptr_info.align_info == null and592 node.ptr_info.align_info == null and
582 node.ptr_info.volatile_token == null and593 node.ptr_info.volatile_token == null and
...@@ -584,13 +595,19 @@ fn ptrType(mod: *Module, scope: *Scope, node: *ast.Node.PtrType) InnerError!*zir...@@ -584,13 +595,19 @@ fn ptrType(mod: *Module, scope: *Scope, node: *ast.Node.PtrType) InnerError!*zir
584595
585 if (simple) {596 if (simple) {
586 const child_type = try expr(mod, scope, .{ .ty = meta_type }, node.rhs);597 const child_type = try expr(mod, scope, .{ .ty = meta_type }, node.rhs);
587 return addZIRUnOp(mod, scope, src, if (node.ptr_info.const_token == null)598 const mutable = node.ptr_info.const_token == null;
588 .single_mut_ptr_type599 // TODO stage1 type inference bug
589 else600 const T = zir.Inst.Tag;
590 .single_const_ptr_type, child_type);601 return addZIRUnOp(mod, scope, src, switch (size) {
602 .One => if (mutable) T.single_mut_ptr_type else T.single_const_ptr_type,
603 .Many => if (mutable) T.many_mut_ptr_type else T.many_const_ptr_type,
604 .C => if (mutable) T.c_mut_ptr_type else T.c_const_ptr_type,
605 else => unreachable,
606 }, child_type);
591 }607 }
592608
593 var kw_args: std.meta.fieldInfo(zir.Inst.PtrType, "kw_args").field_type = .{};609 var kw_args: std.meta.fieldInfo(zir.Inst.PtrType, "kw_args").field_type = .{};
610 kw_args.size = size;
594 kw_args.@"allowzero" = node.ptr_info.allowzero_token != null;611 kw_args.@"allowzero" = node.ptr_info.allowzero_token != null;
595 if (node.ptr_info.align_info) |some| {612 if (node.ptr_info.align_info) |some| {
596 kw_args.@"align" = try expr(mod, scope, .none, some.node);613 kw_args.@"align" = try expr(mod, scope, .none, some.node);
...@@ -1271,7 +1288,7 @@ fn multilineStrLiteral(mod: *Module, scope: *Scope, node: *ast.Node.MultilineStr...@@ -1271,7 +1288,7 @@ fn multilineStrLiteral(mod: *Module, scope: *Scope, node: *ast.Node.MultilineStr
1271 i += 1;1288 i += 1;
1272 }1289 }
1273 const slice = tree.tokenSlice(line);1290 const slice = tree.tokenSlice(line);
1274 mem.copy(u8, bytes[i..], slice[2..slice.len - 1]);1291 mem.copy(u8, bytes[i..], slice[2 .. slice.len - 1]);
1275 i += slice.len - 3;1292 i += slice.len - 3;
1276 }1293 }
12771294
src-self-hosted/codegen.zig+1-1
...@@ -2060,7 +2060,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2060,7 +2060,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2060 if (typed_value.val.isNull())2060 if (typed_value.val.isNull())
2061 return MCValue{ .immediate = 0 };2061 return MCValue{ .immediate = 0 };
20622062
2063 var buf: Type.Payload.Pointer = undefined;2063 var buf: Type.Payload.PointerSimple = undefined;
2064 return self.genTypedValue(src, .{2064 return self.genTypedValue(src, .{
2065 .ty = typed_value.ty.optionalChild(&buf),2065 .ty = typed_value.ty.optionalChild(&buf),
2066 .val = typed_value.val,2066 .val = typed_value.val,
src-self-hosted/type.zig+159-22
...@@ -66,10 +66,15 @@ pub const Type = extern union {...@@ -66,10 +66,15 @@ pub const Type = extern union {
66 .function => return .Fn,66 .function => return .Fn,
6767
68 .array, .array_u8_sentinel_0, .array_u8, .array_sentinel => return .Array,68 .array, .array_u8_sentinel_0, .array_u8, .array_sentinel => return .Array,
69 .single_const_pointer => return .Pointer,69 .single_const_pointer_to_comptime_int,
70 .single_mut_pointer => return .Pointer,70 .const_slice_u8,
71 .single_const_pointer_to_comptime_int => return .Pointer,71 .single_const_pointer,
72 .const_slice_u8 => return .Pointer,72 .single_mut_pointer,
73 .many_const_pointer,
74 .many_mut_pointer,
75 .c_const_pointer,
76 .c_mut_pointer,
77 => return .Pointer,
7378
74 .optional,79 .optional,
75 .optional_single_const_pointer,80 .optional_single_const_pointer,
...@@ -108,13 +113,17 @@ pub const Type = extern union {...@@ -108,13 +113,17 @@ pub const Type = extern union {
108 return @fieldParentPtr(T, "base", self.ptr_otherwise);113 return @fieldParentPtr(T, "base", self.ptr_otherwise);
109 }114 }
110115
111 pub fn castPointer(self: Type) ?*Payload.Pointer {116 pub fn castPointer(self: Type) ?*Payload.PointerSimple {
112 return switch (self.tag()) {117 return switch (self.tag()) {
113 .single_const_pointer,118 .single_const_pointer,
114 .single_mut_pointer,119 .single_mut_pointer,
120 .many_const_pointer,
121 .many_mut_pointer,
122 .c_const_pointer,
123 .c_mut_pointer,
115 .optional_single_const_pointer,124 .optional_single_const_pointer,
116 .optional_single_mut_pointer,125 .optional_single_mut_pointer,
117 => @fieldParentPtr(Payload.Pointer, "base", self.ptr_otherwise),126 => @fieldParentPtr(Payload.PointerSimple, "base", self.ptr_otherwise),
118 else => null,127 else => null,
119 };128 };
120 }129 }
...@@ -198,8 +207,8 @@ pub const Type = extern union {...@@ -198,8 +207,8 @@ pub const Type = extern union {
198 return true;207 return true;
199 },208 },
200 .Optional => {209 .Optional => {
201 var buf_a: Payload.Pointer = undefined;210 var buf_a: Payload.PointerSimple = undefined;
202 var buf_b: Payload.Pointer = undefined;211 var buf_b: Payload.PointerSimple = undefined;
203 return a.optionalChild(&buf_a).eql(b.optionalChild(&buf_b));212 return a.optionalChild(&buf_a).eql(b.optionalChild(&buf_b));
204 },213 },
205 .Float,214 .Float,
...@@ -263,7 +272,7 @@ pub const Type = extern union {...@@ -263,7 +272,7 @@ pub const Type = extern union {
263 }272 }
264 },273 },
265 .Optional => {274 .Optional => {
266 var buf: Payload.Pointer = undefined;275 var buf: Payload.PointerSimple = undefined;
267 std.hash.autoHash(&hasher, self.optionalChild(&buf).hash());276 std.hash.autoHash(&hasher, self.optionalChild(&buf).hash());
268 },277 },
269 .Float,278 .Float,
...@@ -374,9 +383,13 @@ pub const Type = extern union {...@@ -374,9 +383,13 @@ pub const Type = extern union {
374 .optional => return self.copyPayloadSingleField(allocator, Payload.Optional, "child_type"),383 .optional => return self.copyPayloadSingleField(allocator, Payload.Optional, "child_type"),
375 .single_const_pointer,384 .single_const_pointer,
376 .single_mut_pointer,385 .single_mut_pointer,
386 .many_const_pointer,
387 .many_mut_pointer,
388 .c_const_pointer,
389 .c_mut_pointer,
377 .optional_single_mut_pointer,390 .optional_single_mut_pointer,
378 .optional_single_const_pointer,391 .optional_single_const_pointer,
379 => return self.copyPayloadSingleField(allocator, Payload.Pointer, "pointee_type"),392 => return self.copyPayloadSingleField(allocator, Payload.PointerSimple, "pointee_type"),
380 }393 }
381 }394 }
382395
...@@ -482,17 +495,41 @@ pub const Type = extern union {...@@ -482,17 +495,41 @@ pub const Type = extern union {
482 continue;495 continue;
483 },496 },
484 .single_const_pointer => {497 .single_const_pointer => {
485 const payload = @fieldParentPtr(Payload.Pointer, "base", ty.ptr_otherwise);498 const payload = @fieldParentPtr(Payload.PointerSimple, "base", ty.ptr_otherwise);
486 try out_stream.writeAll("*const ");499 try out_stream.writeAll("*const ");
487 ty = payload.pointee_type;500 ty = payload.pointee_type;
488 continue;501 continue;
489 },502 },
490 .single_mut_pointer => {503 .single_mut_pointer => {
491 const payload = @fieldParentPtr(Payload.Pointer, "base", ty.ptr_otherwise);504 const payload = @fieldParentPtr(Payload.PointerSimple, "base", ty.ptr_otherwise);
492 try out_stream.writeAll("*");505 try out_stream.writeAll("*");
493 ty = payload.pointee_type;506 ty = payload.pointee_type;
494 continue;507 continue;
495 },508 },
509 .many_const_pointer => {
510 const payload = @fieldParentPtr(Payload.PointerSimple, "base", ty.ptr_otherwise);
511 try out_stream.writeAll("[*]const ");
512 ty = payload.pointee_type;
513 continue;
514 },
515 .many_mut_pointer => {
516 const payload = @fieldParentPtr(Payload.PointerSimple, "base", ty.ptr_otherwise);
517 try out_stream.writeAll("[*]");
518 ty = payload.pointee_type;
519 continue;
520 },
521 .c_const_pointer => {
522 const payload = @fieldParentPtr(Payload.PointerSimple, "base", ty.ptr_otherwise);
523 try out_stream.writeAll("[*c]const ");
524 ty = payload.pointee_type;
525 continue;
526 },
527 .c_mut_pointer => {
528 const payload = @fieldParentPtr(Payload.PointerSimple, "base", ty.ptr_otherwise);
529 try out_stream.writeAll("[*c]");
530 ty = payload.pointee_type;
531 continue;
532 },
496 .int_signed => {533 .int_signed => {
497 const payload = @fieldParentPtr(Payload.IntSigned, "base", ty.ptr_otherwise);534 const payload = @fieldParentPtr(Payload.IntSigned, "base", ty.ptr_otherwise);
498 return out_stream.print("i{}", .{payload.bits});535 return out_stream.print("i{}", .{payload.bits});
...@@ -508,13 +545,13 @@ pub const Type = extern union {...@@ -508,13 +545,13 @@ pub const Type = extern union {
508 continue;545 continue;
509 },546 },
510 .optional_single_const_pointer => {547 .optional_single_const_pointer => {
511 const payload = @fieldParentPtr(Payload.Pointer, "base", ty.ptr_otherwise);548 const payload = @fieldParentPtr(Payload.PointerSimple, "base", ty.ptr_otherwise);
512 try out_stream.writeAll("?*const ");549 try out_stream.writeAll("?*const ");
513 ty = payload.pointee_type;550 ty = payload.pointee_type;
514 continue;551 continue;
515 },552 },
516 .optional_single_mut_pointer => {553 .optional_single_mut_pointer => {
517 const payload = @fieldParentPtr(Payload.Pointer, "base", ty.ptr_otherwise);554 const payload = @fieldParentPtr(Payload.PointerSimple, "base", ty.ptr_otherwise);
518 try out_stream.writeAll("?*");555 try out_stream.writeAll("?*");
519 ty = payload.pointee_type;556 ty = payload.pointee_type;
520 continue;557 continue;
...@@ -619,6 +656,10 @@ pub const Type = extern union {...@@ -619,6 +656,10 @@ pub const Type = extern union {
619 .array_sentinel => self.elemType().hasCodeGenBits(),656 .array_sentinel => self.elemType().hasCodeGenBits(),
620 .single_const_pointer => self.elemType().hasCodeGenBits(),657 .single_const_pointer => self.elemType().hasCodeGenBits(),
621 .single_mut_pointer => self.elemType().hasCodeGenBits(),658 .single_mut_pointer => self.elemType().hasCodeGenBits(),
659 .many_const_pointer => self.elemType().hasCodeGenBits(),
660 .many_mut_pointer => self.elemType().hasCodeGenBits(),
661 .c_const_pointer => self.elemType().hasCodeGenBits(),
662 .c_mut_pointer => self.elemType().hasCodeGenBits(),
622 .int_signed => self.cast(Payload.IntSigned).?.bits == 0,663 .int_signed => self.cast(Payload.IntSigned).?.bits == 0,
623 .int_unsigned => self.cast(Payload.IntUnsigned).?.bits == 0,664 .int_unsigned => self.cast(Payload.IntUnsigned).?.bits == 0,
624665
...@@ -669,6 +710,10 @@ pub const Type = extern union {...@@ -669,6 +710,10 @@ pub const Type = extern union {
669 .const_slice_u8,710 .const_slice_u8,
670 .single_const_pointer,711 .single_const_pointer,
671 .single_mut_pointer,712 .single_mut_pointer,
713 .many_const_pointer,
714 .many_mut_pointer,
715 .c_const_pointer,
716 .c_mut_pointer,
672 .optional_single_const_pointer,717 .optional_single_const_pointer,
673 .optional_single_mut_pointer,718 .optional_single_mut_pointer,
674 => return @divExact(target.cpu.arch.ptrBitWidth(), 8),719 => return @divExact(target.cpu.arch.ptrBitWidth(), 8),
...@@ -704,7 +749,7 @@ pub const Type = extern union {...@@ -704,7 +749,7 @@ pub const Type = extern union {
704 },749 },
705750
706 .optional => {751 .optional => {
707 var buf: Payload.Pointer = undefined;752 var buf: Payload.PointerSimple = undefined;
708 const child_type = self.optionalChild(&buf);753 const child_type = self.optionalChild(&buf);
709 if (!child_type.hasCodeGenBits()) return 1;754 if (!child_type.hasCodeGenBits()) return 1;
710755
...@@ -772,6 +817,10 @@ pub const Type = extern union {...@@ -772,6 +817,10 @@ pub const Type = extern union {
772 .const_slice_u8,817 .const_slice_u8,
773 .single_const_pointer,818 .single_const_pointer,
774 .single_mut_pointer,819 .single_mut_pointer,
820 .many_const_pointer,
821 .many_mut_pointer,
822 .c_const_pointer,
823 .c_mut_pointer,
775 .optional_single_const_pointer,824 .optional_single_const_pointer,
776 .optional_single_mut_pointer,825 .optional_single_mut_pointer,
777 => return @divExact(target.cpu.arch.ptrBitWidth(), 8),826 => return @divExact(target.cpu.arch.ptrBitWidth(), 8),
...@@ -805,7 +854,7 @@ pub const Type = extern union {...@@ -805,7 +854,7 @@ pub const Type = extern union {
805 },854 },
806855
807 .optional => {856 .optional => {
808 var buf: Payload.Pointer = undefined;857 var buf: Payload.PointerSimple = undefined;
809 const child_type = self.optionalChild(&buf);858 const child_type = self.optionalChild(&buf);
810 if (!child_type.hasCodeGenBits()) return 1;859 if (!child_type.hasCodeGenBits()) return 1;
811860
...@@ -872,6 +921,10 @@ pub const Type = extern union {...@@ -872,6 +921,10 @@ pub const Type = extern union {
872 .optional_single_mut_pointer,921 .optional_single_mut_pointer,
873 .optional_single_const_pointer,922 .optional_single_const_pointer,
874 .enum_literal,923 .enum_literal,
924 .many_const_pointer,
925 .many_mut_pointer,
926 .c_const_pointer,
927 .c_mut_pointer,
875 => false,928 => false,
876929
877 .single_const_pointer,930 .single_const_pointer,
...@@ -922,6 +975,10 @@ pub const Type = extern union {...@@ -922,6 +975,10 @@ pub const Type = extern union {
922 .array_u8_sentinel_0,975 .array_u8_sentinel_0,
923 .single_const_pointer,976 .single_const_pointer,
924 .single_mut_pointer,977 .single_mut_pointer,
978 .many_const_pointer,
979 .many_mut_pointer,
980 .c_const_pointer,
981 .c_mut_pointer,
925 .single_const_pointer_to_comptime_int,982 .single_const_pointer_to_comptime_int,
926 .fn_noreturn_no_args,983 .fn_noreturn_no_args,
927 .fn_void_no_args,984 .fn_void_no_args,
...@@ -987,6 +1044,8 @@ pub const Type = extern union {...@@ -987,6 +1044,8 @@ pub const Type = extern union {
987 .int_unsigned,1044 .int_unsigned,
988 .int_signed,1045 .int_signed,
989 .single_mut_pointer,1046 .single_mut_pointer,
1047 .many_mut_pointer,
1048 .c_mut_pointer,
990 .optional,1049 .optional,
991 .optional_single_mut_pointer,1050 .optional_single_mut_pointer,
992 .optional_single_const_pointer,1051 .optional_single_const_pointer,
...@@ -994,6 +1053,8 @@ pub const Type = extern union {...@@ -994,6 +1053,8 @@ pub const Type = extern union {
994 => false,1053 => false,
9951054
996 .single_const_pointer,1055 .single_const_pointer,
1056 .many_const_pointer,
1057 .c_const_pointer,
997 .single_const_pointer_to_comptime_int,1058 .single_const_pointer_to_comptime_int,
998 .const_slice_u8,1059 .const_slice_u8,
999 => true,1060 => true,
...@@ -1048,6 +1109,10 @@ pub const Type = extern union {...@@ -1048,6 +1109,10 @@ pub const Type = extern union {
1048 .int_signed,1109 .int_signed,
1049 .single_mut_pointer,1110 .single_mut_pointer,
1050 .single_const_pointer,1111 .single_const_pointer,
1112 .many_const_pointer,
1113 .many_mut_pointer,
1114 .c_const_pointer,
1115 .c_mut_pointer,
1051 .single_const_pointer_to_comptime_int,1116 .single_const_pointer_to_comptime_int,
1052 .const_slice_u8,1117 .const_slice_u8,
1053 .optional,1118 .optional,
...@@ -1063,7 +1128,7 @@ pub const Type = extern union {...@@ -1063,7 +1128,7 @@ pub const Type = extern union {
1063 switch (self.tag()) {1128 switch (self.tag()) {
1064 .optional_single_const_pointer, .optional_single_mut_pointer => return true,1129 .optional_single_const_pointer, .optional_single_mut_pointer => return true,
1065 .optional => {1130 .optional => {
1066 var buf: Payload.Pointer = undefined;1131 var buf: Payload.PointerSimple = undefined;
1067 const child_type = self.optionalChild(&buf);1132 const child_type = self.optionalChild(&buf);
1068 // optionals of zero sized pointers behave like bools1133 // optionals of zero sized pointers behave like bools
1069 if (!child_type.hasCodeGenBits()) return false;1134 if (!child_type.hasCodeGenBits()) return false;
...@@ -1101,7 +1166,7 @@ pub const Type = extern union {...@@ -1101,7 +1166,7 @@ pub const Type = extern union {
1101 => return false,1166 => return false,
11021167
1103 .Optional => {1168 .Optional => {
1104 var buf: Payload.Pointer = undefined;1169 var buf: Payload.PointerSimple = undefined;
1105 return ty.optionalChild(&buf).isValidVarType(is_extern);1170 return ty.optionalChild(&buf).isValidVarType(is_extern);
1106 },1171 },
1107 .Pointer, .Array => ty = ty.elemType(),1172 .Pointer, .Array => ty = ty.elemType(),
...@@ -1166,13 +1231,17 @@ pub const Type = extern union {...@@ -1166,13 +1231,17 @@ pub const Type = extern union {
1166 .array_sentinel => self.cast(Payload.ArraySentinel).?.elem_type,1231 .array_sentinel => self.cast(Payload.ArraySentinel).?.elem_type,
1167 .single_const_pointer => self.castPointer().?.pointee_type,1232 .single_const_pointer => self.castPointer().?.pointee_type,
1168 .single_mut_pointer => self.castPointer().?.pointee_type,1233 .single_mut_pointer => self.castPointer().?.pointee_type,
1234 .many_const_pointer => self.castPointer().?.pointee_type,
1235 .many_mut_pointer => self.castPointer().?.pointee_type,
1236 .c_const_pointer => self.castPointer().?.pointee_type,
1237 .c_mut_pointer => self.castPointer().?.pointee_type,
1169 .array_u8, .array_u8_sentinel_0, .const_slice_u8 => Type.initTag(.u8),1238 .array_u8, .array_u8_sentinel_0, .const_slice_u8 => Type.initTag(.u8),
1170 .single_const_pointer_to_comptime_int => Type.initTag(.comptime_int),1239 .single_const_pointer_to_comptime_int => Type.initTag(.comptime_int),
1171 };1240 };
1172 }1241 }
11731242
1174 /// Asserts that the type is an optional.1243 /// Asserts that the type is an optional.
1175 pub fn optionalChild(self: Type, buf: *Payload.Pointer) Type {1244 pub fn optionalChild(self: Type, buf: *Payload.PointerSimple) Type {
1176 return switch (self.tag()) {1245 return switch (self.tag()) {
1177 .optional => self.cast(Payload.Optional).?.child_type,1246 .optional => self.cast(Payload.Optional).?.child_type,
1178 .optional_single_mut_pointer => {1247 .optional_single_mut_pointer => {
...@@ -1199,7 +1268,7 @@ pub const Type = extern union {...@@ -1199,7 +1268,7 @@ pub const Type = extern union {
1199 return switch (self.tag()) {1268 return switch (self.tag()) {
1200 .optional => self.cast(Payload.Optional).?.child_type,1269 .optional => self.cast(Payload.Optional).?.child_type,
1201 .optional_single_mut_pointer, .optional_single_const_pointer => {1270 .optional_single_mut_pointer, .optional_single_const_pointer => {
1202 const payload = try allocator.create(Payload.Pointer);1271 const payload = try allocator.create(Payload.PointerSimple);
1203 payload.* = .{1272 payload.* = .{
1204 .base = .{1273 .base = .{
1205 .tag = if (self.tag() == .optional_single_const_pointer)1274 .tag = if (self.tag() == .optional_single_const_pointer)
...@@ -1258,6 +1327,10 @@ pub const Type = extern union {...@@ -1258,6 +1327,10 @@ pub const Type = extern union {
1258 .function,1327 .function,
1259 .single_const_pointer,1328 .single_const_pointer,
1260 .single_mut_pointer,1329 .single_mut_pointer,
1330 .many_const_pointer,
1331 .many_mut_pointer,
1332 .c_const_pointer,
1333 .c_mut_pointer,
1261 .single_const_pointer_to_comptime_int,1334 .single_const_pointer_to_comptime_int,
1262 .const_slice_u8,1335 .const_slice_u8,
1263 .int_unsigned,1336 .int_unsigned,
...@@ -1318,6 +1391,10 @@ pub const Type = extern union {...@@ -1318,6 +1391,10 @@ pub const Type = extern union {
1318 .function,1391 .function,
1319 .single_const_pointer,1392 .single_const_pointer,
1320 .single_mut_pointer,1393 .single_mut_pointer,
1394 .many_const_pointer,
1395 .many_mut_pointer,
1396 .c_const_pointer,
1397 .c_mut_pointer,
1321 .single_const_pointer_to_comptime_int,1398 .single_const_pointer_to_comptime_int,
1322 .const_slice_u8,1399 .const_slice_u8,
1323 .int_unsigned,1400 .int_unsigned,
...@@ -1368,6 +1445,10 @@ pub const Type = extern union {...@@ -1368,6 +1445,10 @@ pub const Type = extern union {
1368 .array_u8_sentinel_0,1445 .array_u8_sentinel_0,
1369 .single_const_pointer,1446 .single_const_pointer,
1370 .single_mut_pointer,1447 .single_mut_pointer,
1448 .many_const_pointer,
1449 .many_mut_pointer,
1450 .c_const_pointer,
1451 .c_mut_pointer,
1371 .single_const_pointer_to_comptime_int,1452 .single_const_pointer_to_comptime_int,
1372 .const_slice_u8,1453 .const_slice_u8,
1373 .int_unsigned,1454 .int_unsigned,
...@@ -1429,6 +1510,10 @@ pub const Type = extern union {...@@ -1429,6 +1510,10 @@ pub const Type = extern union {
1429 .array_u8_sentinel_0,1510 .array_u8_sentinel_0,
1430 .single_const_pointer,1511 .single_const_pointer,
1431 .single_mut_pointer,1512 .single_mut_pointer,
1513 .many_const_pointer,
1514 .many_mut_pointer,
1515 .c_const_pointer,
1516 .c_mut_pointer,
1432 .single_const_pointer_to_comptime_int,1517 .single_const_pointer_to_comptime_int,
1433 .const_slice_u8,1518 .const_slice_u8,
1434 .int_signed,1519 .int_signed,
...@@ -1490,6 +1575,10 @@ pub const Type = extern union {...@@ -1490,6 +1575,10 @@ pub const Type = extern union {
1490 .array_u8_sentinel_0,1575 .array_u8_sentinel_0,
1491 .single_const_pointer,1576 .single_const_pointer,
1492 .single_mut_pointer,1577 .single_mut_pointer,
1578 .many_const_pointer,
1579 .many_mut_pointer,
1580 .c_const_pointer,
1581 .c_mut_pointer,
1493 .single_const_pointer_to_comptime_int,1582 .single_const_pointer_to_comptime_int,
1494 .const_slice_u8,1583 .const_slice_u8,
1495 .optional,1584 .optional,
...@@ -1549,6 +1638,10 @@ pub const Type = extern union {...@@ -1549,6 +1638,10 @@ pub const Type = extern union {
1549 .array_u8_sentinel_0,1638 .array_u8_sentinel_0,
1550 .single_const_pointer,1639 .single_const_pointer,
1551 .single_mut_pointer,1640 .single_mut_pointer,
1641 .many_const_pointer,
1642 .many_mut_pointer,
1643 .c_const_pointer,
1644 .c_mut_pointer,
1552 .single_const_pointer_to_comptime_int,1645 .single_const_pointer_to_comptime_int,
1553 .const_slice_u8,1646 .const_slice_u8,
1554 .int_unsigned,1647 .int_unsigned,
...@@ -1637,6 +1730,10 @@ pub const Type = extern union {...@@ -1637,6 +1730,10 @@ pub const Type = extern union {
1637 .array_u8_sentinel_0,1730 .array_u8_sentinel_0,
1638 .single_const_pointer,1731 .single_const_pointer,
1639 .single_mut_pointer,1732 .single_mut_pointer,
1733 .many_const_pointer,
1734 .many_mut_pointer,
1735 .c_const_pointer,
1736 .c_mut_pointer,
1640 .single_const_pointer_to_comptime_int,1737 .single_const_pointer_to_comptime_int,
1641 .const_slice_u8,1738 .const_slice_u8,
1642 .u8,1739 .u8,
...@@ -1701,6 +1798,10 @@ pub const Type = extern union {...@@ -1701,6 +1798,10 @@ pub const Type = extern union {
1701 .array_u8_sentinel_0,1798 .array_u8_sentinel_0,
1702 .single_const_pointer,1799 .single_const_pointer,
1703 .single_mut_pointer,1800 .single_mut_pointer,
1801 .many_const_pointer,
1802 .many_mut_pointer,
1803 .c_const_pointer,
1804 .c_mut_pointer,
1704 .single_const_pointer_to_comptime_int,1805 .single_const_pointer_to_comptime_int,
1705 .const_slice_u8,1806 .const_slice_u8,
1706 .u8,1807 .u8,
...@@ -1764,6 +1865,10 @@ pub const Type = extern union {...@@ -1764,6 +1865,10 @@ pub const Type = extern union {
1764 .array_u8_sentinel_0,1865 .array_u8_sentinel_0,
1765 .single_const_pointer,1866 .single_const_pointer,
1766 .single_mut_pointer,1867 .single_mut_pointer,
1868 .many_const_pointer,
1869 .many_mut_pointer,
1870 .c_const_pointer,
1871 .c_mut_pointer,
1767 .single_const_pointer_to_comptime_int,1872 .single_const_pointer_to_comptime_int,
1768 .const_slice_u8,1873 .const_slice_u8,
1769 .u8,1874 .u8,
...@@ -1827,6 +1932,10 @@ pub const Type = extern union {...@@ -1827,6 +1932,10 @@ pub const Type = extern union {
1827 .array_u8_sentinel_0,1932 .array_u8_sentinel_0,
1828 .single_const_pointer,1933 .single_const_pointer,
1829 .single_mut_pointer,1934 .single_mut_pointer,
1935 .many_const_pointer,
1936 .many_mut_pointer,
1937 .c_const_pointer,
1938 .c_mut_pointer,
1830 .single_const_pointer_to_comptime_int,1939 .single_const_pointer_to_comptime_int,
1831 .const_slice_u8,1940 .const_slice_u8,
1832 .u8,1941 .u8,
...@@ -1887,6 +1996,10 @@ pub const Type = extern union {...@@ -1887,6 +1996,10 @@ pub const Type = extern union {
1887 .array_u8_sentinel_0,1996 .array_u8_sentinel_0,
1888 .single_const_pointer,1997 .single_const_pointer,
1889 .single_mut_pointer,1998 .single_mut_pointer,
1999 .many_const_pointer,
2000 .many_mut_pointer,
2001 .c_const_pointer,
2002 .c_mut_pointer,
1890 .single_const_pointer_to_comptime_int,2003 .single_const_pointer_to_comptime_int,
1891 .const_slice_u8,2004 .const_slice_u8,
1892 .u8,2005 .u8,
...@@ -1947,6 +2060,10 @@ pub const Type = extern union {...@@ -1947,6 +2060,10 @@ pub const Type = extern union {
1947 .array_u8_sentinel_0,2060 .array_u8_sentinel_0,
1948 .single_const_pointer,2061 .single_const_pointer,
1949 .single_mut_pointer,2062 .single_mut_pointer,
2063 .many_const_pointer,
2064 .many_mut_pointer,
2065 .c_const_pointer,
2066 .c_mut_pointer,
1950 .single_const_pointer_to_comptime_int,2067 .single_const_pointer_to_comptime_int,
1951 .const_slice_u8,2068 .const_slice_u8,
1952 .u8,2069 .u8,
...@@ -2027,6 +2144,10 @@ pub const Type = extern union {...@@ -2027,6 +2144,10 @@ pub const Type = extern union {
2027 .array_u8_sentinel_0,2144 .array_u8_sentinel_0,
2028 .single_const_pointer,2145 .single_const_pointer,
2029 .single_mut_pointer,2146 .single_mut_pointer,
2147 .many_const_pointer,
2148 .many_mut_pointer,
2149 .c_const_pointer,
2150 .c_mut_pointer,
2030 .single_const_pointer_to_comptime_int,2151 .single_const_pointer_to_comptime_int,
2031 .const_slice_u8,2152 .const_slice_u8,
2032 .optional,2153 .optional,
...@@ -2109,7 +2230,13 @@ pub const Type = extern union {...@@ -2109,7 +2230,13 @@ pub const Type = extern union {
2109 ty = ty.elemType();2230 ty = ty.elemType();
2110 continue;2231 continue;
2111 },2232 },
2112 .single_const_pointer, .single_mut_pointer => {2233 .many_const_pointer,
2234 .many_mut_pointer,
2235 .c_const_pointer,
2236 .c_mut_pointer,
2237 .single_const_pointer,
2238 .single_mut_pointer,
2239 => {
2113 const ptr = ty.castPointer().?;2240 const ptr = ty.castPointer().?;
2114 ty = ptr.pointee_type;2241 ty = ptr.pointee_type;
2115 continue;2242 continue;
...@@ -2167,11 +2294,17 @@ pub const Type = extern union {...@@ -2167,11 +2294,17 @@ pub const Type = extern union {
2167 .array_u8_sentinel_0,2294 .array_u8_sentinel_0,
2168 .single_const_pointer,2295 .single_const_pointer,
2169 .single_mut_pointer,2296 .single_mut_pointer,
2297 .many_const_pointer,
2298 .many_mut_pointer,
2170 .optional,2299 .optional,
2171 .optional_single_mut_pointer,2300 .optional_single_mut_pointer,
2172 .optional_single_const_pointer,2301 .optional_single_const_pointer,
2173 .enum_literal,2302 .enum_literal,
2174 => return false,2303 => return false,
2304
2305 .c_const_pointer,
2306 .c_mut_pointer,
2307 => return true,
2175 };2308 };
2176 }2309 }
21772310
...@@ -2231,6 +2364,10 @@ pub const Type = extern union {...@@ -2231,6 +2364,10 @@ pub const Type = extern union {
2231 array_sentinel,2364 array_sentinel,
2232 single_const_pointer,2365 single_const_pointer,
2233 single_mut_pointer,2366 single_mut_pointer,
2367 many_const_pointer,
2368 many_mut_pointer,
2369 c_const_pointer,
2370 c_mut_pointer,
2234 int_signed,2371 int_signed,
2235 int_unsigned,2372 int_unsigned,
2236 function,2373 function,
...@@ -2272,7 +2409,7 @@ pub const Type = extern union {...@@ -2272,7 +2409,7 @@ pub const Type = extern union {
2272 elem_type: Type,2409 elem_type: Type,
2273 };2410 };
22742411
2275 pub const Pointer = struct {2412 pub const PointerSimple = struct {
2276 base: Payload,2413 base: Payload,
22772414
2278 pointee_type: Type,2415 pointee_type: Type,
src-self-hosted/zir.zig+18-1
...@@ -198,6 +198,14 @@ pub const Inst = struct {...@@ -198,6 +198,14 @@ pub const Inst = struct {
198 single_const_ptr_type,198 single_const_ptr_type,
199 /// Create a mutable pointer type based on the element type. `*T`199 /// Create a mutable pointer type based on the element type. `*T`
200 single_mut_ptr_type,200 single_mut_ptr_type,
201 /// Create a const pointer type based on the element type. `[*]const T`
202 many_const_ptr_type,
203 /// Create a mutable pointer type based on the element type. `[*]T`
204 many_mut_ptr_type,
205 /// Create a const pointer type based on the element type. `[*c]const T`
206 c_const_ptr_type,
207 /// Create a mutable pointer type based on the element type. `[*c]T`
208 c_mut_ptr_type,
201 /// Create a pointer type with attributes209 /// Create a pointer type with attributes
202 ptr_type,210 ptr_type,
203 /// Write a value to a pointer. For loading, see `deref`.211 /// Write a value to a pointer. For loading, see `deref`.
...@@ -262,6 +270,10 @@ pub const Inst = struct {...@@ -262,6 +270,10 @@ pub const Inst = struct {
262 .typeof,270 .typeof,
263 .single_const_ptr_type,271 .single_const_ptr_type,
264 .single_mut_ptr_type,272 .single_mut_ptr_type,
273 .many_const_ptr_type,
274 .many_mut_ptr_type,
275 .c_const_ptr_type,
276 .c_mut_ptr_type,
265 .optional_type,277 .optional_type,
266 .unwrap_optional_safe,278 .unwrap_optional_safe,
267 .unwrap_optional_unsafe,279 .unwrap_optional_unsafe,
...@@ -400,6 +412,10 @@ pub const Inst = struct {...@@ -400,6 +412,10 @@ pub const Inst = struct {
400 .shr,412 .shr,
401 .single_const_ptr_type,413 .single_const_ptr_type,
402 .single_mut_ptr_type,414 .single_mut_ptr_type,
415 .many_const_ptr_type,
416 .many_mut_ptr_type,
417 .c_const_ptr_type,
418 .c_mut_ptr_type,
403 .store,419 .store,
404 .str,420 .str,
405 .sub,421 .sub,
...@@ -859,6 +875,7 @@ pub const Inst = struct {...@@ -859,6 +875,7 @@ pub const Inst = struct {
859 @"const": bool = true,875 @"const": bool = true,
860 @"volatile": bool = false,876 @"volatile": bool = false,
861 sentinel: ?*Inst = null,877 sentinel: ?*Inst = null,
878 size: std.builtin.TypeInfo.Pointer.Size = .One,
862 },879 },
863 };880 };
864881
...@@ -2443,7 +2460,7 @@ const EmitZIR = struct {...@@ -2443,7 +2460,7 @@ const EmitZIR = struct {
2443 }2460 }
2444 },2461 },
2445 .Optional => {2462 .Optional => {
2446 var buf: Type.Payload.Pointer = undefined;2463 var buf: Type.Payload.PointerSimple = undefined;
2447 const inst = try self.arena.allocator.create(Inst.UnOp);2464 const inst = try self.arena.allocator.create(Inst.UnOp);
2448 inst.* = .{2465 inst.* = .{
2449 .base = .{2466 .base = .{
src-self-hosted/zir_sema.zig+12-14
...@@ -51,8 +51,12 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!...@@ -51,8 +51,12 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!
51 .ref => return analyzeInstRef(mod, scope, old_inst.castTag(.ref).?),51 .ref => return analyzeInstRef(mod, scope, old_inst.castTag(.ref).?),
52 .ret_ptr => return analyzeInstRetPtr(mod, scope, old_inst.castTag(.ret_ptr).?),52 .ret_ptr => return analyzeInstRetPtr(mod, scope, old_inst.castTag(.ret_ptr).?),
53 .ret_type => return analyzeInstRetType(mod, scope, old_inst.castTag(.ret_type).?),53 .ret_type => return analyzeInstRetType(mod, scope, old_inst.castTag(.ret_type).?),
54 .single_const_ptr_type => return analyzeInstSingleConstPtrType(mod, scope, old_inst.castTag(.single_const_ptr_type).?),54 .single_const_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.single_const_ptr_type).?, false, .One),
55 .single_mut_ptr_type => return analyzeInstSingleMutPtrType(mod, scope, old_inst.castTag(.single_mut_ptr_type).?),55 .single_mut_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.single_mut_ptr_type).?, true, .One),
56 .many_const_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.many_const_ptr_type).?, false, .Many),
57 .many_mut_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.many_mut_ptr_type).?, true, .Many),
58 .c_const_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.c_const_ptr_type).?, false, .C),
59 .c_mut_ptr_type => return analyzeInstSimplePtrType(mod, scope, old_inst.castTag(.c_mut_ptr_type).?, true, .C),
56 .ptr_type => return analyzeInstPtrType(mod, scope, old_inst.castTag(.ptr_type).?),60 .ptr_type => return analyzeInstPtrType(mod, scope, old_inst.castTag(.ptr_type).?),
57 .store => return analyzeInstStore(mod, scope, old_inst.castTag(.store).?),61 .store => return analyzeInstStore(mod, scope, old_inst.castTag(.store).?),
58 .str => return analyzeInstStr(mod, scope, old_inst.castTag(.str).?),62 .str => return analyzeInstStr(mod, scope, old_inst.castTag(.str).?),
...@@ -324,7 +328,7 @@ fn analyzeInstRetPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerErr...@@ -324,7 +328,7 @@ fn analyzeInstRetPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.NoOp) InnerErr
324328
325fn analyzeInstRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {329fn analyzeInstRef(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
326 const operand = try resolveInst(mod, scope, inst.positionals.operand);330 const operand = try resolveInst(mod, scope, inst.positionals.operand);
327 const ptr_type = try mod.singlePtrType(scope, inst.base.src, false, operand.ty);331 const ptr_type = try mod.simplePtrType(scope, inst.base.src, operand.ty, false, .One);
328332
329 if (operand.value()) |val| {333 if (operand.value()) |val| {
330 const ref_payload = try scope.arena().create(Value.Payload.RefVal);334 const ref_payload = try scope.arena().create(Value.Payload.RefVal);
...@@ -369,7 +373,7 @@ fn analyzeInstAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErro...@@ -369,7 +373,7 @@ fn analyzeInstAlloc(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerErro
369 if (!var_type.isValidVarType(false)) {373 if (!var_type.isValidVarType(false)) {
370 return mod.fail(scope, inst.base.src, "variable of type '{}' must be const or comptime", .{var_type});374 return mod.fail(scope, inst.base.src, "variable of type '{}' must be const or comptime", .{var_type});
371 }375 }
372 const ptr_type = try mod.singlePtrType(scope, inst.base.src, true, var_type);376 const ptr_type = try mod.simplePtrType(scope, inst.base.src, var_type, true, .One);
373 const b = try mod.requireRuntimeBlock(scope, inst.base.src);377 const b = try mod.requireRuntimeBlock(scope, inst.base.src);
374 return mod.addNoOp(b, inst.base.src, ptr_type, .alloc);378 return mod.addNoOp(b, inst.base.src, ptr_type, .alloc);
375}379}
...@@ -723,7 +727,7 @@ fn analyzeInstUnwrapOptional(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp...@@ -723,7 +727,7 @@ fn analyzeInstUnwrapOptional(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp
723 }727 }
724728
725 const child_type = try operand.ty.elemType().optionalChildAlloc(scope.arena());729 const child_type = try operand.ty.elemType().optionalChildAlloc(scope.arena());
726 const child_pointer = try mod.singlePtrType(scope, unwrap.base.src, operand.ty.isConstPtr(), child_type);730 const child_pointer = try mod.simplePtrType(scope, unwrap.base.src, child_type, operand.ty.isConstPtr(), .One);
727731
728 if (operand.value()) |val| {732 if (operand.value()) |val| {
729 if (val.isNull()) {733 if (val.isNull()) {
...@@ -940,7 +944,7 @@ fn analyzeInstElemPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.ElemPtr) Inne...@@ -940,7 +944,7 @@ fn analyzeInstElemPtr(mod: *Module, scope: *Scope, inst: *zir.Inst.ElemPtr) Inne
940 // required a larger index.944 // required a larger index.
941 const elem_ptr = try array_ptr_val.elemPtr(scope.arena(), @intCast(usize, index_u64));945 const elem_ptr = try array_ptr_val.elemPtr(scope.arena(), @intCast(usize, index_u64));
942946
943 const type_payload = try scope.arena().create(Type.Payload.Pointer);947 const type_payload = try scope.arena().create(Type.Payload.PointerSimple);
944 type_payload.* = .{948 type_payload.* = .{
945 .base = .{ .tag = .single_const_pointer },949 .base = .{ .tag = .single_const_pointer },
946 .pointee_type = array_ptr.ty.elemType().elemType(),950 .pointee_type = array_ptr.ty.elemType().elemType(),
...@@ -1311,15 +1315,9 @@ fn analyzeDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) InnerErr...@@ -1311,15 +1315,9 @@ fn analyzeDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) InnerErr
1311 return decl;1315 return decl;
1312}1316}
13131317
1314fn analyzeInstSingleConstPtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {1318fn analyzeInstSimplePtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp, mutable: bool, size: std.builtin.TypeInfo.Pointer.Size) InnerError!*Inst {
1315 const elem_type = try resolveType(mod, scope, inst.positionals.operand);1319 const elem_type = try resolveType(mod, scope, inst.positionals.operand);
1316 const ty = try mod.singlePtrType(scope, inst.base.src, false, elem_type);1320 const ty = try mod.simplePtrType(scope, inst.base.src, elem_type, mutable, size);
1317 return mod.constType(scope, inst.base.src, ty);
1318}
1319
1320fn analyzeInstSingleMutPtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
1321 const elem_type = try resolveType(mod, scope, inst.positionals.operand);
1322 const ty = try mod.singlePtrType(scope, inst.base.src, true, elem_type);
1323 return mod.constType(scope, inst.base.src, ty);1321 return mod.constType(scope, inst.base.src, ty);
1324}1322}
13251323