plutus icon indicating copy to clipboard operation
plutus copied to clipboard

Remove `PlutusTx.Builtins` and replace with `PlutusTx.Builtins.Internal` or fix the design

Open colll78 opened this issue 10 months ago • 1 comments

https://github.com/IntersectMBO/plutus/blob/2596b5b93c100dc9c33c2848b37155cbb8503a21/plutus-tx/src/PlutusTx/Builtins.hs#L515

The name of this module and its functions leads a reasonable developer to expect that PlutusTx.Builtins exposes the interfaces for invoking PlutusCore builtins.

Thus the user of this module naturally expects unsafeDataAsList to be the public interface for the PlutusCore builtin function UnListData and to have the type signature:

unsafeDataAsList :: BuiltinData -> BuiltinList BuiltinData

compiling to:

PLC.UnListData

Instead unsafeDataAsList does not correspond to a PlutusCore builtin at all. This is a standard library concept that translates a BuiltinList to a SOP encoded list. It compiles to a function that applies UnDataAsList to BuiltinData and then recursively traverses the BuiltinList and constructs an SOP encoded equivalent which it returns.

It's not just unsafeDataAsList a huge portion of the functions exported by PlutusTx.Builtins are not builtins, and are instead standard library concepts that do things that are completely unrelated to the underlying builtin.

Please rename all such functions and move them into a different module or get rid of them entirely, or if that is too much work, at-least rename them so they don't have identical names to the ones exposed by PlutusTx.Builtins.Internal and entirely different behavior. The only thing this public module should be doing is calling fromOpaque/toOpaque on simple types for which it translates to a no-op (ie. for Integer to or Bool) and then directly calling the underlying builtin. It should not be using fromOpaque / toOpaque on containers like list, pair or map, where it translates to a recursive function or other work that is not just directly converting the type to call the underlying builtin.

colll78 avatar Apr 03 '25 23:04 colll78

Very good point, thanks for the suggestion!

zliu41 avatar Apr 15 '25 02:04 zliu41