Skip to content

Commit fde88d4

Browse files
committed
[GR-26781] Cleanups related to passing keyword arguments
PullRequest: truffleruby/2223
2 parents fb40eff + faff809 commit fde88d4

25 files changed

+41
-89
lines changed

spec/ruby/language/hash_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ def h.to_hash; {:b => 2, :c => 3}; end
149149
-> { {**obj} }.should raise_error(TypeError)
150150
end
151151

152+
it "raises a TypeError if the object does not respond to #to_hash" do
153+
obj = 42
154+
-> { {**obj} }.should raise_error(TypeError)
155+
-> { {a: 1, **obj} }.should raise_error(TypeError)
156+
end
157+
152158
it "does not change encoding of literal string keys during creation" do
153159
binary_hash = HashStringsBinary.literal_hash
154160
utf8_hash = HashStringsUTF8.literal_hash

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
import com.oracle.truffle.api.profiles.ConditionProfile;
116116
import com.oracle.truffle.api.source.SourceSection;
117117

118-
119118
@CoreModule("Truffle::CExt")
120119
public class CExtNodes {
121120

src/main/java/org/truffleruby/core/basicobject/BasicObjectNodes.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
import com.oracle.truffle.api.object.DynamicObjectLibrary;
8585
import com.oracle.truffle.api.profiles.ConditionProfile;
8686

87-
8887
@CoreModule(value = "BasicObject", isClass = true)
8988
public abstract class BasicObjectNodes {
9089

src/main/java/org/truffleruby/core/cast/ArrayCastNode.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.oracle.truffle.api.frame.VirtualFrame;
2626
import com.oracle.truffle.api.profiles.BranchProfile;
2727

28-
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_RETURN_MISSING;
2928

3029
/*
3130
* TODO(CS): could probably unify this with SplatCastNode with some final configuration getContext().getOptions().
@@ -37,8 +36,6 @@ public abstract class ArrayCastNode extends RubyContextSourceNode {
3736

3837
private final SplatCastNode.NilBehavior nilBehavior;
3938

40-
@Child private DispatchNode toArrayNode = DispatchNode.create(PRIVATE_RETURN_MISSING);
41-
4239
public static ArrayCastNode create() {
4340
return ArrayCastNodeGen.create(null);
4441
}
@@ -104,9 +101,10 @@ protected Object cast(Nil nil) {
104101

105102
@Specialization(guards = { "!isRubyBignum(object)", "!isRubyArray(object)" })
106103
protected Object cast(RubyDynamicObject object,
107-
@Cached BranchProfile errorProfile) {
108-
final Object result = toArrayNode.call(object, "to_ary");
104+
@Cached BranchProfile errorProfile,
105+
@Cached(parameters = "PRIVATE_RETURN_MISSING") DispatchNode toArrayNode) {
109106

107+
final Object result = toArrayNode.call(object, "to_ary");
110108
if (result == nil) {
111109
return nil;
112110
}

src/main/java/org/truffleruby/core/cast/HashCastNode.java

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
package org.truffleruby.core.cast;
1111

1212
import org.truffleruby.core.hash.RubyHash;
13-
import org.truffleruby.core.numeric.RubyBignum;
14-
import org.truffleruby.language.Nil;
1513
import org.truffleruby.language.RubyContextSourceNode;
16-
import org.truffleruby.language.RubyDynamicObject;
1714
import org.truffleruby.language.RubyGuards;
1815
import org.truffleruby.language.RubyNode;
1916
import org.truffleruby.language.control.RaiseException;
@@ -24,59 +21,27 @@
2421
import com.oracle.truffle.api.frame.VirtualFrame;
2522
import com.oracle.truffle.api.profiles.BranchProfile;
2623

27-
import static org.truffleruby.language.dispatch.DispatchConfiguration.PRIVATE_RETURN_MISSING;
28-
29-
// TODO(CS): copy and paste of ArrayCastNode
30-
3124
@NodeChild(value = "child", type = RubyNode.class)
3225
public abstract class HashCastNode extends RubyContextSourceNode {
3326

34-
@Child private DispatchNode toHashNode = DispatchNode.create(PRIVATE_RETURN_MISSING);
35-
3627
protected abstract RubyNode getChild();
3728

3829
@Specialization
39-
protected Object cast(boolean value) {
40-
return nil;
41-
}
42-
43-
@Specialization
44-
protected Object cast(int value) {
45-
return nil;
46-
}
47-
48-
@Specialization
49-
protected Object cast(long value) {
50-
return nil;
51-
}
52-
53-
@Specialization
54-
protected Object cast(double value) {
55-
return nil;
56-
}
57-
58-
@Specialization
59-
protected Object castNil(Nil nil) {
60-
return nil;
61-
}
62-
63-
@Specialization
64-
protected Object castBignum(RubyBignum value) {
65-
return nil;
66-
}
67-
68-
@Specialization
69-
protected Object castHash(RubyHash hash) {
30+
protected RubyHash castHash(RubyHash hash) {
7031
return hash;
7132
}
7233

73-
@Specialization(guards = { "!isRubyBignum(object)", "!isRubyHash(object)" })
74-
protected Object cast(RubyDynamicObject object,
75-
@Cached BranchProfile errorProfile) {
34+
@Specialization(guards = "!isRubyHash(object)")
35+
protected RubyHash cast(Object object,
36+
@Cached BranchProfile errorProfile,
37+
@Cached(parameters = "PRIVATE_RETURN_MISSING") DispatchNode toHashNode) {
7638
final Object result = toHashNode.call(object, "to_hash");
7739

7840
if (result == DispatchNode.MISSING) {
79-
return nil;
41+
errorProfile.enter();
42+
throw new RaiseException(
43+
getContext(),
44+
coreExceptions().typeErrorNoImplicitConversion(object, "Hash", this));
8045
}
8146

8247
if (!RubyGuards.isRubyHash(result)) {
@@ -86,7 +51,7 @@ protected Object cast(RubyDynamicObject object,
8651
coreExceptions().typeErrorCantConvertTo(object, "Hash", "to_hash", result, this));
8752
}
8853

89-
return result;
54+
return (RubyHash) result;
9055
}
9156

9257
@Override

src/main/java/org/truffleruby/core/cast/NumericToFloatNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.oracle.truffle.api.dsl.Specialization;
2222
import com.oracle.truffle.api.profiles.BranchProfile;
2323

24-
2524
/** Casts a value into a Ruby Float (double). */
2625
public abstract class NumericToFloatNode extends RubyContextNode {
2726

src/main/java/org/truffleruby/core/cast/ToAryNode.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@
1515
import org.truffleruby.language.control.RaiseException;
1616
import org.truffleruby.language.dispatch.DispatchNode;
1717

18-
import com.oracle.truffle.api.CompilerDirectives;
1918
import com.oracle.truffle.api.dsl.Cached;
2019
import com.oracle.truffle.api.dsl.NodeChild;
2120
import com.oracle.truffle.api.dsl.Specialization;
2221
import com.oracle.truffle.api.profiles.BranchProfile;
2322

24-
2523
@NodeChild(value = "child", type = RubyNode.class)
2624
public abstract class ToAryNode extends RubyContextSourceNode {
2725

28-
@Child private DispatchNode toAryNode;
29-
3026
public static ToAryNode createInternal() {
3127
return ToAryNodeGen.create(null);
3228
}
@@ -40,12 +36,8 @@ protected RubyArray coerceRubyArray(RubyArray array) {
4036

4137
@Specialization(guards = "!isRubyArray(object)")
4238
protected RubyArray coerceObject(Object object,
43-
@Cached BranchProfile errorProfile) {
44-
if (toAryNode == null) {
45-
CompilerDirectives.transferToInterpreterAndInvalidate();
46-
toAryNode = insert(DispatchNode.create());
47-
}
48-
39+
@Cached BranchProfile errorProfile,
40+
@Cached DispatchNode toAryNode) {
4941
final Object coerced;
5042
try {
5143
coerced = toAryNode.call(object, "to_ary");

src/main/java/org/truffleruby/core/cast/ToStringOrSymbolNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.oracle.truffle.api.profiles.BranchProfile;
2626
import org.truffleruby.language.library.RubyStringLibrary;
2727

28-
2928
/** Convert objects to a String by calling #to_str, but leave existing Strings or Symbols as they are. */
3029
@NodeChild(value = "child", type = RubyNode.class)
3130
public abstract class ToStringOrSymbolNode extends RubyContextSourceNode {

src/main/java/org/truffleruby/core/format/convert/ToDoubleWithCoercionNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.oracle.truffle.api.dsl.Specialization;
1818
import com.oracle.truffle.api.frame.VirtualFrame;
1919

20-
2120
@NodeChild("value")
2221
public abstract class ToDoubleWithCoercionNode extends FormatNode {
2322

src/main/java/org/truffleruby/core/format/convert/ToIntegerNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.oracle.truffle.api.dsl.Specialization;
1919
import com.oracle.truffle.api.frame.VirtualFrame;
2020

21-
2221
@NodeChild("value")
2322
public abstract class ToIntegerNode extends FormatNode {
2423

0 commit comments

Comments
 (0)