mem: Step 3 — thread __sx_ctx through closure/fn-pointer/method dispatch
Continues the implicit-Context refactor. Bare-fn trampolines, lambda trampolines, and protocol thunks now carry __sx_ctx at slot 0; call sites for closures, fn-pointer variables, and method dispatch prepend the caller's current ctx. - emit_llvm.zig:1687 call_indirect treats `fp_ctx_slots` leading args as opaque ptr (the implicit ctx) when the fn-pointer is default-conv under has_implicit_ctx. - lower.zig:fnPtrTypeWantsCtx predicate gates the prepend at both scope-local and global fn-pointer call sites. - lower.zig:fixupMethodReceiver skips __sx_ctx when probing the receiver param's type. - lower.zig:lowerLambda builds closure type from user-visible params only (skip ctx + env). - lower.zig:closure(bare_fn) builds closure type from user-visible params only. - module.zig: Module.has_implicit_ctx flag mirrors Lowering's switch so emit_llvm can read it without a back-pointer. Tests updated: - 5 ObjC-block/runtime tests get `callconv(.c)` on fn-ptr types cast from `objc_msgSend` / Block.invoke (C-side calls into sx). - ffi-06-callback gets `callconv(.c)` on double_it/add_with_ctx — the registered C-side callbacks. - 08-types snapshot regen (undefined-init drift from layout shift). - 11 JNI/ObjC .ir snapshots regen for the ctx-prepended thunk signatures. 151/152 example tests pass. Remaining failure (05-run) is the comptime/interp path that requires Step 7 (callWithDefaultContext).
This commit is contained in:
@@ -24,39 +24,39 @@ declare ptr @memcpy(ptr, ptr, i64)
|
||||
declare ptr @memset(ptr, i32, i64)
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal ptr @CAllocator.alloc(ptr %0, i64 %1) #0 {
|
||||
define internal ptr @CAllocator.alloc(ptr %0, ptr %1, i64 %2) #0 {
|
||||
entry:
|
||||
%alloca = alloca ptr, align 8
|
||||
store ptr %0, ptr %alloca, align 8
|
||||
store ptr %1, ptr %alloca, align 8
|
||||
%allocaN = alloca i64, align 8
|
||||
store i64 %1, ptr %allocaN, align 8
|
||||
store i64 %2, ptr %allocaN, align 8
|
||||
%load = load i64, ptr %allocaN, align 8
|
||||
%call = call ptr @malloc(i64 %load)
|
||||
ret ptr %call
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal void @CAllocator.dealloc(ptr %0, ptr %1) #0 {
|
||||
define internal void @CAllocator.dealloc(ptr %0, ptr %1, ptr %2) #0 {
|
||||
entry:
|
||||
%alloca = alloca ptr, align 8
|
||||
store ptr %0, ptr %alloca, align 8
|
||||
store ptr %1, ptr %alloca, align 8
|
||||
%allocaN = alloca ptr, align 8
|
||||
store ptr %1, ptr %allocaN, align 8
|
||||
store ptr %2, ptr %allocaN, align 8
|
||||
%load = load ptr, ptr %allocaN, align 8
|
||||
call void @free(ptr %load)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @GPA.init() #0
|
||||
declare ptr @GPA.init(ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal ptr @GPA.alloc(ptr %0, i64 %1) #0 {
|
||||
define internal ptr @GPA.alloc(ptr %0, ptr %1, i64 %2) #0 {
|
||||
entry:
|
||||
%alloca = alloca ptr, align 8
|
||||
store ptr %0, ptr %alloca, align 8
|
||||
store ptr %1, ptr %alloca, align 8
|
||||
%allocaN = alloca i64, align 8
|
||||
store i64 %1, ptr %allocaN, align 8
|
||||
store i64 %2, ptr %allocaN, align 8
|
||||
%load = load ptr, ptr %alloca, align 8
|
||||
%gep = getelementptr inbounds { i64 }, ptr %load, i32 0, i32 0
|
||||
%loadN = load i64, ptr %gep, align 8
|
||||
@@ -68,12 +68,12 @@ entry:
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal void @GPA.dealloc(ptr %0, ptr %1) #0 {
|
||||
define internal void @GPA.dealloc(ptr %0, ptr %1, ptr %2) #0 {
|
||||
entry:
|
||||
%alloca = alloca ptr, align 8
|
||||
store ptr %0, ptr %alloca, align 8
|
||||
store ptr %1, ptr %alloca, align 8
|
||||
%allocaN = alloca ptr, align 8
|
||||
store ptr %1, ptr %allocaN, align 8
|
||||
store ptr %2, ptr %allocaN, align 8
|
||||
%load = load ptr, ptr %alloca, align 8
|
||||
%gep = getelementptr inbounds { i64 }, ptr %load, i32 0, i32 0
|
||||
%loadN = load i64, ptr %gep, align 8
|
||||
@@ -85,55 +85,55 @@ entry:
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @Arena.add_chunk(ptr, i64) #0
|
||||
declare void @Arena.add_chunk(ptr, ptr, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @Arena.init(ptr, i64) #0
|
||||
declare ptr @Arena.init(ptr, ptr, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @Arena.reset(ptr) #0
|
||||
declare void @Arena.reset(ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @Arena.deinit(ptr) #0
|
||||
declare void @Arena.deinit(ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @Arena.alloc(ptr, i64) #0
|
||||
declare ptr @Arena.alloc(ptr, ptr, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @Arena.dealloc(ptr, ptr) #0
|
||||
declare void @Arena.dealloc(ptr, ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @BufAlloc.init(ptr, i64) #0
|
||||
declare ptr @BufAlloc.init(ptr, ptr, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @BufAlloc.reset(ptr) #0
|
||||
declare void @BufAlloc.reset(ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @BufAlloc.alloc(ptr, i64) #0
|
||||
declare ptr @BufAlloc.alloc(ptr, ptr, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @BufAlloc.dealloc(ptr, ptr) #0
|
||||
declare void @BufAlloc.dealloc(ptr, ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @TrackingAllocator.init(ptr) #0
|
||||
declare ptr @TrackingAllocator.init(ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare i64 @TrackingAllocator.leak_count(ptr) #0
|
||||
declare i64 @TrackingAllocator.leak_count(ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @TrackingAllocator.report(ptr) #0
|
||||
declare void @TrackingAllocator.report(ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @TrackingAllocator.alloc(ptr, i64) #0
|
||||
declare ptr @TrackingAllocator.alloc(ptr, ptr, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @TrackingAllocator.dealloc(ptr, ptr) #0
|
||||
declare void @TrackingAllocator.dealloc(ptr, ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal { ptr, i64 } @cstring(i64 %0) #0 {
|
||||
define internal { ptr, i64 } @cstring(ptr %0, i64 %1) #0 {
|
||||
entry:
|
||||
%alloca = alloca i64, align 8
|
||||
store i64 %0, ptr %alloca, align 8
|
||||
store i64 %1, ptr %alloca, align 8
|
||||
%load = load i64, ptr %alloca, align 8
|
||||
%add = add i64 %load, 1
|
||||
%heap = call ptr @malloc(i64 %add)
|
||||
@@ -142,7 +142,7 @@ entry:
|
||||
%loadN = load ptr, ptr %allocaN, align 8
|
||||
%loadN = load i64, ptr %alloca, align 8
|
||||
%addN = add i64 %loadN, 1
|
||||
%1 = call ptr @memset(ptr %loadN, i32 0, i64 %addN)
|
||||
%2 = call ptr @memset(ptr %loadN, i32 0, i64 %addN)
|
||||
%allocaN = alloca { ptr, i64 }, align 8
|
||||
store { ptr, i64 } undef, ptr %allocaN, align 8
|
||||
%loadN = load ptr, ptr %allocaN, align 8
|
||||
@@ -157,27 +157,27 @@ entry:
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @int_to_string(i64) #0
|
||||
declare ptr @int_to_string(ptr, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @bool_to_string(i1) #0
|
||||
declare ptr @bool_to_string(ptr, i1) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @float_to_string(double) #0
|
||||
declare ptr @float_to_string(ptr, double) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @hex_group(ptr, i64, i64) #0
|
||||
declare void @hex_group(ptr, ptr, i64, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @int_to_hex_string(i64) #0
|
||||
declare ptr @int_to_hex_string(ptr, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal { ptr, i64 } @concat({ ptr, i64 } %0, { ptr, i64 } %1) #0 {
|
||||
define internal { ptr, i64 } @concat(ptr %0, { ptr, i64 } %1, { ptr, i64 } %2) #0 {
|
||||
entry:
|
||||
%alloca = alloca { ptr, i64 }, align 8
|
||||
store { ptr, i64 } %0, ptr %alloca, align 8
|
||||
store { ptr, i64 } %1, ptr %alloca, align 8
|
||||
%allocaN = alloca { ptr, i64 }, align 8
|
||||
store { ptr, i64 } %1, ptr %allocaN, align 8
|
||||
store { ptr, i64 } %2, ptr %allocaN, align 8
|
||||
%load = load { ptr, i64 }, ptr %alloca, align 8
|
||||
%len = extractvalue { ptr, i64 } %load, 1
|
||||
%allocaN = alloca i64, align 8
|
||||
@@ -189,7 +189,7 @@ entry:
|
||||
%loadN = load i64, ptr %allocaN, align 8
|
||||
%loadN = load i64, ptr %allocaN, align 8
|
||||
%add = add i64 %loadN, %loadN
|
||||
%call = call { ptr, i64 } @cstring(i64 %add)
|
||||
%call = call { ptr, i64 } @cstring(ptr %0, i64 %add)
|
||||
%allocaN = alloca { ptr, i64 }, align 8
|
||||
store { ptr, i64 } %call, ptr %allocaN, align 8
|
||||
%loadN = load { ptr, i64 }, ptr %allocaN, align 8
|
||||
@@ -211,16 +211,16 @@ entry:
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal { ptr, i64 } @substr({ ptr, i64 } %0, i64 %1, i64 %2) #0 {
|
||||
define internal { ptr, i64 } @substr(ptr %0, { ptr, i64 } %1, i64 %2, i64 %3) #0 {
|
||||
entry:
|
||||
%alloca = alloca { ptr, i64 }, align 8
|
||||
store { ptr, i64 } %0, ptr %alloca, align 8
|
||||
%allocaN = alloca i64, align 8
|
||||
store i64 %1, ptr %allocaN, align 8
|
||||
store { ptr, i64 } %1, ptr %alloca, align 8
|
||||
%allocaN = alloca i64, align 8
|
||||
store i64 %2, ptr %allocaN, align 8
|
||||
%allocaN = alloca i64, align 8
|
||||
store i64 %3, ptr %allocaN, align 8
|
||||
%load = load i64, ptr %allocaN, align 8
|
||||
%call = call { ptr, i64 } @cstring(i64 %load)
|
||||
%call = call { ptr, i64 } @cstring(ptr %0, i64 %load)
|
||||
%allocaN = alloca { ptr, i64 }, align 8
|
||||
store { ptr, i64 } %call, ptr %allocaN, align 8
|
||||
%loadN = load { ptr, i64 }, ptr %allocaN, align 8
|
||||
@@ -236,16 +236,16 @@ entry:
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @xml_escape(ptr) #0
|
||||
declare ptr @xml_escape(ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @path_join(ptr) #0
|
||||
declare ptr @path_join(ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @any_to_string([2 x i64]) #0
|
||||
declare ptr @any_to_string(ptr, [2 x i64]) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare ptr @build_format(ptr) #0
|
||||
declare ptr @build_format(ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @BuildOptions.add_link_flag(i64, ptr) #0
|
||||
@@ -389,8 +389,8 @@ entry:
|
||||
store { ptr, i64 } { ptr @str.1, i64 0 }, ptr %allocaN, align 8
|
||||
%loadN = load { ptr, i64 }, ptr %allocaN, align 8
|
||||
%loadN = load { ptr, i64 }, ptr %allocaN, align 8
|
||||
%call = call { ptr, i64 } @substr({ ptr, i64 } %loadN, i64 0, i64 3)
|
||||
%callN = call { ptr, i64 } @concat({ ptr, i64 } %loadN, { ptr, i64 } %call)
|
||||
%call = call { ptr, i64 } @substr(ptr @__sx_default_context, { ptr, i64 } %loadN, i64 0, i64 3)
|
||||
%callN = call { ptr, i64 } @concat(ptr @__sx_default_context, { ptr, i64 } %loadN, { ptr, i64 } %call)
|
||||
store { ptr, i64 } %callN, ptr %allocaN, align 8
|
||||
%loadN = load { ptr, i64 }, ptr %allocaN, align 8
|
||||
%str.ptr = extractvalue { ptr, i64 } %loadN, 0
|
||||
@@ -400,30 +400,30 @@ entry:
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal ptr @__thunk_CAllocator_Allocator_alloc(ptr %0, i64 %1) #0 {
|
||||
define internal ptr @__thunk_CAllocator_Allocator_alloc(ptr %0, ptr %1, i64 %2) #0 {
|
||||
entry:
|
||||
%call = call ptr @CAllocator.alloc(ptr %0, i64 %1)
|
||||
%call = call ptr @CAllocator.alloc(ptr %0, ptr %1, i64 %2)
|
||||
ret ptr %call
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal void @__thunk_CAllocator_Allocator_dealloc(ptr %0, ptr %1) #0 {
|
||||
define internal void @__thunk_CAllocator_Allocator_dealloc(ptr %0, ptr %1, ptr %2) #0 {
|
||||
entry:
|
||||
call void @CAllocator.dealloc(ptr %0, ptr %1)
|
||||
call void @CAllocator.dealloc(ptr %0, ptr %1, ptr %2)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal ptr @__thunk_GPA_Allocator_alloc(ptr %0, i64 %1) #0 {
|
||||
define internal ptr @__thunk_GPA_Allocator_alloc(ptr %0, ptr %1, i64 %2) #0 {
|
||||
entry:
|
||||
%call = call ptr @GPA.alloc(ptr %0, i64 %1)
|
||||
%call = call ptr @GPA.alloc(ptr %0, ptr %1, i64 %2)
|
||||
ret ptr %call
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal void @__thunk_GPA_Allocator_dealloc(ptr %0, ptr %1) #0 {
|
||||
define internal void @__thunk_GPA_Allocator_dealloc(ptr %0, ptr %1, ptr %2) #0 {
|
||||
entry:
|
||||
call void @GPA.dealloc(ptr %0, ptr %1)
|
||||
call void @GPA.dealloc(ptr %0, ptr %1, ptr %2)
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -441,3 +441,5 @@ entry:
|
||||
store ptr %selN, ptr @OBJC_SELECTOR_REFERENCES_release, align 8
|
||||
ret void
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user