Skip to content

Commit ee67399

Browse files
committed
[jvm] drop functional_interface_lut; compute SAM field on demand
The LUT memoized get_singular_interface_field per class, populated by typeloadFields.check_functional_interface and re-checked lazily by AbstractCast (#11549, for display-mode flows where init_class hadn't run yet by the time a SAM conversion was queried). It was a global mutable hashtbl on common.context whose only reader was AbstractCast. The cached computation is a walk over a SAM interface's field list — typically under 10 entries, and short-circuits on the second non-default method, so the perf delta from recomputing is well below noise. Doing that directly in AbstractCast collapses the two load paths into one and removes the field from common.context. Also drops the now-no-op typeloadFields.check_functional_interface (its only effect was populating the LUT) and the bridge call that re-invoked it from init_class when the flag was set via @:functionalInterface meta in typeloadModule.
1 parent cbd81b1 commit ee67399

3 files changed

Lines changed: 4 additions & 20 deletions

File tree

src/context/abstractCast.ml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,9 @@ and do_check_cast ctx uctx tleft eright p =
8888
loop2 a.a_to
8989
end
9090
| TInst(c,tl), TFun _ when has_class_flag c CFunctionalInterface ->
91-
let cf = try
92-
snd (ctx.com.functional_interface_lut#find c.cl_path)
93-
with Not_found -> match TClass.get_singular_interface_field c.cl_ordered_fields with
94-
| None ->
95-
raise Not_found
96-
| Some cf ->
97-
ctx.com.functional_interface_lut#add c.cl_path (c,cf);
98-
cf
91+
let cf = match TClass.get_singular_interface_field c.cl_ordered_fields with
92+
| None -> raise Not_found
93+
| Some cf -> cf
9994
in
10095
let map = apply_params c.cl_params tl in
10196
let monos = Monomorph.spawn_constrained_monos map cf.cf_params in

src/context/common.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ and context = {
345345
mutable modules : Type.module_def list;
346346
mutable types : Type.module_type list;
347347
mutable resources : (string,string) Hashtbl.t;
348-
functional_interface_lut : (path,(tclass * tclass_field)) lookup;
349348
(* target-specific *)
350349
mutable flash_version : float;
351350
mutable neko_lib_paths : string list;
@@ -810,7 +809,6 @@ let create sctx request_scope part_scope display_mode =
810809
parser_cache = new hashtbl_lookup;
811810
overload_cache = new hashtbl_lookup;
812811
is_macro_context = false;
813-
functional_interface_lut = new Lookup.hashtbl_lookup;
814812
hxb_reader_api = None;
815813
hxb_reader_stats = HxbReader.create_hxb_reader_stats ();
816814
hxb_writer_config = None;
@@ -935,7 +933,6 @@ let clone com is_macro_context =
935933
parser_cache = new hashtbl_lookup;
936934
overload_cache = new hashtbl_lookup; (* ! *)
937935
is_macro_context = is_macro_context;
938-
functional_interface_lut = new Lookup.hashtbl_lookup;
939936
hxb_reader_api = None;
940937
hxb_reader_stats = HxbReader.create_hxb_reader_stats ();
941938
}

src/typing/typeloadFields.ml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,14 +1644,6 @@ let finalize_class cctx =
16441644
| Some r -> delay ctx.g PTypeField (fun() -> ignore(lazy_type r)))
16451645
) cctx.delayed_expr
16461646

1647-
let check_functional_interface ctx c =
1648-
match TClass.get_singular_interface_field c.cl_ordered_fields with
1649-
| None ->
1650-
()
1651-
| Some cf ->
1652-
add_class_flag c CFunctionalInterface;
1653-
ctx.com.functional_interface_lut#add c.cl_path (c,cf)
1654-
16551647
let create_class_field cctx f =
16561648
let cf = {(mk_field (fst f.cff_name) ~public:(is_public cctx f.cff_access None) t_dynamic f.cff_pos (pos f.cff_name)) with
16571649
cf_doc = f.cff_doc;
@@ -1793,7 +1785,7 @@ let init_class ctx_c cctx c p herits fields =
17931785
a.a_unops <- List.rev a.a_unops;
17941786
a.a_array <- List.rev a.a_array;
17951787
| None ->
1796-
if (has_class_flag c CFunctionalInterface) && com.platform = Jvm then check_functional_interface ctx_c c;
1788+
()
17971789
end;
17981790
c.cl_ordered_statics <- List.rev c.cl_ordered_statics;
17991791
c.cl_ordered_fields <- List.rev c.cl_ordered_fields;

0 commit comments

Comments
 (0)