ocamlbuild icon indicating copy to clipboard operation
ocamlbuild copied to clipboard

non-termination

Open agarwal opened this issue 9 years ago • 2 comments

To reproduce, create a directory with just the following file:

$ cat myocamlbuild.ml 
open Printf
open Ocamlbuild_plugin

let () = dispatch (function
  | After_rules -> (
      printf "BEFORE RULE\n%!";
      rule "m4" ~dep:"%.m4" ~prod:"%" (fun _ _ -> Nop);
      printf "AFTER RULE\n%!"
    )
  | _ -> ()
)

Now try to build anything:

$ ocamlbuild foo
Finished, 1 target (0 cached) in 00:00:00.
BEFORE RULE
AFTER RULE
(* program hangs ... never finishes here *)

The issue is related to the "%" pattern. A more specific pattern such as ~dep:"%.ml.m4" ~prod:"%.ml" avoids the problem. I guess the "%" pattern is too general and ocamlbuild goes into a loop trying to produce foo from foo.m4, which doesn't exist so it tries to produce that from foo.m4.m4, and so on.

agarwal avatar May 12 '16 20:05 agarwal

I'm not sure how reasonable it is to try to prevent this in all cases. If you had ~dep:"%" ~prod:"%", then I think the cycle detection algorithm would catch here. But here we don't have a cycle, I think the solver tries foo, then foo.ml4, then foo.ml4.ml4, etc. One thing that could be possible is compute the "depth of justification chain" and have a reasonable hard-coded limit (as, 10_000), in order to stop reasonably fast by human time standards and explain what is happening.

gasche avatar May 12 '16 22:05 gasche

Setting a max depth sounds like a sufficiently good solution.

agarwal avatar May 12 '16 22:05 agarwal