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
Fix 14832: iota should have size_t length. #3571
Conversation
This PR is an alternative to #3544 which was rejected. |
I do not believe that pulling in the whole mess of std.conv is the right choice here |
As in #3544, I still do not understand the purpose behind allocating arrays of ulong length in 32 bit code. I'd immediately red flag any code that tried to do that as highly suspicious. Just because it can be made to work does not mean it should be. |
I strongly oppose this absent a compelling rationale for it. |
@WalterBright I think there's some miscommunication here. The original bug report is not talking about allocating arrays of In the original PR, the possibility of fixing |
@DmitryOlshansky Would changing this to an explicit comparison with |
@quickfur - test + throw error is enough. Then it stays nothrow at least. Allocating 2^^32 and beyond in 32-bit is a programming error. Either RangeError or AssertFailure |
iota(10UL).array - there are other cases with bigger numbers. |
Any range that has |
Did what @jmdavis proposed. It works, but dang, it makes the code so ugly. And something just doesn't feel right about having both |
And actually, looking at
rather than
I'm guessing that someone did that because of |
I thought about this a bit more. While So it appears that there are indeed ranges out there that may have finite length that cannot be represented by The question then is, should such ranges still have a |
These abnormal ranges might work with front/popFront/empty but the length should then check for overflow and throw error I guess. Overflow can be checked with these nice core.checkedint thingies. |
A file comes to mind as well.
There isn't a good rationale to support this requirement. Basically, the only reason to require length to be A common-sense implementation for
The third requirement of "Will it fit into the local architecture's word size" doesn't seem to jive with portability, or D's approach to types. It seems very arbitrary and unnecessary. Objectively, I don't think the change is correct. If you want to disallow iotas with larger than Unobjectively, I don't agree with the change to iota at all. The only culprit causing misery here is array (and only when called on 32-bit systems with ranges that have ulong length), it should get the treatment. |
OR current code that currently compiles and works as expected (regardless of what we think of its utility). |
Wow, this is so ridiculous. A trivial issue like creating an array of |
On 32-bit,
iota(10UL)
produces a range whose length is not convertible tosize_t
, causingarray()
to fail, even though its actual length is well within the range ofsize_t
.This fix makes
iota
always returnsize_t
as the length. It will throw an exception if the length is not representable assize_t
.