unison
unison copied to clipboard
Decompile failure with TVar
This probably isn't a very big deal, but I accidentally captured a TVar in a Debug.trace call and noticed that it hits a decompile issue.
main : '{Exception, IO} ()
main = do
m = atomically do TVar.new 0
Debug.trace "m" m
.> run main
trace: m
Couldn't decompile value.
Foreign (Wrap ##TVar _)
()
This is expected, you can’t decompile things like TVars and MVars! And it also doesn’t crash the program, which is good.
Maybe this could print out the TVar as <TVar> or some such just so you can see the rest of the expression?
@pchiusano yep I think that it would totally be fine to just print ##TVar _ for the TVar and show the rest of the expression. The Couldn't decompile value. printed to stdout makes it seem like we hit an unexpected decompilation bug.
So, decompilation has to produce an expression. What expression should one of these turn into?
Should something be added that is only used for information when decompiling, but wouldn't work if it somehow got into an expression to be evaluated?
I don't really know the right answer there, and I don't really know what the representation of an expression looks like in the decompiler. But I could potentially see decompiling into something like Opaque "TVar" or Opaque "Socket 21" for the purposes of pretty-printing Debug.trace output. But I don't know whether that actually makes sense.
It's probably not too likely that someone will call Debug.trace directly on a TVar, but it's fairly easy to call this on a larger structure that happens to contain TVars, socket handles, etc. But it's also hard to see this being a priority, so feel free to close as wontfix.
Here's another issue that comes up here. I cooked up a way to 'decompile' byte arrays using a fake builtin, so that I could see what was going on with something.
But, if you put that in a watch, the decompiled value gets saved in a cache, and will bomb if you ever run the original expression again, because your correct code gets replaced with fake code from the cache. That's probably not an issue with TVar, because you can't use it without IO. But anything that could go in a watch needs to be decompiled to a representation that will actually compile to an equivalent thing, or else it will cause issues down the line.