IntersectMBO / IntersectMBO/plutus

Removing extra bindings for function type argument

Open
#7,205 0 comments 1 reaction 0 assignees View on GitHub
Low priority optimization Plinth Plugin status: triaged
Dominant language
Haskell
Stars
1.6k
Forks
508
Avg merge
3d 10h
Merged PRs (30d)
22

Description

Check: https://github.com/IntersectMBO/plutus/pull/7199#discussion_r2201935863

The plugin will create extra binding to ensure evaluation of all the argument of a given function currently. However, this is not necessary for arguments whose types are function. This can be fixed by either/or of these two approaches: Changing `plutus-tx-plugin` to not generate binding when it compiles Haskell code into pir or having an extra optimization path that will take out bindings of function-typed function argument.

Example:
```hs
foo :: (Integer -> a) -> a
foo f = f 10

-- Compiles into (pseudocode)
foo = /\a -> \(f: Integer -> a) ->
let !f = f
in f 10

-- here we don't need this extra binding, it can simply be
foo = /\a -> \(f: Integer -> a) -> f 10
```

More complicated example can be found here: https://github.com/IntersectMBO/plutus/pull/7199/files#r2202044342

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.