AnyDSL / artic

The AlteRnaTive Impala Compiler
MIT License
25 stars 6 forks source link

Flush printed ast #12

Closed michael-kenzel closed 2 years ago

michael-kenzel commented 2 years ago

Code that triggers assertions within artic/thorin causes the compiler to terminate. An attempt to use --print-ast to produce a repro for such code is likely to result in disappointment as process termination caused by the abort caused by the assertion will leave stdout unflushed and, thus, parts of the printed AST unprinted. This PR aims to fix that by flushing the output stream after printing the AST.

Hugobros3 commented 2 years ago

this sounds weird, in my experience writing \n has always flushed the output when writing out to the terminal, and likewise when the process dies. maybe this is different on windows (assuming you still work on windows) ?

according to this, using std::endl instead of \n should trigger a flush, can you see if that works on your end ? that would be the most elegant thing IMO

michael-kenzel commented 2 years ago

Outputting a '\n' is not guaranteed to flush unless the stream is line-buffered, which it doesn't have to be (and typically won't be on Windows, terminals on Linux tend to be yes). FWIF, I encountered the problem using vscode on Windows but working on Linux in WSL.

Use of std::endl is generally discouraged since the implicit flush is not something most people are even aware of. Since the flush is relevant for functionality here, I would certainly prefer explicitly flushing. It also wouldn't work anyways because log::out isn't an std::ostream and lacks the necessary operator << overload. In fact, that was actually the first thing I tried, and I considered adding the overload but opted to just log::out.stream.flush() instead for the sake of clarity and simplicity.

Hugobros3 commented 2 years ago

Well looks like you did your homework, merging it then