Skip to content

Commit 1d8d9b5

Browse files
committed
Merge pull request ocaml#423 from mshinwell/flambda_prereq-clflags
GPR#423: Clflags changes for flambda
2 parents 7ab7232 + 56c7413 commit 1d8d9b5

15 files changed

+514
-30
lines changed

.depend

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
utils/arg_helper.cmi :
12
utils/ccomp.cmi :
2-
utils/clflags.cmi : utils/misc.cmi
3+
utils/clflags.cmi : utils/numbers.cmi utils/misc.cmi
34
utils/config.cmi :
45
utils/consistbl.cmi :
56
utils/identifiable.cmi :
@@ -10,12 +11,16 @@ utils/tbl.cmi :
1011
utils/terminfo.cmi :
1112
utils/timings.cmi :
1213
utils/warnings.cmi :
14+
utils/arg_helper.cmo : utils/misc.cmi utils/arg_helper.cmi
15+
utils/arg_helper.cmx : utils/misc.cmx utils/arg_helper.cmi
1316
utils/ccomp.cmo : utils/misc.cmi utils/config.cmi utils/clflags.cmi \
1417
utils/ccomp.cmi
1518
utils/ccomp.cmx : utils/misc.cmx utils/config.cmx utils/clflags.cmx \
1619
utils/ccomp.cmi
17-
utils/clflags.cmo : utils/misc.cmi utils/config.cmi utils/clflags.cmi
18-
utils/clflags.cmx : utils/misc.cmx utils/config.cmx utils/clflags.cmi
20+
utils/clflags.cmo : utils/numbers.cmi utils/misc.cmi utils/config.cmi \
21+
utils/arg_helper.cmi utils/clflags.cmi
22+
utils/clflags.cmx : utils/numbers.cmx utils/misc.cmx utils/config.cmx \
23+
utils/arg_helper.cmx utils/clflags.cmi
1924
utils/config.cmo : utils/config.cmi
2025
utils/config.cmx : utils/config.cmi
2126
utils/consistbl.cmo : utils/consistbl.cmi

Makefile.shared

+3-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ OCAMLDOC_OPT=$(WITH_OCAMLDOC:=.opt)
3636
INCLUDES=-I utils -I parsing -I typing -I bytecomp -I asmcomp -I driver \
3737
-I toplevel
3838

39-
UTILS=utils/config.cmo utils/clflags.cmo \
40-
utils/misc.cmo \
41-
utils/identifiable.cmo utils/numbers.cmo \
42-
utils/tbl.cmo utils/timings.cmo \
39+
UTILS=utils/config.cmo utils/misc.cmo \
40+
utils/identifiable.cmo utils/numbers.cmo utils/arg_helper.cmo \
41+
utils/clflags.cmo utils/tbl.cmo utils/timings.cmo \
4342
utils/terminfo.cmo utils/ccomp.cmo utils/warnings.cmo \
4443
utils/consistbl.cmo \
4544
utils/strongly_connected_components.cmo

asmcomp/closure.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,12 @@ and close_functions fenv cenv fun_defs =
11601160
in
11611161
let threshold =
11621162
match inline_attribute with
1163-
| Default_inline -> !Clflags.inline_threshold + n
1163+
| Default_inline ->
1164+
let inline_threshold =
1165+
Clflags.Float_arg_helper.get ~key:0 !Clflags.inline_threshold
1166+
in
1167+
let magic_scale_constant = 8. in
1168+
int_of_float (inline_threshold *. magic_scale_constant) + n
11641169
| Always_inline -> max_int
11651170
| Never_inline -> min_int
11661171
in

debugger/Makefile.shared

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ INCLUDES=\
3030

3131
OTHEROBJS=\
3232
$(UNIXDIR)/unix.cma \
33-
../utils/config.cmo ../utils/tbl.cmo \
34-
../utils/clflags.cmo ../utils/misc.cmo \
33+
../utils/config.cmo ../utils/tbl.cmo ../utils/misc.cmo \
3534
../utils/identifiable.cmo ../utils/numbers.cmo \
35+
../utils/arg_helper.cmo ../utils/clflags.cmo \
3636
../utils/consistbl.cmo ../utils/warnings.cmo \
3737
../utils/terminfo.cmo \
3838
../parsing/location.cmo ../parsing/longident.cmo ../parsing/docstrings.cmo \

driver/compenv.ml

+12-7
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,18 @@ let read_OCAMLPARAM ppf position =
206206
| "wwe" -> Warnings.parse_options false v
207207

208208
(* inlining *)
209-
| "inline" -> begin try
210-
inline_threshold := 8 * int_of_string v
211-
with _ ->
212-
Location.print_warning Location.none ppf
213-
(Warnings.Bad_env_variable ("OCAMLPARAM",
214-
"non-integer parameter for \"inline\""))
215-
end
209+
| "inline" ->
210+
let module F = Float_arg_helper in
211+
begin match F.parse_no_error v inline_threshold with
212+
| F.Ok -> ()
213+
| F.Parse_failed exn ->
214+
let error =
215+
Printf.sprintf "bad syntax for \"inline\": %s"
216+
(Printexc.to_string exn)
217+
in
218+
Location.print_warning Location.none ppf
219+
(Warnings.Bad_env_variable ("OCAMLPARAM", error))
220+
end
216221

217222
(* color output *)
218223
| "color" ->

driver/main_args.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ let mk_init f =
110110
;;
111111

112112
let mk_inline f =
113-
"-inline", Arg.Int f, "<n> Set aggressiveness of inlining to <n>"
113+
"-inline", Arg.String f, "<n> Set aggressiveness of inlining to <n>"
114114
;;
115115

116116
let mk_intf f =
@@ -605,7 +605,7 @@ end;;
605605

606606
module type Optcommon_options = sig
607607
val _compact : unit -> unit
608-
val _inline : int -> unit
608+
val _inline : string -> unit
609609

610610
val _dclambda : unit -> unit
611611
val _dcmm : unit -> unit

driver/main_args.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ end;;
117117

118118
module type Optcommon_options = sig
119119
val _compact : unit -> unit
120-
val _inline : int -> unit
120+
val _inline : string -> unit
121121

122122
val _dclambda : unit -> unit
123123
val _dcmm : unit -> unit

driver/optmain.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ module Options = Main_args.Make_optcomp_options (struct
8686
let _i () = print_types := true; compile_only := true
8787
let _I dir = include_dirs := dir :: !include_dirs
8888
let _impl = impl
89-
let _inline n = inline_threshold := n * 8
89+
let _inline spec =
90+
Float_arg_helper.parse spec ~update:inline_threshold
91+
~help_text:"Syntax: -inline <n>"
9092
let _intf = intf
9193
let _intf_suffix s = Config.interface_suffix := s
9294
let _keep_docs = set keep_docs

otherlibs/dynlink/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ COMPFLAGS=-w +33..39 -warn-error A -bin-annot -g -safe-string \
3030
OBJS=dynlinkaux.cmo dynlink.cmo
3131

3232
COMPILEROBJS=\
33-
../../utils/misc.cmo ../../utils/config.cmo ../../utils/clflags.cmo \
33+
../../utils/misc.cmo ../../utils/config.cmo \
3434
../../utils/identifiable.cmo ../../utils/numbers.cmo \
35+
../../utils/arg_helper.cmo ../../utils/clflags.cmo \
3536
../../utils/tbl.cmo ../../utils/consistbl.cmo \
3637
../../utils/terminfo.cmo ../../utils/warnings.cmo \
3738
../../parsing/asttypes.cmi \

tools/Makefile.shared

+7-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ opt.opt: ocamldep.opt read_cmt.opt
3636

3737
CAMLDEP_OBJ=depend.cmo ocamldep.cmo
3838
CAMLDEP_IMPORTS=timings.cmo misc.cmo config.cmo identifiable.cmo numbers.cmo \
39-
clflags.cmo terminfo.cmo \
39+
arg_helper.cmo clflags.cmo terminfo.cmo \
4040
warnings.cmo location.cmo longident.cmo docstrings.cmo \
4141
syntaxerr.cmo ast_helper.cmo parser.cmo lexer.cmo parse.cmo \
4242
ccomp.cmo ast_mapper.cmo pparse.cmo compenv.cmo builtin_attributes.cmo
@@ -67,18 +67,20 @@ install::
6767

6868
CSLPROF=ocamlprof.cmo
6969
CSLPROF_IMPORTS=misc.cmo config.cmo identifiable.cmo numbers.cmo \
70-
clflags.cmo terminfo.cmo \
70+
arg_helper.cmo clflags.cmo terminfo.cmo \
7171
warnings.cmo location.cmo longident.cmo docstrings.cmo \
7272
syntaxerr.cmo ast_helper.cmo parser.cmo lexer.cmo parse.cmo
7373

7474
ocamlprof: $(CSLPROF) profiling.cmo
7575
$(CAMLC) $(LINKFLAGS) -o ocamlprof $(CSLPROF_IMPORTS) $(CSLPROF)
7676

7777
ocamlcp: ocamlcp.cmo
78-
$(CAMLC) $(LINKFLAGS) -o ocamlcp warnings.cmo main_args.cmo ocamlcp.cmo
78+
$(CAMLC) $(LINKFLAGS) -o ocamlcp warnings.cmo misc.cmo config.cmo \
79+
identifiable.cmo numbers.cmo arg_helper.cmo clflags.cmo main_args.cmo ocamlcp.cmo
7980

8081
ocamloptp: ocamloptp.cmo
81-
$(CAMLC) $(LINKFLAGS) -o ocamloptp warnings.cmo main_args.cmo \
82+
$(CAMLC) $(LINKFLAGS) -o ocamloptp warnings.cmo misc.cmo config.cmo \
83+
identifiable.cmo numbers.cmo arg_helper.cmo clflags.cmo main_args.cmo \
8284
ocamloptp.cmo
8385

8486
opt:: profiling.cmx
@@ -160,7 +162,7 @@ clean::
160162

161163
# Insert labels following an interface file (upgrade 3.02 to 3.03)
162164

163-
ADDLABELS_IMPORTS=misc.cmo config.cmo clflags.cmo \
165+
ADDLABELS_IMPORTS=misc.cmo config.cmo arg_helper.cmo clflags.cmo \
164166
identifiable.cmo numbers.cmo terminfo.cmo \
165167
warnings.cmo location.cmo longident.cmo docstrings.cmo \
166168
syntaxerr.cmo ast_helper.cmo parser.cmo lexer.cmo parse.cmo

tools/ocamloptp.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module Options = Main_args.Make_optcomp_options (struct
5858
let _i = option "-i"
5959
let _I s = option_with_arg "-I" s
6060
let _impl s = with_impl := true; option_with_arg "-impl" s
61-
let _inline n = option_with_int "-inline" n
61+
let _inline s = option_with_arg "-inline" s
6262
let _intf s = with_intf := true; option_with_arg "-intf" s
6363
let _intf_suffix s = option_with_arg "-intf-suffix" s
6464
let _keep_docs = option "-keep-docs"

utils/arg_helper.ml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Pierre Chambart, OCamlPro *)
6+
(* Mark Shinwell and Leo White, Jane Street Europe *)
7+
(* *)
8+
(* Copyright 2015--2016 OCamlPro SAS *)
9+
(* Copyright 2015--2016 Jane Street Group LLC *)
10+
(* *)
11+
(* All rights reserved. This file is distributed under the terms of *)
12+
(* the GNU Lesser General Public License version 2.1, with the *)
13+
(* special exception on linking described in the file ../LICENSE. *)
14+
(* *)
15+
(**************************************************************************)
16+
17+
let fatal err =
18+
prerr_endline err;
19+
exit 2
20+
21+
module Make (S : sig
22+
module Key : sig
23+
type t
24+
val of_string : string -> t
25+
module Map : Map.S with type key = t
26+
end
27+
28+
module Value : sig
29+
type t
30+
val of_string : string -> t
31+
end
32+
end) = struct
33+
type parsed = {
34+
default : S.Value.t;
35+
override : S.Value.t S.Key.Map.t;
36+
}
37+
38+
let default v = { default = v; override = S.Key.Map.empty }
39+
40+
let no_equals value =
41+
match String.index value '=' with
42+
| exception Not_found -> true
43+
| _index -> false
44+
45+
exception Parse_failure of exn
46+
47+
let parse_exn str ~update =
48+
let values = Misc.Stdlib.String.split str ~on:',' in
49+
let parsed =
50+
List.fold_left (fun acc value ->
51+
match String.index value '=' with
52+
| exception Not_found ->
53+
begin match S.Value.of_string value with
54+
| value -> { acc with default = value }
55+
| exception exn -> raise (Parse_failure exn)
56+
end
57+
| equals ->
58+
let key_value_pair = value in
59+
let length = String.length key_value_pair in
60+
assert (equals >= 0 && equals < length);
61+
if equals = 0 then begin
62+
raise (Parse_failure (
63+
Failure "Missing key in argument specification"))
64+
end;
65+
let key =
66+
let key = String.sub key_value_pair 0 equals in
67+
try S.Key.of_string key
68+
with exn -> raise (Parse_failure exn)
69+
in
70+
let value =
71+
let value =
72+
String.sub key_value_pair (equals + 1) (length - equals - 1)
73+
in
74+
try S.Value.of_string value
75+
with exn -> raise (Parse_failure exn)
76+
in
77+
{ acc with override = S.Key.Map.add key value acc.override })
78+
!update
79+
values
80+
in
81+
update := parsed
82+
83+
let parse str ~help_text ~update =
84+
match parse_exn str ~update with
85+
| () -> ()
86+
| exception (Parse_failure exn) ->
87+
fatal (Printf.sprintf "%s: %s" (Printexc.to_string exn) help_text)
88+
89+
type parse_result =
90+
| Ok
91+
| Parse_failed of exn
92+
93+
let parse_no_error str ~update =
94+
match parse_exn str ~update with
95+
| () -> Ok
96+
| exception (Parse_failure exn) -> Parse_failed exn
97+
98+
let get ~key parsed =
99+
match S.Key.Map.find key parsed.override with
100+
| provided -> provided
101+
| exception Not_found ->
102+
parsed.default
103+
end

utils/arg_helper.mli

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Pierre Chambart, OCamlPro *)
6+
(* Mark Shinwell and Leo White, Jane Street Europe *)
7+
(* *)
8+
(* Copyright 2015--2016 OCamlPro SAS *)
9+
(* Copyright 2015--2016 Jane Street Group LLC *)
10+
(* *)
11+
(* All rights reserved. This file is distributed under the terms of *)
12+
(* the GNU Lesser General Public License version 2.1, with the *)
13+
(* special exception on linking described in the file ../LICENSE. *)
14+
(* *)
15+
(**************************************************************************)
16+
17+
(** Decipher command line arguments of the form
18+
<value> | <key>=<value>[,...]
19+
(as used for example for the specification of inlining parameters
20+
varying by simplification round).
21+
*)
22+
23+
module Make (S : sig
24+
module Key : sig
25+
type t
26+
27+
(** The textual representation of a key must not contain '=' or ','. *)
28+
val of_string : string -> t
29+
30+
module Map : Map.S with type key = t
31+
end
32+
33+
module Value : sig
34+
type t
35+
36+
(** The textual representation of a value must not contain ','. *)
37+
val of_string : string -> t
38+
end
39+
end) : sig
40+
type parsed = {
41+
default : S.Value.t;
42+
override : S.Value.t S.Key.Map.t;
43+
}
44+
45+
val default : S.Value.t -> parsed
46+
47+
val parse : string -> help_text:string -> update:parsed ref -> unit
48+
49+
type parse_result =
50+
| Ok
51+
| Parse_failed of exn
52+
53+
val parse_no_error : string -> update:parsed ref -> parse_result
54+
55+
val get : key:S.Key.t -> parsed -> S.Value.t
56+
end

0 commit comments

Comments
 (0)