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

Clarify std::mem-docs wrt host/target #81206

Open
lukaslueg opened this issue Jan 20, 2021 · 2 comments
Open

Clarify std::mem-docs wrt host/target #81206

lukaslueg opened this issue Jan 20, 2021 · 2 comments
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools A-layout Area: Memory layout of types C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lukaslueg
Copy link
Contributor

Functions like std::mem::align_of (and also parts of std::alloc::Layout) which are const can be used to initialize other constants and, soon, types like [u8; { std::mem::align_of::<String>() }]. As far as I can see the docs currently do not explicitly make it clear that the compiler guarantees (including future versions) that the return values of those functions are valid for the target-platform and not for the host-platform, even in a const-context.

This is probably everybody's expectation. If this behavior is guaranteed, the docs should mention that, though.

@nagisa
Copy link
Member

nagisa commented Jan 21, 2021

host vs target vs build is a concern build system needs to deal when selecting toolchains, libraries and flags to use. Such a distinction doesn't exist within the toolchain itself, however… if you ignore accidental breakage once in a while due to failures to normalize for byte order when handling the libraries, that is.

With that in mind I feel like documenting this on potentially every const function is excessive. It might make sense to put a line that states something along these lines in the reference somewhere, however.

@lukaslueg
Copy link
Contributor Author

@nagisa I agree. My concern came up specifically with std::mem::align_of, where one might wonder if const foo: usize = std::mem::align_of::<String>() is String's alignment on the target-platform or it's alignment on the host-platform, which is definitely different.

@camelid camelid added A-layout Area: Memory layout of types A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools A-layout Area: Memory layout of types C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants