manuel-serrano / bigloo

a practical Scheme compiler
http://www-sop.inria.fr/indes/fp/Bigloo
Other
135 stars 19 forks source link

Stack overflow when using SRFI-1 version of filter-map #27

Closed justinethier closed 5 years ago

justinethier commented 5 years ago

The following program segfaults at runtime when using the SRFI 1 version of filter-map:

(module test
        (library srfi1)
)
(write
  (pair? (filter-map even? (iota 1800000))))

However, it works fine when the SRFI 1 library is commented-out, so the built-in version of filter-map is fine. It seems the version in SRFI 1 is not written in a way that can be safely tail-call optimized by Bigloo. Here is the stack trace from gdb. Note that when running into this in an actual program the stack trace was an order of magnitude smaller, so a much shorter list (~10000 elements) caused the crash:

#0  0x0026a583 in BGl_recurz72z72z72z72z72z72z72z72z00zz(short, long double, float, int, z, ) ()
   from /opt/autani/bigloo/lib/libbigloosrfi1_s-3.4a.so
...
#157233 0x0026a822 in BGl_recurz72z72z72z72z72z72z72z72z00zz(short, long double, float, int, z, ) ()
   from /opt/autani/bigloo/lib/libbigloosrfi1_s-3.4a.so
#157234 0x0026a93e in BGl_filterzd2mapzd2zz(short, long double, float, int, z, ) ()
   from /opt/autani/bigloo/lib/libbigloosrfi1_s-3.4a.so

Since the built-in filter-map can handle multiple list arguments, is there any reason to include the SRFI 1 version at all? Perhaps it should be removed like some of the other functions in that module.

There are probably other SRFI 1 functions affected as well.

manuel-serrano commented 5 years ago

Hi Justin,

The SRFI-1 library uses the reference implementation Shivers originally provided. This version might indeed not be optimal for Bigloo. When an equivalent native Bigloo function exists, I strongly recommend to use that version because it is very likely to be more efficient (because for instance, the compiler overrides many of these functions with faster macros).

However, they is not reason to leave that problem in SRFI-1 now we know it exists. I have then replaced the problematic implementation with the BIgloo native one.

Thanks for your report.

justinethier commented 5 years ago

No problem. Thanks @manuel-serrano !