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

Specification language to describe flat conversions and aggregate splats. #358

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

spall
Copy link
Collaborator

@spall spall commented Dec 16, 2024

Specification language to describe flat conversions and aggregate splats.

@spall
Copy link
Collaborator Author

spall commented Dec 16, 2024

@microsoft-github-policy-service agree company="Microsoft"

@microsoft-github-policy-service agree company="Microsoft"

@llvm-beanz llvm-beanz added the Design Meeting Agenda item for the design meeting label Jan 18, 2025
Copy link
Collaborator

@llvm-beanz llvm-beanz left a comment

Choose a reason for hiding this comment

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

Please doublecheck which conversions are allowed to produce cxvalues vs which conversions can only produce prvalues.


\Sec{Array and Class splat conversion}{Conv.asplat}

\p A glvalue of type \texttt{T} can be converted to a cxvalue of type
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe that this conversion can only produce a prvalue, not a cxvalue. The only place cxvalues are created is for inout parameters, and I believe this code is invalid:

struct S {
    float V[4];
};

void fn(inout float4 F) {}

export void call() {
    S V = {1.xxxx};
    fn((float4)V);
    fn(V);
}

see: https://godbolt.org/z/Ms4ocrGMf

the value in the source vector replicated into each element of the flattened
\texttt{S}.

\p A glvalue of type \texttt{T} can be converted to a cxvalue of type
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is an odd case for vector<->array conversions where we can create a cxvalue, but only from an explicit cast:

void fn(inout float4 F) {}

export void call() {
    float V[4] = {1.xxxx};
    fn((float4)V); // valid
    fn(V); // invalid
}

see: https://godbolt.org/z/c3YcGWPex

@@ -118,6 +118,19 @@
of boolean type. A zero value is converted to \texttt{false}; all other values
are converted to \texttt{true}.

\Sec{Flat conversion}{Conv.flat}

\p There is a flattened order of subobjects for an aggregate, \texttt{A},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this language is fine for now, but we should probably have some common definitions and unify this with the language in Decl.Init.Agg.

I filed #372 to track that separately.

prvalue of type \texttt{U[]}, if there are valid conversions from
\texttt{T} to each \texttt{V} in flattened \texttt{U}. The destination value
is the source value \texttt{T} replicated into each element of the flattened
\texttt{U[]}.
Copy link
Collaborator

Choose a reason for hiding this comment

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

U[] is not the same type as U[N], so we should be clear we're talking about sized arrays here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Meeting Agenda item for the design meeting
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants