Really! I believe this section of the reference is not very clear then.
You really define a function for every single call site of the method? Every each call in the whole Crystal stdlib and user’s code creates a distinct each method?
Was that out pseudo-code for closured variables? What happens with self? That connects with the discussion in Performance struct vs class.
You really define a function for every single call site of the method? Every each call in the whole Crystal stdlib and user’s code creates a distinct each method?
As far as I’m aware, yes.
Was that out pseudo-code for closured variables? What happens with self ?
Yes, consider that very pseudo code, I don’t think there’s valid Crystal code to emulate what really happens :) I just meant to indicate that __t is the callside’s t. You can imagine the generated method somehow has full access to the callsite’s scope, in the case of a closuring block anyways.
So I went full circle. First, I imagined literal block inlining. Since blocks are generally different, the obvious meaning of “inlining” made no sense, and then the examples in the reference made me think it was the method being inlined. So, I am back at “each call site invokes a copy of the original method with the block inlined and closured vars, constants, self, etc. working as expected”, whatever that technically really translates to.
This can also be seen if you generate LLVM IR code: you won’t find a definition of r (nor nothing similar to it). And s will have part of r inlined in it.
When I was working on debugger and debugging compilter I was looking explicitly on
visit(Yield)
and
codegen_with_block:
it was clear that it is inlining in case if it is a block. Also when I was looking into generated IR code for methods with blocks it shows you the code as inlined.
It took me a lot of time to realize it as I could not understand at that moment why local block variables was not shown in debugger and why crystal had a bug with methods with blocks when he was jumping somewhere in the local file instead of going into the file that contains the source code for that method.
Some bits and pieces from @asterite helped me to click all pieces to the whole picture.