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?

Copy link
Collaborator Author

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
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 Author

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.

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.


# Initializer Lists

* Proposal: [NNNN](NNNN-initializer-lists.md)
Copy link
Member

Choose a reason for hiding this comment

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

small reminder to:

  1. add proposal number,
  2. rename file
  3. 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
Copy link
Member

@farzonl farzonl Nov 13, 2024

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)
Copy link
Member

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

Copy link
Member

@farzonl farzonl left a comment

Choose a reason for hiding this comment

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

LGTM

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.

5 participants