Commit 90768cc2
90768cc2d0e2Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 1 file · ~1 modified
Description
Add sudoku benchmark, fix GC root tracking for return types
- GC_ROOT for pointer-type local vars in default declaration path
- func_has_gc_vars checks return type too
- sudoku passes with GC disabled; GC mark-sweep bug remains for long-running programs with many allocations
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 90768cc2d0e2
- Parent
- b41e490b83ec
src/emit.cmodifiedView file
@@ -512,6 +512,8 @@
512512
/* Check if this function needs GC rooting */513513
bool func_has_gc_vars = false;514514
if (ctx->needs_gc) {515+
/* Check return type */516+
if (is_gc_type(ctx, f->return_type)) func_has_gc_vars = true;515517
for (int i = 0; i < f->param_count && !func_has_gc_vars; i++)516518
if (is_gc_type(ctx, f->params[i].type)) func_has_gc_vars = true;517519
for (int i = saved_var_count + f->param_count; i < ctx->var_count && !func_has_gc_vars; i++)@@ -586,11 +588,15 @@
586588
}587589
}588590
const char *init = "";591+
bool needs_root = false;589592
if (v->type.kind == SPINEL_TYPE_INTEGER) init = " = 0";590593
else if (v->type.kind == SPINEL_TYPE_FLOAT) init = " = 0.0";591594
else if (v->type.kind == SPINEL_TYPE_BOOLEAN) init = " = FALSE";592595
else if (v->type.kind == SPINEL_TYPE_STRING) init = " = NULL";596+
else if (strstr(ct, "*")) { init = " = NULL"; needs_root = true; }593597
emit(ctx, "%s %s%s;\n", ct, cn, init);598+
if (needs_root && func_has_gc_vars)599+
emit(ctx, "SP_GC_ROOT(%s);\n", cn);594600
free(ct); free(cn);595601
}596602
/* Also declare any outer-scope variables that are used in this function