Skip to content

Commit 9eef10d

Browse files
committed
Add support for Set, Map, WeakSet and WeakMap to @unboxed
1 parent 5ce1de7 commit 9eef10d

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

compiler/ml/ast_untagged_variants.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ module Instance = struct
1919
| Uint32Array
2020
| Uint8Array
2121
| Uint8ClampedArray
22+
| Set
23+
| Map
24+
| WeakSet
25+
| WeakMap
2226
let to_string = function
2327
| Array -> "Array"
2428
| ArrayBuffer -> "ArrayBuffer"
@@ -39,6 +43,10 @@ module Instance = struct
3943
| Uint32Array -> "Uint32Array"
4044
| Uint8Array -> "Uint8Array"
4145
| Uint8ClampedArray -> "Uint8ClampedArray"
46+
| Set -> "Set"
47+
| Map -> "Map"
48+
| WeakSet -> "WeakSet"
49+
| WeakMap -> "WeakMap"
4250
end
4351

4452
type untagged_error =
@@ -256,6 +264,10 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) =
256264
| "Stdlib.Uint8ClampedArray.t" -> Some Uint8ClampedArray
257265
| "Js_file.t" -> Some File
258266
| "Js_blob.t" -> Some Blob
267+
| "Stdlib.Set.t" -> Some Set
268+
| "Stdlib.Map.t" -> Some Map
269+
| "Stdlib.WeakSet.t" -> Some WeakSet
270+
| "Stdlib.WeakMap.t" -> Some WeakMap
259271
| _ -> None)
260272
| _ -> None
261273

tests/tests/src/UntaggedVariants.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,22 @@ async function classifyAll(t) {
573573
console.log("DataView");
574574
return;
575575
}
576+
if (t instanceof Set) {
577+
console.log("Set");
578+
return;
579+
}
580+
if (t instanceof Map) {
581+
console.log("Map");
582+
return;
583+
}
584+
if (t instanceof WeakSet) {
585+
console.log("WeakSet");
586+
return;
587+
}
588+
if (t instanceof WeakMap) {
589+
console.log("WeakMap");
590+
return;
591+
}
576592
switch (typeof t) {
577593
case "string" :
578594
console.log(t);

tests/tests/src/UntaggedVariants.res

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ module AllInstanceofTypes = {
413413
| BigInt64Array(BigInt64Array.t)
414414
| BigUint64Array(BigUint64Array.t)
415415
| DataView(DataView.t)
416+
| Set(Set.t<string>)
417+
| Map(Map.t<string, unknown>)
418+
| WeakSet(WeakSet.t<string>)
419+
| WeakMap(WeakMap.t<string, unknown>)
416420

417421
let classifyAll = async (t: t) =>
418422
switch t {
@@ -437,6 +441,10 @@ module AllInstanceofTypes = {
437441
| BigInt64Array(_) => Console.log("BigInt64Array")
438442
| BigUint64Array(_) => Console.log("BigUint64Array")
439443
| DataView(_) => Console.log("DataView")
444+
| Set(_) => Console.log("Set")
445+
| Map(_) => Console.log("Map")
446+
| WeakSet(_) => Console.log("WeakSet")
447+
| WeakMap(_) => Console.log("WeakMap")
440448
}
441449
}
442450

0 commit comments

Comments
 (0)