Skip to content

Commit

Permalink
Fix unboxed analysis when loading modules
Browse files Browse the repository at this point in the history
There was an issue when loading pre-compiled (.cpp or otherwise)
modules, where we'd try to use analysis information on fns within that
module to determine if we can unbox values. However, since we didn't
analyze the jank code for that module in this session, we don't have
that info. Instead, we should just rely on the meta and the var in that
scenario. When we do have the analysis info, though, we make sure to
verify what we can.
  • Loading branch information
jeaye committed Oct 21, 2023
1 parent 229f423 commit ad89a75
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/cpp/jank/analyze/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ namespace jank::analyze
make_box<runtime::obj::vector>
(
rt_ctx.intern_keyword("", "arities", true),
/* NOTE: We don't support unboxed meta on variadic arities. */
make_box(arg_count)
)
)
Expand All @@ -979,24 +980,19 @@ namespace jank::analyze
if(supports_unboxed_input || supports_unboxed_output)
{
auto const fn_res(vars.find(var_deref->var));
if(fn_res == vars.end())
{ return err(error{ fmt::format("ICE: undefined var: {}", var_deref->var->to_string()) }); }

auto const fn(boost::get<expr::function<expression>>(&fn_res->second->data));
if(!fn)
{ return err(error{ "unsupported arity meta on non-function var" }); }

/* We need to be sure we're calling the exact arity that has been specified. Unboxed
* returns aren't supported for variadic calls right now. */
for(auto const &arity : fn->arities)
/* If we don't have a valid var_deref, we know the var exists, but we
* don't have an AST node for it. This means the var came in through
* a pre-compiled module. In that case, we can only rely on meta to
* tell us what we need. */
if(fn_res != vars.end())
{
if(arity.fn_ctx->param_count == arg_count && !arity.fn_ctx->is_variadic)
{
needs_arg_box = !supports_unboxed_input;
needs_ret_box = needs_box | !supports_unboxed_output;
break;
}
auto const fn(boost::get<expr::function<expression>>(&fn_res->second->data));
if(!fn)
{ return err(error{ "unsupported arity meta on non-function var" }); }
}

needs_arg_box = !supports_unboxed_input;
needs_ret_box = needs_box | !supports_unboxed_output;
}
}
}
Expand Down

0 comments on commit ad89a75

Please sign in to comment.