Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

llvm-beanz
Copy link
Collaborator

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.

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.

```hlsl
float4 F = 1.0.xxxx;
struct A {
Copy link
Collaborator

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.

proposals/xxxx-initializer-lists.md Show resolved Hide resolved
Comment on lines +72 to +74
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
```
Copy link
Collaborator

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};
Copy link
Collaborator

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}?

Copy link
Collaborator

@tex3d tex3d left a 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
Copy link
Collaborator

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?

```
InitListExpr
ImplicitCastExpr float->int
ExtVectorElementExpr .x
Copy link
Collaborator

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?

Copy link
Collaborator

@bogner bogner left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants