···130130- #10555: Do not use ghost locations for type constraints
131131 (Nicolás Ojeda Bär, report by Anton Bachin, review by Thomas Refis)
132132133133-### Build system:
133133+- #10559: Evaluate signature substitutions lazily
134134+ (Stephen Dolan, review by Leo White)
134135135135-- #10471: Fix detection of arm32 architectures with musl in the configure
136136- script.
137137- (Louis Gesbert)
136136+### Build system:
138137139138### Bug fixes:
140139···156155157156- #10542: Fix detection of immediate64 types through unboxed types.
158157 (Leo White, review by Stephen Dolan and Gabriel Scherer)
158158+159159+- #10590: Some typechecker optimisations
160160+ (Stephen Dolan, review by Gabriel Scherer and Leo White)
159161160162OCaml 4.13.0
161163-------------
···354356 (Gabriel Scherer, review by Nicolás Ojeda Bär, Alain Frisch, Xavier Leroy,
355357 Daniel Bünzli and Stephen Dolan)
356358357357-* #10169, #10270, #10301: Use capitalized module names in the Standard Library
358358- prefixing scheme to match Dune, e.g. Stdlib__String instead of Stdlib__string.
359359- This is a breaking change only to code which attempted to use the internal
360360- names before. The Standard Library generated by the Dune rules is now
361361- equivalent to the main build (the Dune rules still do not generate a
359359+* #10169, #10270, #10301, #10451: Use capitalized module names in the Standard
360360+ Library prefixing scheme to match Dune, e.g. Stdlib__String instead of
361361+ Stdlib__string. This is a breaking change only to code which attempted to use
362362+ the internal names before. The Standard Library generated by the Dune rules is
363363+ now equivalent to the main build (the Dune rules still do not generate a
362364 distributable compiler).
363365 (David Allsopp and Mark Shinwell, review by Gabriel Scherer)
364366···650652 which runtime to use while building the compilers (Sébastien Hinderer,
651653 review by David Allsopp)
652654655655+- #10451: Replace the use of iconv with a C utility to convert $(LIBDIR) to a
656656+ C string constant on Windows when building the runtime. Hardens the generation
657657+ of the constant on Unix for paths with backslashes, double-quotes and
658658+ newlines.
659659+ (David Allsopp, review by Florian Angeletti and Sébastien Hinderer)
660660+661661+- #10471: Fix detection of arm32 architectures with musl in configure.
662662+ (Louis Gesbert, review by David Allsopp)
663663+653664### Bug fixes:
654665655666- #6654, #9774, #10401: make `include` and with `constraints` handle correctly
···776787- #10584, #10856: Standard Library documentation build no longer fails if
777788 optional libraries have been disabled.
778789 (David Allsopp, report by Yuri Victorovich review by Florian Angeletti)
790790+791791+- #10593: Fix untyping of patterns without named existential quantifiers. This
792792+ bug was only present in the beta version of OCaml 4.13.0.
793793+ (Ulysse Gérard, review by Florian Angeletti)
779794780795OCaml 4.12, maintenance version
781796-------------------------------
+3
Makefile
···773773774774# The runtime system for the bytecode compiler
775775776776+$(SAK):
777777+ $(MAKE) -C runtime sak$(EXE)
778778+776779.PHONY: runtime
777780runtime: stdlib/libcamlrun.$(A)
778781
+12
Makefile.common
···160160161161%.ml %.mli: %.mly
162162 $(OCAMLYACC) $(OCAMLYACCFLAGS) $<
163163+164164+SAK = $(ROOTDIR)/runtime/sak$(EXE)
165165+166166+# stdlib/StdlibModules cannot be include'd unless $(SAK) has been built. These
167167+# two rules add that dependency. They have to be pattern rules since
168168+# Makefile.common is included before default targets.
169169+$(ROOTDIR)/%/sak$(EXE):
170170+ $(MAKE) -C $(ROOTDIR)/$* sak$(EXE)
171171+172172+ifneq "$(REQUIRES_CONFIGURATION)" ""
173173+$(ROOTDIR)/%/StdlibModules: $(SAK) ;
174174+endif
···252526261. Run `make` in the manual directory.
27272828-NB: If you already set `LD_LIBRARY_PATH` (OS X: `DYLD_LIBRARY_PATH`)
2929- in your environment don't forget to append the absolute paths to
3030- `otherlibs/unix` and `otherlibs/str` to it.
3131-3228Outputs
3329-------
3430
+9-12
manual/src/Makefile
···11-SRC = $(abspath ../..)
22--include $(SRC)/Makefile.config
11+ROOTDIR = ../..
22+-include $(ROOTDIR)/Makefile.build_config
3344-export LD_LIBRARY_PATH ?= "$(SRC)/otherlibs/unix/:$(SRC)/otherlibs/str/"
55-export DYLD_LIBRARY_PATH ?= "$(SRC)/otherlibs/unix/:$(SRC)/otherlibs/str/"
66-77-TEXQUOTE = $(SRC)/runtime/ocamlrun ../tools/texquote2
44+TEXQUOTE = $(ROOTDIR)/runtime/ocamlrun ../tools/texquote2
8596FILES = allfiles.tex biblio.tex foreword.tex version.tex cmds/warnings-help.etex ifocamldoc.tex
107···1815HTML_FLAGS = -fix -exec xxdate.exe -O
1916TEXT_FLAGS = -fix -exec xxdate.exe -text -w 79 -s
20172121-# Copy the documentation files from SRC/api_docgen
2222-APIDOC=$(SRC)/api_docgen
1818+# Copy the documentation files from ROOTDIR/api_docgen
1919+APIDOC=$(ROOTDIR)/api_docgen
2320.PHONY: html_files
2421.PHONY: latex_files
2522ifeq ($(DOCUMENTATION_TOOL),odoc)
···125122 $(TEXQUOTE) < $< > $*.texquote_error.tex
126123 mv $*.texquote_error.tex $@
127124128128-version.tex: $(SRC)/VERSION
125125+version.tex: $(ROOTDIR)/VERSION
129126 sed -n -e '1s/^\([0-9]*\.[0-9]*\).*$$/\\def\\ocamlversion{\1}/p' $< > $@
130127131131-cmds/warnings-help.etex: $(SRC)/utils/warnings.ml $(SRC)/ocamlc
128128+cmds/warnings-help.etex: $(ROOTDIR)/utils/warnings.ml $(ROOTDIR)/ocamlc
132129 (echo "% This file is generated from (ocamlc -warn-help)";\
133130 echo "% according to a rule in manual/src/Makefile.";\
134131 echo "% In particular, the reference to documentation sections";\
135132 echo "% are inserted through the Makefile, which should be updated";\
136133 echo "% when a new warning is documented.";\
137134 echo "%";\
138138- $(SRC)/boot/ocamlrun $(SRC)/ocamlc -warn-help \
135135+ $(ROOTDIR)/boot/ocamlrun $(ROOTDIR)/ocamlc -warn-help \
139136 | LC_ALL=C sed -e 's/^ *\([0-9][0-9]*\) *\[\([a-z][a-z-]*\)\]\(.*\)/\\item[\1 "\2"] \3/' \
140137 -e 's/^ *\([0-9A-Z][0-9]*\) *\([^]].*\)/\\item[\1] \2/'\
141138 | sed -e 's/@/\\@/g' \
···148145 mv $@.tmp $@;\
149146 done
150147151151-ifocamldoc.tex: $(SRC)/Makefile.config
148148+ifocamldoc.tex: $(ROOTDIR)/Makefile.build_config
152149 $(MAKE) -C $(APIDOC) build/latex/ifocamldoc.tex
153150 cp $(APIDOC)/build/latex/ifocamldoc.tex $@
154151
···11+/**************************************************************************/
22+/* */
33+/* OCaml */
44+/* */
55+/* David Allsopp, OCaml Labs, Cambridge. */
66+/* */
77+/* Copyright 2021 David Allsopp Ltd. */
88+/* */
99+/* All rights reserved. This file is distributed under the terms of */
1010+/* the GNU Lesser General Public License version 2.1, with the */
1111+/* special exception on linking described in the file LICENSE. */
1212+/* */
1313+/**************************************************************************/
1414+1515+/* Runtime Builder's Swiss Army Knife. This utility performs functions
1616+ previously delegated to classic Unix utilities but which ultimately seem to
1717+ cause more hassle for maintenance than the initial simplicity suggests.
1818+1919+ This tool is a memorial to the many hours and PRs spent chasing down strange
2020+ locale issues, stray CR characters and fighting yet another incompatible
2121+ implementation of sed or awk. */
2222+2323+/* Borrow the Unicode *_os definitions and T() macro from misc.h */
2424+#define CAML_INTERNALS
2525+#include "caml/misc.h"
2626+2727+#include <stdio.h>
2828+#include <string.h>
2929+#include <ctype.h>
3030+3131+#ifdef _WIN32
3232+#define strncmp_os wcsncmp
3333+#define toupper_os towupper
3434+#define printf_os wprintf
3535+#else
3636+#define strncmp_os strncmp
3737+#define toupper_os toupper
3838+#define printf_os printf
3939+#endif
4040+4141+/* Operations
4242+ - encode-C-literal. Used for the OCAML_STDLIB_DIR macro in
4343+ runtime/build_config.h to ensure the LIBDIR make variable is correctly
4444+ represented as a C string literal.
4545+4646+ On Unix, `sak encode-C-literal /usr/local/lib` returns `"/usr/local/lib"`
4747+4848+ On Windows, `sak encode-C-literal "C:\OCaml🐫\lib"` returns
4949+ `L"C:\\OCaml\xd83d\xdc2b\\lib"`
5050+ - add-stdlib-prefix. Used in stdlib/StdlibModules to convert the list of
5151+ basenames given in STDLIB_MODULE_BASENAMES to the actual file basenames
5252+ in STDLIB_MODULES.
5353+5454+ For example, `sak add-stdlib-prefix stdlib camlinternalAtomic Sys` returns
5555+ ` stdlib camlinternalAtomic stdlib__Sys`
5656+ */
5757+5858+void usage(void)
5959+{
6060+ printf(
6161+ "OCaml Build System Swiss Army Knife\n"
6262+ "Usage: sak command\n"
6363+ "Commands:\n"
6464+ " * encode-C-literal path - encodes path as a C string literal\n"
6565+ " * add-stdlib-prefix name1 ... - prefix standard library module names\n"
6666+ );
6767+}
6868+6969+/* Converts the supplied path (UTF-8 on Unix and UCS-2ish on Windows) to a valid
7070+ C string literal. On Windows, this is always a wchar_t* (L"..."). */
7171+void encode_C_literal(char_os *path)
7272+{
7373+ char_os c;
7474+7575+#ifdef _WIN32
7676+ putchar('L');
7777+#endif
7878+ putchar('"');
7979+8080+ while ((c = *path++) != 0) {
8181+ /* Escape \, " and \n */
8282+ if (c == '\\') {
8383+ printf("\\\\");
8484+ } else if (c == '"') {
8585+ printf("\\\"");
8686+ } else if (c == '\n') {
8787+ printf("\\n");
8888+#ifndef _WIN32
8989+ /* On Unix, nothing else needs escaping */
9090+ } else {
9191+ putchar(c);
9292+#else
9393+ /* On Windows, allow 7-bit printable characters to be displayed literally
9494+ and escape everything else (using the older \x notation for increased
9595+ compatibility, rather than the newer \U. */
9696+ } else if (c < 0x80 && iswprint(c)) {
9797+ putwchar(c);
9898+ } else {
9999+ printf("\\x%04x", c);
100100+#endif
101101+ }
102102+ }
103103+104104+ putchar('"');
105105+}
106106+107107+/* Print the given array of module names to stdout. "stdlib" and names beginning
108108+ "camlinternal" are printed unaltered. All other names are prefixed "stdlib__"
109109+ with the original name capitalised (i.e. "foo" prints "stdlib__Foo"). */
110110+void add_stdlib_prefix(int count, char_os **names)
111111+{
112112+ int i;
113113+ char_os *name;
114114+115115+ for (i = 0; i < count; i++) {
116116+ name = *names++;
117117+118118+ /* "stdlib" and camlinternal* do not get changed. All other names get
119119+ capitalised and prefixed "stdlib__". */
120120+ if (strcmp_os(T("stdlib"), name) == 0
121121+ || strncmp_os(T("camlinternal"), name, 12) == 0) {
122122+ printf_os(T(" %s"), name);
123123+ } else {
124124+ /* name is a null-terminated string, so an empty string simply has the
125125+ null-terminator "capitalised". */
126126+ *name = toupper_os(*name);
127127+ printf_os(T(" stdlib__%s"), name);
128128+ }
129129+ }
130130+}
131131+132132+int main_os(int argc, char_os **argv)
133133+{
134134+ if (argc == 3 && !strcmp_os(argv[1], T("encode-C-literal"))) {
135135+ encode_C_literal(argv[2]);
136136+ } else if (argc > 1 && !strcmp_os(argv[1], T("add-stdlib-prefix"))) {
137137+ add_stdlib_prefix(argc - 2, &argv[2]);
138138+ } else {
139139+ usage();
140140+ return 1;
141141+ }
142142+143143+ return 0;
144144+}
···1515#* *
1616#**************************************************************************
17171818-# This file must be self-contained.
1818+# This file should be included after Makefile.common
19192020# This file lists all standard library modules. It is used by:
2121# 1. stdlib/Makefile when building stdlib.cma
···33333434# Basenames of the source files for the standard library (i.e. unprefixed and
3535# with lowercase first letters). These must be listed in dependency order.
3636-STDLIB_MODULE_BASENAMES=\
3636+STDLIB_MODULE_BASENAMES = \
3737 camlinternalFormatBasics camlinternalAtomic \
3838 stdlib pervasives seq option either result bool char uchar \
3939 sys list int bytes string unit marshal obj array float int32 int64 nativeint \
···4545 filename complex arrayLabels listLabels bytesLabels stringLabels moreLabels \
4646 stdLabels bigarray in_channel out_channel
47474848-STDLIB_PREFIXED_MODULES=\
4848+STDLIB_PREFIXED_MODULES = \
4949 $(filter-out stdlib camlinternal%, $(STDLIB_MODULE_BASENAMES))
50505151-define add_stdlib_prefix_first
5252-$(shell echo $1 | cut -c1 | tr '[:lower:]' '[:upper:]')
5353-endef
5454-5555-# add stdlib__ as prefix to a module except for internal modules
5656-# and the stdlib module itself
5757-define add_stdlib_prefix
5858- $(or $(filter-out $(STDLIB_PREFIXED_MODULES), $1), \
5959- stdlib__$(call add_stdlib_prefix_first,$1)$(shell echo $1 | cut -c2-))
6060-endef
6161-6262-STDLIB_MODULES:=\
6363- $(foreach module, $(STDLIB_MODULE_BASENAMES), \
6464- $(call add_stdlib_prefix,$(module)))
5151+# The pattern FOO = $(eval FOO := $$(shell <cmd>)$(FOO) ensures that <cmd> is
5252+# executed either once or not at all, giving us GNU make's equivalent of a
5353+# string lazy_t.
5454+STDLIB_MODULES = \
5555+ $(eval STDLIB_MODULES := $$(shell \
5656+ $(SAK) add-stdlib-prefix $(STDLIB_MODULE_BASENAMES)))$(STDLIB_MODULES)
+17
testsuite/tests/compiler-libs/test_untypeast.ml
···11+(* TEST
22+ flags = "-I ${ocamlsrcdir}/typing \
33+ -I ${ocamlsrcdir}/parsing"
44+ include ocamlcommon
55+ * expect
66+*)
77+88+let res =
99+ let s = {| match None with Some (Some _) -> () | _ -> () |} in
1010+ let pe = Parse.expression (Lexing.from_string s) in
1111+ let te = Typecore.type_expression (Env.initial_safe_string) pe in
1212+ let ute = Untypeast.untype_expression te in
1313+ Format.asprintf "%a" Pprintast.expression ute
1414+1515+[%%expect{|
1616+val res : string = "match None with | Some (Some _) -> () | _ -> ()"
1717+|}]
···304304 val unit : unit
305305 external e : unit -> unit = "%identity"
306306 module M = N.M
307307- module type T = sig end
307307+ module type T = N.T
308308 exception E
309309 type ext = N.ext = ..
310310 type ext += C
···329329 val unit : unit
330330 external e : unit -> unit = "%identity"
331331 module M = N.M
332332- module type T = sig end
332332+ module type T = N.T
333333 exception E
334334 type ext = N.ext = ..
335335 type ext += C
···352352 val unit : unit
353353 external e : unit -> unit = "%identity"
354354 module M = N.M
355355- module type T = sig end
355355+ module type T = N.T
356356 exception E
357357 type ext = N.ext = ..
358358 type ext += C
···370370[%%expect{|
371371module Module_type :
372372 sig
373373- module type U = sig end
373373+ module type U = N.T
374374 type t = N.t
375375 val unit : unit
376376 external e : unit -> unit = "%identity"
377377 module M = N.M
378378- module type T = sig end
378378+ module type T = N.T
379379 exception E
380380 type ext = N.ext = ..
381381 type ext += C
···398398 val unit : unit
399399 external e : unit -> unit = "%identity"
400400 module M = N.M
401401- module type T = sig end
401401+ module type T = N.T
402402 exception E
403403 type ext = N.ext = ..
404404 type ext += C
···421421 val unit : unit
422422 external e : unit -> unit = "%identity"
423423 module M = N.M
424424- module type T = sig end
424424+ module type T = N.T
425425 exception E
426426 type ext = N.ext = ..
427427 type ext += C
···444444 val unit : unit
445445 external e : unit -> unit = "%identity"
446446 module M = N.M
447447- module type T = sig end
447447+ module type T = N.T
448448 exception E
449449 type ext = N.ext = ..
450450 type ext += C
···467467 val unit : unit
468468 external e : unit -> unit = "%identity"
469469 module M = N.M
470470- module type T = sig end
470470+ module type T = N.T
471471 exception E
472472 type ext = N.ext = ..
473473 type ext += C
+5-19
testsuite/tests/typing-modules/functors.ml
···13101310 module type t = arg -> sig type arg = A.arg end
13111311 end
13121312module Add_one :
13131313- sig
13141314- type witness
13151315- module M = Add_one'.M
13161316- module type t = arg -> sig type arg = A.arg end
13171317- end
13131313+ sig type witness module M = Add_one'.M module type t = Add_one'.t end
13181314module Add_three' :
13191315 sig
13201316 module M : arg -> arg -> arg -> sig type arg = A.arg end
13211317 module type t = arg -> arg -> arg -> sig type arg = A.arg end
13221318 end
13231319module Add_three :
13241324- sig
13251325- module M = Add_three'.M
13261326- module type t = arg -> arg -> arg -> sig type arg = A.arg end
13271327- type witness
13281328- end
13201320+ sig module M = Add_three'.M module type t = Add_three'.t type witness end
13291321Line 22, characters 21-43:
1330132222 | module Wrong_intro = F(Add_three')(A)(A)(A)
13311323 ^^^^^^^^^^^^^^^^^^^^^^
···13361328 functor (X : $T1) arg arg arg -> ...
13371329 1. Modules do not match:
13381330 Add_three' :
13391339- sig
13401340- module M = Add_three'.M
13411341- module type t = arg -> arg -> arg -> sig type arg = A.arg end
13421342- end
13311331+ sig module M = Add_three'.M module type t = Add_three'.t end
13431332 is not included in
13441333 $T1 = sig type witness module type t module M : t end
13451334 The type `witness' is required but not provided
···13601349 functor (X : ...) arg arg arg -> ...
13611350 1. The following extra argument is provided
13621351 Add_one' :
13631363- sig
13641364- module M = Add_one'.M
13651365- module type t = arg -> sig type arg = A.arg end
13661366- end
13521352+ sig module M = Add_one'.M module type t = Add_one'.t end
13671353 2. Module Add_three matches the expected module type
13681354 3. Module A matches the expected module type arg
13691355 4. Module A matches the expected module type arg
···13881374 sig
13891375 type witness = Add_one.witness
13901376 module M = Add_one'.M
13911391- module type t = arg -> sig type arg = A.arg end
13771377+ module type t = Add_one.t
13921378 end
13931379 2. Module Add_three matches the expected module type
13941380 3. Module A matches the expected module type arg
+158-96
typing/env.ml
···500500 flags: int;
501501}
502502503503-and module_declaration_lazy =
504504- (Subst.t * Subst.scoping * module_declaration, module_declaration)
505505- Lazy_backtrack.t
506506-507503and module_components =
508504 {
509505 alerts: alerts;
···520516 cm_prefixing_subst: Subst.t;
521517 cm_path: Path.t;
522518 cm_addr: address_lazy;
523523- cm_mty: Types.module_type;
519519+ cm_mty: Subst.Lazy.modtype;
524520}
525521526522and module_components_repr =
···575571 tda_descriptions : type_descriptions; }
576572577573and module_data =
578578- { mda_declaration : module_declaration_lazy;
574574+ { mda_declaration : Subst.Lazy.module_decl;
579575 mda_components : module_components;
580576 mda_address : address_lazy; }
581577···584580 | Mod_persistent
585581 | Mod_unbound of module_unbound_reason
586582587587-and modtype_data = modtype_declaration
583583+and modtype_data = Subst.Lazy.modtype_declaration
588584589585and class_data =
590586 { clda_declaration : class_declaration;
···671667 | `Class None | `Class_type None | `Component None ->
672668 None
673669674674-let subst_modtype_maker (subst, scoping, md) =
675675- {md with md_type = Subst.modtype scoping subst md.md_type}
676676-677670let empty = {
678671 values = IdTbl.empty; constrs = TycompTbl.empty;
679672 labels = TycompTbl.empty; types = IdTbl.empty;
···747740let strengthen =
748741 (* to be filled with Mtype.strengthen *)
749742 ref ((fun ~aliasable:_ _env _mty _path -> assert false) :
750750- aliasable:bool -> t -> module_type -> Path.t -> module_type)
743743+ aliasable:bool -> t -> Subst.Lazy.modtype ->
744744+ Path.t -> Subst.Lazy.modtype)
751745752746let md md_type =
753747 {md_type; md_attributes=[]; md_loc=Location.none
···865859 in
866860 let mda_address = Lazy_backtrack.create_forced (Aident id) in
867861 let mda_declaration =
868868- Lazy_backtrack.create (Subst.identity, Subst.Make_local, md)
862862+ Subst.(Lazy.module_decl Make_local identity (Lazy.of_module_decl md))
869863 in
870864 let mda_components =
871865 let freshening_subst =
···873867 in
874868 components_of_module ~alerts ~uid:md.md_uid
875869 empty freshening_subst Subst.identity
876876- path mda_address (Mty_signature sign)
870870+ path mda_address (Subst.Lazy.of_modtype (Mty_signature sign))
877871 in
878872 {
879873 mda_declaration;
···10131007 match path with
10141008 | Pident id ->
10151009 let data = find_ident_module id env in
10161016- Lazy_backtrack.force subst_modtype_maker data.mda_declaration
10101010+ Subst.Lazy.force_module_decl data.mda_declaration
10171011 | Pdot(p, s) ->
10181012 let sc = find_structure_components p env in
10191013 let data = NameMap.find s sc.comp_modules in
10201020- Lazy_backtrack.force subst_modtype_maker data.mda_declaration
10141014+ Subst.Lazy.force_module_decl data.mda_declaration
10211015 | Papply(p1, p2) ->
10221016 let fc = find_functor_components p1 env in
10231017 if alias then md (fc.fcomp_res)
10241018 else md (modtype_of_functor_appl fc p1 p2)
1025101910201020+let find_module_lazy ~alias path env =
10211021+ match path with
10221022+ | Pident id ->
10231023+ let data = find_ident_module id env in
10241024+ data.mda_declaration
10251025+ | Pdot(p, s) ->
10261026+ let sc = find_structure_components p env in
10271027+ let data = NameMap.find s sc.comp_modules in
10281028+ data.mda_declaration
10291029+ | Papply(p1, p2) ->
10301030+ let fc = find_functor_components p1 env in
10311031+ let md =
10321032+ if alias then md (fc.fcomp_res)
10331033+ else md (modtype_of_functor_appl fc p1 p2)
10341034+ in
10351035+ Subst.Lazy.of_module_decl md
10361036+10371037+let find_strengthened_module ~aliasable path env =
10381038+ let md = find_module_lazy ~alias:true path env in
10391039+ let mty = !strengthen ~aliasable env md.mdl_type path in
10401040+ Subst.Lazy.force_modtype mty
10411041+10261042let find_value_full path env =
10271043 match path with
10281044 | Pident id -> begin
···10431059 NameMap.find s sc.comp_types
10441060 | Papply _ -> raise Not_found
1045106110461046-let find_modtype path env =
10621062+let find_modtype_lazy path env =
10471063 match path with
10481064 | Pident id -> IdTbl.find_same id env.modtypes
10491065 | Pdot(p, s) ->
10501066 let sc = find_structure_components p env in
10511067 NameMap.find s sc.comp_modtypes
10521068 | Papply _ -> raise Not_found
10691069+10701070+let find_modtype path env =
10711071+ Subst.Lazy.force_modtype_decl (find_modtype_lazy path env)
1053107210541073let find_class_full path env =
10551074 match path with
···12261245 expand_module_path lax env path
1227124612281247and expand_module_path lax env path =
12291229- try match find_module ~alias:true path env with
12301230- {md_type=Mty_alias path1} ->
12481248+ try match find_module_lazy ~alias:true path env with
12491249+ {mdl_type=MtyL_alias path1} ->
12311250 let path' = normalize_module_path lax env path1 in
12321251 if lax || !Clflags.transparent_modules then path' else
12331252 let id = Path.head path in
···12831302 expand_modtype_path env path
1284130312851304and expand_modtype_path env path =
12861286- match (find_modtype path env).mtd_type with
12871287- | Some (Mty_ident path) -> normalize_modtype_path env path
13051305+ match (find_modtype_lazy path env).mtdl_type with
13061306+ | Some (MtyL_ident path) -> normalize_modtype_path env path
12881307 | _ | exception Not_found -> path
1289130812901309let find_module path env =
12911310 find_module ~alias:false path env
13111311+13121312+let find_module_lazy path env =
13131313+ find_module_lazy ~alias:false path env
1292131412931315(* Find the manifest type associated to a type when appropriate:
12941316 - the type should be public or should have a private row,
···13191341 (decl.type_params, body, decl.type_expansion_scope)
13201342 | _ -> raise Not_found
1321134313221322-let find_modtype_expansion path env =
13231323- match (find_modtype path env).mtd_type with
13441344+let find_modtype_expansion_lazy path env =
13451345+ match (find_modtype_lazy path env).mtdl_type with
13241346 | None -> raise Not_found
13251347 | Some mty -> mty
13481348+13491349+let find_modtype_expansion path env =
13501350+ Subst.Lazy.force_modtype (find_modtype_expansion_lazy path env)
1326135113271352let rec is_functor_arg path env =
13281353 match path with
···13741399let iter_env_cont = ref []
1375140013761401let rec scrape_alias_for_visit env (sub : Subst.t option) mty =
14021402+ let open Subst.Lazy in
13771403 match mty with
13781378- | Mty_alias path ->
14041404+ | MtyL_alias path ->
13791405 begin match may_subst Subst.module_path sub path with
13801406 | Pident id
13811407 when Ident.persistent id
13821408 && not (Persistent_env.looked_up !persistent_env (Ident.name id)) ->
13831409 false
13841410 | path -> (* PR#6600: find_module may raise Not_found *)
13851385- try scrape_alias_for_visit env sub (find_module path env).md_type
14111411+ try
14121412+ scrape_alias_for_visit env sub (find_module_lazy path env).mdl_type
13861413 with Not_found -> false
13871414 end
13881415 | _ -> true
···14901517(* Expand manifest module type names at the top of the given module type *)
1491151814921519let rec scrape_alias env sub ?path mty =
15201520+ let open Subst.Lazy in
14931521 match mty, path with
14941494- Mty_ident _, _ ->
15221522+ MtyL_ident _, _ ->
14951523 let p =
14961496- match may_subst (Subst.modtype Keep) sub mty with
14971497- | Mty_ident p -> p
15241524+ match may_subst (Subst.Lazy.modtype Keep) sub mty with
15251525+ | MtyL_ident p -> p
14981526 | _ -> assert false (* only [Mty_ident]s in [sub] *)
14991527 in
15001528 begin try
15011501- scrape_alias env sub (find_modtype_expansion p env) ?path
15291529+ scrape_alias env sub (find_modtype_expansion_lazy p env) ?path
15021530 with Not_found ->
15031531 mty
15041532 end
15051505- | Mty_alias path, _ ->
15331533+ | MtyL_alias path, _ ->
15061534 let path = may_subst Subst.module_path sub path in
15071535 begin try
15081508- scrape_alias env sub (find_module path env).md_type ~path
15361536+ scrape_alias env sub ((find_module_lazy path env).mdl_type) ~path
15091537 with Not_found ->
15101538 (*Location.prerr_warning Location.none
15111539 (Warnings.No_cmi_file (Path.name path));*)
···15251553 let id' = Ident.rename id in
15261554 id', Some (add_fn id (Pident id') sub)
15271555 in
15561556+ let open Subst.Lazy in
15281557 let rec prefix_idents root items_and_paths freshening_sub prefixing_sub =
15291558 function
15301559 | [] -> (List.rev items_and_paths, freshening_sub, prefixing_sub)
15311531- | Sig_value(id, _, _) as item :: rem ->
15601560+ | SigL_value(id, _, _) as item :: rem ->
15321561 let p = Pdot(root, Ident.name id) in
15331562 prefix_idents root
15341563 ((item, p) :: items_and_paths) freshening_sub prefixing_sub rem
15351535- | Sig_type(id, td, rs, vis) :: rem ->
15641564+ | SigL_type(id, td, rs, vis) :: rem ->
15361565 let p = Pdot(root, Ident.name id) in
15371566 let id', freshening_sub = refresh id Subst.add_type freshening_sub in
15381567 prefix_idents root
15391539- ((Sig_type(id', td, rs, vis), p) :: items_and_paths)
15681568+ ((SigL_type(id', td, rs, vis), p) :: items_and_paths)
15401569 freshening_sub
15411570 (Subst.add_type id' p prefixing_sub)
15421571 rem
15431543- | Sig_typext(id, ec, es, vis) :: rem ->
15721572+ | SigL_typext(id, ec, es, vis) :: rem ->
15441573 let p = Pdot(root, Ident.name id) in
15451574 let id', freshening_sub = refresh id Subst.add_type freshening_sub in
15461575 (* we extend the substitution in case of an inlined record *)
15471576 prefix_idents root
15481548- ((Sig_typext(id', ec, es, vis), p) :: items_and_paths)
15771577+ ((SigL_typext(id', ec, es, vis), p) :: items_and_paths)
15491578 freshening_sub
15501579 (Subst.add_type id' p prefixing_sub)
15511580 rem
15521552- | Sig_module(id, pres, md, rs, vis) :: rem ->
15811581+ | SigL_module(id, pres, md, rs, vis) :: rem ->
15531582 let p = Pdot(root, Ident.name id) in
15541583 let id', freshening_sub = refresh id Subst.add_module freshening_sub in
15551584 prefix_idents root
15561556- ((Sig_module(id', pres, md, rs, vis), p) :: items_and_paths)
15851585+ ((SigL_module(id', pres, md, rs, vis), p) :: items_and_paths)
15571586 freshening_sub
15581587 (Subst.add_module id' p prefixing_sub)
15591588 rem
15601560- | Sig_modtype(id, mtd, vis) :: rem ->
15891589+ | SigL_modtype(id, mtd, vis) :: rem ->
15611590 let p = Pdot(root, Ident.name id) in
15621591 let id', freshening_sub =
15631592 refresh id (fun i p s -> Subst.add_modtype i (Mty_ident p) s)
15641593 freshening_sub
15651594 in
15661595 prefix_idents root
15671567- ((Sig_modtype(id', mtd, vis), p) :: items_and_paths)
15961596+ ((SigL_modtype(id', mtd, vis), p) :: items_and_paths)
15681597 freshening_sub
15691598 (Subst.add_modtype id' (Mty_ident p) prefixing_sub)
15701599 rem
15711571- | Sig_class(id, cd, rs, vis) :: rem ->
16001600+ | SigL_class(id, cd, rs, vis) :: rem ->
15721601 (* pretend this is a type, cf. PR#6650 *)
15731602 let p = Pdot(root, Ident.name id) in
15741603 let id', freshening_sub = refresh id Subst.add_type freshening_sub in
15751604 prefix_idents root
15761576- ((Sig_class(id', cd, rs, vis), p) :: items_and_paths)
16051605+ ((SigL_class(id', cd, rs, vis), p) :: items_and_paths)
15771606 freshening_sub
15781607 (Subst.add_type id' p prefixing_sub)
15791608 rem
15801580- | Sig_class_type(id, ctd, rs, vis) :: rem ->
16091609+ | SigL_class_type(id, ctd, rs, vis) :: rem ->
15811610 let p = Pdot(root, Ident.name id) in
15821611 let id', freshening_sub = refresh id Subst.add_type freshening_sub in
15831612 prefix_idents root
15841584- ((Sig_class_type(id', ctd, rs, vis), p) :: items_and_paths)
16131613+ ((SigL_class_type(id', ctd, rs, vis), p) :: items_and_paths)
15851614 freshening_sub
15861615 (Subst.add_type id' p prefixing_sub)
15871616 rem
15881617 in
16181618+ let sg = Subst.Lazy.force_signature_once sg in
15891619 prefix_idents root [] freshening_sub prefixing_sub sg
1590162015911621(* Compute structure descriptions *)
···16081638let module_declaration_address env id presence md =
16091639 match presence with
16101640 | Mp_absent -> begin
16111611- match md.md_type with
16121612- | Mty_alias path -> Lazy_backtrack.create (ModAlias {env; path})
16411641+ let open Subst.Lazy in
16421642+ match md.mdl_type with
16431643+ | MtyL_alias path -> Lazy_backtrack.create (ModAlias {env; path})
16131644 | _ -> assert false
16141645 end
16151646 | Mp_present ->
···16291660 {cm_env; cm_freshening_subst; cm_prefixing_subst;
16301661 cm_path; cm_addr; cm_mty} : _ result =
16311662 match scrape_alias cm_env cm_freshening_subst cm_mty with
16321632- Mty_signature sg ->
16631663+ MtyL_signature sg ->
16331664 let c =
16341665 { comp_values = NameMap.empty;
16351666 comp_constrs = NameMap.empty;
···16501681 Lazy_backtrack.create addr
16511682 in
16521683 let sub = may_subst Subst.compose freshening_sub prefixing_sub in
16531653- List.iter (fun (item, path) ->
16841684+ List.iter (fun ((item : Subst.Lazy.signature_item), path) ->
16541685 match item with
16551655- Sig_value(id, decl, _) ->
16861686+ SigL_value(id, decl, _) ->
16561687 let decl' = Subst.value_description sub decl in
16571688 let addr =
16581689 match decl.val_kind with
···16611692 in
16621693 let vda = { vda_description = decl'; vda_address = addr } in
16631694 c.comp_values <- NameMap.add (Ident.name id) vda c.comp_values;
16641664- | Sig_type(id, decl, _, _) ->
16951695+ | SigL_type(id, decl, _, _) ->
16651696 let fresh_decl =
16661697 may_subst Subst.type_declaration freshening_sub decl
16671698 in
···17041735 in
17051736 c.comp_types <- NameMap.add (Ident.name id) tda c.comp_types;
17061737 env := store_type_infos id fresh_decl !env
17071707- | Sig_typext(id, ext, _, _) ->
17381738+ | SigL_typext(id, ext, _, _) ->
17081739 let ext' = Subst.extension_constructor sub ext in
17091740 let descr =
17101741 Datarepr.extension_descr ~current_unit:(get_unit_name ()) path
···17131744 let addr = next_address () in
17141745 let cda = { cda_description = descr; cda_address = Some addr } in
17151746 c.comp_constrs <- add_to_tbl (Ident.name id) cda c.comp_constrs
17161716- | Sig_module(id, pres, md, _, _) ->
17471747+ | SigL_module(id, pres, md, _, _) ->
17171748 let md' =
17181749 (* The prefixed items get the same scope as [cm_path], which is
17191750 the prefix. *)
17201720- Lazy_backtrack.create
17211721- (sub, Subst.Rescope (Path.scope cm_path), md)
17511751+ Subst.Lazy.module_decl
17521752+ (Subst.Rescope (Path.scope cm_path)) sub md
17221753 in
17231754 let addr =
17241755 match pres with
17251756 | Mp_absent -> begin
17261726- match md.md_type with
17271727- | Mty_alias p ->
17571757+ match md.mdl_type with
17581758+ | MtyL_alias p ->
17281759 let path = may_subst Subst.module_path freshening_sub p in
17291760 Lazy_backtrack.create (ModAlias {env = !env; path})
17301761 | _ -> assert false
···17321763 | Mp_present -> next_address ()
17331764 in
17341765 let alerts =
17351735- Builtin_attributes.alerts_of_attrs md.md_attributes
17661766+ Builtin_attributes.alerts_of_attrs md.mdl_attributes
17361767 in
17371768 let comps =
17381738- components_of_module ~alerts ~uid:md.md_uid !env freshening_sub
17391739- prefixing_sub path addr md.md_type
17691769+ components_of_module ~alerts ~uid:md.mdl_uid !env freshening_sub
17701770+ prefixing_sub path addr md.mdl_type
17401771 in
17411772 let mda =
17421773 { mda_declaration = md';
···17461777 c.comp_modules <-
17471778 NameMap.add (Ident.name id) mda c.comp_modules;
17481779 env :=
17491749- store_module ~freshening_sub ~check:None id addr pres md !env
17501750- | Sig_modtype(id, decl, _) ->
17801780+ store_module ~update_summary:false ~freshening_sub ~check:None
17811781+ id addr pres md !env
17821782+ | SigL_modtype(id, decl, _) ->
17511783 let fresh_decl =
17521784 (* the fresh_decl is only going in the local temporary env, and
17531785 shouldn't be used for anything. So we make the items local. *)
17541754- may_subst (Subst.modtype_declaration Make_local) freshening_sub
17861786+ may_subst (Subst.Lazy.modtype_decl Make_local) freshening_sub
17551787 decl
17561788 in
17571789 let final_decl =
17581790 (* The prefixed items get the same scope as [cm_path], which is
17591791 the prefix. *)
17601760- Subst.modtype_declaration (Rescope (Path.scope cm_path))
17921792+ Subst.Lazy.modtype_decl (Rescope (Path.scope cm_path))
17611793 prefixing_sub fresh_decl
17621794 in
17631795 c.comp_modtypes <-
17641796 NameMap.add (Ident.name id) final_decl c.comp_modtypes;
17651765- env := store_modtype id fresh_decl !env
17661766- | Sig_class(id, decl, _, _) ->
17971797+ env := store_modtype ~update_summary:false id fresh_decl !env
17981798+ | SigL_class(id, decl, _, _) ->
17671799 let decl' = Subst.class_declaration sub decl in
17681800 let addr = next_address () in
17691801 let clda = { clda_declaration = decl'; clda_address = addr } in
17701802 c.comp_classes <- NameMap.add (Ident.name id) clda c.comp_classes
17711771- | Sig_class_type(id, decl, _, _) ->
18031803+ | SigL_class_type(id, decl, _, _) ->
17721804 let decl' = Subst.cltype_declaration sub decl in
17731805 c.comp_cltypes <-
17741806 NameMap.add (Ident.name id) decl' c.comp_cltypes)
17751807 items_and_paths;
17761808 Ok (Structure_comps c)
17771777- | Mty_functor(arg, ty_res) ->
18091809+ | MtyL_functor(arg, ty_res) ->
17781810 let sub =
17791811 may_subst Subst.compose cm_freshening_subst cm_prefixing_subst
17801812 in
17811813 let scoping = Subst.Rescope (Path.scope cm_path) in
18141814+ let open Subst.Lazy in
17821815 Ok (Functor_comps {
17831816 (* fcomp_arg and fcomp_res must be prefixed eagerly, because
17841817 they are interpreted in the outer environment *)
···17861819 (match arg with
17871820 | Unit -> Unit
17881821 | Named (param, ty_arg) ->
17891789- Named (param, Subst.modtype scoping sub ty_arg));
17901790- fcomp_res = Subst.modtype scoping sub ty_res;
18221822+ Named (param, force_modtype (modtype scoping sub ty_arg)));
18231823+ fcomp_res = force_modtype (modtype scoping sub ty_res);
17911824 fcomp_cache = Hashtbl.create 17;
17921825 fcomp_subst_cache = Hashtbl.create 17 })
17931793- | Mty_ident _ -> Error No_components_abstract
17941794- | Mty_alias p -> Error (No_components_alias p)
18261826+ | MtyL_ident _ -> Error No_components_abstract
18271827+ | MtyL_alias p -> Error (No_components_alias p)
1795182817961829(* Insertion of bindings by identifier + path *)
17971830···19651998 constrs = TycompTbl.add id cda env.constrs;
19661999 summary = Env_extension(env.summary, id, ext) }
1967200019681968-and store_module ~check ~freshening_sub id addr presence md env =
19691969- let loc = md.md_loc in
20012001+and store_module ?(update_summary=true) ~check ~freshening_sub
20022002+ id addr presence md env =
20032003+ let open Subst.Lazy in
20042004+ let loc = md.mdl_loc in
19702005 Option.iter
19711971- (fun f -> check_usage loc id md.md_uid f !module_declarations) check;
19721972- let alerts = Builtin_attributes.alerts_of_attrs md.md_attributes in
20062006+ (fun f -> check_usage loc id md.mdl_uid f !module_declarations) check;
20072007+ let alerts = Builtin_attributes.alerts_of_attrs md.mdl_attributes in
19732008 let module_decl_lazy =
19742009 match freshening_sub with
19751975- | None -> Lazy_backtrack.create_forced md
19761976- | Some s -> Lazy_backtrack.create (s, Subst.Rescope (Ident.scope id), md)
20102010+ | None -> md
20112011+ | Some s -> module_decl (Rescope (Ident.scope id)) s md
19772012 in
19782013 let comps =
19791979- components_of_module ~alerts ~uid:md.md_uid
19801980- env freshening_sub Subst.identity (Pident id) addr md.md_type
20142014+ components_of_module ~alerts ~uid:md.mdl_uid
20152015+ env freshening_sub Subst.identity (Pident id) addr md.mdl_type
19812016 in
19822017 let mda =
19832018 { mda_declaration = module_decl_lazy;
19842019 mda_components = comps;
19852020 mda_address = addr }
19862021 in
20222022+ let summary =
20232023+ if not update_summary then env.summary
20242024+ else Env_module (env.summary, id, presence, force_module_decl md) in
19872025 { env with
19882026 modules = IdTbl.add id (Mod_local mda) env.modules;
19891989- summary = Env_module(env.summary, id, presence, md) }
20272027+ summary }
1990202819911991-and store_modtype id info env =
20292029+and store_modtype ?(update_summary=true) id info env =
20302030+ let summary =
20312031+ if not update_summary then env.summary
20322032+ else Env_modtype (env.summary, id, Subst.Lazy.force_modtype_decl info) in
19922033 { env with
19932034 modtypes = IdTbl.add id info env.modtypes;
19941994- summary = Env_modtype(env.summary, id, info) }
20352035+ summary }
1995203619962037and store_class id addr desc env =
19972038 let clda = { clda_declaration = desc; clda_address = addr } in
···20302071 components_of_module ~alerts:Misc.Stdlib.String.Map.empty
20312072 ~uid:Uid.internal_not_actually_unique
20322073 (*???*)
20332033- env None Subst.identity p addr mty
20742074+ env None Subst.identity p addr (Subst.Lazy.of_modtype mty)
20342075 in
20352076 Hashtbl.add f_comp.fcomp_cache arg comps;
20362077 comps
···20682109 else
20692110 Some (fun s -> Warnings.Unused_module s)
20702111 in
21122112+ let md = Subst.Lazy.of_module_decl md in
20712113 let addr = module_declaration_address env id presence md in
20722114 let env = store_module ~freshening_sub:None ~check id addr presence md env in
20732115 if arg then add_functor_arg id env else env
2074211621172117+and add_module_declaration_lazy ~update_summary id presence md env =
21182118+ let addr = module_declaration_address env id presence md in
21192119+ let env = store_module ~update_summary ~freshening_sub:None
21202120+ ~check:None id addr presence md env in
21212121+ env
21222122+20752123and add_modtype id info env =
20762076- store_modtype id info env
21242124+ store_modtype id (Subst.Lazy.of_modtype_decl info) env
21252125+21262126+and add_modtype_lazy ~update_summary id info env =
21272127+ store_modtype ~update_summary id info env
2077212820782129and add_class id ty env =
20792130 let addr = class_declaration_address env id ty in
···20892140 { env with
20902141 local_constraints = Path.Map.add path info env.local_constraints }
2091214221432143+(* Non-lazy version of scrape_alias *)
21442144+let scrape_alias t mty =
21452145+ mty |> Subst.Lazy.of_modtype |> scrape_alias t |> Subst.Lazy.force_modtype
2092214620932147(* Insertion of bindings by name *)
20942148···2115216921162170let enter_modtype ~scope name mtd env =
21172171 let id = Ident.create_scoped ~scope name in
21182118- let env = store_modtype id mtd env in
21722172+ let env = store_modtype id (Subst.Lazy.of_modtype_decl mtd) env in
21192173 (id, env)
2120217421212175let enter_class ~scope name desc env =
···23182372(* Read a signature from a file *)
23192373let read_signature modname filename =
23202374 let mda = read_pers_mod modname filename in
23212321- let md = Lazy_backtrack.force subst_modtype_maker mda.mda_declaration in
23752375+ let md = Subst.Lazy.force_module_decl mda.mda_declaration in
23222376 match md.md_type with
23232377 | Mty_signature sg -> sg
23242378 | Mty_ident _ | Mty_functor _ | Mty_alias _ -> assert false
···25172571 end
2518257225192573let use_modtype ~use ~loc path desc =
25742574+ let open Subst.Lazy in
25202575 if use then begin
25212521- mark_modtype_used desc.mtd_uid;
25222522- Builtin_attributes.check_alerts loc desc.mtd_attributes
25762576+ mark_modtype_used desc.mtdl_uid;
25772577+ Builtin_attributes.check_alerts loc desc.mtdl_attributes
25232578 (Path.name path)
25242579 end
25252580···2608266326092664let lookup_ident_modtype ~errors ~use ~loc s env =
26102665 match IdTbl.find_name wrap_identity ~mark:use s env.modtypes with
26112611- | (path, data) as res ->
26662666+ | (path, data) ->
26122667 use_modtype ~use ~loc path data;
26132613- res
26682668+ (path, data)
26142669 | exception Not_found ->
26152670 may_lookup_error errors loc env (Unbound_modtype (Lident s))
26162671···27492804 match lid with
27502805 | Lident s ->
27512806 let path, data = lookup_ident_module Load ~errors ~use ~loc s env in
27522752- let md = Lazy_backtrack.force subst_modtype_maker data.mda_declaration in
28072807+ let md = Subst.Lazy.force_module_decl data.mda_declaration in
27532808 path, md
27542809 | Ldot(l, s) ->
27552810 let path, data = lookup_dot_module ~errors ~use ~loc l s env in
27562756- let md = Lazy_backtrack.force subst_modtype_maker data.mda_declaration in
28112811+ let md = Subst.Lazy.force_module_decl data.mda_declaration in
27572812 path, md
27582813 | Lapply _ as lid ->
27592814 let path_f, comp_f, path_arg = lookup_apply ~errors ~use ~loc lid env in
···28822937 let (path, tda) = lookup_type_full ~errors ~use ~loc lid env in
28832938 path, tda.tda_declaration
2884293928852885-let lookup_modtype ~errors ~use ~loc lid env =
29402940+let lookup_modtype_lazy ~errors ~use ~loc lid env =
28862941 match lid with
28872942 | Lident s -> lookup_ident_modtype ~errors ~use ~loc s env
28882943 | Ldot(l, s) -> lookup_dot_modtype ~errors ~use ~loc l s env
28892944 | Lapply _ -> assert false
2890294529462946+let lookup_modtype ~errors ~use ~loc lid env =
29472947+ let (path, mt) = lookup_modtype_lazy ~errors ~use ~loc lid env in
29482948+ path, Subst.Lazy.force_modtype_decl mt
29492949+28912950let lookup_class ~errors ~use ~loc lid env =
28922951 match lid with
28932952 | Lident s -> lookup_ident_class ~errors ~use ~loc s env
···2999305830003059let lookup_modtype ?(use=true) ~loc lid env =
30013060 lookup_modtype ~errors:true ~use ~loc lid env
30613061+30623062+let lookup_modtype_path ?(use=true) ~loc lid env =
30633063+ fst (lookup_modtype_lazy ~errors:true ~use ~loc lid env)
3002306430033065let lookup_class ?(use=true) ~loc lid env =
30043066 lookup_class ~errors:true ~use ~loc lid env
···31393201 | Mod_unbound _ -> acc
31403202 | Mod_local mda ->
31413203 let md =
31423142- Lazy_backtrack.force subst_modtype_maker mda.mda_declaration
32043204+ Subst.Lazy.force_module_decl mda.mda_declaration
31433205 in
31443206 f name p md acc
31453207 | Mod_persistent ->
···31473209 | None -> acc
31483210 | Some mda ->
31493211 let md =
31503150- Lazy_backtrack.force subst_modtype_maker
31513151- mda.mda_declaration
32123212+ Subst.Lazy.force_module_decl mda.mda_declaration
31523213 in
31533214 f name p md acc)
31543215 env.modules
···31633224 NameMap.fold
31643225 (fun s mda acc ->
31653226 let md =
31663166- Lazy_backtrack.force subst_modtype_maker mda.mda_declaration
32273227+ Subst.Lazy.force_module_decl mda.mda_declaration
31673228 in
31683229 f s (Pdot (p, s)) md acc)
31693230 c.comp_modules
···31883249 (fun env -> env.types) (fun sc -> sc.comp_types)
31893250 (fun k p tda acc -> f k p tda.tda_declaration acc)
31903251and fold_modtypes f =
32523252+ let f l path data acc = f l path (Subst.Lazy.force_modtype_decl data) acc in
31913253 find_all wrap_identity
31923254 (fun env -> env.modtypes) (fun sc -> sc.comp_modtypes) f
31933255and fold_classes f =
+12-1
typing/env.mli
···8686val find_class: Path.t -> t -> class_declaration
8787val find_cltype: Path.t -> t -> class_type_declaration
88888989+val find_strengthened_module:
9090+ aliasable:bool -> Path.t -> t -> module_type
9191+8992val find_ident_constructor: Ident.t -> t -> constructor_description
9093val find_ident_label: Ident.t -> t -> label_description
9194···9699(* Find the manifest type information associated to a type for the sake
97100 of the compiler's type-based optimisations. *)
98101val find_modtype_expansion: Path.t -> t -> module_type
102102+val find_modtype_expansion_lazy: Path.t -> t -> Subst.Lazy.modtype
99103100104val find_hash_type: Path.t -> t -> type_declaration
101105(* Find the "#t" type given the path for "t" *)
···211215212216val lookup_module_path:
213217 ?use:bool -> loc:Location.t -> load:bool -> Longident.t -> t -> Path.t
218218+val lookup_modtype_path:
219219+ ?use:bool -> loc:Location.t -> Longident.t -> t -> Path.t
214220215221val lookup_constructor:
216222 ?use:bool -> loc:Location.t -> constructor_usage -> Longident.t -> t ->
···278284 ?arg:bool -> Ident.t -> module_presence -> module_type -> t -> t
279285val add_module_declaration: ?arg:bool -> check:bool -> Ident.t ->
280286 module_presence -> module_declaration -> t -> t
287287+val add_module_declaration_lazy: update_summary:bool ->
288288+ Ident.t -> module_presence -> Subst.Lazy.module_decl -> t -> t
281289val add_modtype: Ident.t -> modtype_declaration -> t -> t
290290+val add_modtype_lazy: update_summary:bool ->
291291+ Ident.t -> Subst.Lazy.modtype_declaration -> t -> t
282292val add_class: Ident.t -> class_declaration -> t -> t
283293val add_cltype: Ident.t -> class_type_declaration -> t -> t
284294val add_local_type: Path.t -> type_declaration -> t -> t
···438448val add_delayed_check_forward: ((unit -> unit) -> unit) ref
439449(* Forward declaration to break mutual recursion with Mtype. *)
440450val strengthen:
441441- (aliasable:bool -> t -> module_type -> Path.t -> module_type) ref
451451+ (aliasable:bool -> t -> Subst.Lazy.modtype ->
452452+ Path.t -> Subst.Lazy.modtype) ref
442453(* Forward declaration to break mutual recursion with Ctype. *)
443454val same_constr: (t -> type_expr -> type_expr -> bool) ref
444455(* Forward declaration to break mutual recursion with Printtyp. *)
+12-9
typing/includemod.ml
···210210 | exception Not_found -> None
211211 | x -> Some x
212212213213-let expand_module_alias env path =
214214- match (Env.find_module path env).md_type with
213213+let expand_module_alias ~strengthen env path =
214214+ match
215215+ if strengthen then Env.find_strengthened_module ~aliasable:true path env
216216+ else (Env.find_module path env).md_type
217217+ with
215218 | x -> Ok x
216219 | exception Not_found -> Error (Error.Unbound_module_path path)
217220···345348 | None -> List.rev before, res
346349 end
347350 | Mty_alias p as res ->
348348- begin match expand_module_alias env p with
351351+ begin match expand_module_alias ~strengthen:false env p with
349352 | Ok mty -> retrieve_functor_params before env mty
350353 | Error _ -> List.rev before, res
351354 end
···380383 | exception Env.Error (Env.Missing_module (_, _, path)) ->
381384 Error Error.(Mt_core(Unbound_module_path path))
382385 | p1 ->
383383- begin match expand_module_alias env p1 with
386386+ begin match expand_module_alias ~strengthen:false env p1 with
384387 | Error e -> Error (Error.Mt_core e)
385388 | Ok mty1 ->
386389 match strengthened_modtypes ~loc ~aliasable:true env ~mark
···575578 false
576579 | _ -> name2, true
577580 in
578578- begin try
579579- let (id1, item1, pos1) = FieldMap.find name2 comps1 in
581581+ begin match FieldMap.find name2 comps1 with
582582+ | (id1, item1, pos1) ->
580583 let new_subst =
581584 match item2 with
582585 Sig_type _ ->
···591594 in
592595 pair_components new_subst
593596 ((item1, item2, pos1) :: paired) unpaired rem
594594- with Not_found ->
597597+ | exception Not_found ->
595598 let unpaired =
596599 if report then
597600 item2 :: unpaired
···10321035 | Error mdiff ->
10331036 raise (Error(env,Error.(In_Module_type mdiff)))
1034103710351035-let expand_module_alias env path =
10361036- match expand_module_alias env path with
10381038+let expand_module_alias ~strengthen env path =
10391039+ match expand_module_alias ~strengthen env path with
10371040 | Ok x -> x
10381041 | Result.Error _ ->
10391042 raise (Error(env,In_Expansion(Error.Unbound_module_path path)))
···1919open Path
2020open Types
21212222-2323-let rec scrape env mty =
2222+let rec scrape_lazy env mty =
2323+ let open Subst.Lazy in
2424 match mty with
2525- Mty_ident p ->
2525+ MtyL_ident p ->
2626 begin try
2727- scrape env (Env.find_modtype_expansion p env)
2727+ scrape_lazy env (Env.find_modtype_expansion_lazy p env)
2828 with Not_found ->
2929 mty
3030 end
3131 | _ -> mty
32323333+let scrape env mty =
3434+ match mty with
3535+ Mty_ident p ->
3636+ Subst.Lazy.force_modtype (scrape_lazy env (MtyL_ident p))
3737+ | _ -> mty
3838+3339let freshen ~scope mty =
3440 Subst.modtype (Rescope scope) Subst.identity mty
35413636-let rec strengthen ~aliasable env mty p =
3737- match scrape env mty with
3838- Mty_signature sg ->
3939- Mty_signature(strengthen_sig ~aliasable env sg p)
4040- | Mty_functor(Named (Some param, arg), res)
4242+let rec strengthen_lazy ~aliasable env mty p =
4343+ let open Subst.Lazy in
4444+ match scrape_lazy env mty with
4545+ MtyL_signature sg ->
4646+ MtyL_signature(strengthen_lazy_sig ~aliasable env sg p)
4747+ | MtyL_functor(Named (Some param, arg), res)
4148 when !Clflags.applicative_functors ->
4242- Mty_functor(Named (Some param, arg),
4343- strengthen ~aliasable:false env res (Papply(p, Pident param)))
4444- | Mty_functor(Named (None, arg), res)
4949+ MtyL_functor(Named (Some param, arg),
5050+ strengthen_lazy ~aliasable:false env res (Papply(p, Pident param)))
5151+ | MtyL_functor(Named (None, arg), res)
4552 when !Clflags.applicative_functors ->
4653 let param = Ident.create_scoped ~scope:(Path.scope p) "Arg" in
4747- Mty_functor(Named (Some param, arg),
4848- strengthen ~aliasable:false env res (Papply(p, Pident param)))
5454+ MtyL_functor(Named (Some param, arg),
5555+ strengthen_lazy ~aliasable:false env res (Papply(p, Pident param)))
4956 | mty ->
5057 mty
51585252-and strengthen_sig ~aliasable env sg p =
5959+and strengthen_lazy_sig' ~aliasable env sg p =
6060+ let open Subst.Lazy in
5361 match sg with
5462 [] -> []
5555- | (Sig_value(_, _, _) as sigelt) :: rem ->
5656- sigelt :: strengthen_sig ~aliasable env rem p
5757- | Sig_type(id, {type_kind=Type_abstract}, _, _) :: rem
6363+ | (SigL_value(_, _, _) as sigelt) :: rem ->
6464+ sigelt :: strengthen_lazy_sig' ~aliasable env rem p
6565+ | SigL_type(id, {type_kind=Type_abstract}, _, _) :: rem
5866 when Btype.is_row_name (Ident.name id) ->
5959- strengthen_sig ~aliasable env rem p
6060- | Sig_type(id, decl, rs, vis) :: rem ->
6767+ strengthen_lazy_sig' ~aliasable env rem p
6868+ | SigL_type(id, decl, rs, vis) :: rem ->
6169 let newdecl =
6270 match decl.type_manifest, decl.type_private, decl.type_kind with
6371 Some _, Public, _ -> decl
···7179 else
7280 { decl with type_manifest = manif }
7381 in
7474- Sig_type(id, newdecl, rs, vis) :: strengthen_sig ~aliasable env rem p
7575- | (Sig_typext _ as sigelt) :: rem ->
7676- sigelt :: strengthen_sig ~aliasable env rem p
7777- | Sig_module(id, pres, md, rs, vis) :: rem ->
8282+ SigL_type(id, newdecl, rs, vis) ::
8383+ strengthen_lazy_sig' ~aliasable env rem p
8484+ | (SigL_typext _ as sigelt) :: rem ->
8585+ sigelt :: strengthen_lazy_sig' ~aliasable env rem p
8686+ | SigL_module(id, pres, md, rs, vis) :: rem ->
7887 let str =
7979- strengthen_decl ~aliasable env md (Pdot(p, Ident.name id))
8888+ strengthen_lazy_decl ~aliasable env md (Pdot(p, Ident.name id))
8089 in
8181- Sig_module(id, pres, str, rs, vis)
8282- :: strengthen_sig ~aliasable
8383- (Env.add_module_declaration ~check:false id pres md env) rem p
9090+ let env =
9191+ Env.add_module_declaration_lazy ~update_summary:false id pres md env in
9292+ SigL_module(id, pres, str, rs, vis)
9393+ :: strengthen_lazy_sig' ~aliasable env rem p
8494 (* Need to add the module in case it defines manifest module types *)
8585- | Sig_modtype(id, decl, vis) :: rem ->
9595+ | SigL_modtype(id, decl, vis) :: rem ->
8696 let newdecl =
8787- match decl.mtd_type with
8888- None ->
8989- {decl with mtd_type = Some(Mty_ident(Pdot(p,Ident.name id)))}
9090- | Some _ ->
9797+ match decl.mtdl_type with
9898+ | Some _ when not aliasable ->
9999+ (* [not alisable] condition needed because of recursive modules.
100100+ See [Typemod.check_recmodule_inclusion]. *)
91101 decl
102102+ | _ ->
103103+ {decl with mtdl_type = Some(MtyL_ident(Pdot(p,Ident.name id)))}
92104 in
9393- Sig_modtype(id, newdecl, vis) ::
9494- strengthen_sig ~aliasable (Env.add_modtype id decl env) rem p
105105+ let env = Env.add_modtype_lazy ~update_summary:false id decl env in
106106+ SigL_modtype(id, newdecl, vis) ::
107107+ strengthen_lazy_sig' ~aliasable env rem p
95108 (* Need to add the module type in case it is manifest *)
9696- | (Sig_class _ as sigelt) :: rem ->
9797- sigelt :: strengthen_sig ~aliasable env rem p
9898- | (Sig_class_type _ as sigelt) :: rem ->
9999- sigelt :: strengthen_sig ~aliasable env rem p
109109+ | (SigL_class _ as sigelt) :: rem ->
110110+ sigelt :: strengthen_lazy_sig' ~aliasable env rem p
111111+ | (SigL_class_type _ as sigelt) :: rem ->
112112+ sigelt :: strengthen_lazy_sig' ~aliasable env rem p
113113+114114+and strengthen_lazy_sig ~aliasable env sg p =
115115+ let sg = Subst.Lazy.force_signature_once sg in
116116+ let sg = strengthen_lazy_sig' ~aliasable env sg p in
117117+ Subst.Lazy.of_signature_items sg
118118+119119+and strengthen_lazy_decl ~aliasable env md p =
120120+ let open Subst.Lazy in
121121+ match md.mdl_type with
122122+ | MtyL_alias _ -> md
123123+ | _ when aliasable -> {md with mdl_type = MtyL_alias p}
124124+ | mty -> {md with mdl_type = strengthen_lazy ~aliasable env mty p}
125125+126126+let () = Env.strengthen := strengthen_lazy
100127101101-and strengthen_decl ~aliasable env md p =
102102- match md.md_type with
103103- | Mty_alias _ -> md
104104- | _ when aliasable -> {md with md_type = Mty_alias p}
105105- | mty -> {md with md_type = strengthen ~aliasable env mty p}
128128+let strengthen ~aliasable env mty p =
129129+ let mty = strengthen_lazy ~aliasable env (Subst.Lazy.of_modtype mty) p in
130130+ Subst.Lazy.force_modtype mty
106131107107-let () = Env.strengthen := strengthen
132132+let strengthen_decl ~aliasable env md p =
133133+ let md = strengthen_lazy_decl ~aliasable env
134134+ (Subst.Lazy.of_module_decl md) p in
135135+ Subst.Lazy.force_module_decl md
108136109137let rec make_aliases_absent pres mty =
110138 match mty with
+14-11
typing/rec_check.ml
···12021202 is_destructuring_pattern l || is_destructuring_pattern r
1203120312041204let is_valid_recursive_expression idlist expr =
12051205- let ty = expression expr Return in
12061206- match Env.unguarded ty idlist, Env.dependent ty idlist,
12071207- classify_expression expr with
12081208- | _ :: _, _, _ (* The expression inspects rec-bound variables *)
12091209- | [], _ :: _, Dynamic -> (* The expression depends on rec-bound variables
12101210- and its size is unknown *)
12111211- false
12121212- | [], _, Static (* The expression has known size *)
12131213- | [], [], Dynamic -> (* The expression has unknown size,
12141214- but does not depend on rec-bound variables *)
12151215- true
12051205+ match expr.exp_desc with
12061206+ | Texp_function _ ->
12071207+ (* Fast path: functions can never have invalid recursive references *)
12081208+ true
12091209+ | _ ->
12101210+ match classify_expression expr with
12111211+ | Static ->
12121212+ (* The expression has known size *)
12131213+ let ty = expression expr Return in
12141214+ Env.unguarded ty idlist = []
12151215+ | Dynamic ->
12161216+ (* The expression has unknown size *)
12171217+ let ty = expression expr Return in
12181218+ Env.unguarded ty idlist = [] && Env.dependent ty idlist = []
1216121912171220(* A class declaration may contain let-bindings. If they are recursive,
12181221 their validity will already be checked by [is_valid_recursive_expression]
+268-82
typing/subst.ml
···417417 For_copy.with_scope
418418 (fun copy_scope -> extension_constructor' copy_scope s ext)
419419420420+421421+(* For every binding k |-> d of m1, add k |-> f d to m2
422422+ and return resulting merged map. *)
423423+424424+let merge_path_maps f m1 m2 =
425425+ Path.Map.fold (fun k d accu -> Path.Map.add k (f d) accu) m1 m2
426426+427427+let keep_latest_loc l1 l2 =
428428+ match l2 with
429429+ | None -> l1
430430+ | Some _ -> l2
431431+432432+let type_replacement s = function
433433+ | Path p -> Path (type_path s p)
434434+ | Type_function { params; body } ->
435435+ For_copy.with_scope (fun copy_scope ->
436436+ let params = List.map (typexp copy_scope s) params in
437437+ let body = typexp copy_scope s body in
438438+ Type_function { params; body })
439439+420440type scoping =
421441 | Keep
422442 | Make_local
423443 | Rescope of int
424444445445+module Lazy_types = struct
446446+447447+ type module_decl =
448448+ {
449449+ mdl_type: modtype;
450450+ mdl_attributes: Parsetree.attributes;
451451+ mdl_loc: Location.t;
452452+ mdl_uid: Uid.t;
453453+ }
454454+455455+ and modtype =
456456+ | MtyL_ident of Path.t
457457+ | MtyL_signature of signature
458458+ | MtyL_functor of functor_parameter * modtype
459459+ | MtyL_alias of Path.t
460460+461461+ and modtype_declaration =
462462+ {
463463+ mtdl_type: modtype option;
464464+ mtdl_attributes: Parsetree.attributes;
465465+ mtdl_loc: Location.t;
466466+ mtdl_uid: Uid.t;
467467+ }
468468+469469+ and signature' =
470470+ | S_eager of Types.signature
471471+ | S_lazy of signature_item list
472472+473473+ and signature =
474474+ (scoping * t * signature', signature') Lazy_backtrack.t
475475+476476+ and signature_item =
477477+ SigL_value of Ident.t * value_description * visibility
478478+ | SigL_type of Ident.t * type_declaration * rec_status * visibility
479479+ | SigL_typext of Ident.t * extension_constructor * ext_status * visibility
480480+ | SigL_module of
481481+ Ident.t * module_presence * module_decl * rec_status * visibility
482482+ | SigL_modtype of Ident.t * modtype_declaration * visibility
483483+ | SigL_class of Ident.t * class_declaration * rec_status * visibility
484484+ | SigL_class_type of Ident.t * class_type_declaration *
485485+ rec_status * visibility
486486+487487+ and functor_parameter =
488488+ | Unit
489489+ | Named of Ident.t option * modtype
490490+491491+end
492492+open Lazy_types
493493+425494let rename_bound_idents scoping s sg =
426495 let rename =
427496 let open Ident in
···432501 in
433502 let rec rename_bound_idents s sg = function
434503 | [] -> sg, s
435435- | Sig_type(id, td, rs, vis) :: rest ->
504504+ | SigL_type(id, td, rs, vis) :: rest ->
436505 let id' = rename id in
437506 rename_bound_idents
438507 (add_type id (Pident id') s)
439439- (Sig_type(id', td, rs, vis) :: sg)
508508+ (SigL_type(id', td, rs, vis) :: sg)
440509 rest
441441- | Sig_module(id, pres, md, rs, vis) :: rest ->
510510+ | SigL_module(id, pres, md, rs, vis) :: rest ->
442511 let id' = rename id in
443512 rename_bound_idents
444513 (add_module id (Pident id') s)
445445- (Sig_module (id', pres, md, rs, vis) :: sg)
514514+ (SigL_module (id', pres, md, rs, vis) :: sg)
446515 rest
447447- | Sig_modtype(id, mtd, vis) :: rest ->
516516+ | SigL_modtype(id, mtd, vis) :: rest ->
448517 let id' = rename id in
449518 rename_bound_idents
450519 (add_modtype id (Mty_ident(Pident id')) s)
451451- (Sig_modtype(id', mtd, vis) :: sg)
520520+ (SigL_modtype(id', mtd, vis) :: sg)
452521 rest
453453- | Sig_class(id, cd, rs, vis) :: rest ->
522522+ | SigL_class(id, cd, rs, vis) :: rest ->
454523 (* cheat and pretend they are types cf. PR#6650 *)
455524 let id' = rename id in
456525 rename_bound_idents
457526 (add_type id (Pident id') s)
458458- (Sig_class(id', cd, rs, vis) :: sg)
527527+ (SigL_class(id', cd, rs, vis) :: sg)
459528 rest
460460- | Sig_class_type(id, ctd, rs, vis) :: rest ->
529529+ | SigL_class_type(id, ctd, rs, vis) :: rest ->
461530 (* cheat and pretend they are types cf. PR#6650 *)
462531 let id' = rename id in
463532 rename_bound_idents
464533 (add_type id (Pident id') s)
465465- (Sig_class_type(id', ctd, rs, vis) :: sg)
534534+ (SigL_class_type(id', ctd, rs, vis) :: sg)
466535 rest
467467- | Sig_value(id, vd, vis) :: rest ->
536536+ | SigL_value(id, vd, vis) :: rest ->
468537 (* scope doesn't matter for value identifiers. *)
469538 let id' = Ident.rename id in
470470- rename_bound_idents s (Sig_value(id', vd, vis) :: sg) rest
471471- | Sig_typext(id, ec, es, vis) :: rest ->
539539+ rename_bound_idents s (SigL_value(id', vd, vis) :: sg) rest
540540+ | SigL_typext(id, ec, es, vis) :: rest ->
472541 let id' = rename id in
473473- rename_bound_idents s (Sig_typext(id',ec,es,vis) :: sg) rest
542542+ rename_bound_idents s (SigL_typext(id',ec,es,vis) :: sg) rest
474543 in
475544 rename_bound_idents s [] sg
476545477477-let rec modtype scoping s = function
478478- Mty_ident p as mty ->
546546+let rec lazy_module_decl md =
547547+ { mdl_type = lazy_modtype md.md_type;
548548+ mdl_attributes = md.md_attributes;
549549+ mdl_loc = md.md_loc;
550550+ mdl_uid = md.md_uid }
551551+552552+and subst_lazy_module_decl scoping s md =
553553+ let mdl_type = subst_lazy_modtype scoping s md.mdl_type in
554554+ { mdl_type;
555555+ mdl_attributes = attrs s md.mdl_attributes;
556556+ mdl_loc = loc s md.mdl_loc;
557557+ mdl_uid = md.mdl_uid }
558558+559559+and force_module_decl md =
560560+ let md_type = force_modtype md.mdl_type in
561561+ { md_type;
562562+ md_attributes = md.mdl_attributes;
563563+ md_loc = md.mdl_loc;
564564+ md_uid = md.mdl_uid }
565565+566566+and lazy_modtype = function
567567+ | Mty_ident p -> MtyL_ident p
568568+ | Mty_signature sg ->
569569+ MtyL_signature (Lazy_backtrack.create_forced (S_eager sg))
570570+ | Mty_functor (Unit, mty) -> MtyL_functor (Unit, lazy_modtype mty)
571571+ | Mty_functor (Named (id, arg), res) ->
572572+ MtyL_functor (Named (id, lazy_modtype arg), lazy_modtype res)
573573+ | Mty_alias p -> MtyL_alias p
574574+575575+and subst_lazy_modtype scoping s = function
576576+ | MtyL_ident p ->
479577 begin match Path.Map.find p s.modtypes with
480480- | mty -> mty
578578+ | mty -> lazy_modtype mty
481579 | exception Not_found ->
482580 begin match p with
483483- | Pident _ -> mty
581581+ | Pident _ -> MtyL_ident p
484582 | Pdot(p, n) ->
485485- Mty_ident(Pdot(module_path s p, n))
583583+ MtyL_ident(Pdot(module_path s p, n))
486584 | Papply _ ->
487585 fatal_error "Subst.modtype"
488586 end
489587 end
490490- | Mty_signature sg ->
491491- Mty_signature(signature scoping s sg)
492492- | Mty_functor(Unit, res) ->
493493- Mty_functor(Unit, modtype scoping s res)
494494- | Mty_functor(Named (None, arg), res) ->
495495- Mty_functor(Named (None, (modtype scoping s) arg), modtype scoping s res)
496496- | Mty_functor(Named (Some id, arg), res) ->
588588+ | MtyL_signature sg ->
589589+ MtyL_signature(subst_lazy_signature scoping s sg)
590590+ | MtyL_functor(Unit, res) ->
591591+ MtyL_functor(Unit, subst_lazy_modtype scoping s res)
592592+ | MtyL_functor(Named (None, arg), res) ->
593593+ MtyL_functor(Named (None, (subst_lazy_modtype scoping s) arg),
594594+ subst_lazy_modtype scoping s res)
595595+ | MtyL_functor(Named (Some id, arg), res) ->
497596 let id' = Ident.rename id in
498498- Mty_functor(Named (Some id', (modtype scoping s) arg),
499499- modtype scoping (add_module id (Pident id') s) res)
500500- | Mty_alias p ->
501501- Mty_alias (module_path s p)
597597+ MtyL_functor(Named (Some id', (subst_lazy_modtype scoping s) arg),
598598+ subst_lazy_modtype scoping (add_module id (Pident id') s) res)
599599+ | MtyL_alias p ->
600600+ MtyL_alias (module_path s p)
601601+602602+and force_modtype = function
603603+ | MtyL_ident p -> Mty_ident p
604604+ | MtyL_signature sg -> Mty_signature (force_signature sg)
605605+ | MtyL_functor (param, res) ->
606606+ let param : Types.functor_parameter =
607607+ match param with
608608+ | Unit -> Unit
609609+ | Named (id, mty) -> Named (id, force_modtype mty) in
610610+ Mty_functor (param, force_modtype res)
611611+ | MtyL_alias p -> Mty_alias p
502612503503-and signature scoping s sg =
613613+and lazy_modtype_decl mtd =
614614+ let mtdl_type = Option.map lazy_modtype mtd.mtd_type in
615615+ { mtdl_type;
616616+ mtdl_attributes = mtd.mtd_attributes;
617617+ mtdl_loc = mtd.mtd_loc;
618618+ mtdl_uid = mtd.mtd_uid }
619619+620620+and subst_lazy_modtype_decl scoping s mtd =
621621+ { mtdl_type = Option.map (subst_lazy_modtype scoping s) mtd.mtdl_type;
622622+ mtdl_attributes = attrs s mtd.mtdl_attributes;
623623+ mtdl_loc = loc s mtd.mtdl_loc;
624624+ mtdl_uid = mtd.mtdl_uid }
625625+626626+and force_modtype_decl mtd =
627627+ let mtd_type = Option.map force_modtype mtd.mtdl_type in
628628+ { mtd_type;
629629+ mtd_attributes = mtd.mtdl_attributes;
630630+ mtd_loc = mtd.mtdl_loc;
631631+ mtd_uid = mtd.mtdl_uid }
632632+633633+and subst_lazy_signature scoping s sg =
634634+ match Lazy_backtrack.get_contents sg with
635635+ | Left (scoping', s', sg) ->
636636+ let scoping =
637637+ match scoping', scoping with
638638+ | sc, Keep -> sc
639639+ | _, (Make_local|Rescope _) -> scoping
640640+ in
641641+ let s = compose s' s in
642642+ Lazy_backtrack.create (scoping, s, sg)
643643+ | Right sg ->
644644+ Lazy_backtrack.create (scoping, s, sg)
645645+646646+and force_signature sg =
647647+ List.map force_signature_item (force_signature_once sg)
648648+649649+and force_signature_once sg =
650650+ lazy_signature' (Lazy_backtrack.force force_signature_once' sg)
651651+652652+and lazy_signature' = function
653653+ | S_lazy sg -> sg
654654+ | S_eager sg -> List.map lazy_signature_item sg
655655+656656+and force_signature_once' (scoping, s, sg) =
657657+ let sg = lazy_signature' sg in
504658 (* Components of signature may be mutually recursive (e.g. type declarations
505659 or class and type declarations), so first build global renaming
506660 substitution... *)
507661 let (sg', s') = rename_bound_idents scoping s sg in
508662 (* ... then apply it to each signature component in turn *)
509663 For_copy.with_scope (fun copy_scope ->
510510- List.rev_map (signature_item' copy_scope scoping s') sg'
664664+ S_lazy (List.rev_map (subst_lazy_signature_item' copy_scope scoping s') sg')
511665 )
512666513513-514514-and signature_item' copy_scope scoping s comp =
515515- match comp with
516516- Sig_value(id, d, vis) ->
517517- Sig_value(id, value_description' copy_scope s d, vis)
667667+and lazy_signature_item = function
668668+ | Sig_value(id, d, vis) ->
669669+ SigL_value(id, d, vis)
518670 | Sig_type(id, d, rs, vis) ->
519519- Sig_type(id, type_declaration' copy_scope s d, rs, vis)
671671+ SigL_type(id, d, rs, vis)
520672 | Sig_typext(id, ext, es, vis) ->
521521- Sig_typext(id, extension_constructor' copy_scope s ext, es, vis)
522522- | Sig_module(id, pres, d, rs, vis) ->
523523- Sig_module(id, pres, module_declaration scoping s d, rs, vis)
673673+ SigL_typext(id, ext, es, vis)
674674+ | Sig_module(id, res, d, rs, vis) ->
675675+ SigL_module(id, res, lazy_module_decl d, rs, vis)
524676 | Sig_modtype(id, d, vis) ->
525525- Sig_modtype(id, modtype_declaration scoping s d, vis)
677677+ SigL_modtype(id, lazy_modtype_decl d, vis)
526678 | Sig_class(id, d, rs, vis) ->
527527- Sig_class(id, class_declaration' copy_scope s d, rs, vis)
679679+ SigL_class(id, d, rs, vis)
528680 | Sig_class_type(id, d, rs, vis) ->
529529- Sig_class_type(id, cltype_declaration' copy_scope s d, rs, vis)
681681+ SigL_class_type(id, d, rs, vis)
530682531531-and signature_item scoping s comp =
532532- For_copy.with_scope
533533- (fun copy_scope -> signature_item' copy_scope scoping s comp)
683683+and subst_lazy_signature_item' copy_scope scoping s comp =
684684+ match comp with
685685+ SigL_value(id, d, vis) ->
686686+ SigL_value(id, value_description' copy_scope s d, vis)
687687+ | SigL_type(id, d, rs, vis) ->
688688+ SigL_type(id, type_declaration' copy_scope s d, rs, vis)
689689+ | SigL_typext(id, ext, es, vis) ->
690690+ SigL_typext(id, extension_constructor' copy_scope s ext, es, vis)
691691+ | SigL_module(id, pres, d, rs, vis) ->
692692+ SigL_module(id, pres, subst_lazy_module_decl scoping s d, rs, vis)
693693+ | SigL_modtype(id, d, vis) ->
694694+ SigL_modtype(id, subst_lazy_modtype_decl scoping s d, vis)
695695+ | SigL_class(id, d, rs, vis) ->
696696+ SigL_class(id, class_declaration' copy_scope s d, rs, vis)
697697+ | SigL_class_type(id, d, rs, vis) ->
698698+ SigL_class_type(id, cltype_declaration' copy_scope s d, rs, vis)
534699535535-and module_declaration scoping s decl =
536536- {
537537- md_type = modtype scoping s decl.md_type;
538538- md_attributes = attrs s decl.md_attributes;
539539- md_loc = loc s decl.md_loc;
540540- md_uid = decl.md_uid;
541541- }
542542-543543-and modtype_declaration scoping s decl =
544544- {
545545- mtd_type = Option.map (modtype scoping s) decl.mtd_type;
546546- mtd_attributes = attrs s decl.mtd_attributes;
547547- mtd_loc = loc s decl.mtd_loc;
548548- mtd_uid = decl.mtd_uid;
549549- }
550550-551551-552552-(* For every binding k |-> d of m1, add k |-> f d to m2
553553- and return resulting merged map. *)
554554-555555-let merge_path_maps f m1 m2 =
556556- Path.Map.fold (fun k d accu -> Path.Map.add k (f d) accu) m1 m2
557557-558558-let keep_latest_loc l1 l2 =
559559- match l2 with
560560- | None -> l1
561561- | Some _ -> l2
700700+and force_signature_item = function
701701+ | SigL_value(id, vd, vis) -> Sig_value(id, vd, vis)
702702+ | SigL_type(id, d, rs, vis) -> Sig_type(id, d, rs, vis)
703703+ | SigL_typext(id, ext, es, vis) -> Sig_typext(id, ext, es, vis)
704704+ | SigL_module(id, pres, d, rs, vis) ->
705705+ Sig_module(id, pres, force_module_decl d, rs, vis)
706706+ | SigL_modtype(id, d, vis) ->
707707+ Sig_modtype (id, force_modtype_decl d, vis)
708708+ | SigL_class(id, d, rs, vis) -> Sig_class(id, d, rs, vis)
709709+ | SigL_class_type(id, d, rs, vis) -> Sig_class_type(id, d, rs, vis)
562710563563-let type_replacement s = function
564564- | Path p -> Path (type_path s p)
565565- | Type_function { params; body } ->
566566- For_copy.with_scope (fun copy_scope ->
567567- let params = List.map (typexp copy_scope s) params in
568568- let body = typexp copy_scope s body in
569569- Type_function { params; body })
711711+and modtype scoping s t =
712712+ t |> lazy_modtype |> subst_lazy_modtype scoping s |> force_modtype
570713571714(* Composition of substitutions:
572715 apply (compose s1 s2) x = apply s2 (apply s1 x) *)
573716574574-let compose s1 s2 =
717717+and compose s1 s2 =
718718+ if s1 == identity then s2 else
719719+ if s2 == identity then s1 else
575720 { types = merge_path_maps (type_replacement s2) s1.types s2.types;
576721 modules = merge_path_maps (module_path s2) s1.modules s2.modules;
577722 modtypes = merge_path_maps (modtype Keep s2) s1.modtypes s2.modtypes;
578723 for_saving = s1.for_saving || s2.for_saving;
579724 loc = keep_latest_loc s1.loc s2.loc;
580725 }
726726+727727+728728+let subst_lazy_signature_item scoping s comp =
729729+ For_copy.with_scope
730730+ (fun copy_scope -> subst_lazy_signature_item' copy_scope scoping s comp)
731731+732732+module Lazy = struct
733733+ include Lazy_types
734734+735735+ let of_module_decl = lazy_module_decl
736736+ let of_modtype = lazy_modtype
737737+ let of_modtype_decl = lazy_modtype_decl
738738+ let of_signature sg = Lazy_backtrack.create_forced (S_eager sg)
739739+ let of_signature_items sg = Lazy_backtrack.create_forced (S_lazy sg)
740740+ let of_signature_item = lazy_signature_item
741741+742742+ let module_decl = subst_lazy_module_decl
743743+ let modtype = subst_lazy_modtype
744744+ let modtype_decl = subst_lazy_modtype_decl
745745+ let signature = subst_lazy_signature
746746+ let signature_item = subst_lazy_signature_item
747747+748748+ let force_module_decl = force_module_decl
749749+ let force_modtype = force_modtype
750750+ let force_modtype_decl = force_modtype_decl
751751+ let force_signature = force_signature
752752+ let force_signature_once = force_signature_once
753753+ let force_signature_item = force_signature_item
754754+end
755755+756756+let signature sc s sg =
757757+ Lazy.(sg |> of_signature |> signature sc s |> force_signature)
758758+759759+let signature_item sc s comp =
760760+ Lazy.(comp|> of_signature_item |> signature_item sc s |> force_signature_item)
761761+762762+let modtype_declaration sc s decl =
763763+ Lazy.(decl |> of_modtype_decl |> modtype_decl sc s |> force_modtype_decl)
764764+765765+let module_declaration scoping s decl =
766766+ Lazy.(decl |> of_module_decl |> module_decl scoping s |> force_module_decl)
+63
typing/subst.mli
···8787(* A forward reference to be filled in ctype.ml. *)
8888val ctype_apply_env_empty:
8989 (type_expr list -> type_expr -> type_expr list -> type_expr) ref
9090+9191+9292+module Lazy : sig
9393+ type module_decl =
9494+ {
9595+ mdl_type: modtype;
9696+ mdl_attributes: Parsetree.attributes;
9797+ mdl_loc: Location.t;
9898+ mdl_uid: Uid.t;
9999+ }
100100+101101+ and modtype =
102102+ | MtyL_ident of Path.t
103103+ | MtyL_signature of signature
104104+ | MtyL_functor of functor_parameter * modtype
105105+ | MtyL_alias of Path.t
106106+107107+ and modtype_declaration =
108108+ {
109109+ mtdl_type: modtype option; (* Note: abstract *)
110110+ mtdl_attributes: Parsetree.attributes;
111111+ mtdl_loc: Location.t;
112112+ mtdl_uid: Uid.t;
113113+ }
114114+115115+ and signature
116116+117117+ and signature_item =
118118+ SigL_value of Ident.t * value_description * visibility
119119+ | SigL_type of Ident.t * type_declaration * rec_status * visibility
120120+ | SigL_typext of Ident.t * extension_constructor * ext_status * visibility
121121+ | SigL_module of
122122+ Ident.t * module_presence * module_decl * rec_status * visibility
123123+ | SigL_modtype of Ident.t * modtype_declaration * visibility
124124+ | SigL_class of Ident.t * class_declaration * rec_status * visibility
125125+ | SigL_class_type of Ident.t * class_type_declaration *
126126+ rec_status * visibility
127127+128128+ and functor_parameter =
129129+ | Unit
130130+ | Named of Ident.t option * modtype
131131+132132+133133+ val of_module_decl : Types.module_declaration -> module_decl
134134+ val of_modtype : Types.module_type -> modtype
135135+ val of_modtype_decl : Types.modtype_declaration -> modtype_declaration
136136+ val of_signature : Types.signature -> signature
137137+ val of_signature_items : signature_item list -> signature
138138+ val of_signature_item : Types.signature_item -> signature_item
139139+140140+ val module_decl : scoping -> t -> module_decl -> module_decl
141141+ val modtype : scoping -> t -> modtype -> modtype
142142+ val modtype_decl : scoping -> t -> modtype_declaration -> modtype_declaration
143143+ val signature : scoping -> t -> signature -> signature
144144+ val signature_item : scoping -> t -> signature_item -> signature_item
145145+146146+ val force_module_decl : module_decl -> Types.module_declaration
147147+ val force_modtype : modtype -> Types.module_type
148148+ val force_modtype_decl : modtype_declaration -> Types.modtype_declaration
149149+ val force_signature : signature -> Types.signature
150150+ val force_signature_once : signature -> signature_item list
151151+ val force_signature_item : signature_item -> Types.signature_item
152152+end
+89-50
typing/typecore.ml
···955955956956 (* warn if there are several distinct candidates in scope *)
957957 let warn_if_ambiguous warn lid env lbl rest =
958958- Printtyp.Conflicts.reset ();
959959- let paths = ambiguous_types env lbl rest in
960960- let expansion =
961961- Format.asprintf "%t" Printtyp.Conflicts.print_explanations in
962962- if paths <> [] then
963963- warn lid.loc
964964- (Warnings.Ambiguous_name ([Longident.last lid.txt],
965965- paths, false, expansion))
958958+ if Warnings.is_active (Ambiguous_name ([],[],false,"")) then begin
959959+ Printtyp.Conflicts.reset ();
960960+ let paths = ambiguous_types env lbl rest in
961961+ let expansion =
962962+ Format.asprintf "%t" Printtyp.Conflicts.print_explanations in
963963+ if paths <> [] then
964964+ warn lid.loc
965965+ (Warnings.Ambiguous_name ([Longident.last lid.txt],
966966+ paths, false, expansion))
967967+ end
966968967969 (* a non-principal type was used for disambiguation *)
968970 let warn_non_principal warn lid =
···973975974976 (* we selected a name out of the lexical scope *)
975977 let warn_out_of_scope warn lid env tpath =
976976- let path_s =
977977- Printtyp.wrap_printing_env ~error:true env
978978- (fun () -> Printtyp.string_of_path tpath) in
979979- warn lid.loc
980980- (Warnings.Name_out_of_scope (path_s, [Longident.last lid.txt], false))
978978+ if Warnings.is_active (Name_out_of_scope ("",[],false)) then begin
979979+ let path_s =
980980+ Printtyp.wrap_printing_env ~error:true env
981981+ (fun () -> Printtyp.string_of_path tpath) in
982982+ warn lid.loc
983983+ (Warnings.Name_out_of_scope (path_s, [Longident.last lid.txt], false))
984984+ end
981985982986 (* warn if the selected name is not the last introduced in scope
983987 -- in these cases the resolution is different from pre-disambiguation OCaml
···25162520 List.iter generalize vars;
25172521 check_univars env kind exp ty_expected vars
2518252225192519-let check_partial_application statement exp =
25202520- let rec f delay =
25232523+(* [check_statement] implements the [non-unit-statement] check.
25242524+25252525+ This check is called in contexts where the value of the expression is known
25262526+ to be discarded (eg. the lhs of a sequence). We check that [exp] has type
25272527+ unit, or has an explicit type annotation; otherwise we raise the
25282528+ [non-unit-statement] warning. *)
25292529+25302530+let check_statement exp =
25312531+ let ty = get_desc (expand_head exp.exp_env exp.exp_type) in
25322532+ match ty with
25332533+ | Tconstr (p, _, _) when Path.same p Predef.path_unit -> ()
25342534+ | Tvar _ -> ()
25352535+ | _ ->
25362536+ let rec loop {exp_loc; exp_desc; exp_extra; _} =
25372537+ match exp_desc with
25382538+ | Texp_let (_, _, e)
25392539+ | Texp_sequence (_, e)
25402540+ | Texp_letexception (_, e)
25412541+ | Texp_letmodule (_, _, _, _, e) ->
25422542+ loop e
25432543+ | _ ->
25442544+ let loc =
25452545+ match List.find_opt (function
25462546+ | (Texp_constraint _, _, _) -> true
25472547+ | _ -> false) exp_extra
25482548+ with
25492549+ | Some (_, loc, _) -> loc
25502550+ | None -> exp_loc
25512551+ in
25522552+ Location.prerr_warning loc Warnings.Non_unit_statement
25532553+ in
25542554+ loop exp
25552555+25562556+25572557+(* [check_partial_application] implements the [ignored-partial-application]
25582558+ warning (and if [statement] is [true], also [non-unit-statement]).
25592559+25602560+ If [exp] has a function type, we check that it is not syntactically the
25612561+ result of a function application, as this is often a bug in certain contexts
25622562+ (eg the rhs of a let-binding or in the argument of [ignore]). For example,
25632563+ [ignore (List.map print_int)] written by mistake instad of [ignore (List.map
25642564+ print_int li)].
25652565+25662566+ The check can be disabled by explicitly annotating the expression with a type
25672567+ constraint, eg [(e : _ -> _)].
25682568+25692569+ If [statement] is [true] and the [ignored-partial-application] is {em not}
25702570+ triggered, then the [non-unit-statement] check is performaed (see
25712571+ [check_statement]).
25722572+25732573+ If the type of [exp] is not known at the time this function is called, the
25742574+ check is retried again after typechecking. *)
25752575+25762576+let check_partial_application ~statement exp =
25772577+ let check_statement () = if statement then check_statement exp in
25782578+ let doit () =
25212579 let ty = get_desc (expand_head exp.exp_env exp.exp_type) in
25222522- let check_statement () =
25232523- match ty with
25242524- | Tconstr (p, _, _) when Path.same p Predef.path_unit ->
25252525- ()
25262526- | _ ->
25272527- if statement then
25282528- let rec loop {exp_loc; exp_desc; exp_extra; _} =
25292529- match exp_desc with
25302530- | Texp_let (_, _, e)
25312531- | Texp_sequence (_, e)
25322532- | Texp_letexception (_, e)
25332533- | Texp_letmodule (_, _, _, _, e) ->
25342534- loop e
25352535- | _ ->
25362536- let loc =
25372537- match List.find_opt (function
25382538- | (Texp_constraint _, _, _) -> true
25392539- | _ -> false) exp_extra
25402540- with
25412541- | Some (_, loc, _) -> loc
25422542- | None -> exp_loc
25432543- in
25442544- Location.prerr_warning loc Warnings.Non_unit_statement
25452545- in
25462546- loop exp
25472547- in
25482548- match ty, exp.exp_desc with
25492549- | Tarrow _, _ ->
25802580+ match ty with
25812581+ | Tarrow _ ->
25502582 let rec check {exp_desc; exp_loc; exp_extra; _} =
25512583 if List.exists (function
25522584 | (Texp_constraint _, _, _) -> true
···25782610 end
25792611 in
25802612 check exp
25812581- | Tvar _, _ ->
25822582- if delay then add_delayed_check (fun () -> f false)
25832613 | _ ->
25842614 check_statement ()
25852615 in
25862586- f true
26162616+ let ty = get_desc (expand_head exp.exp_env exp.exp_type) in
26172617+ match ty with
26182618+ | Tvar _ ->
26192619+ (* The type of [exp] is not known. Delay the check until after
26202620+ typechecking in order to give a chance for the type to become known
26212621+ through unification. *)
26222622+ add_delayed_check doit
26232623+ | _ ->
26242624+ doit ()
2587262525882626(* Check that a type is generalizable at some level *)
25892627let generalizable level ty =
···30013039 try rue exp
30023040 with Error (_, _, Expr_type_clash _) as err ->
30033041 Misc.reraise_preserving_backtrace err (fun () ->
30043004- check_partial_application false exp)
30423042+ check_partial_application ~statement:false exp)
30053043 end
30063044 | Pexp_match(sarg, caselist) ->
30073045 begin_def ();
···46444682 [Nolabel, sarg] when is_ignore funct ->
46454683 let ty_arg, ty_res = filter_arrow env (instance funct.exp_type) Nolabel in
46464684 let exp = type_expect env sarg (mk_expected ty_arg) in
46474647- check_partial_application false exp;
46854685+ check_partial_application ~statement:false exp;
46484686 ([Nolabel, Some exp], ty_res)
46494687 | _ ->
46504688 let ty = funct.exp_type in
···47524790 unify_exp env exp expected_ty);
47534791 exp
47544792 else begin
47554755- check_partial_application true exp;
47934793+ check_partial_application ~statement:true exp;
47564794 unify_var env tv ty;
47574795 exp
47584796 end
4759479747604798and type_unpacks ?(in_function : (Location.t * type_expr) option)
47614799 env (unpacks : to_unpack list) sbody expected_ty =
48004800+ if unpacks = [] then type_expect ?in_function env sbody expected_ty else
47624801 let ty = newvar() in
47634802 (* remember original level *)
47644803 let extended_env, tunpacks =
···53085347 | {vb_pat = {pat_desc = Tpat_any; pat_extra; _}; vb_expr; _} ->
53095348 if not (List.exists (function (Tpat_constraint _, _, _) -> true
53105349 | _ -> false) pat_extra) then
53115311- check_partial_application false vb_expr
53505350+ check_partial_application ~statement:false vb_expr
53125351 | _ -> ()) l;
53135352 (l, new_env, unpacks)
53145353
+21-19
typing/typemod.ml
···767767let rec approx_modtype env smty =
768768 match smty.pmty_desc with
769769 Pmty_ident lid ->
770770- let (path, _info) =
771771- Env.lookup_modtype ~use:false ~loc:smty.pmty_loc lid.txt env
770770+ let path =
771771+ Env.lookup_modtype_path ~use:false ~loc:smty.pmty_loc lid.txt env
772772 in
773773 Mty_ident path
774774 | Pmty_alias lid ->
···809809 | Pwith_module (_, lid') ->
810810 (* Lookup the module to make sure that it is not recursive.
811811 (GPR#1626) *)
812812- ignore (Env.lookup_module ~use:false ~loc:lid'.loc lid'.txt env)
812812+ ignore (Env.lookup_module_path ~use:false ~load:false
813813+ ~loc:lid'.loc lid'.txt env)
813814 | Pwith_modsubst (_, lid') ->
814814- ignore (Env.lookup_module ~use:false ~loc:lid'.loc lid'.txt env))
815815+ ignore (Env.lookup_module_path ~use:false ~load:false
816816+ ~loc:lid'.loc lid'.txt env))
815817 constraints;
816818 body
817819 | Pmty_typeof smod ->
···12621264(* Check and translate a module type expression *)
1263126512641266let transl_modtype_longident loc env lid =
12651265- let (path, _info) = Env.lookup_modtype ~loc lid env in
12661266- path
12671267+ Env.lookup_modtype_path ~loc lid env
1267126812681269let transl_module_alias loc env lid =
12691270 Env.lookup_module_path ~load:false ~loc lid env
···21042105 mod_attributes = smod.pmod_attributes;
21052106 mod_loc = smod.pmod_loc } in
21062107 let aliasable = not (Env.is_functor_arg path env) in
21072107- let md =
21082108- if alias && aliasable then
21092109- (Env.add_required_global (Path.head path); md)
21102110- else match (Env.find_module path env).md_type with
21082108+ if alias && aliasable then
21092109+ (Env.add_required_global (Path.head path); md)
21102110+ else begin
21112111+ let mty =
21122112+ if sttn then
21132113+ Env.find_strengthened_module ~aliasable path env
21142114+ else
21152115+ (Env.find_module path env).md_type
21162116+ in
21172117+ match mty with
21112118 | Mty_alias p1 when not alias ->
21122119 let p1 = Env.normalize_module_path (Some smod.pmod_loc) env p1 in
21132113- let mty = Includemod.expand_module_alias env p1 in
21202120+ let mty = Includemod.expand_module_alias
21212121+ ~strengthen:sttn env p1 in
21142122 { md with
21152123 mod_desc =
21162124 Tmod_constraint (md, mty, Tmodtype_implicit,
21172125 Tcoerce_alias (env, path, Tcoerce_none));
21182118- mod_type =
21192119- if sttn then Mtype.strengthen ~aliasable:true env mty p1
21202120- else mty }
21262126+ mod_type = mty }
21212127 | mty ->
21222122- let mty =
21232123- if sttn then Mtype.strengthen ~aliasable env mty path
21242124- else mty
21252125- in
21262128 { md with mod_type = mty }
21272127- in md
21292129+ end
21282130 | Pmod_structure sstr ->
21292131 let (str, sg, names, _finalenv) =
21302132 type_structure funct_body anchor env sstr in
+9-6
typing/untypeast.ml
···331331 | Tpat_tuple list ->
332332 Ppat_tuple (List.map (sub.pat sub) list)
333333 | Tpat_construct (lid, _, args, vto) ->
334334- let vl, tyo =
334334+ let tyo =
335335 match vto with
336336- None -> [], None
336336+ None -> None
337337 | Some (vl, ty) ->
338338- List.map (fun x -> {x with txt = Ident.name x.txt}) vl,
339339- Some (sub.typ sub ty)
338338+ let vl =
339339+ List.map (fun x -> {x with txt = Ident.name x.txt}) vl
340340+ in
341341+ Some (vl, sub.typ sub ty)
340342 in
341343 let arg =
342344 match args with
···346348 in
347349 Ppat_construct (map_loc sub lid,
348350 match tyo, arg with
349349- | Some ty, Some arg ->
351351+ | Some (vl, ty), Some arg ->
350352 Some (vl, Pat.mk ~loc (Ppat_constraint (arg, ty)))
351351- | _ -> None)
353353+ | None, Some arg -> Some ([], arg)
354354+ | _, None -> None)
352355 | Tpat_variant (label, pato, _) ->
353356 Ppat_variant (label, Option.map (sub.pat sub) pato)
354357 | Tpat_record (list, closed) ->
+6
utils/lazy_backtrack.ml
···4242let get_arg x =
4343 match !x with Thunk a -> Some a | _ -> None
44444545+let get_contents x =
4646+ match !x with
4747+ | Thunk a -> Either.Left a
4848+ | Done b -> Either.Right b
4949+ | Raise e -> raise e
5050+4551let create x =
4652 ref (Thunk x)
4753
+1
utils/lazy_backtrack.mli
···2020val force : ('a -> 'b) -> ('a,'b) t -> 'b
2121val create : 'a -> ('a,'b) t
2222val get_arg : ('a,'b) t -> 'a option
2323+val get_contents : ('a,'b) t -> ('a,'b) Either.t
2324val create_forced : 'b -> ('a, 'b) t
2425val create_failed : exn -> ('a, 'b) t
2526