lhs2tex icon indicating copy to clipboard operation
lhs2tex copied to clipboard

Loop on uppercase argument names

Open Blaisorblade opened this issue 7 years ago • 1 comments

The following loops and leaks memory quickly. This got my lhs2TeX up to 23GB RAM usage—took me a while to kill it. Replacing Bar by bar fixes it—because Bar is not a valid variable name. I understand I made a mistake, but I imagine in principle this could be reported better than by looping.

% Emacs, this is -*- latex -*-!
%include polycode.fmt

%format baz Bar = "hi"
|baz a|

Parsing is done at https://github.com/kosmikus/lhs2tex/blob/master/src/Directives.lhs#L121-L122 and at https://github.com/kosmikus/lhs2tex/blob/master/src/Directives.lhs#L53-L64.

It seems my directive somehow passes the parser, because

%format ( baz Bar ) = "hi"

gives a syntax error.

*** Error in file ./pldi14/foo.lhs line 4:
syntax error in directive
 ( baz Bar ) = {-"hi"-}

The same happens with 1bar rather than Bar: %format baz 1bar = "hi" loops but %format (baz 1bar) = "hi" gives a syntax error.

It seems the equation is parsed successfully but it's not clear how and to what.

Blaisorblade avatar May 16 '17 23:05 Blaisorblade

This fits the general theme of:

Actually, I just discovered that this is a general problem if you try to implicitly format anything that's not recognized properly. So even in Haskell mode, the definition and use of the following formatting directive causes a stack overflow:

https://github.com/kosmikus/lhs2tex/issues/33#issuecomment-29065363

I suspect having a configurable maximum expansion depth (defaulting, say, to 1000) would be the most robust fix for all the "infinite loop" issues (especially for actual infinite loops, which can't be fixed otherwise).

Blaisorblade avatar May 17 '17 00:05 Blaisorblade