Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Note that each entry is kept to a minimum, see links for details.

Note: We're only listing outstanding class updates.

* Set

* A deprecated behavior, `Set#to_set`, `Range#to_set`, and
`Enumerable#to_set` accepting arguments, was removed. [[Feature #21390]]

## Stdlib updates

We only list stdlib changes that are notable feature changes.
Expand Down Expand Up @@ -61,3 +66,4 @@ A lot of work has gone into making Ractors more stable, performant, and usable.

## JIT

[Feature #21390]: https://bugs.ruby-lang.org/issues/21390
4 changes: 0 additions & 4 deletions benchmark/set.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,3 @@ benchmark:
to_set_10: s1.to_set
to_set_100: s2.to_set
to_set_1000: s3.to_set
to_set_arg_0: s0.to_set set_subclass
to_set_arg_10: s1.to_set set_subclass
to_set_arg_100: s2.to_set set_subclass
to_set_arg_1000: s3.to_set set_subclass
7 changes: 4 additions & 3 deletions include/ruby/internal/core/rtypeddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ RBIMPL_SYMBOL_EXPORT_END()
*/
#define TypedData_Make_Struct0(result, klass, type, size, data_type, sval) \
VALUE result = rb_data_typed_object_zalloc(klass, size, data_type); \
(sval) = (type *)RTYPEDDATA_GET_DATA(result); \
(sval) = RBIMPL_CAST((type *)RTYPEDDATA_GET_DATA(result)); \
RBIMPL_CAST(/*suppress unused variable warnings*/(void)(sval))

/**
Expand Down Expand Up @@ -594,7 +594,7 @@ RBIMPL_ATTR_ARTIFICIAL()
* @return Data type struct that corresponds to `obj`.
* @pre `obj` must be an instance of ::RTypedData.
*/
static inline const struct rb_data_type_struct *
static inline const rb_data_type_t *
RTYPEDDATA_TYPE(VALUE obj)
{
#if RUBY_DEBUG
Expand All @@ -604,7 +604,8 @@ RTYPEDDATA_TYPE(VALUE obj)
}
#endif

return (const struct rb_data_type_struct *)(RTYPEDDATA(obj)->type & TYPED_DATA_PTR_MASK);
VALUE type = RTYPEDDATA(obj)->type & TYPED_DATA_PTR_MASK;
return RBIMPL_CAST((const rb_data_type_t *)type);
}

RBIMPL_ATTR_ARTIFICIAL()
Expand Down
12 changes: 3 additions & 9 deletions lib/set/subclass_compatible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,9 @@ def replace(enum)
end
end

def to_set(*args, &block)
klass = if args.empty?
Set
else
warn "passing arguments to Enumerable#to_set is deprecated", uplevel: 1
args.shift
end
return self if instance_of?(Set) && klass == Set && block.nil? && args.empty?
klass.new(self, *args, &block)
def to_set(&block)
return self if instance_of?(Set) && block.nil?
Set.new(self, &block)
end

def flatten_merge(set, seen = {}) # :nodoc:
Expand Down
11 changes: 2 additions & 9 deletions prelude.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ def pp(*objs)

module Enumerable
# Makes a set from the enumerable object with given arguments.
# Passing arguments to this method is deprecated.
def to_set(*args, &block)
klass = if args.empty?
Set
else
warn "passing arguments to Enumerable#to_set is deprecated", uplevel: 1
args.shift
end
klass.new(self, *args, &block)
def to_set(&block)
Set.new(self, &block)
end
end
6 changes: 3 additions & 3 deletions range.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,12 +1033,12 @@ range_to_a(VALUE range)
*
*/
static VALUE
range_to_set(int argc, VALUE *argv, VALUE range)
range_to_set(VALUE range)
{
if (NIL_P(RANGE_END(range))) {
rb_raise(rb_eRangeError, "cannot convert endless range to a set");
}
return rb_call_super(argc, argv);
return rb_call_super(0, NULL);
}

static VALUE
Expand Down Expand Up @@ -2868,7 +2868,7 @@ Init_Range(void)
rb_define_method(rb_cRange, "minmax", range_minmax, 0);
rb_define_method(rb_cRange, "size", range_size, 0);
rb_define_method(rb_cRange, "to_a", range_to_a, 0);
rb_define_method(rb_cRange, "to_set", range_to_set, -1);
rb_define_method(rb_cRange, "to_set", range_to_set, 0);
rb_define_method(rb_cRange, "entries", range_to_a, 0);
rb_define_method(rb_cRange, "to_s", range_to_s, 0);
rb_define_method(rb_cRange, "inspect", range_inspect, 0);
Expand Down
28 changes: 7 additions & 21 deletions set.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,36 +648,22 @@ set_i_to_a(VALUE set)

/*
* call-seq:
* to_set(klass = Set, *args, &block) -> self or new_set
* to_set(&block) -> self or new_set
*
* Without arguments, returns +self+ (for duck-typing in methods that
* accept "set, or set-convertible" arguments).
* Without a block, if +self+ is an instance of +Set+, returns +self+.
* Otherwise, calls <tt>Set.new(self, &block)</tt>.
*
* A form with arguments is _deprecated_. It converts the set to another
* with <tt>klass.new(self, *args, &block)</tt>.
*/
static VALUE
set_i_to_set(int argc, VALUE *argv, VALUE set)
set_i_to_set(VALUE set)
{
VALUE klass;

if (argc == 0) {
klass = rb_cSet;
argv = &set;
argc = 1;
}
else {
rb_warn_deprecated("passing arguments to Set#to_set", NULL);
klass = argv[0];
argv[0] = set;
}

if (klass == rb_cSet && rb_obj_is_instance_of(set, rb_cSet) &&
argc == 1 && !rb_block_given_p()) {
if (rb_obj_is_instance_of(set, rb_cSet) && !rb_block_given_p()) {
return set;
}

return rb_funcall_passing_block(klass, id_new, argc, argv);
return rb_funcall_passing_block(rb_cSet, id_new, 0, NULL);
}

/*
Expand Down Expand Up @@ -2292,7 +2278,7 @@ Init_Set(void)
rb_define_method(rb_cSet, "superset?", set_i_superset, 1);
rb_define_alias(rb_cSet, ">=", "superset?");
rb_define_method(rb_cSet, "to_a", set_i_to_a, 0);
rb_define_method(rb_cSet, "to_set", set_i_to_set, -1);
rb_define_method(rb_cSet, "to_set", set_i_to_set, 0);

/* :nodoc: */
VALUE compat = rb_define_class_under(rb_cSet, "compatible", rb_cObject);
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerable/to_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9]
end

ruby_version_is "4.0" do
ruby_version_is "4.0"..."4.1" do
it "instantiates an object of provided as the first argument set class" do
set = nil
proc{set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass)}.should complain(/Enumerable#to_set/)
Expand Down