Skip to content

Commit

Permalink
fix: improve cycle error messages
Browse files Browse the repository at this point in the history
Add human readable descriptions to various memoization functions

Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Nov 4, 2021
1 parent a4fbbfb commit b1fe9ef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 76 deletions.
5 changes: 5 additions & 0 deletions src/dune_engine/build_system.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,11 @@ end = struct

let eval_memo =
Memo.create "eval-pred"
~human_readable_description:(fun glob ->
Pp.concat
[ Pp.textf "evaluating predicate in directory %s"
(Path.to_string_maybe_quoted (File_selector.dir glob))
])
~input:(module File_selector)
~cutoff:Path.Set.equal eval_impl

Expand Down
8 changes: 7 additions & 1 deletion src/dune_rules/dir_contents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,13 @@ end = struct
Path.Build.Map.of_list_map_exn subdirs ~f:(fun x -> (x.dir, x))
}

let memo0 = Memo.create "dir-contents-get0" ~input:(module Key) get0_impl
let memo0 =
Memo.create "dir-contents-get0"
~input:(module Key)
~human_readable_description:(fun (_, dir) ->
Pp.textf "Computing directory contents of %s"
(Path.to_string_maybe_quoted (Path.build dir)))
get0_impl

let get sctx ~dir =
Memo.exec memo0 (sctx, dir) >>= function
Expand Down
9 changes: 8 additions & 1 deletion src/dune_rules/install_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -922,13 +922,20 @@ let memo =
in
Memo.create
~input:(module Sctx_and_package)
~human_readable_description:(fun (_, pkg) ->
Pp.textf "Computing installable artifacts for package %s"
(Package.Name.to_string (Package.name pkg)))
"install-rules-and-pkg-entries"
(fun (sctx, pkg) ->
Memo.Build.return
(let ctx = Super_context.context sctx in
let context_name = ctx.name in
let rules =
Memo.lazy_ ~name:"install-rules-and-pkg-entries-rules" (fun () ->
Memo.lazy_ ~name:"install-rules-and-pkg-entries-rules"
~human_readable_description:(fun () ->
Pp.textf "Computing rules for package %s"
(Package.Name.to_string (Package.name pkg)))
(fun () ->
Rules.collect_unit (fun () ->
let* () = install_rules sctx pkg in
install_alias ctx pkg))
Expand Down
79 changes: 5 additions & 74 deletions test/blackbox-tests/test-cases/reporting-of-cycles.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -79,79 +79,10 @@ This is a reproduction case from issue #4345
> (copy_files (files ../file))
> EOF
$ dune build --root .
Internal error, please report upstream including the contents of _build/log.
Description:
("internal dependency cycle",
{ frames =
[ ("eval-pred",
{ dir = In_build_dir "default"
; predicate = { id = Glob "file" }
; only_generated_files = false
})
; ("dir-contents-get0", ("default", "default/lib"))
; ("stanzas-to-entries", "default")
; ("install-rules-and-pkg-entries-rules", ())
; ("evaluate-restrict", ())
; ("restrict-by-child-non-default-inner", ())
; ("restrict-rules-here", ())
; ("load-dir", In_build_dir "default")
]
})
Raised at Memo.Exec.exec_dep_node.(fun) in file "src/memo/memo.ml", line
1338, characters 31-64
Called from Fiber.Execution_context.apply in file "src/fiber/fiber.ml", line
182, characters 9-14
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
Re-raised at Stdune__Exn.raise_with_backtrace in file
"otherlibs/stdune-unstable/exn.ml", line 36, characters 27-56
Called from Fiber.Execution_context.run_jobs in file "src/fiber/fiber.ml",
line 204, characters 8-13
-> required by ("build-alias", { dir = "default"; name = "default" })
-> required by ("toplevel", ())

I must not crash. Uncertainty is the mind-killer. Exceptions are the
little-death that brings total obliteration. I will fully express my cases.
Execution will pass over me and through me. And when it has gone past, I
will unwind the stack along its path. Where the cases are handled there will
be nothing. Only I will remain.
Error: Dependency cycle between:
Computing rules for package lib
-> evaluating predicate in directory _build/default
-> Computing directory contents of _build/default/lib
-> Computing rules for package lib
[1]
$ cd ..

0 comments on commit b1fe9ef

Please sign in to comment.