]> granicus.if.org Git - vim/commitdiff
patch 8.2.3151: Vim9: profiling fails if nested function is also profiled v8.2.3151
authorBram Moolenaar <Bram@vim.org>
Sun, 11 Jul 2021 18:22:30 +0000 (20:22 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 11 Jul 2021 18:22:30 +0000 (20:22 +0200)
Problem:    Vim9: profiling fails if nested function is also profiled.
Solution:   Use the compile type from the outer function. (closes #8543)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index 10f41c7bf8e1ce480f0d0bc5b05e588b10e2f2b6..b4107e97d16a5fb4911c98519b493aa2efaf8ecf 100644 (file)
@@ -4190,6 +4190,14 @@ def ProfiledNested()
   Nested()
 enddef
 
+def ProfiledNestedProfiled()
+  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()
@@ -4198,8 +4206,17 @@ def Test_xx_profile_with_lambda()
   profile start Xprofile.log
   profile func ProfiledWithLambda
   ProfiledWithLambda()
+
   profile func ProfiledNested
   ProfiledNested()
+
+  # Also profile the nested function.  Use a different function, although the
+  # contents is the same, to make sure it was not already compiled.
+  profile func *
+  ProfiledNestedProfiled()
+
+  profdel func *
+  profile pause
 enddef
 
 " Keep this last, it messes up highlighting.
index 0047c7dbc8784664ff40a1fbf037f7f1a3a5716c..7f9f49efd165fd235e520aa0b7661ba0abfcd2a3 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3151,
 /**/
     3150,
 /**/
index 15c8ef6a8c254ba22836d9f31a52febb9479469d..d25183f19e4dbef7cc087a1d6bcc42eb6d68e6d3 100644 (file)
@@ -5570,6 +5570,7 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx)
     char_u     *lambda_name;
     ufunc_T    *ufunc;
     int                r = FAIL;
+    compiletype_T   compile_type;
 
     if (eap->forceit)
     {
@@ -5636,9 +5637,15 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx)
        }
     }
 
-    if (func_needs_compiling(ufunc, COMPILE_TYPE(ufunc))
-           && compile_def_function(ufunc, TRUE, COMPILE_TYPE(ufunc), cctx)
-                                                                      == FAIL)
+    compile_type = COMPILE_TYPE(ufunc);
+#ifdef FEAT_PROFILE
+    // If the outer function is profiled, also compile the nested function for
+    // profiling.
+    if (cctx->ctx_compile_type == CT_PROFILE)
+       compile_type = CT_PROFILE;
+#endif
+    if (func_needs_compiling(ufunc, compile_type)
+           && compile_def_function(ufunc, TRUE, compile_type, cctx) == FAIL)
     {
        func_ptr_unref(ufunc);
        goto theend;
@@ -5647,8 +5654,7 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx)
 #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))
+    if (compile_type == CT_PROFILE && func_needs_compiling(ufunc, CT_NONE))
        compile_def_function(ufunc, FALSE, CT_NONE, cctx);
 #endif