From d05df0ef3f59428b83e2da44434c0c369ba3e08c Mon Sep 17 00:00:00 2001 From: Levi Roth Date: Wed, 3 Jul 2024 17:55:10 -0400 Subject: [PATCH] fix: compilation unit name conflicts with runtime sub-libraries. (#85) The libraries in subdirectories under `riot/runtime` have been merged into `runtime` itself. In various places we now need to refer to (e.g.) `Runtime.Core` instead of `Core` directly. To avoid name conflicts with the `Runtime` module itself (including via `Lib.Runtime`), I renamed `runtime` to `riot_runtime`. In all, the following compilation unit names have been purged from the global namespace: - Core - Log - Runtime - Scheduler - Time - Util --- bench/spawn_many.ml | 2 +- riot/dune | 2 +- riot/lib/dune | 2 +- riot/lib/global/dune | 2 +- riot/lib/global/global.ml | 6 +++--- riot/lib/hashmap.ml | 2 +- riot/lib/logger/dune | 2 +- riot/lib/logger/logger.ml | 8 ++++---- riot/lib/message.ml | 2 +- riot/lib/pid.ml | 2 +- riot/lib/process.ml | 4 ++-- riot/lib/queue.ml | 2 +- riot/lib/ref.ml | 2 +- riot/lib/runtime_lib.ml | 10 +++++----- riot/lib/telemetry_app.ml | 2 +- riot/riot.ml | 10 ++++++++++ riot/riot.mli | 2 +- riot/runtime/core/core.ml | 13 +++++++++++++ riot/runtime/core/dune | 4 ---- riot/runtime/dune | 14 ++++++++++++-- riot/runtime/log/dune | 4 ---- riot/runtime/{runtime.ml => riot_runtime.ml} | 1 + riot/runtime/scheduler/dune | 4 ---- riot/runtime/time/dune | 4 ---- riot/runtime/time/time.ml | 1 + riot/runtime/util/dune | 4 ---- riot/runtime/util/util.ml | 9 +++++++++ test/send_after_test.ml | 2 +- 28 files changed, 73 insertions(+), 49 deletions(-) create mode 100644 riot/runtime/core/core.ml delete mode 100644 riot/runtime/core/dune delete mode 100644 riot/runtime/log/dune rename riot/runtime/{runtime.ml => riot_runtime.ml} (82%) delete mode 100644 riot/runtime/scheduler/dune delete mode 100644 riot/runtime/time/dune create mode 100644 riot/runtime/time/time.ml delete mode 100644 riot/runtime/util/dune create mode 100644 riot/runtime/util/util.ml diff --git a/bench/spawn_many.ml b/bench/spawn_many.ml index 8763355c..8870cf32 100644 --- a/bench/spawn_many.ml +++ b/bench/spawn_many.ml @@ -7,7 +7,7 @@ module Test_app = struct let loop count = match receive_any () with - | Loop_stop -> Log.debug (fun f -> f "dead at %d%!" count) + | Loop_stop -> Riot_runtime.Log.debug (fun f -> f "dead at %d%!" count) let main t0 () = Logger.info (fun f -> f "boot test app"); diff --git a/riot/dune b/riot/dune index 77d79e2a..a90bf0c2 100644 --- a/riot/dune +++ b/riot/dune @@ -1,4 +1,4 @@ (library (name riot) (public_name riot) - (libraries lib runtime)) + (libraries lib riot_runtime)) diff --git a/riot/lib/dune b/riot/lib/dune index b2d83174..bbab4419 100644 --- a/riot/lib/dune +++ b/riot/lib/dune @@ -4,7 +4,7 @@ (libraries global logger - runtime + riot_runtime tls bytestring telemetry diff --git a/riot/lib/global/dune b/riot/lib/global/dune index 508bc647..9c251931 100644 --- a/riot/lib/global/dune +++ b/riot/lib/global/dune @@ -1,4 +1,4 @@ (library (package riot) (name global) - (libraries runtime)) + (libraries riot_runtime)) diff --git a/riot/lib/global/global.ml b/riot/lib/global/global.ml index 7ed38340..9e1ed8d3 100644 --- a/riot/lib/global/global.ml +++ b/riot/lib/global/global.ml @@ -1,7 +1,7 @@ -include Runtime.Import +include Riot_runtime.Import (* TODO(@leostera): move these into the Runtime module below *) -include Runtime.Core.Process.Exn -include Runtime.Core.Proc_registry.Exn +include Riot_runtime.Core.Process.Exn +include Riot_runtime.Core.Proc_registry.Exn let ( let* ) = Result.bind diff --git a/riot/lib/hashmap.ml b/riot/lib/hashmap.ml index 07bdb99c..bea2f768 100644 --- a/riot/lib/hashmap.ml +++ b/riot/lib/hashmap.ml @@ -1 +1 @@ -include Runtime.Util.Dashmap +include Riot_runtime.Util.Dashmap diff --git a/riot/lib/logger/dune b/riot/lib/logger/dune index a402884c..220cf7cb 100644 --- a/riot/lib/logger/dune +++ b/riot/lib/logger/dune @@ -1,4 +1,4 @@ (library (package riot) (name logger) - (libraries global runtime)) + (libraries global riot_runtime)) diff --git a/riot/lib/logger/logger.ml b/riot/lib/logger/logger.ml index 60050f07..eb26c057 100644 --- a/riot/lib/logger/logger.ml +++ b/riot/lib/logger/logger.ml @@ -1,5 +1,5 @@ -module Scheduler_uid = Runtime.Core.Scheduler_uid -module Log = Runtime.Log +module Scheduler_uid = Riot_runtime.Core.Scheduler_uid +module Log = Riot_runtime.Log open Global type opts = { print_source : bool; print_time : bool; color_output : bool } @@ -43,7 +43,7 @@ end type log = { level : level; ts : Ptime.t; - src : Scheduler_uid.t * Core.Pid.t; + src : Scheduler_uid.t * Riot_runtime.Core.Pid.t; ns : namespace; message : string; } @@ -55,7 +55,7 @@ let on_log log = !__on_log__ log let write : type a. level -> namespace -> (a, unit) logger_format -> unit = fun level ns msgf -> let ts = Ptime_clock.now () in - let sch = Scheduler.get_current_scheduler () in + let sch = Riot_runtime.Scheduler.get_current_scheduler () in let pid = self () in let src = (sch.uid, pid) in let buf = Buffer.create 128 in diff --git a/riot/lib/message.ml b/riot/lib/message.ml index a5f441d1..2f71d654 100644 --- a/riot/lib/message.ml +++ b/riot/lib/message.ml @@ -1 +1 @@ -include Runtime.Core.Message +include Riot_runtime.Core.Message diff --git a/riot/lib/pid.ml b/riot/lib/pid.ml index 1db86596..4f12fe7b 100644 --- a/riot/lib/pid.ml +++ b/riot/lib/pid.ml @@ -1 +1 @@ -include Runtime.Core.Pid +include Riot_runtime.Core.Pid diff --git a/riot/lib/process.ml b/riot/lib/process.ml index 3ac10fd1..c3d1c911 100644 --- a/riot/lib/process.ml +++ b/riot/lib/process.ml @@ -1,5 +1,5 @@ -open Runtime.Import -module P = Runtime.Core.Process +open Riot_runtime.Import +module P = Riot_runtime.Core.Process open Logger.Make (struct let namespace = [ "riot"; "process" ] diff --git a/riot/lib/queue.ml b/riot/lib/queue.ml index 0297196d..602ed062 100644 --- a/riot/lib/queue.ml +++ b/riot/lib/queue.ml @@ -1 +1 @@ -include Runtime.Util.Lf_queue +include Riot_runtime.Util.Lf_queue diff --git a/riot/lib/ref.ml b/riot/lib/ref.ml index cd4d7f64..469e19dc 100644 --- a/riot/lib/ref.ml +++ b/riot/lib/ref.ml @@ -1 +1 @@ -include Runtime.Core.Ref +include Riot_runtime.Core.Ref diff --git a/riot/lib/runtime_lib.ml b/riot/lib/runtime_lib.ml index c4fa9ff1..cb2c030a 100644 --- a/riot/lib/runtime_lib.ml +++ b/riot/lib/runtime_lib.ml @@ -1,6 +1,6 @@ open Global -let set_log_level = Runtime.Log.set_log_level +let set_log_level = Riot_runtime.Log.set_log_level let syscalls () = let pool = _get_pool () in @@ -26,11 +26,11 @@ module Stats = struct let total_schedulers = pool.schedulers |> List.length in let breakdown = pool.schedulers - |> List.map (fun (sch : Scheduler.t) -> + |> List.map (fun (sch : Riot_runtime.Scheduler.t) -> Format.asprintf " sch #%a [live_procs=%d; timers=%d]" - Runtime.Core.Scheduler_uid.pp sch.uid - (Runtime.Core.Proc_queue.size sch.run_queue) - (Runtime.Time.Timer_wheel.size sch.timers)) + Riot_runtime.Core.Scheduler_uid.pp sch.uid + (Riot_runtime.Core.Proc_queue.size sch.run_queue) + (Riot_runtime.Time.Timer_wheel.size sch.timers)) |> String.concat "\n" in info (fun f -> diff --git a/riot/lib/telemetry_app.ml b/riot/lib/telemetry_app.ml index 9e5502a0..15167029 100644 --- a/riot/lib/telemetry_app.ml +++ b/riot/lib/telemetry_app.ml @@ -5,7 +5,7 @@ type event = Telemetry.event = .. let name = "Riot.Telemetry" module Dispatcher = struct - type Core.Message.t += Event of Telemetry.event + type Riot_runtime.Core.Message.t += Event of Telemetry.event let __main_dispatcher__ : Pid.t ref = ref Pid.zero diff --git a/riot/riot.ml b/riot/riot.ml index aa8b5804..ae3a7614 100644 --- a/riot/riot.ml +++ b/riot/riot.ml @@ -1,5 +1,15 @@ include Lib +open struct + open Riot_runtime + module Log = Log + module Core = Core + module Import = Import + module Util = Util + module Scheduler = Scheduler + module Time = Time +end + open Logger.Make (struct let namespace = [ "riot" ] end) diff --git a/riot/riot.mli b/riot/riot.mli index c93cbea1..2f0e7d9d 100644 --- a/riot/riot.mli +++ b/riot/riot.mli @@ -141,7 +141,7 @@ module Process : sig [None] if no process was registered for that name. *) - val sid : t -> Core.Scheduler_uid.t + val sid : t -> Riot_runtime.Core.Scheduler_uid.t (** [sid t] returns the scheduler id for the scheduler in charge of the process. *) diff --git a/riot/runtime/core/core.ml b/riot/runtime/core/core.ml new file mode 100644 index 00000000..e85150ed --- /dev/null +++ b/riot/runtime/core/core.ml @@ -0,0 +1,13 @@ +module Core = Core +module Mailbox = Mailbox +module Message = Message +module Pid = Pid +module Proc_effect = Proc_effect +module Proc_queue = Proc_queue +module Proc_registry = Proc_registry +module Proc_set = Proc_set +module Proc_state = Proc_state +module Proc_table = Proc_table +module Process = Process +module Ref = Ref +module Scheduler_uid = Scheduler_uid diff --git a/riot/runtime/core/dune b/riot/runtime/core/dune deleted file mode 100644 index 0d8d5da8..00000000 --- a/riot/runtime/core/dune +++ /dev/null @@ -1,4 +0,0 @@ -(library - (package riot) - (name core) - (libraries log util gluon)) diff --git a/riot/runtime/dune b/riot/runtime/dune index 2ecf34cd..07049a8e 100644 --- a/riot/runtime/dune +++ b/riot/runtime/dune @@ -1,4 +1,14 @@ (library (package riot) - (name runtime) - (libraries core log scheduler time util rio)) + (name riot_runtime) + (libraries + gluon + mtime + mtime.clock.os + ptime + ptime.clock.os + rio + runtime_events + unix)) + +(include_subdirs unqualified) diff --git a/riot/runtime/log/dune b/riot/runtime/log/dune deleted file mode 100644 index 64904625..00000000 --- a/riot/runtime/log/dune +++ /dev/null @@ -1,4 +0,0 @@ -(library - (package riot) - (name log) - (libraries ptime ptime.clock.os)) diff --git a/riot/runtime/runtime.ml b/riot/runtime/riot_runtime.ml similarity index 82% rename from riot/runtime/runtime.ml rename to riot/runtime/riot_runtime.ml index 0b8c4081..11870954 100644 --- a/riot/runtime/runtime.ml +++ b/riot/runtime/riot_runtime.ml @@ -2,6 +2,7 @@ module Log = Log module Core = Core module Import = Import module Util = Util +module Scheduler = Scheduler module Time = Time let set_log_level = Log.set_log_level diff --git a/riot/runtime/scheduler/dune b/riot/runtime/scheduler/dune deleted file mode 100644 index d61828cf..00000000 --- a/riot/runtime/scheduler/dune +++ /dev/null @@ -1,4 +0,0 @@ -(library - (package riot) - (name scheduler) - (libraries core util gluon rio time log runtime_events)) diff --git a/riot/runtime/time/dune b/riot/runtime/time/dune deleted file mode 100644 index c87ccbd7..00000000 --- a/riot/runtime/time/dune +++ /dev/null @@ -1,4 +0,0 @@ -(library - (package riot) - (name time) - (libraries core rio mtime mtime.clock.os)) diff --git a/riot/runtime/time/time.ml b/riot/runtime/time/time.ml new file mode 100644 index 00000000..a978e50d --- /dev/null +++ b/riot/runtime/time/time.ml @@ -0,0 +1 @@ +module Timer_wheel = Timer_wheel diff --git a/riot/runtime/util/dune b/riot/runtime/util/dune deleted file mode 100644 index 16191f2e..00000000 --- a/riot/runtime/util/dune +++ /dev/null @@ -1,4 +0,0 @@ -(library - (package riot) - (name util) - (libraries log unix runtime_events)) diff --git a/riot/runtime/util/util.ml b/riot/runtime/util/util.ml new file mode 100644 index 00000000..19e6a5e9 --- /dev/null +++ b/riot/runtime/util/util.ml @@ -0,0 +1,9 @@ +module Dashmap = Dashmap +module Lf_queue = Lf_queue +module Min_heap = Min_heap +module Thread_local = Thread_local +module Timeout = Timeout +module Trace = Trace +module Uid = Uid +module Util = Util +module Weak_ref = Weak_ref diff --git a/test/send_after_test.ml b/test/send_after_test.ml index ed604ab8..83719b6f 100644 --- a/test/send_after_test.ml +++ b/test/send_after_test.ml @@ -43,7 +43,7 @@ let main () = Logger.info (fun f -> f "send_after_test: OK") | _ -> let messages = messages |> List.map msg_to_str |> String.concat "," in - Log.error (fun f -> f "bad message sequence: %s" messages); + Riot_runtime.Log.error (fun f -> f "bad message sequence: %s" messages); sleep 0.1; shutdown ~status:1 ()