Skip to content

Commit c746f38

Browse files
matthewdjhawthorn
andauthored
YJIT: Support nil and blockparamproxy as blockarg in send (#6492)
Co-authored-by: John Hawthorn <john@hawthorn.email> Co-authored-by: John Hawthorn <john@hawthorn.email>
1 parent fa0adba commit c746f38

File tree

7 files changed

+221
-47
lines changed

7 files changed

+221
-47
lines changed

bootstraptest/test_yjit.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,3 +3337,46 @@ def respond_to_missing?(*) = true
33373337
33383338
5.times.map { opt_and_kwargs(1, c: 2) }.uniq
33393339
}
3340+
3341+
# bmethod with forwarded block
3342+
assert_equal '2', %q{
3343+
define_method(:foo) do |&block|
3344+
block.call
3345+
end
3346+
3347+
def bar(&block)
3348+
foo(&block)
3349+
end
3350+
3351+
bar { 1 }
3352+
bar { 2 }
3353+
}
3354+
3355+
# bmethod with forwarded block and arguments
3356+
assert_equal '5', %q{
3357+
define_method(:foo) do |n, &block|
3358+
n + block.call
3359+
end
3360+
3361+
def bar(n, &block)
3362+
foo(n, &block)
3363+
end
3364+
3365+
bar(0) { 1 }
3366+
bar(3) { 2 }
3367+
}
3368+
3369+
# bmethod with forwarded unwanted block
3370+
assert_equal '1', %q{
3371+
one = 1
3372+
define_method(:foo) do
3373+
one
3374+
end
3375+
3376+
def bar(&block)
3377+
foo(&block)
3378+
end
3379+
3380+
bar { }
3381+
bar { }
3382+
}

test/ruby/test_yjit.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,8 @@ def foo &blk
513513
RUBY
514514
end
515515

516-
def test_getblockparamproxy_with_no_block
517-
# Currently side exits on the send
518-
assert_compiles(<<~'RUBY', insns: [:getblockparamproxy], exits: { send: 2 })
516+
def test_send_blockarg
517+
assert_compiles(<<~'RUBY', insns: [:getblockparamproxy, :send], exits: {})
519518
def bar
520519
end
521520
@@ -526,6 +525,9 @@ def foo &blk
526525
527526
foo
528527
foo
528+
529+
foo { }
530+
foo { }
529531
RUBY
530532
end
531533

yjit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,12 @@ rb_get_iseq_body_local_iseq(const rb_iseq_t *iseq)
592592
return iseq->body->local_iseq;
593593
}
594594

595+
const rb_iseq_t *
596+
rb_get_iseq_body_parent_iseq(const rb_iseq_t *iseq)
597+
{
598+
return iseq->body->parent_iseq;
599+
}
600+
595601
unsigned int
596602
rb_get_iseq_body_local_table_size(const rb_iseq_t *iseq)
597603
{

yjit/bindgen/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ fn main() {
350350
.allowlist_function("rb_get_def_bmethod_proc")
351351
.allowlist_function("rb_iseq_encoded_size")
352352
.allowlist_function("rb_get_iseq_body_local_iseq")
353+
.allowlist_function("rb_get_iseq_body_parent_iseq")
353354
.allowlist_function("rb_get_iseq_body_iseq_encoded")
354355
.allowlist_function("rb_get_iseq_body_stack_max")
355356
.allowlist_function("rb_get_iseq_flags_has_opt")

0 commit comments

Comments
 (0)