Skip to content

Commit

Permalink
Merge pull request #10718 from voodoos/shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos authored and trefis committed Nov 9, 2021
1 parent e8d5607 commit 2a11a0a
Show file tree
Hide file tree
Showing 47 changed files with 2,601 additions and 589 deletions.
46 changes: 43 additions & 3 deletions .depend
Expand Up @@ -577,6 +577,7 @@ typing/env.cmo : \
utils/warnings.cmi \
typing/types.cmi \
typing/subst.cmi \
typing/shape.cmi \
typing/predef.cmi \
typing/persistent_env.cmi \
typing/path.cmi \
Expand All @@ -598,6 +599,7 @@ typing/env.cmx : \
utils/warnings.cmx \
typing/types.cmx \
typing/subst.cmx \
typing/shape.cmx \
typing/predef.cmx \
typing/persistent_env.cmx \
typing/path.cmx \
Expand All @@ -619,6 +621,7 @@ typing/env.cmi : \
utils/warnings.cmi \
typing/types.cmi \
typing/subst.cmi \
typing/shape.cmi \
typing/path.cmi \
utils/misc.cmi \
parsing/longident.cmi \
Expand Down Expand Up @@ -745,6 +748,7 @@ typing/includemod.cmo : \
typing/types.cmi \
typing/typedtree.cmi \
typing/subst.cmi \
typing/shape.cmi \
typing/printtyp.cmi \
typing/primitive.cmi \
typing/predef.cmi \
Expand All @@ -767,6 +771,7 @@ typing/includemod.cmx : \
typing/types.cmx \
typing/typedtree.cmx \
typing/subst.cmx \
typing/shape.cmx \
typing/printtyp.cmx \
typing/primitive.cmx \
typing/predef.cmx \
Expand All @@ -788,6 +793,7 @@ typing/includemod.cmx : \
typing/includemod.cmi : \
typing/types.cmi \
typing/typedtree.cmi \
typing/shape.cmi \
typing/path.cmi \
parsing/longident.cmi \
parsing/location.cmi \
Expand Down Expand Up @@ -1154,6 +1160,22 @@ typing/rec_check.cmx : \
typing/rec_check.cmi : \
typing/typedtree.cmi \
typing/ident.cmi
typing/shape.cmo : \
typing/path.cmi \
utils/misc.cmi \
utils/identifiable.cmi \
typing/ident.cmi \
typing/shape.cmi
typing/shape.cmx : \
typing/path.cmx \
utils/misc.cmx \
utils/identifiable.cmx \
typing/ident.cmx \
typing/shape.cmi
typing/shape.cmi : \
typing/path.cmi \
utils/identifiable.cmi \
typing/ident.cmi
typing/signature_group.cmo : \
typing/types.cmi \
typing/ident.cmi \
Expand Down Expand Up @@ -1328,6 +1350,7 @@ typing/typecore.cmo : \
typing/typedtree.cmi \
typing/typedecl.cmi \
typing/subst.cmi \
typing/shape.cmi \
typing/rec_check.cmi \
typing/printtyp.cmi \
typing/printpat.cmi \
Expand Down Expand Up @@ -1359,6 +1382,7 @@ typing/typecore.cmx : \
typing/typedtree.cmx \
typing/typedecl.cmx \
typing/subst.cmx \
typing/shape.cmx \
typing/rec_check.cmx \
typing/printtyp.cmx \
typing/printpat.cmx \
Expand Down Expand Up @@ -1386,6 +1410,7 @@ typing/typecore.cmx : \
typing/typecore.cmi : \
typing/types.cmi \
typing/typedtree.cmi \
typing/shape.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
parsing/longident.cmi \
Expand Down Expand Up @@ -1590,6 +1615,7 @@ typing/typedecl_variance.cmi : \
parsing/asttypes.cmi
typing/typedtree.cmo : \
typing/types.cmi \
typing/shape.cmi \
typing/primitive.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
Expand All @@ -1601,6 +1627,7 @@ typing/typedtree.cmo : \
typing/typedtree.cmi
typing/typedtree.cmx : \
typing/types.cmx \
typing/shape.cmx \
typing/primitive.cmx \
typing/path.cmx \
parsing/parsetree.cmi \
Expand All @@ -1612,6 +1639,7 @@ typing/typedtree.cmx : \
typing/typedtree.cmi
typing/typedtree.cmi : \
typing/types.cmi \
typing/shape.cmi \
typing/primitive.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
Expand All @@ -1630,6 +1658,7 @@ typing/typemod.cmo : \
typing/typeclass.cmi \
typing/subst.cmi \
typing/signature_group.cmi \
typing/shape.cmi \
typing/printtyp.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
Expand Down Expand Up @@ -1664,6 +1693,7 @@ typing/typemod.cmx : \
typing/typeclass.cmx \
typing/subst.cmx \
typing/signature_group.cmx \
typing/shape.cmx \
typing/printtyp.cmx \
typing/path.cmx \
parsing/parsetree.cmi \
Expand Down Expand Up @@ -1692,6 +1722,7 @@ typing/typemod.cmi : \
typing/types.cmi \
typing/typedtree.cmi \
typing/typedecl.cmi \
typing/shape.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
parsing/longident.cmi \
Expand Down Expand Up @@ -1738,40 +1769,40 @@ typing/typeopt.cmi : \
typing/env.cmi
typing/types.cmo : \
typing/type_immediacy.cmi \
typing/shape.cmi \
typing/primitive.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
utils/misc.cmi \
parsing/longident.cmi \
parsing/location.cmi \
utils/local_store.cmi \
utils/identifiable.cmi \
typing/ident.cmi \
utils/config.cmi \
parsing/asttypes.cmi \
typing/types.cmi
typing/types.cmx : \
typing/type_immediacy.cmx \
typing/shape.cmx \
typing/primitive.cmx \
typing/path.cmx \
parsing/parsetree.cmi \
utils/misc.cmx \
parsing/longident.cmx \
parsing/location.cmx \
utils/local_store.cmx \
utils/identifiable.cmx \
typing/ident.cmx \
utils/config.cmx \
parsing/asttypes.cmi \
typing/types.cmi
typing/types.cmi : \
typing/type_immediacy.cmi \
typing/shape.cmi \
typing/primitive.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
parsing/longident.cmi \
parsing/location.cmi \
utils/identifiable.cmi \
typing/ident.cmi \
parsing/asttypes.cmi
typing/typetexp.cmo : \
Expand Down Expand Up @@ -3850,6 +3881,7 @@ file_formats/cmt_format.cmo : \
typing/types.cmi \
typing/typedtree.cmi \
typing/tast_mapper.cmi \
typing/shape.cmi \
utils/misc.cmi \
parsing/location.cmi \
utils/load_path.cmi \
Expand All @@ -3863,6 +3895,7 @@ file_formats/cmt_format.cmx : \
typing/types.cmx \
typing/typedtree.cmx \
typing/tast_mapper.cmx \
typing/shape.cmx \
utils/misc.cmx \
parsing/location.cmx \
utils/load_path.cmx \
Expand All @@ -3875,6 +3908,7 @@ file_formats/cmt_format.cmx : \
file_formats/cmt_format.cmi : \
typing/types.cmi \
typing/typedtree.cmi \
typing/shape.cmi \
utils/misc.cmi \
parsing/location.cmi \
typing/env.cmi \
Expand Down Expand Up @@ -5903,6 +5937,7 @@ driver/compile_common.cmo : \
typing/typemod.cmi \
typing/typedtree.cmi \
typing/typecore.cmi \
typing/shape.cmi \
utils/profile.cmi \
typing/printtyped.cmi \
typing/printtyp.cmi \
Expand All @@ -5923,6 +5958,7 @@ driver/compile_common.cmx : \
typing/typemod.cmx \
typing/typedtree.cmx \
typing/typecore.cmx \
typing/shape.cmx \
utils/profile.cmx \
typing/printtyped.cmx \
typing/printtyp.cmx \
Expand Down Expand Up @@ -6404,6 +6440,7 @@ toplevel/byte/topeval.cmo : \
toplevel/topcommon.cmi \
bytecomp/symtable.cmi \
lambda/simplif.cmi \
typing/shape.cmi \
typing/printtyped.cmi \
typing/printtyp.cmi \
lambda/printlambda.cmi \
Expand Down Expand Up @@ -6439,6 +6476,7 @@ toplevel/byte/topeval.cmx : \
toplevel/topcommon.cmx \
bytecomp/symtable.cmx \
lambda/simplif.cmx \
typing/shape.cmx \
typing/printtyped.cmx \
typing/printtyp.cmx \
lambda/printlambda.cmx \
Expand Down Expand Up @@ -6545,6 +6583,7 @@ toplevel/native/topeval.cmo : \
toplevel/native/tophooks.cmi \
toplevel/topcommon.cmi \
lambda/simplif.cmi \
typing/shape.cmi \
typing/printtyped.cmi \
typing/printtyp.cmi \
lambda/printlambda.cmi \
Expand Down Expand Up @@ -6576,6 +6615,7 @@ toplevel/native/topeval.cmx : \
toplevel/native/tophooks.cmx \
toplevel/topcommon.cmx \
lambda/simplif.cmx \
typing/shape.cmx \
typing/printtyped.cmx \
typing/printtyp.cmx \
lambda/printlambda.cmx \
Expand Down
5 changes: 5 additions & 0 deletions Changes
Expand Up @@ -326,6 +326,11 @@ OCaml 4.14.0
(David Allsopp and Nathan Rebours, review by Louis Gesbert,
Nicolás Ojeda Bär and Gabriel Scherer)

- #10718: Add "Shape" information to the cmt files. Shapes are an abstraction of
modules that can be used by external tooling to perform definition-aware
operations. (Ulysse Gérard, Thomas Refis and Leo White, review by Florian
Angeletti)

### Build system:

- #10717: Simplify the installation of man pages
Expand Down
Binary file modified boot/ocamlc
Binary file not shown.
Binary file modified boot/ocamllex
Binary file not shown.
1 change: 1 addition & 0 deletions compilerlibs/Makefile.compilerlibs
Expand Up @@ -76,6 +76,7 @@ TYPING = \
typing/path.cmo \
typing/primitive.cmo \
typing/type_immediacy.cmo \
typing/shape.cmo \
typing/types.cmo \
typing/btype.cmo \
typing/oprint.cmo \
Expand Down
2 changes: 2 additions & 0 deletions driver/compile_common.ml
Expand Up @@ -106,6 +106,8 @@ let typecheck_impl i parsetree =
i.source_file i.output_prefix i.module_name i.env)
|> print_if i.ppf_dump Clflags.dump_typedtree
Printtyped.implementation_with_coercion
|> print_if i.ppf_dump Clflags.dump_shape
(fun fmt {Typedtree.shape; _} -> Shape.print fmt shape)

let implementation info ~backend =
Profile.record_call info.source_file @@ fun () ->
Expand Down
8 changes: 8 additions & 0 deletions driver/main_args.ml
Expand Up @@ -716,6 +716,10 @@ let mk_dtypedtree f =
"-dtypedtree", Arg.Unit f, " (undocumented)"
;;

let mk_dshape f =
"-dshape", Arg.Unit f, " (undocumented)"
;;

let mk_drawlambda f =
"-drawlambda", Arg.Unit f, " (undocumented)"
;;
Expand Down Expand Up @@ -953,6 +957,7 @@ module type Core_options = sig
val _dsource : unit -> unit
val _dparsetree : unit -> unit
val _dtypedtree : unit -> unit
val _dshape : unit -> unit
val _drawlambda : unit -> unit
val _dlambda : unit -> unit

Expand Down Expand Up @@ -1249,6 +1254,7 @@ struct
mk_dsource F._dsource;
mk_dparsetree F._dparsetree;
mk_dtypedtree F._dtypedtree;
mk_dshape F._dshape;
mk_drawlambda F._drawlambda;
mk_dlambda F._dlambda;
mk_dinstr F._dinstr;
Expand Down Expand Up @@ -1316,6 +1322,7 @@ struct
mk_dsource F._dsource;
mk_dparsetree F._dparsetree;
mk_dtypedtree F._dtypedtree;
mk_dshape F._dshape;
mk_drawlambda F._drawlambda;
mk_dlambda F._dlambda;
mk_dinstr F._dinstr;
Expand Down Expand Up @@ -1724,6 +1731,7 @@ module Default = struct
let _drawlambda = set dump_rawlambda
let _dsource = set dump_source
let _dtypedtree = set dump_typedtree
let _dshape = set dump_shape
let _dunique_ids = set unique_ids
let _dno_unique_ids = clear unique_ids
let _dlocations = set locations
Expand Down
1 change: 1 addition & 0 deletions driver/main_args.mli
Expand Up @@ -66,6 +66,7 @@ module type Core_options = sig
val _dsource : unit -> unit
val _dparsetree : unit -> unit
val _dtypedtree : unit -> unit
val _dshape : unit -> unit
val _drawlambda : unit -> unit
val _dlambda : unit -> unit

Expand Down
2 changes: 1 addition & 1 deletion dune
Expand Up @@ -55,7 +55,7 @@
asttypes parsetree

;; TYPING
ident path primitive types btype oprint subst predef datarepr
ident path primitive shape types btype oprint subst predef datarepr
cmi_format persistent_env env type_immediacy errortrace
typedtree printtyped ctype printtyp includeclass mtype envaux includecore
tast_iterator tast_mapper signature_group cmt_format untypeast
Expand Down
6 changes: 5 additions & 1 deletion file_formats/cmt_format.ml
Expand Up @@ -60,6 +60,8 @@ type cmt_infos = {
cmt_imports : (string * Digest.t option) list;
cmt_interface_digest : Digest.t option;
cmt_use_summaries : bool;
cmt_uid_to_loc : Location.t Shape.Uid.Tbl.t;
cmt_impl_shape : Shape.t option; (* None for mli *)
}

type error =
Expand Down Expand Up @@ -162,7 +164,7 @@ let record_value_dependency vd1 vd2 =
if vd1.Types.val_loc <> vd2.Types.val_loc then
value_deps := (vd1, vd2) :: !value_deps

let save_cmt filename modname binary_annots sourcefile initial_env cmi =
let save_cmt filename modname binary_annots sourcefile initial_env cmi shape =
if !Clflags.binary_annotations && not !Clflags.print_types then begin
Misc.output_to_file_via_temporary
~mode:[Open_binary] filename
Expand All @@ -188,6 +190,8 @@ let save_cmt filename modname binary_annots sourcefile initial_env cmi =
cmt_imports = List.sort compare (Env.imports ());
cmt_interface_digest = this_crc;
cmt_use_summaries = need_to_clear_env;
cmt_uid_to_loc = Env.get_uid_to_loc_tbl ();
cmt_impl_shape = shape;
} in
output_cmt oc cmt)
end;
Expand Down
3 changes: 3 additions & 0 deletions file_formats/cmt_format.mli
Expand Up @@ -65,6 +65,8 @@ type cmt_infos = {
cmt_imports : crcs;
cmt_interface_digest : Digest.t option;
cmt_use_summaries : bool;
cmt_uid_to_loc : Location.t Shape.Uid.Tbl.t;
cmt_impl_shape : Shape.t option; (* None for mli *)
}

type error =
Expand Down Expand Up @@ -94,6 +96,7 @@ val save_cmt :
string option -> (* source file *)
Env.t -> (* initial env *)
Cmi_format.cmi_infos option -> (* if a .cmi was generated *)
Shape.t option ->
unit

(* Miscellaneous functions *)
Expand Down
1 change: 1 addition & 0 deletions otherlibs/dynlink/Makefile
Expand Up @@ -100,6 +100,7 @@ COMPILERLIBS_SOURCES=\
typing/path.ml \
typing/primitive.ml \
typing/type_immediacy.ml \
typing/shape.ml \
typing/types.ml \
typing/btype.ml \
typing/subst.ml \
Expand Down

0 comments on commit 2a11a0a

Please sign in to comment.