Skip to content

Commit fcc4403

Browse files
committed
[GR-19839] Clean up primitives.
PullRequest: truffleruby/1170
2 parents 6c7d440 + 0e6eb6e commit fcc4403

File tree

89 files changed

+643
-990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+643
-990
lines changed

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,4 @@ Style/StringLiterals:
373373
# Supports --auto-correct
374374
Style/UnlessElse:
375375
Description: Checks for unless expressions with else clauses.
376-
Enabled: true
376+
Enabled: true

doc/contributor/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ The compiler tests include a sort of test suite for compilation, called the
117117
partial evaluation (*PE*) tests, as well as tests for more subtle things like
118118
on-stack-replacement.
119119

120-
Special methods such as `Truffle::Graal.assert_constant` are used to implement
120+
Special methods such as `TrufflePrimitive.assert_compilation_constant` are used to implement
121121
this.
122122

123123
Compiler tests are in `test/truffle/compiler`.

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

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

2020
test_thread = Thread.new do
2121
begin
22-
eval "loop { Truffle::Graal.assert_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}"
26-
elsif e.message.include? 'Truffle::Graal.assert_constant'
26+
elsif e.message.include? 'TrufflePrimitive.assert_compilation_constant'
2727
puts "No :( Truffle can't constant fold that"
2828
else
2929
puts 'There was an error executing that :('

lib/truffle/digest.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,11 @@ def reset
8383

8484
def digest(message = NO_MESSAGE)
8585
if NO_MESSAGE == message
86-
Truffle.privately do
87-
clone.finish
88-
end
86+
clone.__send__ :finish
8987
else
9088
reset
9189
update message
92-
digested = Truffle.privately { finish }
90+
digested = finish
9391
reset
9492
digested
9593
end

lib/truffle/truffle/cext.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def rb_obj_instance_variables(object)
616616
end
617617

618618
def rb_copy_generic_ivar(clone, original)
619-
Truffle.check_frozen(clone)
619+
TrufflePrimitive.check_frozen clone
620620
original_ivars = original.instance_variables
621621
rb_free_generic_ivar(clone)
622622
original_ivars.each do |var|
@@ -625,7 +625,7 @@ def rb_copy_generic_ivar(clone, original)
625625
end
626626

627627
def rb_free_generic_ivar(original)
628-
Truffle.check_frozen(original)
628+
TrufflePrimitive.check_frozen original
629629
original_ivars = original.instance_variables
630630
original_ivars.each do |var|
631631
original.__send__ :remove_instance_variable, var
@@ -1257,9 +1257,7 @@ def rb_io_puts(out, args)
12571257
end
12581258

12591259
def rb_obj_call_init(obj, args)
1260-
Truffle.privately do
1261-
obj.initialize(*args)
1262-
end
1260+
obj.__send__ :initialize, *args
12631261
end
12641262

12651263
def rb_obj_instance_eval(obj, args, block)
@@ -1363,15 +1361,11 @@ def rb_complex_polar(r, theta)
13631361
end
13641362

13651363
def rb_complex_set_real(complex, real)
1366-
Truffle.privately do
1367-
complex.real = real
1368-
end
1364+
complex.__send__ :real=, real
13691365
end
13701366

13711367
def rb_complex_set_imag(complex, imag)
1372-
Truffle.privately do
1373-
complex.imag = imag
1374-
end
1368+
complex.__send__ :imag=, imag
13751369
end
13761370

13771371
def rb_mutex_new

spec/truffle/graal/assert_constant_spec.rb

Lines changed: 3 additions & 3 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_constant" do
11+
describe "TrufflePrimitive.assert_compilation_constant" do
1212

1313
it "raises a RuntimeError when called dynamically" do
14-
-> { Truffle::Graal.send(:assert_constant, 14 + 2) }.should raise_error(RuntimeError)
14+
-> { tp = TrufflePrimitive; tp.assert_constant(14 + 2) }.should raise_error(NoMethodError, /syntactically/)
1515
end
1616

1717
guard -> { !TruffleRuby.jit? } do
1818
it "returns the value of the argument" do
19-
Truffle::Graal.assert_constant(14 + 2).should == 16
19+
TrufflePrimitive.assert_compilation_constant(14 + 2).should == 16
2020
end
2121
end
2222

spec/truffle/graal/assert_not_compiled_spec.rb

Lines changed: 3 additions & 3 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
14-
-> { Truffle::Graal.send(:assert_not_compiled) }.should raise_error(RuntimeError)
14+
-> { tp = TrufflePrimitive; tp.assert_not_compiled }.should raise_error(NoMethodError, /syntactically/)
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

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/annotations/java/org/truffleruby/builtins/CoreMethod.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@
5959
boolean needsBlock() default false;
6060

6161
/**
62-
* Try to lower argument <code>i</code> (starting at 1) to an int if its value is a long.
63-
* Use 0 for <code>self</code>.
62+
* Try to lower argument <code>i</code> (starting at 0) to an int if its value is a long.
63+
* The 0 is reserved for <code>self</code>.
64+
* If {@link #needsSelf() needsSelf} is false then there is no 0 argument explicitly passed.
65+
* Therefore the remaining arguments start at 1.
6466
*/
6567
int[] lowerFixnum() default {};
6668

src/annotations/java/org/truffleruby/builtins/Primitive.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@
2020

2121
String name();
2222

23-
// TODO (eregon, 28 Sept 2019): is this still needed?
24-
boolean needsSelf() default true;
25-
2623
/**
27-
* Try to lower argument <code>i</code> (starting at 1) to an int if its value is a long.
28-
* Use 0 for <code>self</code>.
24+
* Try to lower argument <code>i</code> (starting at 0) to an int if its value is a long.
25+
* The argument at 0 is usually the <code>receiver</code>.
2926
*/
3027
int[] lowerFixnum() default {};
3128

3229
/**
33-
* Raise an error if self is frozen.
30+
* Raise an error if any of the arguments with a given index is frozen.
31+
* Indexation is same as for {@link #lowerFixnum()}.
3432
*/
35-
boolean raiseIfFrozenSelf() default false;
33+
int[] raiseIfFrozen() default {};
3634

3735
/**
3836
* Use these names in Ruby core methods stubs, ignore argument names in Java specializations.

0 commit comments

Comments
 (0)