Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- Speed up inlining decisions for large functions. https://github.com/rescript-lang/rescript/pull/8771
- Speed up the rewriting of JS globals shadowed by local bindings in nested functions. https://github.com/rescript-lang/rescript/pull/8772
- Speed up dead code elimination of toplevel bindings in large modules. https://github.com/rescript-lang/rescript/pull/8773
- Make .cmt and .cmti files smaller by no longer embedding a copy of the .cmi. https://github.com/rescript-lang/rescript/pull/8774
Comment thread
cknitt marked this conversation as resolved.
- Represent explicit expression braces as `Pexp_braces` in parsetree v1 and format `else` branches consistently with `if` branches. https://github.com/rescript-lang/rescript/pull/8678
- Omit redundant braces around multi-statement switch case bodies when formatting. https://github.com/rescript-lang/rescript/pull/8677
- Avoid running `rescript-schema-ppx` and `sury-ppx` on source files without an `@schema` annotation. https://github.com/rescript-lang/rescript/pull/8662
Expand Down
7 changes: 3 additions & 4 deletions compiler/core/js_implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ let after_parsing_sig ppf outputprefix ast =
Delayed_checks.force_delayed_checks ();
Warnings.check_fatal ();
let deprecated = Builtin_attributes.deprecated_of_sig ast in
let sg =
Env.save_signature ~deprecated sg modulename (outputprefix ^ ".cmi")
in
ignore
(Env.save_signature ~deprecated sg modulename (outputprefix ^ ".cmi"));
Typemod.save_signature modulename tsg outputprefix !Location.input_name
initial_env sg;
initial_env;
process_with_gentype (outputprefix ^ ".cmti"))

let interface ~parser ppf ?outputprefix fname =
Expand Down
4 changes: 2 additions & 2 deletions compiler/ml/cmt_format.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include Cmt_format_common

let save_cmt filename modname binary_annots sourcefile initial_env cmi =
let save_cmt filename modname binary_annots sourcefile initial_env =
Cmt_format_persistence.save_cmt filename modname binary_annots sourcefile
initial_env cmi;
initial_env;
clear ()
21 changes: 8 additions & 13 deletions compiler/ml/cmt_format.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@

(** cmt and cmti files format. *)

(** The layout of a cmt file is as follows:
<cmt> := \{<cmi>\} <cmt magic> \{cmt infos\} \{<source info>\}
(** The layout of a cmt or cmti file is as follows:
<cmt> := \{<cmi>\} <cmt magic> \{cmt infos\}
where <cmi> is the cmi file format:
<cmi> := <cmi magic> <cmi info>.
More precisely, the optional <cmi> part must be present if and only if
the file is:
- a cmti, or
- a cmt, for a ml file which has no corresponding mli (hence no
corresponding cmti).
The compiler no longer writes the optional <cmi> part: the signature is
read from the .cmi file. Files written by older compilers have it in a
cmti, and in the cmt of a module without an interface.

Thus, we provide a common reading function for cmi and cmt(i)
files which returns an option for each of the three parts: cmi
info, cmt info, source info. *)
[read] accepts cmi, cmt and cmti files, with or without the <cmi> part,
and returns an option for the cmi info and the cmt info. *)

open Typedtree

Expand Down Expand Up @@ -83,10 +80,8 @@ val save_cmt :
(* source file *)
Env.t ->
(* initial env *)
Cmi_format.cmi_infos option ->
(* if a .cmi was generated *)
unit
(** [save_cmt filename modname binary_annots sourcefile initial_env cmi]
(** [save_cmt filename modname binary_annots sourcefile initial_env]
writes a cmt(i) file. *)
Comment thread
cknitt marked this conversation as resolved.

(* Miscellaneous functions *)
Expand Down
5 changes: 2 additions & 3 deletions compiler/ml/cmt_format_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ let input_cmt ic = (input_value ic : cmt_infos)
it exists, and the cmt_infos, if it exists. Thus, it can be used
with .cmi, .cmt and .cmti files.

.cmti files always contain a cmi_infos at the beginning. .cmt files
only contain a cmi_infos at the beginning if there is no associated
.cmti file.
The compiler no longer writes a cmi_infos in front of the cmt_infos in
.cmt and .cmti files, but files from older compilers may contain one.
*)
let read filename =
(* Printf.fprintf stderr "Cmt_format.read %s\n%!" filename; *)
Expand Down
14 changes: 5 additions & 9 deletions compiler/ml/platform/native/cmt_format_persistence.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ let output_cmt output_channel cmt =
output_string output_channel Config.cmt_magic_number;
output_value output_channel (cmt : cmt_infos)

let save_cmt filename modname binary_annots sourcefile initial_env cmi =
(* Unlike OCaml, no copy of the .cmi is written in front of the cmt infos:
tools read the .cmi itself. *)
let save_cmt filename modname binary_annots sourcefile initial_env =
if !Clflags.binary_annotations then
Misc.output_to_bin_file_directly filename
(fun temp_file_name output_channel ->
let interface_digest =
match cmi with
| None -> None
| Some cmi ->
Some (Cmi_format.output_cmi temp_file_name output_channel cmi)
in
(fun _temp_file_name output_channel ->
let cmt =
{
cmt_modname = modname;
Expand All @@ -44,7 +40,7 @@ let save_cmt filename modname binary_annots sourcefile initial_env cmi =
(if need_to_clear_env then keep_only_summary initial_env
else initial_env);
cmt_imports = List.sort compare (Env.imports ());
cmt_interface_digest = interface_digest;
cmt_interface_digest = None;
cmt_use_summaries = need_to_clear_env;
cmt_extra_info = {deprecated_used = deprecated_uses ()};
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/ml/platform/playground/cmt_format_persistence.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
let save_cmt _filename _modname _binary_annots _sourcefile _initial_env _cmi =
()
let save_cmt _filename _modname _binary_annots _sourcefile _initial_env = ()
24 changes: 11 additions & 13 deletions compiler/ml/typemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ let type_implementation_more ?check_exists sourcefile outputprefix modulename
so that value declarations which are not used internally but exported
are not reported as being unused. *)
Cmt_format.save_cmt (outputprefix ^ ".cmt") modulename
(Cmt_format.Implementation str) (Some sourcefile) initial_env None;
(Cmt_format.Implementation str) (Some sourcefile) initial_env;
(str, coercion, finalenv, dclsig)
(* identifier is useless might read from serialized cmi files*))
else
Expand All @@ -1753,26 +1753,24 @@ let type_implementation_more ?check_exists sourcefile outputprefix modulename
the value being exported. We can still capture unused
declarations like "let x = true;; let x = 1;;", because in this
case, the inferred signature contains only the last declaration. *)
(if not !Clflags.dont_write_files then
let deprecated = Builtin_attributes.deprecated_of_str ast in
let cmi =
Env.save_signature ?check_exists ~deprecated simple_sg modulename
(outputprefix ^ ".cmi")
in
Cmt_format.save_cmt (outputprefix ^ ".cmt") modulename
(Cmt_format.Implementation str) (Some sourcefile) initial_env
(Some cmi));
if not !Clflags.dont_write_files then (
let deprecated = Builtin_attributes.deprecated_of_str ast in
ignore
(Env.save_signature ?check_exists ~deprecated simple_sg modulename
(outputprefix ^ ".cmi"));
Cmt_format.save_cmt (outputprefix ^ ".cmt") modulename
(Cmt_format.Implementation str) (Some sourcefile) initial_env);
(str, coercion, finalenv, simple_sg)
with e ->
Cmt_format.save_cmt (outputprefix ^ ".cmt") modulename
(Cmt_format.Partial_implementation
(Array.of_list (Cmt_format.get_saved_types ())))
(Some sourcefile) initial_env None;
(Some sourcefile) initial_env;
raise e

let save_signature modname tsg outputprefix source_file initial_env cmi =
let save_signature modname tsg outputprefix source_file initial_env =
Cmt_format.save_cmt (outputprefix ^ ".cmti") modname
(Cmt_format.Interface tsg) (Some source_file) initial_env (Some cmi)
(Cmt_format.Interface tsg) (Some source_file) initial_env

(* "Packaging" of several compilation units into one unit
having them as sub-modules. *)
Expand Down
8 changes: 1 addition & 7 deletions compiler/ml/typemod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ val type_open_ :
Path.t * Env.t

val save_signature :
string ->
Typedtree.signature ->
string ->
string ->
Env.t ->
Cmi_format.cmi_infos ->
unit
string -> Typedtree.signature -> string -> string -> Env.t -> unit

type error =
| Cannot_apply of module_type
Expand Down
Loading