Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .depend
Original file line number Diff line number Diff line change
Expand Up @@ -7090,10 +7090,12 @@ driver/compmisc.cmo : \
typing/types.cmi \
typing/typemod.cmi \
utils/misc.cmi \
lambda/matching.cmi \
parsing/location.cmi \
utils/load_path.cmi \
typing/ident.cmi \
typing/env.cmi \
typing/ctype.cmi \
utils/config.cmi \
driver/compenv.cmi \
utils/clflags.cmi \
Expand All @@ -7103,10 +7105,12 @@ driver/compmisc.cmx : \
typing/types.cmx \
typing/typemod.cmx \
utils/misc.cmx \
lambda/matching.cmx \
parsing/location.cmx \
utils/load_path.cmx \
typing/ident.cmx \
typing/env.cmx \
typing/ctype.cmx \
utils/config.cmx \
driver/compenv.cmx \
utils/clflags.cmx \
Expand Down
31 changes: 31 additions & 0 deletions AI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Guidelines relevant to AI-assisted contributions

Tools using AI are increasingly used to produce text and code, but verifying the
quality of such output can be difficult. We ask you, the contributor(s), to be
willing to adapt your workflow accordingly. The guidelines also apply, or have
a direct counterpart, with entirely human-produced content.

1. We strive to evaluate contributions based on their merit, not their authors.

2. We ask that you have either written, or read and reviewed yourself,
*every part* of your contribution. You are responsible for its quality.
It is strongly recommended that you review a proposed contribution in full
even if you wrote all of it.

3. If a significant portion of your code, PR description, review comments or
messages has been AI-generated, this must be disclosed, stating which tool
was used and for what. Reviewing AI-produced code can require a different
approach from human-written code. You should have an acknowledgement
anyway even if another *human* contributor did some of the work.

4. Please be mindful that reviewer time is a scarce resource. Contributions
(whether human- or AI-authored) should strive to conserve it.

5. When you submit code, however it was written, you take responsibility for
its provenance. You will need to sign the OCaml contributor licence
agreement (CLA) for any significant contribution.

6. The following are never acceptable as contributions: low-effort productions
of code that contributors do not understand; plagiarised works; hallucinated
security reports; or experiments involving humans without their advance
consent.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ log -u` to make sure the rebase patches make sense), but:
changes, or an un-testable intermediary state) is a sure way to
generate ill will.

## Guidelines relevant to AI-assisted contributions

See the dedicated [AI.md](AI.md).

## Contributing to the standard library

Contributions to the standard library are very welcome.
Expand Down
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ Working version
(Jacques Garrigue and Takafumi Saikawa, reported by Olivier Nicole,
review by Gabriel Scherer)

- #14483: Reset type ID and level counters between compilations to restore
reproducibility of debug information between `ocamlc -c foo.mli foo.ml` versus
`ocamlc -c foo.mli; ocamlc -c foo.ml`. Also reset the globals in Matching, or
identifier strings from a previous compilation are marshalled separately from
identifiers referring to the Lazy module.
(David Allsopp, review by ???)

### Other libraries:

- #13700, #14454: Use POSIX thread-safe getgrnam_r, getgrgid_r, getpwnam_r,
Expand Down
3 changes: 3 additions & 0 deletions driver/compmisc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ let init_path ?(standard_library=Config.standard_library)
let initial_env () =
Ident.reinit();
Types.Uid.reinit();
Types.reset();
Ctype.reset();
Matching.reset();
let initially_opened_module =
if !Clflags.nopervasives then
None
Expand Down
19 changes: 13 additions & 6 deletions lambda/matching.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2142,11 +2142,18 @@ let get_pat_args_lazy p rem =

let prim_obj_tag = Primitive.simple ~name:"caml_obj_tag" ~arity:1 ~alloc:false

let code_force_lazy_block =
lazy (transl_prim "CamlinternalLazy" "force_lazy_block")
let dummy = lazy (Lconst (Const_int 42))
let code_force_lazy_block = ref dummy
let code_force_lazy = ref dummy

let code_force_lazy =
lazy (transl_prim "CamlinternalLazy" "force_gen")
let reset () =
code_force_lazy_block :=
lazy (transl_prim "CamlinternalLazy" "force_lazy_block");
code_force_lazy :=
lazy (transl_prim "CamlinternalLazy" "force_gen")

let () =
reset ()

(* inline_lazy_force inlines the beginning of the code of Lazy.force. When
the value argument is tagged as:
Expand All @@ -2164,7 +2171,7 @@ let call_force_lazy_block varg loc =
[CamlinternalLazy.force_gen], and discussions on PRs #9998 and #10909).
Alternatively, [ap_inlined] could be set to [Never_inline] to achieve a
similar result. *)
let force_fun = Lazy.force code_force_lazy_block in
let force_fun = Lazy.force !code_force_lazy_block in
Lapply
{ ap_tailcall = Default_tailcall;
ap_loc = loc;
Expand Down Expand Up @@ -2243,7 +2250,7 @@ let inline_lazy_force arg loc =
Lapply
{ ap_tailcall = Default_tailcall;
ap_loc = loc;
ap_func = Lazy.force code_force_lazy;
ap_func = Lazy.force !code_force_lazy;
ap_args = [ Lconst (Const_int 0); arg ];
ap_inlined = Never_inline;
ap_specialised = Default_specialise
Expand Down
2 changes: 2 additions & 0 deletions lambda/matching.mli
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ val expand_stringswitch:
lambda option -> lambda

val inline_lazy_force : lambda -> scoped_location -> lambda

val reset : unit -> unit
102 changes: 102 additions & 0 deletions testsuite/tests/tool-ocamlc-determinism/determinism.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
(* TEST
include ocamlcommon;
include ocamlbytecomp;
readonly_files = "test_module.ml test_module.mli trigger_lazy.ml";
setup-ocamlc.byte-build-env;

(* First compilation: .mli and .ml separately *)
flags = "-g";
all_modules = "test_module.mli";
compile_only = "true";
ocamlc.byte;
all_modules = "test_module.ml";
ocamlc.byte;
src = "test_module.cmo";
dst = "test_module_solo.cmo";
copy;


(* Second compilation: all files together *)
all_modules = "trigger_lazy.ml test_module.mli test_module.ml";
ocamlc.byte;
src = "test_module.cmo";
dst = "test_module_with_mli.cmo";
copy;

(* Now run the comparison test *)
{
compile_only = "false";
all_modules = "determinism.ml";
program = "${test_build_directory}/determinism.exe";
ocamlc.byte;
run;
check-program-output;
}
*)

(* Test that .cmo files are identical except for debug info
when compiled separately vs together with .mli *)

let load_cmo_and_debug filename =
let ic = open_in_bin filename in
(* Skip magic number *)
let _ = really_input_string ic (String.length Config.cmo_magic_number) in
(* Read compilation unit *)
let compunit_pos = input_binary_int ic in
seek_in ic compunit_pos;
let cu : Cmo_format.compilation_unit = input_value ic in

(* Load debug data if present *)
let debug_data =
if cu.cu_debug > 0 then begin
seek_in ic cu.cu_debug;
let events : Instruct.debug_event list = input_value ic in
let dirs : string list = input_value ic in
Some (events, dirs)
end else
None
in
close_in ic;
(cu, debug_data)

let () =
let (cu1, debug1) = load_cmo_and_debug "test_module_solo.cmo" in
let (cu2, debug2) = load_cmo_and_debug "test_module_with_mli.cmo" in

(* Check that all non-debug-content fields are identical *)
if cu1.cu_name <> cu2.cu_name
|| cu1.cu_imports <> cu2.cu_imports
|| cu1.cu_required_compunits <> cu2.cu_required_compunits
|| cu1.cu_primitives <> cu2.cu_primitives
|| cu1.cu_force_link <> cu2.cu_force_link
|| cu1.cu_debug <> cu2.cu_debug (* offset should be the same *)
then
failwith "Non-debug fields differ!";

(* Check if the files are byte-for-byte identical *)
let load_file filename =
let ic = open_in_bin filename in
let size = in_channel_length ic in
let bytes = Bytes.create size in
really_input ic bytes 0 size;
close_in ic;
bytes
in
let bytes1 = load_file "test_module_solo.cmo" in
let bytes2 = load_file "test_module_with_mli.cmo" in
if bytes1 = bytes2 then
print_endline "CMO files are identical"
else
print_endline "CMO files differ";

if cu1.cu_debug > 0 && cu2.cu_debug > 0 then begin
let debug_section1 = Bytes.sub bytes1 cu1.cu_debug cu1.cu_debugsize in
let debug_section2 = Bytes.sub bytes2 cu2.cu_debug cu2.cu_debugsize in
if debug_section1 = debug_section2 then
print_endline "Debug events are identical"
else
print_endline "Debug events differ"
end else if cu1.cu_debug = 0 && cu2.cu_debug = 0 then
print_endline "No debug data in either file"
else
print_endline "Debug data presence mismatch"
2 changes: 2 additions & 0 deletions testsuite/tests/tool-ocamlc-determinism/determinism.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CMO files are identical
Debug events are identical
9 changes: 9 additions & 0 deletions testsuite/tests/tool-ocamlc-determinism/test_module.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type t = int
let greeting = "Hello"

type 'a u = 'a CamlinternalLazy.t
exception Undefined = CamlinternalLazy.Undefined
external force : 'a u -> 'a = "%lazy_force"

let map f x =
lazy (f (force x))
2 changes: 2 additions & 0 deletions testsuite/tests/tool-ocamlc-determinism/test_module.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type t
val greeting : string
2 changes: 2 additions & 0 deletions testsuite/tests/tool-ocamlc-determinism/trigger_lazy.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let force_lazy = function
| lazy x -> x
7 changes: 7 additions & 0 deletions typing/ctype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ let increase_global_level () =
let restore_global_level gl =
global_level := gl

(* Reset all level counters - used between compilation units *)
let reset () =
current_level := 0;
nongen_level := 0;
global_level := 0;
saved_levels := []

(**** Some type creators ****)

(* Re-export generic type creators *)
Expand Down
3 changes: 3 additions & 0 deletions typing/ctype.mli
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ val create_scope: unit -> int
the scope continues until the end of the compilation unit
or toplevel session. *)

val reset: unit -> unit
(* Reset all level counters - used between compilation units *)

val newty: type_desc -> type_expr
val new_scoped_ty: int -> type_desc -> type_expr
val newvar: ?name:string -> unit -> type_expr
Expand Down
2 changes: 2 additions & 0 deletions typing/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ let match_row_field ~present ~absent ~either (f : row_field) =

let new_id = Local_store.s_ref (-1)

let reset () = new_id := -1

let create_expr = Transient_expr.create

let proto_newty3 ~level ~scope desc =
Expand Down
2 changes: 2 additions & 0 deletions typing/types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,5 @@ val set_univar: type_expr option ref -> type_expr -> unit
val link_kind: inside:field_kind -> field_kind -> unit
val link_commu: inside:commutable -> commutable -> unit
val set_commu_ok: commutable -> unit

val reset : unit -> unit
Loading