Skip to content

Commit 4f73c04

Browse files
committed
Proof of concept for extensible records
Uses convention on field name "dotdotdot", to be replaces with a parser producing e.g. a field called "...". Currently expands the type eagerly. See #5659
1 parent 503a54b commit 4f73c04

File tree

5 files changed

+67
-27
lines changed

5 files changed

+67
-27
lines changed

jscomp/ml/typedecl.ml

+23-1
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,27 @@ let transl_declaration env sdecl id =
446446
then Record_optional_labels optionalLabels
447447
else Record_regular
448448
in
449+
let lbls, lbls' = match lbls, lbls' with
450+
| {ld_name = {txt = "dotdotdot"}; ld_type} :: rest, _ :: rest' ->
451+
let rec extract t = match t.desc with
452+
| Tpoly(t, []) -> extract t
453+
| _ -> Ctype.repr t in
454+
let mkLbl (l: Types.label_declaration) : Typedtree.label_declaration =
455+
{ ld_id = l.ld_id;
456+
ld_name = {txt = Ident.name l.ld_id; loc = l.ld_loc};
457+
ld_mutable = l.ld_mutable;
458+
ld_type = {ld_type with ctyp_type = l.ld_type};
459+
ld_loc = l.ld_loc;
460+
ld_attributes = l.ld_attributes; } in
461+
let lbls, lbls' =
462+
match Ctype.extract_concrete_typedecl env (extract ld_type.ctyp_type) with
463+
(_p0, _p, {type_kind=Type_record (fields, _repr)}) ->
464+
(fields |> List.map mkLbl) @ rest, fields @ rest'
465+
| _ -> assert false
466+
| exception _ -> assert false
467+
in
468+
lbls, lbls'
469+
| _ -> lbls, lbls' in
449470
Ttype_record lbls, Type_record(lbls', rep)
450471
| Ptype_open -> Ttype_open, Type_open
451472
in
@@ -599,7 +620,8 @@ let check_constraints env sdecl (_, decl) =
599620
| Ptype_variant _ | Ptype_abstract | Ptype_open -> assert false
600621
in
601622
let pl = find_pl sdecl.ptype_kind in
602-
check_constraints_labels env visited l pl
623+
let todoFIXTHIS = false in
624+
if todoFIXTHIS then check_constraints_labels env visited l pl
603625
| Type_open -> ()
604626
end;
605627
begin match decl.type_manifest with

jscomp/test/DotDotDot.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
4+
var v = {
5+
x: 10,
6+
y: "",
7+
z: ""
8+
};
9+
10+
exports.v = v;
11+
/* No side effect */

jscomp/test/DotDotDot.res

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type a = {x: int}
2+
3+
type b = {dotdotdot: a, y: string}
4+
5+
type c = {dotdotdot: b, z: string}
6+
7+
let v: c = {x: 10, y: "", z: ""}

lib/es6/belt_internalBuckets.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import * as Curry from "./curry.js";
44
import * as Belt_Array from "./belt_Array.js";
55
import * as Caml_option from "./caml_option.js";
66

7+
function copyBucket(c) {
8+
if (c === undefined) {
9+
return c;
10+
}
11+
var head = {
12+
key: c.key,
13+
value: c.value,
14+
next: undefined
15+
};
16+
copyAuxCont(c.next, head);
17+
return head;
18+
}
19+
720
function copyAuxCont(_c, _prec) {
821
while(true) {
922
var prec = _prec;
@@ -23,19 +36,6 @@ function copyAuxCont(_c, _prec) {
2336
};
2437
}
2538

26-
function copyBucket(c) {
27-
if (c === undefined) {
28-
return c;
29-
}
30-
var head = {
31-
key: c.key,
32-
value: c.value,
33-
next: undefined
34-
};
35-
copyAuxCont(c.next, head);
36-
return head;
37-
}
38-
3939
function copyBuckets(buckets) {
4040
var len = buckets.length;
4141
var newBuckets = new Array(len);

lib/js/belt_internalBuckets.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ var Curry = require("./curry.js");
44
var Belt_Array = require("./belt_Array.js");
55
var Caml_option = require("./caml_option.js");
66

7+
function copyBucket(c) {
8+
if (c === undefined) {
9+
return c;
10+
}
11+
var head = {
12+
key: c.key,
13+
value: c.value,
14+
next: undefined
15+
};
16+
copyAuxCont(c.next, head);
17+
return head;
18+
}
19+
720
function copyAuxCont(_c, _prec) {
821
while(true) {
922
var prec = _prec;
@@ -23,19 +36,6 @@ function copyAuxCont(_c, _prec) {
2336
};
2437
}
2538

26-
function copyBucket(c) {
27-
if (c === undefined) {
28-
return c;
29-
}
30-
var head = {
31-
key: c.key,
32-
value: c.value,
33-
next: undefined
34-
};
35-
copyAuxCont(c.next, head);
36-
return head;
37-
}
38-
3939
function copyBuckets(buckets) {
4040
var len = buckets.length;
4141
var newBuckets = new Array(len);

0 commit comments

Comments
 (0)