Skip to content

Fix termination and performance issues with DecEq#7840

Merged
ana-pantilie merged 11 commits into
masterfrom
ana/remove-terminating-deceq
Jul 16, 2026
Merged

Fix termination and performance issues with DecEq#7840
ana-pantilie merged 11 commits into
masterfrom
ana/remove-terminating-deceq

Conversation

@ana-pantilie

@ana-pantilie ana-pantilie commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Needs #7832
Needs #7843

Termination fix

Removes the need for the TERMINATING pragma in the decEq definitions, Agda can now prove that they terminate.

Performance fix

The matching on refl inside decEq triggered normalization of terms when typechecking, which affected performance significantly, to the point of using more than 128GB of memory for the example @basetunnel and I worked on.

The example is an equality proof of the first AST to itself, from agda-certificates/cardano_constitution_Cardano_Constitution_Validator_Data_Sorted-b48sy0.agda-cert. This was the certificate produced for defaultConstitutionCode from cardano-constitution/src/Cardano/Constitution/Validator/Data/Sorted.hs.

For this particular example comparing cons was the most expensive, so avoiding matching on refl in the recursive call to decEq-⟦ t ⟧tag x x₁ inside decEq-TmCon did the trick.

@ana-pantilie ana-pantilie changed the title Remove TERMINATING pragma from DecEq Fix issues with DecEq Jul 10, 2026
@ana-pantilie ana-pantilie changed the title Fix issues with DecEq Fix termination and performance issues with DecEq Jul 10, 2026
@ana-pantilie
ana-pantilie marked this pull request as ready for review July 15, 2026 08:56
@ana-pantilie
ana-pantilie requested a review from basetunnel July 15, 2026 08:57
... | no a₁≠a₂ | _ = no λ { refl → a₁≠a₂ refl }
... | _ | no b₁≠b₂ = no λ { refl → b₁≠b₂ refl }

decEq-⊢⋆ [] [] = yes refl

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unicode character seems to be used as a suffix for things that refer plutus types, like _⊢⋆_ and Ctx⋆ (probably referencing base kind). Perhaps we could have a different convention for a suffix for these map-like functions that appease the termination checker. I"ve used * in some of the translation relation machinery, but I think historically it was more often List, e.g. dischargeList.

decEq-⊢ : ∀{n} → DecidableEquality (n ⊢)
decEq-⊢ : {n : ℕ} → DecidableEquality (n ⊢)

decEq-⊢⋆ : {n : ℕ} → DecidableEquality (List (n ⊢)) -- {n : ℕ} → (Ms : List (n ⊢)) → (Ns : List (n ⊢)) → Dec (Ms ≡ Ns)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment for documentation purposes or a left-over from writing out DecidableEquality?

Comment thread plutus-metatheory/src/Untyped/Equality.lagda.md
@ana-pantilie
ana-pantilie requested a review from basetunnel July 16, 2026 10:36
@ana-pantilie
ana-pantilie merged commit 7657891 into master Jul 16, 2026
8 checks passed
@ana-pantilie
ana-pantilie deleted the ana/remove-terminating-deceq branch July 16, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants