w6c+wwstage: implicit [N]T->[]T array-to-slice coercion via desugar (#258)
Hare admits an array with a defined length wherever its element slice is
expected (assign / return / call-arg / init) as a borrow; ww rejected it
everywhere (the #108(c) exclusion), so base64 worked around the gap with
explicit a[0:n] slices.
type_assignable / isassignable now admit array->slice on an exact element
match (mirror ref/harec/src/types.c:1080-1097, the SLICE-dst arm). The four
acceptance sites route through one shared helper (desugar_arrayslice /
desugararrayslice) that rewrites the array expr to the explicit full slice
arr[0:len(arr)] — an N_SLICE over the array base. cgen is untouched: the
existing slice lowering (#252/#257/#135 made array bases, incl struct-field
arrays, correct) materialises the borrow header {.ptr=&arr[0], .len=N,
.cap=N}, byte-identically in both stages.
wwstage runs no general call-arg / N_ASSIGN typecheck, so checkassign +
desugarcallargs are added solely to route those two contexts through the
shared desugar (rule-10). desugarcallargs additionally loud-rejects an
element-MISMATCH array into a []T param, scoped to that shape so wwstage's
broader call-arg leniency is untouched.
953_arraytoslice_run covers the four contexts + a borrow-alias proof + the
i32/u8 element axis (dual-stage run + cs==ww byte-id), plus mismatch-reject
rows asserting both stages refuse [4]i32 -> []u8. Regen'd w6c + wwdump
combined.ww (#110).
This commit is contained in:
@@ -386,6 +386,24 @@ type_assignable(Type *dst, Type *src)
|
||||
return pa == NULL && pb == NULL;
|
||||
}
|
||||
|
||||
/* #258: implicit [N]T → []T array-to-slice borrow. Hare admits an
|
||||
* array with a DEFINED length wherever its element slice is expected
|
||||
* — assign / return / call-arg / init alike (ref/harec/src/types.c:
|
||||
* 1080-1097, the SLICE-dst arm). The checker accepts it here; the
|
||||
* acceptance sites (clet / N_ASSIGN / call-arg gather / N_RETURN)
|
||||
* then DESUGAR the array expr to an explicit full slice `arr[0:len
|
||||
* (arr)]` via desugar_arrayslice, reusing the existing slice cgen so
|
||||
* there is ZERO new array→slice store and the borrow header
|
||||
* {.ptr=&arr[0], .len=N, .cap=N} is byte-identical across stages.
|
||||
* Element types must match exactly — no element decay. */
|
||||
{
|
||||
Type *du = (dst->kind == TY_NAMED) ? dst->under : dst;
|
||||
Type *su = (src->kind == TY_NAMED) ? src->under : src;
|
||||
if (du && su && du->kind == TY_SLICE && su->kind == TY_ARRAY &&
|
||||
su->alen != SIZE_UNDEFINED && type_eq(du->sub, su->sub))
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* #108(c): opaque is a type-erasure sink. Any pointer is assignable
|
||||
* to *opaque, and any slice to []opaque — the universal void-pointer
|
||||
* and erased slice. harec type_is_assignable: ptr→*opaque at ref/harec/src/
|
||||
@@ -394,13 +412,11 @@ type_assignable(Type *dst, Type *src)
|
||||
* (to_secondary->storage == STORAGE_OPAQUE) return true;`).
|
||||
*
|
||||
* Array→[]opaque (harec's STORAGE_POINTER-to-array and array→slice
|
||||
* decay, types.c:1080-1099) is deliberately EXCLUDED: ww has no
|
||||
* implicit array→slice conversion for any element type (`let s:
|
||||
* []i32 = a` is rejected too — a slice is built only via an explicit
|
||||
* `a[0:n]` op), so there is no array→slice-header cgen. Accepting
|
||||
* array→[]opaque alone would assign a fat array local into a 24-byte
|
||||
* slot with no decay — a silent miscompile (rule 7). sort's caller
|
||||
* passes a slice, so slice→[]opaque is the only shape it needs.
|
||||
* decay, types.c:1080-1099) stays EXCLUDED here: the #258 arm above
|
||||
* desugars a concrete-element borrow only on an EXACT element match,
|
||||
* and this arm fires only when dst and src share a kind (ptr→ptr,
|
||||
* slice→slice), so an array reaches []opaque only after an explicit
|
||||
* `a[0:n]` slice. ww-stricter than Hare; documented divergence.
|
||||
*
|
||||
* Both rules fire only when the destination element is opaque, so
|
||||
* they are inert on the opaque-free selfhost corpus. */
|
||||
|
||||
Reference in New Issue
Block a user