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

make various intrinsics work in const contexts #50579

Closed
wants to merge 2 commits into from

Conversation

Gankra
Copy link
Contributor

@Gankra Gankra commented May 9, 2018

These intrinsics are fairly inoffensive, and marking them as usable in const contexts doesn't make them any more usable to stable users while making them available to the stdlib at our own discretion. Doing this sooner rather than later minimizes the amount of cfg(stage0) shenanigans that will be required.

Mostly this just avoids enum, dst, and pointer intrinsics.

The implementations are copied from miri verbatim.

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 9, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
travis_fold:end:system_info

Network availability confirmed.
Running apt-get update by default has been disabled.
You can opt into running apt-get update by setting this in your .travis.yml file:
  apt:
travis_fold:start:git.checkout
travis_time:start:00791972
$ git clone --depth=2 https://github.com/rust-lang/rust.git rust-lang/rust
---
[00:57:20] ....................................................................................................
[00:57:26] ....................................................................................................
[00:57:32] ....................................................................................................
[00:57:39] ....................................................................................................
[00:57:45] ...F................i............................................................ii.iii.............
[00:57:58] ..........i..............................i..........................................................
[00:58:04] ....................................................................................................
[00:58:10] ............i.......................................................................................
[00:58:16] ....................................................................................................
---
[01:00:10] failures:
[01:00:10] 
[01:00:10] ---- [compile-fail] compile-fail/const-fn-not-safe-for-const.rs stdout ----
[01:00:10]  
[01:00:10] error: /checkout/src/test/compile-fail/const-fn-not-safe-for-const.rs:20: expected error not found: E0015
[01:00:10] 
[01:00:10] error: 0 unexpected errors found, 1 expected errors not found
[01:00:10] status: exit code: 101
[01:00:10] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/compile-fail/const-fn-not-safe-for-const.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/const-fn-not-safe-for-const.stage2-x86_64-unknown-linux-gnu" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/const-fn-not-safe-for-const.stage2-x86_64-unknown-linux-gnu.aux" "-A" "unused"
[01:00:10] not found errors (from test file): [
[01:00:10]     Error {
[01:00:10]         line_num: 20,
[01:00:10]         kind: Some(
[01:00:10]         ),
[01:00:10]         ),
[01:00:10]         msg: "E0015"
[01:00:10] ]
[01:00:10] 
[01:00:10] thread '[compile-fail] compile-fail/const-fn-not-safe-for-const.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:1312:13
[01:00:10] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[01:00:10] 
[01:00:10] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:492:22
[01:00:10] 
[01:00:10] 
[01:00:10] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/compile-fail" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "compile-fail" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "3.9.1\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:00:10] 
[01:00:10] 
[01:00:10] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:00:10] Build completed unsuccessfully in 0:16:34
[01:00:10] Build completed unsuccessfully in 0:16:34
[01:00:10] make: *** [check] Error 1
[01:00:10] Makefile:58: recipe for target 'check' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:088c003a
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@oli-obk
Copy link
Contributor

oli-obk commented May 9, 2018

Would you be so kind and also open a PR against miri removing all those that are added here?

I think the only controversial one might be transmute, but you can implement a bad version of it with unions, so....

This is related to the const fn discussion, but since this PR is not actually stabilizing anything, just making already unstable intrinsics usable in consts, I see no reason not to do this. On the contrary, this allows us to test out things like transmute and discuss the behaviour we expect from it in consts

@Gankra
Copy link
Contributor Author

Gankra commented May 9, 2018

Minor point: this doesn't constify bit_reverse because that's still unstable in the stdlib and I'm not sure what the bootstrap implications are for that.

@petrochenkov
Copy link
Contributor

r? @oli-obk


fn random() -> u32 { 0 }

const fn sub(x: &u32) -> usize {
unsafe { transmute(x) } //~ ERROR E0015
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so... I have a bad feeling about these intrinsics. The fact that this change was necessary makes me wonder whether the intrinsics have become insta-stable (because e.g. std::mem::transmute is the intrinsic directly, without a wrapper function).

Please add tests that make sure that each intrinsic's stable version does not become const fn on stable Rust.

It's probably best to add some tests that check whether the intrinsics work with feature gates, too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should probably be a #[const_unstable_... attribute on the version of transmute that's marked as stable, and somehow have that checked in qualify_consts.

@bors
Copy link
Contributor

bors commented May 12, 2018

☔ The latest upstream changes (presumably #50249) made this pull request unmergeable. Please resolve the merge conflicts.

@TimNN TimNN added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 15, 2018
@pietroalbini
Copy link
Member

Ping from triage @gankro! It's been a while since we heard from you, will you have time to work on this again soon?

@pietroalbini
Copy link
Member

Thank you for this PR @gankro! Unfortunately we haven't heard from you on this in a while, so I'm closing the PR to keep things tidy. Don't worry though, if you'll have time again in the future please reopen this PR, we'll be happy to review it again!

@pietroalbini pietroalbini added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants