-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Remove const eval loop detector #70087
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
Merged
bors
merged 4 commits into
rust-lang:master
from
ecstatic-morse:remove-const-eval-loop-detector
Mar 24, 2020
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5b66f27
Use `const_eval_limit` instead of infinite loop detector
ecstatic-morse e15c486
Remove infinite loop detector
ecstatic-morse 044dc6e
Update const-eval tests
ecstatic-morse b5636b8
Rename `TimeLimitReached` -> `StepLimitReached`
ecstatic-morse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update const-eval tests
- Loading branch information
commit 044dc6e8dd435eb9c3b6f1dc0c85d0a6e70dae82
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
// check-pass | ||
|
||
#![feature(const_eval_limit)] | ||
#![const_eval_limit="1000"] | ||
#![feature(const_loop, const_if_match)] | ||
|
||
const CONSTANT: usize = limit(); | ||
// This needs to be higher than the number of loop iterations since each pass through the loop may | ||
// hit more than one terminator. | ||
#![const_eval_limit="4000"] | ||
|
||
fn main() { | ||
assert_eq!(CONSTANT, 1764); | ||
} | ||
const X: usize = { | ||
let mut x = 0; | ||
while x != 1000 { | ||
x += 1; | ||
10000 } | ||
|
||
const fn limit() -> usize { | ||
let x = 42; | ||
x | ||
}; | ||
|
||
x * 42 | ||
fn main() { | ||
assert_eq!(X, 1000); | ||
} |
27 changes: 12 additions & 15 deletions
27
src/test/ui/consts/const_limit/const_eval_limit_reached.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
// ignore-tidy-linelength | ||
// only-x86_64 | ||
// check-pass | ||
// NOTE: We always compile this test with -Copt-level=0 because higher opt-levels | ||
// optimize away the const function | ||
// compile-flags:-Copt-level=0 | ||
#![feature(const_eval_limit)] | ||
#![const_eval_limit="2"] | ||
#![feature(const_loop, const_if_match)] | ||
|
||
const CONSTANT: usize = limit(); | ||
//~^ WARNING Constant evaluating a complex constant, this might take some time | ||
#![const_eval_limit="500"] | ||
|
||
fn main() { | ||
assert_eq!(CONSTANT, 1764); | ||
} | ||
const X: usize = { | ||
let mut x = 0; | ||
while x != 1000 { | ||
//~^ ERROR any use of this value will cause an error | ||
x += 1; | ||
} | ||
|
||
const fn limit() -> usize { //~ WARNING Constant evaluating a complex constant, this might take some time | ||
let x = 42; | ||
x | ||
}; | ||
|
||
x * 42 | ||
fn main() { | ||
assert_eq!(X, 1000); | ||
} |
25 changes: 13 additions & 12 deletions
25
src/test/ui/consts/const_limit/const_eval_limit_reached.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
warning: Constant evaluating a complex constant, this might take some time | ||
--> $DIR/const_eval_limit_reached.rs:17:1 | ||
error: any use of this value will cause an error | ||
--> $DIR/const_eval_limit_reached.rs:8:11 | ||
| | ||
LL | / const fn limit() -> usize { | ||
LL | | let x = 42; | ||
LL | / const X: usize = { | ||
LL | | let mut x = 0; | ||
LL | | while x != 1000 { | ||
| | ^^^^^^^^^ exceeded interpreter time limit | ||
LL | | | ||
LL | | x * 42 | ||
LL | | } | ||
| |_^ | ||
|
||
warning: Constant evaluating a complex constant, this might take some time | ||
--> $DIR/const_eval_limit_reached.rs:10:1 | ||
... | | ||
LL | | x | ||
LL | | }; | ||
| |__- | ||
| | ||
LL | const CONSTANT: usize = limit(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: `#[deny(const_err)]` on by default | ||
|
||
error: aborting due to previous error | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be useful to keep around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean at like 1% or 10% of the step limit? Not sure how to choose a good number for that, but anything above 10% of the step limit seems useless since you're hitting the step limit soon, and anything below 30s will likely be annoying more often than not. It's very hard to silence this warning (it may be getting emitted in a different crate from the one currently being evaluated).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anecdotally, the default step limit only takes a few seconds to trigger, so I don't think preserving the warning is helpful.