Skip to content

Commit 9d91b5d

Browse files
committed
Resolve abstract types recursively.
1 parent 57795d6 commit 9d91b5d

File tree

4 files changed

+49
-55
lines changed

4 files changed

+49
-55
lines changed

jscomp/test/ocaml_typedtree_test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45230,7 +45230,7 @@ function rollback_path(subst, _p) {
4523045230
catch (exn){
4523145231
if (exn === Caml_builtin_exceptions.not_found) {
4523245232
switch (p.tag | 0) {
45233-
case /* Unknown */1 :
45233+
case /* Pdot */1 :
4523445234
var p1 = p[0];
4523545235
var p1$prime = rollback_path(subst, p1);
4523645236
if (same(p1, p1$prime)) {
@@ -45243,8 +45243,8 @@ function rollback_path(subst, _p) {
4524345243
]);
4524445244
continue ;
4524545245
}
45246-
case /* Unknown */0 :
45247-
case /* Unknown */2 :
45246+
case /* Pident */0 :
45247+
case /* Papply */2 :
4524845248
return p;
4524945249

4525045250
}
@@ -45258,7 +45258,7 @@ function rollback_path(subst, _p) {
4525845258
function collect_ids(subst, bindings, p) {
4525945259
var match = rollback_path(subst, p);
4526045260
switch (match.tag | 0) {
45261-
case /* Unknown */0 :
45261+
case /* Pident */0 :
4526245262
var id = match[0];
4526345263
var ids;
4526445264
try {
@@ -45272,8 +45272,8 @@ function collect_ids(subst, bindings, p) {
4527245272
}
4527345273
}
4527445274
return add$11(id, ids);
45275-
case /* Unknown */1 :
45276-
case /* Unknown */2 :
45275+
case /* Pdot */1 :
45276+
case /* Papply */2 :
4527745277
return /* Empty */0;
4527845278

4527945279
}

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92399,31 +92399,28 @@ and do_compile_matching repr partial ctx arg pmh = match pmh with
9239992399
Some {consts = consts |> List.rev |> Array.of_list;
9240092400
blocks = blocks |> List.rev |> Array.of_list } in
9240192401

92402+
let rec resolve_path n path =
92403+
match Env.find_type path pat.pat_env with
92404+
| {type_kind = Type_variant cstrs} ->
92405+
names_from_type_variant cstrs
92406+
| {type_kind = Type_abstract; type_manifest = Some t} ->
92407+
( match (Ctype.unalias t).desc with
92408+
| Tconstr (pathn, _, _) ->
92409+
(* Format.eprintf "XXX path%d:%s path%d:%s@." n (Path.name path) (n+1) (Path.name pathn); *)
92410+
resolve_path (n+1) pathn
92411+
| _ -> assert false)
92412+
| {type_kind = Type_abstract; type_manifest = None} ->
92413+
(* Format.eprintf "XXX Type_abstract@."; *)
92414+
Some {consts=[||]; blocks=[||]}
92415+
| {type_kind = Type_record _} ->
92416+
(* Format.eprintf "XXX Type_record@."; *)
92417+
Some {consts=[||]; blocks=[||]}
92418+
| {type_kind = Type_open } ->
92419+
(* Format.eprintf "XXX Type_open@."; *)
92420+
Some {consts=[||]; blocks=[||]} in
92421+
9240292422
let names = match (Btype.repr pat.pat_type).desc with
92403-
| Tconstr (path, _, _) ->
92404-
let names = match Env.find_type path pat.pat_env with
92405-
| {type_kind = Type_variant cstrs} ->
92406-
names_from_type_variant cstrs
92407-
| {type_kind = Type_abstract; type_manifest = Some t} ->
92408-
( match (Ctype.unalias t).desc with
92409-
| Tconstr (path1, _, _) ->
92410-
(* Format.eprintf "XXX path:%s@." (Path.name path);
92411-
Format.eprintf "XXX path1:%s@." (Path.name path1); *)
92412-
( match Env.find_type path1 pat.pat_env with
92413-
| {type_kind = Type_variant cstrs1} ->
92414-
names_from_type_variant cstrs1
92415-
| _ -> Some {consts=[||]; blocks=[||]})
92416-
| _ -> Some {consts=[||]; blocks=[||]})
92417-
| {type_kind = Type_abstract; type_manifest = None} ->
92418-
(* Format.eprintf "XXX Type_abstract@."; *)
92419-
Some {consts=[||]; blocks=[||]}
92420-
| {type_kind = Type_record _} ->
92421-
(* Format.eprintf "XXX Type_record@."; *)
92422-
Some {consts=[||]; blocks=[||]}
92423-
| {type_kind = Type_open } ->
92424-
(* Format.eprintf "XXX Type_open@."; *)
92425-
Some {consts=[||]; blocks=[||]} in
92426-
names
92423+
| Tconstr (path, _, _) -> resolve_path 0 path
9242792424
| _ -> assert false in
9242892425

9242992426
compile_test

lib/4.02.3/whole_compiler.ml

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79919,31 +79919,28 @@ and do_compile_matching repr partial ctx arg pmh = match pmh with
7991979919
Some {consts = consts |> List.rev |> Array.of_list;
7992079920
blocks = blocks |> List.rev |> Array.of_list } in
7992179921

79922+
let rec resolve_path n path =
79923+
match Env.find_type path pat.pat_env with
79924+
| {type_kind = Type_variant cstrs} ->
79925+
names_from_type_variant cstrs
79926+
| {type_kind = Type_abstract; type_manifest = Some t} ->
79927+
( match (Ctype.unalias t).desc with
79928+
| Tconstr (pathn, _, _) ->
79929+
(* Format.eprintf "XXX path%d:%s path%d:%s@." n (Path.name path) (n+1) (Path.name pathn); *)
79930+
resolve_path (n+1) pathn
79931+
| _ -> assert false)
79932+
| {type_kind = Type_abstract; type_manifest = None} ->
79933+
(* Format.eprintf "XXX Type_abstract@."; *)
79934+
Some {consts=[||]; blocks=[||]}
79935+
| {type_kind = Type_record _} ->
79936+
(* Format.eprintf "XXX Type_record@."; *)
79937+
Some {consts=[||]; blocks=[||]}
79938+
| {type_kind = Type_open } ->
79939+
(* Format.eprintf "XXX Type_open@."; *)
79940+
Some {consts=[||]; blocks=[||]} in
79941+
7992279942
let names = match (Btype.repr pat.pat_type).desc with
79923-
| Tconstr (path, _, _) ->
79924-
let names = match Env.find_type path pat.pat_env with
79925-
| {type_kind = Type_variant cstrs} ->
79926-
names_from_type_variant cstrs
79927-
| {type_kind = Type_abstract; type_manifest = Some t} ->
79928-
( match (Ctype.unalias t).desc with
79929-
| Tconstr (path1, _, _) ->
79930-
(* Format.eprintf "XXX path:%s@." (Path.name path);
79931-
Format.eprintf "XXX path1:%s@." (Path.name path1); *)
79932-
( match Env.find_type path1 pat.pat_env with
79933-
| {type_kind = Type_variant cstrs1} ->
79934-
names_from_type_variant cstrs1
79935-
| _ -> Some {consts=[||]; blocks=[||]})
79936-
| _ -> Some {consts=[||]; blocks=[||]})
79937-
| {type_kind = Type_abstract; type_manifest = None} ->
79938-
(* Format.eprintf "XXX Type_abstract@."; *)
79939-
Some {consts=[||]; blocks=[||]}
79940-
| {type_kind = Type_record _} ->
79941-
(* Format.eprintf "XXX Type_record@."; *)
79942-
Some {consts=[||]; blocks=[||]}
79943-
| {type_kind = Type_open } ->
79944-
(* Format.eprintf "XXX Type_open@."; *)
79945-
Some {consts=[||]; blocks=[||]} in
79946-
names
79943+
| Tconstr (path, _, _) -> resolve_path 0 path
7994779944
| _ -> assert false in
7994879945

7994979946
compile_test

ocaml

Submodule ocaml updated from 2e15e28 to 7d98347

0 commit comments

Comments
 (0)