diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-06 04:11:00 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-06 04:11:00 -0400 |
| commit | dc7ee868a6d98169c6ec7305189bc578011bb5e7 (patch) | |
| tree | c6371019e7920501f1a9c019efab7881d69596c2 /compile.c | |
| parent | 89a1f8a401b3ccd1c9708c718c4560e78d2cdd8a (diff) | |
Speculative fix for some incref issues
Diffstat (limited to 'compile.c')
| -rw-r--r-- | compile.c | 21 |
1 files changed, 7 insertions, 14 deletions
@@ -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); } |
