mel-project / melodeon

1 stars 0 forks source link

Compilation of file hangs when it includes an expression #24

Open sadministrator opened 2 years ago

sadministrator commented 2 years ago

Although Melorun compiles function definitions in a file fairly quickly, compilation hangs indefinitely if you include a non-trivial expression to run in the same file; this does not occur when compiling only function definitions and running the same expression in the REPL.

The simplest way I could recreate this issue was trying to run a simple keccak hash keccak(1088, 512, [], 1, 32) in the file vs in the REPL.

nullchinchilla commented 2 years ago

The actual Melodeon compilation seems quite fast; the problem seems to be in mil again. I am looking into it further

nullchinchilla commented 2 years ago

I've tracked down the source of the issue actually as extremely slow execution of the code, which is due to a badly written optimization in the mil compiler that inappropriately inlines loops in such a way to cause multiply nested loops that take a very long time to run.

That bug has yet to be fixed, but it's exacerbated by a much more serious bug: weights for nested loops are calculated completely incorrectly. Not only does this break optimizations (by making optimizations that increase weight look like they decrease weight), it also makes fee calculations for covenants with nested loops completely wrong.

This has been fixed in the latest themelio-stf version, but bugfixes to mil are yet to be pushed.

nullchinchilla commented 2 years ago

I've released version v0.7.7 of melorun that simply disables all optimizations; that should temporarily fix this and allow testing programs. Interactive mode used to work because interactive mode disables optimizations.

sadministrator commented 2 years ago

Interesting detail about melorun REPL disabling optimizations. I'll go ahead and use the newest version then, compilation without optimizations seems fast enough on its own for now anyhow.