{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/174042901","pull_request_review_id":103327273,"id":174042901,"diff_hunk":"@@ -0,0 +1,157 @@\n+- Feature Name: black_box-and-clobber\n+- Start Date: 2018-03-12\n+- RFC PR: (leave this empty)\n+- Rust Issue: (leave this empty)\n+\n+# Summary\n+[summary]: #summary\n+\n+This RFC adds two functions to `core::mem`: `black_box` and `clobber`, which are\n+mainly useful for writing benchmarks.\n+\n+# Motivation\n+[motivation]: #motivation\n+\n+The `black_box` and `clobber` functions are useful for writing synthetic\n+benchmarks where, due to the constrained nature of the benchmark, the compiler\n+is able to perform optimizations that wouldn't otherwise trigger in practice.\n+\n+The implementation of these functions is backend-specific and requires inline\n+assembly. Such that if the standard library does not provide them, the users are\n+required to use brittle workarounds on nightly.\n+\n+# Guide-level explanation\n+[guide-level-explanation]: #guide-level-explanation\n+\n+\n+## `mem::black_box`\n+\n+The function:\n+\n+```rust\n+pub fn black_box<T>(x: T) -> T;\n+```\n+\n+prevents the value `x` from being optimized away and flushes pending reads/writes\n+to memory. It does not prevent optimizations on the expression generating the\n+value `x` nor on the return value of the function. For\n+example ([`rust.godbolt.org`](https://godbolt.org/g/YP2GCJ)):\n+\n+```rust\n+fn foo(x: i32) -> i32{ \n+  mem::black_box(2 + x);\n+  3\n+}\n+let a = foo(2);\n+```\n+\n+Here, the compiler can simplify the expression `2 + x` into `2 + 2` and then\n+`4`, but it is not allowed to discard `4`. Instead, it must store `4` into a\n+register even though it is not used by anything afterwards.\n+\n+## `mem::clobber`\n+\n+The function\n+\n+```rust\n+pub fn clobber() -> ();\n+```\n+ \t \n+flushes all pending writes to memory. Memory managed by block scope objects must","path":"text/0000-bench-utils.md","position":60,"original_position":60,"commit_id":"ec42fd0b7fbc0448d1794bfecaa43621eab76814","original_commit_id":"ec42fd0b7fbc0448d1794bfecaa43621eab76814","user":{"login":"gnzlbg","id":904614,"avatar_url":"https://avatars0.githubusercontent.com/u/904614?v=4","gravatar_id":"","url":"https://api.github.com/users/gnzlbg","html_url":"https://github.com/gnzlbg","followers_url":"https://api.github.com/users/gnzlbg/followers","following_url":"https://api.github.com/users/gnzlbg/following{/other_user}","gists_url":"https://api.github.com/users/gnzlbg/gists{/gist_id}","starred_url":"https://api.github.com/users/gnzlbg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnzlbg/subscriptions","organizations_url":"https://api.github.com/users/gnzlbg/orgs","repos_url":"https://api.github.com/users/gnzlbg/repos","events_url":"https://api.github.com/users/gnzlbg/events{/privacy}","received_events_url":"https://api.github.com/users/gnzlbg/received_events","type":"User","site_admin":false},"body":"@nagisa the only thing that clobber should do is flush pending writes to memory. It doesn't need to require that the compiler reloads memory on reuse. Maybe the `volatile` `asm!` with  `memory` clobber is not the best way to implement that.","created_at":"2018-03-13T08:14:42Z","updated_at":"2018-03-13T08:14:42Z","html_url":"https://github.com/rust-lang/rfcs/pull/2360#discussion_r174042901","pull_request_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/2360","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/174042901"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/2360#discussion_r174042901"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/2360"}},"in_reply_to_id":173893410},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/2360","id":174438410,"html_url":"https://github.com/rust-lang/rfcs/pull/2360","diff_url":"https://github.com/rust-lang/rfcs/pull/2360.diff","patch_url":"https://github.com/rust-lang/rfcs/pull/2360.patch","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/2360","number":2360,"state":"open","locked":false,"title":"RFC: mem::black_box and mem::clobber","user":{"login":"gnzlbg","id":904614,"avatar_url":"https://avatars0.githubusercontent.com/u/904614?v=4","gravatar_id":"","url":"https://api.github.com/users/gnzlbg","html_url":"https://github.com/gnzlbg","followers_url":"https://api.github.com/users/gnzlbg/followers","following_url":"https://api.github.com/users/gnzlbg/following{/other_user}","gists_url":"https://api.github.com/users/gnzlbg/gists{/gist_id}","starred_url":"https://api.github.com/users/gnzlbg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnzlbg/subscriptions","organizations_url":"https://api.github.com/users/gnzlbg/orgs","repos_url":"https://api.github.com/users/gnzlbg/repos","events_url":"https://api.github.com/users/gnzlbg/events{/privacy}","received_events_url":"https://api.github.com/users/gnzlbg/received_events","type":"User","site_admin":false},"body":"Adds `black_box` and `clobber` functions to `core::mem`.\r\n\r\n[Rendered](https://github.com/gnzlbg/rfcs/blob/black_box/text/0000-bench-utils.md).","created_at":"2018-03-12T17:20:44Z","updated_at":"2018-03-13T08:14:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e19970e1df3ad32326cb17cff5d7515580c5e196","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":211667901,"url":"https://api.github.com/repos/rust-lang/rfcs/labels/T-libs","name":"T-libs","color":"bfd4f2","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/2360/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/2360/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/2360/comments","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/ec42fd0b7fbc0448d1794bfecaa43621eab76814","head":{"label":"gnzlbg:black_box","ref":"black_box","sha":"ec42fd0b7fbc0448d1794bfecaa43621eab76814","user":{"login":"gnzlbg","id":904614,"avatar_url":"https://avatars0.githubusercontent.com/u/904614?v=4","gravatar_id":"","url":"https://api.github.com/users/gnzlbg","html_url":"https://github.com/gnzlbg","followers_url":"https://api.github.com/users/gnzlbg/followers","following_url":"https://api.github.com/users/gnzlbg/following{/other_user}","gists_url":"https://api.github.com/users/gnzlbg/gists{/gist_id}","starred_url":"https://api.github.com/users/gnzlbg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnzlbg/subscriptions","organizations_url":"https://api.github.com/users/gnzlbg/orgs","repos_url":"https://api.github.com/users/gnzlbg/repos","events_url":"https://api.github.com/users/gnzlbg/events{/privacy}","received_events_url":"https://api.github.com/users/gnzlbg/received_events","type":"User","site_admin":false},"repo":{"id":95458297,"name":"rfcs","full_name":"gnzlbg/rfcs","owner":{"login":"gnzlbg","id":904614,"avatar_url":"https://avatars0.githubusercontent.com/u/904614?v=4","gravatar_id":"","url":"https://api.github.com/users/gnzlbg","html_url":"https://github.com/gnzlbg","followers_url":"https://api.github.com/users/gnzlbg/followers","following_url":"https://api.github.com/users/gnzlbg/following{/other_user}","gists_url":"https://api.github.com/users/gnzlbg/gists{/gist_id}","starred_url":"https://api.github.com/users/gnzlbg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnzlbg/subscriptions","organizations_url":"https://api.github.com/users/gnzlbg/orgs","repos_url":"https://api.github.com/users/gnzlbg/repos","events_url":"https://api.github.com/users/gnzlbg/events{/privacy}","received_events_url":"https://api.github.com/users/gnzlbg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gnzlbg/rfcs","description":"RFCs for changes to Rust","fork":true,"url":"https://api.github.com/repos/gnzlbg/rfcs","forks_url":"https://api.github.com/repos/gnzlbg/rfcs/forks","keys_url":"https://api.github.com/repos/gnzlbg/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gnzlbg/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gnzlbg/rfcs/teams","hooks_url":"https://api.github.com/repos/gnzlbg/rfcs/hooks","issue_events_url":"https://api.github.com/repos/gnzlbg/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/gnzlbg/rfcs/events","assignees_url":"https://api.github.com/repos/gnzlbg/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/gnzlbg/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/gnzlbg/rfcs/tags","blobs_url":"https://api.github.com/repos/gnzlbg/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gnzlbg/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gnzlbg/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/gnzlbg/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gnzlbg/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/gnzlbg/rfcs/languages","stargazers_url":"https://api.github.com/repos/gnzlbg/rfcs/stargazers","contributors_url":"https://api.github.com/repos/gnzlbg/rfcs/contributors","subscribers_url":"https://api.github.com/repos/gnzlbg/rfcs/subscribers","subscription_url":"https://api.github.com/repos/gnzlbg/rfcs/subscription","commits_url":"https://api.github.com/repos/gnzlbg/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/gnzlbg/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/gnzlbg/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/gnzlbg/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/gnzlbg/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/gnzlbg/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gnzlbg/rfcs/merges","archive_url":"https://api.github.com/repos/gnzlbg/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gnzlbg/rfcs/downloads","issues_url":"https://api.github.com/repos/gnzlbg/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/gnzlbg/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/gnzlbg/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/gnzlbg/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gnzlbg/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/gnzlbg/rfcs/releases{/id}","deployments_url":"https://api.github.com/repos/gnzlbg/rfcs/deployments","created_at":"2017-06-26T14:57:04Z","updated_at":"2017-06-25T15:26:08Z","pushed_at":"2018-03-12T17:58:30Z","git_url":"git://github.com/gnzlbg/rfcs.git","ssh_url":"git@github.com:gnzlbg/rfcs.git","clone_url":"https://github.com/gnzlbg/rfcs.git","svn_url":"https://github.com/gnzlbg/rfcs","homepage":"","size":5363,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"fd70ea35fb60a53c74d1210b1d190ce0a9ef8345","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars1.githubusercontent.com/u/5430905?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":17527989,"name":"rfcs","full_name":"rust-lang/rfcs","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars1.githubusercontent.com/u/5430905?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/rfcs","description":"RFCs for changes to Rust","fork":false,"url":"https://api.github.com/repos/rust-lang/rfcs","forks_url":"https://api.github.com/repos/rust-lang/rfcs/forks","keys_url":"https://api.github.com/repos/rust-lang/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rfcs/teams","hooks_url":"https://api.github.com/repos/rust-lang/rfcs/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rfcs/events","assignees_url":"https://api.github.com/repos/rust-lang/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rfcs/tags","blobs_url":"https://api.github.com/repos/rust-lang/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rfcs/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rfcs/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rfcs/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rfcs/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rfcs/subscription","commits_url":"https://api.github.com/repos/rust-lang/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rfcs/merges","archive_url":"https://api.github.com/repos/rust-lang/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rfcs/downloads","issues_url":"https://api.github.com/repos/rust-lang/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rfcs/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/rfcs/deployments","created_at":"2014-03-07T21:29:00Z","updated_at":"2018-03-13T04:56:56Z","pushed_at":"2018-03-12T19:33:34Z","git_url":"git://github.com/rust-lang/rfcs.git","ssh_url":"git@github.com:rust-lang/rfcs.git","clone_url":"https://github.com/rust-lang/rfcs.git","svn_url":"https://github.com/rust-lang/rfcs","homepage":"http://rust-lang.github.io/rfcs/","size":18739,"stargazers_count":1378,"watchers_count":1378,"language":"Shell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":576,"mirror_url":null,"archived":false,"open_issues_count":715,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":576,"open_issues":715,"watchers":1378,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/2360"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/2360"},"issue":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/2360"},"comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/2360/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/2360/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/2360/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rfcs/statuses/ec42fd0b7fbc0448d1794bfecaa43621eab76814"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"gnzlbg"}}