Diagnostic and cause
СсылкаRuntime comparison guard
- Семейство
- topaz
- Этап
- run
- Код
TPZ5007
Причина и условия
The runtime comparison guard uses TPZ5007. A comparison that exhausts the structural budget fails at the comparison call. Finite nested values can reach this guard. Recursive declarations follow Nested conformance. Data values follow Value semantics.
Связанное правило · Reject a comparison that exhausts the structural budget →Действия
Reduce the nesting or compare smaller parts of the values before repeating the comparison.
Compiler phase: check/runtime.
Compiler explanation: The operation requires equality/order/key semantics that this type does not provide.
Message templates. The marker ⟨value⟩ stands for text computed for the reported program.
⟨value⟩is not ordered comparable, so.cannot sort it Source⟨value⟩() - the
⟨value⟩key type⟨value⟩is not ordered comparable, so.cannot sort it Source⟨value⟩() ⟨value⟩is not comparable, sotest.cannot compare it Source⟨value⟩ ⟨value⟩and⟨value⟩are not ordered comparable Source⟨value⟩and⟨value⟩are not comparable values Source⟨value⟩and⟨value⟩are never equal Source- ⟨value⟩ is not a valid Map/Set key (⟨value⟩ keys are not supported yet) Source
Equality and ordering traverse their supported value structures. A comparison of finite values can exhaust the structural budget and raise runtime TPZ5007.
Reject a comparison that exhausts the structural budget
The runtime comparison guard uses TPZ5007. A comparison that exhausts the structural budget fails at the comparison call. Finite nested values can reach this guard. Recursive declarations follow Nested conformance. Data values follow Value semantics.
Response
СсылкаReduce the nesting or compare smaller parts of the values before repeating the comparison.
Reproduction and verification
СсылкаFinite nested values exhaust the comparison budget
Ссылкаrecord Node derives Eq { children: Array<Node> }let mut left = Node { children: [] }let mut right = Node { children: [] }for _ in (0..200) {left = Node { children: [left] }right = Node { children: [right] }}Eq.equals(left, right)
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Этап отклонения run. Ненулевой код завершения.
structures-comparison-recursion at
example.tpz:8:1
Both trees are finite. The deep comparison exceeds the structural budget. The repaired comparison stays within it. This pair has not been run with the public CLI.
Shallow trees compare within the budget
Ссылкаimport std.iorecord Node derives Eq { children: Array<Node> }let mut left = Node { children: [] }let mut right = Node { children: [] }for _ in (0..2) {left = Node { children: [left] }right = Node { children: [right] }}io.writeLine("{Eq.equals(left, right)}")
true
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
true
Both trees are finite. The deep comparison exceeds the structural budget. The repaired comparison stays within it. This pair has not been run with the public CLI.