-
Notifications
You must be signed in to change notification settings - Fork 11
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
HLSL Initializer List Support #75
base: main
Are you sure you want to change the base?
Conversation
This PR adds a proposal for HLSL initializer list support to align Clang with DXC's behavior while providing a path forward to a better language implementation in the future.
proposals/xxxx-initializer-lists.md
Outdated
|
||
```hlsl | ||
float4 F = 1.0.xxxx; | ||
struct A { |
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.
Consider renaming struct A
to avoid potential conflict with the earlier declaration viz.,
struct A {
int a;
double b;
};
specifically for the variable declaration A a = {F.x, F.y, F.z, F.w};
later in the document.
Given the differences in the language described above it is likely too | ||
significant of a change to make Clang follow C/C++ behavior without a transition | ||
period. Since Clang and DXC will have different underlying representations for |
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.
Given the differences in the language described above it is likely too | |
significant of a change to make Clang follow C/C++ behavior without a transition | |
period. Since Clang and DXC will have different underlying representations for | |
Given the differences in the languages as described above it is likely changes | |
needed to make Clang follow C/C++ behavior would be significant thereby requiring | |
a transition period. Since Clang and DXC will have different underlying representations for |
compatibility with existing HLSL, this proposal suggests that Clang parse HLSL | ||
initialization syntax into valid C++ initializer list ASTs. | ||
|
||
This would mean that given an example like: |
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.
This would mean that given an example like: | |
This would mean that given an HLSL example code such as: |
ImplicitCastExpr float->half | ||
ExtVectorElementExpr .w | ||
DeclRefExpr F | ||
``` |
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.
Rename F
as f
following changes in commit 6902340
|
||
```hlsl | ||
B b3 = {{{1, 2}, {3, 4}}, 5}; | ||
A a = {F.x, F.y, F.z, F.w}; |
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.
Should F
be renamed as f
following changes in commit 6902340?
Given
struct A {
int a;
double b;
};
is this initilization correct? Should it be A a = {f.x, f.y}
?
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 think this is good. Comments are for curiosity, no resolution expected for merging.
``` | ||
InitListExpr | ||
InitListExpr | ||
InitListExpr |
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 wonder how source range would be set for these expressions. Would we just point from the first element to the last element that the expression corresponds to, even though it will cross weird grouping boundaries?
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.
InitListExpr
source ranges are basically the beginning of the first sub-expression to the end of the last. The locations could get a bit wonky, but for error reporting they should work well enough.
``` | ||
InitListExpr | ||
ImplicitCastExpr float->int | ||
ExtVectorElementExpr .x |
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.
What would we set for source locations for expressions like this? Just point to f
for all of them?
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.
Yea, that's what I was thinking. Basically the source location for each of the implicit access expressions points to the argument they are derived from.
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.
This looks good, though as Tex points out I think there are a lot of questions that this opens up about the debug info story. I suspect we'll have to just accept that source locations for these expressions will need to be very limited, since the AST doesn't actually match the source.
|
||
# Initializer Lists | ||
|
||
* Proposal: [NNNN](NNNN-initializer-lists.md) |
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.
small reminder to:
- add proposal number,
- rename file
- change status.
HLSL's initializer lists assume a member-by-member flattened initialization | ||
sequence. It is significantly different in behavior from C/C++ initializer | ||
lists, but in a way that may not be apparent to users that they are depending on | ||
the divergent behavior. This proposal suggests an approach to implementing |
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.
This line reads weird and could be stronger start with the forward looking modifier something like this:
This proposal offers a forward-looking approach to implementing HLSL's unique initializer behavior.
## Proposed solution | ||
|
||
This solution is based on an assumption that we will adopt | ||
[Proposal 0005 - Strict Initializer Lists](https://github.com/microsoft/hlsl-specs/blob/main/proposals/0005-strict-initializer-lists.md) |
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.
So the rich text looks fine but if you want to keep the column length looking more consistent in the raw text I saw justin does the below example on his proposals.
[TEXT][REF_NAME]
/// somewhere at the bottom of the file
[REF_NAME]: URL
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.
LGTM
This PR adds a proposal for HLSL initializer list support to align Clang with DXC's behavior while providing a path forward to a better language implementation in the future.