EIP-2315 Simple Subroutines for the EVM

On a more high-level, I’d be curious to hear from @axic or @chriseth what they think about this EIP.

Chris wrote above some suggestions which would prevent “walking” into a subroutine or jumping into one. IMO that would be a mistake, but I’m curious to hear why it would be beneficial. As it is now, consider the following code, in pseudo-code;

func formula(a, b int) int{
    return add(a * a, b*b)
}
func add(a, b, int) int{
    return a + b
}

When translated to the evm, this could be implemented a tail return,

LABEL_FORMULA:
   // code to put `a*a` and `b*b` on stack
   ...
   JUMP LABEL_ADD

LABEL_ADD:
  BEGINSUB
  add
  RETSUB

For a perhaps better example, see The Go low-level calling convention on x86-64 · dr knz @ work , where a c compiler generates similar code

Compare how DoCallAdd works in C or C++:


DoCallAdd:
     movl    $3, %edx
     movl    $2, %esi
     movl    $1, %edi
     jmp     FuncAdd

In short, allowing jumps into subroutines enables infinite (tail-) recursion.