Skip to content

Commit 464297e

Browse files
committed
[GR-28743] Always-inline Proc#{call,yield,[]}
PullRequest: truffleruby/2455
2 parents 8cd2203 + af3caef commit 464297e

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

spec/truffle/always_inlined_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@
106106
e.backtrace_locations[2].label.should.start_with?('block (4 levels)')
107107
}
108108
end
109+
110+
it "for Proc#call" do
111+
line = 0
112+
-> {
113+
line = __LINE__
114+
proc = -> { raise "foo" }
115+
proc.call
116+
}.should raise_error(RuntimeError, "foo") { |e|
117+
e.backtrace_locations[0].label.should.start_with?('block (5 levels)')
118+
e.backtrace_locations[0].lineno.should == line + 1
119+
e.backtrace_locations[1].label.should.start_with?('block (4 levels)')
120+
e.backtrace_locations[1].lineno.should == line + 2
121+
}
122+
end
109123
end
110124

111125
it "go uncached if seeing too many different always-inlined methods at a call site" do

src/main/java/org/truffleruby/core/proc/ProcNodes.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
package org.truffleruby.core.proc;
1111

12+
import com.oracle.truffle.api.RootCallTarget;
13+
import com.oracle.truffle.api.dsl.GenerateUncached;
14+
import com.oracle.truffle.api.frame.Frame;
1215
import org.jcodings.specific.UTF8Encoding;
1316
import org.truffleruby.builtins.CoreMethod;
1417
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
@@ -20,6 +23,7 @@
2023
import org.truffleruby.core.array.RubyArray;
2124
import org.truffleruby.core.binding.BindingNodes;
2225
import org.truffleruby.core.binding.RubyBinding;
26+
import org.truffleruby.core.inlined.AlwaysInlinedMethodNode;
2327
import org.truffleruby.core.klass.RubyClass;
2428
import org.truffleruby.core.rope.CodeRange;
2529
import org.truffleruby.core.string.RubyString;
@@ -186,13 +190,13 @@ protected RubyBinding binding(RubyProc proc) {
186190
}
187191
}
188192

189-
@CoreMethod(names = { "call", "[]", "yield" }, rest = true, needsBlock = true)
190-
public abstract static class CallNode extends CoreMethodArrayArgumentsNode {
191-
192-
@Child private CallBlockNode callBlockNode = CallBlockNode.create();
193+
@GenerateUncached
194+
@CoreMethod(names = { "call", "[]", "yield" }, rest = true, needsBlock = true, alwaysInlined = true)
195+
public abstract static class CallNode extends AlwaysInlinedMethodNode {
193196

194197
@Specialization
195-
protected Object call(RubyProc proc, Object[] args, Object block) {
198+
protected Object call(Frame callerFrame, RubyProc proc, Object[] args, Object block, RootCallTarget target,
199+
@Cached CallBlockNode callBlockNode) {
196200
return callBlockNode.executeCallBlock(
197201
proc.declarationContext,
198202
proc,

test/truffle/cexts/backtraces/expected.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ Test with an internal error from rb_mutex_lock()
1616

1717
Test error in Ruby => C ext => Ruby => C ext Proc => Ruby
1818
/bin/backtraces:59:in `block in bar': error (RuntimeError)
19-
from /lib/truffle/truffle/cext.rb:n:in `call'
2019
from /lib/truffle/truffle/cext.rb:n:in `rb_funcall'
2120
from /ext/backtraces/backtraces.c:5:in `baz'
2221
from /lib/truffle/truffle/cext.rb:n:in `block in rb_proc_new'
23-
from /bin/backtraces:59:in `call'
2422
from /bin/backtraces:59:in `bar'
2523
from /lib/truffle/truffle/cext.rb:n:in `rb_funcall'
2624
from /ext/backtraces/backtraces.c:9:in `foo'
@@ -30,7 +28,6 @@ Test error in Ruby => C ext => Ruby => C ext Proc => Ruby
3028
Test error in the callback to the Sulong-instrinsified qsort()
3129
[1, 2, 3, 4]
3230
/bin/backtraces:76:in `block in <main>': error from Ruby called from instrinsified qsort() (RuntimeError)
33-
from /lib/truffle/truffle/cext.rb:n:in `call'
3431
from /lib/truffle/truffle/cext.rb:n:in `rb_funcall'
3532
from /ext/backtraces/backtraces.c:17:in `compare_function'
3633
from com.oracle.truffle.llvm.libraries.bitcode/src/qsort.c:n:in `sulong_qsort'
@@ -43,7 +40,6 @@ Test error in callback from a native function
4340
42
4441
/bin/backtraces:88:in `error_helper': error from Ruby called from Sulong called from native callback (RuntimeError)
4542
from /bin/backtraces:93:in `block in <main>'
46-
from /lib/truffle/truffle/cext.rb:n:in `call'
4743
from /lib/truffle/truffle/cext.rb:n:in `rb_funcall'
4844
from /ext/backtraces/backtraces.c:38:in `sulong_callback'
4945
from /ext/backtraces/backtraces.c:44:in `native_callback'

0 commit comments

Comments
 (0)