{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/47975","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/47975/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/47975/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/47975/events","html_url":"https://github.com/rust-lang/rust/pull/47975","id":294030239,"number":47975,"title":"Add safe volatile functions.","user":{"login":"clarcharr","id":15850505,"avatar_url":"https://avatars1.githubusercontent.com/u/15850505?v=4","gravatar_id":"","url":"https://api.github.com/users/clarcharr","html_url":"https://github.com/clarcharr","followers_url":"https://api.github.com/users/clarcharr/followers","following_url":"https://api.github.com/users/clarcharr/following{/other_user}","gists_url":"https://api.github.com/users/clarcharr/gists{/gist_id}","starred_url":"https://api.github.com/users/clarcharr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clarcharr/subscriptions","organizations_url":"https://api.github.com/users/clarcharr/orgs","repos_url":"https://api.github.com/users/clarcharr/repos","events_url":"https://api.github.com/users/clarcharr/events{/privacy}","received_events_url":"https://api.github.com/users/clarcharr/received_events","type":"User","site_admin":false},"labels":[{"id":583426710,"url":"https://api.github.com/repos/rust-lang/rust/labels/S-waiting-on-review","name":"S-waiting-on-review","color":"d3dddd","default":false}],"state":"open","locked":false,"assignee":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars1.githubusercontent.com/u/64996?v=4","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"assignees":[{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars1.githubusercontent.com/u/64996?v=4","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2018-02-02T21:34:08Z","updated_at":"2018-02-03T12:54:16Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/47975","html_url":"https://github.com/rust-lang/rust/pull/47975","diff_url":"https://github.com/rust-lang/rust/pull/47975.diff","patch_url":"https://github.com/rust-lang/rust/pull/47975.patch"},"body":"This adds safe equivalents of `read_volatile` and `write_volatile` to `std::mem`, using references instead of pointers.\r\n\r\nThe `move_opaque` and `drop_opaque` functions are the `value_fence` and `compute_and_drop` mentioned in [rust-lang/rfcs#1484 (comment)](https://github.com/rust-lang/rfcs/issues/1484#issuecomment-362672337). `move_opaque` is roughly equivalent to the unstable `test::black_box`.\r\n\r\n`copy_opaque` and `replace_opaque` are added for completeness, as they are useful equivalents `read_volatile` and `write_volatile` that will work in most cases. This means that volatile reads and writes don't have to be annotated with `unsafe` on each occurrence, and that the programmer simply has to verify that the pointers are correct and cast them to references (probably with `'static` lifetime).\r\n\r\nIf an RFC is required to add these, I'd be willing to write one. However, I think they're reasonable enough to have a PR for now."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/362804102","html_url":"https://github.com/rust-lang/rust/pull/47975#issuecomment-362804102","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/47975","id":362804102,"user":{"login":"rkruppe","id":2311707,"avatar_url":"https://avatars2.githubusercontent.com/u/2311707?v=4","gravatar_id":"","url":"https://api.github.com/users/rkruppe","html_url":"https://github.com/rkruppe","followers_url":"https://api.github.com/users/rkruppe/followers","following_url":"https://api.github.com/users/rkruppe/following{/other_user}","gists_url":"https://api.github.com/users/rkruppe/gists{/gist_id}","starred_url":"https://api.github.com/users/rkruppe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkruppe/subscriptions","organizations_url":"https://api.github.com/users/rkruppe/orgs","repos_url":"https://api.github.com/users/rkruppe/repos","events_url":"https://api.github.com/users/rkruppe/events{/privacy}","received_events_url":"https://api.github.com/users/rkruppe/received_events","type":"User","site_admin":false},"created_at":"2018-02-03T12:54:16Z","updated_at":"2018-02-03T12:54:16Z","author_association":"CONTRIBUTOR","body":"I share the doubts about how useful a volatile load through a safe reference is. I don't believe it's likely to be miscompiled -- in practice LLVM will probably let `volatile` take precedence over any other information we give it, and there might be some way to semantically make sense of volatile accesses to `UnsafeCell` memory. But without an UnsafeCell involved it's inconsistent to create a `&T` reference (which implies no mutation of the referent for some duration) despite the referent beig mutated from some other source. I can think of a few other use cases and exculpatory circumstances that make this not UB and just a very hairy affair, but I believe the danger of wrongly implying safe references without interior mutability can be combined with \"external\" mutation outweight any (dubious, IMO) safety benefit for the niche use cases.\r\n\r\nI also have some doubts about the robustness of the functions that are intended to partially replace `black_box` -- I haven't been able to formulate them precisely, but basically a volatile operation has *much* less power as an optimization barrier than inline asm with side effects, so it seems much trickier to ensure that it's actually doing its job (as the documentation already concedes!)."}}
{"actor":{"display_login":"rkruppe"}}