Skip to content

Commit 4c884b4

Browse files
committed
Don't error on long const evals
1 parent 5d3d23d commit 4c884b4

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

text/0000-const-looping.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,15 @@ const fn fib(n: u128) -> u128 {
7878
A loop in MIR is a cyclic graph of `BasicBlock`s. Evaluating such a loop is no
7979
different from evaluating a linear sequence of `BasicBlock`s, except that
8080
termination is not guaranteed. To ensure that the compiler never hangs
81-
indefinitely, we count the number of terminators processed and once we reach a
82-
fixed limit, we report an error mentioning that we aborted constant evaluation,
83-
because we could not guarantee that it'll terminate.
81+
indefinitely, we count the number of terminators processed and whenever we reach
82+
a fixed limit, we report a lint mentioning that we cannot guarantee that the
83+
evaluation will terminate and reset the counter to zero. This lint should recur
84+
in a non-annoying amount of time (e.g. at least 30 seconds between occurrences).
8485

8586
# Drawbacks
8687
[drawbacks]: #drawbacks
8788

88-
* Loops are not guaranteed to terminate
89-
* We catch this already by having a maximum number of basic blocks that we
90-
can evaluate.
91-
* A guaranteed to terminate, non looping constant might trigger the limit, if it
92-
has too much code.
89+
* Infinite loops will hang the compiler if the lint is not denied
9390

9491
# Rationale and alternatives
9592
[alternatives]: #alternatives
@@ -98,3 +95,9 @@ because we could not guarantee that it'll terminate.
9895

9996
# Unresolved questions
10097
[unresolved]: #unresolved-questions
98+
99+
* Should we add a true recursion check that hashes the interpreter state and
100+
detects if it has reached the same state again?
101+
* This will slow down const evaluation enormously and for complex iterations
102+
is essentially useless because it'll take forever (e.g. counting from 0 to
103+
`u64::max_value()`)

0 commit comments

Comments
 (0)