Skip to content

Commit

Permalink
[hxb] Catch unification errors when trying to close a monomorph (#11882)
Browse files Browse the repository at this point in the history
* [hxb] Catch unification errors when trying to close a monomorph

* Include message about opening an issue, only trigger once per mono
  • Loading branch information
kLabz authored Dec 13, 2024
1 parent 8b3e8a1 commit 4fea9c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src-json/warning.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,10 @@
"name": "WUnboundTypeParameter",
"doc": "Hxb (either --hxb output or haxe compiler cache) failed to link a type parameter to an actual type",
"parent": "WHxb"
},
{
"name": "WUnclosedMonomorph",
"doc": "Hxb writer failed to close a monomorph (that monomorph should have been closed in the first place)",
"parent": "WHxb"
}
]
16 changes: 15 additions & 1 deletion src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ type hxb_writer = {
mutable wrote_local_type_param : bool;
mutable needs_local_context : bool;
unbound_ttp : (typed_type_param,unit) IdentityPool.t;
unclosed_mono : (tmono,unit) IdentityPool.t;
t_instance_chunk : Chunk.t;
}

Expand Down Expand Up @@ -1197,7 +1198,19 @@ module HxbWriter = struct
| TInst ({cl_path = ([],"String")},[]) ->
Chunk.write_u8 writer.chunk 104;
| TMono r ->
Monomorph.close r;
(try Monomorph.close r with TUnification.Unify_error e ->
try ignore(IdentityPool.get writer.unclosed_mono r) with Not_found -> begin
ignore(IdentityPool.add writer.unclosed_mono r ());

let p = file_pos (Path.UniqueKey.lazy_path writer.current_module.m_extra.m_file) in
let msg = Printf.sprintf
"Error while handling unclosed monomorph:\n%s\n\n%s"
(Error.error_msg (Unify e))
"Unclosed monomorph should not reach hxb writer, please submit an issue at https://github.com/HaxeFoundation/haxe/issues/new"
in
writer.warn WUnclosedMonomorph msg p
end;
);
begin match r.tm_type with
| None ->
Chunk.write_u8 writer.chunk 0;
Expand Down Expand Up @@ -2338,6 +2351,7 @@ let create config string_pool warn anon_id =
wrote_local_type_param = false;
needs_local_context = false;
unbound_ttp = IdentityPool.create ();
unclosed_mono = IdentityPool.create ();
t_instance_chunk = Chunk.create EOM cp 32;
}

Expand Down

0 comments on commit 4fea9c0

Please sign in to comment.