Repository navigation
Add safety section for intrinsic volatile operations - #166399
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| /// # Safety | ||
| /// | ||
| /// The safety requirements are consistent with [`copy`] | ||
| /// while the read and write behaviors are volatile, | ||
| /// which means it will not be optimized out unless size is equal to zero. |
There was a problem hiding this comment.
This is not correct. Volatile operations are complicated and have different (weaker) safety requirements.
We will document them properly if/when we ever expose these operations publicly. For internal-only docs, I don't think it is worth spending the effort.
There was a problem hiding this comment.
I understand. I read the definition of volatile in LLVM, but it doe not give a clear explanation about the behaviour of volatile operation. Maybe similar to read_volatile and write_volatile, the safety requirement needs rewriting.
| /// The safety requirements are consistent with [`copy_nonoverlapping`] | ||
| /// while the read and write behaviors are volatile, |
There was a problem hiding this comment.
This old text is in fact also wrong.
|
Thanks! For the unaligned ones, this looks good. But for the volatile copy intrinsics, I don't think this is correct. r? me |
|
Reminder, once the PR becomes ready for a review, use |
| /// This intrinsic does not have a stable counterpart. | ||
| /// # Safety | ||
| /// | ||
| /// The safety requirements are consistent with [`write_bytes`] while the write behavior is volatile, |
There was a problem hiding this comment.
This old text is also not correct for the same reason.
477056b to
8778c7d
Compare
|
I update this PR and only contains changes about (un)aligned ones. @rustbot ready |
|
Thanks. :) |
Add safety section for intrinsic volatile operations This PR adds safety section for volatile operations in `intrinsics/mod.rs`. I find that these apis lack safety comments. I refer to the format of `volatile_copy_nonoverlapping_memory` and `size_of_val`. For `volatile_copy_memory`, I think this api should follow the safety requirement of `ptr::copy`. For `unaligned_volatile_load(store)`, I add the text that they should refer to `read(write)_voaltile` but don't need to follow the align requirement. Thank you for your suggestion.
…uwer Rollup of 4 pull requests Successful merges: - #165538 (Supertraits returns Unnormalized) - #166033 (Abby: move span out of leaf region constraint) - #166399 (Add safety section for intrinsic volatile operations) - #166420 ([rustdoc] Fix search index generation: if crate content didn't change, it should generate the same search index)
…uwer Rollup of 8 pull requests Successful merges: - #166385 ([PERF] Inline some attribute parsing code) - #166013 (make `ReturnsVisitor` more accurate ) - #166033 (Abby: move span out of leaf region constraint) - #166088 (Make rigid alias invalidation explicit when transitioning to PostAnalysis) - #166365 (Drop references to codebuild) - #166399 (Add safety section for intrinsic volatile operations) - #166439 (remove some incorrect docs from volatile intrinsics) - #166445 (fix test enum-repr-abi)
Rollup merge of #166399 - yilin0518:fix_volatile, r=RalfJung Add safety section for intrinsic volatile operations This PR adds safety section for volatile operations in `intrinsics/mod.rs`. I find that these apis lack safety comments. I refer to the format of `volatile_copy_nonoverlapping_memory` and `size_of_val`. For `volatile_copy_memory`, I think this api should follow the safety requirement of `ptr::copy`. For `unaligned_volatile_load(store)`, I add the text that they should refer to `read(write)_voaltile` but don't need to follow the align requirement. Thank you for your suggestion.
…uwer Rollup of 8 pull requests Successful merges: - rust-lang/rust#166385 ([PERF] Inline some attribute parsing code) - rust-lang/rust#166013 (make `ReturnsVisitor` more accurate ) - rust-lang/rust#166033 (Abby: move span out of leaf region constraint) - rust-lang/rust#166088 (Make rigid alias invalidation explicit when transitioning to PostAnalysis) - rust-lang/rust#166365 (Drop references to codebuild) - rust-lang/rust#166399 (Add safety section for intrinsic volatile operations) - rust-lang/rust#166439 (remove some incorrect docs from volatile intrinsics) - rust-lang/rust#166445 (fix test enum-repr-abi)
This PR adds safety section for volatile operations in
intrinsics/mod.rs. I find that these apis lack safety comments. I refer to the format ofvolatile_copy_nonoverlapping_memoryandsize_of_val.For
volatile_copy_memory, I think this api should follow the safety requirement ofptr::copy.For
unaligned_volatile_load(store), I add the text that they should refer toread(write)_voaltilebut don't need to follow the align requirement.Thank you for your suggestion.