issue-0028: ?Protocol = null sentinel-shaped optional protocols

Protocol structs registered via registerProtocolDecl carry a new
is_protocol flag; the ?T paths in sizeOf/typeSizeBytes/toLLVMType
recognise it and lay out ?Protocol as the protocol struct itself
(ctx == null IS the "none" state), matching how ?Closure / ?*T are
sentinel-shaped — no extra storage.

Method dispatch on ?Protocol auto-unwraps in lowerCall's field-access
path; the unwrap is structurally a no-op so we just rebind obj_ty to
the payload type. resolveCallParamTypes extended for optional-protocol
receivers so enum-literal args (gpu.create_texture(.r8, ...)) get the
right target_type and don't silently collapse to tag=0 : s32 — same
issue-0031-class bug closed in Session 66, one type-system layer
deeper.

Library: UIRenderer / UIPipeline / GlyphCache migrated from the verbose
gpu: GPU = ---; has_gpu: bool pattern to gpu: ?GPU = null. set_gpu no
longer maintains a parallel bool flag.

Bundled: dock.sx threads delta_time as a struct field rather than via
a global pointer (cleanup unrelated to issue-0028, committed alongside).

Verified: 85/85 regression tests pass; iOS-sim chess + macOS chess
both render correctly post-migration.
This commit is contained in:
agra
2026-05-18 18:32:55 +03:00
parent f9ecf9d00e
commit 79419b99bd
11 changed files with 117 additions and 93 deletions

View File

@@ -179,20 +179,17 @@ GlyphCache :: struct {
last_shape_len: s64;
last_shape_size_q: u16;
// GPU protocol backend. When `has_gpu`, atlas creation + dirty uploads
// route through `gpu` instead of raw GL.
gpu: GPU = ---;
has_gpu: bool = false;
// GPU protocol backend. When set, atlas creation + dirty uploads route
// through `gpu` instead of raw GL.
gpu: ?GPU = null;
init :: (self: *GlyphCache, path: [:0]u8, default_size: f32) {
// Preserve any pre-set GPU dispatch across the zero-out — the
// surrounding struct memset would otherwise wipe it.
saved_gpu := self.gpu;
saved_has_gpu := self.has_gpu;
// Zero out the entire struct first (parent may be uninitialized with = ---)
memset(self, 0, size_of(GlyphCache));
self.gpu = saved_gpu;
self.has_gpu = saved_has_gpu;
// Load font file
file_size : s32 = 0;
@@ -264,7 +261,7 @@ GlyphCache :: struct {
// update_texture_region — same result as the GL path's glTexImage2D
// with the zeroed bitmap, but works whether or not the backend
// accepts CPU pixel pointers at create time.
if self.has_gpu {
if self.gpu != null {
self.texture_id = self.gpu.create_texture(
self.atlas_width, self.atlas_height, .r8, null);
self.dirty = true;
@@ -435,7 +432,7 @@ GlyphCache :: struct {
// the frame's render pass.
flush :: (self: *GlyphCache) {
if self.dirty == false { return; }
if self.has_gpu { return; }
if self.gpu != null { return; }
glBindTexture(GL_TEXTURE_2D, self.texture_id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, self.atlas_width, self.atlas_height, GL_RED, GL_UNSIGNED_BYTE, self.bitmap);
@@ -443,7 +440,7 @@ GlyphCache :: struct {
}
upload_atlas_to_gpu :: (self: *GlyphCache) {
if self.has_gpu == false { return; }
if self.gpu == null { return; }
if self.dirty == false { return; }
self.gpu.update_texture_region(self.texture_id, 0, 0,
self.atlas_width, self.atlas_height, xx self.bitmap);
@@ -503,7 +500,7 @@ GlyphCache :: struct {
self.atlas_height = new_h;
// Recreate atlas at the new size.
if self.has_gpu {
if self.gpu != null {
// No destroy_texture in the GPU protocol yet — old atlas
// leaks in the backend table until process exit. Atlas grow
// is rare so this is acceptable for now.