Skip to content

Commit

Permalink
Add {Int,Int32,Int64,NativeInt}.{min,max} (ocaml#10392)
Browse files Browse the repository at this point in the history
  • Loading branch information
alainfrisch authored and Nicolas Chataing committed May 20, 2021
1 parent 95e24f2 commit c3dee5e
Show file tree
Hide file tree
Showing 51 changed files with 183 additions and 79 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ Working version
- #4070, #10398: small optimization of Stdlib.{frexp,modf}.
(Markus Mottl, Nicolás Ojeda Bär, review by Gabriel Scherer)

- #10389, #10391, #10392: Add {Int,Int32,Int64,Nativeint}.{min,max}.
(Nicolás Ojeda Bär and Alain Frisch, review by Xavier Leroy)

### Other libraries:

- #10047: Add `Unix.realpath`
Expand Down
2 changes: 1 addition & 1 deletion asmcomp/branch_relaxation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ module Make (T : Branch_relaxation_intf.S) = struct
let rec relax f ~max_out_of_line_code_offset =
let min_of_max_branch_offsets =
List.fold_left (fun min_of_max_branch_offsets branch ->
min min_of_max_branch_offsets
Int.min min_of_max_branch_offsets
(T.Cond_branch.max_displacement branch))
max_int T.Cond_branch.all
in
Expand Down
2 changes: 1 addition & 1 deletion asmcomp/coloring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let allocate_registers() =
if not (Reg.is_visited r) then begin
Reg.mark_visited r;
f r w;
List.iter (fun (r1, w1) -> walk r1 (min w w1)) r.prefer
List.iter (fun (r1, w1) -> walk r1 (Int.min w w1)) r.prefer
end in
List.iter (fun (r, w) -> walk r w) reg.prefer;
Reg.clear_visited_marks () in
Expand Down
8 changes: 4 additions & 4 deletions asmcomp/emitaux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ let emit_string_directive directive s =
end else begin
let i = ref 0 in
while !i < l do
let n = min (l - !i) 80 in
let n = Int.min (l - !i) 80 in
emit_string directive;
emit_string_literal (String.sub s !i n);
emit_char '\n';
Expand Down Expand Up @@ -248,9 +248,9 @@ let emit_frames a =
a.efa_string defname
in
let pack_info fd_raise d has_next =
let line = min 0xFFFFF d.Debuginfo.dinfo_line
and char_start = min 0xFF d.Debuginfo.dinfo_char_start
and char_end = min 0x3FF d.Debuginfo.dinfo_char_end
let line = Int.min 0xFFFFF d.Debuginfo.dinfo_line
and char_start = Int.min 0xFF d.Debuginfo.dinfo_char_start
and char_end = Int.min 0x3FF d.Debuginfo.dinfo_char_end
and kind = if fd_raise then 1 else 0
and has_next = if has_next then 1 else 0 in
Int64.(add (shift_left (of_int line) 44)
Expand Down
2 changes: 1 addition & 1 deletion asmcomp/schedgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ let rec longest_path critical_outputs node =
node.length <-
List.fold_left
(fun len (son, delay) ->
max len (longest_path critical_outputs son + delay))
Int.max len (longest_path critical_outputs son + delay))
0 sons
end;
node.length
Expand Down
2 changes: 1 addition & 1 deletion asmcomp/selectgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ method insert_move env src dst =
self#insert env (Iop Imove) [|src|] [|dst|]

method insert_moves env src dst =
for i = 0 to min (Array.length src) (Array.length dst) - 1 do
for i = 0 to Stdlib.Int.min (Array.length src) (Array.length dst) - 1 do
self#insert_move env src.(i) dst.(i)
done

Expand Down
4 changes: 2 additions & 2 deletions asmcomp/spill.ml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ let rec reload i before =
let date_ifso = !current_date in
current_date := date_fork;
let (new_ifnot, after_ifnot) = reload ifnot at_fork in
current_date := max date_ifso !current_date;
current_date := Int.max date_ifso !current_date;
let (new_next, finally) =
reload i.next (Reg.Set.union after_ifso after_ifnot) in
let new_i =
Expand All @@ -189,7 +189,7 @@ let rec reload i before =
current_date := date_fork;
let (new_c, after_c) = reload c at_fork in
after_cases := Reg.Set.union !after_cases after_c;
date_join := max !date_join !current_date;
date_join := Int.max !date_join !current_date;
new_c)
cases in
current_date := !date_join;
Expand Down
2 changes: 1 addition & 1 deletion debugger/command_line.ml
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ let instr_list _ppf lexbuf =
1
| None ->
begin try
max 1 (line - 10)
Int.max 1 (line - 10)
with Out_of_range ->
1
end
Expand Down
4 changes: 2 additions & 2 deletions debugger/time_travel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ let rec back_to time time_max =
let
{c_time = t} = find_checkpoint_before (pre64 time_max)
in
go_to (max time t);
go_to (Int64.max time t);
let (new_time, break) = find_last_breakpoint time_max in
if break <> None || (new_time <= time) then begin
go_to new_time;
Expand All @@ -520,7 +520,7 @@ let rec back_to time time_max =
let step_backward duration =
let time = current_time () in
if time > _0 then
back_to (max _0 (time -- duration)) time
back_to (Int64.max _0 (time -- duration)) time

(* Run the program from current time. *)
(* Stop at the first breakpoint, or at the end of the program. *)
Expand Down
4 changes: 2 additions & 2 deletions lambda/simplif.ml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ let simplify_exits lam =
match Hashtbl.find_opt exits i with
| Some r ->
r.count <- r.count + nb;
r.max_depth <- max r.max_depth d
r.max_depth <- Int.max r.max_depth d
| None ->
let r = {count = nb; max_depth = d} in
Hashtbl.add exits i r
Expand Down Expand Up @@ -155,7 +155,7 @@ let simplify_exits lam =
increases j's ref count *)
count ~try_depth l1 ;
let ic = get_exit i in
incr_exit j ic.count (max try_depth ic.max_depth)
incr_exit j ic.count (Int.max try_depth ic.max_depth)
| Lstaticcatch(l1, (i,_), l2) ->
count ~try_depth l1;
(* If l1 does not contain (exit i),
Expand Down
2 changes: 1 addition & 1 deletion lex/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let copy_buffer = Bytes.create 1024
let copy_chars_unix ic oc start stop =
let n = ref (stop - start) in
while !n > 0 do
let m = input ic copy_buffer 0 (min !n 1024) in
let m = input ic copy_buffer 0 (Int.min !n 1024) in
output oc copy_buffer 0 m;
n := !n - m
done
Expand Down
4 changes: 2 additions & 2 deletions lex/cset.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ let rec inter l l' = match l, l' with
else if c2' < c1 then
inter l r'
else if c2 < c2' then
(max c1 c1', c2)::inter r l'
(Int.max c1 c1', c2)::inter r l'
else
(max c1 c1', c2')::inter l r'
(Int.max c1 c1', c2')::inter l r'

let rec diff l l' = match l, l' with
_, [] -> l
Expand Down
2 changes: 1 addition & 1 deletion lex/lexgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ let encode_casedef casedef =
Alt(reg, Seq(r, Action count)),
(count, m ,act) :: actions,
(succ count),
max loc_ntags ntags)
Int.max loc_ntags ntags)
(Empty, [], 0, 0)
casedef in
r
Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda/flambda_to_clambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ and to_clambda_switch t env cases num_keys default =
List.iter
(fun (key, lam) ->
index.(key) <- store.act_store () lam;
smallest_key := min key !smallest_key
smallest_key := Int.min key !smallest_key
)
cases;
if !smallest_key < num_keys then begin
Expand Down
4 changes: 2 additions & 2 deletions middle_end/flambda/inline_and_simplify_aux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ module Env = struct
try
Closure_origin.Map.find id t.inlining_counts
with Not_found ->
max 1 (Clflags.Int_arg_helper.get
Int.max 1 (Clflags.Int_arg_helper.get
~key:t.round !Clflags.inline_max_unroll)
in
inlining_count > 0
Expand All @@ -343,7 +343,7 @@ module Env = struct
try
Closure_origin.Map.find id t.inlining_counts
with Not_found ->
max 1 (Clflags.Int_arg_helper.get
Int.max 1 (Clflags.Int_arg_helper.get
~key:t.round !Clflags.inline_max_unroll)
in
let inlining_counts =
Expand Down
6 changes: 3 additions & 3 deletions middle_end/flambda/inlining_cost.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module Threshold = struct
| Never_inline, _ -> Never_inline
| _, Never_inline -> Never_inline
| Can_inline_if_no_larger_than i1, Can_inline_if_no_larger_than i2 ->
Can_inline_if_no_larger_than (min i1 i2)
Can_inline_if_no_larger_than (Int.min i1 i2)

let equal t1 t2 =
match t1, t2 with
Expand Down Expand Up @@ -674,7 +674,7 @@ let maximum_interesting_size_of_function_body_base =
let inline_call_cost = cost !Clflags.inline_call_cost ~round in
direct_call_size + (inline_call_cost * benefit_factor)
in
max_cost := max !max_cost max_size
max_cost := Int.max !max_cost max_size
done;
!max_cost
end
Expand All @@ -687,7 +687,7 @@ let maximum_interesting_size_of_function_body_multiplier =
let inline_prim_cost = cost !Clflags.inline_prim_cost ~round in
inline_prim_cost * benefit_factor
in
max_cost := max !max_cost max_size
max_cost := Int.max !max_cost max_size
done;
!max_cost
end
Expand Down
8 changes: 4 additions & 4 deletions ocamldoc/odoc_dag2html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ let html_table_struct indi_txt phony d t =
next_l next_j;
flush stderr
end;
let next_l = min next_l next_j in
let next_l = Int.min next_l next_j in
let colspan = 3 * (next_l - l) - 2 in
let les =
match t.table.(i).(l).elem, t.table.(i + 1).(l).elem with
Expand Down Expand Up @@ -343,8 +343,8 @@ let rec get_block t i j =
match get_block t i (j + 1) with
Some ((x1, c1) :: list, mpc, span) ->
let (list, mpc) =
if x1 = x.elem then (x1, c1 + 1) :: list, max mpc (c1 + 1)
else (x.elem, 1) :: (x1, c1) :: list, max mpc c1
if x1 = x.elem then (x1, c1 + 1) :: list, Int.max mpc (c1 + 1)
else (x.elem, 1) :: (x1, c1) :: list, Int.max mpc c1
in
Some (list, mpc, span)
| _ -> assert false
Expand Down Expand Up @@ -753,7 +753,7 @@ let find_block_with_parents t i jj1 jj2 jj3 jj4 =
in
if nii <> ii || njj1 <> jj1 || njj2 <> jj2 || njj3 <> jj3 ||
njj4 <> jj4 then
let nii = min ii nii in
let nii = Int.min ii nii in
let (jj1, jj2, jj3, jj4) =
find_linked_children t nii njj1 njj2 njj3 njj4
in
Expand Down
2 changes: 1 addition & 1 deletion ocamltest/ocamltest_stdlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ module Sys = struct
let copy_chan ic oc =
let m = in_channel_length ic in
let m = (m lsr 12) lsl 12 in
let m = max 16384 (min Sys.max_string_length m) in
let m = Int.max 16384 (Int.min Sys.max_string_length m) in
let buf = Bytes.create m in
let rec loop () =
let len = input ic buf 0 m in
Expand Down
4 changes: 2 additions & 2 deletions otherlibs/str/str.ml
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ let compile fold_case re =
emit_instr op_BEGGROUP n;
emit_code r;
emit_instr op_ENDGROUP n;
numgroups := max !numgroups (n+1)
numgroups := Int.max !numgroups (n+1)
| Refgroup n ->
emit_instr op_REFGROUP n;
numgroups := max !numgroups (n+1)
numgroups := Int.max !numgroups (n+1)
| Bol ->
emit_instr op_BOL 0
| Eol ->
Expand Down
14 changes: 14 additions & 0 deletions stdlib/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ stdlib__Arg.cmo : arg.ml \
stdlib__String.cmi \
stdlib__Printf.cmi \
stdlib__List.cmi \
stdlib__Int.cmi \
stdlib__Buffer.cmi \
stdlib__Array.cmi \
stdlib__Arg.cmi
Expand All @@ -11,6 +12,7 @@ stdlib__Arg.cmx : arg.ml \
stdlib__String.cmx \
stdlib__Printf.cmx \
stdlib__List.cmx \
stdlib__Int.cmx \
stdlib__Buffer.cmx \
stdlib__Array.cmx \
stdlib__Arg.cmi
Expand Down Expand Up @@ -80,12 +82,14 @@ stdlib__Bytes.cmo : bytes.ml \
stdlib__Sys.cmi \
stdlib.cmi \
stdlib__Seq.cmi \
stdlib__Int.cmi \
stdlib__Char.cmi \
stdlib__Bytes.cmi
stdlib__Bytes.cmx : bytes.ml \
stdlib__Sys.cmx \
stdlib.cmx \
stdlib__Seq.cmx \
stdlib__Int.cmx \
stdlib__Char.cmx \
stdlib__Bytes.cmi
stdlib__Bytes.cmi : bytes.mli \
Expand Down Expand Up @@ -213,6 +217,7 @@ stdlib__Ephemeron.cmo : ephemeron.ml \
stdlib__Random.cmi \
stdlib__Obj.cmi \
stdlib__Lazy.cmi \
stdlib__Int.cmi \
stdlib__Hashtbl.cmi \
stdlib__Array.cmi \
stdlib__Ephemeron.cmi
Expand All @@ -222,6 +227,7 @@ stdlib__Ephemeron.cmx : ephemeron.ml \
stdlib__Random.cmx \
stdlib__Obj.cmx \
stdlib__Lazy.cmx \
stdlib__Int.cmx \
stdlib__Hashtbl.cmx \
stdlib__Array.cmx \
stdlib__Ephemeron.cmi
Expand Down Expand Up @@ -338,6 +344,7 @@ stdlib__Hashtbl.cmo : hashtbl.ml \
stdlib__Random.cmi \
stdlib__Obj.cmi \
stdlib__Lazy.cmi \
stdlib__Int.cmi \
stdlib__Array.cmi \
stdlib__Hashtbl.cmi
stdlib__Hashtbl.cmx : hashtbl.ml \
Expand All @@ -347,6 +354,7 @@ stdlib__Hashtbl.cmx : hashtbl.ml \
stdlib__Random.cmx \
stdlib__Obj.cmx \
stdlib__Lazy.cmx \
stdlib__Int.cmx \
stdlib__Array.cmx \
stdlib__Hashtbl.cmi
stdlib__Hashtbl.cmi : hashtbl.mli \
Expand Down Expand Up @@ -387,12 +395,14 @@ stdlib__Lazy.cmi : lazy.mli \
stdlib__Lexing.cmo : lexing.ml \
stdlib__Sys.cmi \
stdlib__String.cmi \
stdlib__Int.cmi \
stdlib__Bytes.cmi \
stdlib__Array.cmi \
stdlib__Lexing.cmi
stdlib__Lexing.cmx : lexing.ml \
stdlib__Sys.cmx \
stdlib__String.cmx \
stdlib__Int.cmx \
stdlib__Bytes.cmx \
stdlib__Array.cmx \
stdlib__Lexing.cmi
Expand Down Expand Up @@ -581,6 +591,7 @@ stdlib__Scanf.cmo : scanf.ml \
stdlib.cmi \
stdlib__Printf.cmi \
stdlib__List.cmi \
stdlib__Int.cmi \
camlinternalFormatBasics.cmi \
camlinternalFormat.cmi \
stdlib__Bytes.cmi \
Expand All @@ -591,6 +602,7 @@ stdlib__Scanf.cmx : scanf.ml \
stdlib.cmx \
stdlib__Printf.cmx \
stdlib__List.cmx \
stdlib__Int.cmx \
camlinternalFormatBasics.cmx \
camlinternalFormat.cmx \
stdlib__Bytes.cmx \
Expand Down Expand Up @@ -695,12 +707,14 @@ stdlib__Unit.cmi : unit.mli
stdlib__Weak.cmo : weak.ml \
stdlib__Sys.cmi \
stdlib__Obj.cmi \
stdlib__Int.cmi \
stdlib__Hashtbl.cmi \
stdlib__Array.cmi \
stdlib__Weak.cmi
stdlib__Weak.cmx : weak.ml \
stdlib__Sys.cmx \
stdlib__Obj.cmx \
stdlib__Int.cmx \
stdlib__Hashtbl.cmx \
stdlib__Array.cmx \
stdlib__Weak.cmi
Expand Down
2 changes: 1 addition & 1 deletion stdlib/StdlibModules
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
STDLIB_MODULE_BASENAMES=\
camlinternalFormatBasics camlinternalAtomic \
stdlib pervasives seq option either result bool char uchar \
sys list bytes string unit marshal obj array float int int32 int64 nativeint \
sys list int bytes string unit marshal obj array float int32 int64 nativeint \
lexing parsing set map stack queue camlinternalLazy lazy stream buffer \
camlinternalFormat printf arg atomic \
printexc fun gc digest random hashtbl weak \
Expand Down

0 comments on commit c3dee5e

Please sign in to comment.