Skip to content

Commit 0894ef6

Browse files
committed
Try to handle abstract types.
There are no more Unknown names.
1 parent 9aa849e commit 0894ef6

File tree

6 files changed

+181
-95
lines changed

6 files changed

+181
-95
lines changed

jscomp/test/variant.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ function rollback_path(subst, p) {
8787
catch (exn){
8888
if (exn === Caml_builtin_exceptions.not_found) {
8989
switch (p.tag | 0) {
90-
case /* Unknown */1 :
90+
case /* Pdot */1 :
9191
return "Pdot";
92-
case /* Unknown */0 :
93-
case /* Unknown */2 :
92+
case /* Pident */0 :
93+
case /* Papply */2 :
9494
return "Pident | Papply";
9595

9696
}

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92389,30 +92389,73 @@ and do_compile_matching repr partial ctx arg pmh = match pmh with
9238992389
(combine_constant names pat.pat_loc arg cst partial)
9239092390
ctx pm
9239192391
| Tpat_construct (_, cstr, pats) ->
92392-
let names = match (Btype.repr pat.pat_type).desc with
92393-
| Tconstr (path, types, _) ->
92392+
let names_from_type_variant cstrs =
92393+
let (consts, blocks) = List.fold_left
92394+
(fun (consts, blocks) cstr ->
92395+
if cstr.Types.cd_args = []
92396+
then (Ident.name cstr.Types.cd_id :: consts, blocks)
92397+
else (consts, Ident.name cstr.Types.cd_id :: blocks))
92398+
([], []) cstrs in
92399+
Some {consts = consts |> List.rev |> Array.of_list;
92400+
blocks = blocks |> List.rev |> Array.of_list } in
92401+
92402+
92403+
(* let names = match (Btype.repr pat.pat_type).desc with
92404+
| Tconstr (path, _, _) ->
9239492405
let names = match (Env.find_type path pat.pat_env).type_kind with
9239592406
| 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-
let names = {consts = consts |> List.rev |> Array.of_list;
92403-
blocks = blocks |> List.rev |> Array.of_list } in
92404-
Some names
92407+
names_from_type_variant cstrs
9240592408
| Type_abstract ->
92406-
(* Format.eprintf "XXX Type_abstract@."; *)
92407-
Some {consts=[||]; blocks=[||]}
92409+
(match (Env.find_type path pat.pat_env).type_manifest with
92410+
| None -> Some {consts=[||]; blocks=[||]}
92411+
| Some t ->
92412+
match (Ctype.unalias t).desc with
92413+
| Tconstr (path1, _, _) ->
92414+
(* Format.eprintf "XXX path:%s@." (Path.name path);
92415+
Format.eprintf "XXX path1:%s@." (Path.name path1); *)
92416+
let names = match (Env.find_type path1 pat.pat_env).type_kind with
92417+
| Type_variant cstrs1 ->
92418+
names_from_type_variant cstrs1
92419+
| _ -> Some {consts=[||]; blocks=[||]} in
92420+
names
92421+
| _ -> Some {consts=[||]; blocks=[||]})
9240892422
| Type_record _ ->
9240992423
(* Format.eprintf "XXX Type_record@."; *)
9241092424
Some {consts=[||]; blocks=[||]}
9241192425
| Type_open ->
9241292426
(* Format.eprintf "XXX Type_open@."; *)
9241392427
Some {consts=[||]; blocks=[||]} in
9241492428
names
92429+
| _ -> assert false in *)
92430+
92431+
92432+
let names = match (Btype.repr pat.pat_type).desc with
92433+
| Tconstr (path, _, _) ->
92434+
let names = match Env.find_type path pat.pat_env with
92435+
| {type_kind = Type_variant cstrs} ->
92436+
names_from_type_variant cstrs
92437+
| {type_kind = Type_abstract; type_manifest = Some t} ->
92438+
( match (Ctype.unalias t).desc with
92439+
| Tconstr (path1, _, _) ->
92440+
(* Format.eprintf "XXX path:%s@." (Path.name path);
92441+
Format.eprintf "XXX path1:%s@." (Path.name path1); *)
92442+
( match Env.find_type path1 pat.pat_env with
92443+
| {type_kind = Type_variant cstrs1} ->
92444+
names_from_type_variant cstrs1
92445+
| _ -> Some {consts=[||]; blocks=[||]})
92446+
| _ -> Some {consts=[||]; blocks=[||]})
92447+
| {type_kind = Type_abstract; type_manifest = None} ->
92448+
(* Format.eprintf "XXX Type_abstract@."; *)
92449+
Some {consts=[||]; blocks=[||]}
92450+
| {type_kind = Type_record _} ->
92451+
(* Format.eprintf "XXX Type_record@."; *)
92452+
Some {consts=[||]; blocks=[||]}
92453+
| {type_kind = Type_open } ->
92454+
(* Format.eprintf "XXX Type_open@."; *)
92455+
Some {consts=[||]; blocks=[||]} in
92456+
names
9241592457
| _ -> assert false in
92458+
9241692459
compile_test
9241792460
(compile_match repr partial) partial
9241892461
divide_constructor (combine_constructor names pat.pat_loc arg pat cstr partial)

lib/4.02.3/whole_compiler.ml

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79909,30 +79909,73 @@ and do_compile_matching repr partial ctx arg pmh = match pmh with
7990979909
(combine_constant names pat.pat_loc arg cst partial)
7991079910
ctx pm
7991179911
| Tpat_construct (_, cstr, pats) ->
79912-
let names = match (Btype.repr pat.pat_type).desc with
79913-
| Tconstr (path, types, _) ->
79912+
let names_from_type_variant cstrs =
79913+
let (consts, blocks) = List.fold_left
79914+
(fun (consts, blocks) cstr ->
79915+
if cstr.Types.cd_args = []
79916+
then (Ident.name cstr.Types.cd_id :: consts, blocks)
79917+
else (consts, Ident.name cstr.Types.cd_id :: blocks))
79918+
([], []) cstrs in
79919+
Some {consts = consts |> List.rev |> Array.of_list;
79920+
blocks = blocks |> List.rev |> Array.of_list } in
79921+
79922+
79923+
(* let names = match (Btype.repr pat.pat_type).desc with
79924+
| Tconstr (path, _, _) ->
7991479925
let names = match (Env.find_type path pat.pat_env).type_kind with
7991579926
| 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-
let names = {consts = consts |> List.rev |> Array.of_list;
79923-
blocks = blocks |> List.rev |> Array.of_list } in
79924-
Some names
79927+
names_from_type_variant cstrs
7992579928
| Type_abstract ->
79926-
(* Format.eprintf "XXX Type_abstract@."; *)
79927-
Some {consts=[||]; blocks=[||]}
79929+
(match (Env.find_type path pat.pat_env).type_manifest with
79930+
| None -> Some {consts=[||]; blocks=[||]}
79931+
| Some t ->
79932+
match (Ctype.unalias t).desc with
79933+
| Tconstr (path1, _, _) ->
79934+
(* Format.eprintf "XXX path:%s@." (Path.name path);
79935+
Format.eprintf "XXX path1:%s@." (Path.name path1); *)
79936+
let names = match (Env.find_type path1 pat.pat_env).type_kind with
79937+
| Type_variant cstrs1 ->
79938+
names_from_type_variant cstrs1
79939+
| _ -> Some {consts=[||]; blocks=[||]} in
79940+
names
79941+
| _ -> Some {consts=[||]; blocks=[||]})
7992879942
| Type_record _ ->
7992979943
(* Format.eprintf "XXX Type_record@."; *)
7993079944
Some {consts=[||]; blocks=[||]}
7993179945
| Type_open ->
7993279946
(* Format.eprintf "XXX Type_open@."; *)
7993379947
Some {consts=[||]; blocks=[||]} in
7993479948
names
79949+
| _ -> assert false in *)
79950+
79951+
79952+
let names = match (Btype.repr pat.pat_type).desc with
79953+
| Tconstr (path, _, _) ->
79954+
let names = match Env.find_type path pat.pat_env with
79955+
| {type_kind = Type_variant cstrs} ->
79956+
names_from_type_variant cstrs
79957+
| {type_kind = Type_abstract; type_manifest = Some t} ->
79958+
( match (Ctype.unalias t).desc with
79959+
| Tconstr (path1, _, _) ->
79960+
(* Format.eprintf "XXX path:%s@." (Path.name path);
79961+
Format.eprintf "XXX path1:%s@." (Path.name path1); *)
79962+
( match Env.find_type path1 pat.pat_env with
79963+
| {type_kind = Type_variant cstrs1} ->
79964+
names_from_type_variant cstrs1
79965+
| _ -> Some {consts=[||]; blocks=[||]})
79966+
| _ -> Some {consts=[||]; blocks=[||]})
79967+
| {type_kind = Type_abstract; type_manifest = None} ->
79968+
(* Format.eprintf "XXX Type_abstract@."; *)
79969+
Some {consts=[||]; blocks=[||]}
79970+
| {type_kind = Type_record _} ->
79971+
(* Format.eprintf "XXX Type_record@."; *)
79972+
Some {consts=[||]; blocks=[||]}
79973+
| {type_kind = Type_open } ->
79974+
(* Format.eprintf "XXX Type_open@."; *)
79975+
Some {consts=[||]; blocks=[||]} in
79976+
names
7993579977
| _ -> assert false in
79978+
7993679979
compile_test
7993779980
(compile_match repr partial) partial
7993879981
divide_constructor (combine_constructor names pat.pat_loc arg pat cstr partial)

0 commit comments

Comments
 (0)