Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14192] 64-bit IndexSet #4227

Open
swift-ci opened this issue Feb 12, 2021 · 2 comments
Open

[SR-14192] 64-bit IndexSet #4227

swift-ci opened this issue Feb 12, 2021 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-14192
Radar rdar://problem/74274735
Original Reporter ken (JIRA User)
Type Bug
Environment

Welcome to Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1).

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 76c67376170b897729726db28c69f686

Issue Description:

In IndexSet.swift, and on the developer.apple.com doc page, it says:

/// The range of valid integer values is 0..<INT_MAX-1. Anything outside this range is an error.

But INT_MAX is-an Int32, so this is only 2**31-1.

  • In IndexSet.swift, all the comments say INT_MAX (32-bit, always?), but all the code uses Int.max (64-bit, on 64-bit architectures).

  • IndexSet's public interface uses Int, and it's used in other interfaces (like NSTableView) which use it to index into Int-indexed data structures.

  • IndexSet is bridged to NSIndexSet, whose documentation says its range is 0...(NSNotFound-1) (where NSNotFound is defined as NSIntegerMax-1, a 64-bit value on 64-bit architectures).

So I think all the documentation/comments about the range of IndexSet are mistaken. It should be 0..<Int.max-1, not 0..<INT_MAX-1, correct?

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Contributor Author

Comment by Ken Harris (JIRA)

On further investigation, I think it should be 0..<Int.max, not 0..<Int.max-1.

The value NSNotFound-1 is documented as valid in NSIndexSet, and empirically it works with IndexSet, too.

I think the type of this range got mis-transcribed at some point.

  • NSMutableIndexSet says "0...(NSNotFound - 1)" (looks correct)

  • NSIndexSet says "0 .. NSNotFound - 1" (old Swift syntax for "..<", possibly copied from the above without realizing ".." is different from "...")

  • IndexSet says "0..<INT_MAX-1" (a modern literal translation of the ".." operator)

So I'm proposing IndexSet should say "0..<Int.max".

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants