Skip to content

Commit 6d3d6b0

Browse files
committed
Change Truffle::Graal.assert_not_compiled into a TrufflePrimitive.assert_not_compiled
1 parent 0dfa9c1 commit 6d3d6b0

File tree

10 files changed

+34
-73
lines changed

10 files changed

+34
-73
lines changed

doc/samples/can-we-fold-yet.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
test_thread = Thread.new do
2121
begin
22-
eval "loop { TrufflePrimitive.assert_compilation_constant #{code}; Truffle::Graal.assert_not_compiled; Thread.pass }"
22+
eval "loop { TrufflePrimitive.assert_compilation_constant #{code}; TrufflePrimitive.assert_not_compiled; Thread.pass }"
2323
rescue Truffle::GraalError => e
24-
if e.message.include? 'Truffle::Graal.assert_not_compiled'
24+
if e.message.include? 'TrufflePrimitive.assert_not_compiled'
2525
puts "Yes! Truffle can constant fold this to #{eval(code).inspect}"
2626
elsif e.message.include? 'TrufflePrimitive.assert_compilation_constant'
2727
puts "No :( Truffle can't constant fold that"

spec/truffle/graal/assert_not_compiled_spec.rb

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

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

11-
describe "Truffle::Graal.assert_not_compiled" do
11+
describe "TrufflePrimitive.assert_not_compiled" do
1212

1313
it "raises a RuntimeError when called dynamically" do
1414
-> { Truffle::Graal.send(:assert_not_compiled) }.should raise_error(RuntimeError)
1515
end
1616

1717
guard -> { !TruffleRuby.jit? } do
1818
it "returns nil" do
19-
Truffle::Graal.assert_not_compiled.should be_nil
19+
TrufflePrimitive.assert_not_compiled.should be_nil
2020
end
2121
end
2222

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

Lines changed: 1 addition & 5 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 runtimeErrorCompiled(Node currentNode) {
247-
return runtimeError("Truffle::Graal.assert_not_compiled can only be called lexically", currentNode);
248-
}
249-
250246
public DynamicObject runtimeErrorBailout(Node currentNode) {
251247
return runtimeError("Truffle::Graal.bailout can only be called lexically", currentNode);
252248
}
@@ -964,7 +960,7 @@ public DynamicObject graalErrorAssertConstantNotConstant(Node currentNode) {
964960
}
965961

966962
public DynamicObject graalErrorAssertNotCompiledCompiled(Node currentNode) {
967-
return graalError("call to Truffle::Graal.assert_not_compiled was compiled", currentNode);
963+
return graalError("call to TrufflePrimitive.assert_not_compiled was compiled", currentNode);
968964
}
969965

970966
@TruffleBoundary

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@
3838
@CoreModule("Truffle::Graal")
3939
public abstract class TruffleGraalNodes {
4040

41-
@CoreMethod(names = "assert_not_compiled", onSingleton = true)
42-
public abstract static class AssertNotCompiledNode extends CoreMethodArrayArgumentsNode {
43-
44-
@TruffleBoundary
45-
@Specialization
46-
protected DynamicObject assertNotCompiled() {
47-
throw new RaiseException(getContext(), coreExceptions().runtimeErrorCompiled(this));
48-
}
49-
50-
}
51-
5241
@CoreMethod(names = "bailout", onSingleton = true, required = 1)
5342
public abstract static class BailoutNode extends CoreMethodArrayArgumentsNode {
5443

@@ -165,7 +154,7 @@ protected DynamicObject copyCapturedLocals(DynamicObject proc) {
165154

166155
@NodeChild(value = "value", type = RubyNode.class)
167156
@Primitive(name = "assert_compilation_constant")
168-
public abstract static class AssertConstantNode extends PrimitiveNode {
157+
public abstract static class AssertCompilationConstantNode extends PrimitiveNode {
169158

170159
@Specialization
171160
protected Object assertCompilationConstant(Object value) {
@@ -182,5 +171,23 @@ private void notConstantBoundary() {
182171
}
183172
}
184173

174+
@Primitive(name = "assert_not_compiled")
175+
public abstract static class AssertNotCompilationConstantNode extends PrimitiveNode {
176+
177+
@Specialization
178+
protected DynamicObject assertNotCompiled() {
179+
if (CompilerDirectives.inCompiledCode()) {
180+
compiledBoundary();
181+
}
182+
183+
return nil();
184+
}
185+
186+
@TruffleBoundary
187+
private void compiledBoundary() {
188+
throw new RaiseException(getContext(), coreExceptions().graalErrorAssertNotCompiledCompiled(this), true);
189+
}
190+
}
191+
185192

186193
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +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.AssertConstantNodeGen;
256-
import org.truffleruby.platform.AssertNotCompiledNodeGen;
257255
import org.truffleruby.platform.BailoutNode;
258256

259257
import com.oracle.truffle.api.RootCallTarget;
@@ -519,11 +517,7 @@ public RubyNode visitCallNode(CallParseNode node) {
519517
&& ((Colon2ConstParseNode) receiver).getLeftNode() instanceof ConstParseNode &&
520518
((ConstParseNode) ((Colon2ConstParseNode) receiver).getLeftNode()).getName().equals("Truffle") &&
521519
((Colon2ConstParseNode) receiver).getName().equals("Graal")) {
522-
if (methodName.equals("assert_not_compiled")) {
523-
final RubyNode ret = AssertNotCompiledNodeGen.create();
524-
ret.unsafeSetSourceSection(sourceSection);
525-
return addNewlineIfNeeded(node, ret);
526-
} else if (methodName.equals("bailout")) {
520+
if (methodName.equals("bailout")) {
527521
final RubyNode ret = BailoutNode.create(((ArrayParseNode) node.getArgsNode()).get(0).accept(this));
528522
ret.unsafeSetSourceSection(sourceSection);
529523
return addNewlineIfNeeded(node, ret);

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

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

test/truffle/compiler/osr/osr.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
begin
1414
while Time.now < timeout
15-
Truffle::Graal.assert_not_compiled
15+
TrufflePrimitive.assert_not_compiled
1616
end
17-
17+
1818
puts 'while loop optimisation timed out'
1919
exit 1
2020
rescue Truffle::GraalError => e
21-
if e.message.include? 'Truffle::Graal.assert_not_compiled'
21+
if e.message.include? 'TrufflePrimitive.assert_not_compiled'
2222
puts 'while loop optimising'
2323
exit 0
2424
else

test/truffle/compiler/pe/pe.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ def report(status, code, message = nil)
121121
eval "
122122
def test_pe_code
123123
value = TrufflePrimitive.assert_compilation_constant(begin; #{example.code}; end)
124-
Truffle::Graal.assert_not_compiled
124+
TrufflePrimitive.assert_not_compiled
125125
value
126126
end"
127127
while true
128128
value = test_pe_code
129129
end
130130
rescue Truffle::GraalError => e
131-
if e.message.include? 'Truffle::Graal.assert_not_compiled'
131+
if e.message.include? 'TrufflePrimitive.assert_not_compiled'
132132
constant = true
133133
elsif e.message.include? 'TrufflePrimitive.assert_compilation_constant'
134134
constant = false

test/truffle/compiler/stf-optimises/stf-optimises.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def foo
2424
x = foo
2525
raise 'value not correct' unless x == 200
2626
TrufflePrimitive.assert_compilation_constant x
27-
Truffle::Graal.assert_not_compiled
27+
TrufflePrimitive.assert_not_compiled
2828
end
2929
rescue Truffle::GraalError => e
30-
if e.message.include? 'Truffle::Graal.assert_not_compiled'
30+
if e.message.include? 'TrufflePrimitive.assert_not_compiled'
3131
puts 'STF optimising'
3232
exit 0
3333
elsif e.message.include? 'TrufflePrimitive.assert_compilation_constant'

test/truffle/compiler/tp-optimises/tp-optimises.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def foo
2626
x = foo
2727
raise 'value not correct' unless x == 200
2828
TrufflePrimitive.assert_compilation_constant x
29-
Truffle::Graal.assert_not_compiled
29+
TrufflePrimitive.assert_not_compiled
3030
end
3131
rescue Truffle::GraalError => e
32-
if e.message.include? 'Truffle::Graal.assert_not_compiled'
32+
if e.message.include? 'TrufflePrimitive.assert_not_compiled'
3333
puts 'TP optimising'
3434
exit 0
3535
elsif e.message.include? 'TrufflePrimitive.assert_compilation_constant'

0 commit comments

Comments
 (0)