mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.3147: Vim9: profiling does not work with a nested function
Problem: Vim9: profiling does not work with a nested function. Solution: Also compile a nested function without profiling. (closes #8543) Handle that compiling may cause the table of compiled functions to change.
This commit is contained in:
@@ -4177,19 +4177,29 @@ def Test_xxx_echoerr_line_number()
|
|||||||
CheckDefExecAndScriptFailure(lines, 'some error continued', 1)
|
CheckDefExecAndScriptFailure(lines, 'some error continued', 1)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def ProfiledFunc()
|
def ProfiledWithLambda()
|
||||||
var n = 3
|
var n = 3
|
||||||
echo [[1, 2], [3, 4]]->filter((_, l) => l[0] == n)
|
echo [[1, 2], [3, 4]]->filter((_, l) => l[0] == n)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def ProfiledNested()
|
||||||
|
var x = 0
|
||||||
|
def Nested(): any
|
||||||
|
return x
|
||||||
|
enddef
|
||||||
|
Nested()
|
||||||
|
enddef
|
||||||
|
|
||||||
" Execute this near the end, profiling doesn't stop until Vim exists.
|
" Execute this near the end, profiling doesn't stop until Vim exists.
|
||||||
" This only tests that it works, not the profiling output.
|
" This only tests that it works, not the profiling output.
|
||||||
def Test_xx_profile_with_lambda()
|
def Test_xx_profile_with_lambda()
|
||||||
CheckFeature profile
|
CheckFeature profile
|
||||||
|
|
||||||
profile start Xprofile.log
|
profile start Xprofile.log
|
||||||
profile func ProfiledFunc
|
profile func ProfiledWithLambda
|
||||||
ProfiledFunc()
|
ProfiledWithLambda()
|
||||||
|
profile func ProfiledNested
|
||||||
|
ProfiledNested()
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
" Keep this last, it messes up highlighting.
|
" Keep this last, it messes up highlighting.
|
||||||
|
@@ -755,6 +755,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3147,
|
||||||
/**/
|
/**/
|
||||||
3146,
|
3146,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -3624,10 +3624,12 @@ compile_lambda(char_u **arg, cctx_T *cctx)
|
|||||||
ufunc->uf_ret_type = &t_unknown;
|
ufunc->uf_ret_type = &t_unknown;
|
||||||
compile_def_function(ufunc, FALSE, cctx->ctx_compile_type, cctx);
|
compile_def_function(ufunc, FALSE, cctx->ctx_compile_type, cctx);
|
||||||
|
|
||||||
|
#ifdef FEAT_PROFILE
|
||||||
// When the outer function is compiled for profiling, the lambda may be
|
// When the outer function is compiled for profiling, the lambda may be
|
||||||
// called without profiling. Compile it here in the right context.
|
// called without profiling. Compile it here in the right context.
|
||||||
if (cctx->ctx_compile_type == CT_PROFILE)
|
if (cctx->ctx_compile_type == CT_PROFILE)
|
||||||
compile_def_function(ufunc, FALSE, CT_NONE, cctx);
|
compile_def_function(ufunc, FALSE, CT_NONE, cctx);
|
||||||
|
#endif
|
||||||
|
|
||||||
// evalarg.eval_tofree_cmdline may have a copy of the last line and "*arg"
|
// evalarg.eval_tofree_cmdline may have a copy of the last line and "*arg"
|
||||||
// points into it. Point to the original line to avoid a dangling pointer.
|
// points into it. Point to the original line to avoid a dangling pointer.
|
||||||
@@ -5631,6 +5633,14 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx)
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FEAT_PROFILE
|
||||||
|
// When the outer function is compiled for profiling, the nested function
|
||||||
|
// may be called without profiling. Compile it here in the right context.
|
||||||
|
if (COMPILE_TYPE(ufunc) == CT_PROFILE
|
||||||
|
&& func_needs_compiling(ufunc, CT_NONE))
|
||||||
|
compile_def_function(ufunc, FALSE, CT_NONE, cctx);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (is_global)
|
if (is_global)
|
||||||
{
|
{
|
||||||
char_u *func_name = vim_strnsave(name_start + 2,
|
char_u *func_name = vim_strnsave(name_start + 2,
|
||||||
|
@@ -197,6 +197,7 @@ call_dfunc(
|
|||||||
int idx;
|
int idx;
|
||||||
estack_T *entry;
|
estack_T *entry;
|
||||||
funclocal_T *floc = NULL;
|
funclocal_T *floc = NULL;
|
||||||
|
int res = OK;
|
||||||
|
|
||||||
if (dfunc->df_deleted)
|
if (dfunc->df_deleted)
|
||||||
{
|
{
|
||||||
@@ -219,14 +220,6 @@ call_dfunc(
|
|||||||
(((dfunc_T *)def_functions.ga_data)
|
(((dfunc_T *)def_functions.ga_data)
|
||||||
+ ectx->ec_dfunc_idx)->df_ufunc);
|
+ ectx->ec_dfunc_idx)->df_ufunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Profiling might be enabled/disabled along the way. This should not
|
|
||||||
// fail, since the function was compiled before and toggling profiling
|
|
||||||
// doesn't change any errors.
|
|
||||||
if (func_needs_compiling(ufunc, COMPILE_TYPE(ufunc))
|
|
||||||
&& compile_def_function(ufunc, FALSE, COMPILE_TYPE(ufunc), NULL)
|
|
||||||
== FAIL)
|
|
||||||
return FAIL;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -235,10 +228,14 @@ call_dfunc(
|
|||||||
|
|
||||||
// When debugging and using "cont" switches to the not-debugged
|
// When debugging and using "cont" switches to the not-debugged
|
||||||
// instructions, may need to still compile them.
|
// instructions, may need to still compile them.
|
||||||
if ((func_needs_compiling(ufunc, COMPILE_TYPE(ufunc))
|
if (func_needs_compiling(ufunc, COMPILE_TYPE(ufunc)))
|
||||||
&& compile_def_function(ufunc, FALSE, COMPILE_TYPE(ufunc), NULL)
|
{
|
||||||
== FAIL)
|
res = compile_def_function(ufunc, FALSE, COMPILE_TYPE(ufunc), NULL);
|
||||||
|| INSTRUCTIONS(dfunc) == NULL)
|
|
||||||
|
// compile_def_function() may cause def_functions.ga_data to change
|
||||||
|
dfunc = ((dfunc_T *)def_functions.ga_data) + cdf_idx;
|
||||||
|
}
|
||||||
|
if (res == FAIL || INSTRUCTIONS(dfunc) == NULL)
|
||||||
{
|
{
|
||||||
if (did_emsg_cumul + did_emsg == did_emsg_before)
|
if (did_emsg_cumul + did_emsg == did_emsg_before)
|
||||||
semsg(_(e_function_is_not_compiled_str),
|
semsg(_(e_function_is_not_compiled_str),
|
||||||
|
Reference in New Issue
Block a user