Skip to content

Conversation

@basetunnel
Copy link
Collaborator

This allows CSE to consider all sub-expressions. Currently it excludes work-free subexpressions such as partially applied built-ins (https://github.com/IntersectMBO/plutus-private/issues/1761).

  • factored out isWorkFree' from the logic of cse, makes it easier to understand

  • instead of Bool, I've added a CseWhichSubterms type to avoid boolean blindness. I found that it makes the code more understandable. If Bool is preferred for consistency with other simplifier flags, I'm happy to change it.

@basetunnel basetunnel requested a review from zliu41 January 7, 2026 13:48
@zliu41 zliu41 requested a review from a team January 7, 2026 22:14
Copy link
Member

@zliu41 zliu41 left a comment

Choose a reason for hiding this comment

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

Looks good, but we should look at how turning it on affects the costs and sizes in the existing tests. That will help decide whether or not it should be on by default.

@basetunnel
Copy link
Collaborator Author

basetunnel commented Jan 8, 2026

I've taken a quick look at the five test cases that are there for CSE.

The cseExpensive test becomes 10x slower using AllSubterms. The other tests are too small to observe a difference:

  simplify
    cse
      AllSubterms
        cse1_AllSubterms:                    OK (0.00s)
        cse2_AllSubterms:                    OK (0.00s)
        cse3_AllSubterms:                    OK (0.00s)
        cseExpensive_AllSubterms:            OK (27.91s)
        csePlusTree_AllSubterms:             OK (0.00s)
        cseRepeatPlus_AllSubterms:           OK (0.00s)
      ExcludeWorkFree
        cse1_ExcludeWorkFree:                OK (0.00s)
        cse2_ExcludeWorkFree:                OK (0.00s)
        cse3_ExcludeWorkFree:                OK (0.00s)
        cseExpensive_ExcludeWorkFree:        OK (2.85s)
        csePlusTree_ExcludeWorkFree:         OK (0.01s)
        cseRepeatPlus_ExcludeWorkFree:       OK (0.00s)

Output size on disk (in bytes) is slightly better in some cases, but equal in others:

259 cse1_AllSubterms.golden.uplc
278 cse1_ExcludeWorkFree.golden.uplc
160 cse2_AllSubterms.golden.uplc
160 cse2_ExcludeWorkFree.golden.uplc
119 cse3_AllSubterms.golden.uplc
119 cse3_ExcludeWorkFree.golden.uplc
617455 cseExpensive_AllSubterms.golden.uplc
617455 cseExpensive_ExcludeWorkFree.golden.uplc
162 csePlusTree_AllSubterms.golden.uplc
162 csePlusTree_ExcludeWorkFree.golden.uplc
54 cseRepeatPlus_AllSubterms.golden.uplc
74 cseRepeatPlus_ExcludeWorkFree.golden.uplc

Size on disk is probably not a great measure, but I don't know of a simple way to measure AST size of the outputs.

I'll check why the expensive test gets so much slower, perhaps it's just considering way more sub-expressions.

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.

3 participants