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:
@@ -183,6 +183,33 @@ static void test_structure_parameters(void)
|
||||
harness_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pointer parameters do not consume value-pool slots per call.
|
||||
*
|
||||
* The pointer's parameter variable owns only one reference to the caller's
|
||||
* record, so that reference can live in the variable's inline slot. The target
|
||||
* remains in the caller's storage. One pointer parameter and 8,000 calls make
|
||||
* one leaked slot per call fail against the 4,096-slot value pool.
|
||||
*/
|
||||
static void test_pointer_parameters_do_not_leak_value_slots(void)
|
||||
{
|
||||
TEST_REQUIRE_OK(run_program_bounded("10 TYPE CRATE\n"
|
||||
"20 W#\n"
|
||||
"30 END TYPE\n"
|
||||
"40 DIM A@ AS CRATE\n"
|
||||
"50 DIM P@ AS PTR TO CRATE\n"
|
||||
"60 POINT P@ AT A@\n"
|
||||
"70 DEF POKEIT(P@ AS PTR TO CRATE)\n"
|
||||
"80 P@->W# = P@->W# + 1\n"
|
||||
"90 RETURN P@->W#\n"
|
||||
"100 FOR I# = 1 TO 8000\n"
|
||||
"110 R# = POKEIT(P@)\n"
|
||||
"120 NEXT I#\n"
|
||||
"130 PRINT A@.W#\n", 1000000));
|
||||
TEST_REQUIRE_STR(HARNESS_OUTPUT, "8000\n");
|
||||
harness_stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief A structure parameter must name its type, and the type is checked.
|
||||
*
|
||||
@@ -454,6 +481,7 @@ int main(void)
|
||||
test_runaway_recursion_is_diagnosed();
|
||||
test_single_expression_form();
|
||||
test_structure_parameters();
|
||||
test_pointer_parameters_do_not_leak_value_slots();
|
||||
test_structure_parameter_types_are_checked();
|
||||
test_call_scopes_are_reclaimed();
|
||||
test_calls_do_not_leak_value_slots();
|
||||
|
||||
Reference in New Issue
Block a user