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 {...@@ -542,7 +542,7 @@ pub const ChildProcess = struct {
542 } else if (builtin.output_mode == .Exe) {542 } else if (builtin.output_mode == .Exe) {
543 // Then we have Zig start code and this works.543 // Then we have Zig start code and this works.
544 // TODO type-safety for null-termination of `os.environ`.544 // 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);
546 } else {546 } else {
547 // TODO come up with a solution for this.547 // TODO come up with a solution for this.
548 @compileError("missing std lib enhancement: ChildProcess implementation has no way to collect the environment variables to forward to the child process");548 @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) !...@@ -1425,9 +1425,9 @@ pub fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const EnvMap) !
1425 return try allocator.realloc(result, i);1425 return try allocator.realloc(result, i);
1426}1426}
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 {
1429 const envp_count = env_map.count();1429 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);
1431 {1431 {
1432 var it = env_map.iterator();1432 var it = env_map.iterator();
1433 var i: usize = 0;1433 var i: usize = 0;
lib/std/process.zig+1-1
...@@ -1143,7 +1143,7 @@ pub fn execve(...@@ -1143,7 +1143,7 @@ pub fn execve(
1143 } else if (builtin.output_mode == .Exe) {1143 } else if (builtin.output_mode == .Exe) {
1144 // Then we have Zig start code and this works.1144 // Then we have Zig start code and this works.
1145 // TODO type-safety for null-termination of `os.environ`.1145 // 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);
1147 } else {1147 } else {
1148 // TODO come up with a solution for this.1148 // TODO come up with a solution for this.
1149 @compileError("missing std lib enhancement: std.process.execv implementation has no way to collect the environment variables to forward to the child process");1149 @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...@@ -4614,18 +4614,27 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
4614 .int => |int| return ip.getCoerced(gpa, int, new_ty),4614 .int => |int| return ip.getCoerced(gpa, int, new_ty),
4615 else => {},4615 else => {},
4616 },4616 },
4617 .opt => |opt| if (ip.isPointerType(new_ty))4617 .opt => |opt| switch (ip.indexToKey(new_ty)) {
4618 return switch (opt.val) {4618 .ptr_type => |ptr_type| return switch (opt.val) {
4619 .none => try ip.get(gpa, .{ .ptr = .{4619 .none => try ip.get(gpa, .{ .ptr = .{
4620 .ty = new_ty,4620 .ty = new_ty,
4621 .addr = .{ .int = .zero_usize },4621 .addr = .{ .int = .zero_usize },
4622 .len = switch (ip.indexToKey(new_ty).ptr_type.flags.size) {4622 .len = switch (ptr_type.flags.size) {
4623 .One, .Many, .C => .none,4623 .One, .Many, .C => .none,
4624 .Slice => try ip.get(gpa, .{ .undef = .usize_type }),4624 .Slice => try ip.get(gpa, .{ .undef = .usize_type }),
4625 },4625 },
4626 } }),4626 } }),
4627 else => |payload| try ip.getCoerced(gpa, payload, new_ty),4627 else => |payload| try ip.getCoerced(gpa, payload, new_ty),
4628 },4628 },
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 },
4629 .err => |err| if (ip.isErrorSetType(new_ty))4638 .err => |err| if (ip.isErrorSetType(new_ty))
4630 return ip.get(gpa, .{ .err = .{4639 return ip.get(gpa, .{ .err = .{
4631 .ty = new_ty,4640 .ty = new_ty,
src/Sema.zig+15-4
...@@ -26470,7 +26470,11 @@ fn coerceExtra(...@@ -26470,7 +26470,11 @@ fn coerceExtra(
26470 }26470 }
2647126471
26472 if (dest_info.sentinel == null or inst_info.sentinel == null or26472 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 ))
26474 break :p;26478 break :p;
2647526479
26476 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);26480 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
...@@ -27350,7 +27354,11 @@ fn coerceInMemoryAllowed(...@@ -27350,7 +27354,11 @@ fn coerceInMemoryAllowed(
27350 }27354 }
27351 const ok_sent = dest_info.sentinel == null or27355 const ok_sent = dest_info.sentinel == null or
27352 (src_info.sentinel != null and27356 (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 ));
27354 if (!ok_sent) {27362 if (!ok_sent) {
27355 return InMemoryCoercionResult{ .array_sentinel = .{27363 return InMemoryCoercionResult{ .array_sentinel = .{
27356 .actual = src_info.sentinel orelse Value.@"unreachable",27364 .actual = src_info.sentinel orelse Value.@"unreachable",
...@@ -27704,8 +27712,11 @@ fn coerceInMemoryAllowedPtrs(...@@ -27704,8 +27712,11 @@ fn coerceInMemoryAllowedPtrs(
27704 }27712 }
2770527713
27706 const ok_sent = dest_info.sentinel == null or src_info.size == .C or27714 const ok_sent = dest_info.sentinel == null or src_info.size == .C or
27707 (src_info.sentinel != null and27715 (src_info.sentinel != null and dest_info.sentinel.?.eql(
27708 dest_info.sentinel.?.eql(src_info.sentinel.?, dest_info.pointee_type, sema.mod));27716 try mod.getCoerced(src_info.sentinel.?, dest_info.pointee_type),
27717 dest_info.pointee_type,
27718 sema.mod,
27719 ));
27709 if (!ok_sent) {27720 if (!ok_sent) {
27710 return InMemoryCoercionResult{ .ptr_sentinel = .{27721 return InMemoryCoercionResult{ .ptr_sentinel = .{
27711 .actual = src_info.sentinel orelse Value.@"unreachable",27722 .actual = src_info.sentinel orelse Value.@"unreachable",