Issue #6668 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected
Assignee set to matz (Yukihiro Matsumoto)

Changing return value from massign would be agaist 2.0 compatibility policy.  Maybe in 3.0.
Method inlining in JRuby would help compatibility here as well, wouldn't it?

Matz.


----------------------------------------
Feature #6668: Multiple assignment should not return an Array object
https://bugs.ruby-lang.org/issues/6668#change-30718

Author: headius (Charles Nutter)
Status: Rejected
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


Currently, when doing multiple assignment, the entire expression must return the right-hand side as an array.

system ~ $ ruby -e "ret = (a, b, c = 1, 2, 3); p ret"
[1, 2, 3]

This is an artifact of MRI's implementation, since multiple assignment was traditionally implemented by taking the array node on the right-hand side, standing it up as a full Ruby Array, and then peeling elements off for assignment on the left-hand side. It is also a performance issue, since it requires constructing the RHS array even when it is never used (unless you are able to do various compiler tricks). I propose removing it.

Justification:

* The feature is rarely used; most people don't even know it exists.
* The impact of creating the RHS array is significant; JRuby can optimize it away in cases where the line is not used as an expression, and the performance difference is huge: https://gist.github.com/3019255
* It is counter-intuitive to have an automatic performance hit just from grouping assignments. "a,b = 1,2" should have the exact same performance as "a = 1; b = 2"

Note that while JRuby can eliminate the array creation in non-expression cases, those are somewhat rare since many times masgn is used at the end of a method body, as for initializers:

class Foo
  def initialize(a, b, c)
    @a, @b, @c = a, b, c
  end
end

JRuby and other implementations may get smart enough in our optimizers to eliminate the array in all cases where it's not needed, but this is a very large burden on the optimization subsystem. It may also not be possible to do in all cases (or not possible to do in even a majority of cases).

Multiple assignment should not return RHS as an array. I do not care what it returns.


-- 
http://bugs.ruby-lang.org/