Skip to content

Mutex#sleep and ConditionVariable#wait take a Rational, a BigDecimal or a long as their timeout - #55

Merged
Largo merged 1 commit into
masterfrom
fix/sleep-interval-divmod
Oct 29, 2026
Merged

Largo merged 1 commit into
masterfrom
fix/sleep-interval-divmod

Conversation

@Largo

@Largo Largo commented Oct 29, 2026

Copy link
Copy Markdown
Owner

@sholden's fork PR sholden#7, carried over. Its fork branch fix/sleep-interval-divmod sat on fix/condvar-wait, which is merged here as #42, so the branch can't be opened as is. This branch is sholden's one new commit (13c727a), cherry-picked onto master without conflicts and with sholden still the author. Nothing else changed.

Checked on this branch (Debug, net8.0, Linux):

  • regen-initializers.sh leaves Initializers.Generated.cs exactly as committed.
  • IronRuby.Tests: 0 failures.
  • spec/core/mutex: 35 examples, 0 failures. spec/core/conditionvariable: 11 examples, 0 failures.
  • Util/condvar-matrix.rb prints exactly what CRuby 4.0.6 prints (49 lines).

The description below is sholden's. Bare PR numbers that were fork-local now point at sholden/ironruby, or at the upstream PR where one exists.


Stacked on #42. It builds on the shared RubyMutex.ToSleepSeconds conversion added there.

MRI converts a timeout that isn't an Integer or a Float through divmod(1). The whole seconds go through to_int, and the fraction is multiplied by 1_000_000_000 to give nanoseconds. Anything without a #divmod that returns an Array raises "can't convert X into time interval". IronRuby accepted only an int or a double, so these raised TypeError:

  • m.sleep(Rational(1, 100)) and cv.wait(m, BigDecimal("0.01")), which work in MRI.
  • m.sleep(2**40), which MRI sleeps on. IronRuby stores an Integer past 32 bits as a CLR long, and the conversion didn't handle that type.

A Bignum now raises MRI's RangeError only when it doesn't fit a long. Initializers.Generated.cs was regenerated with ClassInitGenerator, and the regenerated file differs only in the two changed signatures (8 lines).

Testing (Linux, net10.0)

Still different from MRI (not in this PR)

  • Kernel#sleep has its own conversion. A negative Rational gives "time interval must be positive" (MRI: "must not be negative"). Objects that aren't intervals get NoMethodError or "no implicit conversion" instead of "can't convert X into time interval".
  • Error message wording. [nil, 0] from #divmod reports IronRuby's generic "no implicit conversion of nil into Integer" (MRI: "from nil to integer"). NoMethodError messages use IronRuby's backtick quoting.
  • A negative fraction (divmod → [0, -0.05]) raises ArgumentError here. MRI blocks forever.

🤖 Generated with Claude Code

…or a long as their timeout

MRI turns a timeout that is not an Integer or a Float into an interval through
divmod(1): the whole seconds through #to_int, the fraction times 1_000_000_000 as
nanoseconds; an object without a #divmod that answers an Array is "can't convert X
into time interval". IronRuby only took an int or a double, so a Rational or a
BigDecimal was a TypeError - and so was any Integer past 32 bits, which IronRuby holds
as a long (m.sleep(2**40) raised instead of sleeping). A Bignum is MRI's RangeError
only when it does not fit a long.

Initializers.Generated.cs regenerated with ClassInitGenerator: the two signatures only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 180e7651-ca4a-4836-8a91-fc7f7bb16e35
Commits

Reviewing files that changed from the base of the PR and between 3cc808e and 1954c12.

Files ignored due to path filters: 1
  • Src/Libraries/Initializers.Generated.cs is excluded by !**/*.generated.*
Files selected for processing: 3
  • Src/Libraries/Thread/RubyConditionVariable.cs
  • Src/Libraries/Thread/RubyMutex.cs
  • Util/condvar-matrix.rb
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants