Skip to content

Failure to optimize simple tail call to a loop? #431

Closed
@ejgallego

Description

@ejgallego

The documentation says:

Tail call is not optimized in general. However, mutually recursive functions are optimized: self recursive functions (when the tail calls are the function itself) are compiled using a loop. trampolines are used otherwise.

However, this seems not to be the case in a particular part of Coq, see ejgallego/jscoq#13.

In particular, calls to generic_search with large arguments result in stack overflows. They are 100% correlated to the argument size. I need to investigate more, but in particular the codepath here is:

  MPmap.iter apply_mod_obj (ModObjs.all ());
  List.iter apply_node (Lib.contents ())

with MPmap.iter being the regular Map.iter.

Where did things go wrong?

Maybe some cMap trickery could be getting on the way?

https://github.com/ejgallego/coq/blob/jscoq-patchqueue/lib/cMap.ml

An example script illustrating the problem is at https://x80.org/collacoq/xupufegeno.coq We basically add enough definitions to the environnement such that iter will SO.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions