Make Kernel#lambda return non-lambda when block is not literal - #2288
Closed
XrXr wants to merge 1 commit into
Closed
Make Kernel#lambda return non-lambda when block is not literal#2288XrXr wants to merge 1 commit into
XrXr wants to merge 1 commit into
Conversation
This restores the behavior of Kernel#lambda from Ruby 2.4.x when it receives a non literal block. Semantically speaking, once a literal block is passed into a method which takes an ampersand argument, the block becomes a non-lambda Proc object. When Kernel#lambda recieves a non-lambda proc, it is supposed to simply return it. Because of lazy proc allocation, Kernel#lambda wasn't able to tell the difference between a literal block and a block that has passed through an ampersand argument and is semantically supposed to be a Proc object. This commit uses a new pointer tag, `0x2`, to indicate that a block has passed through an ampersand argument. In all other regards, this block handler tag is the same as `block_handler_type_iseq`. I then use this new tag in Kernel#lambda to implement the 2.4.x spec. [Bug ruby#15620]
Member
Author
|
@ko1 Question: You seem to have picked 0x01 and 0x03 intentionally. Are there any issues with using 0x 2 as a tag? I think 0x02 makes the pointer look like a float to the GC. Could that cause problems? I ran tests with EDIT: ah, it looks like I messed something up for 32-bit platforms. |
Member
Author
|
😬 it looks like 0x02 conflicts with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This restores the behavior of Kernel#lambda from Ruby 2.4.x
when it receives a non literal block.
Semantically speaking, once a literal block is passed into a method
which takes an ampersand argument, the block becomes a non-lambda
Proc object. When Kernel#lambda recieves a non-lambda proc,
it is supposed to simply return it.
Because of lazy proc allocation, Kernel#lambda wasn't able to tell
the difference between a literal block and a block that has passed
through an ampersand argument and is semantically supposed to be
a Proc object.
This commit uses a new pointer tag,
0x2, to indicate that a blockhas passed through an ampersand argument. In all other regards,
this block handler tag is the same as
block_handler_type_iseq.I then use this new tag in Kernel#lambda to implement the
2.4.x spec.
Bug #15620