Skip to content

Commit e56d197

Browse files
committed
Update notes in YAML fixtures added for assignment operators
1 parent d39fb66 commit e56d197

17 files changed

+83
-126
lines changed

spec/truffle/parsing/fixtures/operators/&&=/attribute_assignment_with_explicit_self_receiver.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
subject: "&&="
22
description: "Assign attribute with explicit self receiver (self.b &&= c)"
33
notes: >
4-
`a.b &&= c` is translated into `a.b && a.b = c` in the following way:
4+
Method call when receiver is `self` means a private or protected method could be successfully called.
55
6-
```ruby
7-
value_0 = a # execute receiver only once
8-
value_0.b && value_0.b=(c)
9-
```
6+
In AST it's represented with RubyCallNode's field dispatchConfig.
7+
`dispatchConfig = PRIVATE` means a method visibility is ignored.
108
focused_on_node: "org.truffleruby.language.defined.DefinedWrapperNode"
119
ruby: |
1210
self.foo &&= 42

spec/truffle/parsing/fixtures/operators/&&=/attribute_assignment_with_safe_navigation_operator.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
subject: "&&="
22
description: "Assign attribute with safe navigation operator (a&.b &&= c)"
33
notes: >
4-
`a.b &&= c` is translated into `a.b && a.b = c` in the following way:
4+
Safe navigation means `nil` is returned when a not supported method is called on `nil`.
55
6-
```ruby
7-
value_0 = a # execute receiver only once
8-
value_0.b && value_0.b=(c)
9-
```
6+
So actual code looks like:
7+
```ruby
8+
if receiver == nil
9+
return nil
10+
else
11+
...
12+
end
13+
```
14+
15+
This is implemented with the following AST:
16+
(UnlessNodeGen
17+
(IsNilNode
18+
(ReadLocalVariableNode)) # %value_0
19+
(AndNodeGen ...))
1020
focused_on_node: "org.truffleruby.language.defined.DefinedWrapperNode"
1121
ruby: |
1222
a&.foo &&= 42

spec/truffle/parsing/fixtures/operators/&&=/reference_assignment_with_block_argument.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
subject: "&&="
22
description: "Assign an referenced element with block argument (a[&b] &&= c)"
33
notes: >
4-
`a[b] &&= c` is translated into `a[b] && a[b] = c` in the following way:
5-
6-
```ruby
7-
value_1 = b
8-
opelementassign_0 = a
9-
10-
opelementassign_0[value_1] && opelementassign_0[value_1] = c
11-
```
4+
A block argument should be stored in RubyCallNode#block field and not in
5+
a #arguments field with positional ones.
126
yarp_specific: true # wasn't supported
137
focused_on_node: "org.truffleruby.language.control.SequenceNode"
148
ruby: |

spec/truffle/parsing/fixtures/operators/&&=/reference_assignment_with_explicit_self_receiver.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
subject: "&&="
22
description: "Assign an referenced element with explicit self receiver (self[a] &&= b)"
33
notes: >
4-
`a[b] &&= c` is translated into `a[b] && a[b] = c` in the following way:
4+
Method call when receiver is `self` means a private or protected method could be successfully called.
55
6-
```ruby
7-
temp_arg1 = b
8-
temp_receiver = a
9-
10-
temp_receiver[temp_arg1] && temp_receiver[temp_arg1] = c
11-
```
6+
In AST it's represented with RubyCallNode's field dispatchConfig.
7+
`dispatchConfig = PRIVATE` means a method visibility is ignored.
128
yarp_specific: true # don't put self into a local variable and fixed call node and set ignoreVisibility=true
139
focused_on_node: "org.truffleruby.language.control.SequenceNode"
1410
ruby: |

spec/truffle/parsing/fixtures/operators/&&=/reference_assignment_with_multiple_indexes.yaml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
subject: "&&="
22
description: "Assign an element referenced with multiple indexes (a[b, c, d] &&= e)"
33
notes: >
4-
`a[b, c, d] &&= e` is translated into `a[b, c, d] && a[b, c, d] = e` in the following way:
5-
6-
```ruby
7-
temp_arg1 = b
8-
temp_arg2 = c
9-
temp_arg3 = d
10-
temp_receiver = a
11-
12-
temp_receiver[temp_arg1] && temp_receiver[temp_arg1] = c
13-
```
4+
All the arguments should be assigned to local variables to evaluate them only once.
145
focused_on_node: "org.truffleruby.language.control.SequenceNode"
156
ruby: |
167
foo[42, 43, 44] &&= 100500

spec/truffle/parsing/fixtures/operators/&&=/reference_assignment_with_nested_splatted_argument.yaml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
subject: "&&="
22
description: "Assign an element referenced with nested splatted argument (a[*[*b]] &&= c)"
33
notes: >
4-
`a[b, c, d] &&= e` is translated into `a[b, c, d] && a[b, c, d] = e` in the following way:
5-
6-
```ruby
7-
temp_arg1 = b
8-
temp_arg2 = c
9-
temp_arg3 = d
10-
temp_receiver = a
11-
12-
temp_receiver[temp_arg1] && temp_receiver[temp_arg1] = c
13-
```
4+
Nested * operator shouldn't be desugared
145
yarp_specific: true # don't desugar [*a] to a and put only one SplatCastNodeGen to call #to_a only once
15-
# Simplified AST of `foo.[](*[*a], 100500)` and replaced ArrayAppendOneNodeGen by concatenating with array of one element
6+
# Simplified AST of `foo.[]=(*[*a], 100500)` and replaced ArrayAppendOneNodeGen by concatenating with array of one element
167
focused_on_node: "org.truffleruby.language.control.SequenceNode"
178
ruby: |
189
foo[*[*a]] &&= 100500

spec/truffle/parsing/fixtures/operators/&&=/reference_assignment_with_splatted_argument.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
subject: "&&="
22
description: "Assign an element referenced with splatted argument (a[*b] &&= c)"
33
notes: >
4-
`a[b, c, d] &&= e` is translated into `a[b, c, d] && a[b, c, d] = e` in the following way:
4+
Splatting should be specified explicitly for `[]` and `[]=` method calls.
55
6+
So `foo[*a] &&= 100500` is desugared into:
67
```ruby
7-
temp_arg1 = b
8-
temp_arg2 = c
9-
temp_arg3 = d
10-
temp_receiver = a
8+
receiver = foo
9+
argument0 = a
1110
12-
temp_receiver[temp_arg1] && temp_receiver[temp_arg1] = c
11+
receiver.[](*argument0) && receiver.[]=(*argument0, 100500)
1312
```
14-
yarp_specific: true # Simplified AST of `foo.[](*a, 100500)` and replaced ArrayAppendOneNodeGen by concatenating with array of one element
13+
yarp_specific: true # Simplified AST of `foo.[]=(*a, 100500)` and replaced ArrayAppendOneNodeGen by concatenating with array of one element
1514
focused_on_node: "org.truffleruby.language.control.SequenceNode"
1615
ruby: |
1716
foo[*a] &&= 100500

spec/truffle/parsing/fixtures/operators/+=/attribute_assignment_with_explicit_self_receiver.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
subject: "+="
22
description: "Assign attribute with explicit self receiver (self.b += c)"
33
notes: >
4-
`a.b += c` is translated into `a.b = a.b + c` in the following way:
5-
6-
```ruby
7-
temp_receiver = a
8-
temp_receiver.b = temp_receiver.b + c
9-
```
4+
Method call when receiver is `self` means a private or protected method could be successfully called.
5+
6+
In AST it's represented with RubyCallNode's field dispatchConfig.
7+
`dispatchConfig = PRIVATE` means a method visibility is ignored.
108
yarp_specific: true # fixed assigning method call node and set `isAttrAssign = true`
119
focused_on_node: "org.truffleruby.language.control.SequenceNode"
1210
ruby: |

spec/truffle/parsing/fixtures/operators/+=/attribute_assignment_with_safe_navigation_operator.yaml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
subject: "+="
22
description: "Assign attribute with safe navigation operator (a&.b += c)"
33
notes: >
4-
`a&.b += c` is translated into `a.b = a.b + c` in the following way:
5-
6-
```ruby
7-
value_0 = a
8-
value_0.b = value_0.b + c
9-
```
4+
Safe navigation means `nil` is returned when a not supported method is called on `nil`.
5+
6+
So actual code looks like:
7+
```ruby
8+
if receiver == nil
9+
return nil
10+
else
11+
...
12+
end
13+
```
14+
15+
This is implemented with the following AST:
16+
(UnlessNodeGen
17+
(IsNilNode
18+
(ReadLocalVariableNode)) # %value_0
19+
(RubyCallNode ...))
1020
yarp_specific: true # fixed assigning method call node and set `isAttrAssign = true`
1121
focused_on_node: "org.truffleruby.language.control.SequenceNode"
1222
ruby: |

spec/truffle/parsing/fixtures/operators/+=/reference_assignment_with_block_argument.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
subject: "+="
22
description: "Assign a referenced element with block argument (a[&b] += c)"
33
notes: >
4-
`a[b] += c` is translated into `a[b] = a[b] + c` in the following way:
5-
6-
```ruby
7-
value_1 = b
8-
opelementassign_0 = a
9-
10-
opelementassign_0[value_1] = opelementassign_0[value_1] + c
11-
```
4+
A block argument should be stored in RubyCallNode#block field and not in
5+
a #arguments field with positional ones.
126
yarp_specific: true # wasn't supported
137
focused_on_node: "org.truffleruby.language.control.SequenceNode"
148
ruby: |

0 commit comments

Comments
 (0)