From dc7ee868a6d98169c6ec7305189bc578011bb5e7 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 6 Sep 2024 04:11:00 -0400 Subject: Speculative fix for some incref issues --- compile.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/compile.c b/compile.c index ea733334..d9c48ac6 100644 --- a/compile.c +++ b/compile.c @@ -91,7 +91,10 @@ static bool promote(env_t *env, CORD *code, type_t *actual, type_t *needed) CORD compile_maybe_incref(env_t *env, ast_t *ast) { type_t *t = get_type(env, ast); - if (is_idempotent(ast) && can_be_mutated(env, ast)) { + // TODO: not sure if this is underkill or not, but a + // bug was happening with `"":join(table.keys)` + // if (is_idempotent(ast) && can_be_mutated(env, ast)) { + if (ast->tag == Var && can_be_mutated(env, ast)) { if (t->tag == ArrayType) return CORD_all("ARRAY_COPY(", compile(env, ast), ")"); else if (t->tag == TableType || t->tag == SetType) @@ -1006,7 +1009,7 @@ CORD compile_statement(env_t *env, ast_t *ast) loop = CORD_all(loop, "{\n", naked_body, "\n}"); } - if (can_be_mutated(env, array) && is_idempotent(array)) { + if (can_be_mutated(env, array) && is_idempotent(array) && array->tag == Var) { CORD array_code = compile(env, array); loop = CORD_all("{\n" "Array_t iterating = ARRAY_COPY(", array_code, ");\n", @@ -1410,12 +1413,7 @@ CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t } else { env_t *arg_env = with_enum_scope(env, spec_arg->type); type_t *actual_t = get_type(arg_env, call_arg->value); - // TODO: not sure if this should always be incref'd or not, - // bug was happening with `"":join(table.keys)` - if (call_arg->value->tag == Var) - value = compile_maybe_incref(arg_env, call_arg->value); - else - value = compile(arg_env, call_arg->value); + value = compile_maybe_incref(arg_env, call_arg->value); if (!promote(arg_env, &value, actual_t, spec_arg->type)) code_err(call_arg->value, "This argument is supposed to be a %T, but this value is a %T", spec_arg->type, actual_t); } @@ -1443,12 +1441,7 @@ CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t } else { env_t *arg_env = with_enum_scope(env, spec_arg->type); type_t *actual_t = get_type(arg_env, call_arg->value); - // TODO: not sure if this should always be incref'd or not, - // bug was happening with `"":join(table.keys)` - if (call_arg->value->tag == Var) - value = compile_maybe_incref(arg_env, call_arg->value); - else - value = compile(arg_env, call_arg->value); + value = compile_maybe_incref(arg_env, call_arg->value); if (!promote(arg_env, &value, actual_t, spec_arg->type)) code_err(call_arg->value, "This argument is supposed to be a %T, but this value is a %T", spec_arg->type, actual_t); } -- cgit v1.2.3