Repository navigation
Description
foo and foo() produce the same ast.Call, so nothing downstream can tell a VCALL from an FCALL
Sibling of #40, same shape of gap on a different node.
// ast/ast.go
type Call struct {
Recv Node
Name string
Args []Node
Block *Block
Safe bool // &. safe navigation
}Nothing records whether the call site was written with parentheses, and Call carries no position from which a consumer could re-read the source.
Why Ruby needs the difference
MRI distinguishes a VCALL — a bare name that could have been a local variable — from an FCALL, an explicit call. It changes both the exception class and the message:
nope_xyz # NameError: undefined local variable or method 'nope_xyz' for main
nope_xyz() # NoMethodError: undefined method 'nope_xyz' for maingo-embedded-ruby/ruby currently raises NoMethodError for both, and cannot do otherwise: the VM receives two identical nodes. A FlagSendVCall bit was added there and the compiler sets it, but the compiler has nothing to set it from for the parenthesised case, so foo and foo() still cannot diverge.
Cost, measured
One example: language/send_spec.rb:235, "if invoked as an unambiguous method call". Small — but the consumer is otherwise complete on this path, and the residual is entirely here.
Suggested shape
type Call struct {
Recv Node
Name string
Args []Node
Block *Block
Safe bool
Paren bool // written with parentheses: an FCALL, not a VCALL
}Same precedent as #40 — RangeLit.Exclusive already records one bit of written form on a literal node, because the two spellings mean different things. A new field with a false zero value keeps every existing consumer compiling and behaving as it does today; only a consumer that reads it changes.
The grammar already separates them: method_call for the parenthesised form and operation / var_ref for the bare one (parse.y-ruby_4_0), so the information exists at the point the node is built and is discarded there.
Happy to send the PR here and on the consumer side, if the shape is agreeable — the same offer as #40, and the two would land well together.
Activity
vm: raise NameError for a VCALL miss, in both lanes; home enum_for/to…