Disable tail call optimization for better debug call stack

This commit is contained in:
Gaith Hallak 2023-03-18 13:50:32 +03:00
parent 61ffa8f849
commit 3a40ef05fc
3 changed files with 8 additions and 6 deletions

View File

@ -2,7 +2,7 @@
{erl_opts, [debug_info]}. {erl_opts, [debug_info]}.
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref, "69a1c41"}}} {deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref, "bf3a692"}}}
, {getopt, "1.0.1"} , {getopt, "1.0.1"}
, {eblake2, "1.0.0"} , {eblake2, "1.0.0"}
, {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}} , {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}}

View File

@ -1,7 +1,7 @@
{"1.2.0", {"1.2.0",
[{<<"aebytecode">>, [{<<"aebytecode">>,
{git,"https://github.com/aeternity/aebytecode.git", {git,"https://github.com/aeternity/aebytecode.git",
{ref,"69a1c41a4fc31c6449bf077532c22de23f2bbe83"}}, {ref,"bf3a692e0dbebd8ae57becb92566c9c957b0efa6"}},
0}, 0},
{<<"aeserialization">>, {<<"aeserialization">>,
{git,"https://github.com/aeternity/aeserialization.git", {git,"https://github.com/aeternity/aeserialization.git",

View File

@ -52,7 +52,8 @@
tailpos = true, tailpos = true,
child_contracts = #{}, child_contracts = #{},
saved_fresh_names = #{}, saved_fresh_names = #{},
options = [] }). options = [],
debug = false }).
%% -- Debugging -------------------------------------------------------------- %% -- Debugging --------------------------------------------------------------
@ -177,7 +178,8 @@ init_env(ChildContracts, ContractName, FunNames, Name, Args, SavedFreshNames, Op
current_function = Name, current_function = Name,
options = Options, options = Options,
tailpos = true, tailpos = true,
saved_fresh_names = SavedFreshNames }. saved_fresh_names = SavedFreshNames,
debug = proplists:get_value(debug_info, Options, false) }.
next_var(#env{ vars = Vars }) -> next_var(#env{ vars = Vars }) ->
1 + lists:max([-1 | [J || {_, {var, J}} <- Vars]]). 1 + lists:max([-1 | [J || {_, {var, J}} <- Vars]]).
@ -340,7 +342,7 @@ to_scode1(Env, {'let', Ann, X, Expr, Body}) ->
to_scode(Env1, Body) ], to_scode(Env1, Body) ],
[ dbg_loc(Env, Ann) | dbg_scoped_var(Env1, X, SCode) ]; [ dbg_loc(Env, Ann) | dbg_scoped_var(Env1, X, SCode) ];
to_scode1(Env = #env{ current_function = Fun, tailpos = true }, {def, Ann, Fun, Args}) -> to_scode1(Env = #env{ current_function = Fun, tailpos = true, debug = false }, {def, Ann, Fun, Args}) ->
%% Tail-call to current function, f(e0..en). Compile to %% Tail-call to current function, f(e0..en). Compile to
%% [ let xi = ei ] %% [ let xi = ei ]
%% [ STORE argi xi ] %% [ STORE argi xi ]
@ -404,7 +406,7 @@ to_scode1(Env, {closure, Ann, Fun, FVs}) ->
to_scode1(Env, {switch, Ann, Case}) -> to_scode1(Env, {switch, Ann, Case}) ->
[ dbg_loc(Env, Ann) | split_to_scode(Env, Case) ]. [ dbg_loc(Env, Ann) | split_to_scode(Env, Case) ].
local_call( Env, Fun) when Env#env.tailpos -> aeb_fate_ops:call_t(Fun); local_call( Env = #env{debug = false}, Fun) when Env#env.tailpos -> aeb_fate_ops:call_t(Fun);
local_call(_Env, Fun) -> aeb_fate_ops:call(Fun). local_call(_Env, Fun) -> aeb_fate_ops:call(Fun).
split_to_scode(Env, {nosplit, Expr}) -> split_to_scode(Env, {nosplit, Expr}) ->