Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make forcing builtin functions pure and work-free #5627

Closed
wants to merge 5 commits into from

Conversation

zliu41
Copy link
Member

@zliu41 zliu41 commented Nov 11, 2023

and added a test.

@zliu41 zliu41 added the No Changelog Required Add this to skip the Changelog Check label Nov 11, 2023
<> dest
where
workFreedom = case dtermInner of
-- Forcing a builtin is workfree
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Forcing builtin functions is currently work-free. I don't know that there's any reason in principle why we couldn't have a builtin with only type arguments. If this is a constraint we should make sure we're checking it somewhere otherwise this could go wrong later.

@zliu41
Copy link
Member Author

zliu41 commented Nov 13, 2023

Forcing builtin functions is currently work-free

If it is currently work-free then I think we should do this.

The reason I want to do this is because it is needed by CSE. It's a bad idea to consider work-free items like force ifThenElse as a common expression. If isWorkFree doesn't work as it should, then I'd have to implement a totally separate one just for CSE.

@michaelpj
Copy link
Contributor

If it is currently work-free then I think we should do this.

Or we could come up with a more precise version. Forcing a builtin is work-free if the builtin does not have a single type argument.

You also possibly need to handle repeated forcing. In fact, doesn't the work-free check already look at whether the builtin is saturated, which should subsume this?

@zliu41
Copy link
Member Author

zliu41 commented Nov 13, 2023

You also possibly need to handle repeated forcing.

This is already being checked. This is what splitForces is for.

In fact, doesn't the work-free check already look at whether the builtin is saturated, which should subsume this?

No - the additional check I added does this; it isn't done currently.

@michaelpj
Copy link
Contributor

Ah, it's behind the PIR one. Seems better to bring it in line with the PIR one, which I think handles all builtin applications correctly? https://github.com/input-output-hk/plutus/blob/master/plutus-core/plutus-ir/src/PlutusIR/Purity.hs#L149

@zliu41
Copy link
Member Author

zliu41 commented Nov 14, 2023

Seems better to bring it in line with the PIR one, which I think handles all builtin applications correctly?

Yeah that seems the right thing to do

@zliu41
Copy link
Member Author

zliu41 commented Nov 14, 2023

Ok, I'll put this down as a good first task for newhires

@zliu41 zliu41 closed this Nov 14, 2023
@zeme-wana zeme-wana deleted the zliu41/force-bn branch June 20, 2024 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
No Changelog Required Add this to skip the Changelog Check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants