-
-
Notifications
You must be signed in to change notification settings - Fork 369
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 Issue 22141 - Property .capacity is not listed in the array prope… #3356
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the line
This is a fixed quantity for static arrays. It is of type $(D size_t).)
ends up being repeated
|
@thewilsonator done. It was a copy paste error on my part. |
|
Is capacity actually part of the language spec, or just a runtime library feature? It is documented in druntime's docs: http://druntime.dpldocs.info/object.capacity.html |
I think that this distinction is rather moot. It's a property that users may use, therefore it should be present in the docs. |
I agree. It's not hard to dummy the capacity to be the same as length, in case some runtime doesn't support querying the BlkInfo, so I would say we should enforce this to exist to increase portability. |
It is present in the docs.
Where? I just grepped it and the only time I see it appearing is in a test file, where it is just used as a hack to the optimizer instead of any actual spec test. There are no references to the
It would be compile errors, not linker errors, if and only if the function is actually called. Which is the same as any other function or module in there. What about .dup and .idup used to be built in, just like .ptr and .length. But they aren't anymore either. So really, why are there some druntime functions listed here and other ones not? It seems completely arbitrary. BTW speaking of betterC (which is terrible and should be removed), if this PR is merged, dmd -betterC would no longer be compliant with the spec. Which is fine by me, again, it is terrible and should be removed, but you're introducing an inconsistency. |
Wow, you are right. I just looked at the dmd code and it seems that the compiler simply tries UFCS for a I see your point now,
I don't see the relevance of this example. We are talking about the user perspective here, not how the compiler devs categorize the myriad of functions that are being called implicitly by the compiler.
Because you can directly call them as if they were properties of an array without any intervention whatsoever. In my opinion, if you can do |
As you yourself said: "if you can do array.whatever without needing to import anything, then whatever should be in the list of properties for arrays" (I disagree with that statement, but my point is that your position is inconsistent with itself.)
They're exactly the same as any other library import, including the possibility of overrides and conflicts: cap.d(4): Error: function That does NOT happen with the fully built ins: try changing idup to length there and find no error. length is built into the compiler, idup isn't. So, what's the actual logic here in terms of the spec? |
|
@adamdruppe sort, reserve and assumeSafeAppend modify the array. capacity does not, it's just a getter property similar to length. Fair point about built in properties vs runtime functions and overloading. |
|
Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
|
Co-authored-by: Nick Treleaven <ntrel002@gmail.com>
|
I think that a better litmus test for whether the language spec should specify that Now, an argument can be made about Druntime and Phobos: are competing implementations of the language supposed to be able to reuse Druntime and Phobos, with minimum to no changes from the reference implementation? Perhaps only Phobos? But what about TL;DR Instead of arguing about is an isn't part of the language based on the current implementation, we should decide what is the minimum set of stuff that is supposed to be. Otherwise, there will be always push and pull about whether we should document the implementation or change it to match the docs. |
|
Honestly, I find the distinction irrelevant. The reader of the docs is 99.9% of times someone who doesn't care about the implementation. For that particular person, the fact that you can use If we want to highlight the distinction between builtin properties and druntime calls we can do that, but that brings exactly 0 value to anyone reading the docs. |
…rties section