Skip to content

Revert "Magic numbers" #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2021
Merged
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
Binary file modified ocaml/boot/ocamlc
Binary file not shown.
Binary file modified ocaml/boot/ocamllex
Binary file not shown.
2 changes: 1 addition & 1 deletion ocaml/runtime/caml/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct exec_trailer {

/* Magic number for this release */

#define EXEC_MAGIC "Caml2021X029"
#define EXEC_MAGIC "Caml1999X029"

#endif /* CAML_INTERNALS */

Expand Down
18 changes: 9 additions & 9 deletions ocaml/utils/config.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ let function_sections = %%FUNCTION_SECTIONS%%
let probes = %%PROBES%%
let afl_instrument = %%AFL_INSTRUMENT%%

let exec_magic_number = "Caml2021X029"
let exec_magic_number = "Caml1999X029"
(* exec_magic_number is duplicated in runtime/caml/exec.h *)
and cmi_magic_number = "Caml2021I029"
and cmo_magic_number = "Caml2021O029"
and cma_magic_number = "Caml2021A029"
and cmi_magic_number = "Caml1999I029"
and cmo_magic_number = "Caml1999O029"
and cma_magic_number = "Caml1999A029"
and cmx_magic_number =
if flambda || flambda2 then
"Caml2021y029"
Expand All @@ -106,11 +106,11 @@ and cmxa_magic_number =
"Caml2021z029"
else
"Caml2021Z029"
and ast_impl_magic_number = "Caml2021M029"
and ast_intf_magic_number = "Caml2021N029"
and cmxs_magic_number = "Caml2021D029"
and cmt_magic_number = "Caml2021T029"
and linear_magic_number = "Caml2021L029"
and ast_impl_magic_number = "Caml1999M029"
and ast_intf_magic_number = "Caml1999N029"
and cmxs_magic_number = "Caml1999D029"
and cmt_magic_number = "Caml1999T029"
and linear_magic_number = "Caml1999L029"
and cfg_magic_number = "Caml2021G029"

let interface_suffix = ref ".mli"
Expand Down
41 changes: 24 additions & 17 deletions ocaml/utils/misc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -982,30 +982,37 @@ module Magic_number = struct

type raw_kind = string

(* We do not accept Caml1999 prefixes. *)
let parse_kind : raw_kind -> kind option = function
| "Caml2021X" -> Some Exec
| "Caml2021I" -> Some Cmi
| "Caml2021O" -> Some Cmo
| "Caml2021A" -> Some Cma
| "Caml1999X" -> Some Exec
| "Caml1999I" -> Some Cmi
| "Caml1999O" -> Some Cmo
| "Caml1999A" -> Some Cma
| "Caml2021y" -> Some (Cmx {flambda = true})
| "Caml2021Y" -> Some (Cmx {flambda = false})
| "Caml2021z" -> Some (Cmxa {flambda = true})
| "Caml2021Z" -> Some (Cmxa {flambda = false})
| "Caml2021D" -> Some Cmxs
| "Caml2021T" -> Some Cmt
| "Caml2021M" -> Some Ast_impl
| "Caml2021N" -> Some Ast_intf

(* Caml2007D and Caml2012T were used instead of the common Caml1999 prefix
between the introduction of those magic numbers and October 2017
(8ba70ff194b66c0a50ffb97d41fe9c4bdf9362d6).

We accept them here, but will always produce/show kind prefixes
that follow the current convention, Caml1999{D,T}. *)
| "Caml2007D" | "Caml1999D" -> Some Cmxs
| "Caml2012T" | "Caml1999T" -> Some Cmt

| "Caml1999M" -> Some Ast_impl
| "Caml1999N" -> Some Ast_intf
| _ -> None

(* note: over time the magic kind number has changed for certain kinds;
this function returns them as they are produced by the current compiler,
but [parse_kind] accepts older formats as well. *)
let raw_kind : kind -> raw = function
| Exec -> "Caml2021X"
| Cmi -> "Caml2021I"
| Cmo -> "Caml2021O"
| Cma -> "Caml2021A"
| Exec -> "Caml1999X"
| Cmi -> "Caml1999I"
| Cmo -> "Caml1999O"
| Cma -> "Caml1999A"
| Cmx config ->
if config.flambda
then "Caml2021y"
Expand All @@ -1014,10 +1021,10 @@ module Magic_number = struct
if config.flambda
then "Caml2021z"
else "Caml2021Z"
| Cmxs -> "Caml2021D"
| Cmt -> "Caml2021T"
| Ast_impl -> "Caml2021M"
| Ast_intf -> "Caml2021N"
| Cmxs -> "Caml1999D"
| Cmt -> "Caml1999T"
| Ast_impl -> "Caml1999M"
| Ast_intf -> "Caml1999N"

let string_of_kind : kind -> string = function
| Exec -> "exec"
Expand Down