@@ -769,61 +769,6 @@ let rec is_eta_conversion_exn params inner_args outer_args : t list =
769769 | [] , [] , [] -> []
770770 | _ , _ , _ -> raise_notrace Not_simple_form
771771
772- let rec apply ?(ap_transformed_jsx = false ) fn args (ap_info : ap_info ) : t =
773- match fn with
774- | Lfunction
775- {
776- params;
777- body =
778- Lprim
779- {
780- primitive =
781- ( Pnull_to_opt | Pnull_undefined_to_opt | Pis_null
782- | Pis_null_undefined | Ptypeof ) as wrap;
783- args =
784- [Lprim ({primitive = _; args = inner_args} as primitive_call)];
785- };
786- } -> (
787- match is_eta_conversion_exn params inner_args args with
788- | args ->
789- let loc = ap_info.ap_loc in
790- Lprim
791- {primitive = wrap; args = [Lprim {primitive_call with args; loc}]; loc}
792- | exception Not_simple_form ->
793- Lapply {ap_func = fn; ap_args = args; ap_info; ap_transformed_jsx})
794- | Lfunction
795- {
796- params;
797- body = Lprim ({primitive = _; args = inner_args} as primitive_call);
798- } -> (
799- match is_eta_conversion_exn params inner_args args with
800- | args -> Lprim {primitive_call with args; loc = ap_info.ap_loc}
801- | exception _ ->
802- Lapply {ap_func = fn; ap_args = args; ap_info; ap_transformed_jsx})
803- | Lfunction
804- {
805- params;
806- body =
807- Lsequence
808- ( Lprim ({primitive = _; args = inner_args} as primitive_call),
809- (Lconst _ as const) );
810- } -> (
811- match is_eta_conversion_exn params inner_args args with
812- | args ->
813- Lsequence (Lprim {primitive_call with args; loc = ap_info.ap_loc}, const)
814- | exception _ ->
815- Lapply {ap_func = fn; ap_args = args; ap_info; ap_transformed_jsx}
816- (* | Lfunction {params;body} when Ext_list.same_length params args ->
817- Ext_list.fold_right2 (fun p arg acc ->
818- Llet(Strict,p,arg,acc)
819- ) params args body *)
820- (* TODO: more rigirous analysis on [let_kind] *) )
821- | Llet (kind , id , e , (Lfunction _ as fn )) ->
822- Llet (kind, id, e, apply fn args ap_info ~ap_transformed_jsx )
823- (* | Llet (kind0, id0, e0, Llet (kind,id, e, (Lfunction _ as fn))) ->
824- Llet(kind0,id0,e0,Llet (kind, id, e, apply fn args loc status)) *)
825- | _ -> Lapply {ap_func = fn; ap_args = args; ap_info; ap_transformed_jsx}
826-
827772let rec eq_approx (l1 : t ) (l2 : t ) =
828773 match l1 with
829774 | Lglobal_module i1 -> (
@@ -1080,6 +1025,61 @@ let prim ~primitive:(prim : primitive) ~args loc : t =
10801025 *)
10811026 | _ -> default () )
10821027
1028+ let rec apply ?(ap_transformed_jsx = false ) fn args (ap_info : ap_info ) : t =
1029+ match fn with
1030+ | Lfunction
1031+ {
1032+ params;
1033+ body =
1034+ Lprim
1035+ {
1036+ primitive =
1037+ ( Pnull_to_opt | Pnull_undefined_to_opt | Pis_null
1038+ | Pis_null_undefined | Ptypeof ) as wrap;
1039+ args =
1040+ [Lprim ({primitive = _; args = inner_args} as primitive_call)];
1041+ };
1042+ } -> (
1043+ match is_eta_conversion_exn params inner_args args with
1044+ | args ->
1045+ let loc = ap_info.ap_loc in
1046+ Lprim
1047+ {primitive = wrap; args = [Lprim {primitive_call with args; loc}]; loc}
1048+ | exception Not_simple_form ->
1049+ Lapply {ap_func = fn; ap_args = args; ap_info; ap_transformed_jsx})
1050+ | Lfunction
1051+ {
1052+ params;
1053+ body = Lprim ({primitive = _; args = inner_args} as primitive_call);
1054+ } -> (
1055+ match is_eta_conversion_exn params inner_args args with
1056+ | args -> Lprim {primitive_call with args; loc = ap_info.ap_loc}
1057+ | exception _ ->
1058+ Lapply {ap_func = fn; ap_args = args; ap_info; ap_transformed_jsx})
1059+ | Lfunction
1060+ {
1061+ params;
1062+ body =
1063+ Lsequence
1064+ ( Lprim ({primitive = _; args = inner_args} as primitive_call),
1065+ (Lconst _ as const) );
1066+ } -> (
1067+ match is_eta_conversion_exn params inner_args args with
1068+ | args ->
1069+ Lsequence (Lprim {primitive_call with args; loc = ap_info.ap_loc}, const)
1070+ | exception _ ->
1071+ Lapply {ap_func = fn; ap_args = args; ap_info; ap_transformed_jsx}
1072+ (* | Lfunction {params;body} when Ext_list.same_length params args ->
1073+ Ext_list.fold_right2 (fun p arg acc ->
1074+ Llet(Strict,p,arg,acc)
1075+ ) params args body *)
1076+ (* TODO: more rigirous analysis on [let_kind] *) )
1077+ | Llet (kind , id , e , (Lfunction _ as fn )) ->
1078+ Llet (kind, id, e, apply fn args ap_info ~ap_transformed_jsx )
1079+ (* | Llet (kind0, id0, e0, Llet (kind,id, e, (Lfunction _ as fn))) ->
1080+ Llet(kind0,id0,e0,Llet (kind, id, e, apply fn args loc status)) *)
1081+ | _ -> Lapply {ap_func = fn; ap_args = args; ap_info; ap_transformed_jsx}
1082+
10831083let not_ loc x : t =
10841084 match x with
10851085 | Lprim ({primitive = Pintcomp Cneq } as prim ) ->
0 commit comments