Files
sx/examples/issue-0028.sx
agra a1647eab9b metal: pause step 3b pending sx-side fixes (filed 0024-0030)
Step 3b code is wired across UIRenderer + GlyphCache + UIPipeline +
chess game (gpu_mode = .metal on iOS, MetalGPU bound via the GPU
protocol). macOS GL chess, iOS-sim GLES chess, and iOS-sim Metal
triangle (63-metal-clear.sx) all still render.

iOS-sim Metal chess crashes inside replaceRegion uploading the 1MB
font atlas. Bisecting that crash exposed several sx-language issues
where mid-bisect tracers (NSLog inside if/else branch bodies) didn't
produce output, blocking further investigation.

Filing each finding as examples/issue-NNNN.sx rather than working
around piecemeal:

Bugs:
- 0024 NSLog/foreign-call inside if/else body not producing output
- 0025 C-ABI param coercion incomplete for composites >16B
       (combined direct-call abiCoerceParamType TODO + call_indirect
        path that doesn't apply C-ABI coercion at all)
- 0026 replaceRegion 1MB upload crash (likely downstream of 0025)

Features needed for step 4 + cleanup:
- 0027 Obj-C block bridge (^{...}) for animateWithDuration:
- 0028 Optional protocol box (?GPU = null) replaces T = ---; has_T: bool
- 0029 destroy_texture/buffer/shader on GPU protocol
- 0030 extern cross-file globals

Library-side: renderer.sx + glyph_cache.sx + pipeline.sx gain a
`gpu: GPU = ---; has_gpu: bool` field pair + branches that route every
GL touchpoint through the protocol when has_gpu. glyph_cache.init
saves/restores those fields around its memset. pipeline.set_gpu()
propagates to renderer + font. Renderer's MSL shader source added as
UI_MSL_SRC using packed_float2/packed_float4 to keep the 12-float
interleaved vertex layout tight (48 bytes).

metal.sx: dual-phase init (init(null, 0, 0) for eager device+queue,
re-init with the layer once UIKit installs the SxMetalView).
setStorageMode:.shared on every texture descriptor to ensure CPU-
writable atlas pixels on Apple Silicon iOS-sim.

Regression suite: 68 passing, 0 failed. WASM chess build currently
broken under step 3b state (silent compiler crash); documented in
CHECKPOINT.md, likely fallout from one of the filed issues (probably
0028 — the verbose protocol-box pattern). Step 3b resumes after
0024-0030 land.
2026-05-17 21:17:17 +03:00

54 lines
2.9 KiB
Plaintext

// issue-0028: Feature — make protocol boxes assignable to an optional
// type so callers can spell "no GPU bound" as `?GPU = null` instead of
// the verbose `T = ---; has_T: bool` pattern.
//
// ── Current pattern (verbose) ─────────────────────────────────────────────
//
// gpu: GPU = ---;
// has_gpu: bool = false;
// ...
// if self.has_gpu { self.gpu.create_shader(...); }
//
// ── Proposed pattern ──────────────────────────────────────────────────────
//
// gpu: ?GPU = null;
// ...
// if self.gpu != null { self.gpu.create_shader(...); }
//
// ── Where the verbose pattern lives today ─────────────────────────────────
//
// library/modules/ui/renderer.sx — UIRenderer.gpu + has_gpu
// library/modules/ui/glyph_cache.sx — GlyphCache.gpu + has_gpu
// library/modules/ui/pipeline.sx — UIPipeline.gpu + has_gpu (+ set_gpu)
// library/modules/platform/uikit.sx — UIKitPlatform.frame_closure +
// has_frame_closure (Closure type,
// same pattern but on a closure)
//
// ── Implementation sketch ─────────────────────────────────────────────────
//
// Protocol boxes are 2-pointer structs ({vtable, ctx} or {ctx, fn_ptrs...}
// depending on the inline-vs-vtable shape — see src/ir/lower.zig
// `buildProtocolValue` ~7800-7869). `?T` for these can use `vtable_ptr ==
// null` (or `ctx == null`, depending on layout choice) as the "none"
// sentinel — no extra storage needed. This matches the existing
// optional-closure handling at src/ir/emit_llvm.zig where `?Closure` uses
// `fn_ptr == null` as none.
//
// Approach:
// 1. Extend `?T` type construction to accept T being a protocol type.
// Files: src/ir/types.zig + src/ir/lower.zig (type-resolution).
// 2. Implement `optional_wrap` / `optional_unwrap` /
// `optional_has_value` for protocol-typed payloads in
// src/ir/emit_llvm.zig — model after the closure-optional path.
// 3. Keep the existing `T = ---; has_T: bool` pattern working — the
// new `?T` is additive, not a replacement. Don't churn existing
// files (uikit.sx's frame_closure pattern stays).
//
// ── Syntax constraint ─────────────────────────────────────────────────────
//
// `?T` syntax already exists for primitives + pointers. Extending to
// protocols is a type-system change; no new surface syntax needed.
#import "modules/std.sx";
main :: () -> s32 { 0; }