-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #67260 - TheSamsa:const-limit, r=oli-obk
const limit for CTFE I tried to tackle the first steps for this issue. The active feature flag does link to the issue below, I think this has to change, because there should be a tracking issue? https://github.com/TheSamsa/rust/blob/1679a7647da0de672bac26b716db82d16f3896a8/src/librustc_feature/active.rs#L530 Also, I only put up the storage of the limit like "recursion_limit" but created a seperate file in the same place. Since I guess the invocation happens seperately. https://github.com/TheSamsa/rust/blob/const-limit/src/librustc/middle/const_limit.rs If this does not hold up for the issue and since there is a time pressure, just reject it. hopefully this does not put more load on you than I expected...
- Loading branch information
Showing
24 changed files
with
163 additions
and
34 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/doc/unstable-book/src/language-features/const-eval-limit.md
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# `const_eval_limit` | ||
|
||
The tracking issue for this feature is: [#67217] | ||
|
||
[#67217]: https://github.com/rust-lang/rust/issues/67217 | ||
|
||
The `const_eval_limit` allows someone to limit the evaluation steps the CTFE undertakes to evaluate a `const fn`. |
This file contains 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 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 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 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 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 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 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 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 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
15 changes: 15 additions & 0 deletions
15
src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// check-pass | ||
#![feature(const_eval_limit)] | ||
#![const_eval_limit="1000"] | ||
|
||
const CONSTANT: usize = limit(); | ||
|
||
fn main() { | ||
assert_eq!(CONSTANT, 1764); | ||
} | ||
|
||
const fn limit() -> usize { | ||
let x = 42; | ||
|
||
x * 42 | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/ui/consts/const_limit/const_eval_limit_overflow.rs
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![feature(const_eval_limit)] | ||
#![const_eval_limit="18_446_744_073_709_551_615"] | ||
//~^ ERROR `limit` must be a non-negative integer | ||
|
||
const CONSTANT: usize = limit(); | ||
|
||
fn main() { | ||
assert_eq!(CONSTANT, 1764); | ||
} | ||
|
||
const fn limit() -> usize { | ||
let x = 42; | ||
|
||
x * 42 | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/consts/const_limit/const_eval_limit_overflow.stderr
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: `limit` must be a non-negative integer | ||
--> $DIR/const_eval_limit_overflow.rs:2:1 | ||
| | ||
LL | #![const_eval_limit="18_446_744_073_709_551_615"] | ||
| ^^^^^^^^^^^^^^^^^^^^----------------------------^ | ||
| | | ||
| not a valid integer | ||
|
||
error: aborting due to previous error | ||
|
21 changes: 21 additions & 0 deletions
21
src/test/ui/consts/const_limit/const_eval_limit_reached.rs
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// 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"] | ||
|
||
const CONSTANT: usize = limit(); | ||
//~^ WARNING Constant evaluating a complex constant, this might take some time | ||
|
||
fn main() { | ||
assert_eq!(CONSTANT, 1764); | ||
} | ||
|
||
const fn limit() -> usize { //~ WARNING Constant evaluating a complex constant, this might take some time | ||
let x = 42; | ||
|
||
x * 42 | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/ui/consts/const_limit/const_eval_limit_reached.stderr
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
warning: Constant evaluating a complex constant, this might take some time | ||
--> $DIR/const_eval_limit_reached.rs:17:1 | ||
| | ||
LL | / const fn limit() -> usize { | ||
LL | | let x = 42; | ||
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 | const CONSTANT: usize = limit(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/consts/const_limit/feature-gate-const_eval_limit.rs
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![const_eval_limit="42"] | ||
//~^ ERROR the `#[const_eval_limit]` attribute is an experimental feature [E0658] | ||
|
||
const CONSTANT: usize = limit(); | ||
|
||
fn main() { | ||
assert_eq!(CONSTANT, 1764); | ||
} | ||
|
||
const fn limit() -> usize { | ||
let x = 42; | ||
|
||
x * 42 | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/consts/const_limit/feature-gate-const_eval_limit.stderr
This file contains 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0658]: the `#[const_eval_limit]` attribute is an experimental feature | ||
--> $DIR/feature-gate-const_eval_limit.rs:1:1 | ||
| | ||
LL | #![const_eval_limit="42"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #67217 <https://github.com/rust-lang/rust/issues/67217> for more information | ||
= help: add `#![feature(const_eval_limit)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains 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,6 +1,6 @@ | ||
// Test the parse error for an empty recursion_limit | ||
|
||
#![recursion_limit = ""] //~ ERROR `recursion_limit` must be a non-negative integer | ||
//~| `recursion_limit` must be a non-negative integer | ||
#![recursion_limit = ""] //~ ERROR `limit` must be a non-negative integer | ||
//~| `limit` must be a non-negative integer | ||
|
||
fn main() {} |
This file contains 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,10 +1,10 @@ | ||
error: `recursion_limit` must be a non-negative integer | ||
error: `limit` must be a non-negative integer | ||
--> $DIR/empty.rs:3:1 | ||
| | ||
LL | #![recursion_limit = ""] | ||
| ^^^^^^^^^^^^^^^^^^^^^--^ | ||
| | | ||
| `recursion_limit` must be a non-negative integer | ||
| `limit` must be a non-negative integer | ||
|
||
error: aborting due to previous error | ||
|
This file contains 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,6 +1,6 @@ | ||
// Test the parse error for an invalid digit in recursion_limit | ||
|
||
#![recursion_limit = "-100"] //~ ERROR `recursion_limit` must be a non-negative integer | ||
#![recursion_limit = "-100"] //~ ERROR `limit` must be a non-negative integer | ||
//~| not a valid integer | ||
|
||
fn main() {} |
This file contains 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 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,7 +1,7 @@ | ||
// Test the parse error for an overflowing recursion_limit | ||
|
||
#![recursion_limit = "999999999999999999999999"] | ||
//~^ ERROR `recursion_limit` must be a non-negative integer | ||
//~| `recursion_limit` is too large | ||
//~^ ERROR `limit` must be a non-negative integer | ||
//~| `limit` is too large | ||
|
||
fn main() {} |
This file contains 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,10 +1,10 @@ | ||
error: `recursion_limit` must be a non-negative integer | ||
error: `limit` must be a non-negative integer | ||
--> $DIR/overflow.rs:3:1 | ||
| | ||
LL | #![recursion_limit = "999999999999999999999999"] | ||
| ^^^^^^^^^^^^^^^^^^^^^--------------------------^ | ||
| | | ||
| `recursion_limit` is too large | ||
| `limit` is too large | ||
|
||
error: aborting due to previous error | ||
|
This file contains 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,4 +1,4 @@ | ||
// Test that a `recursion_limit` of 0 is valid | ||
// Test that a `limit` of 0 is valid | ||
|
||
#![recursion_limit = "0"] | ||
|
||
|