Issue #19315 has been reported by Eregon (Benoit Daloze).
----------------------------------------
Feature #19315: Lazy substrings in CRuby
https://bugs.ruby-lang.org/issues/19315
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
----------------------------------------
CRuby should implement lazy substrings, i.e., "abcdef"[1..3] must not copy bytes.
Currently CRuby only reuse the char* if the substring is until the end of the buffer.
But it should also work wherever the substring starts and ends.
Yes, it means RSTRING_PTR() might need to allocate to \0-terminate, so be it, it's worth it.
There is already code for this (`SHARABLE_MIDDLE_SUBSTRING`), but it's disabled by default and `RSTRING_PTR()` needs to be changed to deal with this.
It seems a good idea to introduce a variant of `RSTRING_PTR` which doesn't guarantee \0-termination, so such callers can then use the existing bytes always without copy.
There are countless workarounds for this missing optimization, all not worth and all less readable:
* https://bugs.ruby-lang.org/issues/19314
* https://github.com/ruby/net-protocol/pull/14
* Manual lazy substrings which track string + index + length
* More but I don't remember all now, feel free to comment or link more urls/tickets.
--
https://bugs.ruby-lang.org/
Issue #19520 has been reported by ioquatix (Samuel Williams).
----------------------------------------
Feature #19520: Support for `Module.new(name)` and `Class.new(superclass, name)`.
https://bugs.ruby-lang.org/issues/19520
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
----------------------------------------
See <https://bugs.ruby-lang.org/issues/19450> for previous discussion and motivation.
[This proposal](https://github.com/ruby/ruby/pull/7376) introduces the `name` parameter to `Class.new` and `Module.new`:
```ruby
Class.new(superclass, name)
Module.new(name)
```
As a slight change, we could use keyword arguments instead.
--
https://bugs.ruby-lang.org/
Issue #19197 has been reported by AMomchilov (Alexander Momchilov).
----------------------------------------
Feature #19197: Add Exception#root_cause
https://bugs.ruby-lang.org/issues/19197
* Author: AMomchilov (Alexander Momchilov)
* Status: Open
* Priority: Normal
----------------------------------------
## Description
I would like to add a `#root_cause` method to `Exception`.
It returns the last exception in linked-list of causality chain, that is, the original exception (whose own `cause` is `nil`).
## Example
```ruby
e = begin
raise 'a' # This is the root cause
rescue => a
begin
raise 'b'
rescue => b
begin
raise 'c' # This is the outermost cause assigned to `e`
rescue => c
c
end
end
end
p(e) # => #<RuntimeError: c>
p(e.cause) # => #<RuntimeError: b>
p(e.cause.cause) # => #<RuntimeError: a>
p(e.cause.cause.cause) # => nil
p(e.root_cause) # => #<RuntimeError: a>
p(e.root_cause.cause) # => nil
```
# Motivation
There are some kinds of exceptions that can occur all over the place (and might be wrapped by arbitrarily many middlemen), but are attributable to a singular global cause. For example, a database outage could raise exceptions in almost every line of business logic of an app that uses ActiveRecord models.
Fundamentally, you wouldn't want an error report for every one of these lines. You'd want to look at the root cause, and bucket all SQL-connection issues into a single report, regardless of where they surface.
### Implementation
Draft PR: https://github.com/ruby/ruby/pull/6913
--
https://bugs.ruby-lang.org/
Issue #19452 has been reported by ioquatix (Samuel Williams).
----------------------------------------
Bug #19452: `Thread::Backtrace::Location` should have column information if possible.
https://bugs.ruby-lang.org/issues/19452
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
I discussed this with @mame and it would be pretty useful if we could also get the column information from exception backtrace location, even if it was slow.
A POC:
```ruby
class Thread::Backtrace::Location
if defined?(RubyVM::AbstractSyntaxTree)
def first_column
RubyVM::AbstractSyntaxTree.of(self, keep_script_lines: true).first_column
end
else
def first_column
raise NotImplementedError
end
end
end
```
It would be good to have a standard interface, so we follow the same interface as https://bugs.ruby-lang.org/issues/19451 and vice versa where it makes sense. I'll investigate it.
--
https://bugs.ruby-lang.org/
Issue #19559 has been reported by sawa (Tsuyoshi Sawada).
----------------------------------------
Feature #19559: Introduce `Symbol#+@` and `Symbol#-@`, and eventually replace boolean arguments with symbols
https://bugs.ruby-lang.org/issues/19559
* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
----------------------------------------
I propose to define `Symbol#+@` and `Symbol#-@`, so that we can add positive or negative polarity to symbols. A possible implementation can be equivalent to what can be achieved by this:
```ruby
class Symbol
def -@; "-#{self}".to_sym end
def +@; self end
end
```
The intention behind this is to, eventually, replace boolean positional or keyword arguments with symbols so that, instead of this:
```ruby
"foo".methods(false)
gets(chomp: true)
Integer("2.3", exception: false)
```
we can write like this:
```ruby
"foo".methods(-:inherit)
gets(+:chomp)
Integer("2.3", -:exception)
```
--
https://bugs.ruby-lang.org/
Issue #19294 has been reported by zverok (Victor Shepelev).
----------------------------------------
Bug #19294: Enumerator.product works incorrectly with consuming enumerators
https://bugs.ruby-lang.org/issues/19294
* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
```ruby
s = StringIO.new('abc')
Enumerator.product([1, 2, 3], s.each_char).to_a
# Expected: => [[1, "a"], [1, "b"], [1, "c"], [2, "a"], [2, "b"], [2, "c"], [3, "a"], [3, "b"], [3, "c"]]
# Actual: => [[1, "a"], [1, "b"], [1, "c"]]
```
The implementation consumes the non-first enumerator to produce the first combination.
Somewhat related to the dilemma of consuming and non-consuming enumerators (#19061).
PS: I noticed I don't understand why it is `Enumerator.product` and not `Enumerable#product`, but probably it is too late to raise the questions :(
--
https://bugs.ruby-lang.org/