Skip to content

Commit c656dc9

Browse files
committed
Merge flambda-backend changes
2 parents 11b5424 + 23a7f73 commit c656dc9

26 files changed

+203
-86
lines changed

driver/compenv.ml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ let read_one_param ppf position name v =
469469
| Some pass -> set_save_ir_after pass true
470470
end
471471

472+
| "extension" -> Clflags.Extension.enable v
473+
| "disable-all-extensions" ->
474+
if check_bool ppf name v then Clflags.Extension.disable_all ()
475+
472476
| _ ->
473477
if !warnings_for_discarded_params &&
474478
not (List.mem name !can_discard) then begin
@@ -617,11 +621,13 @@ let c_object_of_filename name =
617621
Filename.chop_suffix (Filename.basename name) ".c" ^ Config.ext_obj
618622

619623
let process_action
620-
(ppf, implementation, interface, ocaml_mod_ext, ocaml_lib_ext) action =
624+
(ppf, implementation, interface, ocaml_mod_ext, ocaml_lib_ext) action
625+
~keep_symbol_tables =
621626
let impl ~start_from name =
622627
readenv ppf (Before_compile name);
623628
let opref = output_prefix name in
624-
implementation ~start_from ~source_file:name ~output_prefix:opref;
629+
implementation ~start_from ~source_file:name ~output_prefix:opref
630+
~keep_symbol_tables;
625631
objfiles := (opref ^ ocaml_mod_ext) :: !objfiles
626632
in
627633
match action with
@@ -705,7 +711,14 @@ let process_deferred_actions env =
705711
| ProcessOtherFile name -> Filename.check_suffix name ".cmxa"
706712
| _ -> false) !deferred_actions then
707713
fatal "Option -a cannot be used with .cmxa input files.";
708-
List.iter (process_action env) (List.rev !deferred_actions);
714+
let compiling_multiple_impls =
715+
List.length (List.filter (function
716+
| ProcessImplementation _ -> true
717+
| _ -> false) !deferred_actions) > 1
718+
in
719+
let keep_symbol_tables = compiling_multiple_impls in
720+
List.iter (process_action env ~keep_symbol_tables)
721+
(List.rev !deferred_actions);
709722
output_name := final_output_name;
710723
stop_early :=
711724
!compile_only ||

driver/compenv.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ val intf : string -> unit
8282
val process_deferred_actions :
8383
Format.formatter *
8484
(start_from:Clflags.Compiler_pass.t ->
85-
source_file:string -> output_prefix:string -> unit) *
85+
source_file:string -> output_prefix:string ->
86+
keep_symbol_tables:bool -> unit) *
8687
(* compile implementation *)
8788
(source_file:string -> output_prefix:string -> unit) *
8889
(* compile interface *)

driver/compile.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ let emit_bytecode i (bytecode, required_globals) =
5757
(Emitcode.to_file oc i.module_name cmofile ~required_globals);
5858
)
5959

60-
let implementation ~start_from ~source_file ~output_prefix =
60+
let implementation ~start_from ~source_file ~output_prefix
61+
~keep_symbol_tables:_ =
6162
let backend info typed =
6263
let bytecode = to_bytecode info typed in
6364
emit_bytecode info bytecode

driver/compile.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ val interface:
1919
source_file:string -> output_prefix:string -> unit
2020
val implementation:
2121
start_from:Clflags.Compiler_pass.t ->
22-
source_file:string -> output_prefix:string -> unit
22+
source_file:string -> output_prefix:string -> keep_symbol_tables:bool -> unit
2323

2424
(** {2 Internal functions} **)
2525

driver/main_args.ml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,19 @@ let mk_dump_into_file f =
716716
;;
717717

718718
let mk_extension f =
719-
"-extension", Arg.String f, "<extension> Enable the extension"
719+
let available_extensions =
720+
Clflags.Extension.(List.map to_string all)
721+
in
722+
"-extension", Arg.Symbol (available_extensions, f),
723+
"<extension> Enable the extension (may be specified more than once)"
720724
;;
721725

722-
let mk_standard f =
723-
"-standard", Arg.Unit f, " Disable all default extensions"
726+
let mk_disable_all_extensions f =
727+
"-disable-all-extensions", Arg.Unit f,
728+
" Disable all extensions, wherever they are specified; this flag\n\
729+
\ overrides the -extension flag (whether specified before or after this\n\
730+
\ flag), disables any extensions that are enabled by default, and\n\
731+
\ ignores any extensions requested in OCAMLPARAM."
724732
;;
725733

726734
let mk_dparsetree f =
@@ -1031,7 +1039,7 @@ module type Compiler_options = sig
10311039
val _match_context_rows : int -> unit
10321040
val _dtimings : unit -> unit
10331041
val _dprofile : unit -> unit
1034-
val _standard : unit -> unit
1042+
val _disable_all_extensions : unit -> unit
10351043
val _dump_into_file : unit -> unit
10361044

10371045
val _args: string -> string array
@@ -1283,7 +1291,7 @@ struct
12831291
mk_dcamlprimc F._dcamlprimc;
12841292
mk_dtimings F._dtimings;
12851293
mk_dprofile F._dprofile;
1286-
mk_standard F._standard;
1294+
mk_disable_all_extensions F._disable_all_extensions;
12871295
mk_dump_into_file F._dump_into_file;
12881296
mk_extension F._extension;
12891297

@@ -1510,7 +1518,7 @@ struct
15101518
mk_dstartup F._dstartup;
15111519
mk_dtimings F._dtimings;
15121520
mk_dprofile F._dprofile;
1513-
mk_standard F._standard;
1521+
mk_disable_all_extensions F._disable_all_extensions;
15141522
mk_dump_into_file F._dump_into_file;
15151523
mk_dump_pass F._dump_pass;
15161524
mk_extension F._extension;
@@ -1769,7 +1777,7 @@ module Default = struct
17691777
let _unsafe = set unsafe
17701778
let _warn_error s = Warnings.parse_options true s
17711779
let _warn_help = Warnings.help_warnings
1772-
let _extension s = add_extension s
1780+
let _extension s = Extension.enable s
17731781
end
17741782

17751783
module Native = struct
@@ -1884,7 +1892,7 @@ module Default = struct
18841892
let _config_var = Misc.show_config_variable_and_exit
18851893
let _dprofile () = profile_columns := Profile.all_columns
18861894
let _dtimings () = profile_columns := [`Time]
1887-
let _standard = set_standard
1895+
let _disable_all_extensions = Extension.disable_all
18881896
let _dump_into_file = set dump_into_file
18891897
let _for_pack s = for_package := (Some s)
18901898
let _g = set debug

driver/main_args.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module type Compiler_options = sig
119119
val _match_context_rows : int -> unit
120120
val _dtimings : unit -> unit
121121
val _dprofile : unit -> unit
122-
val _standard : unit -> unit
122+
val _disable_all_extensions : unit -> unit
123123
val _dump_into_file : unit -> unit
124124

125125
val _args: string -> string array

driver/optcompile.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ let emit i =
8787
Compilenv.reset ?packname:!Clflags.for_package i.module_name;
8888
Asmgen.compile_implementation_linear i.output_prefix ~progname:i.source_file
8989

90-
let implementation ~backend ~start_from ~source_file ~output_prefix =
90+
let implementation ~backend ~start_from ~source_file
91+
~output_prefix ~keep_symbol_tables:_ =
9192
let backend info typed =
9293
Compilenv.reset ?packname:!Clflags.for_package info.module_name;
9394
if Config.flambda

driver/optcompile.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ val interface: source_file:string -> output_prefix:string -> unit
2020
val implementation:
2121
backend:(module Backend_intf.S)
2222
-> start_from:Clflags.Compiler_pass.t
23-
-> source_file:string -> output_prefix:string -> unit
23+
-> source_file:string -> output_prefix:string -> keep_symbol_tables:bool
24+
-> unit
2425

2526
(** {2 Internal functions} **)
2627

lambda/debuginfo.ml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ module Scoped_location = struct
2424
| Sc_module_definition
2525
| Sc_class_definition
2626
| Sc_method_definition
27+
| Sc_partial_or_eta_wrapper
28+
| Sc_lazy
2729

2830
type scopes =
2931
| Empty
3032
| Cons of {item: scope_item; str: string; str_fun: string}
3133

34+
let str = function
35+
| Empty -> ""
36+
| Cons r -> r.str
37+
3238
let str_fun = function
3339
| Empty -> "(fun)"
3440
| Cons r -> r.str_fun
@@ -45,8 +51,12 @@ module Scoped_location = struct
4551
| 'a'..'z' | 'A'..'Z' | '_' | '0'..'9' -> s
4652
| _ -> "(" ^ s ^ ")"
4753

48-
let dot ?(sep = ".") scopes s =
49-
let s = add_parens_if_symbolic s in
54+
let dot ?(sep = ".") ?no_parens scopes s =
55+
let s =
56+
match no_parens with
57+
| None -> add_parens_if_symbolic s
58+
| Some () -> s
59+
in
5060
match scopes with
5161
| Empty -> s
5262
| Cons {str; _} -> str ^ sep ^ s
@@ -72,6 +82,11 @@ module Scoped_location = struct
7282
in
7383
cons Sc_method_definition str
7484

85+
let enter_lazy ~scopes = cons Sc_lazy (str scopes)
86+
87+
let enter_partial_or_eta_wrapper ~scopes =
88+
cons Sc_partial_or_eta_wrapper (dot ~no_parens:() scopes "(partial)")
89+
7590
let string_of_scopes = function
7691
| Empty -> "<unknown>"
7792
| Cons {str; _} -> str
@@ -106,6 +121,11 @@ module Scoped_location = struct
106121
let string_of_scoped_location = function
107122
| Loc_unknown -> "??"
108123
| Loc_known { loc = _; scopes } -> string_of_scopes scopes
124+
125+
let map_scopes f t =
126+
match t with
127+
| Loc_unknown -> Loc_unknown
128+
| Loc_known { loc; scopes } -> Loc_known { loc; scopes = f ~scopes }
109129
end
110130

111131
type item = {

lambda/debuginfo.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module Scoped_location : sig
2323
val enter_module_definition : scopes:scopes -> Ident.t -> scopes
2424
val enter_class_definition : scopes:scopes -> Ident.t -> scopes
2525
val enter_method_definition : scopes:scopes -> Asttypes.label -> scopes
26+
val enter_lazy : scopes:scopes -> scopes
27+
val enter_partial_or_eta_wrapper : scopes:scopes -> scopes
2628

2729
type t =
2830
| Loc_unknown
@@ -33,6 +35,8 @@ module Scoped_location : sig
3335
val of_location : scopes:scopes -> Location.t -> t
3436
val to_location : t -> Location.t
3537
val string_of_scoped_location : t -> string
38+
39+
val map_scopes : (scopes:scopes -> scopes) -> t -> t
3640
end
3741

3842
type item = private {

lambda/translcore.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ and transl_exp0 ~in_new_scope ~scopes e =
721721
transl_exp ~scopes e
722722
| `Other ->
723723
(* other cases compile to a lazy block holding a function *)
724+
let scopes = enter_lazy ~scopes in
724725
let fn = Lfunction {kind = Curried {nlocal=0};
725726
params= [Ident.create_local "param", Pgenval];
726727
return = Pgenval;
@@ -892,7 +893,7 @@ and transl_apply ~scopes
892893
?(mode=Alloc_heap)
893894
lam sargs loc
894895
=
895-
let lapply funct args pos =
896+
let lapply funct args loc pos =
896897
match funct, pos with
897898
| Lsend((Self | Public) as k, lmet, lobj, [], _, _, _), _ ->
898899
Lsend(k, lmet, lobj, args, pos, mode, loc)
@@ -925,7 +926,7 @@ and transl_apply ~scopes
925926
ap_probe=None;
926927
}
927928
in
928-
let rec build_apply lam args pos = function
929+
let rec build_apply lam args loc pos = function
929930
| Omitted { mode_closure; mode_arg; mode_ret } :: l ->
930931
let defs = ref [] in
931932
let protect name lam =
@@ -937,7 +938,7 @@ and transl_apply ~scopes
937938
Lvar id
938939
in
939940
let lam =
940-
if args = [] then lam else lapply lam (List.rev args) pos
941+
if args = [] then lam else lapply lam (List.rev args) loc pos
941942
in
942943
let handle = protect "func" lam in
943944
let l =
@@ -950,7 +951,8 @@ and transl_apply ~scopes
950951
in
951952
let id_arg = Ident.create_local "param" in
952953
let body =
953-
let body = build_apply handle [Lvar id_arg] Apply_nontail l in
954+
let loc = map_scopes enter_partial_or_eta_wrapper loc in
955+
let body = build_apply handle [Lvar id_arg] loc Apply_nontail l in
954956
let mode = transl_alloc_mode mode_closure in
955957
let arg_mode = transl_alloc_mode mode_arg in
956958
let ret_mode = transl_alloc_mode mode_ret in
@@ -971,8 +973,8 @@ and transl_apply ~scopes
971973
List.fold_right
972974
(fun (id, lam) body -> Llet(Strict, Pgenval, id, lam, body))
973975
!defs body
974-
| Arg arg :: l -> build_apply lam (arg :: args) pos l
975-
| [] -> lapply lam (List.rev args) pos
976+
| Arg arg :: l -> build_apply lam (arg :: args) loc pos l
977+
| [] -> lapply lam (List.rev args) loc pos
976978
in
977979
let args =
978980
List.map
@@ -982,7 +984,7 @@ and transl_apply ~scopes
982984
| Arg exp -> Arg (transl_exp ~scopes exp))
983985
sargs
984986
in
985-
build_apply lam [] position args
987+
build_apply lam [] loc position args
986988

987989
and transl_curried_function
988990
~scopes loc return

lambda/translprim.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,11 @@ let transl_primitive loc p env ty ~poly_mode path =
755755
in
756756
let params = make_params p.prim_arity in
757757
let args = List.map (fun (id, _) -> Lvar id) params in
758+
let loc =
759+
Debuginfo.Scoped_location.map_scopes (fun ~scopes ->
760+
Debuginfo.Scoped_location.enter_partial_or_eta_wrapper ~scopes)
761+
loc
762+
in
758763
let body = lambda_of_prim p.prim_name prim loc args None in
759764
match params with
760765
| [] -> body

runtime/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143

144144
(rule
145145
(targets runtime_native.ml)
146-
(action (write-file %{targets} "let linkme = ()")))
146+
(action (write-file %{targets} "")))
147147

148148
(install
149149
(files

testsuite/tests/backtrace/names.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
(* TEST
22
flags = "-g"
3+
34
*)
45

56

67
let id x = Sys.opaque_identity x
78

89
let[@inline never] bang () = raise Exit
910

10-
1111
let[@inline never] fn_multi _ _ f = f 42 + 1
1212

1313
let[@inline never] fn_function = function
@@ -97,6 +97,10 @@ let inline_object f =
9797
end in
9898
obj#meth
9999

100+
let[@inline never] lazy_ f =
101+
let x = Sys.opaque_identity (lazy (1 + f ())) in
102+
Lazy.force x
103+
100104
let () =
101105
Printexc.record_backtrace true;
102106
match
@@ -116,6 +120,7 @@ let () =
116120
42 +@+ fun _ ->
117121
(new klass)#meth @@ fun _ ->
118122
inline_object @@ fun _ ->
123+
lazy_ @@ fun _ ->
119124
bang ()
120125
with
121126
| _ -> assert false

testsuite/tests/backtrace/names.reference

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
Raised at Names.bang in file "names.ml", line 8, characters 29-39
1+
Raised at Names.bang in file "names.ml", line 9, characters 29-39
2+
Called from Names.lazy_ in file "names.ml", line 101, characters 41-45
3+
Called from CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 37, characters 17-27
4+
Re-raised at CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 42, characters 4-11
25
Called from Names.inline_object.object#othermeth in file "names.ml", line 96, characters 6-10
36
Called from Names.inline_object.object#meth in file "names.ml", line 94, characters 6-26
47
Called from Names.klass2#othermeth.(fun) in file "names.ml", line 88, characters 18-22
@@ -23,4 +26,4 @@ Called from Names.Mod1.Nested.apply in file "names.ml", line 21, characters 33-3
2326
Called from Names.fn_poly in file "names.ml", line 17, characters 2-5
2427
Called from Names.fn_function in file "names.ml", line 14, characters 9-13
2528
Called from Names.fn_multi in file "names.ml", line 11, characters 36-40
26-
Called from Names in file "names.ml", line 103, characters 4-445
29+
Called from Names in file "names.ml", line 107, characters 4-467
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Raised at Names_partial_application.bang in file "names_partial_application.ml", line 9, characters 29-39
2+
Called from Names_partial_application.labelled_arguments_partial.f in file "names_partial_application.ml", line 12, characters 38-42
3+
Called from Names_partial_application.labelled_arguments_partial in file "names_partial_application.ml", line 14, characters 2-15
4+
Called from Names_partial_application in file "names_partial_application.ml", line 20, characters 4-54

0 commit comments

Comments
 (0)