Patch 8.2.2409

9 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 25, 2021, 3:02:34 PM1/25/21
to vim...@googlegroups.com

Patch 8.2.2409
Problem: Vim9: profiling only works for one function.
Solution: Select the right instructions when calling and returning.
(closes #7743)
Files: src/vim9compile.c, src/vim9execute.c, src/vim9.h,
src/testdir/test_profile.vim


*** ../vim-8.2.2408/src/vim9compile.c 2021-01-24 21:30:45.214803823 +0100
--- src/vim9compile.c 2021-01-25 20:54:04.799091117 +0100
***************
*** 1775,1783 ****
return FAIL;
}
}
! if (func_needs_compiling(ufunc, cctx->ctx_profiling)
&& compile_def_function(ufunc, ufunc->uf_ret_type == NULL,
! cctx->ctx_profiling, NULL) == FAIL)
return FAIL;
}

--- 1775,1783 ----
return FAIL;
}
}
! if (func_needs_compiling(ufunc, PROFILING(ufunc))
&& compile_def_function(ufunc, ufunc->uf_ret_type == NULL,
! PROFILING(ufunc), NULL) == FAIL)
return FAIL;
}

***************
*** 2615,2622 ****
return FAIL;

// Need to compile any default values to get the argument types.
! if (func_needs_compiling(ufunc, cctx->ctx_profiling)
! && compile_def_function(ufunc, TRUE, cctx->ctx_profiling, NULL)
== FAIL)
return FAIL;
return generate_PUSHFUNC(cctx, ufunc->uf_name, ufunc->uf_func_type);
--- 2615,2622 ----
return FAIL;

// Need to compile any default values to get the argument types.
! if (func_needs_compiling(ufunc, PROFILING(ufunc))
! && compile_def_function(ufunc, TRUE, PROFILING(ufunc), NULL)
== FAIL)
return FAIL;
return generate_PUSHFUNC(cctx, ufunc->uf_name, ufunc->uf_func_type);
***************
*** 3111,3117 ****
clear_tv(&rettv);

// Compile the function into instructions.
! compile_def_function(ufunc, TRUE, cctx->ctx_profiling, cctx);

clear_evalarg(&evalarg, NULL);

--- 3111,3117 ----
clear_tv(&rettv);

// Compile the function into instructions.
! compile_def_function(ufunc, TRUE, PROFILING(ufunc), cctx);

clear_evalarg(&evalarg, NULL);

***************
*** 5088,5095 ****
r = eap->skip ? OK : FAIL;
goto theend;
}
! if (func_needs_compiling(ufunc, cctx->ctx_profiling)
! && compile_def_function(ufunc, TRUE, cctx->ctx_profiling, cctx)
== FAIL)
{
func_ptr_unref(ufunc);
--- 5088,5095 ----
r = eap->skip ? OK : FAIL;
goto theend;
}
! if (func_needs_compiling(ufunc, PROFILING(ufunc))
! && compile_def_function(ufunc, TRUE, PROFILING(ufunc), cctx)
== FAIL)
{
func_ptr_unref(ufunc);
*** ../vim-8.2.2408/src/vim9execute.c 2021-01-24 20:51:56.784245253 +0100
--- src/vim9execute.c 2021-01-25 21:00:54.689995350 +0100
***************
*** 181,186 ****
--- 181,196 ----
return FAIL;
}

+ #ifdef FEAT_PROFILE
+ // 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, PROFILING(ufunc))
+ && compile_def_function(ufunc, FALSE, PROFILING(ufunc), NULL)
+ == FAIL)
+ return FAIL;
+ #endif
+
if (ufunc->uf_va_name != NULL)
{
// Need to make a list out of the vararg arguments.
***************
*** 293,299 ****

// Set execution state to the start of the called function.
ectx->ec_dfunc_idx = cdf_idx;
! ectx->ec_instr = dfunc->df_instr;
entry = estack_push_ufunc(ufunc, 1);
if (entry != NULL)
{
--- 303,309 ----

// Set execution state to the start of the called function.
ectx->ec_dfunc_idx = cdf_idx;
! ectx->ec_instr = INSTRUCTIONS(dfunc);
entry = estack_push_ufunc(ufunc, 1);
if (entry != NULL)
{
***************
*** 542,548 ****
ectx->ec_frame_idx = STACK_TV(ectx->ec_frame_idx
+ STACK_FRAME_IDX_OFF)->vval.v_number;
dfunc = ((dfunc_T *)def_functions.ga_data) + ectx->ec_dfunc_idx;
! ectx->ec_instr = dfunc->df_instr;

if (ret_idx > 0)
{
--- 552,558 ----
ectx->ec_frame_idx = STACK_TV(ectx->ec_frame_idx
+ STACK_FRAME_IDX_OFF)->vval.v_number;
dfunc = ((dfunc_T *)def_functions.ga_data) + ectx->ec_dfunc_idx;
! ectx->ec_instr = INSTRUCTIONS(dfunc);

if (ret_idx > 0)
{
***************
*** 1103,1108 ****
--- 1113,1119 ----
return OK;
}

+
/*
* Call a "def" function from old Vim script.
* Return OK or FAIL.
***************
*** 1135,1145 ****
int save_did_emsg_def = did_emsg_def;
int trylevel_at_start = trylevel;
int orig_funcdepth;
- #ifdef FEAT_PROFILE
- int profiling = do_profiling == PROF_YES && ufunc->uf_profiling;
- #else
- # define profiling FALSE
- #endif

// Get pointer to item in the stack.
#define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx)
--- 1146,1151 ----
***************
*** 1152,1159 ****
#define STACK_TV_VAR(idx) (((typval_T *)ectx.ec_stack.ga_data) + ectx.ec_frame_idx + STACK_FRAME_SIZE + idx)

if (ufunc->uf_def_status == UF_NOT_COMPILED
! || (func_needs_compiling(ufunc, profiling)
! && compile_def_function(ufunc, FALSE, profiling, NULL)
== FAIL))
{
if (did_emsg_cumul + did_emsg == did_emsg_before)
--- 1158,1165 ----
#define STACK_TV_VAR(idx) (((typval_T *)ectx.ec_stack.ga_data) + ectx.ec_frame_idx + STACK_FRAME_SIZE + idx)

if (ufunc->uf_def_status == UF_NOT_COMPILED
! || (func_needs_compiling(ufunc, PROFILING(ufunc))
! && compile_def_function(ufunc, FALSE, PROFILING(ufunc), NULL)
== FAIL))
{
if (did_emsg_cumul + did_emsg == did_emsg_before)
***************
*** 1166,1176 ****
// Check the function was really compiled.
dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
+ ufunc->uf_dfunc_idx;
! if ((
! #ifdef FEAT_PROFILE
! profiling ? dfunc->df_instr_prof :
! #endif
! dfunc->df_instr) == NULL)
{
iemsg("using call_def_function() on not compiled function");
return FAIL;
--- 1172,1178 ----
// Check the function was really compiled.
dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
+ ufunc->uf_dfunc_idx;
! if (INSTRUCTIONS(dfunc) == NULL)
{
iemsg("using call_def_function() on not compiled function");
return FAIL;
***************
*** 1309,1319 ****
++ectx.ec_stack.ga_len;
}

! #ifdef FEAT_PROFILE
! ectx.ec_instr = profiling ? dfunc->df_instr_prof : dfunc->df_instr;
! #else
! ectx.ec_instr = dfunc->df_instr;
! #endif
}

// Following errors are in the function, not the caller.
--- 1311,1317 ----
++ectx.ec_stack.ga_len;
}

! ectx.ec_instr = INSTRUCTIONS(dfunc);
}

// Following errors are in the function, not the caller.
*** ../vim-8.2.2408/src/vim9.h 2021-01-24 13:34:15.007739955 +0100
--- src/vim9.h 2021-01-25 20:52:01.863421948 +0100
***************
*** 408,410 ****
--- 408,420 ----

// Used for "lnum" when a range is to be taken from the stack and "!" is used.
#define LNUM_VARIABLE_RANGE_ABOVE -888
+
+ #ifdef FEAT_PROFILE
+ # define PROFILING(ufunc) (do_profiling == PROF_YES && (ufunc)->uf_profiling)
+ # define INSTRUCTIONS(dfunc) \
+ ((do_profiling == PROF_YES && (dfunc->df_ufunc)->uf_profiling) \
+ ? (dfunc)->df_instr_prof : (dfunc)->df_instr)
+ #else
+ # define PROFILING FALSE
+ # define INSTRUCTIONS(dfunc) ((dfunc)->df_instr)
+ #endif
*** ../vim-8.2.2408/src/testdir/test_profile.vim 2021-01-24 20:51:56.784245253 +0100
--- src/testdir/test_profile.vim 2021-01-25 20:57:29.370543108 +0100
***************
*** 5,10 ****
--- 5,11 ----

source shared.vim
source screendump.vim
+ source vim9.vim

func Test_profile_func()
call RunProfileFunc('func', 'let', 'let')
***************
*** 583,586 ****
--- 584,604 ----
call delete('XtestProfile')
endfunc

+ func Test_vim9_profiling()
+ " only tests that compiling and calling functions doesn't crash
+ let lines =<< trim END
+ vim9script
+ def Func()
+ Crash()
+ enddef
+ def Crash()
+ enddef
+ prof start /tmp/profile.log
+ prof func Func
+ Func()
+ END
+ call CheckScriptSuccess(lines)
+ endfunc
+
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.2408/src/version.c 2021-01-25 19:17:58.817907495 +0100
--- src/version.c 2021-01-25 20:58:15.526419809 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2409,
/**/

--
"The amigos also appear to be guilty of not citing the work of others who had
gone before them. Even worse, they have a chapter about modeling time and
space without making a single reference to Star Trek!"
(Scott Ambler, reviewing the UML User Guide)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

John Marriott

unread,
Jan 25, 2021, 3:51:12 PM1/25/21
to vim...@googlegroups.com

On 26-Jan-2021 07:02, Bram Moolenaar wrote:
> Patch 8.2.2409
> Problem: Vim9: profiling only works for one function.
> Solution: Select the right instructions when calling and returning.
> (closes #7743)
> Files: src/vim9compile.c, src/vim9execute.c, src/vim9.h,
> src/testdir/test_profile.vim
>
>
After this patch, mingw64 (gcc 10.2), spits out this if FEAT_PROFILE is
not defined:
<snip>
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
-pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return
-fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD vim9compile.c -o
gobjnative/vim9compile.o
In file included from
d:\users\john\documents\software\mingw\mingw64\x86_64-w64-mingw32\include\windef.h:9,
                 from
d:\users\john\documents\software\mingw\mingw64\x86_64-w64-mingw32\include\windows.h:69,
                 from os_win32.h:95,
                 from vim.h:262,
                 from vim9compile.c:15:
vim9compile.c: In function 'generate_CALL':
vim9.h:418:20: error: called object is not a function or function pointer
  418 | # define PROFILING FALSE
      |                    ^~~~~
vim9compile.c:1778:34: note: in expansion of macro 'PROFILING'
 1778 |  if (func_needs_compiling(ufunc, PROFILING(ufunc))
      |                                  ^~~~~~~~~
vim9.h:418:20: error: called object is not a function or function pointer
  418 | # define PROFILING FALSE
      |                    ^~~~~
vim9compile.c:1780:13: note: in expansion of macro 'PROFILING'
 1780 |             PROFILING(ufunc), NULL) == FAIL)
      |             ^~~~~~~~~
vim9compile.c: In function 'generate_funcref':
vim9.h:418:20: error: called object is not a function or function pointer
  418 | # define PROFILING FALSE
      |                    ^~~~~
vim9compile.c:2618:37: note: in expansion of macro 'PROFILING'
 2618 |     if (func_needs_compiling(ufunc, PROFILING(ufunc))
      |                                     ^~~~~~~~~
vim9.h:418:20: error: called object is not a function or function pointer
  418 | # define PROFILING FALSE
      |                    ^~~~~
vim9compile.c:2619:43: note: in expansion of macro 'PROFILING'
 2619 |      && compile_def_function(ufunc, TRUE, PROFILING(ufunc), NULL)
      |                                           ^~~~~~~~~
vim9compile.c: In function 'compile_lambda':
vim9.h:418:20: error: called object is not a function or function pointer
  418 | # define PROFILING FALSE
      |                    ^~~~~
vim9compile.c:3114:39: note: in expansion of macro 'PROFILING'
 3114 |     compile_def_function(ufunc, TRUE, PROFILING(ufunc), cctx);
      |                                       ^~~~~~~~~
vim9compile.c: In function 'compile_nested_function':
vim9.h:418:20: error: called object is not a function or function pointer
  418 | # define PROFILING FALSE
      |                    ^~~~~
vim9compile.c:5091:37: note: in expansion of macro 'PROFILING'
 5091 |     if (func_needs_compiling(ufunc, PROFILING(ufunc))
      |                                     ^~~~~~~~~
vim9.h:418:20: error: called object is not a function or function pointer
  418 | # define PROFILING FALSE
      |                    ^~~~~
vim9compile.c:5092:43: note: in expansion of macro 'PROFILING'
 5092 |      && compile_def_function(ufunc, TRUE, PROFILING(ufunc), cctx)
      |                                           ^~~~~~~~~
make: *** [Make_cyg_ming.mak:1145: gobjnative/vim9compile.o] Error 1
</snip>

and this:
<snip>
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
-pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return
-fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD vim9execute.c -o
gobjnative/vim9execute.o
In file included from
d:\users\john\documents\software\mingw\mingw64\x86_64-w64-mingw32\include\windef.h:9,
                 from
d:\users\john\documents\software\mingw\mingw64\x86_64-w64-mingw32\include\windows.h:69,
                 from os_win32.h:95,
                 from vim.h:262,
                 from vim9execute.c:15:
vim9execute.c: In function 'call_def_function':
vim9.h:418:20: error: called object is not a function or function pointer
  418 | # define PROFILING FALSE
      |                    ^~~~~
vim9execute.c:1161:38: note: in expansion of macro 'PROFILING'
 1161 |      || (func_needs_compiling(ufunc, PROFILING(ufunc))
      |                                      ^~~~~~~~~
vim9.h:418:20: error: called object is not a function or function pointer
  418 | # define PROFILING FALSE
      |                    ^~~~~
vim9execute.c:1162:41: note: in expansion of macro 'PROFILING'
 1162 |   && compile_def_function(ufunc, FALSE, PROFILING(ufunc), NULL)
      |                                         ^~~~~~~~~
make: *** [Make_cyg_ming.mak:1145: gobjnative/vim9execute.o] Error 1
</snip>

The attached patch tries to fix it.

Cheers
John
vim9.h.8.2.22409.patch
Reply all
Reply to author
Forward
0 new messages