Skip to content

Commit 59fe755

Browse files
hyperpolymathclaude
andcommitted
refactor: migrate Js.Dict to Dict in src/shared/ (6 files)
Replace deprecated Js.Dict API with modern Dict equivalents in Coprocessor, Coprocessor_IO, DLCLoader, Kernel_Crypto, Kernel_Quantum, and ResourceAccounting. Part of #28. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bce352c commit 59fe755

File tree

6 files changed

+75
-75
lines changed

6 files changed

+75
-75
lines changed

src/shared/Coprocessor.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ type backend = {
6464

6565
// --- Global Registry ---
6666

67-
let backends: Js.Dict.t<backend> = Js.Dict.empty()
67+
let backends: dict<backend> = Dict.make()
6868

6969
let register = (b: backend): unit => {
70-
Js.Dict.set(backends, b.id, b)
70+
Dict.set(backends, b.id, b)
7171
Js.Console.log(`Coprocessor: Registered backend "${b.id}" for domain ${Domain.toString(b.domain)}`)
7272
}
7373

7474
let get = (id: string): option<backend> => {
75-
Js.Dict.get(backends, id)
75+
Dict.get(backends, id)
7676
}
7777

7878
let listByDomain = (d: Domain.t): array<backend> => {
79-
Js.Dict.values(backends)->Belt.Array.keep(b => b.domain == d)
79+
Dict.valuesToArray(backends)->Belt.Array.keep(b => b.domain == d)
8080
}
8181

8282
// --- Power Integration ---

src/shared/Coprocessor_IO.res

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ open Coprocessor
5858

5959
// Two-level dict: deviceId → (filePath → content).
6060
// Lazily populated on first access per device.
61-
let filesystems: Js.Dict.t<Js.Dict.t<array<int>>> = Js.Dict.empty()
61+
let filesystems: dict<dict<array<int>>> = Dict.make()
6262

6363
// Tombstone set for deleted paths.
6464
// Key format: deviceId ++ "\x00" ++ filePath.
6565
// Value true = deleted; false (or absent) = live.
66-
let deletedPaths: Js.Dict.t<bool> = Js.Dict.empty()
66+
let deletedPaths: dict<bool> = Dict.make()
6767

6868
// Retrieve (or lazily create) the file dict for a device.
69-
let getFs = (deviceId: string): Js.Dict.t<array<int>> =>
70-
switch Js.Dict.get(filesystems, deviceId) {
69+
let getFs = (deviceId: string): dict<array<int>> =>
70+
switch Dict.get(filesystems, deviceId) {
7171
| Some(fs) => fs
7272
| None =>
73-
let fs = Js.Dict.empty()
74-
Js.Dict.set(filesystems, deviceId, fs)
73+
let fs = Dict.make()
74+
Dict.set(filesystems, deviceId, fs)
7575
fs
7676
}
7777

@@ -81,18 +81,18 @@ let tombKey = (deviceId: string, path: string): string =>
8181

8282
// Return true if a path has been tombstoned on this device.
8383
let isTombstoned = (deviceId: string, path: string): bool =>
84-
switch Js.Dict.get(deletedPaths, tombKey(deviceId, path)) {
84+
switch Dict.get(deletedPaths, tombKey(deviceId, path)) {
8585
| Some(true) => true
8686
| _ => false
8787
}
8888

8989
// Mark a path as deleted.
9090
let tombstone = (deviceId: string, path: string): unit =>
91-
Js.Dict.set(deletedPaths, tombKey(deviceId, path), true)
91+
Dict.set(deletedPaths, tombKey(deviceId, path), true)
9292

9393
// Clear a tombstone so a subsequent write is visible again.
9494
let clearTombstone = (deviceId: string, path: string): unit =>
95-
Js.Dict.set(deletedPaths, tombKey(deviceId, path), false)
95+
Dict.set(deletedPaths, tombKey(deviceId, path), false)
9696

9797
// ---------------------------------------------------------------------------
9898
// Data encoding helpers
@@ -165,7 +165,7 @@ let cmdWrite = (deviceId: string, data: array<int>): executionResult => {
165165
} else {
166166
let fs = getFs(deviceId)
167167
let contentLen = Belt.Array.length(content)
168-
Js.Dict.set(fs, path, content)
168+
Dict.set(fs, path, content)
169169
clearTombstone(deviceId, path)
170170
{
171171
status: 0,
@@ -193,7 +193,7 @@ let cmdRead = (deviceId: string, data: array<int>): executionResult => {
193193
message: Some(`IO: read "${path}" not found (deleted)`)}
194194
} else {
195195
let fs = getFs(deviceId)
196-
switch Js.Dict.get(fs, path) {
196+
switch Dict.get(fs, path) {
197197
| None =>
198198
{status: 404, data: [], metrics: emptyMetrics,
199199
message: Some(`IO: read "${path}" not found`)}
@@ -221,7 +221,7 @@ let cmdList = (deviceId: string, data: array<int>): executionResult => {
221221
let prefix = decodePath(data)
222222
let fs = getFs(deviceId)
223223
let paths =
224-
Js.Dict.keys(fs)
224+
Dict.keysToArray(fs)
225225
->Belt.Array.keep(p =>
226226
!isTombstoned(deviceId, p) &&
227227
(Js.String2.length(prefix) == 0 || Js.String2.startsWith(p, prefix))
@@ -254,7 +254,7 @@ let cmdDelete = (deviceId: string, data: array<int>): executionResult => {
254254
} else {
255255
let fs = getFs(deviceId)
256256
let live =
257-
switch Js.Dict.get(fs, path) {
257+
switch Dict.get(fs, path) {
258258
| Some(_) => !isTombstoned(deviceId, path)
259259
| None => false
260260
}
@@ -287,7 +287,7 @@ let cmdStat = (deviceId: string, data: array<int>): executionResult => {
287287
0
288288
} else {
289289
let fs = getFs(deviceId)
290-
switch Js.Dict.get(fs, path) {
290+
switch Dict.get(fs, path) {
291291
| None => 0
292292
| Some(content) => Belt.Array.length(content)
293293
}

src/shared/DLCLoader.res

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ let inferTierFromInstructions = (instrs: array<string>): PuzzleFormat.tier => {
9898
let extractRegisters = (stateJson: Js.Json.t): array<(string, int)> => {
9999
switch Js.Json.classify(stateJson) {
100100
| JSONObject(dict) =>
101-
let keys = Js.Dict.keys(dict)
101+
let keys = Dict.keysToArray(dict)
102102
Belt.Array.keepMap(keys, key => {
103-
switch Js.Dict.get(dict, key) {
103+
switch Dict.get(dict, key) {
104104
| Some(v) =>
105105
switch Js.Json.classify(v) {
106106
| JSONNumber(n) => Some((key, Belt.Float.toInt(n)))
@@ -123,22 +123,22 @@ let parseHints = (json: Js.Json.t): array<PuzzleFormat.hint> => {
123123
| JSONString(s) => Some({PuzzleFormat.moveThreshold: 3, text: s})
124124
// Old format: {moveNumber, text} objects
125125
| JSONObject(dict) => {
126-
let text = switch Js.Dict.get(dict, "text") {
126+
let text = switch Dict.get(dict, "text") {
127127
| Some(v) =>
128128
switch Js.Json.classify(v) {
129129
| JSONString(s) => s
130130
| _ => ""
131131
}
132132
| None => ""
133133
}
134-
let threshold = switch Js.Dict.get(dict, "moveNumber") {
134+
let threshold = switch Dict.get(dict, "moveNumber") {
135135
| Some(v) =>
136136
switch Js.Json.classify(v) {
137137
| JSONNumber(n) => Belt.Float.toInt(n)
138138
| _ => 3
139139
}
140140
| None =>
141-
switch Js.Dict.get(dict, "moveThreshold") {
141+
switch Dict.get(dict, "moveThreshold") {
142142
| Some(v) =>
143143
switch Js.Json.classify(v) {
144144
| JSONNumber(n) => Belt.Float.toInt(n)
@@ -161,8 +161,8 @@ let parseHints = (json: Js.Json.t): array<PuzzleFormat.hint> => {
161161
}
162162

163163
// Get a string field from a JSON object
164-
let getString = (dict: Js.Dict.t<Js.Json.t>, key: string, default: string): string => {
165-
switch Js.Dict.get(dict, key) {
164+
let getString = (dict: dict<Js.Json.t>, key: string, default: string): string => {
165+
switch Dict.get(dict, key) {
166166
| Some(v) =>
167167
switch Js.Json.classify(v) {
168168
| JSONString(s) => s
@@ -173,8 +173,8 @@ let getString = (dict: Js.Dict.t<Js.Json.t>, key: string, default: string): stri
173173
}
174174

175175
// Get an int field from a JSON object
176-
let getInt = (dict: Js.Dict.t<Js.Json.t>, key: string, default: int): int => {
177-
switch Js.Dict.get(dict, key) {
176+
let getInt = (dict: dict<Js.Json.t>, key: string, default: int): int => {
177+
switch Dict.get(dict, key) {
178178
| Some(v) =>
179179
switch Js.Json.classify(v) {
180180
| JSONNumber(n) => Belt.Float.toInt(n)
@@ -185,8 +185,8 @@ let getInt = (dict: Js.Dict.t<Js.Json.t>, key: string, default: int): int => {
185185
}
186186

187187
// Get a string array from a JSON object
188-
let getStringArray = (dict: Js.Dict.t<Js.Json.t>, key: string): array<string> => {
189-
switch Js.Dict.get(dict, key) {
188+
let getStringArray = (dict: dict<Js.Json.t>, key: string): array<string> => {
189+
switch Dict.get(dict, key) {
190190
| Some(v) =>
191191
switch Js.Json.classify(v) {
192192
| JSONArray(arr) =>
@@ -211,7 +211,7 @@ let parsePuzzleJson = (id: string, jsonStr: string): option<PuzzleFormat.t> => {
211211
let description = getString(dict, "description", "")
212212
let difficulty = getString(dict, "difficulty", "beginner")->parseDifficulty
213213
let maxMoves = getInt(dict, "maxMoves", 50)
214-
let parMoves = switch Js.Dict.get(dict, "optimalMoves") {
214+
let parMoves = switch Dict.get(dict, "optimalMoves") {
215215
| Some(v) =>
216216
switch Js.Json.classify(v) {
217217
| JSONNumber(n) => Belt.Float.toInt(n)
@@ -221,28 +221,28 @@ let parsePuzzleJson = (id: string, jsonStr: string): option<PuzzleFormat.t> => {
221221
}
222222

223223
// Parse initial/goal state (supports both initialState and initialRegisters)
224-
let initialRegisters = switch Js.Dict.get(dict, "initialState") {
224+
let initialRegisters = switch Dict.get(dict, "initialState") {
225225
| Some(v) => extractRegisters(v)
226226
| None =>
227-
switch Js.Dict.get(dict, "initialRegisters") {
227+
switch Dict.get(dict, "initialRegisters") {
228228
| Some(v) => extractRegisters(v)
229229
| None => []
230230
}
231231
}
232-
let goalRegisters = switch Js.Dict.get(dict, "goalState") {
232+
let goalRegisters = switch Dict.get(dict, "goalState") {
233233
| Some(v) => extractRegisters(v)
234234
| None =>
235-
switch Js.Dict.get(dict, "goalRegisters") {
235+
switch Dict.get(dict, "goalRegisters") {
236236
| Some(v) => extractRegisters(v)
237237
| None => []
238238
}
239239
}
240240

241241
// Parse tier explicit, or inferred
242-
let tier = switch Js.Dict.get(dict, "tier") {
242+
let tier = switch Dict.get(dict, "tier") {
243243
| Some(v) => parseTier(v)
244244
| None => {
245-
let fromInstr = switch Js.Dict.get(dict, "allowedInstructions") {
245+
let fromInstr = switch Dict.get(dict, "allowedInstructions") {
246246
| Some(_) => {
247247
let instrs = getStringArray(dict, "allowedInstructions")
248248
if Belt.Array.length(instrs) > 0 {
@@ -271,7 +271,7 @@ let parsePuzzleJson = (id: string, jsonStr: string): option<PuzzleFormat.t> => {
271271
}
272272

273273
// Parse hints
274-
let hints = switch Js.Dict.get(dict, "hints") {
274+
let hints = switch Dict.get(dict, "hints") {
275275
| Some(v) => parseHints(v)
276276
| None => []
277277
}
@@ -282,7 +282,7 @@ let parsePuzzleJson = (id: string, jsonStr: string): option<PuzzleFormat.t> => {
282282
if Belt.Array.length(topLevel) > 0 {
283283
topLevel
284284
} else {
285-
switch Js.Dict.get(dict, "metadata") {
285+
switch Dict.get(dict, "metadata") {
286286
| Some(v) =>
287287
switch Js.Json.classify(v) {
288288
| JSONObject(metaDict) => getStringArray(metaDict, "tags")
@@ -316,59 +316,59 @@ let parsePuzzleJson = (id: string, jsonStr: string): option<PuzzleFormat.t> => {
316316

317317
// Serialize a puzzle to JSON (for bundle generation)
318318
let puzzleToJson = (p: PuzzleFormat.t): Js.Json.t => {
319-
let dict = Js.Dict.empty()
320-
Js.Dict.set(dict, "id", Js.Json.string(p.id))
321-
Js.Dict.set(dict, "name", Js.Json.string(p.name))
322-
Js.Dict.set(dict, "description", Js.Json.string(p.description))
323-
Js.Dict.set(dict, "difficulty", Js.Json.string(PuzzleFormat.difficultyToString(p.difficulty)))
324-
Js.Dict.set(dict, "tier", Js.Json.number(Belt.Int.toFloat(PuzzleFormat.tierToInt(p.tier))))
325-
Js.Dict.set(dict, "maxMoves", Js.Json.number(Belt.Int.toFloat(p.maxMoves)))
326-
Js.Dict.set(dict, "parMoves", Js.Json.number(Belt.Int.toFloat(p.parMoves)))
319+
let dict = Dict.make()
320+
Dict.set(dict, "id", Js.Json.string(p.id))
321+
Dict.set(dict, "name", Js.Json.string(p.name))
322+
Dict.set(dict, "description", Js.Json.string(p.description))
323+
Dict.set(dict, "difficulty", Js.Json.string(PuzzleFormat.difficultyToString(p.difficulty)))
324+
Dict.set(dict, "tier", Js.Json.number(Belt.Int.toFloat(PuzzleFormat.tierToInt(p.tier))))
325+
Dict.set(dict, "maxMoves", Js.Json.number(Belt.Int.toFloat(p.maxMoves)))
326+
Dict.set(dict, "parMoves", Js.Json.number(Belt.Int.toFloat(p.parMoves)))
327327

328328
// Registers as objects
329329
let regsToJson = (regs: array<(string, int)>): Js.Json.t => {
330-
let d = Js.Dict.empty()
330+
let d = Dict.make()
331331
Belt.Array.forEach(regs, ((k, v)) => {
332-
Js.Dict.set(d, k, Js.Json.number(Belt.Int.toFloat(v)))
332+
Dict.set(d, k, Js.Json.number(Belt.Int.toFloat(v)))
333333
})
334334
Js.Json.object_(d)
335335
}
336-
Js.Dict.set(dict, "initialRegisters", regsToJson(p.initialRegisters))
337-
Js.Dict.set(dict, "goalRegisters", regsToJson(p.goalRegisters))
336+
Dict.set(dict, "initialRegisters", regsToJson(p.initialRegisters))
337+
Dict.set(dict, "goalRegisters", regsToJson(p.goalRegisters))
338338

339339
// Memory pairs
340340
if Belt.Array.length(p.initialMemory) > 0 {
341341
let memToJson = (pairs: array<(int, int)>): Js.Json.t => {
342342
Js.Json.array(
343343
Belt.Array.map(pairs, ((addr, val_)) => {
344-
let d = Js.Dict.empty()
345-
Js.Dict.set(d, "addr", Js.Json.number(Belt.Int.toFloat(addr)))
346-
Js.Dict.set(d, "value", Js.Json.number(Belt.Int.toFloat(val_)))
344+
let d = Dict.make()
345+
Dict.set(d, "addr", Js.Json.number(Belt.Int.toFloat(addr)))
346+
Dict.set(d, "value", Js.Json.number(Belt.Int.toFloat(val_)))
347347
Js.Json.object_(d)
348348
}),
349349
)
350350
}
351-
Js.Dict.set(dict, "initialMemory", memToJson(p.initialMemory))
352-
Js.Dict.set(dict, "goalMemory", memToJson(p.goalMemory))
351+
Dict.set(dict, "initialMemory", memToJson(p.initialMemory))
352+
Dict.set(dict, "goalMemory", memToJson(p.goalMemory))
353353
}
354354

355355
// Allowed instructions
356356
switch p.allowedInstructions {
357357
| Some(instrs) =>
358-
Js.Dict.set(dict, "allowedInstructions", Js.Json.array(Belt.Array.map(instrs, Js.Json.string)))
358+
Dict.set(dict, "allowedInstructions", Js.Json.array(Belt.Array.map(instrs, Js.Json.string)))
359359
| None => ()
360360
}
361361

362362
// Hints
363363
if Belt.Array.length(p.hints) > 0 {
364-
Js.Dict.set(
364+
Dict.set(
365365
dict,
366366
"hints",
367367
Js.Json.array(
368368
Belt.Array.map(p.hints, h => {
369-
let d = Js.Dict.empty()
370-
Js.Dict.set(d, "moveThreshold", Js.Json.number(Belt.Int.toFloat(h.moveThreshold)))
371-
Js.Dict.set(d, "text", Js.Json.string(h.text))
369+
let d = Dict.make()
370+
Dict.set(d, "moveThreshold", Js.Json.number(Belt.Int.toFloat(h.moveThreshold)))
371+
Dict.set(d, "text", Js.Json.string(h.text))
372372
Js.Json.object_(d)
373373
}),
374374
),
@@ -377,18 +377,18 @@ let puzzleToJson = (p: PuzzleFormat.t): Js.Json.t => {
377377

378378
// Tags
379379
if Belt.Array.length(p.tags) > 0 {
380-
Js.Dict.set(dict, "tags", Js.Json.array(Belt.Array.map(p.tags, Js.Json.string)))
380+
Dict.set(dict, "tags", Js.Json.array(Belt.Array.map(p.tags, Js.Json.string)))
381381
}
382382

383383
Js.Json.object_(dict)
384384
}
385385

386386
// Serialize an array of puzzles to a bundle JSON string
387387
let bundleToJsonString = (puzzles: array<PuzzleFormat.t>): string => {
388-
let bundle = Js.Dict.empty()
389-
Js.Dict.set(bundle, "version", Js.Json.string("1.0.0"))
390-
Js.Dict.set(bundle, "generatedAt", Js.Json.string("build-time"))
391-
Js.Dict.set(bundle, "count", Js.Json.number(Belt.Int.toFloat(Belt.Array.length(puzzles))))
392-
Js.Dict.set(bundle, "puzzles", Js.Json.array(Belt.Array.map(puzzles, puzzleToJson)))
388+
let bundle = Dict.make()
389+
Dict.set(bundle, "version", Js.Json.string("1.0.0"))
390+
Dict.set(bundle, "generatedAt", Js.Json.string("build-time"))
391+
Dict.set(bundle, "count", Js.Json.number(Belt.Int.toFloat(Belt.Array.length(puzzles))))
392+
Dict.set(bundle, "puzzles", Js.Json.array(Belt.Array.map(puzzles, puzzleToJson)))
393393
Js.Json.stringify(Js.Json.object_(bundle))
394394
}

src/shared/Kernel_Crypto.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ let maxConcurrentCrypto = 3
3131

3232
// Active crypto call counts keyed by deviceId.
3333
// Lazily populated; never shrinks (counts reset to 0 rather than removed).
34-
let cryptoActiveCounts: Js.Dict.t<ref<int>> = Js.Dict.empty()
34+
let cryptoActiveCounts: dict<ref<int>> = Dict.make()
3535

3636
// Retrieve (or lazily create) the active-count ref for a device.
3737
let getCount = (deviceId: string): ref<int> =>
38-
switch Js.Dict.get(cryptoActiveCounts, deviceId) {
38+
switch Dict.get(cryptoActiveCounts, deviceId) {
3939
| Some(r) => r
4040
| None =>
4141
let r = ref(0)
42-
Js.Dict.set(cryptoActiveCounts, deviceId, r)
42+
Dict.set(cryptoActiveCounts, deviceId, r)
4343
r
4444
}
4545

0 commit comments

Comments
 (0)