mem: implicit-Context platform fixes — chess green on macOS/iOS/Android
Verify-step uncovered three categories of regressions where sx code
calls into the platform's C ABI through fn-pointer types or as a
registered callback. Every site now declares the right convention.
C-side calls INTO sx → callconv(.c) on the sx function:
- platform/android.sx: sx_android_render_thread_entry is the start
routine pthread_create invokes — pthread treats it as a C function.
Also annotate the pthread_create signature so the start-routine fn-
pointer field rejects mismatching sx fns at compile time.
sx code calling typed fn-pointers cast from C symbols → callconv(.c)
on the fn-pointer type:
- opengl.sx: 55 GL fn-ptr globals + load_gl's proc-loader param. GL
trampolines are macOS/iOS/Android system code.
- std/objc.sx: the two typed `objc_msgSend` casts.
- gpu/metal.sx: ~40 typed `objc_msgSend` casts across Metal command
encoder / device / pipeline construction.
The block invoke trampolines (objc_block.sx) call back INTO sx (the
closure trampoline). The typed fn-ptr there stays default-conv so
ctx prepends correctly. Compiler change: a callconv(.c) sx function
now binds `current_ctx_ref` to `&__sx_default_context` at entry (used
to be gated by `isExportedEntryName`). C-callable sx callbacks like
the block invokes don't get their own __sx_ctx param but their bodies
still need a real Context to forward to the closure they delegate to.
Tests: 152/152 example suite + chess green on all 3 platforms.
Screenshots at /tmp/sx-game-{macos,iossim,android}.png.
This commit is contained in:
@@ -1006,9 +1006,12 @@ pub const Lowering = struct {
|
||||
scope.put(p.name, .{ .ref = slot, .ty = pty, .is_alloca = true });
|
||||
}
|
||||
|
||||
// Inbound entry points: bind current_ctx_ref to the static default
|
||||
// before any user code runs.
|
||||
if (!wants_ctx and self.implicit_ctx_enabled and isExportedEntryName(name)) {
|
||||
// Inbound entry points and callconv(.c) sx functions: bind
|
||||
// current_ctx_ref to the static default before any user code
|
||||
// runs. C-callable sx functions don't get a __sx_ctx param,
|
||||
// but their bodies may call ctx-aware sx functions / fn-ptrs
|
||||
// and need a real Context to forward.
|
||||
if (!wants_ctx and self.implicit_ctx_enabled) {
|
||||
if (self.global_names.get("__sx_default_context")) |dctx_gi| {
|
||||
self.current_ctx_ref = self.builder.emit(.{ .global_addr = dctx_gi.id }, self.module.types.ptrTo(.void));
|
||||
}
|
||||
@@ -1147,8 +1150,10 @@ pub const Lowering = struct {
|
||||
scope.put(p.name, .{ .ref = slot, .ty = pty, .is_alloca = true });
|
||||
}
|
||||
|
||||
// Inbound entry points: bind current_ctx_ref to &__sx_default_context.
|
||||
if (!wants_ctx_lf and self.implicit_ctx_enabled and isExportedEntryName(name)) {
|
||||
// Inbound entry points + callconv(.c) sx functions: bind
|
||||
// current_ctx_ref to &__sx_default_context. See companion comment
|
||||
// in `lowerFunction` for the same case.
|
||||
if (!wants_ctx_lf and self.implicit_ctx_enabled) {
|
||||
if (self.global_names.get("__sx_default_context")) |dctx_gi| {
|
||||
self.current_ctx_ref = self.builder.emit(.{ .global_addr = dctx_gi.id }, self.module.types.ptrTo(.void));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user