From e8d118930cf4cac98d5d9431ac25625f67b414b4 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 15 Feb 2024 21:51:23 -0800 Subject: [PATCH] fix: handle case of missing `.cmj` when trying to inline external field --- jscomp/core/lam_compile.ml | 16 ++++++++++++++-- jscomp/core/mel_exception.mli | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/jscomp/core/lam_compile.ml b/jscomp/core/lam_compile.ml index a1df320a1a..5bc4faf68d 100644 --- a/jscomp/core/lam_compile.ml +++ b/jscomp/core/lam_compile.ml @@ -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) diff --git a/jscomp/core/mel_exception.mli b/jscomp/core/mel_exception.mli index fbc417e77d..62a85dbb55 100644 --- a/jscomp/core/mel_exception.mli +++ b/jscomp/core/mel_exception.mli @@ -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 *)