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
10 changes: 0 additions & 10 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,6 @@ Note: We're only listing outstanding class updates.

* `Math.log1p` and `Math.expm1` are added. [[Feature #21527]]

* Method

* `Method#source_location`, `Proc#source_location`, and
`UnboundMethod#source_location` now return extended location
information with 5 elements: `[path, start_line, start_column,
end_line, end_column]`. The previous 2-element format `[path,
line]` can still be obtained by calling `.take(2)` on the result.
[[Feature #6012]]

* Proc

* `Proc#parameters` now shows anonymous optional parameters as `[:opt]`
Expand Down Expand Up @@ -443,7 +434,6 @@ A lot of work has gone into making Ractors more stable, performant, and usable.
* `--rjit` is removed. We will move the implementation of the third-party JIT API
to the [ruby/rjit](https://github.com/ruby/rjit) repository.

[Feature #6012]: https://bugs.ruby-lang.org/issues/6012
[Feature #15408]: https://bugs.ruby-lang.org/issues/15408
[Feature #17473]: https://bugs.ruby-lang.org/issues/17473
[Feature #18455]: https://bugs.ruby-lang.org/issues/18455
Expand Down
14 changes: 5 additions & 9 deletions box.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ rb_get_box_object(rb_box_t *box)

/*
* call-seq:
* Namespace.new -> new_box
* Ruby::Box.new -> new_box
*
* Returns a new Ruby::Box object.
*/
Expand Down Expand Up @@ -389,7 +389,7 @@ box_initialize(VALUE box_value)

/*
* call-seq:
* Namespace.enabled? -> true or false
* Ruby::Box.enabled? -> true or false
*
* Returns +true+ if Ruby::Box is enabled.
*/
Expand All @@ -401,7 +401,7 @@ rb_box_s_getenabled(VALUE recv)

/*
* call-seq:
* Namespace.current -> box, nil or false
* Ruby::Box.current -> box, nil or false
*
* Returns the current box.
* Returns +nil+ if Ruby Box is not enabled.
Expand Down Expand Up @@ -795,10 +795,6 @@ rb_box_local_extension(VALUE box_value, VALUE fname, VALUE path, VALUE *cleanup)
return new_path;
}

// TODO: delete it just after dln_load? or delay it?
// At least for _WIN32, deleting extension files should be delayed until the namespace's destructor.
// And it requires calling dlclose before deleting it.

static VALUE
rb_box_load(int argc, VALUE *argv, VALUE box)
{
Expand Down Expand Up @@ -929,11 +925,11 @@ rb_box_inspect(VALUE obj)
rb_box_t *box;
VALUE r;
if (obj == Qfalse) {
r = rb_str_new_cstr("#<Namespace:root>");
r = rb_str_new_cstr("#<Ruby::Box:root>");
return r;
}
box = rb_get_box_t(obj);
r = rb_str_new_cstr("#<Namespace:");
r = rb_str_new_cstr("#<Ruby::Box:");
rb_str_concat(r, rb_funcall(LONG2NUM(box->box_id), rb_intern("to_s"), 0));
if (BOX_ROOT_P(box)) {
rb_str_cat_cstr(r, ",root");
Expand Down
17 changes: 4 additions & 13 deletions cont.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ struct rb_fiber_struct {

unsigned int killed : 1;

rb_serial_t serial;

struct coroutine_context context;
struct fiber_pool_stack stack;
};
Expand Down Expand Up @@ -1012,13 +1010,6 @@ rb_fiber_threadptr(const rb_fiber_t *fiber)
return fiber->cont.saved_ec.thread_ptr;
}

rb_serial_t
rb_fiber_serial(const rb_fiber_t *fiber)
{
VM_ASSERT(fiber->serial >= 1);
return fiber->serial;
}

static VALUE
cont_thread_value(const rb_context_t *cont)
{
Expand Down Expand Up @@ -2005,9 +1996,9 @@ fiber_alloc(VALUE klass)
}

static rb_serial_t
next_fiber_serial(rb_ractor_t *cr)
next_ec_serial(rb_ractor_t *cr)
{
return cr->next_fiber_serial++;
return cr->next_ec_serial++;
}

static rb_fiber_t*
Expand All @@ -2026,10 +2017,10 @@ fiber_t_alloc(VALUE fiber_value, unsigned int blocking)
fiber->cont.type = FIBER_CONTEXT;
fiber->blocking = blocking;
fiber->killed = 0;
fiber->serial = next_fiber_serial(th->ractor);
cont_init(&fiber->cont, th);

fiber->cont.saved_ec.fiber_ptr = fiber;
fiber->cont.saved_ec.serial = next_ec_serial(th->ractor);
rb_ec_clear_vm_stack(&fiber->cont.saved_ec);

fiber->prev = NULL;
Expand Down Expand Up @@ -2576,10 +2567,10 @@ rb_threadptr_root_fiber_setup(rb_thread_t *th)
}
fiber->cont.type = FIBER_CONTEXT;
fiber->cont.saved_ec.fiber_ptr = fiber;
fiber->cont.saved_ec.serial = next_ec_serial(th->ractor);
fiber->cont.saved_ec.thread_ptr = th;
fiber->blocking = 1;
fiber->killed = 0;
fiber->serial = next_fiber_serial(th->ractor);
fiber_status_set(fiber, FIBER_RESUMED); /* skip CREATED */
th->ec = &fiber->cont.saved_ec;
cont_init_jit_cont(&fiber->cont);
Expand Down
2 changes: 1 addition & 1 deletion ext/-test-/box/yay1/extconf.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create_makefile('-test-/namespace/yay1')
create_makefile('-test-/box/yay1')
2 changes: 1 addition & 1 deletion ext/-test-/box/yay2/extconf.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create_makefile('-test-/namespace/yay2')
create_makefile('-test-/box/yay2')
9 changes: 8 additions & 1 deletion ext/socket/lib/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,14 @@ def self.tcp_without_fast_fallback(host, port, local_host, local_port, connect_t
local_addr = nil
end
begin
timeout = open_timeout ? open_timeout - (current_clock_time - starts_at) : connect_timeout
timeout =
if open_timeout
t = open_timeout - (current_clock_time - starts_at)
t.negative? ? 0 : t
else
connect_timeout
end

sock = local_addr ?
ai.connect_from(local_addr, timeout:) :
ai.connect(timeout:)
Expand Down
2 changes: 0 additions & 2 deletions internal/cont.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,4 @@ VALUE rb_fiber_inherit_storage(struct rb_execution_context_struct *ec, struct rb
VALUE rb_fiberptr_self(struct rb_fiber_struct *fiber);
unsigned int rb_fiberptr_blocking(struct rb_fiber_struct *fiber);
struct rb_execution_context_struct * rb_fiberptr_get_ec(struct rb_fiber_struct *fiber);
rb_serial_t rb_fiber_serial(const struct rb_fiber_struct *fiber);

#endif /* INTERNAL_CONT_H */
16 changes: 5 additions & 11 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1511,20 +1511,14 @@ proc_eq(VALUE self, VALUE other)
static VALUE
iseq_location(const rb_iseq_t *iseq)
{
VALUE loc[5];
int i = 0;
VALUE loc[2];

if (!iseq) return Qnil;
rb_iseq_check(iseq);
loc[i++] = rb_iseq_path(iseq);
const rb_code_location_t *cl = &ISEQ_BODY(iseq)->location.code_location;
loc[i++] = RB_INT2NUM(cl->beg_pos.lineno);
loc[i++] = RB_INT2NUM(cl->beg_pos.column);
loc[i++] = RB_INT2NUM(cl->end_pos.lineno);
loc[i++] = RB_INT2NUM(cl->end_pos.column);
RUBY_ASSERT_ALWAYS(i == numberof(loc));

return rb_ary_new_from_values(i, loc);
loc[0] = rb_iseq_path(iseq);
loc[1] = RB_INT2NUM(ISEQ_BODY(iseq)->location.first_lineno);

return rb_ary_new4(2, loc);
}

VALUE
Expand Down
4 changes: 2 additions & 2 deletions ractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ ractor_alloc(VALUE klass)
VALUE rv = TypedData_Make_Struct(klass, rb_ractor_t, &ractor_data_type, r);
FL_SET_RAW(rv, RUBY_FL_SHAREABLE);
r->pub.self = rv;
r->next_fiber_serial = 1;
r->next_ec_serial = 1;
VM_ASSERT(ractor_status_p(r, ractor_created));
return rv;
}
Expand All @@ -440,7 +440,7 @@ rb_ractor_main_alloc(void)
r->name = Qnil;
r->pub.self = Qnil;
r->newobj_cache = rb_gc_ractor_cache_alloc(r);
r->next_fiber_serial = 1;
r->next_ec_serial = 1;
ruby_single_main_ractor = r;

return r;
Expand Down
2 changes: 1 addition & 1 deletion ractor_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct rb_ractor_struct {

// ractor local data

rb_serial_t next_fiber_serial;
rb_serial_t next_ec_serial;

st_table *local_storage;
struct rb_id_table *idkey_local_storage;
Expand Down
16 changes: 5 additions & 11 deletions spec/ruby/core/method/source_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
end

it "sets the first value to the path of the file in which the method was defined" do
file = @method.source_location[0]
file = @method.source_location.first
file.should be_an_instance_of(String)
file.should == File.realpath('fixtures/classes.rb', __dir__)
end

it "sets the last value to an Integer representing the line on which the method was defined" do
line = @method.source_location[1]
line = @method.source_location.last
line.should be_an_instance_of(Integer)
line.should == 5
end

it "returns the last place the method was defined" do
MethodSpecs::SourceLocation.method(:redefined).source_location[1].should == 13
MethodSpecs::SourceLocation.method(:redefined).source_location.last.should == 13
end

it "returns the location of the original method even if it was aliased" do
MethodSpecs::SourceLocation.new.method(:aka).source_location[1].should == 17
MethodSpecs::SourceLocation.new.method(:aka).source_location.last.should == 17
end

it "works for methods defined with a block" do
Expand Down Expand Up @@ -108,13 +108,7 @@ def f
c = Class.new do
eval('def self.m; end', nil, "foo", 100)
end
location = c.method(:m).source_location
ruby_version_is(""..."4.0") do
location.should == ["foo", 100]
end
ruby_version_is("4.0") do
location.should == ["foo", 100, 0, 100, 15]
end
c.method(:m).source_location.should == ["foo", 100]
end

describe "for a Method generated by respond_to_missing?" do
Expand Down
6 changes: 3 additions & 3 deletions spec/ruby/core/module/ancestors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
ModuleSpecs.ancestors.should == [ModuleSpecs]
ModuleSpecs::Basic.ancestors.should == [ModuleSpecs::Basic]
ModuleSpecs::Super.ancestors.should == [ModuleSpecs::Super, ModuleSpecs::Basic]
if defined?(Namespace) && Namespace.enabled?
if defined?(Ruby::Box) && Ruby::Box.enabled?
ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should ==
[ModuleSpecs::Parent, Object, Namespace::Loader, Kernel, BasicObject]
[ModuleSpecs::Parent, Object, Ruby::Box::Loader, Kernel, BasicObject]
ModuleSpecs.without_test_modules(ModuleSpecs::Child.ancestors).should ==
[ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Namespace::Loader, Kernel, BasicObject]
[ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Ruby::Box::Loader, Kernel, BasicObject]
else
ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should ==
[ModuleSpecs::Parent, Object, Kernel, BasicObject]
Expand Down
51 changes: 19 additions & 32 deletions spec/ruby/core/proc/source_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,57 @@
end

it "sets the first value to the path of the file in which the proc was defined" do
file = @proc.source_location[0]
file = @proc.source_location.first
file.should be_an_instance_of(String)
file.should == File.realpath('fixtures/source_location.rb', __dir__)

file = @proc_new.source_location[0]
file = @proc_new.source_location.first
file.should be_an_instance_of(String)
file.should == File.realpath('fixtures/source_location.rb', __dir__)

file = @lambda.source_location[0]
file = @lambda.source_location.first
file.should be_an_instance_of(String)
file.should == File.realpath('fixtures/source_location.rb', __dir__)

file = @method.source_location[0]
file = @method.source_location.first
file.should be_an_instance_of(String)
file.should == File.realpath('fixtures/source_location.rb', __dir__)
end

it "sets the second value to an Integer representing the line on which the proc was defined" do
line = @proc.source_location[1]
it "sets the last value to an Integer representing the line on which the proc was defined" do
line = @proc.source_location.last
line.should be_an_instance_of(Integer)
line.should == 4

line = @proc_new.source_location[1]
line = @proc_new.source_location.last
line.should be_an_instance_of(Integer)
line.should == 12

line = @lambda.source_location[1]
line = @lambda.source_location.last
line.should be_an_instance_of(Integer)
line.should == 8

line = @method.source_location[1]
line = @method.source_location.last
line.should be_an_instance_of(Integer)
line.should == 15
end

it "works even if the proc was created on the same line" do
ruby_version_is(""..."4.0") do
proc { true }.source_location.should == [__FILE__, __LINE__]
Proc.new { true }.source_location.should == [__FILE__, __LINE__]
-> { true }.source_location.should == [__FILE__, __LINE__]
end
ruby_version_is("4.0") do
proc { true }.source_location.should == [__FILE__, __LINE__, 11, __LINE__, 19]
Proc.new { true }.source_location.should == [__FILE__, __LINE__, 15, __LINE__, 23]
-> { true }.source_location.should == [__FILE__, __LINE__, 8, __LINE__, 17]
end
proc { true }.source_location.should == [__FILE__, __LINE__]
Proc.new { true }.source_location.should == [__FILE__, __LINE__]
-> { true }.source_location.should == [__FILE__, __LINE__]
end

it "returns the first line of a multi-line proc (i.e. the line containing 'proc do')" do
ProcSpecs::SourceLocation.my_multiline_proc.source_location[1].should == 20
ProcSpecs::SourceLocation.my_multiline_proc_new.source_location[1].should == 34
ProcSpecs::SourceLocation.my_multiline_lambda.source_location[1].should == 27
ProcSpecs::SourceLocation.my_multiline_proc.source_location.last.should == 20
ProcSpecs::SourceLocation.my_multiline_proc_new.source_location.last.should == 34
ProcSpecs::SourceLocation.my_multiline_lambda.source_location.last.should == 27
end

it "returns the location of the proc's body; not necessarily the proc itself" do
ProcSpecs::SourceLocation.my_detached_proc.source_location[1].should == 41
ProcSpecs::SourceLocation.my_detached_proc_new.source_location[1].should == 51
ProcSpecs::SourceLocation.my_detached_lambda.source_location[1].should == 46
ProcSpecs::SourceLocation.my_detached_proc.source_location.last.should == 41
ProcSpecs::SourceLocation.my_detached_proc_new.source_location.last.should == 51
ProcSpecs::SourceLocation.my_detached_lambda.source_location.last.should == 46
end

it "returns the same value for a proc-ified method as the method reports" do
Expand All @@ -93,12 +86,6 @@

it "works for eval with a given line" do
proc = eval('-> {}', nil, "foo", 100)
location = proc.source_location
ruby_version_is(""..."4.0") do
location.should == ["foo", 100]
end
ruby_version_is("4.0") do
location.should == ["foo", 100, 2, 100, 5]
end
proc.source_location.should == ["foo", 100]
end
end
Loading