-
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 #66294 - davidhewitt:const_fn_memoization, r=oli-obk
Add memoization for const function evaluations When a const function is being evaluated, as long as all its arguments are zero-sized-types (or it has no arguments) then we can trivially memoize the evaluation result using the existing query mechanism. With thanks to @oli-obk for mentoring me through this at RustFest Barcelona. r? @oli-obk
- Loading branch information
Showing
10 changed files
with
101 additions
and
132 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// build-pass | ||
|
||
// Check that the evaluation of const-functions with | ||
// zero-sized types as arguments compiles successfully | ||
|
||
struct Zst {} | ||
|
||
const fn foo(val: Zst) -> Zst { val } | ||
|
||
const FOO: Zst = foo(Zst {}); | ||
|
||
fn main() { | ||
const _: Zst = FOO; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,21 @@ | ||
error: any use of this value will cause an error | ||
error[E0391]: cycle detected when const-evaluating `hint_unreachable` | ||
--> $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| | ||
LL | fake_type() | ||
| ^^^^^^^^^^^ | ||
| | ||
note: ...which requires const-evaluating `fake_type`... | ||
--> $DIR/uninhabited-const-issue-61744.rs:4:5 | ||
| | ||
LL | hint_unreachable() | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| reached the configured maximum number of stack frames | ||
| inside call to `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:4:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:8:5 | ||
| inside call to `fake_type::<i32>` at $DIR/uninhabited-const-issue-61744.rs:12:36 | ||
... | ||
LL | const CONSTANT: i32 = unsafe { fake_type() }; | ||
| --------------------------------------------- | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
|
||
error[E0080]: erroneous constant used | ||
--> $DIR/uninhabited-const-issue-61744.rs:18:10 | ||
= note: ...which again requires const-evaluating `hint_unreachable`, completing the cycle | ||
note: cycle used when const-evaluating `fake_type` | ||
--> $DIR/uninhabited-const-issue-61744.rs:4:5 | ||
| | ||
LL | dbg!(i32::CONSTANT); | ||
| ^^^^^^^^^^^^^ referenced constant has errors | ||
LL | hint_unreachable() | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. | ||
For more information about this error, try `rustc --explain E0391`. |
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,66 +1,21 @@ | ||
error[E0080]: evaluation of constant value failed | ||
error[E0391]: cycle detected when const-evaluating `a` | ||
--> $DIR/infinite-recursion-const-fn.rs:3:25 | ||
| | ||
LL | const fn a() -> usize { b() } | ||
| ^^^ | ||
| | | ||
| reached the configured maximum number of stack frames | ||
| inside call to `b` at $DIR/infinite-recursion-const-fn.rs:3:25 | ||
| | ||
note: ...which requires const-evaluating `b`... | ||
--> $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| | ||
LL | const fn b() -> usize { a() } | ||
| --- | ||
| | | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| inside call to `a` at $DIR/infinite-recursion-const-fn.rs:4:25 | ||
| ^^^ | ||
= note: ...which again requires const-evaluating `a`, completing the cycle | ||
note: cycle used when const-evaluating `ARR::{{constant}}#0` | ||
--> $DIR/infinite-recursion-const-fn.rs:5:18 | ||
| | ||
LL | const ARR: [i32; a()] = [5; 6]; | ||
| --- inside call to `a` at $DIR/infinite-recursion-const-fn.rs:5:18 | ||
| ^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. | ||
For more information about this error, try `rustc --explain E0391`. |
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