Skip to content

Commit b2cab95

Browse files
committed
flambda-backend: Merge ocaml-jst
2 parents a6d6e0e + 0b0aefb commit b2cab95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+448
-259
lines changed

.depend

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,12 @@ utils/profile.cmi :
121121
utils/strongly_connected_components.cmo : \
122122
utils/numbers.cmi \
123123
utils/misc.cmi \
124-
utils/identifiable.cmi \
125124
utils/strongly_connected_components.cmi
126125
utils/strongly_connected_components.cmx : \
127126
utils/numbers.cmx \
128127
utils/misc.cmx \
129-
utils/identifiable.cmx \
130128
utils/strongly_connected_components.cmi
131-
utils/strongly_connected_components.cmi : \
132-
utils/identifiable.cmi
129+
utils/strongly_connected_components.cmi :
133130
utils/target_system.cmo : \
134131
utils/misc.cmi \
135132
utils/config.cmi \
@@ -343,15 +340,13 @@ parsing/lexer.cmo : \
343340
utils/misc.cmi \
344341
parsing/location.cmi \
345342
parsing/docstrings.cmi \
346-
utils/clflags.cmi \
347343
parsing/lexer.cmi
348344
parsing/lexer.cmx : \
349345
utils/warnings.cmx \
350346
parsing/parser.cmx \
351347
utils/misc.cmx \
352348
parsing/location.cmx \
353349
parsing/docstrings.cmx \
354-
utils/clflags.cmx \
355350
parsing/lexer.cmi
356351
parsing/lexer.cmi : \
357352
parsing/parser.cmi \
@@ -480,13 +475,15 @@ typing/annot.cmi : \
480475
typing/btype.cmo : \
481476
typing/types.cmi \
482477
typing/path.cmi \
478+
utils/misc.cmi \
483479
utils/local_store.cmi \
484480
typing/ident.cmi \
485481
parsing/asttypes.cmi \
486482
typing/btype.cmi
487483
typing/btype.cmx : \
488484
typing/types.cmx \
489485
typing/path.cmx \
486+
utils/misc.cmx \
490487
utils/local_store.cmx \
491488
typing/ident.cmx \
492489
parsing/asttypes.cmi \
@@ -815,11 +812,13 @@ typing/mtype.cmi : \
815812
typing/oprint.cmo : \
816813
parsing/pprintast.cmi \
817814
typing/outcometree.cmi \
815+
utils/clflags.cmi \
818816
parsing/asttypes.cmi \
819817
typing/oprint.cmi
820818
typing/oprint.cmx : \
821819
parsing/pprintast.cmx \
822820
typing/outcometree.cmi \
821+
utils/clflags.cmx \
823822
parsing/asttypes.cmi \
824823
typing/oprint.cmi
825824
typing/oprint.cmi : \
@@ -2106,14 +2105,12 @@ asmcomp/CSEgen.cmi : \
21062105
asmcomp/mach.cmi \
21072106
parsing/asttypes.cmi
21082107
asmcomp/afl_instrument.cmo : \
2109-
lambda/lambda.cmi \
21102108
asmcomp/cmm.cmi \
21112109
utils/clflags.cmi \
21122110
middle_end/backend_var.cmi \
21132111
parsing/asttypes.cmi \
21142112
asmcomp/afl_instrument.cmi
21152113
asmcomp/afl_instrument.cmx : \
2116-
lambda/lambda.cmx \
21172114
asmcomp/cmm.cmx \
21182115
utils/clflags.cmx \
21192116
middle_end/backend_var.cmx \
@@ -2921,6 +2918,7 @@ asmcomp/selectgen.cmo : \
29212918
asmcomp/mach.cmi \
29222919
lambda/lambda.cmi \
29232920
lambda/debuginfo.cmi \
2921+
utils/config.cmi \
29242922
asmcomp/cmm.cmi \
29252923
middle_end/backend_var.cmi \
29262924
parsing/asttypes.cmi \
@@ -2934,6 +2932,7 @@ asmcomp/selectgen.cmx : \
29342932
asmcomp/mach.cmx \
29352933
lambda/lambda.cmx \
29362934
lambda/debuginfo.cmx \
2935+
utils/config.cmx \
29372936
asmcomp/cmm.cmx \
29382937
middle_end/backend_var.cmx \
29392938
parsing/asttypes.cmi \
@@ -3343,6 +3342,7 @@ lambda/lambda.cmo : \
33433342
typing/ident.cmi \
33443343
typing/env.cmi \
33453344
lambda/debuginfo.cmi \
3345+
utils/config.cmi \
33463346
utils/clflags.cmi \
33473347
parsing/asttypes.cmi \
33483348
lambda/lambda.cmi
@@ -3355,6 +3355,7 @@ lambda/lambda.cmx : \
33553355
typing/ident.cmx \
33563356
typing/env.cmx \
33573357
lambda/debuginfo.cmx \
3358+
utils/config.cmx \
33583359
utils/clflags.cmx \
33593360
parsing/asttypes.cmi \
33603361
lambda/lambda.cmi
@@ -5145,6 +5146,7 @@ middle_end/flambda/lift_let_to_initialize_symbol.cmo : \
51455146
middle_end/variable.cmi \
51465147
middle_end/flambda/base_types/tag.cmi \
51475148
middle_end/symbol.cmi \
5149+
lambda/lambda.cmi \
51485150
middle_end/internal_variable_names.cmi \
51495151
utils/int_replace_polymorphic_compare.cmi \
51505152
middle_end/flambda/flambda_utils.cmi \
@@ -5155,6 +5157,7 @@ middle_end/flambda/lift_let_to_initialize_symbol.cmx : \
51555157
middle_end/variable.cmx \
51565158
middle_end/flambda/base_types/tag.cmx \
51575159
middle_end/symbol.cmx \
5160+
lambda/lambda.cmx \
51585161
middle_end/internal_variable_names.cmx \
51595162
utils/int_replace_polymorphic_compare.cmx \
51605163
middle_end/flambda/flambda_utils.cmx \
@@ -5251,6 +5254,7 @@ middle_end/flambda/remove_unused_arguments.cmo : \
52515254
middle_end/variable.cmi \
52525255
middle_end/flambda/projection.cmi \
52535256
middle_end/flambda/parameter.cmi \
5257+
lambda/lambda.cmi \
52545258
middle_end/flambda/invariant_params.cmi \
52555259
utils/int_replace_polymorphic_compare.cmi \
52565260
middle_end/flambda/flambda_utils.cmi \
@@ -5266,6 +5270,7 @@ middle_end/flambda/remove_unused_arguments.cmx : \
52665270
middle_end/variable.cmx \
52675271
middle_end/flambda/projection.cmx \
52685272
middle_end/flambda/parameter.cmx \
5273+
lambda/lambda.cmx \
52695274
middle_end/flambda/invariant_params.cmx \
52705275
utils/int_replace_polymorphic_compare.cmx \
52715276
middle_end/flambda/flambda_utils.cmx \

asmcomp/selectgen.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,8 @@ method emit_tail (env:environment) exp =
11041104
end
11051105
| Cphantom_let (_var, _defining_expr, body) ->
11061106
self#emit_tail env body
1107-
| Cop((Capply(ty, pos)) as op, args, dbg) ->
1107+
| Cop((Capply(ty, ((Rc_close_at_apply | Rc_normal) as pos))) as op,
1108+
args, dbg) ->
11081109
let tail = (pos = Lambda.Rc_close_at_apply) in
11091110
let endregion = env.region_tail in
11101111
begin match self#emit_parts_list env' args with

boot/ocamlc

23.6 KB
Binary file not shown.

boot/ocamllex

1.41 KB
Binary file not shown.

bytecomp/bytegen.ml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ let comp_primitive p args =
512512

513513
let is_immed n = immed_min <= n && n <= immed_max
514514

515+
let is_nontail = function
516+
| Rc_nontail -> true
517+
| Rc_normal | Rc_close_at_apply -> false
518+
515519
module Storer =
516520
Switch.Store
517521
(struct type t = lambda type key = lambda
@@ -546,9 +550,9 @@ let rec comp_expr env exp sz cont =
546550
end
547551
| Lconst cst ->
548552
Kconst cst :: cont
549-
| Lapply{ap_func = func; ap_args = args} ->
553+
| Lapply{ap_func = func; ap_args = args; ap_region_close = rc} ->
550554
let nargs = List.length args in
551-
if is_tailcall cont then begin
555+
if is_tailcall cont && not (is_nontail rc) then begin
552556
comp_args env args sz
553557
(Kpush :: comp_expr env func (sz + nargs)
554558
(Kappterm(nargs, sz + nargs) :: discard_dead_code cont))
@@ -564,7 +568,7 @@ let rec comp_expr env exp sz cont =
564568
(Kapply nargs :: cont1))
565569
end
566570
end
567-
| Lsend(kind, met, obj, args, _, _, _) ->
571+
| Lsend(kind, met, obj, args, rc, _, _) ->
568572
let args = if kind = Cached then List.tl args else args in
569573
let nargs = List.length args + 1 in
570574
let getmethod, args' =
@@ -573,7 +577,7 @@ let rec comp_expr env exp sz cont =
573577
Lconst(Const_base(Const_int n)) -> (Kgetpubmet n, obj::args)
574578
| _ -> (Kgetdynmet, met::obj::args)
575579
in
576-
if is_tailcall cont then
580+
if is_tailcall cont && not (is_nontail rc) then
577581
comp_args env args' sz
578582
(getmethod :: Kappterm(nargs, sz + nargs) :: discard_dead_code cont)
579583
else
@@ -978,6 +982,9 @@ let rec comp_expr env exp sz cont =
978982
let preserve_tailcall =
979983
match lam with
980984
| Lprim(prim, _, _) -> preserve_tailcall_for_prim prim
985+
| Lapply {ap_region_close=rc; _}
986+
| Lsend(_, _, _, _, rc, _, _) ->
987+
not (is_nontail rc)
981988
| _ -> true
982989
in
983990
if preserve_tailcall && is_tailcall cont then

debugger/.depend

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ loadprinter.cmx : \
301301
../utils/load_path.cmx \
302302
../typing/ident.cmx \
303303
../typing/env.cmx \
304-
../otherlibs/dynlink/dynlink.cmi \
304+
../otherlibs/dynlink/dynlink.cmx \
305305
../typing/ctype.cmx \
306306
loadprinter.cmi
307307
loadprinter.cmi : \

lambda/lambda.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type initialization_or_assignment =
9999

100100
type region_close =
101101
| Rc_normal
102+
| Rc_nontail
102103
| Rc_close_at_apply
103104

104105
type primitive =

lambda/lambda.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ type field_read_semantics =
6565

6666
(* Tail calls can close their enclosing region early *)
6767
type region_close =
68-
| Rc_normal
69-
| Rc_close_at_apply
68+
| Rc_normal (* do not close region, may TCO if in tail position *)
69+
| Rc_nontail (* do not close region, must not TCO *)
70+
| Rc_close_at_apply (* close region and tail call *)
7071

7172
type primitive =
7273
| Pidentity

lambda/printlambda.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ let apply_kind name pos mode =
581581
let name =
582582
match pos with
583583
| Rc_normal -> name
584+
| Rc_nontail -> name ^ "nontail"
584585
| Rc_close_at_apply -> name ^ "tail"
585586
in
586587
name ^ alloc_kind mode

lambda/simplif.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,11 @@ let simplify_exits lam =
221221
let ll = List.map simplif ll in
222222
match p, ll with
223223
(* Simplify %revapply, for n-ary functions with n > 1 *)
224-
| Prevapply Rc_normal, [x; Lapply ap]
225-
| Prevapply Rc_normal, [x; Levent (Lapply ap,_)] ->
224+
| Prevapply ((Rc_normal | Rc_nontail) as pos), [x; Lapply ap]
225+
| Prevapply ((Rc_normal | Rc_nontail) as pos),
226+
[x; Levent (Lapply ap,_)] ->
226227
Lapply {ap with ap_args = ap.ap_args @ [x]; ap_loc = loc;
227-
ap_region_close = Rc_normal}
228+
ap_region_close = pos}
228229
| Prevapply pos, [x; f] ->
229230
Lapply {
230231
ap_loc=loc;
@@ -238,10 +239,11 @@ let simplify_exits lam =
238239
ap_probe=None;
239240
}
240241
(* Simplify %apply, for n-ary functions with n > 1 *)
241-
| Pdirapply Rc_normal, [Lapply ap; x]
242-
| Pdirapply Rc_normal, [Levent (Lapply ap,_); x] ->
242+
| Pdirapply ((Rc_normal | Rc_nontail) as pos), [Lapply ap; x]
243+
| Pdirapply ((Rc_normal | Rc_nontail) as pos),
244+
[Levent (Lapply ap,_); x] ->
243245
Lapply {ap with ap_args = ap.ap_args @ [x];
244-
ap_loc = loc; ap_region_close=Rc_normal}
246+
ap_loc = loc; ap_region_close=pos}
245247
| Pdirapply pos, [f; x] ->
246248
Lapply {
247249
ap_loc=loc;
@@ -883,7 +885,7 @@ let simplify_local_functions lam =
883885
| Lapply {ap_func = Lvar id; ap_args; ap_region_close; _} ->
884886
let curr_scope =
885887
match ap_region_close with
886-
| Rc_normal -> !current_scope
888+
| Rc_normal | Rc_nontail -> !current_scope
887889
| Rc_close_at_apply -> !current_region_scope
888890
in
889891
begin match Hashtbl.find_opt slots id with

0 commit comments

Comments
 (0)