Stop pointer parameters leaking value-pool slots

Create structure parameters before allocating their representation, then keep pointer references in the call variable's inline slot. Add an 8,000-call regression and document the remaining by-value structure escape limitation.

Co-authored-by: andrew <andrew@aklabs.net>
Co-authored-by: OpenAI Codex (GPT-5) <noreply@openai.com>
This commit is contained in:
2026-08-04 23:09:15 -04:00
parent ed6f463897
commit fd6521d381
7 changed files with 83 additions and 12 deletions

View File

@@ -99,18 +99,21 @@ akerr_ErrorContext *akbasic_variable_init(akbasic_Variable *obj, akbasic_ValuePo
* the run was over, which a game loop reaches in half a minute. TODO.md
* section 6 item 30 has the whole reduction.
*
* **A `@` name is the one exclusion**, and it is the whole of it. A
* structure or a pointer to one keeps pool storage because a pointer may
* outlive the scope that DIMmed it -- docs/16-structures.md says nothing is
* reclaimed and akbasic_runtime_prev_environment() relies on it. The suffix
* is the right test rather than `structtype`, which the DIM path sets
* **A `@` name is the one exclusion**, except for a one-slot pointer
* parameter. A structure or a pointer variable keeps pool storage because
* a pointer may outlive the scope that DIMmed it -- docs/16-structures.md
* says nothing is reclaimed and akbasic_runtime_prev_environment() relies
* on it. A pointer parameter owns only its reference slot; the target is
* owned by the caller, so bind_structure_parameter() marks it before this
* call and lets that slot use inline storage. The suffix is the right test
* for every other case rather than `structtype`, which the DIM path sets
* *after* calling this.
*
* Otherwise: reuse the existing slice when it is already big enough, which
* makes a re-DIM to the same or a smaller size free; growing takes fresh
* slots and abandons the old ones, as documented on akbasic_ValuePool.
*/
if ( totalsize == 1 && lastchar != '@' ) {
if ( totalsize == 1 && (lastchar != '@' || obj->ispointer) ) {
obj->values = &obj->inlinevalue;
} else if ( obj->values == NULL || obj->valuecount < (int)totalsize ) {
PASS(errctx, akbasic_valuepool_take(pool, (int)totalsize, &obj->values));