Skip to content

Commit

Permalink
fix: compilation unit name conflicts with runtime sub-libraries. (#85)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
leviroth committed Jul 3, 2024
1 parent ac9e22f commit d05df0e
Show file tree
Hide file tree
Showing 28 changed files with 73 additions and 49 deletions.
2 changes: 1 addition & 1 deletion bench/spawn_many.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion riot/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name riot)
(public_name riot)
(libraries lib runtime))
(libraries lib riot_runtime))
2 changes: 1 addition & 1 deletion riot/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(libraries
global
logger
runtime
riot_runtime
tls
bytestring
telemetry
Expand Down
2 changes: 1 addition & 1 deletion riot/lib/global/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(package riot)
(name global)
(libraries runtime))
(libraries riot_runtime))
6 changes: 3 additions & 3 deletions riot/lib/global/global.ml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion riot/lib/hashmap.ml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include Runtime.Util.Dashmap
include Riot_runtime.Util.Dashmap
2 changes: 1 addition & 1 deletion riot/lib/logger/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(package riot)
(name logger)
(libraries global runtime))
(libraries global riot_runtime))
8 changes: 4 additions & 4 deletions riot/lib/logger/logger.ml
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion riot/lib/message.ml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include Runtime.Core.Message
include Riot_runtime.Core.Message
2 changes: 1 addition & 1 deletion riot/lib/pid.ml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include Runtime.Core.Pid
include Riot_runtime.Core.Pid
4 changes: 2 additions & 2 deletions riot/lib/process.ml
Original file line number Diff line number Diff line change
@@ -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" ]
Expand Down
2 changes: 1 addition & 1 deletion riot/lib/queue.ml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include Runtime.Util.Lf_queue
include Riot_runtime.Util.Lf_queue
2 changes: 1 addition & 1 deletion riot/lib/ref.ml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include Runtime.Core.Ref
include Riot_runtime.Core.Ref
10 changes: 5 additions & 5 deletions riot/lib/runtime_lib.ml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 ->
Expand Down
2 changes: 1 addition & 1 deletion riot/lib/telemetry_app.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions riot/riot.ml
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion riot/riot.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)

Expand Down
13 changes: 13 additions & 0 deletions riot/runtime/core/core.ml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions riot/runtime/core/dune

This file was deleted.

14 changes: 12 additions & 2 deletions riot/runtime/dune
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 0 additions & 4 deletions riot/runtime/log/dune

This file was deleted.

1 change: 1 addition & 0 deletions riot/runtime/runtime.ml → riot/runtime/riot_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions riot/runtime/scheduler/dune

This file was deleted.

4 changes: 0 additions & 4 deletions riot/runtime/time/dune

This file was deleted.

1 change: 1 addition & 0 deletions riot/runtime/time/time.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Timer_wheel = Timer_wheel
4 changes: 0 additions & 4 deletions riot/runtime/util/dune

This file was deleted.

9 changes: 9 additions & 0 deletions riot/runtime/util/util.ml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/send_after_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()

Expand Down

0 comments on commit d05df0e

Please sign in to comment.