diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index c6783b36bd506c12d6dba8117a9bc72750f70e5a..dab6e5dec91d75d69f4f556bfd850cf2156113b9 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -3411,7 +3411,21 @@ let octez_protocol_compiler_compat = [ S "copy"; S "compat_files/compiler_libs_ocaml5.ml"; S "%{target}"; ] - ~enabled_if:[S ">="; S "%{ocaml_version}"; S "5"]; + ~enabled_if: + [ + S "and"; + [S ">="; S "%{ocaml_version}"; S "5"]; + [S "<"; S "%{ocaml_version}"; S "5.2"]; + ]; + target_rule + "compiler_libs.ml" + ~action: + [ + S "copy"; + S "compat_files/compiler_libs_ocaml5_2.ml"; + S "%{target}"; + ] + ~enabled_if:[S ">="; S "%{ocaml_version}"; S "5.2"]; ] let _octez_protocol_compiler_cmis_of_cma = diff --git a/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml4.ml b/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml4.ml index dfc499ec2f56bdae87f1bfdd9faa70bcf0f3424d..c32259f3d0bbdde7606693a0b0113df4d922185e 100644 --- a/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml4.ml +++ b/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml4.ml @@ -18,3 +18,5 @@ let make_persistent_signature ~filename ~cmi = Persistent_env.Persistent_signature.{filename; cmi} let compunit_name compunit = compunit.Cmo_format.cu_name + +let mark_attribute_used _ = () diff --git a/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml5.ml b/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml5.ml index 74cceb0f7210773aa93ff9299d7cb3749f4c87a5..f3bfefc6d71235feb34893b36540178634ea12b8 100644 --- a/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml5.ml +++ b/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml5.ml @@ -18,3 +18,5 @@ let make_persistent_signature ~filename ~cmi = let compunit_name compunit = let (Cmo_format.Compunit cuname) = compunit.Cmo_format.cu_name in cuname + +let mark_attribute_used _ = () diff --git a/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml5_2.ml b/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml5_2.ml new file mode 100644 index 0000000000000000000000000000000000000000..8fce82d4edca0309c3ff1f10e3b7b028ef75a635 --- /dev/null +++ b/src/lib_protocol_compiler/compat/compat_files/compiler_libs_ocaml5_2.ml @@ -0,0 +1,26 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +let default_persistent_signature_loader = + !Persistent_env.Persistent_signature.load + +let override_persistent_signature_loader f = + Persistent_env.Persistent_signature.load := f + +let make_persistent_signature ~filename ~cmi = + Persistent_env.Persistent_signature. + {filename; cmi; visibility = Load_path.Visible} + +let compunit_name compunit = + let (Cmo_format.Compunit cuname) = compunit.Cmo_format.cu_name in + cuname + +let mark_attribute_used attribute = + Builtin_attributes.select_attributes + [(attribute.Parsetree.attr_name.txt, Mark_used_only)] + [attribute] + |> ignore diff --git a/src/lib_protocol_compiler/compat/compiler_libs.mli b/src/lib_protocol_compiler/compat/compiler_libs.mli index 2f3cdaba8b6c44a43235958fb18a99a10416c740..6a8d6a83af53f9dd9daa6da06b9f95f3dcde1812 100644 --- a/src/lib_protocol_compiler/compat/compiler_libs.mli +++ b/src/lib_protocol_compiler/compat/compiler_libs.mli @@ -28,3 +28,7 @@ val make_persistent_signature : (** [compunit_name cu] returns the name of the compilation unit *) val compunit_name : Cmo_format.compilation_unit -> string + +(** [mark_attribute_used attr] marks the attribute used, so that it doesn't + trigger warning 53. See [Packer.check_syntax]. *) +val mark_attribute_used : Parsetree.attribute -> unit diff --git a/src/lib_protocol_compiler/compat/dune b/src/lib_protocol_compiler/compat/dune index 8eedaa5b79a709dcdee5d97dc6ab81084146d374..a71283fe5804dc7b56ea0b10c7deb20044f6e1fd 100644 --- a/src/lib_protocol_compiler/compat/dune +++ b/src/lib_protocol_compiler/compat/dune @@ -28,4 +28,9 @@ (rule (target compiler_libs.ml) (action (copy compat_files/compiler_libs_ocaml5.ml %{target})) - (enabled_if (>= %{ocaml_version} 5))) + (enabled_if (and (>= %{ocaml_version} 5) (< %{ocaml_version} 5.2)))) + +(rule + (target compiler_libs.ml) + (action (copy compat_files/compiler_libs_ocaml5_2.ml %{target})) + (enabled_if (>= %{ocaml_version} 5.2))) diff --git a/src/lib_protocol_compiler/packer.ml b/src/lib_protocol_compiler/packer.ml index d52976c977d4ce35436d82c2c888840e9df9db73..221213ae56cc2e932b1a667e76d1aada50559aa1 100644 --- a/src/lib_protocol_compiler/packer.ml +++ b/src/lib_protocol_compiler/packer.ml @@ -64,6 +64,24 @@ let check_syntax kind file = struct_item.pstr_loc | _should_be_fine -> default_iterator.structure_item iterator struct_item); + attribute = + (* Starting OCaml 5.2, attributes are accumulated during parsing and + marked as used during typechecking. As parsing only is not + supported by the OCaml compiler (and especially calling the + compiler in different mode during the same execution), there is no + rule to cleanup the table of unused builtin attributes if + typechecking is never reached. This shouldn't be an issue to parse + a file twice as the attributes are registered by their location, + thus the first occurence would be replaced. However in the case of + the protocol compiler the files are repacked into a single functor, + which effectively changes their location. As a result, the previous + locations are never cleaned up and the attributes will eventually be + declared as unused. As such they need to be marked as used. *) + (fun iterator attribute -> + (* The result is ignored, as when `Mark_used_only` is set it should + return nothing. *) + Compiler_libs.mark_attribute_used attribute ; + default_iterator.attribute iterator attribute); } in (match kind with