@@ -96,8 +96,9 @@ and lambda_with_env = {
96
96
env : binding_size Ident.Map .t ;
97
97
}
98
98
99
- let dynamic_size () =
100
- Misc. fatal_error " letrec: No size found for Static binding"
99
+ let dynamic_size lam =
100
+ Misc. fatal_errorf " letrec: No size found for Static binding:@ %a"
101
+ Printlambda. lambda lam
101
102
102
103
(* [join_sizes] is used to compute the size of an expression with multiple
103
104
branches. Such expressions are normally classified as [Dynamic] by
@@ -108,26 +109,26 @@ let dynamic_size () =
108
109
Note that the current compilation scheme would work if we allowed the
109
110
[Constant] and [Block] cases to be joined, but [Function] needs to be
110
111
a single function. *)
111
- let join_sizes size1 size2 =
112
+ let join_sizes lam size1 size2 =
112
113
match size1, size2 with
113
114
| Unreachable , size | size , Unreachable -> size
114
- | _ , _ -> dynamic_size ()
115
+ | _ , _ -> dynamic_size lam
115
116
116
117
let compute_static_size lam =
117
118
let rec compute_expression_size env lam =
118
119
match lam with
119
120
| Lvar v ->
120
121
begin match Ident.Map. find_opt v env with
121
122
| None ->
122
- dynamic_size ()
123
+ dynamic_size lam
123
124
| Some binding_size ->
124
125
Lazy_backtrack. force
125
126
(fun { lambda; env } -> compute_expression_size env lambda)
126
127
binding_size
127
128
end
128
- | Lmutvar _ -> dynamic_size ()
129
+ | Lmutvar _ -> dynamic_size lam
129
130
| Lconst _ -> Constant
130
- | Lapply _ -> dynamic_size ()
131
+ | Lapply _ -> dynamic_size lam
131
132
| Lfunction lfun -> Function lfun
132
133
| Llet (_ , _ , id , def , body ) ->
133
134
let env =
@@ -170,7 +171,7 @@ let compute_static_size lam =
170
171
| Lwhile _
171
172
| Lfor _
172
173
| Lassign _ -> Constant
173
- | Lsend _ -> dynamic_size ()
174
+ | Lsend _ -> dynamic_size lam
174
175
| Levent (e , _ ) ->
175
176
compute_expression_size env e
176
177
| Lifused _ -> Constant
@@ -180,20 +181,20 @@ let compute_static_size lam =
180
181
(* Lexclave should only occur in tail position of a function.
181
182
Since we only compute sizes for let-bound definitions, we should never
182
183
reach this case.
183
- This justifies using [assert false] instead of [dynamic_size () ],
184
+ This justifies using [assert false] instead of [dynamic_size lam ],
184
185
the latter meaning that [Value_rec_check] should have forbidden that case.
185
186
*)
186
187
assert false
187
188
and compute_and_join_sizes env branches =
188
189
List. fold_left (fun size branch ->
189
- join_sizes size (compute_expression_size env branch))
190
+ join_sizes branch size (compute_expression_size env branch))
190
191
Unreachable branches
191
192
and compute_and_join_sizes_switch :
192
193
type a . binding_size Ident.Map. t -> (a * lambda ) list list -> size =
193
194
fun env all_cases ->
194
195
List. fold_left (fun size cases ->
195
196
List. fold_left (fun size (_key , action ) ->
196
- join_sizes size (compute_expression_size env action))
197
+ join_sizes action size (compute_expression_size env action))
197
198
size cases)
198
199
Unreachable all_cases
199
200
and size_of_primitive env p args =
@@ -335,7 +336,7 @@ let compute_static_size lam =
335
336
| Patomic_fetch_add
336
337
| Popaque _
337
338
| Pdls_get ->
338
- dynamic_size ()
339
+ dynamic_size lam
339
340
340
341
(* Primitives specific to flambda-backend *)
341
342
| Pmakefloatblock (_ , _ ) ->
@@ -356,7 +357,7 @@ let compute_static_size lam =
356
357
357
358
| Pmakeufloatblock (_, _)
358
359
| Pmake_unboxed_product _ ->
359
- dynamic_size () (* Not allowed *)
360
+ dynamic_size lam (* Not allowed *)
360
361
361
362
| Pobj_dup
362
363
| Parray_to_iarray
@@ -385,7 +386,7 @@ let compute_static_size lam =
385
386
| Pfloatoffloat32 _
386
387
| Pfloat32offloat _
387
388
| Pget_header _ ->
388
- dynamic_size ()
389
+ dynamic_size lam
389
390
in
390
391
compute_expression_size Ident.Map. empty lam
391
392
@@ -584,7 +585,9 @@ let rec split_static_function lfun block_var local_idents lam :
584
585
Reachable (lfun, switch)
585
586
| Reachable _, Reachable _, _ | Reachable _, _, Some (Reachable _)
586
587
| _ , Reachable _ , Some (Reachable _ ) ->
587
- Misc. fatal_error " letrec: multiple functions"
588
+ Misc. fatal_errorf " letrec: multiple functions:@ lfun=%a@ lam=%a"
589
+ Printlambda. lfunction lfun
590
+ Printlambda. lambda lam
588
591
end
589
592
| Lstringswitch (arg , arms , failaction , loc , layout ) ->
590
593
let arms_res = rebuild_arms lfun block_var local_idents arms in
@@ -598,7 +601,9 @@ let rec split_static_function lfun block_var local_idents lam :
598
601
| Unreachable , Some (Reachable (lfun , failaction )) ->
599
602
Reachable (lfun, Lstringswitch (arg, arms, Some failaction, loc, layout))
600
603
| Reachable _ , Some (Reachable _ ) ->
601
- Misc. fatal_error " letrec: multiple functions"
604
+ Misc. fatal_errorf " letrec: multiple functions:@ lfun=%a@ lam=%a"
605
+ Printlambda. lfunction lfun
606
+ Printlambda. lambda lam
602
607
end
603
608
| Lstaticcatch (body , (nfail , params ), handler , r , layout ) ->
604
609
let body_res = split_static_function lfun block_var local_idents body in
@@ -616,7 +621,9 @@ let rec split_static_function lfun block_var local_idents lam :
616
621
| Unreachable , Reachable (lfun , handler ) ->
617
622
Reachable (lfun, Lstaticcatch (body, (nfail, params), handler, r, layout))
618
623
| Reachable _ , Reachable _ ->
619
- Misc. fatal_error " letrec: multiple functions"
624
+ Misc. fatal_errorf " letrec: multiple functions:@ lfun=%a@ lam=%a"
625
+ Printlambda. lfunction lfun
626
+ Printlambda. lambda lam
620
627
end
621
628
| Ltrywith (body , exn_var , handler , layout ) ->
622
629
let body_res = split_static_function lfun block_var local_idents body in
@@ -631,7 +638,9 @@ let rec split_static_function lfun block_var local_idents lam :
631
638
| Unreachable , Reachable (lfun , handler ) ->
632
639
Reachable (lfun, Ltrywith (body, exn_var, handler, layout))
633
640
| Reachable _ , Reachable _ ->
634
- Misc. fatal_error " letrec: multiple functions"
641
+ Misc. fatal_errorf " letrec: multiple functions:@ lfun=%a@ lam=%a"
642
+ Printlambda. lfunction lfun
643
+ Printlambda. lambda lam
635
644
end
636
645
| Lifthenelse (cond , ifso , ifnot , layout ) ->
637
646
let ifso_res = split_static_function lfun block_var local_idents ifso in
@@ -643,7 +652,9 @@ let rec split_static_function lfun block_var local_idents lam :
643
652
| Unreachable , Reachable (lfun , ifnot ) ->
644
653
Reachable (lfun, Lifthenelse (cond, ifso, ifnot, layout))
645
654
| Reachable _ , Reachable _ ->
646
- Misc. fatal_error " letrec: multiple functions"
655
+ Misc. fatal_errorf " letrec: multiple functions:@ lfun=%a@ lam=%a"
656
+ Printlambda. lfunction lfun
657
+ Printlambda. lambda lam
647
658
end
648
659
| Lsequence (e1 , e2 ) ->
649
660
let + e2 = split_static_function lfun block_var local_idents e2 in
@@ -661,7 +672,11 @@ let rec split_static_function lfun block_var local_idents lam :
661
672
| Lsend _
662
673
| Lifused _
663
674
| Lregion _
664
- | Lexclave _ -> Misc. fatal_error " letrec binding is not a static function"
675
+ | Lexclave _ ->
676
+ Misc. fatal_errorf
677
+ " letrec binding is not a static function:@ lfun=%a@ lam=%a"
678
+ Printlambda. lfunction lfun
679
+ Printlambda. lambda lam
665
680
and rebuild_arms :
666
681
type a . _ -> _ -> _ -> (a * Lambda. lambda ) list ->
667
682
(a * Lambda. lambda ) list split_result =
@@ -678,7 +693,9 @@ and rebuild_arms :
678
693
| Unreachable , Reachable (lfun , arms ) ->
679
694
Reachable (lfun, (i, lam) :: arms)
680
695
| Reachable _ , Reachable _ ->
681
- Misc. fatal_error " letrec: multiple functions"
696
+ Misc. fatal_errorf " letrec: multiple functions:@ lfun=%a@ lam=%a"
697
+ Printlambda. lfunction lfun
698
+ Printlambda. lambda lam
682
699
683
700
(* * {1. Compilation} *)
684
701
@@ -796,6 +813,13 @@ let update_prim =
796
813
(* * Compilation function *)
797
814
798
815
let compile_letrec input_bindings body =
816
+ if ! Clflags. dump_letreclambda then (
817
+ Format. eprintf " Value_rec_compiler input bindings:\n " ;
818
+ List. iter (fun (id , _ , def ) ->
819
+ Format. eprintf " %a = %a\n %!" Ident. print id Printlambda. lambda def)
820
+ input_bindings;
821
+ Format. eprintf " Value_rec_compiler body:@ %a\n %!" Printlambda. lambda body
822
+ );
799
823
let subst_for_constants =
800
824
List. fold_left (fun subst (id , _ , _ ) ->
801
825
Ident.Map. add id Lambda. dummy_constant subst)
@@ -833,7 +857,9 @@ let compile_letrec input_bindings body =
833
857
split_static_function lfun ctx_id Ident.Set. empty def
834
858
with
835
859
| Unreachable ->
836
- Misc. fatal_error " letrec: no function for binding"
860
+ Misc. fatal_errorf
861
+ " letrec: no function for binding:@ def=%a@ lfun=%a"
862
+ Printlambda. lambda def Printlambda. lfunction lfun
837
863
| Reachable ({ lfun; free_vars_block_size } , lam ) ->
838
864
let functions = (id, lfun) :: rev_bindings.functions in
839
865
let static =
0 commit comments