authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-06-02 01:15:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:59-07:00
log04e66e6b4deb67aef9a4064decd82a678cb7ec82
tree85c7c8127147467d13707adbc255fc1239b1b7f6
parentfdfe730487972f089786938706f311b1f8631333

InternPool: add optional coercion


4 files changed, 31 insertions(+), 11 deletions(-)

lib/std/child_process.zig+3-3
......@@ -542,7 +542,7 @@ pub const ChildProcess = struct {
542542 } else if (builtin.output_mode == .Exe) {
543543 // Then we have Zig start code and this works.
544544 // TODO type-safety for null-termination of `os.environ`.
545 break :m @ptrCast([*:null]?[*:0]const u8, os.environ.ptr);
545 break :m @ptrCast([*:null]const ?[*:0]const u8, os.environ.ptr);
546546 } else {
547547 // TODO come up with a solution for this.
548548 @compileError("missing std lib enhancement: ChildProcess implementation has no way to collect the environment variables to forward to the child process");
......@@ -1425,9 +1425,9 @@ pub fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const EnvMap) !
14251425 return try allocator.realloc(result, i);
14261426}
14271427
1428pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) ![:null]?[*:0]const u8 {
1428pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) ![:null]?[*:0]u8 {
14291429 const envp_count = env_map.count();
1430 const envp_buf = try arena.allocSentinel(?[*:0]const u8, envp_count, null);
1430 const envp_buf = try arena.allocSentinel(?[*:0]u8, envp_count, null);
14311431 {
14321432 var it = env_map.iterator();
14331433 var i: usize = 0;
lib/std/process.zig+1-1
......@@ -1143,7 +1143,7 @@ pub fn execve(
11431143 } else if (builtin.output_mode == .Exe) {
11441144 // Then we have Zig start code and this works.
11451145 // TODO type-safety for null-termination of `os.environ`.
1146 break :m @ptrCast([*:null]?[*:0]const u8, os.environ.ptr);
1146 break :m @ptrCast([*:null]const ?[*:0]const u8, os.environ.ptr);
11471147 } else {
11481148 // TODO come up with a solution for this.
11491149 @compileError("missing std lib enhancement: std.process.execv implementation has no way to collect the environment variables to forward to the child process");
src/InternPool.zig+12-3
......@@ -4614,18 +4614,27 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
46144614 .int => |int| return ip.getCoerced(gpa, int, new_ty),
46154615 else => {},
46164616 },
4617 .opt => |opt| if (ip.isPointerType(new_ty))
4618 return switch (opt.val) {
4617 .opt => |opt| switch (ip.indexToKey(new_ty)) {
4618 .ptr_type => |ptr_type| return switch (opt.val) {
46194619 .none => try ip.get(gpa, .{ .ptr = .{
46204620 .ty = new_ty,
46214621 .addr = .{ .int = .zero_usize },
4622 .len = switch (ip.indexToKey(new_ty).ptr_type.flags.size) {
4622 .len = switch (ptr_type.flags.size) {
46234623 .One, .Many, .C => .none,
46244624 .Slice => try ip.get(gpa, .{ .undef = .usize_type }),
46254625 },
46264626 } }),
46274627 else => |payload| try ip.getCoerced(gpa, payload, new_ty),
46284628 },
4629 .opt_type => |child_type| return try ip.get(gpa, .{ .opt = .{
4630 .ty = new_ty,
4631 .val = switch (opt.val) {
4632 .none => .none,
4633 else => try ip.getCoerced(gpa, opt.val, child_type),
4634 },
4635 } }),
4636 else => {},
4637 },
46294638 .err => |err| if (ip.isErrorSetType(new_ty))
46304639 return ip.get(gpa, .{ .err = .{
46314640 .ty = new_ty,
src/Sema.zig+15-4
......@@ -26470,7 +26470,11 @@ fn coerceExtra(
2647026470 }
2647126471
2647226472 if (dest_info.sentinel == null or inst_info.sentinel == null or
26473 !dest_info.sentinel.?.eql(inst_info.sentinel.?, dest_info.pointee_type, mod))
26473 !dest_info.sentinel.?.eql(
26474 try mod.getCoerced(inst_info.sentinel.?, dest_info.pointee_type),
26475 dest_info.pointee_type,
26476 mod,
26477 ))
2647426478 break :p;
2647526479
2647626480 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
......@@ -27350,7 +27354,11 @@ fn coerceInMemoryAllowed(
2735027354 }
2735127355 const ok_sent = dest_info.sentinel == null or
2735227356 (src_info.sentinel != null and
27353 dest_info.sentinel.?.eql(src_info.sentinel.?, dest_info.elem_type, mod));
27357 dest_info.sentinel.?.eql(
27358 try mod.getCoerced(src_info.sentinel.?, dest_info.elem_type),
27359 dest_info.elem_type,
27360 mod,
27361 ));
2735427362 if (!ok_sent) {
2735527363 return InMemoryCoercionResult{ .array_sentinel = .{
2735627364 .actual = src_info.sentinel orelse Value.@"unreachable",
......@@ -27704,8 +27712,11 @@ fn coerceInMemoryAllowedPtrs(
2770427712 }
2770527713
2770627714 const ok_sent = dest_info.sentinel == null or src_info.size == .C or
27707 (src_info.sentinel != null and
27708 dest_info.sentinel.?.eql(src_info.sentinel.?, dest_info.pointee_type, sema.mod));
27715 (src_info.sentinel != null and dest_info.sentinel.?.eql(
27716 try mod.getCoerced(src_info.sentinel.?, dest_info.pointee_type),
27717 dest_info.pointee_type,
27718 sema.mod,
27719 ));
2770927720 if (!ok_sent) {
2771027721 return InMemoryCoercionResult{ .ptr_sentinel = .{
2771127722 .actual = src_info.sentinel orelse Value.@"unreachable",