authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-08-16 21:51:05+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-08-17 19:21:03+03:00
log13b2f1e90ba9e373c655fc881836209c4fa381fa
treee9a84642b41805a0c46e54d7e9718b88971051c7
parentece4a2fc512bffba3845bf611370f5ea436c57b4
signaturelock-open Commit is signed but in an unrecognized format.

address review feedback


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
24332433 return self.constInst(scope, inst.src, .{ .ty = dest_type, .val = val });
24342434 }
24352435
2436 // TODO how do we get the result location
24372436 const b = try self.requireRuntimeBlock(scope, inst.src);
24382437 return self.addUnOp(b, inst.src, dest_type, .wrap_optional, inst);
24392438}
src-self-hosted/astgen.zig+12-13
......@@ -453,8 +453,6 @@ fn boolNot(mod: *Module, scope: *Scope, node: *ast.Node.SimplePrefixOp) InnerErr
453453}
454454
455455fn 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;
458456 return expr(mod, scope, .lvalue, node.rhs);
459457}
460458
......@@ -490,8 +488,6 @@ fn ptrType(mod: *Module, scope: *Scope, node: *ast.Node.PtrType) InnerError!*zir
490488 .single_const_ptr_type, child_type);
491489 }
492490
493 const child_type = try expr(mod, scope, .{ .ty = meta_type }, node.rhs);
494
495491 var kw_args: std.meta.fieldInfo(zir.Inst.PtrType, "kw_args").field_type = .{};
496492 kw_args.@"allowzero" = node.ptr_info.allowzero_token != null;
497493 if (node.ptr_info.align_info) |some| {
......@@ -504,7 +500,12 @@ fn ptrType(mod: *Module, scope: *Scope, node: *ast.Node.PtrType) InnerError!*zir
504500 kw_args.@"const" = node.ptr_info.const_token != null;
505501 kw_args.@"volatile" = node.ptr_info.volatile_token != null;
506502 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);
508509 }
509510
510511 return addZIRInst(mod, scope, src, zir.Inst.PtrType, .{ .child_type = child_type }, kw_args);
......@@ -629,7 +630,9 @@ const CondKind = union(enum) {
629630 const payload = payload_node.?.castTag(.PointerPayload).?;
630631 const is_ptr = payload.ptr_token != null;
631632 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);
633636 if (mem.eql(u8, ident_name, "_")) {
634637 if (is_ptr)
635638 return mod.failTok(&then_scope.base, payload.ptr_token.?, "pointer modifier invalid on discard", .{});
......@@ -646,7 +649,9 @@ const CondKind = union(enum) {
646649
647650 const payload = payload_node.?.castTag(.Payload).?;
648651 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);
650655 if (mem.eql(u8, ident_name, "_")) {
651656 return &else_scope.base;
652657 }
......@@ -660,9 +665,6 @@ fn ifExpr(mod: *Module, scope: *Scope, rl: ResultLoc, if_node: *ast.Node.If) Inn
660665 if (if_node.payload) |_| cond_kind = .{ .optional = null };
661666 if (if_node.@"else") |else_node| {
662667 if (else_node.payload) |payload| {
663 if (cond_kind != .optional) {
664 return mod.failNode(scope, payload, "else payload invalid on bool conditions", .{});
665 }
666668 cond_kind = .{ .err_union = null };
667669 }
668670 }
......@@ -760,9 +762,6 @@ fn whileExpr(mod: *Module, scope: *Scope, rl: ResultLoc, while_node: *ast.Node.W
760762 if (while_node.payload) |_| cond_kind = .{ .optional = null };
761763 if (while_node.@"else") |else_node| {
762764 if (else_node.payload) |payload| {
763 if (cond_kind != .optional) {
764 return mod.failNode(scope, payload, "else payload invalid on bool conditions", .{});
765 }
766765 cond_kind = .{ .err_union = null };
767766 }
768767 }
src-self-hosted/codegen.zig+2-2
......@@ -2052,7 +2052,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
20522052 return mcv;
20532053 }
20542054
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 {
20562056 if (typed_value.val.isUndef())
20572057 return MCValue{ .undef = {} };
20582058 const ptr_bits = self.target.cpu.arch.ptrBitWidth();
......@@ -2199,7 +2199,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
21992199 };
22002200 }
22012201
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 {
22032203 @setCold(true);
22042204 assert(self.err_msg == null);
22052205 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 {
362362 .single_mut_pointer,
363363 .optional_single_mut_pointer,
364364 .optional_single_const_pointer,
365 => return self.copyPayloadSingleField(allocator, Payload.Pointer, "pointee_type"),
365 => return self.copyPayloadSingleField(allocator, Payload.Pointer, "pointee_type"),
366366 }
367367 }
368368
......@@ -1086,14 +1086,14 @@ pub const Type = extern union {
10861086 .optional_single_mut_pointer => {
10871087 buf.* = .{
10881088 .base = .{ .tag = .single_mut_pointer },
1089 .pointee_type = self.castPointer().?.pointee_type
1089 .pointee_type = self.castPointer().?.pointee_type,
10901090 };
10911091 return Type.initPayload(&buf.base);
10921092 },
10931093 .optional_single_const_pointer => {
10941094 buf.* = .{
10951095 .base = .{ .tag = .single_const_pointer },
1096 .pointee_type = self.castPointer().?.pointee_type
1096 .pointee_type = self.castPointer().?.pointee_type,
10971097 };
10981098 return Type.initPayload(&buf.base);
10991099 },
......@@ -1101,6 +1101,28 @@ pub const Type = extern union {
11011101 };
11021102 }
11031103
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
11041126 /// Asserts the type is an array or vector.
11051127 pub fn arrayLen(self: Type) u64 {
11061128 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
710710 return mod.fail(scope, unwrap.base.src, "expected optional type, found {}", .{operand.ty.elemType()});
711711 }
712712
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());
715714 const child_pointer = try mod.singlePtrType(scope, unwrap.base.src, operand.ty.isConstPtr(), child_type);
716715
717716 if (operand.value()) |val| {