Skip to content

Commit 275c8b7

Browse files
committed
upgrade more syntax to 4.06
1 parent a1f3f36 commit 275c8b7

19 files changed

+615
-190
lines changed

jscomp/all.depend

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ syntax/ast_derive.cmx : ext/string_map.cmx ext/literals.cmx \
203203
syntax/ast_comb.cmx : ext/ext_list.cmx syntax/ast_literal.cmx \
204204
syntax/ast_compatible.cmx syntax/ast_comb.cmi
205205
syntax/ast_core_type.cmx : ext/ext_list.cmx syntax/bs_syntaxerr.cmx \
206-
syntax/ast_comb.cmx syntax/ast_core_type.cmi
206+
syntax/ast_compatible.cmx syntax/ast_comb.cmx syntax/ast_core_type.cmi
207207
syntax/bs_ast_invariant.cmx : ext/literals.cmx ext/hash_set_poly.cmx \
208208
ext/ext_string.cmx common/bs_warnings.cmx syntax/bs_ast_iterator.cmx \
209209
syntax/ast_core_type.cmx syntax/bs_ast_invariant.cmi
210210
syntax/ast_attributes.cmx : ext/ext_string.cmx syntax/bs_syntaxerr.cmx \
211211
syntax/bs_ast_invariant.cmx syntax/ast_payload.cmx \
212-
syntax/ast_attributes.cmi
212+
syntax/ast_compatible.cmx syntax/ast_attributes.cmi
213213
syntax/ast_polyvar.cmx : syntax/external_arg_spec.cmx ext/ext_pervasives.cmx \
214214
ext/ext_list.cmx syntax/bs_syntaxerr.cmx syntax/ast_attributes.cmx \
215215
syntax/ast_polyvar.cmi
@@ -299,7 +299,7 @@ syntax/bs_ast_mapper.cmi :
299299
syntax/ast_derive.cmi : syntax/ast_structure.cmi syntax/ast_signature.cmi \
300300
syntax/ast_payload.cmi
301301
syntax/ast_comb.cmi :
302-
syntax/ast_core_type.cmi :
302+
syntax/ast_core_type.cmi : syntax/ast_compatible.cmi
303303
syntax/bs_ast_invariant.cmi : syntax/bs_ast_iterator.cmi
304304
syntax/ast_attributes.cmi : syntax/ast_payload.cmi
305305
syntax/ast_polyvar.cmi : syntax/external_arg_spec.cmi

jscomp/bin/all_ounit_tests.ml

+51
Original file line numberDiff line numberDiff line change
@@ -14415,6 +14415,30 @@ val arrow :
1441514415
core_type ->
1441614416
core_type ->
1441714417
core_type
14418+
14419+
val label_arrow :
14420+
?loc:Location.t ->
14421+
?attrs:attrs ->
14422+
string ->
14423+
core_type ->
14424+
core_type ->
14425+
core_type
14426+
14427+
val opt_arrow:
14428+
?loc:Location.t ->
14429+
?attrs:attrs ->
14430+
string ->
14431+
core_type ->
14432+
core_type ->
14433+
core_type
14434+
14435+
val object_:
14436+
?loc:loc ->
14437+
?attrs:attrs ->
14438+
(string * attributes * core_type) list ->
14439+
(*FIXME shall we use [string loc] instead?*)
14440+
Asttypes.closed_flag ->
14441+
core_type
1441814442
end = struct
1441914443
#1 "ast_compatible.ml"
1442014444
(* Copyright (C) 2018 Authors of BuckleScript
@@ -14558,9 +14582,36 @@ let apply_labels
1455814582
fn,
1455914583
args ) }
1456014584

14585+
let object_ = Ast_helper.Typ.object_
14586+
1456114587

1456214588

1456314589

14590+
let label_arrow ?(loc=default_loc) ?(attrs=[]) s a b : core_type =
14591+
{
14592+
ptyp_desc = Ptyp_arrow(
14593+
14594+
s
14595+
14596+
,
14597+
a,
14598+
b);
14599+
ptyp_loc = loc;
14600+
ptyp_attributes = attrs
14601+
}
14602+
14603+
let opt_arrow ?(loc=default_loc) ?(attrs=[]) s a b : core_type =
14604+
{
14605+
ptyp_desc = Ptyp_arrow(
14606+
14607+
"?" ^ s
14608+
14609+
,
14610+
a,
14611+
b);
14612+
ptyp_loc = loc;
14613+
ptyp_attributes = attrs
14614+
}
1456414615

1456514616
let const_exp_int_list_as_array xs =
1456614617
Ast_helper.Exp.array

jscomp/syntax/ast_attributes.ml

+5-12
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,9 @@ let bs_get_arity : attr
360360
PStr
361361
[{pstr_desc =
362362
Pstr_eval (
363-
{pexp_desc =
364-
Pexp_constant
365-
(Const_int 1);
366-
pexp_loc = locg;
367-
pexp_attributes = []
368-
},[])
363+
Ast_compatible.const_exp_int ~loc:locg 1
364+
,
365+
[])
369366
; pstr_loc = locg}]
370367

371368

@@ -394,10 +391,6 @@ let deprecated s : attr =
394391
[
395392
{pstr_desc =
396393
Pstr_eval (
397-
{pexp_desc =
398-
Pexp_constant
399-
(Const_string (s,None));
400-
pexp_loc = locg;
401-
pexp_attributes = []
402-
},[])
394+
Ast_compatible.const_exp_string ~loc:locg s,
395+
[])
403396
; pstr_loc = locg}]

jscomp/syntax/ast_compatible.ml

+46
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ let apply_labels
141141
fn,
142142
Ext_list.map (fun (l,a) -> Asttypes.Labelled l, a) args ) }
143143

144+
let object_
145+
?(loc= default_loc)
146+
?(attrs = [])
147+
(fields : (string * attributes * core_type) list)
148+
(* FIXME after upgrade *)
149+
flg : core_type =
150+
{
151+
ptyp_desc =
152+
Ptyp_object(
153+
Ext_list.map (fun (a,b,c) ->
154+
Parsetree.Otag ({txt = a; loc = c.ptyp_loc},b,c)) fields,flg);
155+
ptyp_loc = loc;
156+
ptyp_attributes = attrs
157+
}
158+
144159
#else
145160

146161
let const_exp_string
@@ -179,9 +194,40 @@ let apply_labels
179194
fn,
180195
args ) }
181196

197+
let object_ = Ast_helper.Typ.object_
198+
182199

183200
#end
184201

202+
let label_arrow ?(loc=default_loc) ?(attrs=[]) s a b : core_type =
203+
{
204+
ptyp_desc = Ptyp_arrow(
205+
#if OCAML_VERSION =~ ">4.03.0" then
206+
Asttypes.Labelled s
207+
#else
208+
s
209+
#end
210+
,
211+
a,
212+
b);
213+
ptyp_loc = loc;
214+
ptyp_attributes = attrs
215+
}
216+
217+
let opt_arrow ?(loc=default_loc) ?(attrs=[]) s a b : core_type =
218+
{
219+
ptyp_desc = Ptyp_arrow(
220+
#if OCAML_VERSION =~ ">4.03.0" then
221+
Asttypes.Optional s
222+
#else
223+
"?" ^ s
224+
#end
225+
,
226+
a,
227+
b);
228+
ptyp_loc = loc;
229+
ptyp_attributes = attrs
230+
}
185231

186232
let const_exp_int_list_as_array xs =
187233
Ast_helper.Exp.array

jscomp/syntax/ast_compatible.mli

+25-1
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,28 @@ val arrow :
116116
?attrs:attrs ->
117117
core_type ->
118118
core_type ->
119-
core_type
119+
core_type
120+
121+
val label_arrow :
122+
?loc:Location.t ->
123+
?attrs:attrs ->
124+
string ->
125+
core_type ->
126+
core_type ->
127+
core_type
128+
129+
val opt_arrow:
130+
?loc:Location.t ->
131+
?attrs:attrs ->
132+
string ->
133+
core_type ->
134+
core_type ->
135+
core_type
136+
137+
val object_:
138+
?loc:loc ->
139+
?attrs:attrs ->
140+
(string * attributes * core_type) list ->
141+
(*FIXME shall we use [string loc] instead?*)
142+
Asttypes.closed_flag ->
143+
core_type

jscomp/syntax/ast_core_type.ml

+12-9
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,20 @@ let from_labels ~loc arity labels
138138
Typ.var ~loc ("a" ^ string_of_int i)))) in
139139
let result_type =
140140
Ast_comb.to_js_type loc
141-
(Typ.object_ ~loc
141+
(Ast_compatible.object_ ~loc
142142
(Ext_list.map2 (fun x y -> x.Asttypes.txt ,[], y) labels tyvars) Closed)
143143
in
144144
Ext_list.fold_right2
145145
(fun {Asttypes.loc ; txt = label }
146-
tyvar acc -> Typ.arrow ~loc label tyvar acc) labels tyvars result_type
146+
tyvar acc -> Ast_compatible.label_arrow ~loc label tyvar acc) labels tyvars result_type
147147

148148

149149
let make_obj ~loc xs =
150150
Ast_comb.to_js_type loc
151-
(Ast_helper.Typ.object_ ~loc xs Closed)
151+
(Ast_compatible.object_ ~loc xs Closed)
152+
152153

153154

154-
let opt_arrow loc label ty1 ty2 =
155-
Typ.arrow ~loc ("?" ^ label) ty1 ty2
156155
(**
157156
158157
{[ 'a . 'a -> 'b ]}
@@ -169,15 +168,19 @@ let rec get_uncurry_arity_aux (ty : t) acc =
169168
| _ -> acc
170169

171170
(**
172-
{[ unit -> 'a1 -> a2']} arity 2
173171
{[ unit -> 'b ]} return arity 0
172+
{[ unit -> 'a1 -> a2']} arity 2
174173
{[ 'a1 -> 'a2 -> ... 'aN -> 'b ]} return arity N
175174
*)
176175
let get_uncurry_arity (ty : t ) =
177176
match ty.ptyp_desc with
178-
| Ptyp_arrow("", {ptyp_desc = (Ptyp_constr ({txt = Lident "unit"}, []))},
179-
({ptyp_desc = Ptyp_arrow _ } as rest )) -> `Arity (get_uncurry_arity_aux rest 1 )
180-
| Ptyp_arrow("", {ptyp_desc = (Ptyp_constr ({txt = Lident "unit"}, []))}, _) -> `Arity 0
177+
| Ptyp_arrow(arg_label, {ptyp_desc = (Ptyp_constr ({txt = Lident "unit"}, []))},
178+
rest ) when Ast_compatible.is_arg_label_simple arg_label ->
179+
begin match rest with
180+
| {ptyp_desc = Ptyp_arrow _ } ->
181+
`Arity (get_uncurry_arity_aux rest 1 )
182+
| _ -> `Arity 0
183+
end
181184
| Ptyp_arrow(_,_,rest ) ->
182185
`Arity(get_uncurry_arity_aux rest 1)
183186
| _ -> `Not_function

jscomp/syntax/ast_core_type.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ val lift_option_type : t -> t
3232
val is_any : t -> bool
3333
val replace_result : t -> t -> t
3434

35-
val opt_arrow: Location.t -> string -> t -> t -> t
35+
(* val opt_arrow: Location.t -> string -> t -> t -> t *)
3636

3737
val is_unit : t -> bool
3838
val is_array : t -> bool
@@ -82,6 +82,6 @@ val get_uncurry_arity : t -> [`Arity of int | `Not_function ]
8282
(** fails when Ptyp_poly *)
8383
val list_of_arrow :
8484
t ->
85-
t * (Asttypes.label * t * Parsetree.attributes * Location.t) list
85+
t * (Ast_compatible.arg_label * t * Parsetree.attributes * Location.t) list
8686

8787
val is_arity_one : t -> bool

jscomp/syntax/ast_derive_abstract.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ let handleTdcl (tdcl : Parsetree.type_declaration) =
9494
let maker, acc =
9595
if is_optional then
9696
let optional_type = Ast_core_type.lift_option_type pld_type in
97-
(Ast_core_type.opt_arrow pld_loc label_name optional_type maker,
97+
(Ast_compatible.opt_arrow ~loc:pld_loc label_name optional_type maker,
9898
let aux b pld_name =
9999
(Val.mk ~loc:pld_loc
100100
(if b then pld_name else

jscomp/syntax/ast_derive_dyn.ml

+15-3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ let exp_of_core_type_exprs
182182

183183
let destruct_constructor_declaration
184184
({pcd_name = {txt ;loc}; pcd_args} : Parsetree.constructor_declaration) =
185+
#if OCAML_VERSION =~ ">4.03.0" then
186+
let pcd_args =
187+
match pcd_args with
188+
| Pcstr_tuple pcd_args -> pcd_args
189+
| Pcstr_record _ -> assert false in
190+
#end
185191
let last_i, core_type_exprs, pats =
186192
List.fold_left (fun (i,core_type_exps, pats) core_type ->
187193
let txt = "a" ^ string_of_int i in
@@ -279,10 +285,16 @@ let init () =
279285
if explict_nonrec then
280286
let names, arities =
281287
Ext_list.fold_right
282-
(fun (ctdcl : Parsetree.constructor_declaration)
288+
(fun ( {pcd_name = {txt}; pcd_args} : Parsetree.constructor_declaration)
283289
(names,arities) ->
284-
ctdcl.pcd_name.txt :: names,
285-
List.length ctdcl.pcd_args :: arities
290+
#if OCAML_VERSION =~ ">4.03.0" then
291+
let pcd_args =
292+
match pcd_args with
293+
| Pcstr_tuple pcd_args -> pcd_args
294+
| Pcstr_record _ -> assert false in
295+
#end
296+
txt :: names,
297+
List.length pcd_args :: arities
286298
) cd ([],[]) in
287299
constraint_
288300
[

jscomp/syntax/ast_derive_js_mapper.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ let init () =
432432

433433
let objType flag =
434434
Ast_comb.to_js_type loc @@
435-
Typ.object_
435+
Ast_compatible.object_
436436
(List.map
437437
(fun ({pld_name = {loc; txt }; pld_type } : Parsetree.label_declaration) ->
438438
txt, [], pld_type

jscomp/syntax/ast_derive_projector.ml

+20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ let invalid_config (config : Parsetree.expression) =
77

88
type tdcls = Parsetree.type_declaration list
99

10+
(* #if OCAML_VERSION =~ ">4.03.0" then
11+
let constructor_arguments_length (xs : Parsetree.constructor_arguments) =
12+
match xs with
13+
| Pcstr_tuple xs -> List.length xs
14+
| Pcstr_record xs -> List.length xs (* inline record FIXME*)
15+
#else
16+
let constructor_arguments_length = List.length
17+
#end *)
1018
let derivingName = "accessors"
1119
let init () =
1220

@@ -41,6 +49,12 @@ let init () =
4149
( {pcd_name = {loc ; txt = con_name} ; pcd_args ; pcd_loc }:
4250
Parsetree.constructor_declaration)
4351
-> (* TODO: add type annotations *)
52+
#if OCAML_VERSION =~ ">4.03.0" then
53+
let pcd_args =
54+
match pcd_args with
55+
| Pcstr_tuple pcd_args -> pcd_args
56+
| Pcstr_record _ -> assert false in
57+
#end
4458
let little_con_name = Ext_string.uncapitalize_ascii con_name in
4559
let arity = List.length pcd_args in
4660
Ast_comb.single_non_rec_value {loc ; txt = little_con_name}
@@ -106,6 +120,12 @@ let init () =
106120
(fun ({pcd_name = {loc ; txt = con_name} ; pcd_args ; pcd_loc }:
107121
Parsetree.constructor_declaration)
108122
->
123+
#if OCAML_VERSION =~ ">4.03.0" then
124+
let pcd_args =
125+
match pcd_args with
126+
| Pcstr_tuple pcd_args -> pcd_args
127+
| Pcstr_record _ -> assert false in
128+
#end
109129
Ast_comb.single_non_rec_val {loc ; txt = (Ext_string.uncapitalize_ascii con_name)}
110130
(Ext_list.fold_right
111131
(fun x acc -> Ast_compatible.arrow x acc)

0 commit comments

Comments
 (0)