From 0c5ff455d41bfeb51a9b2f4da1abf1d0b81eb618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Dimino?= Date: Wed, 13 Feb 2019 11:30:49 +0000 Subject: [PATCH] Better fix of the watch mode (#1839) Signed-off-by: Jeremie Dimino --- CHANGES.md | 2 +- src/memo/memo.ml | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e638534cf2d..cde3c12daf6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,7 @@ 1.7.1 (13/02/2019) ------------------ -- Fix the watch mode (#1837, fix #1836, @diml) +- Fix the watch mode (#1837, #1839, fix #1836, @diml) - Configurator: Fix misquoting when running pkg-config (#1835, fix #1833, @Chris00) diff --git a/src/memo/memo.ml b/src/memo/memo.ml index 6cdf90913ce..34416aaac45 100644 --- a/src/memo/memo.ml +++ b/src/memo/memo.ml @@ -63,7 +63,19 @@ end = struct let is_current t = !t end -let reset = Run.restart +(* We can get rid of this once we use the memoization system more + pervasively and all the dependencies are properly specified *) +module Caches = struct + let cleaners = ref [] + let register ~clear = + cleaners := clear :: !cleaners + let clear () = + List.iter !cleaners ~f:(fun f -> f ()) +end + +let reset () = + Caches.clear (); + Run.restart () module M = struct module Generic_dag = Dag @@ -166,16 +178,6 @@ module Cached_value = struct t.calculated_at <- Run.current (); Some t.data end - - (* We don't use this version of [get] yet as all the dependencies - are not yet properly specified. *) - let _ = get - - let get t = - if Run.is_current t.calculated_at then - Fiber.return (Some t.data) - else - Fiber.return None end let ser_input (type a) (node : (a, _) Dep_node.t) = @@ -301,7 +303,9 @@ module Make_gen (match Visibility.visibility with | Public -> Spec.register spec | Private -> ()); - { cache = Table.create 1024 + let cache = Table.create 1024 in + Caches.register ~clear:(fun () -> Table.clear cache); + { cache ; spec ; fdecl }