-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Make Vector.bsearch
and bsearch_custom
const
#90341
base: master
Are you sure you want to change the base?
Conversation
Vector.bsearch
and bsearch_custom
const
I see. I will investigate why godot --doctool does not produce the const qualifiers for PackedByteArray, PackedColorArray and PackedFloat32Array specifically. |
It does, you didn't update them yourself, the automated check generates them correctly, you must have forgotten to |
Vector's bsearch and bsearch_custom methods internally call SearchArray.bisect, which is a const method. By using ptr() instead of ptrw() to retrieve a const pointer, we can ensure that bsearch and bsearch_custom do not modify the Vector instance, allowing these methods to be marked as const. This change aligns Vector's bsearch methods with Array.bsearch, which is already const. Also, previously you could not use const references to Vectors like PackedXXXArrays and bsearch them.
3a4af36
to
db7d722
Compare
You are awesome! I had no idea about documentation before. Ran --doctool, added everything as suggested. |
As you can see the compatibility is broken and we can't (currently) bind compatibility methods for these methods, see: Just like that one this can't be merged before such a system is implemented |
You got it! I was thinking, providing compatibility binding for Variants/core builtins would be a huge improvement. I already decided to dedicate myself to that. But as a preamble: My solutions will not be the prettiest. There is a lot to consider and I will need careful reviews for the iterations to come. |
You'll have to wait until that's implemented, there's no way to do this right now, it should be in a separate PR, and to add this would require a lot of knowledge on the lower level stuff, I'd not suggest it for a new contributor |
I agree. After all, variants are bound directly in And I don't want to spam this project with unnecessarily bad requests with insufficient solutions for such an important problem. But still, am I allowed to try? |
You're very welcome to try, but this is a very complex part of the engine, you'd want the functionality of The complexity of this and that it requires a whole new system is the reason it hasn't been done yet, even by the team who implemented the original feature |
I would say that the best solution here is a new system for all compatibility methods, or rather a new backing for it, which the |
I will try to draft something according to your suggestion. I will mention it here. I can't promise anything because of the complexity, so I'd suggest giving me some time and see, if I can come up with something. If I manage, I'd be very happy about any further suggestions. |
Description
This pull request updates
Vector
'sbsearch
andbsearch_custom
methods to be marked as const by usingptr()
instead of the write pointerptrw()
. This adjustment ensures that these methods don't modify the Vector instance, aligning the behavior withArray.bsearch
, which is already const.This change is particularly relevant when using GDExtensions, as it enables the use of const references for
PackedXXXArrays
casted fromVariants
when using bsearch.Backward compatibility
The transition to const methods is straightforward in theory, as non-const methods can call const methods without issue. However, this modification alters the "is_const" property in the API dictionary generation and affects method hashes due to their dependency on method constness.
Even though this is not an issue for me, it does affect backward compatibility for some GDExtension modules. At least those modules that use bsearch need to be recompiled with the newly dumped api currently.
So, this might be a major issue.
I believe backward compatibility issues have been addressed before in scenarios like this, but I'm not entirely sure how. If you have any insights or previous experiences on providing backward compatibility, I'd be glad to collaborate.
Documentation
Const qualifiers get added to PackedXXXArray.xml like so:
<method name="bsearch" qualifiers="const">
My knowledge regarding documentation is limited. So, if there is more to do, I am happy about any input.