patch 8.2.0323: Vim9: calling a function that is defined later is slow
Problem: Vim9: calling a function that is defined later is slow.
Solution: Once the function is found update the instruction so it can be
called directly.
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index 3758697..9196184 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -222,6 +222,38 @@
enddef
+def FuncWithForwardCall(): string
+ return DefinedLater("yes")
+enddef
+
+def DefinedLater(arg: string): string
+ return arg
+enddef
+
+def Test_disassemble_update_instr()
+ let res = execute('disass FuncWithForwardCall')
+ assert_match('FuncWithForwardCall.*'
+ \ .. 'return DefinedLater("yes").*'
+ \ .. '\d PUSHS "yes".*'
+ \ .. '\d UCALL DefinedLater(argc 1).*'
+ \ .. '\d CHECKTYPE string stack\[-1].*'
+ \ .. '\d RETURN.*'
+ \, res)
+
+ " Calling the function will change UCALL into the faster DCALL
+ assert_equal('yes', FuncWithForwardCall())
+
+ res = execute('disass FuncWithForwardCall')
+ assert_match('FuncWithForwardCall.*'
+ \ .. 'return DefinedLater("yes").*'
+ \ .. '\d PUSHS "yes".*'
+ \ .. '\d DCALL DefinedLater(argc 1).*'
+ \ .. '\d CHECKTYPE string stack\[-1].*'
+ \ .. '\d RETURN.*'
+ \, res)
+enddef
+
+
def FuncWithDefault(arg: string = 'default'): string
return arg
enddef
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 53ee511..f1b21d4 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -212,6 +212,19 @@
return a:arg
endfunc
+def FuncWithForwardCall()
+ return DefinedEvenLater("yes")
+enddef
+
+def DefinedEvenLater(arg: string): string
+ return arg
+enddef
+
+def Test_error_in_nested_function()
+ " Error in called function requires unwinding the call stack.
+ assert_fails('call FuncWithForwardCall()', 'E1029')
+enddef
+
def Test_return_type_wrong()
CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 'expected number but got string')
CheckScriptFailure(['def Func(): string', 'return 1', 'enddef'], 'expected string but got number')