Commit graph

7412 commits

Author SHA1 Message Date
NARUSE, Yui
fee5b8f263 merge revision(s) 2c93c554019ebdc394d3c51c6d925620d3005f84,f5ea43a2e61789357e9c4b374b4bc6756abeae17: [Backport #19360]
Ensure main file has default coverage if required. (#7169)

	* Extract common code for coverage setup.
	---
	 iseq.c | 13 +++++++++++--
	 1 file changed, 11 insertions(+), 2 deletions(-)

	More coverage tests & specs. (#7171)

	* Add spec for eval and line coverage.

	* Add test for main file coverage.
	---
	 spec/ruby/library/coverage/start_spec.rb | 8 +++++++-
	 test/coverage/autostart.rb               | 2 ++
	 test/coverage/main.rb                    | 1 +
	 test/coverage/test_coverage.rb           | 7 +++++++
	 4 files changed, 17 insertions(+), 1 deletion(-)
	 create mode 100644 test/coverage/autostart.rb
	 create mode 100644 test/coverage/main.rb
2023-01-25 16:34:24 +09:00
NARUSE, Yui
4110137fcf merge revision(s) 6f3aff3961: [Backport #19289]
[Bug #19289] Retain `ruby_abi_version` function

	A few extension libraries, to hide all symbols except for necessary to
	load, hardcode the symbols to be exported in symbol list files for
	linker without even checking by `have_func`.  As a workaround for such
	libraries, retain `ruby_abi_version` symbol always even in released
	versions for now.
	---
	 include/ruby/internal/abi.h | 7 +++++--
	 1 file changed, 5 insertions(+), 2 deletions(-)
2023-01-25 13:26:25 +09:00
NARUSE, Yui
0090cb82b0 merge revision(s) df6b72b8ff: [Backport #19348]
Avoid checking interrupt when loading iseq
	MIME-Version: 1.0
	Content-Type: text/plain; charset=UTF-8
	Content-Transfer-Encoding: 8bit

	The interrupt check will unintentionally release the VM lock when loading an iseq.
	And this will cause issues with the `debug` gem's
	[`ObjectSpace.each_iseq` method](0fcfc28aca/ext/debug/iseq_collector.c (L61-L67)),
	which wraps iseqs with a wrapper and exposes their internal states when they're actually not ready to be used.

	And when that happens, errors like this would occur and kill the `debug` gem's thread:

	```
	 DEBUGGER: ReaderThreadError: uninitialized InstructionSequence
	┃ DEBUGGER: Disconnected.
	┃ ["/opt/rubies/ruby-3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:247:in `absolute_path'",
	┃  "/opt/rubies/ruby-3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:247:in `block in iterate_iseq'",
	┃  "/opt/rubies/ruby-3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:246:in `each_iseq'",
	...
	```

	A way to reproduce the issue is to satisfy these conditions at the same time:

	1. `debug` gem calling `ObjectSpace.each_iseq` (e.g. [activating a `LineBreakpoint`](0fcfc28aca/lib/debug/breakpoint.rb (L246))).
	2. A large amount of iseq being loaded from another thread (possibly through the `bootsnap` gem).
	3. 1 and 2 iterating through the same iseq(s) at the same time.

	Because this issue requires external dependencies and a rather complicated timing setup to reproduce, I wasn't able to write a test case for it.
	But here's some pseudo code to help reproduce it:

	```rb
	require "debug/session"

	Thread.new do
	  100.times do
	    ObjectSpace.each_iseq do |iseq|
	      iseq.absolute_path
	    end
	  end
	end

	sleep 0.1

	load_a_bunch_of_iseq
	possibly_through_bootsnap
	```

	[Bug #19348]

	Co-authored-by: Peter Zhu <peter@peterzhu.ca>
	---
	 compile.c       |  2 +-
	 vm_core.h       |  1 +
	 vm_insnhelper.c | 11 +++++++++++
	 3 files changed, 13 insertions(+), 1 deletion(-)
2023-01-25 10:23:38 +09:00
NARUSE, Yui
a20061cb1a merge revision(s) 72eb33066f: [Backport #19320]
Fix off-by-one error in rb_vm_each_stack_value

	Applying the following patch to test/erb/test_erb.rb and running that
	file will cause Ruby to crash on my machine (macOS 13.1 on M1 Pro):

	```
	--- a/test/erb/test_erb.rb
	+++ b/test/erb/test_erb.rb
	@@ -7,6 +7,12 @@
	 class TestERB < Test::Unit::TestCase
	   class MyError < RuntimeError ; end

	+  def setup
	+    GC.auto_compact = true
	+    GC.stress = true
	+    GC.verify_compaction_references(expand_heap: true, toward: :empty)
	+  end
	+
	```

	It crashes with the following log:

	```
	/Users/peter/src/ruby/lib/erb/compiler.rb:276: [BUG] Segmentation fault at 0x00000001083a8690
	...
	-- C level backtrace information -------------------------------------------
	...
	/Users/peter/src/ruby/build/ruby(rb_vm_each_stack_value+0xa8) [0x104cc3a44] ../vm.c:2737
	/Users/peter/src/ruby/build/ruby(rb_vm_each_stack_value+0xa8) [0x104cc3a44] ../vm.c:2737
	/Users/peter/src/ruby/build/ruby(check_stack_for_moved+0x2c) [0x104b272a4] ../gc.c:5512
	/Users/peter/src/ruby/build/ruby(gc_compact_finish) ../gc.c:5534
	/Users/peter/src/ruby/build/ruby(gc_sweep_compact) ../gc.c:8653
	/Users/peter/src/ruby/build/ruby(gc_sweep) ../gc.c:6196
	/Users/peter/src/ruby/build/ruby(has_sweeping_pages+0x0) [0x104b19c54] ../gc.c:9568
	/Users/peter/src/ruby/build/ruby(gc_rest) ../gc.c:9570
	```

	This crash happens because it's reading the VALUE at sp. But since
	sp points to the top of the stack, it's reading the VALUE above the
	top of the stack, which is causing this segfault.

	Fixes [Bug #19320]
	---
	 vm.c | 2 +-
	 1 file changed, 1 insertion(+), 1 deletion(-)
2023-01-24 17:41:35 +09:00
NARUSE, Yui
c0df0a85de merge revision(s) ed6fbb79e1: [Backport #19339]
Fix crash when defining ivars on special constants

	[Bug #19339]
	---
	 test/ruby/test_variable.rb | 6 ++++++
	 vm_insnhelper.c            | 5 +++++
	 2 files changed, 11 insertions(+)
2023-01-20 17:01:47 +09:00
NARUSE, Yui
373e62248c merge revision(s) f7b72462aa: [Backport #19356]
String#bytesplice should return self

	In Feature #19314, we concluded that the return value of String#bytesplice
	should be changed from the source string to the receiver, because the source
	string is useless and confusing when extra arguments are added.

	This change should be included in Ruby 3.2.1.
	---
	 string.c                 | 4 ++--
	 test/ruby/test_string.rb | 2 +-
	 2 files changed, 3 insertions(+), 3 deletions(-)
2023-01-20 12:24:24 +09:00
NARUSE, Yui
6a8fcb5021 merge revision(s) 3be2acfafd: [Backport #19327]
Fix re-embedding of strings during compaction

	The reference updating code for strings is not re-embedding strings
	because the code is incorrectly wrapped inside of a
	`if (STR_SHARED_P(obj))` clause. Shared strings can't be re-embedded
	so this ends up being a no-op. This means that strings can be moved to a
	large size pool during compaction, but won't be re-embedded, which would
	waste the space.
	---
	 gc.c                         | 16 +++++++++-------
	 string.c                     | 12 ++++++++----
	 test/ruby/test_gc_compact.rb |  8 ++++----
	 3 files changed, 21 insertions(+), 15 deletions(-)
2023-01-19 21:52:47 +09:00
NARUSE, Yui
686b38f83e merge revision(s) d8ef0a98c6: [Backport #19319]
[Bug #19319] Fix crash in rb_str_casemap

	The following code crashes on my machine:

	```
	GC.stress = true

	str = "testing testing testing"

	puts str.capitalize
	```

	We need to ensure that the object `buffer_anchor` remains on the stack
	so it does not get GC'd.
	---
	 string.c | 2 ++
	 1 file changed, 2 insertions(+)
2023-01-19 11:59:43 +09:00
NARUSE, Yui
1a2447ac99 merge revision(s) 979dd02e2f: [Backport #19262]
Check if the argument is Thread::Backtrace::Location object

	[Bug #19262]
	---
	 ast.c                 | 5 +++++
	 test/ruby/test_ast.rb | 6 ++++++
	 2 files changed, 11 insertions(+)
2023-01-19 11:05:29 +09:00
NARUSE, Yui
08ae7f64dc merge revision(s) 273dca3aed: [Backport #19248]
Fix undefined behavior in shape.c

	Under strict aliasing, writing to the memory location of a different
	type is not allowed and will result in undefined behavior. This was
	happening in shape.c due to `rb_id_table_lookup` writing to the memory
	location of `VALUE *` that was casted from a `rb_shape_t **`.

	This was causing test failures when compiled with LTO.

	Fixes [Bug #19248]

	Co-Authored-By: Alan Wu <alanwu@ruby-lang.org>
	---
	 shape.c | 13 +++++++++++--
	 1 file changed, 11 insertions(+), 2 deletions(-)
2023-01-19 09:31:47 +09:00
NARUSE, Yui
d7fb4629b4 merge revision(s) 837ef8911c: [Backport #19305]
Fix crash in TracePoint c_call for removed method

	trace_arg->id is the ID of the original method of an aliased method. If
	the original method is removed, then the lookup will fail. We should use
	trace_arg->called_id instead, which is the ID of the aliased method.

	Fixes [Bug #19305]
	---
	 test/ruby/test_settracefunc.rb | 23 +++++++++++++++++++++++
	 vm_trace.c                     |  2 +-
	 2 files changed, 24 insertions(+), 1 deletion(-)
2023-01-18 20:15:28 +09:00
NARUSE, Yui
44a3043d11 merge revision(s) 2bbf63dd86: [Backport #19298]
Remove lib/mjit/instruction.rb

	This was accidentally re-introduced in f6620037ba.

	[Bug #19298]
	---
	 lib/mjit/instruction.rb | 2162 -----------------------------------------------
	 1 file changed, 2162 deletions(-)
	 delete mode 100644 lib/mjit/instruction.rb
2023-01-18 20:14:43 +09:00
NARUSE, Yui
1fb5eb5740 merge revision(s) aeddc19340: [Backport #19316]
YJIT: Save PC and SP before calling leaf builtins (#7090)

	Previously, we did not update `cfp->sp` before calling the C function of
	ISEQs marked with `Primitive.attr! "inline"` (leaf builtins). This
	caused the GC to miss temporary values on the stack in case the function
	allocates and triggers a GC run. Right now, there is only a few leaf
	builtins in numeric.rb on Integer methods such as `Integer#~`. Since
	these methods only allocate when operating on big numbers, we missed
	this issue.

	Fix by saving PC and SP before calling the functions -- our usual
	protocol for calling C functions that may allocate on the GC heap.

	[Bug #19316]
	---
	 test/ruby/test_yjit.rb | 16 ++++++++++++++++
	 yjit/src/codegen.rs    |  4 ++++
	 2 files changed, 20 insertions(+)
2023-01-18 18:56:51 +09:00
NARUSE, Yui
f7e9b79f81 merge revision(s) 4959e01932: [Backport #19271]
common.mk: Do not invoke outdate-bundled-gems by default

	If baseruby is available (and its version is different from one being
	built) when compiling ruby, tool/outdate-bundled-gems.rb (which is
	invoked by `make install`) wrongly deletes debug.so and rbs_extension.so
	in .bundle/extension/*.

	This leads to a broken installation of ruby which lacks the libraries,
	which may make rubygems show the following warnings (in some additional
	complex conditions):

	```
	$ irb
	Ignoring debug-1.7.1 because its extensions are not built. Try: gem pristine debug --version 1.7.1
	Ignoring rbs-2.8.2 because its extensions are not built. Try: gem pristine rbs --version 2.8.2
	irb(main):001:0>
	```

	According to some committers, tool/outdate-bundled-gems.rb is introduced
	for fixing a build issue, but the detail is not recorded. The issue
	seems to occur only when debug gem or rbs gem is updated, so it is
	difficult to fix the script so soon.

	Tentatively, this change stops invoking the script by default.
	This should be backported to ruby_3_2.

	Fixes [Bug #19271]
	---
	 common.mk | 1 -
	 1 file changed, 1 deletion(-)
2023-01-18 18:56:09 +09:00
NARUSE, Yui
97c32b49e2 merge revision(s) 43ff0c2c48: [Backport #19299]
YJIT: Fix `yield` into block with >=30 locals on ARM

	It's a register spill issue. Fix by moving the Qnil fill snippet to
	after registers are released.

	[Bug #19299]
	---
	 test/ruby/test_yjit.rb | 14 ++++++++++++++
	 yjit/src/codegen.rs    | 29 ++++++++++++++---------------
	 2 files changed, 28 insertions(+), 15 deletions(-)
2023-01-18 17:18:44 +09:00
NARUSE, Yui
52ea5ea990 merge revision(s) 291a4098cf649c027cb50c16b872455f26ad1dfb,5be0d42d2c4dc765230c76738289560f9ee37f09: [Backport #19296]
Add missing assertion

	---
	 test/ruby/test_time.rb | 3 +++
	 1 file changed, 3 insertions(+)

	[Bug #19296] Precheck bits of time components

	---
	 test/ruby/test_time.rb | 15 +++++++++++++++
	 time.c                 | 14 ++++++++------
	 2 files changed, 23 insertions(+), 6 deletions(-)
2023-01-18 17:17:27 +09:00
NARUSE, Yui
057eff7663 merge revision(s) eab7f4623f: [Backport #19336]
Return 0 if there is no CFP on the EC yet

	StackProf uses a signal handler to call `rb_profile_frames`.  Signals
	are delivered to threads randomly, and can be delivered after the thread
	has been created but before the CFP has been established on the EC.

	This commit returns early if there is no CFP to use.

	Here is some info from the core files we are seeing.  Here you can see
	the CFP on the current EC is 0x0:

	```
	(gdb) p ruby_current_ec
	$20 = (struct rb_execution_context_struct *) 0x7f3481301b50
	(gdb) p ruby_current_ec->cfp
	$21 = (rb_control_frame_t *) 0x0
	```

	Here is where VM_FRAME_CFRAME_P gets a 0x0 CFP:

	```
	6  VM_FRAME_CFRAME_P (cfp=0x0) at vm_core.h:1350
	7  VM_FRAME_RUBYFRAME_P (cfp=<optimized out>) at vm_core.h:1350
	8  rb_profile_frames (start=0, limit=2048, buff=0x7f3493809590, lines=0x7f349380d590) at vm_backtrace.c:1587
	```

	Down the stack we can see this is happening after thread creation:

	```
	19 0x00007f3495bf9420 in <signal handler called> () at /lib/x86_64-linux-gnu/libpthread.so.0
	20 0x000055d531574e55 in thread_start_func_2 (th=<optimized out>, stack_start=<optimized out>) at thread.c:676
	21 0x000055d531575b31 in thread_start_func_1 (th_ptr=<optimized out>) at thread_pthread.c:1170
	22 0x00007f3495bed609 in start_thread (arg=<optimized out>) at pthread_create.c:477
	23 0x00007f3495b12133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
	```
	---
	 vm_backtrace.c | 9 +++++++++
	 1 file changed, 9 insertions(+)
2023-01-18 17:08:23 +09:00
NARUSE, Yui
89cd61890f merge revision(s) 542e984d82: [Backport #19292]
[Bug #19292] Re-initialize tm when wday or yday is not set

	---
	 test/ruby/test_time.rb |  3 ++-
	 time.c                 | 31 ++++++++++++++++++++++---------
	 2 files changed, 24 insertions(+), 10 deletions(-)
2023-01-17 11:21:00 +09:00
NARUSE, Yui
49cf0896a2 merge revision(s) 90a80eb076: [Backport #19284]
Fix integer underflow when using HEAP_INIT_SLOTS

	There is an integer underflow when the environment variable
	RUBY_GC_HEAP_INIT_SLOTS is less than the number of slots currently
	in the Ruby heap.

	[Bug #19284]
	---
	 gc.c                 | 25 +++++++++++++------------
	 test/ruby/test_gc.rb |  5 +++++
	 2 files changed, 18 insertions(+), 12 deletions(-)
2023-01-17 11:20:40 +09:00
NARUSE, Yui
a7d467a792 merge revision(s) b726d60c98: [Backport #19273]
Fix [Bug 19273], set correct value to `outer_repeat` on `OP_REPEAT`
	 (#7035)

	---
	 regexec.c                | 2 +-
	 test/ruby/test_regexp.rb | 5 +++++
	 2 files changed, 6 insertions(+), 1 deletion(-)
2022-12-29 15:59:52 +09:00
NARUSE, Yui
5c551ac59f merge revision(s) fc03ba50f1: [Backport #19263]
MJIT: Fix JIT code for multiple values in a single case

	[Bug #19263]
	---
	 lib/ruby_vm/mjit/compiler.rb |  2 +-
	 test/ruby/test_mjit.rb       | 10 ++++++++++
	 2 files changed, 11 insertions(+), 1 deletion(-)
2022-12-27 14:56:51 +09:00
NARUSE, Yui
a528908271 v3.2.0 2022-12-25 15:55:25 +09:00
Takashi Kokubun
38a7a13ac6
Auto-generate the release date on version.h from git CommitDate (#6382)
* Auto-generate the release date on version.h

from git CommitDate

* Generate revision.h on mswin
2022-09-17 21:16:06 +09:00
git
e3a32abe2e * 2022-09-17 [ci skip] 2022-09-17 02:25:39 +09:00
git
3ff65dcd8b * 2022-09-16 [ci skip] 2022-09-16 13:37:37 +09:00
git
0953ea64a2 * 2022-09-15 [ci skip] 2022-09-15 00:32:30 +09:00
git
b876230e5c * 2022-09-14 [ci skip] 2022-09-14 07:21:38 +09:00
git
bc8bbd23ab * 2022-09-13 [ci skip] 2022-09-13 09:25:25 +09:00
git
6f8267b7f3 * 2022-09-12 [ci skip] 2022-09-12 07:48:12 +09:00
git
c22a668580 * 2022-09-11 [ci skip] 2022-09-11 02:03:41 +09:00
git
2a08a39d7d * 2022-09-10 [ci skip] 2022-09-10 00:38:09 +09:00
git
6d93644ba1 * 2022-09-09 [ci skip] 2022-09-09 00:46:21 +09:00
git
b1efdcee6e * 2022-09-08 [ci skip] 2022-09-08 11:25:32 +09:00
git
a9c85c0c45 * 2022-09-07 [ci skip] 2022-09-07 00:05:24 +09:00
git
ca172540d0 * 2022-09-06 [ci skip] 2022-09-06 00:27:06 +09:00
git
e83183b498 * 2022-09-05 [ci skip] 2022-09-05 00:00:20 +09:00
git
13a59747c8 * 2022-09-04 [ci skip] 2022-09-04 03:01:51 +09:00
git
6bb2a43ca3 * 2022-09-03 [ci skip] 2022-09-03 03:28:11 +09:00
git
419118473e * 2022-09-02 [ci skip] 2022-09-02 03:56:03 +09:00
git
036bb55980 * 2022-09-01 [ci skip] 2022-09-01 04:44:44 +09:00
Nobuyoshi Nakada
32a0591515
Move macros from version.h to version.c
Moved the contents of `ruby_description` and `ruby_copyright` which
are never used in the other places.
2022-08-31 18:00:45 +09:00
git
f4cdfff084 * 2022-08-31 [ci skip] 2022-08-31 06:22:01 +09:00
git
18dc379aca * 2022-08-30 [ci skip] 2022-08-30 00:45:14 +09:00
git
5fcce23ae2 * 2022-08-29 [ci skip] 2022-08-29 00:33:32 +09:00
git
4de09574e0 * 2022-08-28 [ci skip] 2022-08-28 02:04:31 +09:00
git
f97af5cdc3 * 2022-08-27 [ci skip] 2022-08-27 12:56:00 +09:00
git
c2daa05693 * 2022-08-26 [ci skip] 2022-08-26 00:08:09 +09:00
git
fa9f4d387c * 2022-08-25 [ci skip] 2022-08-25 02:43:03 +09:00
git
feff683306 * 2022-08-24 [ci skip] 2022-08-24 06:28:39 +09:00
git
c96ffec984 * 2022-08-23 [ci skip] 2022-08-23 01:22:01 +09:00