authorgravatar for mitchell.hashimoto@gmail.comMitchell Hashimoto <mitchell.hashimoto@gmail.com> 2022-02-25 13:21:07-08:00
committergravatar for mitchell.hashimoto@gmail.comMitchell Hashimoto <mitchell.hashimoto@gmail.com> 2022-02-25 13:21:07-08:00
log117ef22d3cb86858632d84699e19a90c24745d89
treec515711b49391ca123e98c3ce85f7fcbd0715a45
parentbf6540ce50f8613386be09aac7dc03604af12e1e
signaturelock-open Commit is signed but in an unrecognized format.

stage2: peer resolve *[N]T to []T (and vice versa)


1 files changed, 50 insertions(+), 0 deletions(-)

src/Sema.zig+50
......@@ -17085,6 +17085,47 @@ fn resolvePeerTypes(
1708517085 }
1708617086 }
1708717087
17088 // *[N]T to []T (prev is slice)
17089 if (chosen_ty.isSlice() and
17090 candidate_ty.ptrSize() == .One and
17091 candidate_ty.childType().zigTypeTag() == .Array)
17092 {
17093 const chosen_elem_ty = chosen_ty.elemType2();
17094 const candidate_elem_ty = candidate_ty.childType().elemType2();
17095 if ((try sema.coerceInMemoryAllowed(block, candidate_elem_ty, chosen_elem_ty, false, target, src, src)) == .ok) {
17096 convert_to_slice = false; // it already is a slice
17097
17098 // If the pointer is const then we need to const
17099 if (candidate_ty.childType().isConstPtr())
17100 make_the_slice_const = true;
17101
17102 continue;
17103 }
17104 }
17105
17106 // *[N]T to []T (current is slice)
17107 if (chosen_ty_tag == .Pointer and
17108 chosen_ty.ptrSize() == .One and
17109 chosen_ty.childType().zigTypeTag() == .Array and
17110 candidate_ty.isSlice())
17111 {
17112 const chosen_child_ty = chosen_ty.childType();
17113 const chosen_elem_ty = chosen_child_ty.elemType2();
17114 const candidate_elem_ty = candidate_ty.elemType2();
17115 if ((try sema.coerceInMemoryAllowed(block, candidate_elem_ty, chosen_elem_ty, false, target, src, src)) == .ok) {
17116 chosen = candidate;
17117 chosen_i = candidate_i + 1;
17118
17119 convert_to_slice = false; // it already is a slice
17120
17121 // If the prev pointer is const then we need to const
17122 if (chosen_child_ty.isConstPtr())
17123 make_the_slice_const = true;
17124
17125 continue;
17126 }
17127 }
17128
1708817129 // *[N]T and *[M]T
1708917130 // verify both are pointers to known lengths
1709017131 if (chosen_ty_tag == .Pointer and
......@@ -17222,6 +17263,15 @@ fn resolvePeerTypes(
1722217263 return Type.ptr(sema.arena, info.data);
1722317264 }
1722417265
17266 if (make_the_slice_const) {
17267 // turn []T => []const T
17268 var info = chosen_ty.ptrInfo();
17269 info.data.mutable = false;
17270
17271 std.debug.print("TYPE: {}\n", .{Type.ptr(sema.arena, info.data)});
17272 return Type.ptr(sema.arena, info.data);
17273 }
17274
1722517275 return chosen_ty;
1722617276}
1722717277