feat(lang): block value requires no trailing ; (Rust-style)

A block's value is now its last statement ONLY when that statement is a
trailing expression with no `;`. A trailing `;` discards the value,
leaving the block void. This makes value-vs-statement explicit and lets
the compiler reject "this block was supposed to produce a value".

Compiler:
- Parser records `Block.produces_value` (last stmt is a no-`;` trailing
  expression) + `Block.discarded_semi` (the `;` that discarded a value),
  via `expectSemicolonAfter`. A trailing expression before `}` may now
  omit its `;` (previously a parse error). Match-arm and else-arm bodies
  are built value-producing regardless of the arm `;` (arms are exempt —
  the `;` is an arm terminator).
- Lowering: `lowerBlockValue` / the block-expr path / `inferExprType`
  respect `produces_value`. A value-position block that discards its value
  is a hard error (`lowerValueBody` for function bodies; the value-context
  `.block` path for if/else branches, `catch` bodies, value bindings,
  match arms). Pure-failable `-> !` bodies (value rides the error channel)
  and a value-if whose branches are void are handled without false errors.
- `defer`/`onfail` cleanup bodies lower as statements (void), so a
  trailing `;` there is fine.

Migration (behavior-preserving — output unchanged):
- stdlib + ~210 examples: dropped the trailing `;` on value-position last
  expressions. `format` now ends with an explicit `#insert "return
  result;"` (it relied on `#insert`-as-block-value, which `;` discards).
- Two `main :: () -> s32` examples that relied on the old silent
  default-return got an explicit trailing `0`.
- Rejection snapshots 0412 / 1013 regenerated (their quoted source lines
  lost a `;`); the diagnostics themselves are unchanged.

Docs/tests: specs.md "Block values" section; examples 0040 (rules) + 0041
(rejection); 3 parser unit tests. Filed issue 0066 (pre-existing
match-arm negated-literal phi-width quirk, surfaced not caused here).

Gates: zig build, zig build test, run_examples.sh -> 343 passed,
cross_compile.sh -> 7 passed (also refreshed its stale example names).
This commit is contained in:
agra
2026-06-02 09:23:50 +03:00
parent 634cf9bc7f
commit bdd0e96d78
265 changed files with 1070 additions and 761 deletions

View File

@@ -107,7 +107,7 @@ impl GPU for MetalGPU {
self.pixel_h = pixel_h;
}
self.parent_allocator = context.allocator;
metal_init_ios(self);
metal_init_ios(self)
}
shutdown :: (self: *MetalGPU) {
@@ -125,7 +125,7 @@ impl GPU for MetalGPU {
begin_frame :: (self: *MetalGPU, clear: ClearColor) -> bool {
inline if OS != .ios { return false; }
metal_begin_frame_ios(self, clear);
metal_begin_frame_ios(self, clear)
}
end_frame :: (self: *MetalGPU, target_time: f64) {
@@ -141,12 +141,12 @@ impl GPU for MetalGPU {
create_shader :: (self: *MetalGPU, vsrc: string, fsrc: string) -> ShaderHandle {
inline if OS != .ios { return 0; }
metal_create_shader_ios(self, vsrc);
metal_create_shader_ios(self, vsrc)
}
create_buffer :: (self: *MetalGPU, size_bytes: s64) -> BufferHandle {
inline if OS != .ios { return 0; }
metal_create_buffer_ios(self, size_bytes);
metal_create_buffer_ios(self, size_bytes)
}
update_buffer :: (self: *MetalGPU, buf: BufferHandle, data: *void, size_bytes: s64) {
@@ -163,7 +163,7 @@ impl GPU for MetalGPU {
create_texture :: (self: *MetalGPU, w: s32, h: s32, format: TextureFormat, pixels: *void) -> TextureHandle {
inline if OS != .ios { return 0; }
metal_create_texture_ios(self, w, h, format, pixels);
metal_create_texture_ios(self, w, h, format, pixels)
}
update_texture_region :: (self: *MetalGPU, tex: TextureHandle, x: s32, y: s32, w: s32, h: s32, pixels: *void) {
@@ -282,7 +282,7 @@ metal_init_ios :: (self: *MetalGPU) -> bool {
}
}
true;
true
}
metal_resize_ios :: (self: *MetalGPU) {
@@ -343,7 +343,7 @@ metal_begin_frame_ios :: (self: *MetalGPU, clear: ClearColor) -> bool {
sel_registerName("renderCommandEncoderWithDescriptor:".ptr), pass);
if self.encoder == null { self.cmd_buffer = null; self.drawable = null; return false; }
true;
true
}
metal_end_frame_ios :: (self: *MetalGPU, target_time: f64) {
@@ -438,7 +438,7 @@ metal_create_shader_ios :: (self: *MetalGPU, src: string) -> u32 {
}
self.shaders.append(state, self.parent_allocator);
xx self.shaders.len;
xx self.shaders.len
}
// ── Buffers ──────────────────────────────────────────────────────────────
@@ -458,7 +458,7 @@ metal_create_buffer_ios :: (self: *MetalGPU, size_bytes: s64) -> u32 {
if buf == null { return 0; }
self.buffers.append(buf, self.parent_allocator);
xx self.buffers.len;
xx self.buffers.len
}
metal_update_buffer_ios :: (self: *MetalGPU, handle: u32, data: *void, size_bytes: s64) {
@@ -498,7 +498,7 @@ metal_lookup_buffer :: (self: *MetalGPU, handle: u32) -> *void {
if handle == 0 { return null; }
h64 : s64 = xx handle;
if h64 > self.buffers.len { return null; }
self.buffers.items[handle - 1];
self.buffers.items[handle - 1]
}
metal_lookup_shader :: (self: *MetalGPU, handle: u32) -> *void {
@@ -506,7 +506,7 @@ metal_lookup_shader :: (self: *MetalGPU, handle: u32) -> *void {
if handle == 0 { return null; }
h64 : s64 = xx handle;
if h64 > self.shaders.len { return null; }
self.shaders.items[handle - 1];
self.shaders.items[handle - 1]
}
// ── Textures ─────────────────────────────────────────────────────────────
@@ -553,7 +553,7 @@ metal_create_texture_ios :: (self: *MetalGPU, w: s32, h: s32, format: TextureFor
metal_update_texture_region_ios(self, handle, 0, 0, w, h, pixels);
}
xx self.textures.len;
xx self.textures.len
}
metal_update_texture_region_ios :: (self: *MetalGPU, handle: u32, x: s32, y: s32, w: s32, h: s32, pixels: *void) {