[#106355] [Ruby master Bug#18373] RBS build failure: '/include/x86_64-linux/ruby/config.h', needed by 'constants.o'. — "vo.x (Vit Ondruch)" <noreply@...>

Issue #18373 has been reported by vo.x (Vit Ondruch).

28 messages 2021/12/01

[#106356] [Ruby master Bug#18374] make: Circular spec/ruby/optional/capi/ext/array_spec.c <- spec/ruby/optional/capi/ext/array_spec.c dependency dropped. — "vo.x (Vit Ondruch)" <noreply@...>

Issue #18374 has been reported by vo.x (Vit Ondruch).

8 messages 2021/12/01

[#106360] [Ruby master Feature#18376] Version comparison API — "vo.x (Vit Ondruch)" <noreply@...>

Issue #18376 has been reported by vo.x (Vit Ondruch).

28 messages 2021/12/01

[#106543] [Ruby master Bug#18396] An unexpected "hash value omission" syntax error when parentheses call expr follows — "koic (Koichi ITO)" <noreply@...>

Issue #18396 has been reported by koic (Koichi ITO).

10 messages 2021/12/08

[#106596] [Ruby master Misc#18399] DevMeeting-2022-01-13 — "mame (Yusuke Endoh)" <noreply@...>

Issue #18399 has been reported by mame (Yusuke Endoh).

11 messages 2021/12/09

[#106621] [Ruby master Misc#18404] 3.1 documentation problems tracking ticket — "zverok (Victor Shepelev)" <noreply@...>

Issue #18404 has been reported by zverok (Victor Shepelev).

16 messages 2021/12/11

[#106634] [Ruby master Bug#18407] Behavior difference between integer and string flags to File creation — deivid <noreply@...>

Issue #18407 has been reported by deivid (David Rodr鱈guez).

12 messages 2021/12/13

[#106644] [Ruby master Bug#18408] Rightward assignment into instance variable — "Dan0042 (Daniel DeLorme)" <noreply@...>

Issue #18408 has been reported by Dan0042 (Daniel DeLorme).

23 messages 2021/12/13

[#106686] [Ruby master Bug#18409] Crash (free(): invalid pointer) if LD_PRELOAD doesn't explicitly include libjemalloc.so.2 — "itay-grudev (Itay Grudev)" <noreply@...>

Issue #18409 has been reported by itay-grudev (Itay Grudev).

7 messages 2021/12/15

[#106730] [Ruby master Bug#18417] IO::Buffer problems — "zverok (Victor Shepelev)" <noreply@...>

Issue #18417 has been reported by zverok (Victor Shepelev).

9 messages 2021/12/19

[#106784] [CommonRuby Feature#18429] Configure ruby-3.0.3 on Solaris 10 Unknown keyword 'URL' in './ruby.tmp.pc' — "dklein (Dmitri Klein)" <noreply@...>

Issue #18429 has been reported by dklein (Dmitri Klein).

32 messages 2021/12/23

[#106828] [Ruby master Bug#18435] Calling `protected` on ancestor method changes result of `instance_methods(false)` — "ufuk (Ufuk Kayserilioglu)" <noreply@...>

Issue #18435 has been reported by ufuk (Ufuk Kayserilioglu).

23 messages 2021/12/26

[#106833] [Ruby master Feature#18438] Add `Exception#additional_message` to show additional error information — "mame (Yusuke Endoh)" <noreply@...>

Issue #18438 has been reported by mame (Yusuke Endoh).

30 messages 2021/12/27

[#106834] [Ruby master Bug#18439] Support YJIT for VC++ — "usa (Usaku NAKAMURA)" <noreply@...>

Issue #18439 has been reported by usa (Usaku NAKAMURA).

11 messages 2021/12/27

[#106851] [Ruby master Bug#18442] Make Ruby 3.0.3 on Solaris 10 with "The following command caused the error: cc -D_STDC_C99= " — "dklein (Dmitri Klein)" <noreply@...>

Issue #18442 has been reported by dklein (Dmitri Klein).

8 messages 2021/12/27

[#106928] [Ruby master Bug#18454] YJIT slowing down key Discourse benchmarks — "sam.saffron (Sam Saffron)" <noreply@...>

Issue #18454 has been reported by sam.saffron (Sam Saffron).

8 messages 2021/12/31

[ruby-core:106366] [Ruby master Bug#18377] Integer#times has different behavior depending on the size of the integer

From: "Eregon (Benoit Daloze)" <noreply@...>
Date: 2021-12-01 20:42:50 UTC
List: ruby-core #106366
Issue #18377 has been updated by Eregon (Benoit Daloze).


I think this should remain unspecified, or explicitly mention both behavior (respecting +, < or not) are valid.
For instance it's been shown rewriting `Integer#times` in Ruby is beneficial for JITs (among other things it also enables inlining and OSR), and then using +/< is natural.
But if `times` is written in C/Java it doesn't make sense to call the +/< methods dynamically.

The inconsistency for bignums is indeed surprising, I think that is worth fixing in CRuby.

----------------------------------------
Bug #18377: Integer#times has different behavior depending on the size of the integer
https://bugs.ruby-lang.org/issues/18377#change-95001

* Author: jemmai (Jemma Issroff)
* Status: Open
* Priority: Normal
* ruby -v: 3.0.2
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
If we redefine `+` or `>`, `Integer#times` adheres to this redefinition for big integers but not for small integers.

Reproduction script to run on Ruby 3.0.2:

```
ARGV.first.to_i.times do
  Integer.undef_method(:+)
  Integer.define_method(:+) do |_other|
    puts "my custom add"
    exit
  end
end
```

Using `1` as an argument has no printed output:

```
$ ruby test_add.rb 1
```

whereas using `2 ** 64` (`18446744073709551615`) prints "my custom add":

```
$ ruby test_add.rb 18446744073709551615
my custom add
```

We see the same difference when we override behavior of `<`:

```
ARGV.first.to_i.times do
  Integer.undef_method(:<)
  Integer.define_method(:<) do |_other|
    puts "my custom less than"
    exit
  end
end
```
```
$ ruby test_less_than.rb 1
```
```
$ ruby test_less_than.rb 18446744073709551615
my custom less than
```

Note that the boxed number which changes the `Integer#times` behavior will vary on different machines.

**Options**

There are three potential paths forward here:
1. *Change behavior for small integers to match behavior for big integer.*
This will have a performance cost. It’s uncommon to redefine `+` or `<` on Integers. For this reason, I would argue that correctness on an obscure edge case (especially one that has been unreported since almost the beginning of the language) is less important than performance on the default case.

2. *Change behavior for big integers to match behavior for small integers.* 
This will mean that behavior is incorrect on both big integers and small integers, but at least it is consistent. Right now it is arbitrary and hard to explain why the behavior would change based on the integer itself. If we keep this behavior consistent for all integers, we can document this clearly in a way that is easy to understand.

3. *Do nothing.* 
This bug has existed for many years unreported. The last option is to not pursue any code changes, but potentially document this behavior.

**Proposal**

I propose we pursue option 2 and make the behavior consistent and documented. As I said, it’s unlikely that developers override integer behavior of `+`, and especially unlikely to do this within an `Integer#times` block. As long as this is documented and consistent, it seems okay to me to have this known incorrectness to save the performance cost of accommodating different definitions of `+`.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread