Skip to content

Commit

Permalink
[Truffle] Pulled in almost all of Rubinius's String.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nirvdrum committed Mar 30, 2015
1 parent c83f089 commit fe5b4b4
Show file tree
Hide file tree
Showing 17 changed files with 2,077 additions and 623 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/casecmp_tags.txt
Expand Up @@ -2,7 +2,6 @@ fails:String#casecmp independent of case returns -1 when less than other
fails:String#casecmp independent of case returns 0 when equal to other
fails:String#casecmp independent of case returns 1 when greater than other
fails:String#casecmp independent of case tries to convert other to string using to_str
fails:String#casecmp independent of case raises a TypeError if other can't be converted to a string
fails:String#casecmp independent of case in UTF-8 mode for non-ASCII characters returns -1 when numerically less than other
fails:String#casecmp independent of case in UTF-8 mode for non-ASCII characters returns 0 when numerically equal to other
fails:String#casecmp independent of case in UTF-8 mode for non-ASCII characters returns 1 when numerically greater than other
Expand Down
6 changes: 6 additions & 0 deletions spec/truffle/tags/core/string/chomp_tags.txt
@@ -0,0 +1,6 @@
fails:String#chomp removes the final carriage return, newline from a multibyte String
fails:String#chomp removes the final carriage return, newline from a non-ASCII String
fails:String#chomp removes the final carriage return, newline from a non-ASCII String when the record separator is changed
fails:String#chomp! removes the final carriage return, newline from a multibyte String
fails:String#chomp! removes the final carriage return, newline from a non-ASCII String
fails:String#chomp! removes the final carriage return, newline from a non-ASCII String when the record separator is changed
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/crypt_tags.txt
Expand Up @@ -2,7 +2,6 @@ fails:String#crypt returns a cryptographic hash of self by applying the UNIX cry
fails:String#crypt returns '.' prepended to the string for each NULL byte the salt contains
fails:String#crypt raises an ArgumentError when the salt is shorter than two characters
fails:String#crypt calls #to_str to converts the salt arg to a String
fails:String#crypt raises a type error when the salt arg can't be converted to a string
fails:String#crypt taints the result if either salt or self is tainted
fails:String#crypt doesn't return subclass instances
fails:String#crypt returns NULL bytes prepended to the string when the salt contains NULL bytes
Binary file modified spec/truffle/tags/core/string/lstrip_tags.txt
Binary file not shown.
1 change: 1 addition & 0 deletions spec/truffle/tags/core/string/modulo_tags.txt
Expand Up @@ -99,3 +99,4 @@ fails:String#% wraps the object in an Array if #to_ary returns nil
fails:String#% raises a TypeError if #to_ary does not return an Array
fails:String#% supports float formats using %e, but Inf, -Inf, and NaN are not floats
fails:String#% supports float formats using %E, but Inf, -Inf, and NaN are not floats
fails:String#% raises an error if NULL or \n appear anywhere else in the format string
10 changes: 0 additions & 10 deletions spec/truffle/tags/core/string/next_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/core/string/partition_tags.txt
@@ -1,7 +1,4 @@
fails:String#partition with String returns an array of substrings based on splitting on the given string
fails:String#partition with String always returns 3 elements
fails:String#partition with String accepts regexp
fails:String#partition with String sets global vars if regexp used
fails:String#partition with String converts its argument using :to_str
fails:String#partition with String raises an error if not convertible to string
fails:String#partition with String takes precedence over a given block
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/string/rpartition_tags.txt
@@ -1,6 +1 @@
fails:String#rpartition with String returns an array of substrings based on splitting on the given string
fails:String#rpartition with String always returns 3 elements
fails:String#rpartition with String accepts regexp
fails:String#rpartition with String affects $~
fails:String#rpartition with String converts its argument using :to_str
fails:String#rpartition with String raises an error if not convertible to string
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/string/rstrip_tags.txt
@@ -1,7 +1,2 @@
fails:String#rstrip returns a copy of self with trailing whitespace removed
fails:String#rstrip returns a copy of self with all trailing whitespace and NULL bytes removed
fails:String#rstrip! modifies self in place and returns self
fails:String#rstrip! modifies self removing trailing NULL bytes and whitespace
fails:String#rstrip! returns nil if no modifications were made
fails:String#rstrip! raises a RuntimeError on a frozen instance that is modified
fails:String#rstrip! raises a RuntimeError on a frozen instance that would not be modified
10 changes: 0 additions & 10 deletions spec/truffle/tags/core/string/scrub_tags.txt
@@ -1,12 +1,2 @@
fails:String#scrub with a default replacement returns self for valid strings
fails:String#scrub with a default replacement replaces invalid byte sequences
fails:String#scrub with a custom replacement returns self for valid strings
fails:String#scrub with a custom replacement replaces invalid byte sequences
fails:String#scrub with a custom replacement replaces groups of sequences together with a single replacement
fails:String#scrub with a custom replacement raises ArgumentError for replacements with an invalid encoding
fails:String#scrub with a custom replacement raises TypeError when a non String replacement is given
fails:String#scrub with a block returns self for valid strings
fails:String#scrub with a block replaces invalid byte sequences
fails:String#scrub with a block replaces invalid byte sequences using a custom encoding
fails:String#scrub! modifies self for valid strings
fails:String#scrub! accepts blocks
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/squeeze_tags.txt
Expand Up @@ -5,7 +5,6 @@ fails:String#squeeze squeezes all chars in a sequence
fails:String#squeeze raises an ArgumentError when the parameter is out of sequence
fails:String#squeeze taints the result when self is tainted
fails:String#squeeze tries to convert each set arg to a string using to_str
fails:String#squeeze raises a TypeError when one set arg can't be converted to a string
fails:String#squeeze returns subclass instances when called on a subclass
fails:String#squeeze! modifies self in place and returns self
fails:String#squeeze! returns nil if no modifications were made
Expand Down
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/string/strip_tags.txt
Expand Up @@ -2,7 +2,4 @@ fails:String#strip returns a new string with leading and trailing whitespace rem
fails:String#strip returns a copy of self with trailing NULL bytes and whitespace
fails:String#strip taints the result when self is tainted
fails:String#strip! modifies self in place and returns self
fails:String#strip! returns nil if no modifications where made
fails:String#strip! modifies self removing trailing NULL bytes and whitespace
fails:String#strip! raises a RuntimeError on a frozen instance that is modified
fails:String#strip! raises a RuntimeError on a frozen instance that would not be modified
Expand Up @@ -33,7 +33,7 @@ public RubiniusPrimitiveConstructor getPrimitive(String name) {
final RubiniusPrimitiveConstructor constructor = primitives.get(name);

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

return constructor;
Expand All @@ -56,6 +56,7 @@ public static RubiniusPrimitiveManager create() {
nodeFactories.addAll(ModulePrimitiveNodesFactory.getFactories());
nodeFactories.addAll(RandomPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(ArrayPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(UndefinedPrimitiveNodesFactory.getFactories());

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

Expand Down
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.runtime.RubyContext;

/**
* Catch-all class for Rubinius primitives that are invoked but haven't yet been defined. Its only purpose is to
* allow Truffle to parse Rubinius primitive calls without failing during the translation phase. If any code ever
* executes nodes here, things will break and you must implement the primitive in its respective parent.
*/
public abstract class UndefinedPrimitiveNodes {
public final static String NAME = "undefined";


@RubiniusPrimitive(name = NAME)
public static abstract class UndefinedPrimitiveNode extends RubiniusPrimitiveNode {

public UndefinedPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public UndefinedPrimitiveNode(UndefinedPrimitiveNode prev) {
super(prev);
}

@Specialization
public Object undefined(Object... args) {
throw new UnsupportedOperationException("Undefined Rubinius primitive.");
}
}

}
Expand Up @@ -332,7 +332,6 @@ private void includeModules(RubyModule comparableModule) {
objectClass.include(null, kernelModule);

numericClass.include(null, comparableModule);
stringClass.include(null, comparableModule);
symbolClass.include(null, comparableModule);

arrayClass.include(null, enumerableModule);
Expand Down

0 comments on commit fe5b4b4

Please sign in to comment.