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

Layout of vector types #47

Merged
merged 8 commits into from
Nov 29, 2018
Merged

Layout of vector types #47

merged 8 commits into from
Nov 29, 2018

Conversation

gnzlbg
Copy link
Contributor

@gnzlbg gnzlbg commented Nov 18, 2018

Closes #38 .



* Should unions containing a vector type and any number of ZSTs also be vector
types? For example, should `MaybeUninit<Vector<T, N>>` also be a vector type?
Copy link
Member

Choose a reason for hiding this comment

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

Which consequences does it have to answer this with "no" or "yes"? I don't understand what "being a vector type" entails.

I would find it strange if this document said anything about unions; that should all fall out of the general union rules. In terms of layout, repr(C) unions have all their fields starting at offset 0 and hence if all but one variant are size-0-align-1, their layout (at least size and alignment) is identical to that of the only non-ZST field.

Copy link
Contributor Author

@gnzlbg gnzlbg Nov 19, 2018

Choose a reason for hiding this comment

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

I don't understand what "being a vector type" entails.

It affects the calling convention, e.g., when interfacing with C (vectors are not aggregates). So depending on what we decide here, one might be able to use MaybeUninit<Vector> when interfacing with C or not. Calling conventions are neither representation nor validity AFAICT, so I don't know when and where to discuss this, but we should not forget about it. It also affects what kind of optimizations LLVM can do, which do differ depending on whether MaybeUninit<Vector> is a "vector" or not.

I would find it strange if this document said anything about unions; that should all fall out of the general union rules.

Yes, this should be resolved more generally in the context of unions. MaybeUninit<T> is a general construct, and we might want it to be an aggregate only if T is an aggregate, but not if e.g. T is c_int.

This document should, at most, repeat what's mentioned about this somewhere else.

Copy link
Member

Choose a reason for hiding this comment

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

Ah so this is about ABI then. Yeah I have no idea.^^

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Nov 27, 2018

Note: I've opened rust-lang/stdarch#607 to require documenting not only the size but also the implementation-defined alignment of the x86 and x86_64 vector types.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Nov 29, 2018

So I made N a power-of-two. This does not break any code, and relaxing this is a backwards compatible change.

@gnzlbg gnzlbg merged commit fb2ef0c into rust-lang:master Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants