To: vim_dev@googlegroups.com Subject: Patch 8.2.3147 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3147 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. Files: src/vim9compile.c, src/vim9execute.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.3146/src/vim9compile.c 2021-07-11 15:26:09.939038701 +0200 --- src/vim9compile.c 2021-07-11 17:19:14.229509686 +0200 *************** *** 3624,3633 **** --- 3624,3635 ---- ufunc->uf_ret_type = &t_unknown; 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 // called without profiling. Compile it here in the right context. if (cctx->ctx_compile_type == CT_PROFILE) compile_def_function(ufunc, FALSE, CT_NONE, cctx); + #endif // 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. *************** *** 5631,5636 **** --- 5633,5646 ---- 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) { char_u *func_name = vim_strnsave(name_start + 2, *** ../vim-8.2.3146/src/vim9execute.c 2021-07-07 20:10:40.624454968 +0200 --- src/vim9execute.c 2021-07-11 17:48:49.961634751 +0200 *************** *** 197,202 **** --- 197,203 ---- int idx; estack_T *entry; funclocal_T *floc = NULL; + int res = OK; if (dfunc->df_deleted) { *************** *** 219,232 **** (((dfunc_T *)def_functions.ga_data) + 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 --- 220,225 ---- *************** *** 235,244 **** // When debugging and using "cont" switches to the not-debugged // instructions, may need to still compile them. ! if ((func_needs_compiling(ufunc, COMPILE_TYPE(ufunc)) ! && compile_def_function(ufunc, FALSE, COMPILE_TYPE(ufunc), NULL) ! == FAIL) ! || INSTRUCTIONS(dfunc) == NULL) { if (did_emsg_cumul + did_emsg == did_emsg_before) semsg(_(e_function_is_not_compiled_str), --- 228,241 ---- // When debugging and using "cont" switches to the not-debugged // instructions, may need to still compile them. ! if (func_needs_compiling(ufunc, COMPILE_TYPE(ufunc))) ! { ! res = compile_def_function(ufunc, FALSE, COMPILE_TYPE(ufunc), 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) semsg(_(e_function_is_not_compiled_str), *** ../vim-8.2.3146/src/testdir/test_vim9_script.vim 2021-07-11 16:52:41.355572247 +0200 --- src/testdir/test_vim9_script.vim 2021-07-11 17:51:19.733323743 +0200 *************** *** 4177,4195 **** CheckDefExecAndScriptFailure(lines, 'some error continued', 1) enddef ! def ProfiledFunc() var n = 3 echo [[1, 2], [3, 4]]->filter((_, l) => l[0] == n) enddef " Execute this near the end, profiling doesn't stop until Vim exists. " This only tests that it works, not the profiling output. def Test_xx_profile_with_lambda() CheckFeature profile profile start Xprofile.log ! profile func ProfiledFunc ! ProfiledFunc() enddef " Keep this last, it messes up highlighting. --- 4177,4205 ---- CheckDefExecAndScriptFailure(lines, 'some error continued', 1) enddef ! def ProfiledWithLambda() var n = 3 echo [[1, 2], [3, 4]]->filter((_, l) => l[0] == n) 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. " This only tests that it works, not the profiling output. def Test_xx_profile_with_lambda() CheckFeature profile profile start Xprofile.log ! profile func ProfiledWithLambda ! ProfiledWithLambda() ! profile func ProfiledNested ! ProfiledNested() enddef " Keep this last, it messes up highlighting. *** ../vim-8.2.3146/src/version.c 2021-07-11 16:52:41.355572247 +0200 --- src/version.c 2021-07-11 17:53:37.325046458 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3147, /**/ -- hundred-and-one symptoms of being an internet addict: 118. You are on a first-name basis with your ISP's staff. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///