@@ -78,18 +78,15 @@ const fn fib(n: u128) -> u128 {
78
78
A loop in MIR is a cyclic graph of ` BasicBlock ` s. Evaluating such a loop is no
79
79
different from evaluating a linear sequence of ` BasicBlock ` s, except that
80
80
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).
84
85
85
86
# Drawbacks
86
87
[ drawbacks ] : #drawbacks
87
88
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
93
90
94
91
# Rationale and alternatives
95
92
[ alternatives ] : #alternatives
@@ -98,3 +95,9 @@ because we could not guarantee that it'll terminate.
98
95
99
96
# Unresolved questions
100
97
[ 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