{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rfcs/issues/1484","labels_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1484/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1484/comments","events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1484/events","html_url":"https://github.com/rust-lang/rfcs/issues/1484","id":130324640,"number":1484,"title":"Move test::black_box to std and stabilize it","user":{"login":"SimonSapin","id":291359,"avatar_url":"https://avatars.githubusercontent.com/u/291359?v=3","gravatar_id":"","url":"https://api.github.com/users/SimonSapin","html_url":"https://github.com/SimonSapin","followers_url":"https://api.github.com/users/SimonSapin/followers","following_url":"https://api.github.com/users/SimonSapin/following{/other_user}","gists_url":"https://api.github.com/users/SimonSapin/gists{/gist_id}","starred_url":"https://api.github.com/users/SimonSapin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SimonSapin/subscriptions","organizations_url":"https://api.github.com/users/SimonSapin/orgs","repos_url":"https://api.github.com/users/SimonSapin/repos","events_url":"https://api.github.com/users/SimonSapin/events{/privacy}","received_events_url":"https://api.github.com/users/SimonSapin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rfcs/labels/T-libs","name":"T-libs","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-02-01T10:39:28Z","updated_at":"2016-02-01T16:57:50Z","closed_at":null,"body":"The `test` crate is not stable, and I’m not aware of plans to stabilize it soon. It’s probably better to spend some time experimenting on crates.io using `harness = false` in `Cargo.toml` (see https://github.com/rust-lang/cargo/issues/2305).\r\n\r\nI’ve extracted the test crate to eventually publish it separately and am removing usage of unstable features one by one. One of them is `asm`, used in:\r\n\r\n```rust\r\n/// A function that is opaque to the optimizer, to allow benchmarks to\r\n/// pretend to use outputs to assist in avoiding dead-code\r\n/// elimination.\r\n///\r\n/// This function is a no-op, and does not even read from `dummy`.\r\n#[cfg(not(all(target_os = \"nacl\", target_arch = \"le32\")))]\r\npub fn black_box<T>(dummy: T) -> T {\r\n    // we need to \"use\" the argument in some way LLVM can't\r\n    // introspect.\r\n    unsafe { asm!(\"\" : : \"r\"(&dummy)) }\r\n    dummy\r\n}\r\n#[cfg(all(target_os = \"nacl\", target_arch = \"le32\"))]\r\n#[inline(never)]\r\npub fn black_box<T>(dummy: T) -> T {\r\n    dummy\r\n}\r\n```\r\n\r\nIt’s an important part of benchmarking. Since `asm!` is not stable and also unlikely to be stable soon, I’d like to have `black_box` stabilized in `std`, as a building block for external test and benchmarking harnesses.\r\n\r\nI’m not sure what module it would go into. Maybe `std::time`?"},"comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments/178067045","html_url":"https://github.com/rust-lang/rfcs/issues/1484#issuecomment-178067045","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1484","id":178067045,"user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","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},"created_at":"2016-02-01T16:57:50Z","updated_at":"2016-02-01T16:57:50Z","body":"I don't think that we should stabilize `black_box` as it's currently \"just a hack that appears to work\". We don't really have any guarantees on behalf of LLVM nor do we really know what it does, it just emperically seems to not optimize things away. A solution like @huonw mentioned of a non-cross-crate function (e.g. something that forces codegen) would unfortunately have runtime overhead (which in theory this doesn't)."}}