Skip to content

Commit

Permalink
fix: handle case of missing .cmj when trying to inline external field
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Feb 16, 2024
1 parent 2f540d1 commit e8d1189
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions jscomp/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,24 @@ type initialization = J.block
-: we should not do functor application inlining in a
non-toplevel, it will explode code very quickly
*)
let rec compile_external_field (* Like [List.empty]*)
let rec compile_external_field (* Like [List.empty] *)
(lamba_cxt : Lam_compile_context.t) (id : Ident.t) name : Js_output.t =
(* NOTE(anmonteiro): This function checks whether there's inlining
information available for the lambda being compiled.
The fallback case happens in 2 scenarios:
1. there's no inlining information available in the `.cmj` file
2. there's no `.cmj` file available. This can happen if we're compiling
a dune virtual library where one of the modules uses a binding from
any of its virtual modules. Because we're programming against the
interface file at this point, we can emit the fallback expression
too.
*)
match Lam_compile_env.query_external_id_info id name with
| { persistent_closed_lambda = Some lam; _ } when Lam_util.not_function lam ->
compile_lambda lamba_cxt lam
| _ ->
| _ | (exception Mel_exception.Error (Cmj_not_found _)) ->
Js_output.output_of_expression lamba_cxt.continuation
~no_effects:no_effects_const (E.ml_var_dot id name)

Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/mel_exception.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TODO: In the futrue, we should refine dependency [bsb]
should not rely on such exception, it should have its own exception handling
*)

(* exception Error of error *)
exception Error of error

(* val report_error : Format.formatter -> error -> unit *)

Expand Down

0 comments on commit e8d1189

Please sign in to comment.