IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.56k stars 479 forks source link

Allow trace to dump arbitrary expressions. #4269

Closed phadej closed 1 year ago

phadej commented 2 years ago

Currently trace can dump only Text values. That is very limiting. Allowing to dump arbitrary values (including Data) would be very helpful for print-style debugging.

michaelpj commented 2 years ago

Related: https://github.com/input-output-hk/plutus/issues/3164

Dumping arbitrary values is not easy, we'd need an on-chain Show class, along with showing builtins for all the builtin types. It would be easy to accidentally incur a dependency on Show, which would bring in a lot of bulky code (since it will have lots of strings in it). So while this would be nice, it's quite a lot of work and I'd be a little concerned about using it...

phadej commented 2 years ago

we'd need an on-chain Show class,

I don't think so. I'll be perfectly fine with emulator dumping some version of internal representation. Definitely not Show, that would be expensive/slow. trace is for debugging. Having something closer to anythingToString then `show. If it's

trace :: a -> b -> b -- no restriction on a

Then Plutus won't be able to observe how values are serialized, and that is completely fine.

michaelpj commented 2 years ago

What are the semantics of that? I don't want to add something that exposes the innards in a non-principled way. Then we can't change the implementation! If we could make it available only off-chain that might work, but at the moment we don't have an easy way of doing that.

phadej commented 2 years ago

AFAIK on-chain cannot expect the traced messages now either. From the formalization perspective the traced messages could be PLC-values (instead of Text). I haven't looked at the formalization, so I don't know what you do now. I think even having a subclass of Maybe Text as traced messages would be enough to ensure ordering of trace messages (as if textual traces are ordered, then by parametricity of trace all other messages are too).

effectfully commented 1 year ago

Currently trace can dump only Text values. That is very limiting. Allowing to dump arbitrary values (including Data)

@zliu41 @michaelpj given #4777 our current answer seems to be "won't do"? Could you remind me why this PR was closed?

We're also working on a debugger which will probably alleviate the need for a polymorphic version of trace.

zliu41 commented 1 year ago

We added the PlutusTx.Show class last year so I think this issue can be closed.

4777 was closed because PlutusTx.Show does not require new builtins. All instances can be written using existing stuff.

And yes, Show is expensive. A production script is supposed to have trace removed via remove-trace.

effectfully commented 1 year ago

Great, thanks a lot.