Skip to content

Commit

Permalink
Revert "[Truffle] Work on Hash#[]"
Browse files Browse the repository at this point in the history
This reverts commit 25ab933.
  • Loading branch information
chrisseaton committed Mar 7, 2015
1 parent 25ab933 commit e2cd719
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 173 deletions.
2 changes: 2 additions & 0 deletions spec/truffle/tags/core/array/to_ary_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:Array#to_ary returns self
fails:Array#to_ary properly handles recursive arrays
5 changes: 5 additions & 0 deletions spec/truffle/tags/core/hash/constructor_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
fails:Hash.[] coerces a single argument which responds to #to_ary
fails:Hash.[] ignores elements that are not arrays
fails:Hash.[] raises an ArgumentError for arrays of more than 2 elements
fails:Hash.[] raises an ArgumentError when passed a list of value-invalid-pairs in an array
fails:Hash.[] raises an ArgumentError when passed an odd number of arguments
fails:Hash.[] calls to_hash
fails:Hash.[] passed an array treats elements that are 1 element arrays as keys with value nil
fails:Hash.[] passed a single argument which responds to #to_hash coerces it and returns a copy
4 changes: 0 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,4 @@ protected Object ruby(VirtualFrame frame, String expression, Object... arguments
return getContext().eval(ByteList.create(expression), binding, true, "inline-ruby", this);
}

public boolean isSingleArgument(Object[] arguments) {
return arguments.length == 1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public ConstructNode(ConstructNode prev) {
}

@ExplodeLoop
@Specialization(guards = {"!isSingleArgument(arguments[1])", "isEvenArguments(arguments[1])"})
@Specialization
public RubyHash construct(RubyClass hashClass, Object[] args) {
if (args.length == 1) {
singleObject.enter();
Expand Down Expand Up @@ -241,24 +241,6 @@ public RubyHash construct(RubyClass hashClass, Object[] args) {
}
}

@Specialization(guards = {"!isSingleArgument(arguments[1])", "!isEvenArguments(arguments[1])"})
public Object construct(VirtualFrame frame, RubyClass hashClass, Object[] args) {
notDesignedForCompilation();

return ruby(frame, "_construct_fallback(args)", "args", RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), args));
}

@Specialization(guards = "isSingleArgument(arguments[1])")
public Object constructSingle(VirtualFrame frame, RubyClass hashClass, Object[] args) {
notDesignedForCompilation();

return ruby(frame, "_construct_fallback(args)", "args", RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), args));
}

protected boolean isEvenArguments(Object[] arguments) {
return arguments.length % 2 == 0;
}

}

@CoreMethod(names = "[]", required = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1637,28 +1637,6 @@ public RubyNode visitInstVarNode(org.jruby.ast.InstVarNode node) {
}
}

if (sourceSection.getSource().getPath().equals("core:/core/rubinius/common/range.rb")) {
if (nameWithoutSigil.equals("@begin")) {
return new RubyCallNode(context, sourceSection,
"begin",
new SelfNode(context, sourceSection),
null,
false);
} else if (nameWithoutSigil.equals("@end")) {
return new RubyCallNode(context, sourceSection,
"end",
new SelfNode(context, sourceSection),
null,
false);
} else if (nameWithoutSigil.equals("@excl")) {
return new RubyCallNode(context, sourceSection,
"exclude_end?",
new SelfNode(context, sourceSection),
null,
false);
}
}

final RubyNode receiver = new SelfNode(context, sourceSection);

return new ReadInstanceVariableNode(context, sourceSection, nameWithoutSigil, receiver, false);
Expand Down
1 change: 0 additions & 1 deletion truffle/src/main/ruby/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
require_relative 'core/rubinius/common/object_space'
require_relative 'core/rubinius/common/proc'
require_relative 'core/rubinius/common/string'
require_relative 'core/rubinius/common/range'
require_relative 'core/rubinius/common/struct'
require_relative 'core/rubinius/common/symbol'
require_relative 'core/rubinius/common/regexp'
Expand Down
58 changes: 0 additions & 58 deletions truffle/src/main/ruby/core/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,6 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

# Copyright (c) 2007-2014, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Rubinius nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class Hash

def invert
Expand Down Expand Up @@ -74,36 +48,4 @@ def find_item(key)
end
end

# From Rubinius

def self._construct_fallback(*args)
if args.size == 1
obj = args.first
if hash = Rubinius::Type.check_convert_type(obj, Hash, :to_hash)
new_hash = allocate.replace(hash)
new_hash.default = nil
return new_hash
elsif associate_array = Rubinius::Type.check_convert_type(obj, Array, :to_ary)
return new_from_associate_array(associate_array)
end
end

return new if args.empty?

if args.size & 1 == 1
raise ArgumentError, "Expected an even number, got #{args.length}"
end

hash = new
i = 0
total = args.size

while i < total
hash[args[i]] = args[i+1]
i += 2
end

hash
end

end
4 changes: 0 additions & 4 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,4 @@ def fetch(idx, default=undefined)
at(idx)
end

def to_ary
self
end

end
14 changes: 0 additions & 14 deletions truffle/src/main/ruby/core/rubinius/common/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,4 @@ def value?(value)

alias_method :has_value?, :value?

def self.new_from_associate_array(associate_array)
hash = new
associate_array.each do |array|
next unless array.respond_to? :to_ary
array = array.to_ary
unless (1..2).cover? array.size
raise ArgumentError, "invalid number of elements (#{array.size} for 1..2)"
end
hash[array.at(0)] = array.at(1)
end
hash
end
private_class_method :new_from_associate_array

end
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Only part of Rubinius' integer.rb
# Only part of Rubinius' kernel.rb

class Integer < Numeric

Expand Down
50 changes: 0 additions & 50 deletions truffle/src/main/ruby/core/rubinius/common/range.rb

This file was deleted.

0 comments on commit e2cd719

Please sign in to comment.