Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized forwarding callers and callees #10510

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
150 changes: 150 additions & 0 deletions bootstraptest/test_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1176,3 +1176,153 @@ def foo
foo
foo
}, '[Bug #20178]'

assert_equal 'ok', %q{
def bar(x); x; end
def foo(...); bar(...); end
foo('ok')
}

assert_equal 'ok', %q{
def bar(x); x; end
def foo(z, ...); bar(...); end
foo(1, 'ok')
}

assert_equal 'ok', %q{
def bar(x, y); x; end
def foo(...); bar("ok", ...); end
foo(1)
}

assert_equal 'ok', %q{
def bar(x); x; end
def foo(...); 1.times { return bar(...) }; end
foo("ok")
}

assert_equal 'ok', %q{
def bar(x); x; end
def foo(...); x = nil; 1.times { x = bar(...) }; x; end
foo("ok")
}

assert_equal 'ok', %q{
def bar(x); yield; end
def foo(...); bar(...); end
foo(1) { "ok" }
}

assert_equal 'ok', %q{
def baz(x); x; end
def bar(...); baz(...); end
def foo(...); bar(...); end
foo("ok")
}

assert_equal '[1, 2, 3, 4]', %q{
def baz(a, b, c, d); [a, b, c, d]; end
def bar(...); baz(1, ...); end
def foo(...); bar(2, ...); end
foo(3, 4)
}

assert_equal 'ok', %q{
class Foo; def self.foo(x); x; end; end
class Bar < Foo; def self.foo(...); super; end; end
Bar.foo('ok')
}

assert_equal 'ok', %q{
class Foo; def self.foo(x); x; end; end
class Bar < Foo; def self.foo(...); super(...); end; end
Bar.foo('ok')
}

assert_equal 'ok', %q{
class Foo; def self.foo(x, y); x + y; end; end
class Bar < Foo; def self.foo(...); super("o", ...); end; end
Bar.foo('k')
}

assert_equal 'ok', %q{
def bar(a); a; end
def foo(...); lambda { bar(...) }; end
foo("ok").call
}

assert_equal 'ok', %q{
class Foo; def self.foo(x, y); x + y; end; end
class Bar < Foo; def self.y(&b); b; end; def self.foo(...); y { super("o", ...) }; end; end
Bar.foo('k').call
}

assert_equal 'ok', %q{
def baz(n); n; end
def foo(...); bar = baz(...); lambda { lambda { bar } }; end
foo("ok").call.call
}

assert_equal 'ok', %q{
class A; def self.foo(...); new(...); end; attr_reader :b; def initialize(a, b:"ng"); @a = a; @b = b; end end
A.foo(1).b
A.foo(1, b: "ok").b
}

assert_equal 'ok', %q{
class A; def initialize; @a = ["ok"]; end; def first(...); @a.first(...); end; end
def call x; x.first; end
def call1 x; x.first(1); end
call(A.new)
call1(A.new).first
}

assert_equal 'ok', %q{
class A; def foo; yield("o"); end; end
class B < A; def foo(...); super { |x| yield(x + "k") }; end; end
B.new.foo { |x| x }
}

assert_equal "[1, 2, 3, 4]", %q{
def foo(*b) = b

def forward(...)
splat = [1,2,3]
foo(*splat, ...)
end

forward(4)
}

assert_equal "[1, 2, 3, 4]", %q{
class A
def foo(*b) = b
end

class B < A
def foo(...)
splat = [1,2,3]
super(*splat, ...)
end
end

B.new.foo(4)
}

assert_equal 'ok', %q{
class A; attr_reader :iv; def initialize(...) = @iv = "ok"; end
A.new("foo", bar: []).iv
}

assert_equal 'ok', %q{
def foo(a, b) = a + b
def bar(...) = foo(...)
bar(1, 2)
bar(1, 2)
begin
bar(1, 2, 3)
"ng"
rescue ArgumentError
"ok"
end
}
16 changes: 16 additions & 0 deletions bootstraptest/test_yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4772,6 +4772,22 @@ def entry(define)
entry(true)
}

assert_equal 'ok', %q{
def ok
:ok
end

def delegator(...)
ok(...)
end

def caller
send(:delegator)
end

caller
}

assert_equal '[:ok, :ok, :ok]', %q{
def identity(x) = x
def foo(x, _) = x
Expand Down