Skip to content

Commit 99ae454

Browse files
committed
Move function switch_track_names_of_constructors to bucklescript.
Sync up ocaml too.
1 parent e91c5fe commit 99ae454

File tree

4 files changed

+117
-61
lines changed

4 files changed

+117
-61
lines changed

jscomp/core/lam_compile.ml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,38 @@ type default_case =
9393
let no_effects_const = lazy true
9494
let has_effects_const = lazy false
9595

96+
let names_from_construct_pattern (pat: Typedtree.pattern) =
97+
let names_from_type_variant cstrs =
98+
let (consts, blocks) = List.fold_left
99+
(fun (consts, blocks) cstr ->
100+
if cstr.Types.cd_args = []
101+
then (Ident.name cstr.Types.cd_id :: consts, blocks)
102+
else (consts, Ident.name cstr.Types.cd_id :: blocks))
103+
([], []) cstrs in
104+
Some {Lambda.consts = consts |> List.rev |> Array.of_list;
105+
blocks = blocks |> List.rev |> Array.of_list } in
106+
107+
let rec resolve_path n path =
108+
match Env.find_type path pat.pat_env with
109+
| {type_kind = Type_variant cstrs} ->
110+
names_from_type_variant cstrs
111+
| {type_kind = Type_abstract; type_manifest = Some t} ->
112+
( match (Ctype.unalias t).desc with
113+
| Tconstr (pathn, _, _) ->
114+
(* Format.eprintf "XXX path%d:%s path%d:%s@." n (Path.name path) (n+1) (Path.name pathn); *)
115+
resolve_path (n+1) pathn
116+
| _ -> None)
117+
| {type_kind = Type_abstract; type_manifest = None} ->
118+
None
119+
| {type_kind = Type_record _ | Type_open (* Exceptions *) } ->
120+
None in
121+
122+
match (Btype.repr pat.pat_type).desc with
123+
| Tconstr (path, _, _) -> resolve_path 0 path
124+
| _ -> assert false
125+
126+
let () = Matching.names_from_construct_pattern := names_from_construct_pattern
127+
96128
(** We drop the ability of cross-compiling
97129
the compiler has to be the same running
98130
*)

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89497,6 +89497,9 @@ val expand_stringswitch:
8949789497

8949889498
val inline_lazy_force : lambda -> Location.t -> lambda
8949989499

89500+
(* To be set by Lam_compile *)
89501+
val names_from_construct_pattern : (pattern -> switch_names option) ref
89502+
8950089503
end = struct
8950189504
#1 "matching.ml"
8950289505
(***********************************************************************)
@@ -92321,6 +92324,9 @@ let arg_to_var arg cls = match arg with
9232192324
let v = name_pattern "match" cls in
9232292325
v,Lvar v
9232392326

92327+
(* To be set by Lam_compile *)
92328+
let names_from_construct_pattern : (pattern -> switch_names option) ref =
92329+
ref (fun _ -> assert false)
9232492330

9232592331
(*
9232692332
The main compilation function.
@@ -92392,38 +92398,12 @@ and do_compile_matching repr partial ctx arg pmh = match pmh with
9239292398
(combine_constant names pat.pat_loc arg cst partial)
9239392399
ctx pm
9239492400
| Tpat_construct (_, cstr, pats) ->
92395-
let names_from_type_variant cstrs =
92396-
let (consts, blocks) = List.fold_left
92397-
(fun (consts, blocks) cstr ->
92398-
if cstr.Types.cd_args = []
92399-
then (Ident.name cstr.Types.cd_id :: consts, blocks)
92400-
else (consts, Ident.name cstr.Types.cd_id :: blocks))
92401-
([], []) cstrs in
92402-
Some {consts = consts |> List.rev |> Array.of_list;
92403-
blocks = blocks |> List.rev |> Array.of_list } in
92404-
92405-
let rec resolve_path n path =
92406-
match Env.find_type path pat.pat_env with
92407-
| {type_kind = Type_variant cstrs} ->
92408-
names_from_type_variant cstrs
92409-
| {type_kind = Type_abstract; type_manifest = Some t} ->
92410-
( match (Ctype.unalias t).desc with
92411-
| Tconstr (pathn, _, _) ->
92412-
(* Format.eprintf "XXX path%d:%s path%d:%s@." n (Path.name path) (n+1) (Path.name pathn); *)
92413-
resolve_path (n+1) pathn
92414-
| _ -> None)
92415-
| {type_kind = Type_abstract; type_manifest = None} ->
92416-
None
92417-
| {type_kind = Type_record _ | Type_open (* Exceptions *) } ->
92418-
None in
92419-
92420-
let names = match (Btype.repr pat.pat_type).desc with
92421-
| Tconstr (path, _, _) -> resolve_path 0 path
92422-
| _ -> assert false in
92423-
92401+
let sw_names = if !Clflags.bs_only
92402+
then !names_from_construct_pattern pat
92403+
else None in
9242492404
compile_test
9242592405
(compile_match repr partial) partial
92426-
divide_constructor (combine_constructor names pat.pat_loc arg pat cstr partial)
92406+
divide_constructor (combine_constructor sw_names pat.pat_loc arg pat cstr partial)
9242792407
ctx pm
9242892408
| Tpat_array _ ->
9242992409
let names = None in
@@ -110768,6 +110748,38 @@ type default_case =
110768110748
let no_effects_const = lazy true
110769110749
let has_effects_const = lazy false
110770110750

110751+
let names_from_construct_pattern (pat: Typedtree.pattern) =
110752+
let names_from_type_variant cstrs =
110753+
let (consts, blocks) = List.fold_left
110754+
(fun (consts, blocks) cstr ->
110755+
if cstr.Types.cd_args = []
110756+
then (Ident.name cstr.Types.cd_id :: consts, blocks)
110757+
else (consts, Ident.name cstr.Types.cd_id :: blocks))
110758+
([], []) cstrs in
110759+
Some {Lambda.consts = consts |> List.rev |> Array.of_list;
110760+
blocks = blocks |> List.rev |> Array.of_list } in
110761+
110762+
let rec resolve_path n path =
110763+
match Env.find_type path pat.pat_env with
110764+
| {type_kind = Type_variant cstrs} ->
110765+
names_from_type_variant cstrs
110766+
| {type_kind = Type_abstract; type_manifest = Some t} ->
110767+
( match (Ctype.unalias t).desc with
110768+
| Tconstr (pathn, _, _) ->
110769+
(* Format.eprintf "XXX path%d:%s path%d:%s@." n (Path.name path) (n+1) (Path.name pathn); *)
110770+
resolve_path (n+1) pathn
110771+
| _ -> None)
110772+
| {type_kind = Type_abstract; type_manifest = None} ->
110773+
None
110774+
| {type_kind = Type_record _ | Type_open (* Exceptions *) } ->
110775+
None in
110776+
110777+
match (Btype.repr pat.pat_type).desc with
110778+
| Tconstr (path, _, _) -> resolve_path 0 path
110779+
| _ -> assert false
110780+
110781+
let () = Matching.names_from_construct_pattern := names_from_construct_pattern
110782+
110771110783
(** We drop the ability of cross-compiling
110772110784
the compiler has to be the same running
110773110785
*)

lib/4.02.3/whole_compiler.ml

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77017,6 +77017,9 @@ val expand_stringswitch:
7701777017

7701877018
val inline_lazy_force : lambda -> Location.t -> lambda
7701977019

77020+
(* To be set by Lam_compile *)
77021+
val names_from_construct_pattern : (pattern -> switch_names option) ref
77022+
7702077023
end = struct
7702177024
#1 "matching.ml"
7702277025
(***********************************************************************)
@@ -79841,6 +79844,9 @@ let arg_to_var arg cls = match arg with
7984179844
let v = name_pattern "match" cls in
7984279845
v,Lvar v
7984379846

79847+
(* To be set by Lam_compile *)
79848+
let names_from_construct_pattern : (pattern -> switch_names option) ref =
79849+
ref (fun _ -> assert false)
7984479850

7984579851
(*
7984679852
The main compilation function.
@@ -79912,38 +79918,12 @@ and do_compile_matching repr partial ctx arg pmh = match pmh with
7991279918
(combine_constant names pat.pat_loc arg cst partial)
7991379919
ctx pm
7991479920
| Tpat_construct (_, cstr, pats) ->
79915-
let names_from_type_variant cstrs =
79916-
let (consts, blocks) = List.fold_left
79917-
(fun (consts, blocks) cstr ->
79918-
if cstr.Types.cd_args = []
79919-
then (Ident.name cstr.Types.cd_id :: consts, blocks)
79920-
else (consts, Ident.name cstr.Types.cd_id :: blocks))
79921-
([], []) cstrs in
79922-
Some {consts = consts |> List.rev |> Array.of_list;
79923-
blocks = blocks |> List.rev |> Array.of_list } in
79924-
79925-
let rec resolve_path n path =
79926-
match Env.find_type path pat.pat_env with
79927-
| {type_kind = Type_variant cstrs} ->
79928-
names_from_type_variant cstrs
79929-
| {type_kind = Type_abstract; type_manifest = Some t} ->
79930-
( match (Ctype.unalias t).desc with
79931-
| Tconstr (pathn, _, _) ->
79932-
(* Format.eprintf "XXX path%d:%s path%d:%s@." n (Path.name path) (n+1) (Path.name pathn); *)
79933-
resolve_path (n+1) pathn
79934-
| _ -> None)
79935-
| {type_kind = Type_abstract; type_manifest = None} ->
79936-
None
79937-
| {type_kind = Type_record _ | Type_open (* Exceptions *) } ->
79938-
None in
79939-
79940-
let names = match (Btype.repr pat.pat_type).desc with
79941-
| Tconstr (path, _, _) -> resolve_path 0 path
79942-
| _ -> assert false in
79943-
79921+
let sw_names = if !Clflags.bs_only
79922+
then !names_from_construct_pattern pat
79923+
else None in
7994479924
compile_test
7994579925
(compile_match repr partial) partial
79946-
divide_constructor (combine_constructor names pat.pat_loc arg pat cstr partial)
79926+
divide_constructor (combine_constructor sw_names pat.pat_loc arg pat cstr partial)
7994779927
ctx pm
7994879928
| Tpat_array _ ->
7994979929
let names = None in
@@ -101882,6 +101862,38 @@ type default_case =
101882101862
let no_effects_const = lazy true
101883101863
let has_effects_const = lazy false
101884101864

101865+
let names_from_construct_pattern (pat: Typedtree.pattern) =
101866+
let names_from_type_variant cstrs =
101867+
let (consts, blocks) = List.fold_left
101868+
(fun (consts, blocks) cstr ->
101869+
if cstr.Types.cd_args = []
101870+
then (Ident.name cstr.Types.cd_id :: consts, blocks)
101871+
else (consts, Ident.name cstr.Types.cd_id :: blocks))
101872+
([], []) cstrs in
101873+
Some {Lambda.consts = consts |> List.rev |> Array.of_list;
101874+
blocks = blocks |> List.rev |> Array.of_list } in
101875+
101876+
let rec resolve_path n path =
101877+
match Env.find_type path pat.pat_env with
101878+
| {type_kind = Type_variant cstrs} ->
101879+
names_from_type_variant cstrs
101880+
| {type_kind = Type_abstract; type_manifest = Some t} ->
101881+
( match (Ctype.unalias t).desc with
101882+
| Tconstr (pathn, _, _) ->
101883+
(* Format.eprintf "XXX path%d:%s path%d:%s@." n (Path.name path) (n+1) (Path.name pathn); *)
101884+
resolve_path (n+1) pathn
101885+
| _ -> None)
101886+
| {type_kind = Type_abstract; type_manifest = None} ->
101887+
None
101888+
| {type_kind = Type_record _ | Type_open (* Exceptions *) } ->
101889+
None in
101890+
101891+
match (Btype.repr pat.pat_type).desc with
101892+
| Tconstr (path, _, _) -> resolve_path 0 path
101893+
| _ -> assert false
101894+
101895+
let () = Matching.names_from_construct_pattern := names_from_construct_pattern
101896+
101885101897
(** We drop the ability of cross-compiling
101886101898
the compiler has to be the same running
101887101899
*)

ocaml

Submodule ocaml updated from 2c3a6d8 to 5b63735

0 commit comments

Comments
 (0)