Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/rubyPublic

[Bug #21513] Raise on converting endless range to set#13902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
viralpraxis wants to merge1 commit intoruby:master
base:master
Choose a base branch
Loading
fromviralpraxis:raise-on-endless-range-to-set

Conversation

viralpraxis
Copy link
Contributor

@viralpraxisviralpraxis commentedJul 15, 2025
edited
Loading

Before this patch, trying to convert endless range (e.g.(1..) or any other inifinte enumerable) to set (usingto_set) would hang

Copy link
Contributor

@jeremyevansjeremyevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for working on this.

range.c Outdated
range_to_set(VALUErange)
{
if (NIL_P(RANGE_END(range))) {
rb_raise(rb_eRangeError,"cannot convert endless range to a set");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I believe that endless range error should be the same error type as beginless range error. Callingto_set on a beginless range currently raisesTypeError. This method should probably have beginless range raiseRangeError instead, and include a test and an example for that.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Makes sense. Should we also tweakRange#to_a to raiseRangeError in both cases?

./ruby -e'(..1).to_a'-e:1:in'Range#each': can't iterate from NilClass (TypeError)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Makes sense. Should we also tweakRange#to_a to raiseRangeError in both cases?

@nobu what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It feels clearer for me.
@knu Any thoughts?

If we will change it too, maybe ruby/spec also needs to be updated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should perhaps check the size of a given Enumerable in Set.new and raise an error when it is infinity.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should perhaps check the size of a given Enumerable in Set.new and raise an error when it is infinity.

Seems good to me. I'll try to follow this path

Copy link
ContributorAuthor

@viralpraxisviralpraxisJul 17, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I tried out this idea and it seems to work fine (we now raiseArgumentError error for any endless enumerable, e.g.1.upto(Float::INFINITY).

$ ./ruby -e'Set.new((1..nil))'-e:1:in'Set#initialize': cannot initialize Set from a enumerable with infinite size (ArgumentError)from -e:1:in'<main>'$ ./ruby -e'(1..nil).to_set'  -e:1:in'Enumerable#to_set': cannot initialize Set from a enumerable with infinite size (ArgumentError)from -e:1:in'<main>'

@viralpraxisviralpraxisforce-pushed theraise-on-endless-range-to-set branch 2 times, most recently from4b9f122 to31a3861CompareJuly 15, 2025 22:33
@viralpraxis
Copy link
ContributorAuthor

There's a SEGV in the ZJIT test suite:https://github.com/ruby/ruby/actions/runs/16305765996/job/46051383888?pr=13902

Not sure if it's related to my changes

@viralpraxisviralpraxisforce-pushed theraise-on-endless-range-to-set branch from31a3861 toa5a7db6CompareJuly 15, 2025 22:52
@tekknolagi
Copy link
Contributor

There's a SEGV in the ZJIT test suite:https://github.com/ruby/ruby/actions/runs/16305765996/job/46051383888?pr=13902

Not sure if it's related to my changes

ZJIT error seems entirely unrelated to your change from a quick glance

@tekknolagi
Copy link
Contributor

Looks like a weird GC issue related to marking though so paging in@k0kubun for good measure

@viralpraxisviralpraxisforce-pushed theraise-on-endless-range-to-set branch froma5a7db6 toe1b6f53CompareJuly 15, 2025 23:39
@viralpraxisviralpraxis changed the title[Feature #21513] Raise on converting endless range to set[Bug #21513] Raise on converting endless range to setJul 15, 2025
@viralpraxisviralpraxisforce-pushed theraise-on-endless-range-to-set branch frome1b6f53 toca35402CompareJuly 15, 2025 23:40
@launchable-appLaunchable app

This comment has been minimized.

@k0kubun
Copy link
Member

k0kubun commentedJul 16, 2025
edited
Loading

I agree that it's probably not related to the changes. We're looking into GC issues with ZJIT.

@viralpraxisviralpraxisforce-pushed theraise-on-endless-range-to-set branch 4 times, most recently from4fcebf3 to76fe90bCompareJuly 17, 2025 15:12
ref:https://bugs.ruby-lang.org/issues/21513Before this patch, trying to convert endless range (e.g. `(1..)`) to set(using `to_set`) would hang
@viralpraxisviralpraxisforce-pushed theraise-on-endless-range-to-set branch from76fe90b to7753557CompareJuly 17, 2025 15:47
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jeremyevansjeremyevansjeremyevans requested changes

@knuknuknu left review comments

@nobunobunobu left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@viralpraxis@tekknolagi@k0kubun@jeremyevans@knu@nobu

[8]ページ先頭

©2009-2025 Movatter.jp