haskell / alex

A lexical analyser generator for Haskell
https://hackage.haskell.org/package/alex
BSD 3-Clause "New" or "Revised" License
297 stars 82 forks source link

Compiled with alex-3.2.2, Agda segfaults #116

Closed andreasabel closed 7 years ago

andreasabel commented 7 years ago

We are experiencing problems with alex-3.2.2, see https://github.com/agda/agda/issues/2736. alex-3.2.1 seems to work fine.

nad commented 7 years ago

The problem is most likely that Alex 3.2.2 breaks long strings over several lines using backslash characters at the end of the lines, with the expectation that the code will be processed by a standard C preprocessor that joins the lines again. Agda code is by default processed using cpphs, which does not touch these end-of-line backslashes, leaving code that by accident stands for valid Haskell strings with string gaps. See https://github.com/agda/agda/issues/2736#issuecomment-327916143 and #84.

simonmar commented 7 years ago

Ok, I propose to revert 73bee2f2622004a400d58694475c919c70ee8af2. Any comments @sergv?

sergv commented 7 years ago

It seems that cpphs just does not remove backslashes at end of line and I cannot find any option to make it remove them. It seems that cpphs will play nicely with standard multi-line literals like

foo =
  "bar\
  \baz\
  \quux"

but they conflict with system-wide -traditional C preprocessor. So, I guess, if we're determined to support both cpphs and system-wide preprocessors then we have to concede that there's no way to have multi-line string literals and thus revert the patch.

I have another idea on how to solve this without reverting, although it's a bit less pretty. Namely, declare that for cpphs alex must be run without -g flag, i.e. without ghc extensions. In this mode it will generate mutli-line array literals which do not depend on preprocessor at all. But this approach requires special-casing cpphs and may bring a performance hit (I'm not sure how big it will be though).

simonmar commented 7 years ago

3.2.3 released including the revert.