Skip to content

Commit b4890b4

Browse files
committed
[GR-45043] Cleanup after migrating to Prism
PullRequest: truffleruby/4142
2 parents 5df847e + 33df281 commit b4890b4

File tree

900 files changed

+13997
-48152
lines changed

Some content is hidden

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

900 files changed

+13997
-48152
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
New features:
44

55
* C/C++ extensions are now compiled using the system toolchain and executed natively instead of using GraalVM LLVM (Sulong). This leads to faster startup, no warmup, better compatibility, smaller distribution and faster installation for C/C++ extensions (#3118, @eregon).
6-
* Full suport for the Ruby 3.2 and Ruby 3.3 syntax by adopting the [Prism](https://github.com/ruby/prism) parser (#3117, #3038, #3039, @andrykonchin, @eregon).
6+
* Full suport for the Ruby 3.2 and Ruby 3.3 syntax by adopting the [Prism](https://github.com/ruby/prism) parser, which is about twice as fast as the old parser (#3117, #3038, #3039, @andrykonchin, @eregon).
77
* Pattern matching is now fully supported, with the exception of Find pattern (`in [*, a, *]`) (#3332, #2683, @eregon, @razetime).
88

99
Bug fixes:

doc/contributor/how-to-guide.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,24 +1139,6 @@ jt -q ruby -e 'puts Truffle::Debug.java_class_of([])'
11391139
RubyArray
11401140
```
11411141
1142-
### Truffle::Debug.yarp_serialize
1143-
1144-
```
1145-
jt -q ruby -e 'puts Truffle::Debug.yarp_serialize("1").dump'
1146-
"YARP\x00\x04\x00@7\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00L\f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00S\x19\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00&\b\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00"
1147-
```
1148-
1149-
### Truffle::Debug.yarp_parse
1150-
1151-
```
1152-
jt -q ruby -e 'puts Truffle::Debug.yarp_parse("[].to_ary")'
1153-
ProgramNode
1154-
Scope
1155-
StatementsNode
1156-
CallNode
1157-
ArrayNode
1158-
```
1159-
11601142
### Truffle::Debug.ast
11611143
11621144
```

doc/contributor/interop_details.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@
7878

7979
# Behavior of interop messages for Ruby objects
8080

81+
## toDisplayString()
82+
83+
When interop message `toDisplayString` is sent
84+
- to
85+
it returns a String representing the object.
86+
- otherwise
87+
it returns the same as `subject.inspect`.
88+
89+
## MetaObject related messages
90+
91+
When interop message `hasMetaObject` is sent
92+
- to **`nil`**, **`:symbol`**, **a `String`**, **a `BigDecimal`**, **an `Object`**, **a frozen `Object`**, **a `StructWithValue`**, **a `Class`**, **a `Hash`**, **an `Array`**, **an `Exception`**, **an `Exception` with a cause**, **`proc {...}`**, **`lambda {...}`**, **a `Method`**, **a `Truffle::FFI::Pointer`**, **polyglot pointer**, **polyglot members**, **polyglot array** or **polyglot hash**
93+
it returns true.
94+
- otherwise
95+
it returns false.
96+
97+
When interop message `getMetaObject` is sent
98+
- to
99+
it returns the Ruby exception's class.
100+
- otherwise
101+
it returns the same Ruby class as `subject.class`.
102+
81103
## `null` related messages
82104

83105
When interop message `isNull` is sent
@@ -329,7 +351,7 @@ When interop message `writeMember` is sent
329351
it writes the given value under the given name.
330352
- to **a `StructWithValue`**
331353
it writes the value to the given struct member.
332-
- to **a `BigDecimal`**, **`nil`**, **`:symbol`** or **a frozen `Object`**
354+
- to **`nil`**, **`false`**, **`true`**, **`:symbol`**, **an `Integer`**, **a `Float`**, **a `BigDecimal`** or **a frozen `Object`**
333355
it fails with `UnsupportedMessageError` when the receiver is frozen.
334356
- otherwise
335357
it fails with `UnsupportedMessageError`.

doc/contributor/parser.md

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

doc/contributor/prism.md

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,74 @@
88

99
## Print Detailed Prism AST
1010

11+
### From the Prism repository
12+
1113
```bash
12-
cd prism
13-
bundle exec rake
14-
bin/parse -e '1&.itself'
14+
$ cd prism
15+
$ bundle exec rake compile
16+
$ bin/parse -e '1&.itself'
17+
@ ProgramNode (location: (1,0)-(1,9))
18+
├── locals: []
19+
└── statements:
20+
@ StatementsNode (location: (1,0)-(1,9))
21+
└── body: (length: 1)
22+
└── @ CallNode (location: (1,0)-(1,9))
23+
├── flags: safe_navigation
24+
├── receiver:
25+
│ @ IntegerNode (location: (1,0)-(1,1))
26+
│ └── flags: decimal
27+
├── call_operator_loc: (1,1)-(1,3) = "&."
28+
├── name: :itself
29+
├── message_loc: (1,3)-(1,9) = "itself"
30+
├── opening_loc: ∅
31+
├── arguments: ∅
32+
├── closing_loc: ∅
33+
└── block: ∅
1534
```
1635

36+
### From TruffleRuby
37+
1738
We can also see what the AST as Java nodes and without extra location fields looks like on TruffleRuby with:
1839
```bash
19-
cd truffleruby
20-
jt -q ruby -e 'puts Truffle::Debug.yarp_parse(ARGV[0])' -- '1&.itself'
40+
$ cd truffleruby
41+
$ jt -q ruby tool/parse_ast.rb '1&.itself'
42+
Source:
43+
1&.itself
44+
45+
AST:
46+
ProgramNode
47+
locals:
48+
statements: StatementsNode
49+
body:
50+
CallNode[Li]
51+
flags: 1
52+
receiver: IntegerNode
53+
flags: 2
54+
name: "itself"
55+
arguments: null
56+
block: null
57+
```
58+
59+
```bash
60+
$ jt -q ruby tool/parse_ast.rb some_file.rb
61+
```
62+
63+
You can also compare to JRuby's AST with:
64+
```bash
65+
$ jruby tool/parse_ast.rb '1&.itself'
66+
Source:
67+
1&.itself
68+
69+
AST:
70+
RootNode line: 0
71+
CallNode*[lazy]:itself line: 0
72+
FixnumNode line: 0, long: 1
73+
, null, null
74+
```
75+
76+
## Print the Truffle AST
77+
78+
```bash
79+
$ cd truffleruby
80+
$ jt -q ruby tool/truffle_ast.rb '1&.itself'
2181
```

doc/contributor/updating-jruby-parser.md

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

doc/contributor/workflow.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,3 @@ file to fix it.
321321

322322
You can also recompute the tags automatically for an entire test file with
323323
`jt retag test/mri/tests/file.rb`.
324-
325-
## Building the parser
326-
327-
TruffleRuby uses the Jay parser generator. A copy of this is located in
328-
`tool/jay`. The command `jt build parser` will build Jay, if needed, and then
329-
regenerate the parser. We check the generated parser into the source repository.

doc/legal/legal.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,6 @@ Engine Yard and are released under an MIT licence (see `mit.txt`).
208208
We do not distribute the FFI Specs, but they are copyright 2008-2014
209209
Ruby-FFI contributors and are released under an MIT licence (see `mit.txt`).
210210

211-
## Jay
212-
213-
TruffleRuby uses the Jay parser generator, modified from
214-
https://github.com/jruby/jay revision `9ffc59a`. Jay is copyright 1989 The
215-
Regents of the University of California, ported by Axel T. Schreiner, and is
216-
covered by the three-clause BSD licence (see `jay.txt`). We only distribute Jay
217-
in the source repository - it isn't part of releases.
218-
219211
## Written offer for source code
220212

221213
For any software that you receive from Oracle in binary form which is licensed

doc/user/debugging.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,41 @@ Also see [Tools](tools.md) for more tools besides just debuggers.
1414

1515
## VSCode
1616

17+
### Simple and Fast
18+
19+
1. Open VSCode in the project you want to debug:
20+
```bash
21+
$ cd /path/to/project
22+
$ code .
23+
```
24+
25+
1. Create a file `.vscode/launch.json` with this contents:
26+
27+
```json
28+
{
29+
"version": "0.2.0",
30+
"configurations": [
31+
{
32+
"name": "Attach",
33+
"type": "node",
34+
"request": "attach",
35+
"debugServer": 4711
36+
}
37+
]
38+
}
39+
```
40+
41+
3. Run TruffleRuby on the command line and pass `--dap`, e.g.
42+
```bash
43+
$ ruby --dap test.rb
44+
$ ruby --dap -Ilib test/some_test.rb
45+
$ TRUFFLERUBYOPT=--dap bundle exec rspec some_spec.rb
46+
```
47+
48+
4. In VSCode click on `Run` -> `Start Debugging`.
49+
50+
### With the GraalVM VSCode extension
51+
1752
First install [the GraalVM VSCode extension](https://marketplace.visualstudio.com/items?itemName=oracle-labs-graalvm.graalvm).
1853

1954
Then follow [this documentation](https://www.graalvm.org/latest/tools/vscode/graalvm-extension/polyglot-runtime/#debugging-ruby) to debug TruffleRuby with VSCode.

spec/ruby/core/kernel/eval_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ class EvalSpecs
270270
ScratchPad.clear
271271
end
272272

273+
it "returns nil if given an empty string" do
274+
eval("").should == nil
275+
end
276+
273277
# See language/magic_comment_spec.rb for more magic comments specs
274278
describe "with a magic encoding comment" do
275279
it "uses the magic comment encoding for the encoding of literal strings" do

spec/truffle/interop/matrix_spec.rb

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,23 @@ def spec_it(subject)
231231
strange_symbol: Subject.(:"strange -=@\0x2397"),
232232
empty_string: Subject.() { "" },
233233
string: Subject.(name: AN_INSTANCE, doc: true) { "string" },
234+
frozen_string: Subject.() { "frozen".freeze },
234235

235236
zero: Subject.(0),
236237
small_integer: Subject.(1, name: AN_INSTANCE, doc: true),
238+
long_integer: Subject.(1 << 60),
239+
big_integer: Subject.(1 << 80),
237240
zero_float: Subject.(0.0),
238241
small_float: Subject.(1.0, name: AN_INSTANCE, doc: true),
239242
big_decimal: Subject.(BigDecimal('1e99'), name: AN_INSTANCE, doc: true),
240243

244+
# Other immutables
245+
range: Subject.(1..),
246+
int_range: Subject.(1..2),
247+
long_range: Subject.((1 << 60)..(1 << 61)),
248+
encoding: Subject.(Encoding::UTF_8),
249+
regexp: Subject.(/regexp/),
250+
241251
object: Subject.(name: AN_INSTANCE, doc: true) { Object.new },
242252
frozen_object: Subject.(name: "a frozen `Object`", doc: true) { Object.new.freeze },
243253
struct: Subject.(name: AN_INSTANCE, doc: true, explanation: "a `Struct` with one property named `value`") { StructWithValue.new DEFAULT },
@@ -312,9 +322,9 @@ def spec_it(subject)
312322
interop_library_reference) { TruffleInteropSpecs::PolyglotHash.new }
313323
}.each { |key, subject| subject.key = key }
314324

315-
immediate_subjects = [:false, :true, :zero, :small_integer, :zero_float, :small_float]
325+
immediate_subjects = [:false, :true, :zero, :small_integer, :long_integer, :zero_float, :small_float]
316326
non_immediate_subjects = SUBJECTS.keys - immediate_subjects
317-
frozen_subjects = [:big_decimal, :nil, :symbol, :strange_symbol, :frozen_object]
327+
frozen_subjects = SUBJECTS.each_pair.select { |key, subject| key != :raise_exception && subject.value.frozen? }.map(&:first)
318328
exception_subjects = [:exception, :exception_with_cause, :raise_exception]
319329

320330
# not part of the standard matrix, not considered in last rest case
@@ -352,6 +362,28 @@ def array_element_predicate(message, predicate, insert_on_true_case)
352362
end
353363

354364
MESSAGES = [
365+
Delimiter["toDisplayString()"],
366+
Message[:toDisplayString,
367+
Test.new("returns a String representing the object", :strange_symbol, :raise_exception) do |subject|
368+
Truffle::Interop.should.string? Truffle::Interop.to_display_string(subject)
369+
end,
370+
Test.new("returns the same as `subject.inspect`") do |subject|
371+
Truffle::Interop.to_display_string(subject).should == subject.inspect
372+
end],
373+
374+
Delimiter["MetaObject related messages"],
375+
Message[:hasMetaObject,
376+
Test.new("returns true", *non_immediate_subjects, &predicate(:has_meta_object?, true)),
377+
Test.new("returns false", &predicate(:has_meta_object?, false))],
378+
Message[:getMetaObject,
379+
Test.new("returns the Ruby exception's class", :raise_exception) do |subject|
380+
Truffle::Interop.meta_object(subject).should == RuntimeError
381+
end,
382+
Test.new("returns the same Ruby class as `subject.class`") do |subject|
383+
# It works for immediate_subjects too because of Truffle::Interop.meta_object handling that
384+
Truffle::Interop.meta_object(subject).should == subject.class
385+
end],
386+
355387
Delimiter["`null` related messages"],
356388
Message[:isNull,
357389
Test.new("returns true", :nil, &predicate(:null?, true)),

spec/truffle/interop/meta_object_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
Truffle::Interop.meta_object([1, 2, 3]).should == Array
3030
end
3131

32+
it "returns Range class for a range" do
33+
Truffle::Interop.should.has_meta_object?(1..)
34+
Truffle::Interop.should.has_meta_object?(1..2)
35+
Truffle::Interop.should.has_meta_object?((1<<60)..(1<<61))
36+
37+
Truffle::Interop.meta_object(1..).should == Range
38+
Truffle::Interop.meta_object(1..2).should == Range
39+
Truffle::Interop.meta_object((1<<60)..(1<<61)).should == Range
40+
end
41+
3242
it "returns a Ruby class implementing all meta objects methods" do
3343
meta = Truffle::Interop.meta_object("string")
3444
Truffle::Interop.meta_simple_name(meta).should == 'String'

0 commit comments

Comments
 (0)