Diagnostic and cause
LinkRuntime comparison guard
- Family
- topaz
- Phase
- run
- Code
TPZ5007
Cause and conditions
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.
Related rule: Reject a comparison that exhausts the structural budgetResponse
Reduce the nesting or compare smaller parts of the values before repeating the comparison.
Source evidence
- compiler/crates/topaz_diag/src/explain.rs at
151141d7bb44· 655-664 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 68-68 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
151141d7bb44· 1174-1174 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 963-963 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
151141d7bb44· 638-638 - compiler/crates/topaz_self_frontend/topaz/checker/diagnostics_derives.tpz at
151141d7bb44· 42-74 - compiler/crates/topaz_self_frontend/topaz/checker/diagnostics_derives.tpz at
151141d7bb44· 178-191 - compiler/crates/topaz_value/src/value/compare.rs at
151141d7bb44· 21-31 - compiler/crates/topaz_value/src/value/compare.rs at
151141d7bb44· 109-179 - compiler/crates/topaz_value/src/value/guards.rs at
151141d7bb44· 80-86 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 68-68 - compiler/crates/topaz_value/src/value/model.rs at
151141d7bb44· 3-11 - compiler/crates/topaz_syntax/src/literal.rs at
151141d7bb44· 48-49
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.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/diagnostics_derives.tpz at
151141d7bb44· 42-74 - compiler/crates/topaz_self_frontend/topaz/checker/diagnostics_derives.tpz at
151141d7bb44· 178-191 - compiler/crates/topaz_value/src/value/compare.rs at
151141d7bb44· 21-31 - compiler/crates/topaz_value/src/value/compare.rs at
151141d7bb44· 109-179 - compiler/crates/topaz_value/src/value/guards.rs at
151141d7bb44· 80-86 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 68-68 - compiler/crates/topaz_value/src/value/model.rs at
151141d7bb44· 3-11 - compiler/crates/topaz_syntax/src/literal.rs at
151141d7bb44· 48-49
Response
LinkReduce the nesting or compare smaller parts of the values before repeating the comparison.
Reproduction and verification
LinkFinite nested values exhaust the comparison budget
Linkrecord 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)
No stdout.
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ5007structures-comparison-recursion atexample.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.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/diagnostics_derives.tpz at
151141d7bb44· 42-74 - compiler/crates/topaz_self_frontend/topaz/checker/diagnostics_derives.tpz at
151141d7bb44· 178-191 - compiler/crates/topaz_value/src/value/compare.rs at
151141d7bb44· 21-31 - compiler/crates/topaz_value/src/value/compare.rs at
151141d7bb44· 109-179 - compiler/crates/topaz_value/src/value/guards.rs at
151141d7bb44· 80-86 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 68-68 - compiler/crates/topaz_value/src/value/model.rs at
151141d7bb44· 3-11 - compiler/crates/topaz_syntax/src/literal.rs at
151141d7bb44· 48-49
Shallow trees compare within the budget
Linkimport 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
Expected result
Expected result
Execution completes. Exit code 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.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/diagnostics_derives.tpz at
151141d7bb44· 42-74 - compiler/crates/topaz_self_frontend/topaz/checker/diagnostics_derives.tpz at
151141d7bb44· 178-191 - compiler/crates/topaz_value/src/value/compare.rs at
151141d7bb44· 21-31 - compiler/crates/topaz_value/src/value/compare.rs at
151141d7bb44· 109-179 - compiler/crates/topaz_value/src/value/guards.rs at
151141d7bb44· 80-86 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 68-68 - compiler/crates/topaz_value/src/value/model.rs at
151141d7bb44· 3-11 - compiler/crates/topaz_syntax/src/literal.rs at
151141d7bb44· 48-49