| author | |
| committer | |
| log | 13b2f1e90ba9e373c655fc881836209c4fa381fa |
| tree | e9a84642b41805a0c46e54d7e9718b88971051c7 |
| parent | ece4a2fc512bffba3845bf611370f5ea436c57b4 |
| signature |
5 files changed, 40 insertions(+), 21 deletions(-)
src-self-hosted/Module.zig-1| ... | ... | @@ -2433,7 +2433,6 @@ fn wrapOptional(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*In |
| 2433 | 2433 | return self.constInst(scope, inst.src, .{ .ty = dest_type, .val = val }); |
| 2434 | 2434 | } |
| 2435 | 2435 | |
| 2436 | // TODO how do we get the result location | |
| 2437 | 2436 | const b = try self.requireRuntimeBlock(scope, inst.src); |
| 2438 | 2437 | return self.addUnOp(b, inst.src, dest_type, .wrap_optional, inst); |
| 2439 | 2438 | } |
src-self-hosted/astgen.zig+12-13| ... | ... | @@ -453,8 +453,6 @@ fn boolNot(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp) InnerErr |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | fn addressOf(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp) InnerError!*zir.Inst { |
| 456 | const tree = scope.tree(); | |
| 457 | const src = tree.token_locs[node.op_token].start; | |
| 458 | 456 | return expr(mod, scope, .lvalue, node.rhs); |
| 459 | 457 | } |
| 460 | 458 | |
| ... | ... | @@ -490,8 +488,6 @@ fn ptrType(mod: *Module, scope: *Scope, node: *ast.Node.PtrType) InnerError!*zir |
| 490 | 488 | .single_const_ptr_type, child_type); |
| 491 | 489 | } |
| 492 | 490 | |
| 493 | const child_type = try expr(mod, scope, .{ .ty = meta_type }, node.rhs); | |
| 494 | ||
| 495 | 491 | var kw_args: std.meta.fieldInfo(zir.Inst.PtrType, "kw_args").field_type = .{}; |
| 496 | 492 | kw_args.@"allowzero" = node.ptr_info.allowzero_token != null; |
| 497 | 493 | if (node.ptr_info.align_info) |some| { |
| ... | ... | @@ -504,7 +500,12 @@ fn ptrType(mod: *Module, scope: *Scope, node: *ast.Node.PtrType) InnerError!*zir |
| 504 | 500 | kw_args.@"const" = node.ptr_info.const_token != null; |
| 505 | 501 | kw_args.@"volatile" = node.ptr_info.volatile_token != null; |
| 506 | 502 | if (node.ptr_info.sentinel) |some| { |
| 507 | kw_args.sentinel = try expr(mod, scope, .{ .ty = child_type }, some); | |
| 503 | kw_args.sentinel = try expr(mod, scope, .none, some); | |
| 504 | } | |
| 505 | ||
| 506 | const child_type = try expr(mod, scope, .{ .ty = meta_type }, node.rhs); | |
| 507 | if (kw_args.sentinel) |some| { | |
| 508 | kw_args.sentinel = try addZIRBinOp(mod, scope, some.src, .as, child_type, some); | |
| 508 | 509 | } |
| 509 | 510 | |
| 510 | 511 | return addZIRInst(mod, scope, src, zir.Inst.PtrType, .{ .child_type = child_type }, kw_args); |
| ... | ... | @@ -629,7 +630,9 @@ const CondKind = union(enum) { |
| 629 | 630 | const payload = payload_node.?.castTag(.PointerPayload).?; |
| 630 | 631 | const is_ptr = payload.ptr_token != null; |
| 631 | 632 | const ident_node = payload.value_symbol.castTag(.Identifier).?; |
| 632 | const ident_name = try identifierTokenString(mod, &then_scope.base, ident_node.token); | |
| 633 | ||
| 634 | // This intentionally does not support @"_" syntax. | |
| 635 | const ident_name = then_scope.base.tree().tokenSlice(ident_node.token); | |
| 633 | 636 | if (mem.eql(u8, ident_name, "_")) { |
| 634 | 637 | if (is_ptr) |
| 635 | 638 | return mod.failTok(&then_scope.base, payload.ptr_token.?, "pointer modifier invalid on discard", .{}); |
| ... | ... | @@ -646,7 +649,9 @@ const CondKind = union(enum) { |
| 646 | 649 | |
| 647 | 650 | const payload = payload_node.?.castTag(.Payload).?; |
| 648 | 651 | const ident_node = payload.error_symbol.castTag(.Identifier).?; |
| 649 | const ident_name = try identifierTokenString(mod, &else_scope.base, ident_node.token); | |
| 652 | ||
| 653 | // This intentionally does not support @"_" syntax. | |
| 654 | const ident_name = else_scope.base.tree().tokenSlice(ident_node.token); | |
| 650 | 655 | if (mem.eql(u8, ident_name, "_")) { |
| 651 | 656 | return &else_scope.base; |
| 652 | 657 | } |
| ... | ... | @@ -660,9 +665,6 @@ fn ifExpr(mod: *Module, scope: *Scope, rl: ResultLoc, if_node: *ast.Node.If) Inn |
| 660 | 665 | if (if_node.payload) |_| cond_kind = .{ .optional = null }; |
| 661 | 666 | if (if_node.@"else") |else_node| { |
| 662 | 667 | if (else_node.payload) |payload| { |
| 663 | if (cond_kind != .optional) { | |
| 664 | return mod.failNode(scope, payload, "else payload invalid on bool conditions", .{}); | |
| 665 | } | |
| 666 | 668 | cond_kind = .{ .err_union = null }; |
| 667 | 669 | } |
| 668 | 670 | } |
| ... | ... | @@ -760,9 +762,6 @@ fn whileExpr(mod: *Module, scope: *Scope, rl: ResultLoc, while_node: *ast.Node.W |
| 760 | 762 | if (while_node.payload) |_| cond_kind = .{ .optional = null }; |
| 761 | 763 | if (while_node.@"else") |else_node| { |
| 762 | 764 | if (else_node.payload) |payload| { |
| 763 | if (cond_kind != .optional) { | |
| 764 | return mod.failNode(scope, payload, "else payload invalid on bool conditions", .{}); | |
| 765 | } | |
| 766 | 765 | cond_kind = .{ .err_union = null }; |
| 767 | 766 | } |
| 768 | 767 | } |
src-self-hosted/codegen.zig+2-2| ... | ... | @@ -2052,7 +2052,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2052 | 2052 | return mcv; |
| 2053 | 2053 | } |
| 2054 | 2054 | |
| 2055 | fn genTypedValue(self: *Self, src: usize, typed_value: TypedValue) error{ CodegenFail, OutOfMemory }!MCValue { | |
| 2055 | fn genTypedValue(self: *Self, src: usize, typed_value: TypedValue) InnerError!MCValue { | |
| 2056 | 2056 | if (typed_value.val.isUndef()) |
| 2057 | 2057 | return MCValue{ .undef = {} }; |
| 2058 | 2058 | const ptr_bits = self.target.cpu.arch.ptrBitWidth(); |
| ... | ... | @@ -2199,7 +2199,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2199 | 2199 | }; |
| 2200 | 2200 | } |
| 2201 | 2201 | |
| 2202 | fn fail(self: *Self, src: usize, comptime format: []const u8, args: anytype) error{ CodegenFail, OutOfMemory } { | |
| 2202 | fn fail(self: *Self, src: usize, comptime format: []const u8, args: anytype) InnerError { | |
| 2203 | 2203 | @setCold(true); |
| 2204 | 2204 | assert(self.err_msg == null); |
| 2205 | 2205 | self.err_msg = try ErrorMsg.create(self.bin_file.base.allocator, src, format, args); |
src-self-hosted/type.zig+25-3| ... | ... | @@ -362,7 +362,7 @@ pub const Type = extern union { |
| 362 | 362 | .single_mut_pointer, |
| 363 | 363 | .optional_single_mut_pointer, |
| 364 | 364 | .optional_single_const_pointer, |
| 365 | => return self.copyPayloadSingleField(allocator, Payload.Pointer, "pointee_type"), | |
| 365 | => return self.copyPayloadSingleField(allocator, Payload.Pointer, "pointee_type"), | |
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | |
| ... | ... | @@ -1086,14 +1086,14 @@ pub const Type = extern union { |
| 1086 | 1086 | .optional_single_mut_pointer => { |
| 1087 | 1087 | buf.* = .{ |
| 1088 | 1088 | .base = .{ .tag = .single_mut_pointer }, |
| 1089 | .pointee_type = self.castPointer().?.pointee_type | |
| 1089 | .pointee_type = self.castPointer().?.pointee_type, | |
| 1090 | 1090 | }; |
| 1091 | 1091 | return Type.initPayload(&buf.base); |
| 1092 | 1092 | }, |
| 1093 | 1093 | .optional_single_const_pointer => { |
| 1094 | 1094 | buf.* = .{ |
| 1095 | 1095 | .base = .{ .tag = .single_const_pointer }, |
| 1096 | .pointee_type = self.castPointer().?.pointee_type | |
| 1096 | .pointee_type = self.castPointer().?.pointee_type, | |
| 1097 | 1097 | }; |
| 1098 | 1098 | return Type.initPayload(&buf.base); |
| 1099 | 1099 | }, |
| ... | ... | @@ -1101,6 +1101,28 @@ pub const Type = extern union { |
| 1101 | 1101 | }; |
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | /// Asserts that the type is an optional. | |
| 1105 | /// Same as `optionalChild` but allocates the buffer if needed. | |
| 1106 | pub fn optionalChildAlloc(self: Type, allocator: *Allocator) !Type { | |
| 1107 | return switch (self.tag()) { | |
| 1108 | .optional => self.cast(Payload.Optional).?.child_type, | |
| 1109 | .optional_single_mut_pointer, .optional_single_const_pointer => { | |
| 1110 | const payload = try allocator.create(Payload.Pointer); | |
| 1111 | payload.* = .{ | |
| 1112 | .base = .{ | |
| 1113 | .tag = if (self.tag() == .optional_single_const_pointer) | |
| 1114 | .single_const_pointer | |
| 1115 | else | |
| 1116 | .single_mut_pointer, | |
| 1117 | }, | |
| 1118 | .pointee_type = self.castPointer().?.pointee_type, | |
| 1119 | }; | |
| 1120 | return Type.initPayload(&payload.base); | |
| 1121 | }, | |
| 1122 | else => unreachable, | |
| 1123 | }; | |
| 1124 | } | |
| 1125 | ||
| 1104 | 1126 | /// Asserts the type is an array or vector. |
| 1105 | 1127 | pub fn arrayLen(self: Type) u64 { |
| 1106 | 1128 | return switch (self.tag()) { |
src-self-hosted/zir_sema.zig+1-2| ... | ... | @@ -710,8 +710,7 @@ fn analyzeInstUnwrapOptional(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp |
| 710 | 710 | return mod.fail(scope, unwrap.base.src, "expected optional type, found {}", .{operand.ty.elemType()}); |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | var buf: Type.Payload.Pointer = undefined; | |
| 714 | const child_type = try operand.ty.elemType().optionalChild(&buf).copy(scope.arena()); | |
| 713 | const child_type = try operand.ty.elemType().optionalChildAlloc(scope.arena()); | |
| 715 | 714 | const child_pointer = try mod.singlePtrType(scope, unwrap.base.src, operand.ty.isConstPtr(), child_type); |
| 716 | 715 | |
| 717 | 716 | if (operand.value()) |val| { |