Patch 8.2.3151
Problem:    Vim9: profiling fails if nested function is also profiled.
Solution:   Use the compile type from the outer function. (closes #8543)
Files:      src/vim9compile.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.3150/src/vim9compile.c   2021-07-11 18:23:15.437471705 +0200
--- src/vim9compile.c   2021-07-11 20:16:40.204594739 +0200
***************
*** 5570,5575 ****
--- 5570,5576 ----
      char_u    *lambda_name;
      ufunc_T   *ufunc;
      int               r = FAIL;
+     compiletype_T   compile_type;
  
      if (eap->forceit)
      {
***************
*** 5636,5644 ****
        }
      }
  
!     if (func_needs_compiling(ufunc, COMPILE_TYPE(ufunc))
!           && compile_def_function(ufunc, TRUE, COMPILE_TYPE(ufunc), cctx)
!                                                                      == FAIL)
      {
        func_ptr_unref(ufunc);
        goto theend;
--- 5637,5651 ----
        }
      }
  
!     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,5654 ****
  #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
  
--- 5654,5660 ----
  #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 == CT_PROFILE && func_needs_compiling(ufunc, CT_NONE))
        compile_def_function(ufunc, FALSE, CT_NONE, cctx);
  #endif
  
*** ../vim-8.2.3150/src/testdir/test_vim9_script.vim    2021-07-11 
17:54:55.580891616 +0200
--- src/testdir/test_vim9_script.vim    2021-07-11 20:20:46.172283116 +0200
***************
*** 4190,4195 ****
--- 4190,4203 ----
    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,4205 ****
--- 4206,4222 ----
    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.
*** ../vim-8.2.3150/src/version.c       2021-07-11 19:44:14.114416536 +0200
--- src/version.c       2021-07-11 20:21:48.004203963 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3151,
  /**/

-- 
"Computers in the future may weigh no more than 1.5 tons."
                                   Popular Mechanics, 1949

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202107111823.16BINV3u887380%40masaka.moolenaar.net.

Raspunde prin e-mail lui