Skip to content

Commit 7bc7061

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 3aedb24 commit 7bc7061

10 files changed

+150
-43
lines changed

jscomp/main/builtin_cmj_datasets.ml

+3-3
Large diffs are not rendered by default.

jscomp/ml/typedecl.ml

+23-1
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,27 @@ let transl_declaration env sdecl id =
416416
then Record_optional_labels optionalLabels
417417
else Record_regular
418418
in
419+
let lbls, lbls' = match lbls, lbls' with
420+
| {ld_name = {txt = "dotdotdot"}; ld_type} :: rest, _ :: rest' ->
421+
let rec extract t = match t.desc with
422+
| Tpoly(t, []) -> extract t
423+
| _ -> Ctype.repr t in
424+
let mkLbl (l: Types.label_declaration) : Typedtree.label_declaration =
425+
{ ld_id = l.ld_id;
426+
ld_name = {txt = Ident.name l.ld_id; loc = l.ld_loc};
427+
ld_mutable = l.ld_mutable;
428+
ld_type = {ld_type with ctyp_type = l.ld_type};
429+
ld_loc = l.ld_loc;
430+
ld_attributes = l.ld_attributes; } in
431+
let lbls, lbls' =
432+
match Ctype.extract_concrete_typedecl env (extract ld_type.ctyp_type) with
433+
(_p0, _p, {type_kind=Type_record (fields, _repr)}) ->
434+
(fields |> List.map mkLbl) @ rest, fields @ rest'
435+
| _ -> assert false
436+
| exception _ -> assert false
437+
in
438+
lbls, lbls'
439+
| _ -> lbls, lbls' in
419440
Ttype_record lbls, Type_record(lbls', rep)
420441
| Ptype_open -> Ttype_open, Type_open
421442
in
@@ -569,7 +590,8 @@ let check_constraints env sdecl (_, decl) =
569590
| Ptype_variant _ | Ptype_abstract | Ptype_open -> assert false
570591
in
571592
let pl = find_pl sdecl.ptype_kind in
572-
check_constraints_labels env visited l pl
593+
let todoFIXTHIS = false in
594+
if todoFIXTHIS then check_constraints_labels env visited l pl
573595
| Type_open -> ()
574596
end;
575597
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: ""}

jscomp/test/build.ninja

+2-1
Large diffs are not rendered by default.

lib/4.06.1/unstable/js_compiler.ml

+26-4
Large diffs are not rendered by default.

lib/4.06.1/unstable/js_playground_compiler.ml

+26-4
Large diffs are not rendered by default.

lib/4.06.1/whole_compiler.ml

+26-4
Large diffs are not rendered by default.

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)