Skip to content

Commit 20b9eaf

Browse files
committed
[GR-45043] Integrate YARP parser [Part 5]
PullRequest: truffleruby/4030
2 parents a4a9d08 + c821a7f commit 20b9eaf

File tree

341 files changed

+3758
-1795
lines changed

Some content is hidden

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

341 files changed

+3758
-1795
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Bug fixes:
99
* Fix `rb_enc_left_char_head()` so it is not always `ArgumentError` (#3267, @eregon).
1010
* Fix `IO.copy_stream` with a `Tempfile` destination (#3280, @eregon).
1111
* Fix `Regexp.union` negotiating the wrong result encoding (#3287, @nirvdrum, @simonlevasseur).
12+
* Fix `Proc#parameters` and return all the numbered parameters lower than the used explicitly ones (@andrykonchin).
1213

1314
Compatibility:
1415

spec/ruby/language/numbered_parameters_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@
8282
lambda { _9 }.arity.should == 9
8383
end
8484

85+
it "affects block parameters" do
86+
-> { _1 }.parameters.should == [[:req, :_1]]
87+
-> { _2 }.parameters.should == [[:req, :_1], [:req, :_2]]
88+
89+
proc { _1 }.parameters.should == [[:opt, :_1]]
90+
proc { _2 }.parameters.should == [[:opt, :_1], [:opt, :_2]]
91+
end
92+
93+
it "affects binding local variables" do
94+
-> { _1; binding.local_variables }.call("a").should == [:_1]
95+
-> { _2; binding.local_variables }.call("a", "b").should == [:_1, :_2]
96+
end
97+
8598
it "does not work in methods" do
8699
obj = Object.new
87100
def obj.foo; _1 end

spec/tags/truffle/parsing/parsing_tags.txt

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,86 +2,27 @@ fails:Parsing a BEGIN block (BEGIN { ... }) case is parsed correctly
22
fails:Parsing a END block (END { ... }) case is parsed correctly
33
fails:Parsing a Encoding keyword (__ENCODING__ keyword) case is parsed correctly
44
fails:Parsing a begin ... end block (with multiple expressions inside a block) case is parsed correctly
5-
fails:Parsing a Block (Argument descriptors / when numbered parameters used in a block) case is parsed correctly
6-
fails:Parsing a Block (Argument descriptors / with block (def a(&b))) case is parsed correctly
7-
fails:Parsing a Block (Argument descriptors / with double splat operator (**kw)) case is parsed correctly
8-
fails:Parsing a Block (Argument descriptors / with double splat operator without variable name (**)) case is parsed correctly
9-
fails:Parsing a Block (Argument descriptors / with keyword arguments) case is parsed correctly
10-
fails:Parsing a Block (Argument descriptors / with optional keyword arguments) case is parsed correctly
11-
fails:Parsing a Block (Argument descriptors / with optional positional parameters) case is parsed correctly
12-
fails:Parsing a Block (Argument descriptors / when multiple positional parameters only) case is parsed correctly
13-
fails:Parsing a Block (Argument descriptors / with splat operator and preceding and following parameters) case is parsed correctly
14-
fails:Parsing a Block (Argument descriptors / with splat operator without name and preceding and following parameters) case is parsed correctly
5+
6+
# issue with implicit rest parameters is tracked here:
7+
# - https://bugs.ruby-lang.org/issues/19971
8+
# - https://github.com/ruby/prism/issues/1722
159
fails:Parsing a Block (Argument descriptors / with implicit rest parameter (|a,|)) case is parsed correctly
16-
fails:Parsing a Block (Arity / with block (def a(&b))) case is parsed correctly
17-
fails:Parsing a Block (Arity / with double splat operator (**kw)) case is parsed correctly
18-
fails:Parsing a Block (Arity / with keyword arguments) case is parsed correctly
19-
fails:Parsing a Block (Arity / with optional keyword arguments) case is parsed correctly
20-
fails:Parsing a Block (Arity / with optional positional parameters) case is parsed correctly
21-
fails:Parsing a Block (Arity / when multiple positional parameters only) case is parsed correctly
22-
fails:Parsing a Block (Arity / when numbered parameters used in a block) case is parsed correctly
23-
fails:Parsing a Block (Arity / with splat operator and preceding and following parameters) case is parsed correctly
2410
fails:Parsing a Block (Arity / with implicit rest parameter (|a,|)) case is parsed correctly
25-
fails:Parsing a Block (Destructuring array argument / when no rest positional parameter but optional parameters count > 1 - it tries to destruct) case is parsed correctly
26-
fails:Parsing a Block (Destructuring array argument / when no rest positional parameter but required parameters count > 1 - it tries to destruct) case is parsed correctly
27-
fails:Parsing a Block (Destructuring array argument / when no rest positional parameter but one required parameter and one optional one - it tries to destruct) case is parsed correctly
28-
fails:Parsing a Block (Destructuring array argument / when rest positional parameter and multiple required terminating ones - it tries to destruct) case is parsed correctly
29-
fails:Parsing a Block (Destructuring array argument / when rest positional parameter and multiple required ones - it tries to destruct) case is parsed correctly
30-
fails:Parsing a Block (Destructuring array argument / when no positional parameters (required/optional/rest) - it doesn't try to destruct) case is parsed correctly
31-
fails:Parsing a Block (Destructuring array argument / when one optional positional parameter - it doesn't try to destruct) case is parsed correctly
32-
fails:Parsing a Block (Destructuring array argument / when one required positional parameter - it doesn't try to destruct) case is parsed correctly
33-
fails:Parsing a Block (Destructuring array argument / when no positional parameters but a rest parameter - it doesn't try to destruct) case is parsed correctly
34-
fails:Parsing a Block (Destructuring array argument / when a rest parameter and optional positional parameters - it doesn't try to destruct) case is parsed correctly
35-
fails:Parsing a Block (Name / in a block) case is parsed correctly
36-
fails:Parsing a Block (Name / in a method) case is parsed correctly
37-
fails:Parsing a Block (Name / at top level) case is parsed correctly
38-
fails:Parsing a Block (Parameters to local variables / with block (proc { |&b| })) case is parsed correctly
39-
fails:Parsing a Block (Parameters to local variables / with double splat operator (**kw)) case is parsed correctly
40-
fails:Parsing a Block (Parameters to local variables / with keyword arguments) case is parsed correctly
41-
fails:Parsing a Block (Parameters to local variables / with optional keyword arguments) case is parsed correctly
42-
fails:Parsing a Block (Parameters to local variables / with optional positional parameters) case is parsed correctly
43-
fails:Parsing a Block (Parameters to local variables / when multiple positional parameters only) case is parsed correctly
44-
fails:Parsing a Block (Parameters to local variables / when numbered parameters used in a block) case is parsed correctly
45-
fails:Parsing a Block (Parameters to local variables / with splat operator and preceding and following parameters) case is parsed correctly
46-
fails:Parsing a Block (Parameters to local variables / without parameters) case is parsed correctly
47-
fails:Parsing a Block (Tail expression / with explicit return inside then branch of the `if` operator) case is parsed correctly
48-
fails:Parsing a Block (Tail expression / with explicit return inside then/else branches of the `if` operator) case is parsed correctly
49-
fails:Parsing a Block (Tail expression / with explicit return at the end of a sequence of multiple expressions) case is parsed correctly
50-
fails:Parsing a Block (Tail expression / with explicit return) case is parsed correctly
51-
fails:Parsing a Block (Tail expression / with explicit return inside then branch of the `unless` operator) case is parsed correctly
52-
fails:Parsing a Block (a block with empty body) case is parsed correctly
53-
fails:Parsing a Block (a block with not empty body) case is parsed correctly
54-
fails:Parsing a Block (a block without parameters) case is parsed correctly
55-
fails:Parsing a Break (within a block) case is parsed correctly
11+
5612
fails:Parsing a class << (reopen an object singleton class) case is parsed correctly
5713
fails:Parsing a Complex number (Complex literal `bri` (without real part) where b is Float is represented as `Complext.convert(0, Rational.convert(b*100, 100))` where 100 is some power of 10 to convert b to Integer) case is parsed correctly
5814
fails:Parsing a Complex number (Complex literal `bri` (without real part) where b is Integer is represented as `Complext.convert(0, Rational.convert(b, 1))`) case is parsed correctly
5915
fails:Parsing a Complex number (Complex literal in format of a + bi is represented as `a + Complex.convert(0, b)`) case is parsed correctly
6016
fails:Parsing a Def (Name / Non singleton / in an anonymous module) case is parsed correctly
6117
fails:Parsing a Def (Name / Singleton / in an anonymous module) case is parsed correctly
6218
fails:Parsing a defined? (with yield in a method body (defined? yield)) case is parsed correctly
63-
fails:Parsing a Ensure keyword (ensure in a do/end block) case is parsed correctly
6419
fails:Parsing a Ensure keyword (ensure in a method) case is parsed correctly
6520
fails:Parsing a For operator (for ... in ... operator) case is parsed correctly
6621
fails:Parsing a Integer (when doesn't fit into Java Long (>= 64 bits)) case is parsed correctly
67-
fails:Parsing a Lambda (literal `-> () { ... }`) case is parsed correctly
68-
fails:Parsing a Local variable (in a block / reading a local variable) case is parsed correctly
69-
fails:Parsing a Local variable (in a block / assigning a local variable new value) case is parsed correctly
70-
fails:Parsing a Local variable (in a block but defined in an outer scope / reading a local variable) case is parsed correctly
71-
fails:Parsing a Local variable (in a block but defined in an outer scope / assigning a local variable new value) case is parsed correctly
7222
fails:Parsing a Method call (super / in a method body with explicit arguments) case is parsed correctly
7323
fails:Parsing a Method call (super / in a method body without explicit arguments) case is parsed correctly
7424
fails:Parsing a Method call (super / outside a method body with explicit arguments) case is parsed correctly
7525
fails:Parsing a Method call (super / outside a method body without explicit arguments) case is parsed correctly
76-
fails:Parsing a Method call (Arguments/with a &-deconstruction to a block argument (&bar)) case is parsed correctly
77-
fails:Parsing a Method call (Arguments/with block literal argument) case is parsed correctly
78-
fails:Parsing a Method call (Arguments/with double splat operator (**kw)) case is parsed correctly
79-
fails:Parsing a Method call (Arguments/with keyword arguments) case is parsed correctly
80-
fails:Parsing a Method call (Arguments/with positional argument and splat operator (a, *args)) case is parsed correctly
81-
fails:Parsing a Method call (Arguments/with splat operator (*args)) case is parsed correctly
82-
fails:Parsing a Method call (Arguments/with splat operator and positional arguments (*args, a)) case is parsed correctly
83-
fails:Parsing a Method call (Special cases/method #lambda (Kernel#lambda)) case is parsed correctly
84-
fails:Parsing a Method call (Special cases/method #lambda (not Kernel#lambda)) case is parsed correctly
8526
fails:Parsing a Method call (super / in a method body with explicit arguments) case is parsed correctly
8627
fails:Parsing a Method call (super / in a method body without explicit arguments) case is parsed correctly
8728
fails:Parsing a Method call (super / outside a method body with explicit arguments) case is parsed correctly
@@ -95,9 +36,6 @@ fails:Parsing a &&= (Variable assignment/fully qualified constant (::A &&= b)) c
9536
fails:Parsing a &&= (Variable assignment/global variable ($a &&= b)) case is parsed correctly
9637
fails:Parsing a &&= (Variable assignment/instance variable (@a &&= b)) case is parsed correctly
9738
fails:Parsing a &&= (Variable assignment/local variable (a &&= b)) case is parsed correctly
98-
fails:Parsing a Flip-flop operator (in a block) case is parsed correctly
99-
fails:Parsing a Flip-flop operator (in a lambda) case is parsed correctly
100-
fails:Parsing a Flip-flop operator (in a method) case is parsed correctly
10139
fails:Parsing a Match (=~ operator) case is parsed correctly
10240
fails:Parsing a Match (=~ operator/with Regexp literal as a RHS) case is parsed correctly
10341
fails:Parsing a Match (=~ operator/with Regexp literal as a LHS (without named capture groups)) case is parsed correctly
@@ -135,7 +73,6 @@ fails:Parsing a Rescue keyword (backtrace optimization / disabled / when rescue
13573
fails:Parsing a Rescue keyword (backtrace optimization / disabled / when rescue section is Regexp (... rescue /a/)) case is parsed correctly
13674
fails:Parsing a Rescue keyword (backtrace optimization / enabled / when rescue section is __FILE__ constant (... rescue __FILE__)) case is parsed correctly
13775
fails:Parsing a Rescue keyword (backtrace optimization / enabled / when rescue section is local variable defined in outer scope (... rescue a)) case is parsed correctly
138-
fails:Parsing a Rescue keyword (rescue in a do/end block) case is parsed correctly
13976
fails:Parsing a Rescue keyword (rescue in a method) case is parsed correctly
14077
fails:Parsing a Rescue keyword (modifier / backtrace optimization / disabled / when rescue section is Range (... rescue 1..3)) case is parsed correctly
14178
fails:Parsing a Rescue keyword (modifier / backtrace optimization / disabled / when rescue section is Regexp (... rescue /a/)) case is parsed correctly
@@ -144,16 +81,6 @@ fails:Parsing a Rescue keyword (modifier / backtrace optimization / enabled / wh
14481
fails:Parsing a Rescue keyword (with exception and variable) case is parsed correctly
14582
fails:Parsing a Rescue keyword (with multiple rescue branches) case is parsed correctly
14683
fails:Parsing a Rescue keyword (without exception but with a variable) case is parsed correctly
147-
fails:Parsing a Return (return operator in a block (with a value)) case is parsed correctly
148-
fails:Parsing a Return (return operator in a block in a class definition body) case is parsed correctly
149-
fails:Parsing a Return (return operator in a block in a module definition body) case is parsed correctly
150-
fails:Parsing a Return (return operator in a block without a value) case is parsed correctly
151-
fails:Parsing a Return (return operator in a lambda) case is parsed correctly
152-
fails:Parsing a Return (return operator in a lambda in a class definition body) case is parsed correctly
153-
fails:Parsing a Return (return operator in a lambda in a module definition body) case is parsed correctly
154-
fails:Parsing a Return (return operator in a lambda method call) case is parsed correctly
155-
fails:Parsing a Return (return operator in a lambda method call in a class definition body) case is parsed correctly
156-
fails:Parsing a Return (return operator in a lambda method call in a module definition body) case is parsed correctly
15784
fails:Parsing a Sequence of expressions () case is parsed correctly
15885
fails:Parsing a String (Literal with interpolation when when expressions are % String literals) case is parsed correctly
15986
fails:Parsing a String (Literal with interpolation when expressions are Strings) case is parsed correctly

spec/truffle/parsing/fixtures/END.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ast: |
3030
child =
3131
RubyCallNode
3232
attributes:
33-
descriptor = org.truffleruby.language.arguments.EmptyArgumentsDescriptor@...
33+
descriptor = org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor@...
3434
dispatchConfig = PROTECTED
3535
emptyKeywordsProfile = false
3636
flags = 0
@@ -53,7 +53,7 @@ ast: |
5353
BlockDefinitionNodeGen
5454
attributes:
5555
breakID = org.truffleruby.language.control.BreakID@...
56-
callTargets = ProcCallTargets(callTargetForProc = block in <top (required)>, callTargetForLambda = null, altCallTargetCompiler = org.truffleruby.parser.MethodTranslator$$Lambda$.../0x...@...)
56+
callTargets = ProcCallTargets(callTargetForProc = block in <top (required)>, callTargetForLambda = null, altCallTargetCompiler = ...$$Lambda$.../0x...@...)
5757
flags = 0
5858
frameOnStackMarkerSlot = 2
5959
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [])

spec/truffle/parsing/fixtures/block/argument_descriptors/with_block.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ast: |
1313
BlockDefinitionNodeGen
1414
attributes:
1515
breakID = org.truffleruby.language.control.BreakID@...
16-
callTargets = ProcCallTargets(callTargetForProc = block in <top (required)>, callTargetForLambda = null, altCallTargetCompiler = org.truffleruby.parser.MethodTranslator$$Lambda$.../0x...@...)
16+
callTargets = ProcCallTargets(callTargetForProc = block in <top (required)>, callTargetForLambda = null, altCallTargetCompiler = ...$$Lambda$.../0x...@...)
1717
flags = 0
1818
frameOnStackMarkerSlot = 2
1919
sharedMethodInfo = SharedMethodInfo(staticLexicalScope = :: Object, arity = Arity{preRequired = 0, optional = 0, hasRest = false, postRequired = 0, keywordArguments = [], requiredKeywordArgumentsCount = 0, hasKeywordsRest = false}, originName = block in <top (required)>, blockDepth = 1, parseName = block in <top (required)>, notes = <top (required)>, argumentDescriptors = [ArgumentDescriptor(name = bar, type = block)])
@@ -42,7 +42,7 @@ ast: |
4242
WriteLocalVariableNode
4343
attributes:
4444
flags = 0
45-
frameSlot = 0
45+
frameSlot = 0 # (self)
4646
children:
4747
valueNode =
4848
ProfileArgumentNodeGen

0 commit comments

Comments
 (0)