authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-10 12:02:31+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-10 12:02:31+02:00
logb9f521b40217835c72bcb91debf3904d5b9df6e7
treeefa8c458a5449474a82cb29f3a8136b518970e39
parentf736cde397a6abb1399827ed5988c43001706580

Sema: add coercion from [:x]T to [*:x]T


1 files changed, 32 insertions(+), 2 deletions(-)

src/Sema.zig+32-2
......@@ -16033,7 +16033,6 @@ fn coerce(
1603316033 },
1603416034 .Pointer => p: {
1603516035 const inst_info = inst_ty.ptrInfo().data;
16036 if (inst_info.size == .Slice) break :p;
1603716036 switch (try sema.coerceInMemoryAllowed(
1603816037 block,
1603916038 dest_info.pointee_type,
......@@ -16046,6 +16045,14 @@ fn coerce(
1604616045 .ok => {},
1604716046 .no_match => break :p,
1604816047 }
16048 if (inst_info.size == .Slice) {
16049 if (dest_info.sentinel == null or inst_info.sentinel == null or
16050 !dest_info.sentinel.?.eql(inst_info.sentinel.?, dest_info.pointee_type))
16051 break :p;
16052
16053 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
16054 return sema.coerceCompatiblePtrs(block, dest_ty, slice_ptr, inst_src);
16055 }
1604916056 return sema.coerceCompatiblePtrs(block, dest_ty, inst, inst_src);
1605016057 },
1605116058 else => {},
......@@ -16089,7 +16096,30 @@ fn coerce(
1608916096 return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src);
1609016097 }
1609116098 },
16092 .Many => {},
16099 .Many => p: {
16100 const inst_info = inst_ty.ptrInfo().data;
16101 if (inst_info.size != .Slice) break :p;
16102
16103 switch (try sema.coerceInMemoryAllowed(
16104 block,
16105 dest_info.pointee_type,
16106 inst_info.pointee_type,
16107 dest_info.mutable,
16108 target,
16109 dest_ty_src,
16110 inst_src,
16111 )) {
16112 .ok => {},
16113 .no_match => break :p,
16114 }
16115
16116 if (dest_info.sentinel == null or inst_info.sentinel == null or
16117 !dest_info.sentinel.?.eql(inst_info.sentinel.?, dest_info.pointee_type))
16118 break :p;
16119
16120 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
16121 return sema.coerceCompatiblePtrs(block, dest_ty, slice_ptr, inst_src);
16122 },
1609316123 }
1609416124
1609516125 // This will give an extra hint on top of what the bottom of this func would provide.