Skip to content

Commit 04dc4a5

Browse files
authored
Merge pull request #3982 from BuckleScript/record_label_renaming
record renaming support fix #3979
2 parents 405b34e + bf2558c commit 04dc4a5

37 files changed

+102798
-101812
lines changed

jscomp/common/bs_version.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* You should have received a copy of the GNU Lesser General Public License
2323
* along with this program; if not, write to the Free Software
2424
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
25-
let version = "6.3.0-dev.1"
25+
let version = "7.0.0-dev.2"
2626
let header =
2727
"// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE"
2828
let package_name = "bs-platform"

jscomp/core/bs_conditional_initial.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ let setup_env () =
3737
Clflags.binary_annotations := true;
3838
(* Turn on [-no-alias-deps] by default -- double check *)
3939
Oprint.out_ident := Outcome_printer_ns.out_ident;
40-
40+
Builtin_attributes.check_bs_attributes_inclusion := Record_attributes_check.check_bs_attributes_inclusion;
41+
Lambda.fld_record := Record_attributes_check.fld_record;
42+
Lambda.fld_record_set := Record_attributes_check.fld_record_set;
43+
Lambda.blk_record := Record_attributes_check.blk_record;
4144
#if undefined BS_RELEASE_BUILD then
4245
Printexc.record_backtrace true;
4346
(match Ext_sys.getenv_opt "BS_DEBUG_FILE" with

jscomp/core/js_dump.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,9 @@ and expression_desc cxt ~(level:int) f x : cxt =
811811
(Ext_list.map_combine fields el Ext_ident.convert)))
812812
| Caml_block(el,_, _, Blk_record fields) ->
813813
expression_desc cxt ~level f (Object (
814-
(Ext_list.map_combine (Array.to_list fields) el Ext_ident.convert)))
815-
(*FIXME: avoid allocaton *)
814+
(List.combine (Array.to_list fields) el )))
815+
(* name convention of Record is slight different from modules
816+
*)
816817
| Caml_block( el, mutable_flag, tag, tag_info)
817818
->
818819
(* Note that, if we ignore more than tag [0] we loose some information

jscomp/core/js_exp_make.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ let array_index_by_int ?comment (e : t) (pos : int32) : t =
397397
| _ -> { expression_desc = Array_index (e, int ?comment pos); comment = None}
398398

399399
let record_access (e : t) (name : string) (pos : int32) =
400-
let name = Ext_ident.convert name in
400+
(* let name = Ext_ident.convert name in *)
401401
match e.expression_desc with
402402
| Array (l,_) (* Float i -- should not appear here *)
403403
| Caml_block (l,_, _, _) when no_side_effect e

jscomp/core/js_of_lam_block.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let field (field_info : Lam_compat.field_dbg_info) e i =
6060
->
6161
E.array_index_by_int ~comment e i
6262
#end
63-
| Fld_record name
63+
| Fld_record {name}
6464
-> E.record_access e name i
6565
| Fld_module name
6666
-> E.module_access e name i

jscomp/core/lam_compat.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ type meth_kind = Lambda.meth_kind
184184

185185
type field_dbg_info = Lambda.field_dbg_info =
186186
| Fld_na
187-
| Fld_record of string
187+
| Fld_record of {name : string; mutable_flag : Asttypes.mutable_flag}
188188
| Fld_module of string
189189
#if OCAML_VERSION =~ ">4.03.0" then
190190
| Fld_record_inline of string
@@ -195,7 +195,7 @@ let str_of_field_info (x : field_dbg_info) : string option =
195195
match x with
196196
| Fld_na
197197
| Fld_tuple -> None
198-
| Fld_record s
198+
| Fld_record {name = s}
199199
| Fld_module s
200200
| Fld_record_inline s
201201
| Fld_record_extension s

jscomp/core/lam_compat.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type meth_kind = Lambda.meth_kind
8585

8686
type field_dbg_info = Lambda.field_dbg_info =
8787
| Fld_na
88-
| Fld_record of string
88+
| Fld_record of {name : string; mutable_flag : Asttypes.mutable_flag}
8989
| Fld_module of string
9090
#if OCAML_VERSION =~ ">4.03.0" then
9191
| Fld_record_inline of string
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
(* Copyright (C) 2019- Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
type label = Types.label_description
26+
27+
let fn = (fun (attr : Parsetree.attribute) ->
28+
match attr with
29+
| {txt = "bs.as"}, PStr
30+
[{pstr_desc = Pstr_eval ({pexp_desc = Pexp_constant (Pconst_string(s,_))},_ )}] ->
31+
(* Bs_ast_invariant.mark_used_bs_attribute attr; *)
32+
Some s
33+
| _ -> None
34+
)
35+
36+
let fld_record (lbl : label) =
37+
Lambda.Fld_record
38+
{name = Ext_list.find_def lbl.lbl_attributes fn lbl.lbl_name; mutable_flag = lbl.Types.lbl_mut}
39+
40+
let fld_record_set (lbl : label) =
41+
Lambda.Fld_record_set
42+
(Ext_list.find_def lbl.lbl_attributes fn lbl.lbl_name)
43+
44+
let blk_record fields =
45+
let all_labels_info =
46+
Ext_array.map fields
47+
(fun ((lbl : label),_) ->
48+
Ext_list.find_def lbl.Types.lbl_attributes fn lbl.lbl_name) in
49+
Lambda.Blk_record all_labels_info
50+
51+
let check_bs_attributes_inclusion
52+
(attrs1 : Parsetree.attributes)
53+
(attrs2 : Parsetree.attributes)
54+
lbl_name =
55+
let a = Ext_list.find_def attrs1 fn lbl_name in
56+
let b = Ext_list.find_def attrs2 fn lbl_name in
57+
if a = b then None
58+
else Some (a,b)
59+
60+
61+

jscomp/ext/ext_list.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,13 @@ let rec find_opt xs p =
583583
| Some _ as v -> v
584584
| None -> find_opt l p
585585

586-
586+
let rec find_def xs p def =
587+
match xs with
588+
| [] -> def
589+
| x::l ->
590+
match p x with
591+
| Some v -> v
592+
| None -> find_def l p def
587593

588594
let rec split_map l f =
589595
match l with

jscomp/ext/ext_list.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,13 @@ val find_opt :
259259
('a -> 'b option) ->
260260
'b option
261261

262+
val find_def :
263+
'a list ->
264+
('a -> 'b option) ->
265+
'b ->
266+
'b
262267

268+
263269
val rev_iter :
264270
'a list ->
265271
('a -> unit) ->

0 commit comments

Comments
 (0)