Skip to content

Commit fe5b4b4

Browse files
committed
[Truffle] Pulled in almost all of Rubinius's String.
There are a couple bugs in Rubinius 2.4.1's String implementation that are not fixable via monkey-patching. In these case I removed the lines entirely. Most of those have been fixed upstream and so future upgrades won't conflict anyway. The other cases that would fail do so by failing specs, so we'll be able to just upgrade and see what, if anything, is failing.
1 parent c83f089 commit fe5b4b4

File tree

17 files changed

+2077
-623
lines changed

17 files changed

+2077
-623
lines changed

spec/truffle/tags/core/string/casecmp_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ fails:String#casecmp independent of case returns -1 when less than other
22
fails:String#casecmp independent of case returns 0 when equal to other
33
fails:String#casecmp independent of case returns 1 when greater than other
44
fails:String#casecmp independent of case tries to convert other to string using to_str
5-
fails:String#casecmp independent of case raises a TypeError if other can't be converted to a string
65
fails:String#casecmp independent of case in UTF-8 mode for non-ASCII characters returns -1 when numerically less than other
76
fails:String#casecmp independent of case in UTF-8 mode for non-ASCII characters returns 0 when numerically equal to other
87
fails:String#casecmp independent of case in UTF-8 mode for non-ASCII characters returns 1 when numerically greater than other
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fails:String#chomp removes the final carriage return, newline from a multibyte String
2+
fails:String#chomp removes the final carriage return, newline from a non-ASCII String
3+
fails:String#chomp removes the final carriage return, newline from a non-ASCII String when the record separator is changed
4+
fails:String#chomp! removes the final carriage return, newline from a multibyte String
5+
fails:String#chomp! removes the final carriage return, newline from a non-ASCII String
6+
fails:String#chomp! removes the final carriage return, newline from a non-ASCII String when the record separator is changed

spec/truffle/tags/core/string/crypt_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ fails:String#crypt returns a cryptographic hash of self by applying the UNIX cry
22
fails:String#crypt returns '.' prepended to the string for each NULL byte the salt contains
33
fails:String#crypt raises an ArgumentError when the salt is shorter than two characters
44
fails:String#crypt calls #to_str to converts the salt arg to a String
5-
fails:String#crypt raises a type error when the salt arg can't be converted to a string
65
fails:String#crypt taints the result if either salt or self is tainted
76
fails:String#crypt doesn't return subclass instances
87
fails:String#crypt returns NULL bytes prepended to the string when the salt contains NULL bytes
-281 Bytes
Binary file not shown.

spec/truffle/tags/core/string/modulo_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,4 @@ fails:String#% wraps the object in an Array if #to_ary returns nil
9999
fails:String#% raises a TypeError if #to_ary does not return an Array
100100
fails:String#% supports float formats using %e, but Inf, -Inf, and NaN are not floats
101101
fails:String#% supports float formats using %E, but Inf, -Inf, and NaN are not floats
102+
fails:String#% raises an error if NULL or \n appear anywhere else in the format string

spec/truffle/tags/core/string/next_tags.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
fails:String#partition with String returns an array of substrings based on splitting on the given string
22
fails:String#partition with String always returns 3 elements
3-
fails:String#partition with String accepts regexp
4-
fails:String#partition with String sets global vars if regexp used
53
fails:String#partition with String converts its argument using :to_str
6-
fails:String#partition with String raises an error if not convertible to string
74
fails:String#partition with String takes precedence over a given block
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
fails:String#rpartition with String returns an array of substrings based on splitting on the given string
2-
fails:String#rpartition with String always returns 3 elements
31
fails:String#rpartition with String accepts regexp
4-
fails:String#rpartition with String affects $~
5-
fails:String#rpartition with String converts its argument using :to_str
6-
fails:String#rpartition with String raises an error if not convertible to string
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
fails:String#rstrip returns a copy of self with trailing whitespace removed
22
fails:String#rstrip returns a copy of self with all trailing whitespace and NULL bytes removed
3-
fails:String#rstrip! modifies self in place and returns self
4-
fails:String#rstrip! modifies self removing trailing NULL bytes and whitespace
5-
fails:String#rstrip! returns nil if no modifications were made
6-
fails:String#rstrip! raises a RuntimeError on a frozen instance that is modified
7-
fails:String#rstrip! raises a RuntimeError on a frozen instance that would not be modified
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
1-
fails:String#scrub with a default replacement returns self for valid strings
2-
fails:String#scrub with a default replacement replaces invalid byte sequences
3-
fails:String#scrub with a custom replacement returns self for valid strings
4-
fails:String#scrub with a custom replacement replaces invalid byte sequences
5-
fails:String#scrub with a custom replacement replaces groups of sequences together with a single replacement
6-
fails:String#scrub with a custom replacement raises ArgumentError for replacements with an invalid encoding
7-
fails:String#scrub with a custom replacement raises TypeError when a non String replacement is given
8-
fails:String#scrub with a block returns self for valid strings
91
fails:String#scrub with a block replaces invalid byte sequences
102
fails:String#scrub with a block replaces invalid byte sequences using a custom encoding
11-
fails:String#scrub! modifies self for valid strings
12-
fails:String#scrub! accepts blocks

spec/truffle/tags/core/string/squeeze_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ fails:String#squeeze squeezes all chars in a sequence
55
fails:String#squeeze raises an ArgumentError when the parameter is out of sequence
66
fails:String#squeeze taints the result when self is tainted
77
fails:String#squeeze tries to convert each set arg to a string using to_str
8-
fails:String#squeeze raises a TypeError when one set arg can't be converted to a string
98
fails:String#squeeze returns subclass instances when called on a subclass
109
fails:String#squeeze! modifies self in place and returns self
1110
fails:String#squeeze! returns nil if no modifications were made

spec/truffle/tags/core/string/strip_tags.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ fails:String#strip returns a new string with leading and trailing whitespace rem
22
fails:String#strip returns a copy of self with trailing NULL bytes and whitespace
33
fails:String#strip taints the result when self is tainted
44
fails:String#strip! modifies self in place and returns self
5-
fails:String#strip! returns nil if no modifications where made
65
fails:String#strip! modifies self removing trailing NULL bytes and whitespace
7-
fails:String#strip! raises a RuntimeError on a frozen instance that is modified
8-
fails:String#strip! raises a RuntimeError on a frozen instance that would not be modified

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/RubiniusPrimitiveManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public RubiniusPrimitiveConstructor getPrimitive(String name) {
3333
final RubiniusPrimitiveConstructor constructor = primitives.get(name);
3434

3535
if (constructor == null) {
36-
throw new RuntimeException(String.format("Rubinius primitive %s not found", name));
36+
return primitives.get(UndefinedPrimitiveNodes.NAME);
3737
}
3838

3939
return constructor;
@@ -56,6 +56,7 @@ public static RubiniusPrimitiveManager create() {
5656
nodeFactories.addAll(ModulePrimitiveNodesFactory.getFactories());
5757
nodeFactories.addAll(RandomPrimitiveNodesFactory.getFactories());
5858
nodeFactories.addAll(ArrayPrimitiveNodesFactory.getFactories());
59+
nodeFactories.addAll(UndefinedPrimitiveNodesFactory.getFactories());
5960

6061
final Map<String, RubiniusPrimitiveConstructor> primitives = new HashMap<>();
6162

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
3+
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4+
* redistribute it and/or modify it under the terms of the:
5+
*
6+
* Eclipse Public License version 1.0
7+
* GNU General Public License version 2
8+
* GNU Lesser General Public License version 2.1
9+
*/
10+
package org.jruby.truffle.nodes.rubinius;
11+
12+
import com.oracle.truffle.api.dsl.Specialization;
13+
import com.oracle.truffle.api.source.SourceSection;
14+
import org.jruby.truffle.runtime.RubyContext;
15+
16+
/**
17+
* Catch-all class for Rubinius primitives that are invoked but haven't yet been defined. Its only purpose is to
18+
* allow Truffle to parse Rubinius primitive calls without failing during the translation phase. If any code ever
19+
* executes nodes here, things will break and you must implement the primitive in its respective parent.
20+
*/
21+
public abstract class UndefinedPrimitiveNodes {
22+
public final static String NAME = "undefined";
23+
24+
25+
@RubiniusPrimitive(name = NAME)
26+
public static abstract class UndefinedPrimitiveNode extends RubiniusPrimitiveNode {
27+
28+
public UndefinedPrimitiveNode(RubyContext context, SourceSection sourceSection) {
29+
super(context, sourceSection);
30+
}
31+
32+
public UndefinedPrimitiveNode(UndefinedPrimitiveNode prev) {
33+
super(prev);
34+
}
35+
36+
@Specialization
37+
public Object undefined(Object... args) {
38+
throw new UnsupportedOperationException("Undefined Rubinius primitive.");
39+
}
40+
}
41+
42+
}

truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ private void includeModules(RubyModule comparableModule) {
332332
objectClass.include(null, kernelModule);
333333

334334
numericClass.include(null, comparableModule);
335-
stringClass.include(null, comparableModule);
336335
symbolClass.include(null, comparableModule);
337336

338337
arrayClass.include(null, enumerableModule);

0 commit comments

Comments
 (0)