Skip to content

Commit f18700b

Browse files
authored
Merge pull request #3966 from BuckleScript/refactor_meta_data_collection
Improve module coercion in strict subtyping, fix #3897
2 parents 49ba24e + 4783c8a commit f18700b

25 files changed

+288
-282
lines changed

jscomp/core/js_block_runtime.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ let tag_is_zero (tag : J.expression) =
3838
| Blk_record_inlined _ -> true
3939
#end
4040
| Blk_record _
41+
| Blk_module_export
4142
| Blk_module _ -> false
4243
| Blk_tuple
4344
| Blk_extension
@@ -53,6 +54,7 @@ let needBlockRuntime (tag : J.expression) (tag_info : J.tag_info) =
5354
match tag_info with
5455
| Blk_variant _
5556
| Blk_module _
57+
| Blk_module_export
5658
| Blk_record _
5759
| Blk_tuple
5860
| Blk_extension

jscomp/core/js_dump.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,8 @@ and expression_desc cxt ~(level:int) f x : cxt =
841841
(
842842
match tag_info with
843843
| Blk_record _
844-
| Blk_module _ ->
844+
| Blk_module _
845+
| Blk_module_export ->
845846
assert false
846847
(*
847848
This can not happen, see the pattern match on previous branch

jscomp/core/js_exp_make.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ let make_block ?comment
198198
(* TODO: may overriden its previous comments *)
199199
| Blk_record _
200200
| Blk_module _
201+
| Blk_module_export
201202
| Blk_tuple
202203
| Blk_array
203204
| Blk_extension_slot

jscomp/core/lam.ml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -646,30 +646,35 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t =
646646
end
647647
| _ -> default ()
648648
end
649-
650649
| _ ->
651-
652-
#if 0 then
653650
match prim with
654651
| Pmakeblock(size,Blk_module fields,_)->
655-
let rec aux fields args (var : Ident.t) =
652+
let rec aux fields args (var : Ident.t) i =
656653
match fields, args with
657654
| [], [] -> true
658-
| f :: fields, Lprim {primitive = Pfield (_, Fld_module f1); args = [Lglobal_module v1 | Lvar v1]} :: args
659-
-> f = f1 && Ident.same var v1 && aux fields args var
655+
| f :: fields, Lprim {primitive = Pfield (pos, Fld_module f1); args = [Lglobal_module v1 | Lvar v1]} :: args
656+
->
657+
pos = i &&
658+
f = f1 &&
659+
Ident.same var v1 && aux fields args var (i + 1)
660660
| _, _ -> false in
661661
begin match fields, args with
662662
| field1 :: rest,
663-
Lprim{primitive = Pfield (_, Fld_module f1); args = [Lglobal_module v1 | Lvar v1 as lam]} :: args1
663+
Lprim{primitive = Pfield (pos, Fld_module f1); args = [Lglobal_module v1 | Lvar v1 as lam]} :: args1
664664
->
665-
if field1 = f1 && aux rest args1 v1 then
665+
if pos = 0 && field1 = f1 && aux rest args1 v1 1 then
666666
lam
667667
else
668668
default ()
669669
| _ -> default ()
670-
end
670+
end
671+
(* In this level, include is already expanded, so that
672+
{[
673+
{ x0 : y0 ; x1 : y1 }
674+
]}
675+
such module x can indeed be replaced by module y
676+
*)
671677
| _ ->
672-
#end
673678
default ()
674679

675680
let not_ loc x : t =

jscomp/core/lam_compile_util.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ let comment_of_tag_info (x : Lam_tag_info.t) =
5252
| Blk_record_ext _ -> None
5353
#end
5454
| Blk_array -> Some "array"
55+
| Blk_module_export
5556
| Blk_module _ ->
5657
(* Turn it on next time to save some noise diff*)
5758
None

jscomp/core/lam_constant_convert.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ let rec convert_constant ( const : Lambda.structured_constant) : Lam_constant.t
7777
| Blk_module s ->
7878
let t : Lam_tag_info.t = Blk_module s in
7979
Const_block (i,t, Ext_list.map xs convert_constant )
80+
| Blk_module_export s ->
81+
let t : Lam_tag_info.t = Blk_module_export in
82+
Const_block (i,t, Ext_list.map xs convert_constant )
8083
| Blk_extension_slot ->
8184
let t : Lam_tag_info.t = Blk_extension_slot in
8285
Const_block (i,t, Ext_list.map xs convert_constant )

jscomp/core/lam_convert.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
252252
| Blk_module s ->
253253
let info : Lam_tag_info.t = Blk_module s in
254254
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
255+
| Blk_module_export _ ->
256+
let info : Lam_tag_info.t = Blk_module_export in
257+
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
255258
| Blk_extension_slot ->
256259
let info : Lam_tag_info.t = Blk_extension_slot in
257260
(

jscomp/core/lam_tag_info.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ type t =
4141
| Blk_record_inlined of string array * string * int
4242
| Blk_record_ext of string array
4343
#end
44-
| Blk_class
44+
| Blk_class
45+
| Blk_module_export

jscomp/test/build.ninja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ build test/gpr_3865_foo.cmi test/gpr_3865_foo.cmj : cc test/gpr_3865_foo.re | $s
310310
build test/gpr_3875_test.cmi test/gpr_3875_test.cmj : cc test/gpr_3875_test.ml | test/mt.cmj $stdlib
311311
build test/gpr_3877_test.cmi test/gpr_3877_test.cmj : cc test/gpr_3877_test.ml | $stdlib
312312
build test/gpr_3895_test.cmi test/gpr_3895_test.cmj : cc test/gpr_3895_test.ml | $stdlib
313+
build test/gpr_3897_test.cmi test/gpr_3897_test.cmj : cc test/gpr_3897_test.ml | $stdlib
313314
build test/gpr_3931_test.cmi test/gpr_3931_test.cmj : cc test/gpr_3931_test.ml | $stdlib
314315
build test/gpr_405_test.cmj : cc_cmi test/gpr_405_test.ml | test/gpr_405_test.cmi $stdlib
315316
build test/gpr_405_test.cmi : cc test/gpr_405_test.mli | $stdlib

jscomp/test/defunctor_make_test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ function getcompare(x) {
88
}
99

1010
function Make(M) {
11-
return {
12-
compare: M.compare
13-
};
11+
return M;
1412
}
1513

1614
var Comparable = {

0 commit comments

Comments
 (0)