Skip to content

Commit 2913c62

Browse files
committed
Change Truffle::Graal.bailout into a TrufflePrimitive.compiler_bailout
1 parent 6d3d6b0 commit 2913c62

File tree

5 files changed

+17
-66
lines changed

5 files changed

+17
-66
lines changed

spec/truffle/graal/bailout_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88

99
require_relative '../../ruby/spec_helper'
1010

11-
describe "Truffle::Graal.bailout" do
12-
13-
it "raises a RuntimeError when called dynamically" do
14-
-> { Truffle::Graal.send(:bailout, "message") }.should raise_error(RuntimeError)
15-
end
11+
describe "TrufflePrimitive.compiler_bailout" do
1612

1713
guard -> { !TruffleRuby.jit? } do
1814
it "returns nil" do
19-
Truffle::Graal.bailout("message").should be_nil
15+
TrufflePrimitive.compiler_bailout("message").should be_nil
2016
end
2117
end
2218

src/main/java/org/truffleruby/core/exception/CoreExceptions.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ public DynamicObject frozenError(String message, Node currentNode) {
243243

244244
// RuntimeError
245245

246-
public DynamicObject runtimeErrorBailout(Node currentNode) {
247-
return runtimeError("Truffle::Graal.bailout can only be called lexically", currentNode);
248-
}
249-
250246
public DynamicObject runtimeErrorCoverageNotEnabled(Node currentNode) {
251247
return runtimeError("coverage measurement is not enabled", currentNode);
252248
}

src/main/java/org/truffleruby/extra/TruffleGraalNodes.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.truffleruby.extra;
1111

1212
import com.oracle.truffle.api.CompilerDirectives;
13+
import com.oracle.truffle.api.dsl.Cached;
1314
import com.oracle.truffle.api.dsl.NodeChild;
1415
import org.truffleruby.Layouts;
1516
import org.truffleruby.builtins.CoreModule;
@@ -18,6 +19,7 @@
1819
import org.truffleruby.builtins.Primitive;
1920
import org.truffleruby.builtins.PrimitiveNode;
2021
import org.truffleruby.core.proc.ProcType;
22+
import org.truffleruby.interop.ToJavaStringNode;
2123
import org.truffleruby.language.RubyNode;
2224
import org.truffleruby.language.RubyRootNode;
2325
import org.truffleruby.language.arguments.RubyArguments;
@@ -38,17 +40,6 @@
3840
@CoreModule("Truffle::Graal")
3941
public abstract class TruffleGraalNodes {
4042

41-
@CoreMethod(names = "bailout", onSingleton = true, required = 1)
42-
public abstract static class BailoutNode extends CoreMethodArrayArgumentsNode {
43-
44-
@TruffleBoundary
45-
@Specialization(guards = "isRubyString(message)")
46-
protected DynamicObject bailout(DynamicObject message) {
47-
throw new RaiseException(getContext(), coreExceptions().runtimeErrorBailout(this));
48-
}
49-
50-
}
51-
5243
@CoreMethod(names = "always_split", onSingleton = true, required = 1, argumentNames = "method_or_proc")
5344
public abstract static class AlwaysSplitNode extends CoreMethodArrayArgumentsNode {
5445

@@ -189,5 +180,17 @@ private void compiledBoundary() {
189180
}
190181
}
191182

183+
@Primitive(name = "compiler_bailout")
184+
@NodeChild(value = "value", type = RubyNode.class)
185+
public abstract static class BailoutNode extends PrimitiveNode {
186+
187+
@Specialization(guards = "isRubyString(message)")
188+
protected DynamicObject bailout(DynamicObject message,
189+
@Cached ToJavaStringNode toJavaStringNode) {
190+
CompilerDirectives.bailout(toJavaStringNode.executeToJavaString(message));
191+
return nil();
192+
}
193+
}
194+
192195

193196
}

src/main/java/org/truffleruby/parser/BodyTranslator.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@
252252
import org.truffleruby.parser.parser.ParseNodeTuple;
253253
import org.truffleruby.parser.parser.ParserSupport;
254254
import org.truffleruby.parser.scope.StaticScope;
255-
import org.truffleruby.platform.BailoutNode;
256255

257256
import com.oracle.truffle.api.RootCallTarget;
258257
import com.oracle.truffle.api.Truffle;
@@ -513,16 +512,7 @@ public RubyNode visitCallNode(CallParseNode node) {
513512
return addNewlineIfNeeded(node, ret);
514513
}
515514

516-
if (receiver instanceof Colon2ConstParseNode // Truffle::Graal.<method>
517-
&& ((Colon2ConstParseNode) receiver).getLeftNode() instanceof ConstParseNode &&
518-
((ConstParseNode) ((Colon2ConstParseNode) receiver).getLeftNode()).getName().equals("Truffle") &&
519-
((Colon2ConstParseNode) receiver).getName().equals("Graal")) {
520-
if (methodName.equals("bailout")) {
521-
final RubyNode ret = BailoutNode.create(((ArrayParseNode) node.getArgsNode()).get(0).accept(this));
522-
ret.unsafeSetSourceSection(sourceSection);
523-
return addNewlineIfNeeded(node, ret);
524-
}
525-
} else if (receiver instanceof VCallParseNode // undefined.equal?(obj)
515+
if (receiver instanceof VCallParseNode // undefined.equal?(obj)
526516
&& ((VCallParseNode) receiver).getName().equals("undefined") && inCore() &&
527517
methodName.equals("equal?")) {
528518
RubyNode argument = translateArgumentsAndBlock(sourceSection, null, node.getArgsNode(), methodName)

src/main/java/org/truffleruby/platform/BailoutNode.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)