mem: Steps 5-7 — context-identifier rebind + interp ctx bootstrap
Step 5 — `context` resolves through `current_ctx_ref`. The compile-time
emit of the default GPA into the `context` global is gone; entry points
already bind `current_ctx_ref` to `&__sx_default_context` and every
sx-to-sx call forwards it. `allocViaContext` sources from
`current_ctx_ref` too. `matchContextAllocCall` is kept as a comptime
escape hatch: the ct_module spun up by `evalComptimeString` doesn't get
the full Allocator/CAllocator/Context type registration so the protocol-
dispatch chain wouldn't run in the interp; codegen also wins from the
direct libc malloc/free.
Step 6 — `push Context.{...}` stack-discipline rewrite. Allocates a
fresh `Context` slot, binds `current_ctx_ref` to it for the body's
lexical scope, restores on exit. No global, no walk.
Step 7 — interp parity. `defaultContextValue()` builds the Context
aggregate (CAllocator thunks for alloc/dealloc, null data) on demand.
`interp.call` bootstraps slot_ptr(0) when an entry function with
implicit ctx is called sans args; `materializeCtxArg` dereferences the
caller's slot_ptr into the aggregate at every sx-to-sx call boundary so
the callee's `load(ref_0)` lands on the value; `load` of an aggregate
is a passthrough. `.global_addr` of `__sx_default_context` returns the
aggregate directly so exported entries' first-line `global_addr(...)`
runs cleanly in `#run`.
`ct_lowering` inherits `implicit_ctx_enabled` + `has_implicit_ctx` so
functions lowered into the ct module carry ctx like their main-module
twins.
152/152 example tests pass. Snapshots regen.
This commit is contained in:
@@ -51,38 +51,10 @@ entry:
|
||||
declare ptr @GPA.init(ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal ptr @GPA.alloc(ptr %0, ptr %1, i64 %2) #0 {
|
||||
entry:
|
||||
%alloca = alloca ptr, align 8
|
||||
store ptr %1, ptr %alloca, align 8
|
||||
%allocaN = alloca i64, 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
|
||||
%add = add i64 %loadN, 1
|
||||
store i64 %add, ptr %gep, align 8
|
||||
%loadN = load i64, ptr %allocaN, align 8
|
||||
%call = call ptr @malloc(i64 %loadN)
|
||||
ret ptr %call
|
||||
}
|
||||
declare ptr @GPA.alloc(ptr, ptr, i64) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal void @GPA.dealloc(ptr %0, ptr %1, ptr %2) #0 {
|
||||
entry:
|
||||
%alloca = alloca ptr, align 8
|
||||
store ptr %1, ptr %alloca, align 8
|
||||
%allocaN = alloca ptr, 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
|
||||
%sub = sub i64 %loadN, 1
|
||||
store i64 %sub, ptr %gep, align 8
|
||||
%loadN = load ptr, ptr %allocaN, align 8
|
||||
call void @free(ptr %loadN)
|
||||
ret void
|
||||
}
|
||||
declare void @GPA.dealloc(ptr, ptr, ptr) #0
|
||||
|
||||
; Function Attrs: nounwind
|
||||
declare void @Arena.add_chunk(ptr, ptr, i64) #0
|
||||
@@ -362,14 +334,6 @@ declare i64 @build_options() #0
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
call void @__sx_objc_selector_init()
|
||||
%alloca = alloca { i64 }, align 8
|
||||
store { i64 } zeroinitializer, ptr %alloca, align 8
|
||||
%si = insertvalue { ptr, ptr, ptr } undef, ptr %alloca, 0
|
||||
%siN = insertvalue { ptr, ptr, ptr } %si, ptr @__thunk_GPA_Allocator_alloc, 1
|
||||
%siN = insertvalue { ptr, ptr, ptr } %siN, ptr @__thunk_GPA_Allocator_dealloc, 2
|
||||
%siN = insertvalue { { ptr, ptr, ptr }, ptr } undef, { ptr, ptr, ptr } %siN, 0
|
||||
%siN = insertvalue { { ptr, ptr, ptr }, ptr } %siN, ptr null, 1
|
||||
store { { ptr, ptr, ptr }, ptr } %siN, ptr @context, align 8
|
||||
%load = load ptr, ptr @OBJC_SELECTOR_REFERENCES_init, align 8
|
||||
call void @objc_msgSend(ptr null, ptr %load)
|
||||
%loadN = load ptr, ptr @OBJC_SELECTOR_REFERENCES_init, align 8
|
||||
@@ -378,10 +342,10 @@ entry:
|
||||
call void @objc_msgSend(ptr null, ptr %loadN)
|
||||
%loadN = load ptr, ptr @OBJC_SELECTOR_REFERENCES_release, align 8
|
||||
call void @objc_msgSend(ptr null, ptr %loadN)
|
||||
%allocaN = alloca { ptr, i64 }, align 8
|
||||
%gep = getelementptr inbounds { ptr, i64 }, ptr %allocaN, i32 0, i32 0
|
||||
%alloca = alloca { ptr, i64 }, align 8
|
||||
%gep = getelementptr inbounds { ptr, i64 }, ptr %alloca, i32 0, i32 0
|
||||
store ptr null, ptr %gep, align 8
|
||||
%gepN = getelementptr inbounds { ptr, i64 }, ptr %allocaN, i32 0, i32 1
|
||||
%gepN = getelementptr inbounds { ptr, i64 }, ptr %alloca, i32 0, i32 1
|
||||
store i64 0, ptr %gepN, align 8
|
||||
%allocaN = alloca { ptr, i64 }, align 8
|
||||
store { ptr, i64 } { ptr @str, i64 3 }, ptr %allocaN, align 8
|
||||
@@ -413,20 +377,6 @@ entry:
|
||||
ret void
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal ptr @__thunk_GPA_Allocator_alloc(ptr %0, ptr %1, i64 %2) #0 {
|
||||
entry:
|
||||
%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, ptr %2) #0 {
|
||||
entry:
|
||||
call void @GPA.dealloc(ptr %0, ptr %1, ptr %2)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @objc_msgSend(ptr, ptr)
|
||||
|
||||
declare i64 @write(i32, ptr, i64)
|
||||
|
||||
Reference in New Issue
Block a user