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

Enable `loop` and `while` in constants behind a feature flag #67216

Merged
merged 19 commits into from Dec 15, 2019

Conversation

@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Dec 11, 2019

This PR is an initial implementation of #52000. It adds a const_loop feature gate, which allows while and loop expressions through both HIR and MIR const-checkers if enabled. for expressions remain forbidden by the HIR const-checker, since they desugar to a call to IntoIterator::into_iter, which will be rejected anyways.

while loops also require #![feature(const_if_match)], since they have a conditional built into them. The diagnostics from the HIR const checker will suggest this to the user.

r? @oli-obk
cc @rust-lang/wg-const-eval

@ecstatic-morse

This comment has been minimized.

Copy link
Contributor Author

ecstatic-morse commented Dec 11, 2019

cc #66946. This needn't be blocked on my changes to the infinite loop detector or vice versa, but having loop will make invoking the detector a lot easier. It's possible we want to add a #![rustc_const_eval_iteration_limit] attribute before this PR lands that could, e.g., be set to -1 to disable the loop detector entirely (see #67217).

src/librustc_passes/check_const.rs Show resolved Hide resolved
src/librustc_feature/active.rs Outdated Show resolved Hide resolved
src/librustc_passes/check_const.rs Outdated Show resolved Hide resolved
src/librustc_passes/check_const.rs Show resolved Hide resolved
src/test/ui/consts/control-flow/loop.rs Outdated Show resolved Hide resolved
@Centril

This comment has been minimized.

Copy link
Member

Centril commented Dec 11, 2019

cc #66946. This needn't be blocked on my changes to the infinite loop detector or vice versa, but having loop will make invoking the detector a lot easier. It's possible we want to add a #![rustc_const_eval_iteration_limit] attribute before this PR lands that could, e.g., be set to -1 to disable the loop detector entirely (see #67217).

These seem independent to me and I would prefer landing this PR before beta branches so that we can get this into the new bootstrap compiler.

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Dec 11, 2019

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, 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.
2019-12-11T06:25:09.8046464Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-12-11T06:25:09.8231065Z ##[command]git config gc.auto 0
2019-12-11T06:25:09.8315842Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-12-11T06:25:09.8386794Z ##[command]git config --get-all http.proxy
2019-12-11T06:25:09.8583287Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/67216/merge:refs/remotes/pull/67216/merge
---
2019-12-11T07:22:44.4095113Z .................................................................................................... 1600/9344
2019-12-11T07:22:48.8726347Z .................................................................................................... 1700/9344
2019-12-11T07:23:00.7895328Z ....................................................i............................................... 1800/9344
2019-12-11T07:23:08.6971966Z .................................................................................................... 1900/9344
2019-12-11T07:23:22.4190209Z .....................................iiiii.......................................................... 2000/9344
2019-12-11T07:23:32.3360669Z .................................................................................................... 2200/9344
2019-12-11T07:23:35.2428103Z .................................................................................................... 2300/9344
2019-12-11T07:23:38.9662181Z .................................................................................................... 2400/9344
2019-12-11T07:24:00.2300196Z .................................................................................................... 2500/9344
---
2019-12-11T07:26:35.4430591Z ........................................i...............i........................................... 4800/9344
2019-12-11T07:26:44.8943617Z .................................................................................................... 4900/9344
2019-12-11T07:26:51.1978166Z ....................................................................................i............... 5000/9344
2019-12-11T07:26:57.0367438Z .................................................................................................... 5100/9344
2019-12-11T07:27:06.6304215Z ..................................................ii.ii...........i................................. 5200/9344
2019-12-11T07:27:15.4615966Z .................................................................................................... 5400/9344
2019-12-11T07:27:25.2946390Z .................................................................................................... 5500/9344
2019-12-11T07:27:32.1600930Z .................................i.................................................................. 5600/9344
2019-12-11T07:27:38.4133303Z .................................................................................................... 5700/9344
2019-12-11T07:27:38.4133303Z .................................................................................................... 5700/9344
2019-12-11T07:27:49.6759065Z .................................................................................................... 5800/9344
2019-12-11T07:28:00.0590115Z ...................ii...i..ii...........i........................................................... 5900/9344
2019-12-11T07:28:17.4048134Z .................................................................................................... 6100/9344
2019-12-11T07:28:25.4298357Z .................................................................................................... 6200/9344
2019-12-11T07:28:25.4298357Z .................................................................................................... 6200/9344
2019-12-11T07:28:38.6049419Z ...........................................i..ii.................................................... 6300/9344
2019-12-11T07:28:59.7023575Z .................................................................................................... 6500/9344
2019-12-11T07:29:01.6629146Z ...............i.................................................................................... 6600/9344
2019-12-11T07:29:03.8304016Z .................................................................................................... 6700/9344
2019-12-11T07:29:06.2975210Z ......i............................................................................................. 6800/9344
---
2019-12-11T07:30:37.1115072Z .................................................................................................... 7400/9344
2019-12-11T07:30:41.8103764Z .................................................................................................... 7500/9344
2019-12-11T07:30:48.4605600Z .................................................................................................... 7600/9344
2019-12-11T07:30:58.1182216Z .................................................................................................... 7700/9344
2019-12-11T07:31:03.9660700Z ......................iiii.......................................................................... 7800/9344
2019-12-11T07:31:17.3581140Z .................................................................................................... 8000/9344
2019-12-11T07:31:27.1905281Z .................................................................................................... 8100/9344
2019-12-11T07:31:39.3589691Z .................................................................................................... 8200/9344
2019-12-11T07:31:46.1769836Z .................................................................................................... 8300/9344
---
2019-12-11T07:33:55.9073411Z  finished in 5.679
2019-12-11T07:33:55.9073690Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-12-11T07:33:55.9433400Z 
2019-12-11T07:33:55.9433550Z running 165 tests
2019-12-11T07:33:58.8588473Z iiii......i.......ii..iiii...i.............................i..i..................i....i............i 100/165
2019-12-11T07:34:00.8922042Z .i.i...iii..ii.iiiii......................iii............ii......
2019-12-11T07:34:00.8926361Z 
2019-12-11T07:34:00.8932326Z  finished in 5.123
2019-12-11T07:34:00.9105816Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-12-11T07:34:01.0680359Z 
---
2019-12-11T07:34:02.9283618Z  finished in 2.017
2019-12-11T07:34:02.9467260Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-12-11T07:34:03.1023235Z 
2019-12-11T07:34:03.1023373Z running 9 tests
2019-12-11T07:34:03.1024122Z iiiiiiiii
2019-12-11T07:34:03.1041636Z 
2019-12-11T07:34:03.1050679Z  finished in 0.157
2019-12-11T07:34:03.1218316Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-12-11T07:34:03.2864183Z 
---
2019-12-11T07:34:21.2397060Z  finished in 18.118
2019-12-11T07:34:21.2601123Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-12-11T07:34:21.4288096Z 
2019-12-11T07:34:21.4288433Z running 124 tests
2019-12-11T07:34:44.4431747Z .iiiii..ii.....i..i...i..i.i.i..i..i..iii....ii.ii....ii..........iiii..........i.....i..ii.......ii 100/124
2019-12-11T07:34:48.2487073Z .i.iii.....iiiiii.....ii
2019-12-11T07:34:48.2489216Z 
2019-12-11T07:34:48.2492876Z  finished in 26.989
2019-12-11T07:34:48.2500970Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-12-11T07:34:48.2501709Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-12-11T07:45:36.3896007Z 
2019-12-11T07:45:36.3901393Z    Doc-tests core
2019-12-11T07:45:40.5473658Z 
2019-12-11T07:45:40.5474900Z running 2435 tests
2019-12-11T07:45:49.0418661Z ......iiiii......................................................................................... 100/2435
2019-12-11T07:46:06.8215264Z .................................................................................................... 300/2435
2019-12-11T07:46:16.6557766Z ..............i..................................................................................... 400/2435
2019-12-11T07:46:16.6557766Z ..............i..................................................................................... 400/2435
2019-12-11T07:46:25.2606145Z ..............................................................i..i..................iiii............ 500/2435
2019-12-11T07:46:40.4900507Z .................................................................................................... 700/2435
2019-12-11T07:46:48.5207467Z .................................................................................................... 800/2435
2019-12-11T07:46:56.6257105Z .................................................................................................... 900/2435
2019-12-11T07:47:04.6509339Z .................................................................................................... 1000/2435
---
2019-12-11T07:50:34.4617454Z 
2019-12-11T07:50:34.4618989Z running 1003 tests
2019-12-11T07:50:51.0303020Z i................................................................................................... 100/1003
2019-12-11T07:51:00.2643394Z .................................................................................................... 200/1003
2019-12-11T07:51:06.9575330Z ..................iii......i......i...i......i...................................................... 300/1003
2019-12-11T07:51:11.4302548Z .................................................................................................... 400/1003
2019-12-11T07:51:17.7648069Z ..........................................i..i.....................................ii............... 500/1003
2019-12-11T07:51:29.6938714Z .................................................................................................... 700/1003
2019-12-11T07:51:29.6938714Z .................................................................................................... 700/1003
2019-12-11T07:51:35.7133983Z .............................iiii................................................................... 800/1003
2019-12-11T07:51:48.7486522Z .................................................................................................... 900/1003
2019-12-11T07:51:55.0615993Z ...................................................iiii............................................. 1000/1003
2019-12-11T07:51:55.1599438Z test result: ok. 983 passed; 0 failed; 20 ignored; 0 measured; 0 filtered out
2019-12-11T07:51:55.1599471Z 
2019-12-11T07:51:55.1686660Z  finished in 168.022
2019-12-11T07:51:55.1702175Z Testing term stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---
2019-12-11T08:08:24.1950206Z 9  | |         }
2019-12-11T08:08:24.1950247Z 10 | |     }
2019-12-11T08:08:24.1950287Z    | |_____^
2019-12-11T08:08:24.1950338Z    |
2019-12-11T08:08:24.1950741Z    = note: for more information, see ***/issues/52000
2019-12-11T08:08:24.1950946Z 
2019-12-11T08:08:24.1950993Z error[E0658]: `if` is not allowed in a `const`
2019-12-11T08:08:24.1951238Z  --> /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md:13331:9
2019-12-11T08:08:24.1951279Z   |
2019-12-11T08:08:24.1951279Z   |
2019-12-11T08:08:24.1951326Z 7 | /         if x == 4 {
2019-12-11T08:08:24.1951370Z 8 | |             break;
2019-12-11T08:08:24.1951407Z 9 | |         }
2019-12-11T08:08:24.1951450Z   | |_________^
2019-12-11T08:08:24.1951484Z   |
2019-12-11T08:08:24.1951739Z   = note: for more information, see ***/issues/49146
2019-12-11T08:08:24.1951802Z   = help: add `#![feature(const_if_match)]` to the crate attributes to enable
2019-12-11T08:08:24.1951872Z error: aborting due to 2 previous errors
2019-12-11T08:08:24.1951899Z 
2019-12-11T08:08:24.1952265Z For more information about this error, try `rustc --explain E0658`.
2019-12-11T08:08:24.1952265Z For more information about this error, try `rustc --explain E0658`.
2019-12-11T08:08:24.1952323Z Some expected error codes were not found: ["E0744"]
2019-12-11T08:08:24.1952388Z failures:
2019-12-11T08:08:24.1952712Z     /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md - Rust_Compiler_Error_Index::E0744 (line 13326)
2019-12-11T08:08:24.1952746Z 
2019-12-11T08:08:24.1952791Z test result: FAILED. 797 passed; 1 failed; 28 ignored; 0 measured; 0 filtered out
---
2019-12-11T08:08:24.1953436Z   local time: Wed Dec 11 08:08:24 UTC 2019
2019-12-11T08:08:24.4589432Z   network time: Wed, 11 Dec 2019 08:08:24 GMT
2019-12-11T08:08:24.4589547Z == end clock drift check ==
2019-12-11T08:08:25.9599053Z 
2019-12-11T08:08:25.9726573Z ##[error]Bash exited with code '1'.
2019-12-11T08:08:25.9761020Z ##[section]Starting: Checkout
2019-12-11T08:08:25.9762667Z ==============================================================================
2019-12-11T08:08:25.9762717Z Task         : Get sources
2019-12-11T08:08:25.9762792Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

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)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Dec 11, 2019

The job mingw-check of your PR failed (pretty log, 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.
2019-12-11T18:42:57.9089763Z ========================== Starting Command Output ===========================
2019-12-11T18:42:57.9095227Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/4a3a19bd-72f1-48b3-bfb8-33d41b9f1ace.sh
2019-12-11T18:42:57.9095488Z 
2019-12-11T18:42:57.9099603Z ##[section]Finishing: Disable git automatic line ending conversion
2019-12-11T18:42:57.9106155Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/67216/merge to s
2019-12-11T18:42:57.9108317Z Task         : Get sources
2019-12-11T18:42:57.9108352Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2019-12-11T18:42:57.9108385Z Version      : 1.0.0
2019-12-11T18:42:57.9108464Z Author       : Microsoft
---
2019-12-11T18:43:00.2441862Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-12-11T18:43:01.0241937Z ##[command]git config gc.auto 0
2019-12-11T18:43:01.0244568Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-12-11T18:43:01.0246695Z ##[command]git config --get-all http.proxy
2019-12-11T18:43:01.0254499Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/67216/merge:refs/remotes/pull/67216/merge
---
2019-12-11T18:52:10.6069709Z 
2019-12-11T18:52:10.6116623Z error[E0425]: cannot find value `gates` in this scope
2019-12-11T18:52:10.6116921Z    --> src/librustc_passes/check_const.rs:169:46
2019-12-11T18:52:10.6117193Z     |
2019-12-11T18:52:10.6117513Z 169 |             &[gate @ sym::const_if_match] if gates.contains(&sym::const_loop) => {
2019-12-11T18:52:10.6118060Z     |                                              ^^^^^ help: a local variable with a similar name exists: `gate`
2019-12-11T18:52:11.1590589Z error: aborting due to 2 previous errors
2019-12-11T18:52:11.1590679Z 
2019-12-11T18:52:11.1594531Z For more information about this error, try `rustc --explain E0425`.
2019-12-11T18:52:11.1758195Z error: could not compile `rustc_passes`.
---
2019-12-11T18:52:29.6910304Z   local time: Wed Dec 11 18:52:29 UTC 2019
2019-12-11T18:52:29.9709226Z   network time: Wed, 11 Dec 2019 18:52:29 GMT
2019-12-11T18:52:29.9709494Z == end clock drift check ==
2019-12-11T18:52:31.4202197Z 
2019-12-11T18:52:31.4292907Z ##[error]Bash exited with code '1'.
2019-12-11T18:52:31.4307660Z ##[section]Finishing: Run build
2019-12-11T18:52:31.4361438Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/67216/merge to s
2019-12-11T18:52:31.4363914Z Task         : Get sources
2019-12-11T18:52:31.4363962Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2019-12-11T18:52:31.4364010Z Version      : 1.0.0
2019-12-11T18:52:31.4364070Z Author       : Microsoft
2019-12-11T18:52:31.4364070Z Author       : Microsoft
2019-12-11T18:52:31.4364117Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2019-12-11T18:52:31.4364167Z ==============================================================================
2019-12-11T18:52:32.0053849Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2019-12-11T18:52:32.0103078Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/67216/merge to s
2019-12-11T18:52:32.0234939Z Start cleaning up orphan processes.
2019-12-11T18:52:32.0366463Z Terminate orphan process: pid (3537) (python)
2019-12-11T18:52:32.2165299Z ##[section]Finishing: Finalize Job
2019-12-11T18:52:32.2237085Z ##[section]Finishing: Linux mingw-check

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)

@ecstatic-morse ecstatic-morse force-pushed the ecstatic-morse:const-loop branch from 4e0ea6e to 93fd93c Dec 11, 2019
@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Dec 11, 2019

All lgtm, I'd just like @Centril to sign off on the fact that both control flow and loops can be used on stable const fn (only in libstd) without any additional annotation

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Dec 11, 2019

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, 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.
2019-12-11T21:10:25.0576372Z ========================== Starting Command Output ===========================
2019-12-11T21:10:25.0577446Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/8ec7e3d2-1471-464b-b41b-8547d959aac6.sh
2019-12-11T21:10:25.0577470Z 
2019-12-11T21:10:25.0579392Z ##[section]Finishing: Disable git automatic line ending conversion
2019-12-11T21:10:25.0584179Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/67216/merge to s
2019-12-11T21:10:25.0585495Z Task         : Get sources
2019-12-11T21:10:25.0585565Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2019-12-11T21:10:25.0585591Z Version      : 1.0.0
2019-12-11T21:10:25.0585617Z Author       : Microsoft
---
2019-12-11T21:10:26.8567266Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-12-11T21:10:26.8734435Z ##[command]git config gc.auto 0
2019-12-11T21:10:26.8795225Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-12-11T21:10:26.9094810Z ##[command]git config --get-all http.proxy
2019-12-11T21:10:26.9222072Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/67216/merge:refs/remotes/pull/67216/merge
---
2019-12-11T21:55:08.6762229Z .................................................................................................... 1600/9354
2019-12-11T21:55:12.0186866Z ....F............................................................................................... 1700/9354
2019-12-11T21:55:21.0342451Z ........................................................i........................................... 1800/9354
2019-12-11T21:55:27.0887578Z .................................................................................................... 1900/9354
2019-12-11T21:55:37.4751261Z .........................................iiiii...................................................... 2000/9354
2019-12-11T21:55:44.8923460Z .................................................................................................... 2200/9354
2019-12-11T21:55:46.6523778Z .................................................................................................... 2300/9354
2019-12-11T21:55:49.4291769Z .................................................................................................... 2400/9354
2019-12-11T21:56:05.7632330Z .................................................................................................... 2500/9354
---
2019-12-11T21:58:01.9434051Z .................................................i...............i.................................. 4800/9354
2019-12-11T21:58:07.9811780Z .................................................................................................... 4900/9354
2019-12-11T21:58:14.0035857Z .............................................................................................i...... 5000/9354
2019-12-11T21:58:18.1320739Z .................................................................................................... 5100/9354
2019-12-11T21:58:26.0172820Z ...........................................................ii.ii...........i........................ 5200/9354
2019-12-11T21:58:32.8478896Z .................................................................................................... 5400/9354
2019-12-11T21:58:40.4887559Z .................................................................................................... 5500/9354
2019-12-11T21:58:45.4630949Z .........................................i.......................................................... 5600/9354
2019-12-11T21:58:50.6444152Z .................................................................................................... 5700/9354
2019-12-11T21:58:50.6444152Z .................................................................................................... 5700/9354
2019-12-11T21:58:59.0859742Z .................................................................................................... 5800/9354
2019-12-11T21:59:07.2286237Z .............................ii...i..ii...........i................................................. 5900/9354
2019-12-11T21:59:20.9840301Z .................................................................................................... 6100/9354
2019-12-11T21:59:26.7469446Z .................................................................................................... 6200/9354
2019-12-11T21:59:26.7469446Z .................................................................................................... 6200/9354
2019-12-11T21:59:32.0201444Z .....................................................i..ii.......................................... 6300/9354
2019-12-11T21:59:51.6729078Z .................................................................................................... 6500/9354
2019-12-11T21:59:53.1585370Z .........................i.......................................................................... 6600/9354
2019-12-11T21:59:54.7235551Z .................................................................................................... 6700/9354
2019-12-11T21:59:56.4506916Z ................i................................................................................... 6800/9354
---
2019-12-11T22:01:08.7052020Z .................................................................................................... 7400/9354
2019-12-11T22:01:12.2569931Z .................................................................................................... 7500/9354
2019-12-11T22:01:17.3720026Z .................................................................................................... 7600/9354
2019-12-11T22:01:23.9413259Z .................................................................................................... 7700/9354
2019-12-11T22:01:29.5518177Z ................................iiii................................................................ 7800/9354
2019-12-11T22:01:40.3596789Z .................................................................................................... 8000/9354
2019-12-11T22:01:46.6859895Z .................................................................................................... 8100/9354
2019-12-11T22:01:57.3487762Z .................................................................................................... 8200/9354
2019-12-11T22:02:03.0634451Z .................................................................................................... 8300/9354
---
2019-12-11T22:03:27.2534868Z 1 error[E0716]: temporary value dropped while borrowed
2019-12-11T22:03:27.2535288Z -   --> $DIR/interior-mutability.rs:40:26
2019-12-11T22:03:27.2535705Z +   --> $DIR/interior-mutability.rs:44:26
2019-12-11T22:03:27.2535933Z 3    |
2019-12-11T22:03:27.2536310Z 4 LL |     let x: &'static _ = &X;
2019-12-11T22:03:27.2536755Z 5    |            ----------    ^ creates a temporary which is freed while still in use
2019-12-11T22:03:27.2537401Z 10    | - temporary value is freed at the end of this statement
2019-12-11T22:03:27.2537633Z 11 
2019-12-11T22:03:27.2537821Z 12 error[E0716]: temporary value dropped while borrowed
2019-12-11T22:03:27.2538224Z -   --> $DIR/interior-mutability.rs:41:26
2019-12-11T22:03:27.2538224Z -   --> $DIR/interior-mutability.rs:41:26
2019-12-11T22:03:27.2538628Z +   --> $DIR/interior-mutability.rs:45:26
2019-12-11T22:03:27.2538872Z 14    |
2019-12-11T22:03:27.2539263Z 15 LL |     let y: &'static _ = &Y;
2019-12-11T22:03:27.2539704Z 16    |            ----------    ^ creates a temporary which is freed while still in use
2019-12-11T22:03:27.2540473Z 21    | - temporary value is freed at the end of this statement
2019-12-11T22:03:27.2540755Z 22 
2019-12-11T22:03:27.2540944Z 23 error[E0716]: temporary value dropped while borrowed
2019-12-11T22:03:27.2541367Z -   --> $DIR/interior-mutability.rs:42:26
2019-12-11T22:03:27.2541367Z -   --> $DIR/interior-mutability.rs:42:26
2019-12-11T22:03:27.2541777Z +   --> $DIR/interior-mutability.rs:46:26
2019-12-11T22:03:27.2542025Z 25    |
2019-12-11T22:03:27.2542386Z 26 LL |     let z: &'static _ = &Z;
2019-12-11T22:03:27.2542826Z 27    |            ----------    ^ creates a temporary which is freed while still in use
2019-12-11T22:03:27.2543231Z 
2019-12-11T22:03:27.2543413Z The actual stderr differed from the expected stderr.
2019-12-11T22:03:27.2543854Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/control-flow/interior-mutability/interior-mutability.stderr
2019-12-11T22:03:27.2543854Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/control-flow/interior-mutability/interior-mutability.stderr
2019-12-11T22:03:27.2544495Z To update references, rerun the tests and pass the `--bless` flag
2019-12-11T22:03:27.2545033Z To only update this specific test, also pass `--test-args consts/control-flow/interior-mutability.rs`
2019-12-11T22:03:27.2548447Z error: 1 errors occurred comparing output.
2019-12-11T22:03:27.2550183Z status: exit code: 1
2019-12-11T22:03:27.2550183Z status: exit code: 1
2019-12-11T22:03:27.2551313Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/consts/control-flow/interior-mutability.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/control-flow/interior-mutability" "-Crpath" "-O" "-Cdebuginfo=0" "-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/ui/consts/control-flow/interior-mutability/auxiliary" "-A" "unused"
2019-12-11T22:03:27.2552155Z ------------------------------------------
2019-12-11T22:03:27.2552390Z 
2019-12-11T22:03:27.2552822Z ------------------------------------------
2019-12-11T22:03:27.2553073Z stderr:
2019-12-11T22:03:27.2553073Z stderr:
2019-12-11T22:03:27.2553465Z ------------------------------------------
2019-12-11T22:03:27.2553729Z error[E0716]: temporary value dropped while borrowed
2019-12-11T22:03:27.2554152Z   --> /checkout/src/test/ui/consts/control-flow/interior-mutability.rs:44:26
2019-12-11T22:03:27.2554396Z    |
2019-12-11T22:03:27.2554843Z LL |     let x: &'static _ = &X; //~ ERROR temporary value dropped while borrowed
2019-12-11T22:03:27.2555827Z    |            ----------    ^ creates a temporary which is freed while still in use
2019-12-11T22:03:27.2556491Z    |            type annotation requires that borrow lasts for `'static`
2019-12-11T22:03:27.2556696Z ...
2019-12-11T22:03:27.2556828Z LL | }
2019-12-11T22:03:27.2557185Z    | - temporary value is freed at the end of this statement
2019-12-11T22:03:27.2557185Z    | - temporary value is freed at the end of this statement
2019-12-11T22:03:27.2557336Z 
2019-12-11T22:03:27.2557499Z error[E0716]: temporary value dropped while borrowed
2019-12-11T22:03:27.2557846Z   --> /checkout/src/test/ui/consts/control-flow/interior-mutability.rs:45:26
2019-12-11T22:03:27.2559937Z    |
2019-12-11T22:03:27.2561263Z LL |     let y: &'static _ = &Y; //~ ERROR temporary value dropped while borrowed
2019-12-11T22:03:27.2561761Z    |            ----------    ^ creates a temporary which is freed while still in use
2019-12-11T22:03:27.2562385Z    |            type annotation requires that borrow lasts for `'static`
2019-12-11T22:03:27.2562385Z    |            type annotation requires that borrow lasts for `'static`
2019-12-11T22:03:27.2562819Z LL |     let z: &'static _ = &Z; //~ ERROR temporary value dropped while borrowed
2019-12-11T22:03:27.2563408Z    | - temporary value is freed at the end of this statement
2019-12-11T22:03:27.2563609Z 
2019-12-11T22:03:27.2563972Z error[E0716]: temporary value dropped while borrowed
2019-12-11T22:03:27.2564381Z   --> /checkout/src/test/ui/consts/control-flow/interior-mutability.rs:46:26
2019-12-11T22:03:27.2564381Z   --> /checkout/src/test/ui/consts/control-flow/interior-mutability.rs:46:26
2019-12-11T22:03:27.2565136Z    |
2019-12-11T22:03:27.2565757Z LL |     let z: &'static _ = &Z; //~ ERROR temporary value dropped while borrowed
2019-12-11T22:03:27.2566279Z    |            ----------    ^ creates a temporary which is freed while still in use
2019-12-11T22:03:27.2566895Z    |            type annotation requires that borrow lasts for `'static`
2019-12-11T22:03:27.2567086Z LL | }
2019-12-11T22:03:27.2567482Z    | - temporary value is freed at the end of this statement
2019-12-11T22:03:27.2567658Z 
---
2019-12-11T22:03:27.2572909Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-12-11T22:03:27.2573076Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-12-11T22:03:27.2573204Z 
2019-12-11T22:03:27.2573309Z 
2019-12-11T22:03:27.2574658Z 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/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-7/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -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" "7.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-12-11T22:03:27.2575081Z 
2019-12-11T22:03:27.2575190Z 
2019-12-11T22:03:27.2575329Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-12-11T22:03:27.2575466Z Build completed unsuccessfully in 0:47:52
2019-12-11T22:03:27.2575466Z Build completed unsuccessfully in 0:47:52
2019-12-11T22:03:27.2621751Z == clock drift check ==
2019-12-11T22:03:27.2635735Z   local time: Wed Dec 11 22:03:27 UTC 2019
2019-12-11T22:03:27.7881409Z   network time: Wed, 11 Dec 2019 22:03:27 GMT
2019-12-11T22:03:27.7885752Z == end clock drift check ==
2019-12-11T22:03:29.1422487Z 
2019-12-11T22:03:29.1493593Z ##[error]Bash exited with code '1'.
2019-12-11T22:03:29.1503390Z ##[section]Finishing: Run build
2019-12-11T22:03:29.1530946Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/67216/merge to s
2019-12-11T22:03:29.1532557Z Task         : Get sources
2019-12-11T22:03:29.1532629Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2019-12-11T22:03:29.1532666Z Version      : 1.0.0
2019-12-11T22:03:29.1532698Z Author       : Microsoft
2019-12-11T22:03:29.1532698Z Author       : Microsoft
2019-12-11T22:03:29.1532751Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2019-12-11T22:03:29.1532789Z ==============================================================================
2019-12-11T22:03:29.4851647Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2019-12-11T22:03:29.4881171Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/67216/merge to s
2019-12-11T22:03:29.4965219Z Start cleaning up orphan processes.
2019-12-11T22:03:29.5047875Z Terminate orphan process: pid (4081) (python)
2019-12-11T22:03:29.5250867Z ##[section]Finishing: Finalize Job
2019-12-11T22:03:29.5294836Z ##[section]Finishing: Linux x86_64-gnu-llvm-7

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)

@ecstatic-morse ecstatic-morse force-pushed the ecstatic-morse:const-loop branch from 7b37d44 to 93bdd54 Dec 11, 2019
@bors

This comment was marked as resolved.

Copy link
Contributor

bors commented Dec 13, 2019

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

ecstatic-morse and others added 9 commits Dec 11, 2019
Conditionals and loops now have unstable features, and `feature_err` has
its own error code. I think that `feature_err` should take an error code
as a parameter, but don't have the energy to make this change throughout
the codebase. Also, the error code system may be torn out entirely.
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
@ecstatic-morse ecstatic-morse force-pushed the ecstatic-morse:const-loop branch from aeb4da4 to faa52d1 Dec 13, 2019
@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Dec 13, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 13, 2019

📌 Commit faa52d1 has been approved by oli-obk

Centril added a commit to Centril/rust that referenced this pull request Dec 14, 2019
Enable `loop` and `while` in constants behind a feature flag

This PR is an initial implementation of rust-lang#52000. It adds a `const_loop` feature gate, which allows `while` and `loop` expressions through both HIR and MIR const-checkers if enabled. `for` expressions remain forbidden by the HIR const-checker, since they desugar to a call to `IntoIterator::into_iter`, which will be rejected anyways.

`while` loops also require [`#![feature(const_if_match)]`](rust-lang#66507), since they have a conditional built into them. The diagnostics from the HIR const checker will suggest this to the user.

r? @oli-obk
cc @rust-lang/wg-const-eval
bors added a commit that referenced this pull request Dec 14, 2019
Rollup of 5 pull requests

Successful merges:

 - #67151 (doc comments: Less attribute mimicking)
 - #67216 (Enable `loop` and `while` in constants behind a feature flag)
 - #67255 (Remove i686-unknown-dragonfly target)
 - #67267 (Fix signature of `__wasilibc_find_relpath`)
 - #67282 (Fix example code of OpenOptions::open)

Failed merges:

r? @ghost
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 15, 2019

⌛️ Testing commit faa52d1 with merge fc6b5d6...

bors added a commit that referenced this pull request Dec 15, 2019
Enable `loop` and `while` in constants behind a feature flag

This PR is an initial implementation of #52000. It adds a `const_loop` feature gate, which allows `while` and `loop` expressions through both HIR and MIR const-checkers if enabled. `for` expressions remain forbidden by the HIR const-checker, since they desugar to a call to `IntoIterator::into_iter`, which will be rejected anyways.

`while` loops also require [`#![feature(const_if_match)]`](#66507), since they have a conditional built into them. The diagnostics from the HIR const checker will suggest this to the user.

r? @oli-obk
cc @rust-lang/wg-const-eval
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 15, 2019

☀️ Test successful - checks-azure
Approved by: oli-obk
Pushing fc6b5d6 to master...

@bors bors added the merged-by-bors label Dec 15, 2019
@bors bors merged commit faa52d1 into rust-lang:master Dec 15, 2019
5 checks passed
5 checks passed
homu Test successful
Details
pr #20191213.31 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-7) Linux x86_64-gnu-llvm-7 succeeded
Details
pr (Linux x86_64-gnu-tools) Linux x86_64-gnu-tools succeeded
Details
@@ -390,8 +390,12 @@ fn check_terminator(
cleanup: _,
} => check_operand(tcx, cond, span, def_id, body),

| TerminatorKind::FalseUnwind { .. }
if feature_allowed(tcx, def_id, sym::const_loop)
=> Ok(()),

This comment has been minimized.

Copy link
@eddyb

eddyb Jan 16, 2020

Member

This seems very fragile. FalseUnwind is supposed to be ignored (unless you care about unwind paths).

What this code should be doing is a CFG cyclicity check.

This comment has been minimized.

Copy link
@ecstatic-morse

ecstatic-morse Jan 17, 2020

Author Contributor

There is one in check_consts that will run even if #![feature(const_fn)] is specified. I hope we can lose that feature gate in favor of fine-grained ones in the future, as well as merge check_consts and qualify_min_const_fn.

This comment has been minimized.

Copy link
@eddyb

eddyb Jan 17, 2020

Member

Do both run? That makes me happier, I guess, but then the FalseUnwind check here is not needed at all, is it?

This comment has been minimized.

Copy link
@ecstatic-morse

ecstatic-morse Jan 17, 2020

Author Contributor

check_consts validation is always run. qualify_min_const_fn is run when #![feature(const_fn)] is not specified. My opinion is that this pass should be removed along with #![feature(const_fn)] and any check that isn't already in check_consts given its own feature gate along with an entry in check_consts/ops.rs. I don't wanna spend political capital to spearhead this, however.

This comment has been minimized.

Copy link
@RalfJung

RalfJung Jan 17, 2020

Member

qualify_min_const_fn was added as a hack back when the normal const-checking pass was such a mess that nobody was confident in its ability to rule out all bad code. It was always meant to be temporary.

So, assuming const-check these days is well-structured enough that everyone is confident in its ability to do what it is supposed to do, I don't think you'll need to spend any political capital to get rid of it. Quite the contrary, at least I personally would be delighted to see it go. :)

This comment has been minimized.

Copy link
@Centril

Centril Jan 17, 2020

Member

I would prefer if we could wait with removing qualify_min_const_fn. Not necessarily because the new const checker is messy, but because I don't understand the new code (which is based on data-flow) nearly as well as the old code. And as the lang team point-person for the const things, I would like to understand the thing that checks for stability wrt. const. So I'd appreciate if we don't do it right now and allow me some time to study the new stuff. (Also, is there an urgency to this?)

This comment has been minimized.

Copy link
@oli-obk

oli-obk Jan 17, 2020

Contributor

There's no urgency, there are some preliminary things that can be done like eliminating the const_fn feature gate

This comment has been minimized.

Copy link
@eddyb

eddyb Jan 17, 2020

Member

You could just make the handling of FalseUnwind consistent, for now.
It's not, and should not be mistaken for, a loop.

As the name says, it's a "false" (or "phantom") unwind edge. It's for situations where analyses which care about unwinding / cleanup blocks need to be conservative and assume unwinding can happen "out of the blue".

Everything else in const-checking ignores unwind edges (e.g. from calls) and associated cleanup blocks, because we completely bypass unwinding at compile-time.

This comment has been minimized.

Copy link
@eddyb

eddyb Jan 17, 2020

Member

See #62274 for precedent.

This comment has been minimized.

Copy link
@eddyb

eddyb Jan 17, 2020

Member

Also looks like FalseEdges is also mishandled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.