-
Notifications
You must be signed in to change notification settings - Fork 36
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
[202y] Propose adding C++11-style constructors #325
base: main
Are you sure you want to change the base?
Conversation
This proposal adds user-defined constructors and destructors to HLSL and defines how they should interact with semantics and global initialization.
* Added explicit reference to ISO C++ standard * Added description of handling groupshared * Added some cases that diagnostics should be emitted for
Hello! As I was working on input/output/global/private variable using address spaces (to convert this to SPIR-V storage classes), I reached a bit of a question: Do you have a plan on how to handle ctor/dtor overload resolution depending on Example: struct S {
S(int value) : member(value) { }
/* implicit: S(int value) __attribute__((address_space(10))) : member(value) { } */
int member;
};
static S s_global(23); // AS=10, SC=Private
[numthreads(1, 1, 1)]
void main() {
S s_local(24) /* AS=0, SC=Function */;
} Today, OpenCL deals with this with an In my initial plan, I wanted to instantiate one version of the ctor for each used address-space. But this assumes the |
This problem is bigger than just constructors. The same problem occurs for any non-static member function. HLSL 2021 does not allow overloading functions based on the implicit object parameter (constness or address space). That likely does need to change in the future. That's out of the scope of this PR. WRT your plans for upstream LLVM, I think that we likely need to do what OpenCL does in order to maintain source compatibility for HLSL 202x and earlier. We could consider changing this for 202y, but I don't want to rule out the possibility of supporting overloading by implicit object address space especially as we look to future C++ features like deducing-this, where we may want to allow users a lot more flexibility. |
instead require that every field either have a semantic annotation, or a default | ||
initialization through either a default constructor or a default initializer. | ||
|
||
HLSL will also introduce default initialization and defaulted and deleted |
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.
Can you add to the proposal any commentary on the inclusion/exclusion of implicit constructors? (and if included, which ones would be implicit)
I'm assuming we wouldn't want to have any implicit constructors in HLSL but the presence of delete
d constructors implies we'd need some implicit compiler constructor to delete
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.
I'll add language around this, but I think we need to match C++'s implicit constructors. As much as I tend to dislike implicit behavior, without implicit default constructors, copy constructors, assignment operators, and destructors we would violently break source compatibility.
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.
Right got it, forgot that we still need to contend with the ctors people were previously depending on
This proposal adds user-defined constructors and destructors to HLSL and defines how they should interact with semantics and global initialization. The intent is to align with C++11.
This proposal was originally proposed as #5, however it didn't merge before the repository was moved from private to public, and it got stranded in GitHub's tooling and closed.